mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Allow merged games marked as 'release' to have their save dir directly in the appdata dir
This commit is contained in:
@@ -34,7 +34,7 @@ namespace filesystem
|
||||
namespace physfs
|
||||
{
|
||||
Filesystem::Filesystem()
|
||||
: open_count(0), buffer(0), isInited(false)
|
||||
: open_count(0), buffer(0), isInited(false), release(false), releaseSet(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -59,6 +59,14 @@ namespace physfs
|
||||
isInited = true;
|
||||
}
|
||||
|
||||
void Filesystem::setRelease(bool release)
|
||||
{
|
||||
if (releaseSet)
|
||||
return;
|
||||
this->release = release;
|
||||
releaseSet = true;
|
||||
}
|
||||
|
||||
bool Filesystem::setIdentity( const char * ident )
|
||||
{
|
||||
if(!isInited)
|
||||
@@ -68,11 +76,14 @@ namespace physfs
|
||||
save_identity = std::string(ident);
|
||||
|
||||
// Generate the relative path to the game save folder.
|
||||
save_path_relative = std::string(LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR) + save_identity;
|
||||
save_path_relative = std::string(LOVE_APPDATA_PREFIX LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR) + save_identity;
|
||||
|
||||
// Generate the full path to the game save folder.
|
||||
save_path_full = std::string(getAppdataDirectory()) + std::string(LOVE_PATH_SEPARATOR);
|
||||
save_path_full += save_path_relative;
|
||||
if (release)
|
||||
save_path_full += std::string(LOVE_APPDATA_PREFIX) + save_identity;
|
||||
else
|
||||
save_path_full += save_path_relative;
|
||||
|
||||
// We now have something like:
|
||||
// save_identity: game
|
||||
@@ -120,7 +131,13 @@ namespace physfs
|
||||
return false;
|
||||
|
||||
// Create the save folder. (We're now "at" %APPDATA%).
|
||||
if(!mkdir(save_path_relative.c_str()))
|
||||
bool success = false;
|
||||
if (release)
|
||||
success = mkdir(save_identity.c_str());
|
||||
else
|
||||
success = mkdir(save_path_relative.c_str());
|
||||
|
||||
if(!success)
|
||||
{
|
||||
PHYSFS_setWriteDir(0); // Clear the write directory in case of error.
|
||||
return false;
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
// In Windows, we would like to use "LOVE" as the
|
||||
// application folder, but in Linux, we like .love.
|
||||
#define LOVE_APPDATA_PREFIX ""
|
||||
#ifdef LOVE_WINDOWS
|
||||
# define LOVE_APPDATA_FOLDER "LOVE"
|
||||
# define LOVE_PATH_SEPARATOR "/"
|
||||
@@ -56,7 +57,8 @@
|
||||
# elif defined(LOVE_LINUX)
|
||||
# define LOVE_APPDATA_FOLDER "love"
|
||||
# else
|
||||
# define LOVE_APPDATA_FOLDER ".love"
|
||||
# define LOVE_APPDATA_PREFIX "."
|
||||
# define LOVE_APPDATA_FOLDER "love"
|
||||
# endif
|
||||
# define LOVE_PATH_SEPARATOR "/"
|
||||
# define LOVE_MAX_PATH MAXPATHLEN
|
||||
@@ -99,6 +101,11 @@ namespace physfs
|
||||
// Workaround for machines without PhysFS 2.0
|
||||
bool isInited;
|
||||
|
||||
// Allow saving outside of the LOVE_APPDATA_FOLDER
|
||||
// for release 'builds'
|
||||
bool release;
|
||||
bool releaseSet;
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
@@ -111,6 +118,8 @@ namespace physfs
|
||||
|
||||
void init(const char * arg0);
|
||||
|
||||
void setRelease(bool release);
|
||||
|
||||
/**
|
||||
* This sets up the save directory. If the
|
||||
* it is already set up, nothing happens.
|
||||
|
||||
@@ -52,6 +52,14 @@ namespace physfs
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_setRelease(lua_State * L)
|
||||
{
|
||||
// no error checking needed, everything, even nothing
|
||||
// can be converted to a boolean
|
||||
instance->setRelease(lua_toboolean(L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_setIdentity(lua_State * L)
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
@@ -290,6 +298,7 @@ namespace physfs
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "init", w_init },
|
||||
{ "setRelease", w_setRelease },
|
||||
{ "setIdentity", w_setIdentity },
|
||||
{ "setSource", w_setSource },
|
||||
{ "newFile", w_newFile },
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace physfs
|
||||
{
|
||||
bool hack_setupWriteDirectory();
|
||||
int w_init(lua_State * L);
|
||||
int w_setRelease(lua_State * L);
|
||||
int w_setIdentity(lua_State * L);
|
||||
int w_setSource(lua_State * L);
|
||||
int w_newFile(lua_State * L);
|
||||
|
||||
Reference in New Issue
Block a user