Implement experimental fusing method.

https://github.com/love2d/love-android/issues/201#issuecomment-772628115
This commit is contained in:
Miku AuahDark
2021-02-06 22:10:49 +08:00
parent e967348409
commit 22455276f6
+49 -19
View File
@@ -108,6 +108,10 @@ Filesystem::Filesystem()
Filesystem::~Filesystem() Filesystem::~Filesystem()
{ {
#ifdef LOVE_ANDROID
love::android::deinitializeVirtualArchive();
#endif
if (PHYSFS_isInit()) if (PHYSFS_isInit())
PHYSFS_deinit(); PHYSFS_deinit();
} }
@@ -224,30 +228,56 @@ bool Filesystem::setSource(const char *source)
if (!love::android::createStorageDirectories()) if (!love::android::createStorageDirectories())
SDL_Log("Error creating storage directories!"); SDL_Log("Error creating storage directories!");
new_search_path = love::android::getSelectedGameFile(); new_search_path = "";
// try mounting first, if that fails, load to memory and mount PHYSFS_Io *gameLoveIO;
if (!PHYSFS_mount(new_search_path.c_str(), nullptr, 1)) bool hasFusedGame = love::android::checkFusedGame((void **) &gameLoveIO);
if (hasFusedGame)
{ {
// PHYSFS cannot yet mount a zip file inside an .apk if (gameLoveIO)
SDL_Log("Mounting %s did not work. Loading to memory.",
new_search_path.c_str());
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()); // Actually we should just be able to mount gameLoveIO, but that's experimental.
return false; gameLoveIO->destroy(gameLoveIO);
goto oldschool;
} }
if (!PHYSFS_mountMemory( else
game_archive_ptr, game_archive_size,
love::android::freeGameArchiveMemory, "archive.zip", "/", 0))
{ {
SDL_Log("Failure mounting in-memory archive."); if (!love::android::initializeVirtualArchive())
love::android::freeGameArchiveMemory(game_archive_ptr); {
return false; SDL_Log("Unable to mount AAsset: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
return false;
}
}
}
else
{
oldschool:
new_search_path = love::android::getSelectedGameFile();
// try mounting first, if that fails, load to memory and mount
if (!PHYSFS_mount(new_search_path.c_str(), nullptr, 1))
{
// PHYSFS cannot yet mount a zip file inside an .apk
SDL_Log("Mounting %s did not work. Loading to memory.",
new_search_path.c_str());
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 #else