Browse Source

made a method for setting external save location on android

BobbyJones 9 years ago
parent
commit
3aa51763e2

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

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

+ 19 - 1
src/modules/filesystem/Filesystem.h

@@ -79,12 +79,26 @@ public:
 	 **/
 	 **/
 	virtual bool setupWriteDirectory() = 0;
 	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.
 	 * Sets the name of the save folder.
 	 * @param ident The name of the game. Will be used to
 	 * @param ident The name of the game. Will be used to
 	 * to create the folder in the LOVE data folder.
 	 * to create the folder in the LOVE data folder.
 	 **/
 	 **/
-	virtual bool setIdentity(const char *ident, bool appendToPath = false, bool internalStorage = false) = 0;
+	virtual bool setIdentity(const char *ident, bool appendToPath = false) = 0;
 	virtual const char *getIdentity() const = 0;
 	virtual const char *getIdentity() const = 0;
 
 
 	/**
 	/**
@@ -263,6 +277,10 @@ public:
 	 **/
 	 **/
 	virtual std::string getExecutablePath() const;
 	virtual std::string getExecutablePath() const;
 
 
+private:
+
+	//should we save external or internal for Android
+	bool useExternal;
 }; // Filesystem
 }; // Filesystem
 
 
 } // filesystem
 } // filesystem

+ 4 - 4
src/modules/filesystem/physfs/Filesystem.cpp

@@ -144,7 +144,7 @@ bool Filesystem::isFused() const
 	return fused;
 	return fused;
 }
 }
 
 
-bool Filesystem::setIdentity(const char *ident, bool appendToPath, bool internalStorage) 
+bool Filesystem::setIdentity(const char *ident, bool appendToPath) 
 {
 {
 	if (!PHYSFS_isInit())
 	if (!PHYSFS_isInit())
 		return false;
 		return false;
@@ -171,10 +171,10 @@ bool Filesystem::setIdentity(const char *ident, bool appendToPath, bool internal
 		save_identity = "unnamed";
 		save_identity = "unnamed";
 
 
 	std::string storage_path;
 	std::string storage_path;
-	if (internalStorage)
-		storage_path = SDL_AndroidGetInternalStoragePath();
-	else
+	if (isAndroidSaveExternal())
 		storage_path = SDL_AndroidGetExternalStoragePath();
 		storage_path = SDL_AndroidGetExternalStoragePath();
+	else
+		storage_path = SDL_AndroidGetInternalStoragePath();
 
 
 	std::string save_directory = storage_path + "/save";
 	std::string save_directory = storage_path + "/save";
 
 

+ 1 - 1
src/modules/filesystem/physfs/Filesystem.h

@@ -52,7 +52,7 @@ public:
 
 
 	bool setupWriteDirectory();
 	bool setupWriteDirectory();
 
 
-	bool setIdentity(const char *ident, bool appendToPath = false, bool internalStorage = false);
+	bool setIdentity(const char *ident, bool appendToPath = false);
 	const char *getIdentity() const;
 	const char *getIdentity() const;
 
 
 	bool setSource(const char *source);
 	bool setSource(const char *source);

+ 16 - 3
src/modules/filesystem/wrap_Filesystem.cpp

@@ -69,14 +69,25 @@ int w_isFused(lua_State *L)
 	return 1;
 	return 1;
 }
 }
 
 
+int w_setAndroidSaveExternal(lua_State *L)
+{
+	bool useExternal = luax_optboolean(L, 1, false);
+	instance()->setAndroidSaveExternal(useExternal);
+	return 0;
+}
+
+int w_isAndroidSaveExternal(lua_State *L)
+{
+	luax_pushboolean(L, instance()->isAndroidSaveExternal());
+	return 1;
+}
+
 int w_setIdentity(lua_State *L)
 int w_setIdentity(lua_State *L)
 {
 {
 	const char *arg = luaL_checkstring(L, 1);
 	const char *arg = luaL_checkstring(L, 1);
 	bool append = luax_optboolean(L, 2, false);
 	bool append = luax_optboolean(L, 2, false);
-	bool internalStorage = luax_optboolean(L, 3, false);
-
 
 
-	if (!instance()->setIdentity(arg, append, internalStorage))
+	if (!instance()->setIdentity(arg, append))
 		return luaL_error(L, "Could not set write directory.");
 		return luaL_error(L, "Could not set write directory.");
 
 
 	return 0;
 	return 0;
@@ -710,6 +721,8 @@ static const luaL_Reg functions[] =
 	{ "init", w_init },
 	{ "init", w_init },
 	{ "setFused", w_setFused },
 	{ "setFused", w_setFused },
 	{ "isFused", w_isFused },
 	{ "isFused", w_isFused },
+	{ "setAndroidSaveExternal", w_setAndroidSaveExternal },
+	{ "getAndroidSaveExternal", w_isAndroidSaveExternal },
 	{ "setIdentity", w_setIdentity },
 	{ "setIdentity", w_setIdentity },
 	{ "getIdentity", w_getIdentity },
 	{ "getIdentity", w_getIdentity },
 	{ "setSource", w_setSource },
 	{ "setSource", w_setSource },

+ 3 - 2
src/scripts/boot.lua

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

+ 9 - 6
src/scripts/boot.lua.h

@@ -684,10 +684,10 @@ const unsigned char boot_lua[] =
 	0x2c, 0x0a,
 	0x2c, 0x0a,
 	0x09, 0x09, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x3d, 
 	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,
 	0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x0a,
-	0x09, 0x09, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x53, 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, 0x75, 0x73, 0x65, 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, 
 	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, 
 	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, 
 	0x6e, 0x6c, 0x79, 0x20, 0x72, 0x65, 0x6c, 0x65, 0x76, 0x61, 0x6e, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x41, 
@@ -913,12 +913,15 @@ const unsigned char boot_lua[] =
 	0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 
 	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,
 	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, 
 	0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 
+	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, 0x75, 0x73, 0x65, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 
+	0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 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, 
 	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, 
 	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, 
 	0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x67, 0x65, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x28, 
 	0x29, 0x2c, 0x20, 0x63, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 
 	0x29, 0x2c, 0x20, 0x63, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 
-	0x79, 0x2c, 0x20, 0x63, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x53, 0x74, 0x6f, 0x72, 0x61, 
-	0x67, 0x65, 0x29, 0x0a,
+	0x79, 0x29, 0x0a,
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 
 	0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x79, 0x73, 0x74, 
 	0x65, 0x6d, 0x2e, 0x69, 0x73, 0x46, 0x69, 0x6c, 0x65, 0x28, 0x22, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x6c, 0x75, 
 	0x65, 0x6d, 0x2e, 0x69, 0x73, 0x46, 0x69, 0x6c, 0x65, 0x28, 0x22, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x6c, 0x75, 
 	0x61, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
 	0x61, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,