Browse Source

Merged in Bobbyjones/love/new-conf-flag-for-android-2 (pull request #53)

New conf flag for android 2
Alex Szpakowski 9 years ago
parent
commit
8566729229

+ 10 - 0
src/modules/filesystem/Filesystem.cpp

@@ -50,6 +50,16 @@ Filesystem::~Filesystem()
 {
 }
 
+void Filesystem::setAndroidSaveExternal(bool useExternal)
+{	
+	this->useExternal = useExternal;
+}
+
+bool Filesystem::isAndroidSaveExternal() const
+{ 
+	return useExternal;
+}
+
 bool Filesystem::isRealDirectory(const std::string &path) const
 {
 #ifdef LOVE_WINDOWS

+ 18 - 0
src/modules/filesystem/Filesystem.h

@@ -79,6 +79,20 @@ public:
 	 **/
 	virtual bool setupWriteDirectory() = 0;
 
+	/**
+	 * This sets the save location on Android. 
+	 * False for internal, true for external
+	 * @param external Bool for whether 
+	 * Android should use external file storage.
+	**/
+	virtual void setAndroidSaveExternal(bool useExternal = false);
+
+	/**
+	 * Gets whether the Android save is external.
+	 * Returns a bool.
+	**/
+	virtual bool isAndroidSaveExternal() const; 
+
 	/**
 	 * Sets the name of the save folder.
 	 * @param ident The name of the game. Will be used to
@@ -263,6 +277,10 @@ public:
 	 **/
 	virtual std::string getExecutablePath() const;
 
+private:
+
+	//should we save external or internal for Android
+	bool useExternal;
 }; // Filesystem
 
 } // filesystem

+ 10 - 5
src/modules/filesystem/physfs/Filesystem.cpp

@@ -144,7 +144,7 @@ bool Filesystem::isFused() const
 	return fused;
 }
 
-bool Filesystem::setIdentity(const char *ident, bool appendToPath)
+bool Filesystem::setIdentity(const char *ident, bool appendToPath) 
 {
 	if (!PHYSFS_isInit())
 		return false;
@@ -169,11 +169,16 @@ bool Filesystem::setIdentity(const char *ident, bool appendToPath)
 #ifdef LOVE_ANDROID
 	if (save_identity == "")
 		save_identity = "unnamed";
-	
-	std::string internal_storage_path = SDL_AndroidGetInternalStoragePath();
-	std::string save_directory = internal_storage_path + "/save";
 
-	save_path_full = std::string(SDL_AndroidGetInternalStoragePath()) + std::string("/save/") + save_identity;
+	std::string storage_path;
+	if (isAndroidSaveExternal())
+		storage_path = SDL_AndroidGetExternalStoragePath();
+	else
+		storage_path = SDL_AndroidGetInternalStoragePath();
+
+	std::string save_directory = storage_path + "/save";
+
+	save_path_full = storage_path + std::string("/save/") + save_identity;
 
 	if (!love::android::directoryExists(save_path_full.c_str()) &&
 			!love::android::mkdir(save_path_full.c_str()))

+ 8 - 0
src/modules/filesystem/wrap_Filesystem.cpp

@@ -69,6 +69,13 @@ int w_isFused(lua_State *L)
 	return 1;
 }
 
+int w_setAndroidSaveExternal(lua_State *L)
+{
+	bool useExternal = luax_optboolean(L, 1, false);
+	instance()->setAndroidSaveExternal(useExternal);
+	return 0;
+}
+
 int w_setIdentity(lua_State *L)
 {
 	const char *arg = luaL_checkstring(L, 1);
@@ -708,6 +715,7 @@ static const luaL_Reg functions[] =
 	{ "init", w_init },
 	{ "setFused", w_setFused },
 	{ "isFused", w_isFused },
+	{ "_setAndroidSaveExternal", w_setAndroidSaveExternal },
 	{ "setIdentity", w_setIdentity },
 	{ "getIdentity", w_getIdentity },
 	{ "setSource", w_setSource },

+ 2 - 0
src/scripts/boot.lua

@@ -374,6 +374,7 @@ function love.init()
 		console = false, -- Only relevant for windows.
 		identity = false,
 		appendidentity = false,
+		externalstorage = false, -- Only relevant for Android.
 		accelerometerjoystick = true, -- Only relevant for Android / iOS.
 		gammacorrect = false,
 	}
@@ -493,6 +494,7 @@ function love.init()
 	end
 
 	if love.filesystem then
+		love.filesystem._setAndroidSaveExternal(c.externalstorage)
 		love.filesystem.setIdentity(c.identity or love.filesystem.getIdentity(), c.appendidentity)
 		if love.filesystem.isFile("main.lua") then
 			require("main")

+ 8 - 0
src/scripts/boot.lua.h

@@ -684,6 +684,10 @@ const unsigned char boot_lua[] =
 	0x2c, 0x0a,
 	0x09, 0x09, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x3d, 
 	0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x0a,
+	0x09, 0x09, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x20, 
+	0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x4f, 0x6e, 0x6c, 0x79, 0x20, 0x72, 
+	0x65, 0x6c, 0x65, 0x76, 0x61, 0x6e, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 
+	0x64, 0x2e, 0x0a,
 	0x09, 0x09, 0x61, 0x63, 0x63, 0x65, 0x6c, 0x65, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x6a, 0x6f, 0x79, 
 	0x73, 0x74, 0x69, 0x63, 0x6b, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x4f, 
 	0x6e, 0x6c, 0x79, 0x20, 0x72, 0x65, 0x6c, 0x65, 0x76, 0x61, 0x6e, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x41, 
@@ -909,6 +913,10 @@ const unsigned char boot_lua[] =
 	0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 
 	0x6d, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 
+	0x5f, 0x73, 0x65, 0x74, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x53, 0x61, 0x76, 0x65, 0x45, 0x78, 0x74, 
+	0x65, 0x72, 0x6e, 0x61, 0x6c, 0x28, 0x63, 0x2e, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x73, 0x74, 
+	0x6f, 0x72, 0x61, 0x67, 0x65, 0x29, 0x0a,
+	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 
 	0x73, 0x65, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x28, 0x63, 0x2e, 0x69, 0x64, 0x65, 0x6e, 
 	0x74, 0x69, 0x74, 0x79, 0x20, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 
 	0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x67, 0x65, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x28,