// Android paths void setPaths() { PATH_CONF = std::string(SDL_AndroidGetInternalStoragePath()) + "/config"; PATH_USER = std::string(SDL_AndroidGetInternalStoragePath()) + "/userdata"; createDir(PATH_CONF); createDir(PATH_USER); createDir(PATH_USER + "/mods"); createDir(PATH_USER + "/saves"); std::string mods_folder = "data/org.flare.app/files"; if (SDL_AndroidGetExternalStorageState() != 0) { PATH_DATA = std::string(SDL_AndroidGetExternalStoragePath()); } else if (dirExists("/sdcard/Android")) { PATH_DATA = "/sdcard/Android/" + mods_folder; } else if (dirExists("/mnt/sdcard/Android")) { PATH_DATA = "/mnt/sdcard/Android/" + mods_folder; } else if (dirExists("storage/sdcard0/Android")) { PATH_DATA = "/storage/sdcard0/Android/" + mods_folder; } else if (dirExists("/storage/emulated/0/Android")) { PATH_DATA = "/storage/emulated/0/Android/" + mods_folder; } else if (dirExists("/storage/emulated/legacy/Android")) { PATH_DATA = "/storage/emulated/legacy/Android/" + mods_folder; } else { logError("Settings: Android external storage unavailable: %s", SDL_GetError()); } PATH_CONF = PATH_CONF + "/"; PATH_USER = PATH_USER + "/"; PATH_DATA = PATH_DATA + "/"; }
void init(const char* company, const char* app) { if (_fsInitialized) return; _fsInitialized = true; #ifdef __S3E__ _nfs.setPath("rom://"); _nfsWrite.setPath("ram://"); #elif EMSCRIPTEN //mkdir("data-ram/", S_IRWXU|S_IRWXG|S_IRWXO); //_nfsWrite.setPath("data-ram/"); #elif __ANDROID__ log::messageln("internal %s", SDL_AndroidGetInternalStoragePath()); log::messageln("external %s", SDL_AndroidGetExternalStoragePath()); _nfsWrite.setPath(SDL_AndroidGetInternalStoragePath()); #elif OXYGINE_EDITOR #elif __APPLE__ _nfsWrite.setPath(getSupportFolder().c_str()); #else if (company && app && *company && *app) { char* base_path = SDL_GetPrefPath(company, app); if (base_path) { _nfsWrite.setPath(base_path); SDL_free(base_path); } } else { # ifdef _WIN32 _mkdir("../data-ram/"); # else mkdir("../data-ram/", ACCESSPERMS); # endif _nfsWrite.setPath("../data-ram/"); } #endif _nfs.mount(&_nfsWrite); }
void init() { #ifdef __S3E__ _nfs.setPath("rom://"); _nfsWrite.setPath("ram://"); #endif #ifdef __ANDROID__ log::messageln("internal %s", SDL_AndroidGetInternalStoragePath()); log::messageln("external %s", SDL_AndroidGetExternalStoragePath()); _nfsWrite.setPath(SDL_AndroidGetInternalStoragePath()); #endif // __ANDROID__ #ifdef WIN32 _mkdir("../data-ram/"); _nfsWrite.setPath("../data-ram/"); #endif _nfs.mount(&_nfsWrite); //_nfs.mount(&_nfsExtended); }
char * SDL_GetPrefPath(const char *org, const char *app) { const char *path = SDL_AndroidGetInternalStoragePath(); if (path) { size_t pathlen = SDL_strlen(path)+2; char *fullpath = (char *)SDL_malloc(pathlen); if (!fullpath) { SDL_OutOfMemory(); return NULL; } SDL_snprintf(fullpath, pathlen, "%s/", path); return fullpath; } return NULL; }
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; }
SDL_RWops * SDL_RWFromFile(const char *file, const char *mode) { SDL_RWops *rwops = NULL; if (!file || !*file || !mode || !*mode) { SDL_SetError("SDL_RWFromFile(): No file or no mode specified"); return NULL; } #if defined(ANDROID) #ifdef HAVE_STDIO_H /* Try to open the file on the filesystem first */ if (*file == '/') { FILE *fp = fopen(file, mode); if (fp) { return SDL_RWFromFP(fp, 1); } } else { /* Try opening it from internal storage if it's a relative path */ char *path; FILE *fp; path = SDL_stack_alloc(char, PATH_MAX); if (path) { SDL_snprintf(path, PATH_MAX, "%s/%s", SDL_AndroidGetInternalStoragePath(), file); fp = fopen(path, mode); SDL_stack_free(path); if (fp) { return SDL_RWFromFP(fp, 1); } } } #endif /* HAVE_STDIO_H */ /* Try to open the file from the asset system */ rwops = SDL_AllocRW(); if (!rwops) return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ if (Android_JNI_FileOpen(rwops, file, mode) < 0) { SDL_FreeRW(rwops); return NULL; } rwops->size = Android_JNI_FileSize; rwops->seek = Android_JNI_FileSeek; rwops->read = Android_JNI_FileRead; rwops->write = Android_JNI_FileWrite; rwops->close = Android_JNI_FileClose; #elif defined(__WIN32__) rwops = SDL_AllocRW(); if (!rwops) return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ if (windows_file_open(rwops, file, mode) < 0) { SDL_FreeRW(rwops); return NULL; } rwops->size = windows_file_size; rwops->seek = windows_file_seek; rwops->read = windows_file_read; rwops->write = windows_file_write; rwops->close = windows_file_close; #elif HAVE_STDIO_H { #ifdef __APPLE__ FILE *fp = SDL_OpenFPFromBundleOrFallback(file, mode); #else FILE *fp = fopen(file, mode); #endif if (fp == NULL) { SDL_SetError("Couldn't open %s", file); } else { rwops = SDL_RWFromFP(fp, 1); } } #else SDL_SetError("SDL not compiled with stdio support"); #endif /* !HAVE_STDIO_H */ return (rwops); }
void PlatformSetPaths() { const std::string externalSDList[] = { "/mnt/extSdCard/Android", "/storage/extSdCard/Android" }; const int externalSDList_size = 2; PATH_CONF = std::string(SDL_AndroidGetInternalStoragePath()) + "/config"; const std::string package_name = AndroidGetPackageName(); const std::string user_folder = "data/" + package_name + "/files"; if (SDL_AndroidGetExternalStorageState() != 0) { PATH_USER = std::string(SDL_AndroidGetExternalStoragePath()); } // NOTE: Next condition shouldn't be needed, but in theory SDL_AndroidGetExternalStoragePath() can fail. else { const std::string internalSDList[] = { "/sdcard/Android", "/mnt/sdcard/Android", "/storage/sdcard0/Android", "/storage/emulated/0/Android", "/storage/emulated/legacy/Android", }; const int internalSDList_size = 5; for (int i = 0; i < internalSDList_size; i++) { if (dirExists(internalSDList[i])) { PATH_USER = internalSDList[i] + "/" + user_folder; break; } } } if (PATH_USER.empty()) { logError("Settings: Android external storage unavailable: %s", SDL_GetError()); } for (int i = 0; i < externalSDList_size; i++) { if (dirExists(externalSDList[i])) { PATH_DATA = externalSDList[i] + "/" + user_folder; if (!dirExists(PATH_DATA)) { createDir(externalSDList[i] + "/data" + package_name); createDir(externalSDList[i] + "/data" + package_name + "/files"); } break; } } PATH_USER += "/userdata"; createDir(PATH_CONF); createDir(PATH_USER); createDir(PATH_USER + "/mods"); createDir(PATH_USER + "/saves"); PATH_CONF += "/"; PATH_USER += "/"; PATH_DATA += "/"; }