Changed the SearchOrder argument of love.filesystem.setIdentity and love.filesystem.mount to a boolean (append) instead of an enum

This commit is contained in:
Alex Szpakowski
2013-10-30 17:05:46 -03:00
parent 95e1861f35
commit 8cc5364d15
5 changed files with 17 additions and 65 deletions
+4 -26
View File
@@ -96,7 +96,7 @@ bool Filesystem::isFused() const
return fused;
}
bool Filesystem::setIdentity(const char *ident, SearchOrder searchorder)
bool Filesystem::setIdentity(const char *ident, bool appendToPath)
{
if (!initialized)
return false;
@@ -126,11 +126,9 @@ bool Filesystem::setIdentity(const char *ident, SearchOrder searchorder)
if (!old_save_path.empty())
PHYSFS_removeFromSearchPath(old_save_path.c_str());
bool append = (searchorder == SEARCH_ORDER_LAST);
// Try to add the save directory to the search path.
// (No error on fail, it means that the path doesn't exist).
PHYSFS_addToSearchPath(save_path_full.c_str(), append);
PHYSFS_addToSearchPath(save_path_full.c_str(), appendToPath);
return true;
}
@@ -200,7 +198,7 @@ bool Filesystem::setupWriteDirectory()
return true;
}
bool Filesystem::mount(const char *archive, const char *mountpoint, SearchOrder searchorder)
bool Filesystem::mount(const char *archive, const char *mountpoint, bool appendToPath)
{
if (!initialized || !archive)
return false;
@@ -238,9 +236,7 @@ bool Filesystem::mount(const char *archive, const char *mountpoint, SearchOrder
if (realPath.length() == 0)
return false;
bool append = (searchorder == SEARCH_ORDER_LAST);
return PHYSFS_mount(realPath.c_str(), mountpoint, append);
return PHYSFS_mount(realPath.c_str(), mountpoint, appendToPath);
}
bool Filesystem::unmount(const char *archive)
@@ -608,24 +604,6 @@ int64 Filesystem::getSize(const char *filename) const
return size;
}
bool Filesystem::getConstant(const char *in, Filesystem::SearchOrder &out)
{
return orders.find(in, out);
}
bool Filesystem::getConstant(Filesystem::SearchOrder in, const char *&out)
{
return orders.find(in, out);
}
StringMap<Filesystem::SearchOrder, Filesystem::SEARCH_ORDER_MAX_ENUM>::Entry Filesystem::orderEntries[] =
{
{"first", Filesystem::SEARCH_ORDER_FIRST},
{"last", Filesystem::SEARCH_ORDER_LAST},
};
StringMap<Filesystem::SearchOrder, Filesystem::SEARCH_ORDER_MAX_ENUM> Filesystem::orders(Filesystem::orderEntries, sizeof(Filesystem::orderEntries));
} // physfs
} // filesystem
} // love
+3 -19
View File
@@ -31,7 +31,6 @@
#include "common/Module.h"
#include "common/config.h"
#include "common/int.h"
#include "common/StringMap.h"
#include "filesystem/FileData.h"
#include "File.h"
@@ -77,17 +76,8 @@ class Filesystem : public Module
{
public:
// love.filesystem.setIdentity("foo", "last")
enum SearchOrder
{
SEARCH_ORDER_FIRST,
SEARCH_ORDER_LAST,
SEARCH_ORDER_MAX_ENUM
};
Filesystem();
~Filesystem();
virtual ~Filesystem();
const char *getName() const;
@@ -108,7 +98,7 @@ public:
* @param ident The name of the game. Will be used to
* to create the folder in the LOVE data folder.
**/
bool setIdentity(const char *ident, SearchOrder searchorder = SEARCH_ORDER_FIRST);
bool setIdentity(const char *ident, bool appendToPath = false);
const char *getIdentity() const;
/**
@@ -124,7 +114,7 @@ public:
**/
const char *getSource() const;
bool mount(const char *archive, const char *mountpoint, SearchOrder searchorder = SEARCH_ORDER_FIRST);
bool mount(const char *archive, const char *mountpoint, bool appendToPath = false);
bool unmount(const char *archive);
/**
@@ -288,9 +278,6 @@ public:
**/
static int lines_i(lua_State *L);
static bool getConstant(const char *in, SearchOrder &out);
static bool getConstant(SearchOrder in, const char *&out);
private:
// Contains the current working directory (UTF8).
@@ -319,9 +306,6 @@ private:
bool fused;
bool fusedSet;
static StringMap<SearchOrder, SEARCH_ORDER_MAX_ENUM>::Entry orderEntries[];
static StringMap<SearchOrder, SEARCH_ORDER_MAX_ENUM> orders;
}; // Filesystem
} // physfs
@@ -64,14 +64,9 @@ int w_isFused(lua_State *L)
int w_setIdentity(lua_State *L)
{
const char *arg = luaL_checkstring(L, 1);
bool append = luax_optboolean(L, 2, false);
Filesystem::SearchOrder order = Filesystem::SEARCH_ORDER_FIRST;
const char *ostr = lua_isnoneornil(L, 2) ? 0 : lua_tostring(L, 2);
if (ostr && !Filesystem::getConstant(ostr, order))
return luaL_error(L, "Invalid filesystem search order: %s", ostr);
if (!instance->setIdentity(arg, order))
if (!instance->setIdentity(arg, append))
return luaL_error(L, "Could not set write directory.");
return 0;
@@ -103,14 +98,9 @@ int w_mount(lua_State *L)
{
const char *archive = luaL_checkstring(L, 1);
const char *mountpoint = luaL_checkstring(L, 2);
bool append = luax_optboolean(L, 3, false);
Filesystem::SearchOrder order = Filesystem::SEARCH_ORDER_FIRST;
const char *ostr = lua_isnoneornil(L, 3) ? 0 : lua_tostring(L, 3);
if (ostr && !Filesystem::getConstant(ostr, order))
return luaL_error(L, "Invalid filesystem search order: %s", ostr);
luax_pushboolean(L, instance->mount(archive, mountpoint, order));
luax_pushboolean(L, instance->mount(archive, mountpoint, append));
return 1;
}