mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Clean up some hacky love.filesystem code.
--HG-- branch : minor
This commit is contained in:
@@ -32,11 +32,15 @@ namespace love
|
|||||||
namespace filesystem
|
namespace filesystem
|
||||||
{
|
{
|
||||||
|
|
||||||
extern bool hack_setupWriteDirectory();
|
|
||||||
|
|
||||||
namespace physfs
|
namespace physfs
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static bool setupWriteDirectory()
|
||||||
|
{
|
||||||
|
auto fs = Module::getInstance<love::filesystem::Filesystem>(Module::M_FILESYSTEM);
|
||||||
|
return fs != nullptr && fs->setupWriteDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
File::File(const std::string &filename)
|
File::File(const std::string &filename)
|
||||||
: filename(filename)
|
: filename(filename)
|
||||||
, file(nullptr)
|
, file(nullptr)
|
||||||
@@ -65,7 +69,7 @@ bool File::open(Mode mode)
|
|||||||
throw love::Exception("Could not open file %s. Does not exist.", filename.c_str());
|
throw love::Exception("Could not open file %s. Does not exist.", filename.c_str());
|
||||||
|
|
||||||
// Check whether the write directory is set.
|
// Check whether the write directory is set.
|
||||||
if ((mode == MODE_APPEND || mode == MODE_WRITE) && (PHYSFS_getWriteDir() == nullptr) && !hack_setupWriteDirectory())
|
if ((mode == MODE_APPEND || mode == MODE_WRITE) && (PHYSFS_getWriteDir() == nullptr) && !setupWriteDirectory())
|
||||||
throw love::Exception("Could not set write directory.");
|
throw love::Exception("Could not set write directory.");
|
||||||
|
|
||||||
// File already open?
|
// File already open?
|
||||||
|
|||||||
@@ -45,13 +45,6 @@ namespace filesystem
|
|||||||
|
|
||||||
#define instance() (Module::getInstance<Filesystem>(Module::M_FILESYSTEM))
|
#define instance() (Module::getInstance<Filesystem>(Module::M_FILESYSTEM))
|
||||||
|
|
||||||
bool hack_setupWriteDirectory()
|
|
||||||
{
|
|
||||||
if (instance() != 0)
|
|
||||||
return instance()->setupWriteDirectory();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int w_init(lua_State *L)
|
int w_init(lua_State *L)
|
||||||
{
|
{
|
||||||
const char *arg0 = luaL_checkstring(L, 1);
|
const char *arg0 = luaL_checkstring(L, 1);
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ File *luax_getfile(lua_State *L, int idx);
|
|||||||
Data *luax_getdata(lua_State *L, int idx);
|
Data *luax_getdata(lua_State *L, int idx);
|
||||||
bool luax_cangetdata(lua_State *L, int idx);
|
bool luax_cangetdata(lua_State *L, int idx);
|
||||||
|
|
||||||
bool hack_setupWriteDirectory();
|
|
||||||
int loader(lua_State *L);
|
int loader(lua_State *L);
|
||||||
int extloader(lua_State *L);
|
int extloader(lua_State *L);
|
||||||
extern "C" LOVE_EXPORT int luaopen_love_filesystem(lua_State *L);
|
extern "C" LOVE_EXPORT int luaopen_love_filesystem(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user