From 3aa51763e296d1df4c1c993a724e2cb5723d7636 Mon Sep 17 00:00:00 2001 From: BobbyJones Date: Sat, 2 Jan 2016 18:52:25 -0500 Subject: [PATCH] made a method for setting external save location on android --- src/modules/filesystem/Filesystem.cpp | 11 +++++++++++ src/modules/filesystem/Filesystem.h | 20 +++++++++++++++++++- src/modules/filesystem/physfs/Filesystem.cpp | 8 ++++---- src/modules/filesystem/physfs/Filesystem.h | 2 +- src/modules/filesystem/wrap_Filesystem.cpp | 19 ++++++++++++++++--- src/scripts/boot.lua | 5 +++-- src/scripts/boot.lua.h | 15 +++++++++------ 7 files changed, 63 insertions(+), 17 deletions(-) diff --git a/src/modules/filesystem/Filesystem.cpp b/src/modules/filesystem/Filesystem.cpp index b3a8b43c7..f62748638 100644 --- a/src/modules/filesystem/Filesystem.cpp +++ b/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 { #ifdef LOVE_WINDOWS diff --git a/src/modules/filesystem/Filesystem.h b/src/modules/filesystem/Filesystem.h index 837496f32..64bde25c9 100644 --- a/src/modules/filesystem/Filesystem.h +++ b/src/modules/filesystem/Filesystem.h @@ -79,12 +79,26 @@ 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 * 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; /** @@ -263,6 +277,10 @@ public: **/ virtual std::string getExecutablePath() const; +private: + + //should we save external or internal for Android + bool useExternal; }; // Filesystem } // filesystem diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index c9b68ed64..b1edf777a 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/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 internalStorage) +bool Filesystem::setIdentity(const char *ident, bool appendToPath) { if (!PHYSFS_isInit()) return false; @@ -171,10 +171,10 @@ bool Filesystem::setIdentity(const char *ident, bool appendToPath, bool internal save_identity = "unnamed"; std::string storage_path; - if (internalStorage) - storage_path = SDL_AndroidGetInternalStoragePath(); - else + if (isAndroidSaveExternal()) storage_path = SDL_AndroidGetExternalStoragePath(); + else + storage_path = SDL_AndroidGetInternalStoragePath(); std::string save_directory = storage_path + "/save"; diff --git a/src/modules/filesystem/physfs/Filesystem.h b/src/modules/filesystem/physfs/Filesystem.h index a5b369f28..fc6941e48 100644 --- a/src/modules/filesystem/physfs/Filesystem.h +++ b/src/modules/filesystem/physfs/Filesystem.h @@ -52,7 +52,7 @@ public: 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; bool setSource(const char *source); diff --git a/src/modules/filesystem/wrap_Filesystem.cpp b/src/modules/filesystem/wrap_Filesystem.cpp index 175c0fc3b..63537f593 100644 --- a/src/modules/filesystem/wrap_Filesystem.cpp +++ b/src/modules/filesystem/wrap_Filesystem.cpp @@ -69,14 +69,25 @@ 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_isAndroidSaveExternal(lua_State *L) +{ + luax_pushboolean(L, instance()->isAndroidSaveExternal()); + return 1; +} + int w_setIdentity(lua_State *L) { const char *arg = luaL_checkstring(L, 1); 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 0; @@ -710,6 +721,8 @@ static const luaL_Reg functions[] = { "init", w_init }, { "setFused", w_setFused }, { "isFused", w_isFused }, + { "setAndroidSaveExternal", w_setAndroidSaveExternal }, + { "getAndroidSaveExternal", w_isAndroidSaveExternal }, { "setIdentity", w_setIdentity }, { "getIdentity", w_getIdentity }, { "setSource", w_setSource }, diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index f9a4cc5a1..6598e8530 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -374,7 +374,7 @@ function love.init() console = false, -- Only relevant for windows. identity = false, appendidentity = false, - internalStorage = false, -- Only relevant for Android. + useexternalstorage = false, -- Only relevant for Android. accelerometerjoystick = true, -- Only relevant for Android / iOS. gammacorrect = false, } @@ -494,7 +494,8 @@ function love.init() end 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 require("main") end diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index 621bdf420..e2020df06 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -684,10 +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, 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, 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, @@ -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, 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, + 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, 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, 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, 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,