Browse Source

Merged in cigumo/love (pull request #99)

Changes Filesystem::setSource mount order on Android

Simplifies the way setSource is handled on Android. It tries to mount
first and if that fails it will copy to memory and mount.

This works alongside a separate patch to GameActivity.java submitted
to the love-android-sdl2 repo, that contains the /sdcard/lovegame
fallback mechanism, and also allows to copy the game.love to the app
cache dir, which is useful for large files.
Alex Szpakowski 7 years ago
parent
commit
0bc820ee0e
1 changed files with 17 additions and 45 deletions
  1. 17 45
      src/modules/filesystem/physfs/Filesystem.cpp

+ 17 - 45
src/modules/filesystem/physfs/Filesystem.cpp

@@ -224,57 +224,29 @@ bool Filesystem::setSource(const char *source)
 	if (!love::android::createStorageDirectories())
 		SDL_Log("Error creating storage directories!");
 
-	char* game_archive_ptr = NULL;
-	size_t game_archive_size = 0;
-	bool archive_loaded = false;
+	new_search_path = love::android::getSelectedGameFile();
 
-	// try to load the game that was sent to LÖVE via a Intent
-	archive_loaded = love::android::loadGameArchiveToMemory(love::android::getSelectedGameFile(), &game_archive_ptr, &game_archive_size);
-
-	if (!archive_loaded)
-	{
-		// try to load the game in the assets/ folder
-		archive_loaded = love::android::loadGameArchiveToMemory("game.love", &game_archive_ptr, &game_archive_size);
-	}
-
-	if (archive_loaded)
+	// try mounting first, if that fails, load to memory and mount
+	if (!PHYSFS_mount(new_search_path.c_str(), nullptr, 1))
 	{
-		if (!PHYSFS_mountMemory(game_archive_ptr, game_archive_size, love::android::freeGameArchiveMemory, "archive.zip", "/", 0))
+		// 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("Mounting of in-memory game archive failed!");
-			love::android::freeGameArchiveMemory(game_archive_ptr);
+			SDL_Log("Failure memory loading archive %s", new_search_path.c_str());
 			return false;
 		}
-	}
-	else
-	{
-		// try to load the game in the directory that was sent to LÖVE via an
-		// Intent ...
-		std::string game_path = std::string(love::android::getSelectedGameFile());
-
-		if (game_path == "")
-		{
-			// ... or fall back to the game at /sdcard/lovegame
-			game_path = "/sdcard/lovegame/";
-		}
-
-		SDL_RWops *sdcard_main = SDL_RWFromFile(std::string(game_path + "main.lua").c_str(), "rb");
-
-		if (sdcard_main)
+		if (!PHYSFS_mountMemory(
+			    game_archive_ptr, game_archive_size,
+			    love::android::freeGameArchiveMemory, "archive.zip", "/", 0))
 		{
-			new_search_path = game_path;
-			sdcard_main->close(sdcard_main);
-
-			if (!PHYSFS_mount(new_search_path.c_str(), nullptr, 1))
-			{
-				SDL_Log("mounting of %s failed", new_search_path.c_str());
-				return false;
-			}
-		}
-		else
-		{
-			// Neither assets/game.love or /sdcard/lovegame was mounted
-			// sucessfully, therefore simply fail.
+			SDL_Log("Failure mounting in-memory archive.");
+			love::android::freeGameArchiveMemory(game_archive_ptr);
 			return false;
 		}
 	}