diff --git a/sc2/ChangeLog b/sc2/ChangeLog index b6d0d64b6..b6343f1a7 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ 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 - Androsynth ruins freeing condition now uses cycles (Bug #1028) - Michael - .rmp files now carry the types of the targets - Michael diff --git a/sc2/src/options.c b/sc2/src/options.c index b50cccfda..eebaad18a 100644 --- a/sc2/src/options.c +++ b/sc2/src/options.c @@ -36,6 +36,10 @@ #include #include #include +#ifdef __APPLE__ +# include + /* for dirname() */ +#endif int optWhichCoarseScan; @@ -117,8 +121,12 @@ findFileInDirs (const char *locs[], int numLocs, const char *file) 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 -prepareContentDir (const char *contentDirName) +prepareContentDir (const char *contentDirName, const char *execFile) { const char *testFile = "version"; const char *loc; @@ -133,6 +141,20 @@ prepareContentDir (const char *contentDirName) "../../content" /* For running from MSVC */ }; 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 { @@ -145,7 +167,8 @@ prepareContentDir (const char *contentDirName) 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 " "directory: %s", strerror (errno)); @@ -155,6 +178,10 @@ prepareContentDir (const char *contentDirName) log_add (log_Debug, "Using '%s' as base content dir.", baseContentPath); mountContentDir (repository, baseContentPath); + +#ifndef __APPLE__ + (void) execFile; +#endif } void diff --git a/sc2/src/options.h b/sc2/src/options.h index 1e63922a8..ff678479d 100644 --- a/sc2/src/options.h +++ b/sc2/src/options.h @@ -66,7 +66,7 @@ typedef struct _input_template { 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 prepareMeleeDir (void); void prepareSaveDir (void); diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 62304aba2..b9ab01f23 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -432,7 +432,7 @@ main (int argc, char *argv[]) speechVolumeScale = options.speechVolumeScale; optAddons = options.addons; - prepareContentDir (options.contentDir); + prepareContentDir (options.contentDir, argv[0]); prepareMeleeDir (); prepareSaveDir (); #if 0