Browse Source

Added a flag that changes android storage from internal to external.

BobbyJones 9 years ago
parent
commit
3c83fb8626

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

@@ -84,7 +84,7 @@ public:
 	 * @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) = 0;
+	virtual bool setIdentity(const char *ident, bool appendToPath = false, bool internalStorage = false) = 0;
 	virtual const char *getIdentity() const = 0;
 	virtual const char *getIdentity() const = 0;
 
 
 	/**
 	/**

+ 10 - 5
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 Filesystem::setIdentity(const char *ident, bool appendToPath, bool internalStorage) 
 {
 {
 	if (!PHYSFS_isInit())
 	if (!PHYSFS_isInit())
 		return false;
 		return false;
@@ -169,11 +169,16 @@ bool Filesystem::setIdentity(const char *ident, bool appendToPath)
 #ifdef LOVE_ANDROID
 #ifdef LOVE_ANDROID
 	if (save_identity == "")
 	if (save_identity == "")
 		save_identity = "unnamed";
 		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 (internalStorage)
+		storage_path = SDL_AndroidGetInternalStoragePath();
+	else
+		storage_path = SDL_AndroidGetExternalStoragePath();
+
+	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()) &&
 	if (!love::android::directoryExists(save_path_full.c_str()) &&
 			!love::android::mkdir(save_path_full.c_str()))
 			!love::android::mkdir(save_path_full.c_str()))

+ 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 setIdentity(const char *ident, bool appendToPath = false, bool internalStorage = false);
 	const char *getIdentity() const;
 	const char *getIdentity() const;
 
 
 	bool setSource(const char *source);
 	bool setSource(const char *source);

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

@@ -73,8 +73,10 @@ 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))
+
+	if (!instance()->setIdentity(arg, append, internalStorage))
 		return luaL_error(L, "Could not set write directory.");
 		return luaL_error(L, "Could not set write directory.");
 
 
 	return 0;
 	return 0;

+ 2 - 1
src/scripts/boot.lua

@@ -374,6 +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.
 		accelerometerjoystick = true, -- Only relevant for Android / iOS.
 		accelerometerjoystick = true, -- Only relevant for Android / iOS.
 		gammacorrect = false,
 		gammacorrect = false,
 	}
 	}
@@ -493,7 +494,7 @@ function love.init()
 	end
 	end
 
 
 	if love.filesystem then
 	if love.filesystem then
-		love.filesystem.setIdentity(c.identity or love.filesystem.getIdentity(), c.appendidentity)
+		love.filesystem.setIdentity(c.identity or love.filesystem.getIdentity(), c.appendidentity, c.internalStorage)
 		if love.filesystem.isFile("main.lua") then
 		if love.filesystem.isFile("main.lua") then
 			require("main")
 			require("main")
 		end
 		end