diff --git a/src/Starfighter.c b/src/Starfighter.c index fc77dee..66e2fe3 100644 --- a/src/Starfighter.c +++ b/src/Starfighter.c @@ -55,26 +55,26 @@ int main(int argc, char **argv) int cheatAttempt; int cheatCount; int section; - + +#ifdef __APPLE__ + // This makes relative paths work in Xcode by changing directory to the Resources folder inside the .app bundle + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); + char path[PATH_MAX]; + if (CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) + { + chdir(path); + printf("Current directory \"%s\"\n", path); + } + else + { + if (chdir(DATADIR) == -1) + printf("Warning: failed to change directory to \"%s\"\n", DATADIR); + } +#else if (chdir(DATADIR) == -1) printf("Warning: failed to change directory to \"%s\"\n", DATADIR); - - // This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle -#ifdef __APPLE__ - CFBundleRef mainBundle = CFBundleGetMainBundle(); - CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); - char path[PATH_MAX]; - if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) - { - // error! - } - CFRelease(resourcesURL); - - chdir(path); - printf("Current directory \"%s\"\n", path); #endif - // ---------------------------------------------------------------------------- - engine_init(); // Must do this first!