Allow merged games marked as 'release' to have their save dir directly in the appdata dir

This commit is contained in:
Bart van Strien
2011-06-15 13:09:32 +02:00
parent d613505a77
commit fc5cda36e2
6 changed files with 1918 additions and 1871 deletions
+21 -4
View File
@@ -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;
+10 -1
View File
@@ -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);
+8 -3
View File
@@ -182,6 +182,8 @@ function love.createhandlers()
end
local is_fused_game = false
-- This can't be overriden.
function love.boot()
@@ -198,6 +200,7 @@ function love.boot()
-- Is this one of those fancy "fused" games?
local can_has_game = pcall(love.filesystem.setSource, arg0)
is_fused_game = can_has_game
if not can_has_game and o.game.set and o.game.arg[1] then
local full_source = love.path.getfull(o.game.arg[1])
@@ -297,9 +300,11 @@ function love.init()
love.graphics.setCaption(c.title)
end
if love.filesystem and c.identity then love.filesystem.setIdentity(c.identity) end
if love.filesystem and love.filesystem.exists("main.lua") then require("main.lua") end
if love.filesystem then
love.filesystem.setRelease(c.release and is_fused_game)
if c.identity then love.filesystem.setIdentity(c.identity) end
if love.filesystem.exists("main.lua") then require("main.lua") end
end
if no_game_code then
error("No code to run\nYour game might be packaged incorrectly\nMake sure main.lua is at the top level of the zip")
+1869 -1863
View File
File diff suppressed because it is too large Load Diff