Skip to content

Instantly share code, notes, and snippets.

@cigumo
Created November 16, 2017 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cigumo/0f1d6a7dcf1ddc0a17a9bdcbd2290aab to your computer and use it in GitHub Desktop.
Save cigumo/0f1d6a7dcf1ddc0a17a9bdcbd2290aab to your computer and use it in GitHub Desktop.
bool Filesystem::setSource(const char *source)
{
if (!PHYSFS_isInit())
return false;
// Check whether directory is already set.
if (!game_source.empty())
return false;
std::string new_search_path = source;
#ifdef LOVE_ANDROID
if (!love::android::createStorageDirectories())
SDL_Log("Error creating storage directories!");
new_search_path = love::android::getSelectedGameFile();
// try mounting first, if that fails, try loading to memory and mounting then
if (! (PHYSFS_mount(new_search_path.c_str(), nullptr, 1) == 1) )
{
SDL_Log("Mounting did not work. Loading archive to memory and mounting.");
char* game_archive_ptr = NULL;
size_t game_archive_size = 0;
if (!love::android::loadGameArchiveToMemory(new_search_path.c_str(), &game_archive_ptr, &game_archive_size))
{
SDL_Log("Failure memory loading archive %s", new_search_path.c_str());
return false;
}
if (!PHYSFS_mountMemory(game_archive_ptr, game_archive_size, love::android::freeGameArchiveMemory, "archive.zip", "/", 0))
{
SDL_Log("Failure mounting in-memory archive.");
love::android::freeGameArchiveMemory(game_archive_ptr);
return false;
}
}
#else
// Add the directory.
if (!PHYSFS_mount(new_search_path.c_str(), nullptr, 1))
return false;
#endif
// Save the game source.
game_source = new_search_path;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment