mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
made a method for setting external save location on android
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user