bool SetupDefaultDirs(const char *exefilepath, const char *auxfilepath, bool forcecommandline) { datadir = StripFilePart(exefilepath); auxdir = auxfilepath ? StripFilePart(SanitizePath(auxfilepath).c_str()) : datadir; writedir = auxdir; #ifdef __APPLE__ if (!forcecommandline) { // default data dir is the Resources folder inside the .app bundle CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; auto res = CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX); CFRelease(resourcesURL); if (!res) return false; datadir = string(path) + "/"; #ifdef __IOS__ writedir = StripFilePart(path) + "Documents/"; // there's probably a better way to do this in CF #else writedir = datadir; // FIXME: this should probably be ~/Library/Application Support/AppName, but for now this works for non-app store apps #endif } #elif defined(ANDROID) datadir = "/Documents/Lobster/"; // FIXME: temp solution writedir = datadir; #endif return true; }
bool SetupDefaultDirs(const char *exefilepath, const char *auxfilepath, bool from_bundle) { datadir = StripFilePart(exefilepath); auxdir = auxfilepath ? StripFilePart(SanitizePath(auxfilepath).c_str()) : datadir; writedir = auxdir; // FIXME: use SDL_GetBasePath() instead? #ifdef __APPLE__ if (from_bundle) { // default data dir is the Resources folder inside the .app bundle CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; auto res = CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX); CFRelease(resourcesURL); if (!res) return false; datadir = string(path) + "/"; #ifdef __IOS__ writedir = StripFilePart(path) + "Documents/"; // there's probably a better way to do this in CF #else // FIXME: this should probably be ~/Library/Application Support/AppName, // but for now this works for non-app store apps writedir = datadir; #endif } #elif defined(__ANDROID__) SDL_Init(0); // FIXME, is this needed? bad dependency. auto internalstoragepath = SDL_AndroidGetInternalStoragePath(); auto externalstoragepath = SDL_AndroidGetExternalStoragePath(); Output(OUTPUT_INFO, internalstoragepath); Output(OUTPUT_INFO, externalstoragepath); if (internalstoragepath) datadir = internalstoragepath + string("/"); if (externalstoragepath) writedir = externalstoragepath + string("/"); // for some reason, the above SDL functionality doesn't actually work, // we have to use the relative path only to access APK files: datadir = ""; auxdir = writedir; #endif (void)from_bundle; return true; }