Upgrade to Squirrel 2.1.2 <http://squirrel-lang.org/>
[supertux.git] / src / main.cpp
index aa998fd..2148861 100644 (file)
 #include <SDL.h>
 #include <SDL_image.h>
 
+#ifdef MACOSX
+# include <CoreFoundation/CoreFoundation.h>
+#endif
+
 #include "gameconfig.hpp"
 #include "resources.hpp"
 #include "gettext.hpp"
@@ -165,8 +169,18 @@ static void init_physfs(const char* argv0)
 
 #ifdef MACOSX
   // when started from Application file on Mac OS X...
-  dir = PHYSFS_getBaseDir();
-  dir += "SuperTux.app/Contents/Resources/data";
+  char path[PATH_MAX];
+  CFBundleRef mainBundle = CFBundleGetMainBundle();
+  assert(mainBundle != 0);
+  CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
+  assert(mainBundleURL != 0);
+  CFStringRef pathStr = CFUrlCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle);
+  assert(pathStr != 0);
+  CFStringGetCString(pathStr, path, PATH_MAX, kCFStringEncodingUTF8);
+  CFRelease(mainBundleURL);
+  CFRelease(pathStr);
+
+  dir = std::string(path) + "/Contents/Resources/data";
   testfname = dir + "/credits.txt";
   sourcedir = false;
   f = fopen(testfname.c_str(), "r");
@@ -193,12 +207,13 @@ static void init_physfs(const char* argv0)
     br_init (NULL);
     dir = br_find_data_dir(APPDATADIR);
     datadir = dir;
-    datadir += "/" PACKAGE_NAME;
     free(dir);
 
 #else
     datadir = APPDATADIR;
 #endif
+    datadir += "/";
+    datadir += application;
     if(!PHYSFS_addToSearchPath(datadir.c_str(), 1)) {
       log_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
     }
@@ -581,7 +596,6 @@ int main(int argc, char** argv)
   delete main_loop;
   main_loop = NULL;
 
-  free_options_menu();
   unload_shared();
   quit_audio();