Fixed most PhysFS deprecated call warnings on iOS/Android.

This commit is contained in:
Alex Szpakowski
2015-12-09 17:22:46 -04:00
parent 5c3ee15ded
commit 7ee02e8d37
3 changed files with 51 additions and 2 deletions
+8
View File
@@ -154,7 +154,11 @@ int64 File::read(void *dst, int64 size)
if (size < 0)
throw love::Exception("Invalid read size.");
#ifdef LOVE_USE_PHYSFS_2_1
int64 read = PHYSFS_readBytes(file, dst, (PHYSFS_uint64) size);
#else
int64 read = (int64)PHYSFS_read(file, dst, 1, (PHYSFS_uint32) size);
#endif
return read;
}
@@ -171,7 +175,11 @@ bool File::write(const void *data, int64 size)
throw love::Exception("Invalid write size.");
// Try to write.
#ifdef LOVE_USE_PHYSFS_2_1
int64 written = PHYSFS_writeBytes(file, data, (PHYSFS_uint64) size);
#else
int64 written = (int64) PHYSFS_write(file, data, 1, (PHYSFS_uint32) size);
#endif
// Check that correct amount of data was written.
if (written != size)
+7
View File
@@ -22,6 +22,7 @@
#define LOVE_FILESYSTEM_PHYSFS_FILE_H
// LOVE
#include "common/config.h"
#include "filesystem/File.h"
// PhysFS
@@ -34,6 +35,12 @@
// STD
#include <string>
// These platforms always use PhysFS 2.1.
#if (defined(LOVE_IOS) || defined(LOVE_ANDROID)) \
&& (PHYSFS_VER_MAJOR == 2 && PHYSFS_VER_MINOR >= 1)
#define LOVE_USE_PHYSFS_2_1
#endif
namespace love
{
namespace filesystem
+36 -2
View File
@@ -188,7 +188,13 @@ bool Filesystem::setIdentity(const char *ident, bool appendToPath)
// We don't want old read-only save paths to accumulate when we set a new
// identity.
if (!old_save_path.empty())
{
#ifdef LOVE_USE_PHYSFS_2_1
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.
// (No error on fail, it means that the path doesn't exist).
@@ -433,7 +439,11 @@ bool Filesystem::unmount(const char *archive)
if (!mountPoint)
return false;
#ifdef LOVE_USE_PHYSFS_2_1
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
@@ -571,12 +581,20 @@ std::string Filesystem::getRealDirectory(const char *filename) const
bool Filesystem::isDirectory(const char *dir) const
{
#ifdef LOVE_USE_PHYSFS_2_1
PHYSFS_Stat stat = {};
if (PHYSFS_stat(dir, &stat))
return stat.filetype == PHYSFS_FILETYPE_DIRECTORY;
else
return false;
#else
return PHYSFS_isDirectory(dir) != 0;
#endif
}
bool Filesystem::isFile(const char *file) const
{
return PHYSFS_exists(file) && !PHYSFS_isDirectory(file);
return PHYSFS_exists(file) && !isDirectory(file);
}
bool Filesystem::createDirectory(const char *dir)
@@ -643,7 +661,15 @@ void Filesystem::getDirectoryItems(const char *dir, std::vector<std::string> &it
int64 Filesystem::getLastModified(const char *filename) const
{
PHYSFS_sint64 time = PHYSFS_getLastModTime(filename);
PHYSFS_sint64 time = -1;
#ifdef LOVE_USE_PHYSFS_2_1
PHYSFS_Stat stat = {};
if (PHYSFS_stat(filename, &stat))
time = stat.modtime;
#else
time = PHYSFS_getLastModTime(filename);
#endif
if (time == -1)
throw love::Exception("Could not determine file modification date.");
@@ -681,7 +707,15 @@ bool Filesystem::areSymlinksEnabled() const
bool Filesystem::isSymlink(const char *filename) const
{
#ifdef LOVE_USE_PHYSFS_2_1
PHYSFS_Stat stat = {};
if (PHYSFS_stat(filename, &stat))
return stat.filetype == PHYSFS_FILETYPE_SYMLINK;
else
return false;
#else
return PHYSFS_isSymbolicLink(filename) != 0;
#endif
}
std::vector<std::string> &Filesystem::getRequirePath()