mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Remove PhysFS 2.x-specific code, it's no longer needed since we always have PhysFS 3.
This commit is contained in:
@@ -72,11 +72,7 @@ bool File::open(Mode mode)
|
|||||||
if (file != nullptr)
|
if (file != nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifdef LOVE_USE_PHYSFS_2_1
|
|
||||||
PHYSFS_getLastErrorCode();
|
PHYSFS_getLastErrorCode();
|
||||||
#else
|
|
||||||
PHYSFS_getLastError(); // Clear the error buffer.
|
|
||||||
#endif
|
|
||||||
PHYSFS_File *handle = nullptr;
|
PHYSFS_File *handle = nullptr;
|
||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
@@ -96,11 +92,7 @@ bool File::open(Mode mode)
|
|||||||
|
|
||||||
if (handle == nullptr)
|
if (handle == nullptr)
|
||||||
{
|
{
|
||||||
#ifdef LOVE_USE_PHYSFS_2_1
|
|
||||||
const char *err = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
|
const char *err = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
|
||||||
#else
|
|
||||||
const char *err = PHYSFS_getLastError();
|
|
||||||
#endif
|
|
||||||
if (err == nullptr)
|
if (err == nullptr)
|
||||||
err = "unknown error";
|
err = "unknown error";
|
||||||
throw love::Exception("Could not open file %s (%s)", filename.c_str(), err);
|
throw love::Exception("Could not open file %s (%s)", filename.c_str(), err);
|
||||||
@@ -163,15 +155,7 @@ int64 File::read(void *dst, int64 size)
|
|||||||
if (size < 0)
|
if (size < 0)
|
||||||
throw love::Exception("Invalid read size.");
|
throw love::Exception("Invalid read size.");
|
||||||
|
|
||||||
#ifdef LOVE_USE_PHYSFS_2_1
|
return PHYSFS_readBytes(file, dst, (PHYSFS_uint64) size);
|
||||||
int64 read = PHYSFS_readBytes(file, dst, (PHYSFS_uint64) size);
|
|
||||||
#else
|
|
||||||
// Sadly, we'll have to clamp to 32 bits here
|
|
||||||
size = (size > LOVE_UINT32_MAX) ? LOVE_UINT32_MAX : size;
|
|
||||||
int64 read = (int64)PHYSFS_read(file, dst, 1, (PHYSFS_uint32) size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return read;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::write(const void *data, int64 size)
|
bool File::write(const void *data, int64 size)
|
||||||
@@ -183,13 +167,7 @@ bool File::write(const void *data, int64 size)
|
|||||||
throw love::Exception("Invalid write size.");
|
throw love::Exception("Invalid write size.");
|
||||||
|
|
||||||
// Try to write.
|
// Try to write.
|
||||||
#ifdef LOVE_USE_PHYSFS_2_1
|
|
||||||
int64 written = PHYSFS_writeBytes(file, data, (PHYSFS_uint64) size);
|
int64 written = PHYSFS_writeBytes(file, data, (PHYSFS_uint64) size);
|
||||||
#else
|
|
||||||
// Another clamp, for the time being.
|
|
||||||
size = (size > LOVE_UINT32_MAX) ? LOVE_UINT32_MAX : size;
|
|
||||||
int64 written = (int64) PHYSFS_write(file, data, 1, (PHYSFS_uint32) size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Check that correct amount of data was written.
|
// Check that correct amount of data was written.
|
||||||
if (written != size)
|
if (written != size)
|
||||||
|
|||||||
@@ -31,10 +31,6 @@
|
|||||||
// STD
|
// STD
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#if PHYSFS_VER_MAJOR > 2 || (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1)
|
|
||||||
#define LOVE_USE_PHYSFS_2_1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
namespace filesystem
|
namespace filesystem
|
||||||
|
|||||||
@@ -120,16 +120,9 @@ const char *Filesystem::getName() const
|
|||||||
void Filesystem::init(const char *arg0)
|
void Filesystem::init(const char *arg0)
|
||||||
{
|
{
|
||||||
if (!PHYSFS_init(arg0))
|
if (!PHYSFS_init(arg0))
|
||||||
{
|
throw love::Exception("%s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
||||||
#ifdef LOVE_USE_PHYSFS_2_1
|
|
||||||
const char *err = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
|
|
||||||
#else
|
|
||||||
const char *err = PHYSFS_getLastError();
|
|
||||||
#endif
|
|
||||||
throw love::Exception("%s", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable symlinks by default. Also fixes an issue in PhysFS 2.1-alpha.
|
// Enable symlinks by default.
|
||||||
setSymlinksEnabled(true);
|
setSymlinksEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,13 +190,7 @@ bool Filesystem::setIdentity(const char *ident, bool appendToPath)
|
|||||||
// We don't want old read-only save paths to accumulate when we set a new
|
// We don't want old read-only save paths to accumulate when we set a new
|
||||||
// identity.
|
// identity.
|
||||||
if (!old_save_path.empty())
|
if (!old_save_path.empty())
|
||||||
{
|
|
||||||
#ifdef LOVE_USE_PHYSFS_2_1
|
|
||||||
PHYSFS_unmount(old_save_path.c_str());
|
PHYSFS_unmount(old_save_path.c_str());
|
||||||
#else
|
|
||||||
PHYSFS_removeFromSearchPath(old_save_path.c_str());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to add the save directory to the search path.
|
// Try to add the save directory to the search path.
|
||||||
// (No error on fail, it means that the path doesn't exist).
|
// (No error on fail, it means that the path doesn't exist).
|
||||||
@@ -448,11 +435,7 @@ bool Filesystem::unmount(const char *archive)
|
|||||||
if (!mountPoint)
|
if (!mountPoint)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifdef LOVE_USE_PHYSFS_2_1
|
|
||||||
return PHYSFS_unmount(realPath.c_str()) != 0;
|
return PHYSFS_unmount(realPath.c_str()) != 0;
|
||||||
#else
|
|
||||||
return PHYSFS_removeFromSearchPath(realPath.c_str()) != 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
love::filesystem::File *Filesystem::newFile(const char *filename) const
|
love::filesystem::File *Filesystem::newFile(const char *filename) const
|
||||||
@@ -564,7 +547,7 @@ std::string Filesystem::getRealDirectory(const char *filename) const
|
|||||||
const char *dir = PHYSFS_getRealDir(filename);
|
const char *dir = PHYSFS_getRealDir(filename);
|
||||||
|
|
||||||
if (dir == nullptr)
|
if (dir == nullptr)
|
||||||
throw love::Exception("File does not exist.");
|
throw love::Exception("File does not exist on disk.");
|
||||||
|
|
||||||
return std::string(dir);
|
return std::string(dir);
|
||||||
}
|
}
|
||||||
@@ -574,7 +557,6 @@ bool Filesystem::getInfo(const char *filepath, Info &info) const
|
|||||||
if (!PHYSFS_isInit())
|
if (!PHYSFS_isInit())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifdef LOVE_USE_PHYSFS_2_1
|
|
||||||
PHYSFS_Stat stat = {};
|
PHYSFS_Stat stat = {};
|
||||||
if (!PHYSFS_stat(filepath, &stat))
|
if (!PHYSFS_stat(filepath, &stat))
|
||||||
return false;
|
return false;
|
||||||
@@ -590,30 +572,6 @@ bool Filesystem::getInfo(const char *filepath, Info &info) const
|
|||||||
info.type = FILETYPE_SYMLINK;
|
info.type = FILETYPE_SYMLINK;
|
||||||
else
|
else
|
||||||
info.type = FILETYPE_OTHER;
|
info.type = FILETYPE_OTHER;
|
||||||
#else
|
|
||||||
if (!PHYSFS_exists(filepath))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File file(filepath);
|
|
||||||
info.size = file.getSize();
|
|
||||||
}
|
|
||||||
catch (love::Exception &)
|
|
||||||
{
|
|
||||||
info.size = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
info.modtime = (int64) PHYSFS_getLastModTime(filepath);
|
|
||||||
|
|
||||||
if (PHYSFS_isSymbolicLink(filepath))
|
|
||||||
info.type = FILETYPE_SYMLINK;
|
|
||||||
else if (PHYSFS_isDirectory(filepath))
|
|
||||||
info.type = FILETYPE_DIRECTORY;
|
|
||||||
else
|
|
||||||
info.type = FILETYPE_FILE;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -699,17 +657,6 @@ void Filesystem::setSymlinksEnabled(bool enable)
|
|||||||
if (!PHYSFS_isInit())
|
if (!PHYSFS_isInit())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!enable)
|
|
||||||
{
|
|
||||||
PHYSFS_Version version = {};
|
|
||||||
PHYSFS_getLinkedVersion(&version);
|
|
||||||
|
|
||||||
// FIXME: This is a workaround for a bug in PHYSFS_enumerateFiles in
|
|
||||||
// PhysFS 2.1.0-alpha.
|
|
||||||
if (version.major == 2 && version.minor == 1 && version.patch == 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PHYSFS_permitSymbolicLinks(enable ? 1 : 0);
|
PHYSFS_permitSymbolicLinks(enable ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user