summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/files.cpp14
-rw-r--r--src/utils/translation/poparser.cpp2
-rw-r--r--src/utils/virtfs.cpp39
-rw-r--r--src/utils/virtfs.h16
-rw-r--r--src/utils/virtfsrwops.cpp12
-rw-r--r--src/utils/virtfsrwops.h10
-rw-r--r--src/utils/virtfstools.cpp8
7 files changed, 53 insertions, 48 deletions
diff --git a/src/utils/files.cpp b/src/utils/files.cpp
index 57964f2f3..b2cba4c52 100644
--- a/src/utils/files.cpp
+++ b/src/utils/files.cpp
@@ -53,10 +53,10 @@ void Files::extractLocale()
FOR_EACH (StringVectCIter, i, rootDirs->names)
{
const std::string dir = std::string("locale/").append(*i);
- if (VirtFs::isDirectory(dir.c_str()))
+ if (VirtFs::isDirectory(dir))
{
const std::string moFile = dir + "/LC_MESSAGES/manaplus.mo";
- if (VirtFs::exists((moFile).c_str()))
+ if (VirtFs::exists((moFile)))
{
const std::string localFile = localDir + moFile;
const std::string localDir2 = localDir + dir + "/LC_MESSAGES";
@@ -114,7 +114,7 @@ void Files::copyPhysFsDir(const std::string &restrict inDir,
{
const std::string file = std::string(inDir).append("/").append(*i);
const std::string outDir2 = std::string(outDir).append("/").append(*i);
- if (VirtFs::isDirectory(file.c_str()))
+ if (VirtFs::isDirectory(file))
copyPhysFsDir(file, outDir2);
else
copyPhysFsFile(file, outDir2);
@@ -214,7 +214,7 @@ void Files::getFiles(const std::string &path, StringVect &list)
VirtList *const fonts = VirtFs::enumerateFiles(path);
FOR_EACH (StringVectCIter, i, fonts->names)
{
- if (!VirtFs::isDirectory((path + *i).c_str()))
+ if (!VirtFs::isDirectory(path + *i))
list.push_back(*i);
}
VirtFs::freeList(fonts);
@@ -225,7 +225,7 @@ void Files::getDirs(const std::string &path, StringVect &list)
VirtList *const fonts = VirtFs::enumerateFiles(path);
FOR_EACH (StringVectCIter, i, fonts->names)
{
- if (VirtFs::isDirectory((path + *i).c_str()))
+ if (VirtFs::isDirectory(path + *i))
list.push_back(*i);
}
VirtFs::freeList(fonts);
@@ -236,7 +236,7 @@ void Files::getFilesWithDir(const std::string &path, StringVect &list)
VirtList *const fonts = VirtFs::enumerateFiles(path);
FOR_EACH (StringVectCIter, i, fonts->names)
{
- if (!VirtFs::isDirectory((path + *i).c_str()))
+ if (!VirtFs::isDirectory(path + *i))
list.push_back(path + *i);
}
VirtFs::freeList(fonts);
@@ -256,7 +256,7 @@ bool Files::existsLocal(const std::string &path)
std::string Files::getPath(const std::string &file)
{
// get the real path to the file
- const char *const tmp = VirtFs::getRealDir(file.c_str());
+ const char *const tmp = VirtFs::getRealDir(file);
std::string path;
// if the file is not in the search path, then its nullptr
diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp
index 7aaca2349..1bd051b48 100644
--- a/src/utils/translation/poparser.cpp
+++ b/src/utils/translation/poparser.cpp
@@ -262,7 +262,7 @@ PoDict *PoParser::getEmptyDict()
bool PoParser::checkLang(const std::string &lang)
{
// check is po file exists
- return VirtFs::exists(getFileName(lang).c_str());
+ return VirtFs::exists(getFileName(lang));
}
std::string PoParser::getFileName(const std::string &lang)
diff --git a/src/utils/virtfs.cpp b/src/utils/virtfs.cpp
index 6b87f87e9..5fcb568d3 100644
--- a/src/utils/virtfs.cpp
+++ b/src/utils/virtfs.cpp
@@ -39,18 +39,18 @@ const char *dirSeparator = nullptr;
namespace VirtFs
{
#if defined(__native_client__)
- void init(const char *restrict const name A_UNUSED)
+ void init(const std::string &restrict name A_UNUSED)
{
if (!PHYSFS_init("/fakebinary"))
#elif defined(ANDROID)
- void init(const char *restrict const name A_UNUSED)
+ void init(const std::string &restrict name A_UNUSED)
{
if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str()))
#else // defined(__native_client__)
- void init(const char *restrict const name)
+ void init(const std::string &restrict name)
{
- if (!PHYSFS_init(name))
+ if (!PHYSFS_init(name.c_str()))
#endif // defined(__native_client__)
{
std::cout << "Error while initializing PhysFS: "
@@ -81,9 +81,9 @@ namespace VirtFs
return PHYSFS_getUserDir();
}
- bool exists(const char *restrict const fname)
+ bool exists(const std::string &restrict name)
{
- return PHYSFS_exists(fname);
+ return PHYSFS_exists(name.c_str());
}
VirtList *enumerateFiles(const std::string &restrict dir)
@@ -101,9 +101,9 @@ namespace VirtFs
return files;
}
- bool isDirectory(const char *restrict const fname)
+ bool isDirectory(const std::string &restrict name)
{
- return PHYSFS_isDirectory(fname);
+ return PHYSFS_isDirectory(name.c_str());
}
void freeList(VirtList *restrict const handle)
@@ -111,9 +111,10 @@ namespace VirtFs
delete handle;
}
- VirtFile *openRead(const char *restrict const filename)
+ VirtFile *openRead(const std::string &restrict filename)
{
- PHYSFS_file *restrict const handle = PHYSFS_openRead(filename);
+ PHYSFS_file *restrict const handle = PHYSFS_openRead(
+ filename.c_str());
if (!handle)
return nullptr;
VirtFile *restrict const file = new VirtFile;
@@ -121,9 +122,10 @@ namespace VirtFs
return file;
}
- VirtFile *openWrite(const char *restrict const filename)
+ VirtFile *openWrite(const std::string &restrict filename)
{
- PHYSFS_file *restrict const handle = PHYSFS_openWrite(filename);
+ PHYSFS_file *restrict const handle = PHYSFS_openWrite(
+ filename.c_str());
if (!handle)
return nullptr;
VirtFile *restrict const file = new VirtFile;
@@ -131,9 +133,10 @@ namespace VirtFs
return file;
}
- VirtFile *openAppend(const char *restrict const filename)
+ VirtFile *openAppend(const std::string &restrict filename)
{
- PHYSFS_file *restrict const handle = PHYSFS_openAppend(filename);
+ PHYSFS_file *restrict const handle = PHYSFS_openAppend(
+ filename.c_str());
if (!handle)
return nullptr;
VirtFile *restrict const file = new VirtFile;
@@ -194,14 +197,14 @@ namespace VirtFs
return PHYSFS_removeFromSearchPath(oldDir.c_str());
}
- const char *getRealDir(const char *restrict const filename)
+ const char *getRealDir(const std::string &restrict filename)
{
- return PHYSFS_getRealDir(filename);
+ return PHYSFS_getRealDir(filename.c_str());
}
- bool mkdir(const char *restrict const dirname)
+ bool mkdir(const std::string &restrict dirname)
{
- return PHYSFS_mkdir(dirname);
+ return PHYSFS_mkdir(dirname.c_str());
}
bool deinit()
diff --git a/src/utils/virtfs.h b/src/utils/virtfs.h
index 5888d52eb..4f4471ad0 100644
--- a/src/utils/virtfs.h
+++ b/src/utils/virtfs.h
@@ -32,18 +32,18 @@ struct VirtList;
namespace VirtFs
{
- void init(const char *restrict const name);
+ void init(const std::string &restrict name);
void updateDirSeparator();
const char *getDirSeparator();
const char *getBaseDir();
const char *getUserDir();
- bool exists(const char *restrict const fname);
+ bool exists(const std::string &restrict name);
VirtList *enumerateFiles(const std::string &restrict dir) RETURNS_NONNULL;
- bool isDirectory(const char *restrict const fname);
+ bool isDirectory(const std::string &restrict name);
void freeList(VirtList *restrict const handle);
- VirtFile *openRead(const char *restrict const filename);
- VirtFile *openWrite(const char *restrict const filename);
- VirtFile *openAppend(const char *restrict const filename);
+ VirtFile *openRead(const std::string &restrict filename);
+ VirtFile *openWrite(const std::string &restrict filename);
+ VirtFile *openAppend(const std::string &restrict filename);
bool setWriteDir(const std::string &restrict newDir);
bool addDirToSearchPath(const std::string &restrict newDir,
const Append append);
@@ -51,8 +51,8 @@ namespace VirtFs
bool addZipToSearchPath(const std::string &restrict newDir,
const Append append);
bool removeZipFromSearchPath(const std::string &restrict oldDir);
- const char *getRealDir(const char *restrict const filename);
- bool mkdir(const char *restrict const dirName);
+ const char *getRealDir(const std::string &restrict filename);
+ bool mkdir(const std::string &restrict dirName);
bool deinit();
void permitLinks(const bool val);
const char *getLastError();
diff --git a/src/utils/virtfsrwops.cpp b/src/utils/virtfsrwops.cpp
index ade942385..837704465 100644
--- a/src/utils/virtfsrwops.cpp
+++ b/src/utils/virtfsrwops.cpp
@@ -343,9 +343,9 @@ SDL_RWops *VirtFs::MakeRWops(VirtFile *const handle)
} /* RWopsmakeRWops */
#ifdef __APPLE__
-static bool checkFilePath(const char *const fname)
+static bool checkFilePath(const std::string &restrict fname)
{
- if (!fname || !*fname)
+ if (fname.empty())
return false;
if (!VirtFs::exists(fname) || VirtFs::isDirectory(fname))
return false;
@@ -355,11 +355,11 @@ static bool checkFilePath(const char *const fname)
#ifdef DEBUG_VIRTFS
#undef RWopsOpenRead
-SDL_RWops *VirtFs::RWopsOpenRead(const char *const fname,
+SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname,
const char *restrict const file,
const unsigned line)
#else // DEBUG_VIRTFS
-SDL_RWops *VirtFs::RWopsOpenRead(const char *const fname)
+SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname)
#endif // DEBUG_VIRTFS
{
BLOCK_START("RWopsopenRead")
@@ -399,7 +399,7 @@ SDL_RWops *VirtFs::RWopsOpenRead(const char *const fname)
#endif // USE_PROFILER
} /* RWopsopenRead */
-SDL_RWops *VirtFs::RWopsOpenWrite(const char *const fname)
+SDL_RWops *VirtFs::RWopsOpenWrite(const std::string &restrict fname)
{
#ifdef __APPLE__
if (!checkFilePath(fname))
@@ -409,7 +409,7 @@ SDL_RWops *VirtFs::RWopsOpenWrite(const char *const fname)
return create_rwops(VirtFs::openWrite(fname));
} /* RWopsopenWrite */
-SDL_RWops *VirtFs::RWopsOpenAppend(const char *const fname)
+SDL_RWops *VirtFs::RWopsOpenAppend(const std::string &restrict fname)
{
#ifdef __APPLE__
if (!checkFilePath(fname))
diff --git a/src/utils/virtfsrwops.h b/src/utils/virtfsrwops.h
index 5a8871377..82bb740de 100644
--- a/src/utils/virtfsrwops.h
+++ b/src/utils/virtfsrwops.h
@@ -47,6 +47,7 @@
#include "localconsts.h"
+#include <string>
#include <SDL_rwops.h>
struct VirtFile;
@@ -54,16 +55,17 @@ struct VirtFile;
namespace VirtFs
{
#ifdef DEBUG_VIRTFS
- SDL_RWops *RWopsOpenRead(const char *const fname,
+ SDL_RWops *RWopsOpenRead(const std::string &restrict fname,
const char *restrict const file,
const unsigned line);
void reportLeaks();
#else // DEBUG_VIRTFS
- SDL_RWops *RWopsOpenRead(const char *const fname);
+ SDL_RWops *RWopsOpenRead(const std::string &restrict fname);
#endif // DEBUG_VIRTFS
- SDL_RWops *RWopsOpenWrite(const char *const fname) A_WARN_UNUSED;
- SDL_RWops *RWopsOpenAppend(const char *const fname) A_WARN_UNUSED;
+ SDL_RWops *RWopsOpenWrite(const std::string &restrict fname) A_WARN_UNUSED;
+ SDL_RWops *RWopsOpenAppend(const std::string &restrict fname)
+ A_WARN_UNUSED;
SDL_RWops *MakeRWops(VirtFile *const handle) A_WARN_UNUSED;
#ifdef DUMP_LEAKED_RESOURCES
void reportRWops();
diff --git a/src/utils/virtfstools.cpp b/src/utils/virtfstools.cpp
index d804dfd41..0b87670bf 100644
--- a/src/utils/virtfstools.cpp
+++ b/src/utils/virtfstools.cpp
@@ -33,7 +33,7 @@ namespace VirtFs
int &restrict fileSize)
{
// Attempt to open the specified file using PhysicsFS
- VirtFile *restrict const file = VirtFs::openRead(fileName.c_str());
+ VirtFile *restrict const file = VirtFs::openRead(fileName);
if (!file)
{
@@ -44,7 +44,7 @@ namespace VirtFs
}
logger->log("Loaded %s/%s",
- VirtFs::getRealDir(fileName.c_str()),
+ VirtFs::getRealDir(fileName),
fileName.c_str());
fileSize = CAST_S32(VirtFs::fileLength(file));
@@ -71,7 +71,7 @@ namespace VirtFs
{
const std::string file = path + str;
const std::string realPath = std::string(
- VirtFs::getRealDir(file.c_str()));
+ VirtFs::getRealDir(file));
VirtFs::addZipToSearchPath(std::string(realPath).append(
dirSeparator).append(file), append);
}
@@ -92,7 +92,7 @@ namespace VirtFs
{
const std::string file = path + str;
const std::string realPath = std::string(
- VirtFs::getRealDir(file.c_str()));
+ VirtFs::getRealDir(file));
VirtFs::removeZipFromSearchPath(std::string(
realPath).append(
dirSeparator).append(