From 9eacd483c60832f8e3ea26b78b2fad154ee05b83 Mon Sep 17 00:00:00 2001 From: Miku AuahDark Date: Tue, 19 Mar 2024 22:24:45 +0800 Subject: [PATCH] Android: Fixed assets/game.love fusing not being recognized. Fixes love2d/love-android#267. --- src/common/android.cpp | 14 ++++++++------ src/modules/filesystem/physfs/Filesystem.cpp | 10 +++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/common/android.cpp b/src/common/android.cpp index d8c775093..1ec823536 100644 --- a/src/common/android.cpp +++ b/src/common/android.cpp @@ -385,18 +385,20 @@ struct AssetInfo: public love::filesystem::physfs::PhysfsIo return 1; } - AssetInfo *duplicate() const + AssetInfo(const AssetInfo &other) + : assetManager(other.assetManager) + , size(strlen(other.filename) + 1) { - AAsset *newAsset = AAssetManager_open(assetManager, filename, AASSET_MODE_RANDOM); + asset = AAssetManager_open(assetManager, other.filename, AASSET_MODE_RANDOM); - if (newAsset == nullptr) + if (asset == nullptr) { PHYSFS_setErrorCode(PHYSFS_ERR_OS_ERROR); - return nullptr; + throw new love::Exception("Unable to duplicate AssetInfo"); } - AAsset_seek64(asset, tell(), SEEK_SET); - return fromAAsset(assetManager, filename, asset); + filename = new (std::nothrow) char[size]; + memcpy(filename, other.filename, size); } ~AssetInfo() override diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index 586e064c0..52e190c56 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/src/modules/filesystem/physfs/Filesystem.cpp @@ -245,8 +245,14 @@ bool Filesystem::setSource(const char *source) if (hasFusedGame) { if (gameLoveIO) - // Actually we should just be able to mount gameLoveIO, but that's experimental. + { + if (PHYSFS_mountIo(gameLoveIO, ".zip", nullptr, 0)) { + gameSource = new_search_path; + return true; + } + gameLoveIO->destroy(gameLoveIO); + } else { if (!love::android::initializeVirtualArchive()) @@ -274,6 +280,8 @@ bool Filesystem::setSource(const char *source) gameSource = new_search_path; return true; } + + io->destroy(io); } } #endif