On MacOS X, search for the content in the application bundle, from Nic.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2919 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
Meep-Eep
2008-02-07 00:01:07 +00:00
parent 58b9361927
commit de203d2f6c
4 changed files with 32 additions and 4 deletions
+1
View File
@@ -1,4 +1,5 @@
Changes towards version 0.7: Changes towards version 0.7:
- On MacOS X, search for the content in the application bundle, from Nic
- Planetside resource names are now consistent and generatable - Michael - Planetside resource names are now consistent and generatable - Michael
- Androsynth ruins freeing condition now uses cycles (Bug #1028) - Michael - Androsynth ruins freeing condition now uses cycles (Bug #1028) - Michael
- .rmp files now carry the types of the targets - Michael - .rmp files now carry the types of the targets - Michael
+29 -2
View File
@@ -36,6 +36,10 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#ifdef __APPLE__
# include <libgen.h>
/* for dirname() */
#endif
int optWhichCoarseScan; int optWhichCoarseScan;
@@ -117,8 +121,12 @@ findFileInDirs (const char *locs[], int numLocs, const char *file)
return NULL; return NULL;
} }
// contentDirName is an explicitely specified location for the content,
// or NULL if none was explicitely specified.
// execFile is the path to the uqm executable, as acquired through
// main()'s argv[0].
void void
prepareContentDir (const char *contentDirName) prepareContentDir (const char *contentDirName, const char *execFile)
{ {
const char *testFile = "version"; const char *testFile = "version";
const char *loc; const char *loc;
@@ -133,6 +141,20 @@ prepareContentDir (const char *contentDirName)
"../../content" /* For running from MSVC */ "../../content" /* For running from MSVC */
}; };
loc = findFileInDirs (locs, sizeof locs / sizeof locs[0], testFile); loc = findFileInDirs (locs, sizeof locs / sizeof locs[0], testFile);
#ifdef __APPLE__
/* On OSX, if the content can't be found in any of the static
* locations, attempt to look inside the application bundle,
* by looking relative to the location of the uqm executable. */
if (loc == NULL)
{
char *tempDir = (char *) HMalloc (PATH_MAX);
snprintf (tempDir, sizeof tempDir, "%s/../Resources/content",
dirname (execFile));
loc = findFileInDirs ((const char **) &tempDir, 1, testFile);
HFree (tempDir);
}
#endif
} }
else else
{ {
@@ -145,7 +167,8 @@ prepareContentDir (const char *contentDirName)
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
if (expandPath (baseContentPath, sizeof baseContentPath, loc, EP_ALL_SYSTEM) == -1) if (expandPath (baseContentPath, sizeof baseContentPath, loc,
EP_ALL_SYSTEM) == -1)
{ {
log_add (log_Fatal, "Fatal error: Could not expand path to content " log_add (log_Fatal, "Fatal error: Could not expand path to content "
"directory: %s", strerror (errno)); "directory: %s", strerror (errno));
@@ -155,6 +178,10 @@ prepareContentDir (const char *contentDirName)
log_add (log_Debug, "Using '%s' as base content dir.", baseContentPath); log_add (log_Debug, "Using '%s' as base content dir.", baseContentPath);
mountContentDir (repository, baseContentPath); mountContentDir (repository, baseContentPath);
#ifndef __APPLE__
(void) execFile;
#endif
} }
void void
+1 -1
View File
@@ -66,7 +66,7 @@ typedef struct _input_template {
extern INPUT_TEMPLATE input_templates[6]; extern INPUT_TEMPLATE input_templates[6];
void prepareContentDir (const char *contentDirName); void prepareContentDir (const char *contentDirName, const char *execFile);
void prepareConfigDir (const char *configDirName); void prepareConfigDir (const char *configDirName);
void prepareMeleeDir (void); void prepareMeleeDir (void);
void prepareSaveDir (void); void prepareSaveDir (void);
+1 -1
View File
@@ -432,7 +432,7 @@ main (int argc, char *argv[])
speechVolumeScale = options.speechVolumeScale; speechVolumeScale = options.speechVolumeScale;
optAddons = options.addons; optAddons = options.addons;
prepareContentDir (options.contentDir); prepareContentDir (options.contentDir, argv[0]);
prepareMeleeDir (); prepareMeleeDir ();
prepareSaveDir (); prepareSaveDir ();
#if 0 #if 0