summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-02-18 01:07:09 +0300
committerAndrei Karas <akaras@inbox.ru>2013-02-18 01:07:09 +0300
commit566ce2ee769e863977d57ba156a281ade5cb9c05 (patch)
tree57c7fed83e2fa35588bd488431dd1129cf2345c3 /src
parent1c119959b43d7dde5291ea5ae5d70b59e72b8c10 (diff)
downloadplus-566ce2ee769e863977d57ba156a281ade5cb9c05.tar.gz
plus-566ce2ee769e863977d57ba156a281ade5cb9c05.tar.bz2
plus-566ce2ee769e863977d57ba156a281ade5cb9c05.tar.xz
plus-566ce2ee769e863977d57ba156a281ade5cb9c05.zip
move most direct calls to physfs to separate file.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/chatlogger.cpp7
-rw-r--r--src/client.cpp38
-rw-r--r--src/game.cpp5
-rw-r--r--src/gui/theme.cpp28
-rw-r--r--src/main.cpp4
-rw-r--r--src/map.cpp4
-rw-r--r--src/resources/resourcemanager.cpp43
-rw-r--r--src/resources/wallpaper.cpp12
-rw-r--r--src/utils/paths.cpp15
-rw-r--r--src/utils/physfsrwops.cpp10
-rw-r--r--src/utils/physfsrwops.h3
-rw-r--r--src/utils/physfstools.cpp99
-rw-r--r--src/utils/physfstools.h45
15 files changed, 229 insertions, 88 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6f10f0712..4eadd8178 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -486,6 +486,8 @@ SET(SRCS
utils/perfomance.h
utils/physfsrwops.cpp
utils/physfsrwops.h
+ utils/physfstools.cpp
+ utils/physfstools.h
utils/process.cpp
utils/process.h
utils/stringutils.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index bd5a5d62e..ddc6776d2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -488,6 +488,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
utils/perfomance.h \
utils/physfsrwops.cpp \
utils/physfsrwops.h \
+ utils/physfstools.cpp \
+ utils/physfstools.h \
utils/process.cpp \
utils/process.h \
utils/specialfolder.cpp \
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp
index 5c0f83cb2..3b1cbc771 100644
--- a/src/chatlogger.cpp
+++ b/src/chatlogger.cpp
@@ -39,8 +39,7 @@
#include "logger.h"
#include "configuration.h"
#include "utils/mkdir.h"
-
-#include <physfs.h>
+#include "utils/physfstools.h"
#include "debug.h"
@@ -171,11 +170,11 @@ void ChatLogger::setServerName(const std::string &serverName)
secureName(mServerName);
if (mLogDir != "")
{
- DIR *const dir = opendir((mLogDir + PHYSFS_getDirSeparator()
+ DIR *const dir = opendir((mLogDir + PhysFs::getDirSeparator()
+ mServerName).c_str());
if (!dir)
{
- mkdir_r((mLogDir + PHYSFS_getDirSeparator()
+ mkdir_r((mLogDir + PhysFs::getDirSeparator()
+ mServerName).c_str());
}
else
diff --git a/src/client.cpp b/src/client.cpp
index caa78b310..371dab3d8 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -95,6 +95,7 @@
#include "utils/gettext.h"
#include "utils/mkdir.h"
#include "utils/paths.h"
+#include "utils/physfstools.h"
#include "utils/translation/translationmanager.h"
@@ -105,7 +106,6 @@
#include <CoreFoundation/CFBundle.h>
#endif
-#include <physfs.h>
#include <SDL_image.h>
#ifdef WIN32
@@ -348,15 +348,15 @@ void Client::gameInit()
setEnv("LANGUAGE", lang.c_str());
}
#ifdef ANDROID
- bindTextDomain("manaplus", (std::string(PHYSFS_getBaseDir())
+ bindTextDomain("manaplus", (std::string(PhysFs::getBaseDir())
+ "/locale").c_str());
#else
#ifdef ENABLE_PORTABLE
- bindTextDomain("manaplus", (std::string(PHYSFS_getBaseDir())
+ bindTextDomain("manaplus", (std::string(PhysFs::getBaseDir())
+ "../locale/").c_str());
#else
#ifdef __APPLE__
- bindTextDomain("manaplus", (std::string(PHYSFS_getBaseDir())
+ bindTextDomain("manaplus", (std::string(PhysFs::getBaseDir())
+ "ManaPlus.app/Contents/Resources/locale/").c_str());
#else
bindTextDomain("manaplus", LOCALEDIR);
@@ -503,7 +503,7 @@ void Client::gameInit()
else
{
mOptions.dataPath = branding.getDirectory()
- + PHYSFS_getDirSeparator()
+ + PhysFs::getDirSeparator()
+ branding.getStringValue("dataPath");
}
mOptions.skipUpdate = true;
@@ -1331,14 +1331,14 @@ int Client::gameExec()
else if (loginData.updateType & LoginData::Upd_Skip)
{
UpdaterWindow::loadLocalUpdates(mLocalDataDir
- + PHYSFS_getDirSeparator() + mUpdatesDir);
+ + PhysFs::getDirSeparator() + mUpdatesDir);
mState = STATE_LOAD_DATA;
}
else
{
logger->log1("State: UPDATE");
mCurrentDialog = new UpdaterWindow(mUpdateHost,
- mLocalDataDir + PHYSFS_getDirSeparator()
+ mLocalDataDir + PhysFs::getDirSeparator()
+ mUpdatesDir, mOptions.dataPath.empty(),
loginData.updateType);
}
@@ -1372,7 +1372,7 @@ int Client::gameExec()
false);
resman->addToSearchPath(mLocalDataDir
- + PHYSFS_getDirSeparator()
+ + PhysFs::getDirSeparator()
+ mUpdatesDir + "/local/", false);
}
@@ -1790,7 +1790,7 @@ void Client::action(const gcn::ActionEvent &event)
void Client::initRootDir()
{
- mRootDir = PHYSFS_getBaseDir();
+ mRootDir = PhysFs::getBaseDir();
std::string portableName = mRootDir + "portable.xml";
struct stat statbuf;
@@ -1856,22 +1856,22 @@ void Client::initLocalDataDir()
{
#ifdef __APPLE__
// Use Application Directory instead of .mana
- mLocalDataDir = std::string(PHYSFS_getUserDir()) +
+ mLocalDataDir = std::string(PhysFs::getUserDir()) +
"/Library/Application Support/" +
branding.getValue("appName", "ManaPlus");
#elif defined __HAIKU__
- mLocalDataDir = std::string(PHYSFS_getUserDir()) +
+ mLocalDataDir = std::string(PhysFs::getUserDir()) +
"/config/data/Mana";
#elif defined WIN32
mLocalDataDir = getSpecialFolderLocation(CSIDL_LOCAL_APPDATA);
if (mLocalDataDir.empty())
- mLocalDataDir = std::string(PHYSFS_getUserDir());
+ mLocalDataDir = std::string(PhysFs::getUserDir());
mLocalDataDir += "/Mana";
#elif defined __ANDROID__
mLocalDataDir = getenv("DATADIR2") + branding.getValue(
"appShort", "ManaPlus") + "/local";
#else
- mLocalDataDir = std::string(PHYSFS_getUserDir()) +
+ mLocalDataDir = std::string(PhysFs::getUserDir()) +
".local/share/mana";
#endif
}
@@ -1888,7 +1888,7 @@ void Client::initLocalDataDir()
void Client::initTempDir()
{
- mTempDir = mLocalDataDir + PHYSFS_getDirSeparator() + "temp";
+ mTempDir = mLocalDataDir + PhysFs::getDirSeparator() + "temp";
if (mkdir_r(mTempDir.c_str()))
{
@@ -1904,10 +1904,10 @@ void Client::initConfigDir()
if (mConfigDir.empty())
{
#ifdef __APPLE__
- mConfigDir = mLocalDataDir + PHYSFS_getDirSeparator()
+ mConfigDir = mLocalDataDir + PhysFs::getDirSeparator()
+ branding.getValue("appShort", "mana");
#elif defined __HAIKU__
- mConfigDir = std::string(PHYSFS_getUserDir()) +
+ mConfigDir = std::string(PhysFs::getUserDir()) +
"/config/settings/Mana" +
branding.getValue("appName", "ManaPlus");
#elif defined WIN32
@@ -1920,7 +1920,7 @@ void Client::initConfigDir()
mConfigDir = getenv("DATADIR2") + branding.getValue(
"appShort", "ManaPlus") + "/config";
#else
- mConfigDir = std::string(PHYSFS_getUserDir()) +
+ mConfigDir = std::string(PhysFs::getUserDir()) +
"/.config/mana/" + branding.getValue("appShort", "mana");
#endif
logger->log("Generating config dir: " + mConfigDir);
@@ -1939,7 +1939,7 @@ void Client::initConfigDir()
*/
void Client::initServerConfig(std::string serverName)
{
- mServerConfigDir = mConfigDir + PHYSFS_getDirSeparator() + serverName;
+ mServerConfigDir = mConfigDir + PhysFs::getDirSeparator() + serverName;
if (mkdir_r(mServerConfigDir.c_str()))
{
@@ -2192,7 +2192,7 @@ void Client::initScreenshotDir()
if (!configScreenshotSuffix.empty())
{
- mScreenshotDir += PHYSFS_getDirSeparator()
+ mScreenshotDir += PhysFs::getDirSeparator()
+ configScreenshotSuffix;
}
}
diff --git a/src/game.cpp b/src/game.cpp
index 33aa1ca02..ef053bd8f 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -89,12 +89,11 @@
#include "utils/gettext.h"
#include "utils/mkdir.h"
+#include "utils/physfstools.h"
#include <guichan/exception.hpp>
#include <guichan/focushandler.hpp>
-#include <physfs.h>
-
#include <fstream>
#include <sstream>
#include <string>
@@ -513,7 +512,7 @@ bool Game::saveScreenshot(SDL_Surface *const screenshot)
logger->log("Directory %s doesn't exist and can't be created! "
"Setting screenshot directory to home.",
screenshotDirectory.c_str());
- screenshotDirectory = std::string(PHYSFS_getUserDir());
+ screenshotDirectory = std::string(PhysFs::getUserDir());
}
do
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 042373250..acd188031 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -33,11 +33,9 @@
#include "resources/resourcemanager.h"
#include "utils/dtor.h"
-
-#include <physfs.h>
+#include "utils/physfstools.h"
#include <algorithm>
-#include <physfs.h>
#include "debug.h"
@@ -578,7 +576,7 @@ bool Theme::tryThemePath(std::string themeName)
if (!themeName.empty())
{
std::string path = defaultThemePath + themeName;
- if (PHYSFS_exists(path.c_str()))
+ if (PhysFs::exists(path.c_str()))
{
mThemePath = path;
mThemeName = themeName;
@@ -593,48 +591,48 @@ bool Theme::tryThemePath(std::string themeName)
void Theme::fillSkinsList(StringVect &list)
{
- char **skins = PHYSFS_enumerateFiles(
+ char **skins = PhysFs::enumerateFiles(
branding.getStringValue("guiThemePath").c_str());
for (char **i = skins; *i; i++)
{
- if (PHYSFS_isDirectory((
+ if (PhysFs::isDirectory((
branding.getStringValue("guiThemePath") + *i).c_str()))
{
list.push_back(*i);
}
}
- PHYSFS_freeList(skins);
+ PhysFs::freeList(skins);
}
void Theme::fillFontsList(StringVect &list)
{
PHYSFS_permitSymbolicLinks(1);
- char **fonts = PHYSFS_enumerateFiles(
+ char **fonts = PhysFs::enumerateFiles(
branding.getStringValue("fontsPath").c_str());
for (char **i = fonts; *i; i++)
{
- if (!PHYSFS_isDirectory((
+ if (!PhysFs::isDirectory((
branding.getStringValue("fontsPath") + *i).c_str()))
{
list.push_back(*i);
}
}
- PHYSFS_freeList(fonts);
+ PhysFs::freeList(fonts);
PHYSFS_permitSymbolicLinks(0);
}
void Theme::fillSoundsList(StringVect &list)
{
- char **skins = PHYSFS_enumerateFiles(
+ char **skins = PhysFs::enumerateFiles(
branding.getStringValue("systemsounds").c_str());
for (char **i = skins; *i; i++)
{
- if (!PHYSFS_isDirectory((
+ if (!PhysFs::isDirectory((
branding.getStringValue("systemsounds") + *i).c_str()))
{
std::string str = *i;
@@ -643,7 +641,7 @@ void Theme::fillSoundsList(StringVect &list)
}
}
- PHYSFS_freeList(skins);
+ PhysFs::freeList(skins);
}
void Theme::selectSkin()
@@ -688,14 +686,14 @@ std::string Theme::resolveThemePath(const std::string &path)
if (file.find('/') != std::string::npos)
{
// Might be a valid path already
- if (PHYSFS_exists(file.c_str()))
+ if (PhysFs::exists(file.c_str()))
return path;
}
// Try the theme
file = getThemePath() + "/" + file;
- if (PHYSFS_exists(file.c_str()))
+ if (PhysFs::exists(file.c_str()))
return getThemePath() + "/" + path;
// Backup
diff --git a/src/main.cpp b/src/main.cpp
index 9351536b9..0266dde21 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -27,13 +27,13 @@
#include <getopt.h>
#include <iostream>
-#include <physfs.h>
#include "utils/gettext.h"
#ifdef ANDROID
#include "utils/mkdir.h"
#endif
#include "utils/paths.h"
+#include "utils/physfstools.h"
#include "utils/xml.h"
#ifdef UNITTESTS
@@ -262,7 +262,7 @@ int main(int argc, char *argv[])
XML::initXML();
#ifdef WIN32
- SetCurrentDirectory(PHYSFS_getBaseDir());
+ SetCurrentDirectory(PhysFs::getBaseDir());
#endif
Client client(options);
if (!options.testMode)
diff --git a/src/map.cpp b/src/map.cpp
index 4f8cab3eb..c30592073 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -40,9 +40,9 @@
#include "utils/dtor.h"
#include "utils/mkdir.h"
+#include "utils/physfstools.h"
#include <limits.h>
-#include <physfs.h>
#include <queue>
#include <sys/stat.h>
@@ -1223,7 +1223,7 @@ void Map::saveExtraLayer() const
std::string Map::getUserMapDirectory() const
{
- return Client::getServerConfigDirectory() + PHYSFS_getDirSeparator()
+ return Client::getServerConfigDirectory() + PhysFs::getDirSeparator()
+ getProperty("_realfilename");
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index bd739644c..dbd2f60cf 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -40,7 +40,6 @@
#include "utils/mkdir.h"
#include "utils/physfsrwops.h"
-#include <physfs.h>
#include <SDL_image.h>
#include <cassert>
#include <fstream>
@@ -298,7 +297,7 @@ void ResourceManager::clearDeleted(bool full)
}
bool ResourceManager::setWriteDir(const std::string &path) const
{
- return static_cast<bool>(PHYSFS_setWriteDir(path.c_str()));
+ return static_cast<bool>(PhysFs::setWriteDir(path.c_str()));
}
bool ResourceManager::addToSearchPath(const std::string &path,
@@ -306,7 +305,7 @@ bool ResourceManager::addToSearchPath(const std::string &path,
{
logger->log("Adding to PhysicsFS: %s (%s)", path.c_str(),
append ? "append" : "prepend");
- if (!PHYSFS_addToSearchPath(path.c_str(), append ? 1 : 0))
+ if (!PhysFs::addToSearchPath(path.c_str(), append ? 1 : 0))
{
logger->log("Error: %s", PHYSFS_getLastError());
return false;
@@ -317,7 +316,7 @@ bool ResourceManager::addToSearchPath(const std::string &path,
bool ResourceManager::removeFromSearchPath(const std::string &path) const
{
logger->log("Removing from PhysicsFS: %s", path.c_str());
- if (!PHYSFS_removeFromSearchPath(path.c_str()))
+ if (!PhysFs::removeFromSearchPath(path.c_str()))
{
logger->log("Error: %s", PHYSFS_getLastError());
return false;
@@ -329,8 +328,8 @@ void ResourceManager::searchAndAddArchives(const std::string &path,
const std::string &ext,
const bool append) const
{
- const char *const dirSep = PHYSFS_getDirSeparator();
- char **list = PHYSFS_enumerateFiles(path.c_str());
+ const char *const dirSep = PhysFs::getDirSeparator();
+ char **list = PhysFs::enumerateFiles(path.c_str());
for (char **i = list; *i; i++)
{
@@ -341,21 +340,21 @@ void ResourceManager::searchAndAddArchives(const std::string &path,
std::string file, realPath, archive;
file = path + (*i);
- realPath = std::string(PHYSFS_getRealDir(file.c_str()));
+ realPath = std::string(PhysFs::getRealDir(file.c_str()));
archive = realPath + dirSep + file;
addToSearchPath(archive, append);
}
}
- PHYSFS_freeList(list);
+ PhysFs::freeList(list);
}
void ResourceManager::searchAndRemoveArchives(const std::string &path,
const std::string &ext) const
{
- const char *const dirSep = PHYSFS_getDirSeparator();
- char **list = PHYSFS_enumerateFiles(path.c_str());
+ const char *const dirSep = PhysFs::getDirSeparator();
+ char **list = PhysFs::enumerateFiles(path.c_str());
for (char **i = list; *i; i++)
{
@@ -366,24 +365,24 @@ void ResourceManager::searchAndRemoveArchives(const std::string &path,
std::string file, realPath, archive;
file = path + (*i);
- realPath = std::string(PHYSFS_getRealDir(file.c_str()));
+ realPath = std::string(PhysFs::getRealDir(file.c_str()));
archive = realPath + dirSep + file;
removeFromSearchPath(archive);
}
}
- PHYSFS_freeList(list);
+ PhysFs::freeList(list);
}
bool ResourceManager::mkdir(const std::string &path) const
{
- return static_cast<bool>(PHYSFS_mkdir(path.c_str()));
+ return static_cast<bool>(PhysFs::mkdir(path.c_str()));
}
bool ResourceManager::exists(const std::string &path) const
{
- return PHYSFS_exists(path.c_str());
+ return PhysFs::exists(path.c_str());
}
bool ResourceManager::existsLocal(const std::string &path) const
@@ -399,24 +398,24 @@ bool ResourceManager::existsLocal(const std::string &path) const
bool ResourceManager::isDirectory(const std::string &path) const
{
- return PHYSFS_isDirectory(path.c_str());
+ return PhysFs::isDirectory(path.c_str());
}
std::string ResourceManager::getPath(const std::string &file) const
{
// get the real path to the file
- const char *const tmp = PHYSFS_getRealDir(file.c_str());
+ const char *const tmp = PhysFs::getRealDir(file.c_str());
std::string path;
// if the file is not in the search path, then its nullptr
if (tmp)
{
- path = std::string(tmp) + PHYSFS_getDirSeparator() + file;
+ path = std::string(tmp) + PhysFs::getDirSeparator() + file;
}
else
{
// if not found in search path return the default path
- path = Client::getPackageDirectory() + PHYSFS_getDirSeparator() + file;
+ path = Client::getPackageDirectory() + PhysFs::getDirSeparator() + file;
}
return path;
@@ -894,7 +893,7 @@ void ResourceManager::deleteInstance()
void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
{
// Attempt to open the specified file using PhysicsFS
- PHYSFS_file *const file = PHYSFS_openRead(fileName.c_str());
+ PHYSFS_file *const file = PhysFs::openRead(fileName.c_str());
// If the handler is an invalid pointer indicate failure
if (!file)
@@ -905,7 +904,7 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
}
// Log the real dir of the file
- logger->log("Loaded %s/%s", PHYSFS_getRealDir(fileName.c_str()),
+ logger->log("Loaded %s/%s", PhysFs::getRealDir(fileName.c_str()),
fileName.c_str());
// Get the size of the file
@@ -924,13 +923,13 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
bool ResourceManager::copyFile(const std::string &src,
const std::string &dst) const
{
- PHYSFS_file *const srcFile = PHYSFS_openRead(src.c_str());
+ PHYSFS_file *const srcFile = PhysFs::openRead(src.c_str());
if (!srcFile)
{
logger->log("Read error: %s", PHYSFS_getLastError());
return false;
}
- PHYSFS_file *const dstFile = PHYSFS_openWrite(dst.c_str());
+ PHYSFS_file *const dstFile = PhysFs::openWrite(dst.c_str());
if (!dstFile)
{
logger->log("Write error: %s", PHYSFS_getLastError());
diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp
index 381fe7466..9c694ece9 100644
--- a/src/resources/wallpaper.cpp
+++ b/src/resources/wallpaper.cpp
@@ -22,13 +22,13 @@
#include "resources/wallpaper.h"
-#include "resources/resourcemanager.h"
+#include "configuration.h"
#include "logger.h"
-#include "utils/stringutils.h"
-#include "configuration.h"
+#include "resources/resourcemanager.h"
-#include <physfs.h>
+#include "utils/physfstools.h"
+#include "utils/stringutils.h"
#include <algorithm>
#include <cstring>
@@ -92,7 +92,7 @@ void Wallpaper::loadWallpapers()
initDefaultWallpaperPaths();
- char **imgs = PHYSFS_enumerateFiles(wallpaperPath.c_str());
+ char **imgs = PhysFs::enumerateFiles(wallpaperPath.c_str());
for (char **i = imgs; *i; i++)
{
@@ -130,7 +130,7 @@ void Wallpaper::loadWallpapers()
}
}
- PHYSFS_freeList(imgs);
+ PhysFs::freeList(imgs);
std::sort(wallpaperData.begin(), wallpaperData.end(), wallpaperCompare);
}
diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp
index 6f10262f6..271178c23 100644
--- a/src/utils/paths.cpp
+++ b/src/utils/paths.cpp
@@ -25,7 +25,7 @@
#endif
#include "utils/paths.h"
-
+#include "utils/physfstools.h"
#include "utils/stringutils.h"
#include "resources/resourcemanager.h"
@@ -33,7 +33,6 @@
#include <string.h>
#include <cstdarg>
#include <cstdio>
-#include <physfs.h>
#include <stdlib.h>
#ifdef WIN32
@@ -80,7 +79,7 @@ bool checkPath(std::string path)
std::string &fixDirSeparators(std::string &str)
{
- if (*PHYSFS_getDirSeparator() == '/')
+ if (*PhysFs::getDirSeparator() == '/')
return str;
return replaceAll(str, "/", "\\");
@@ -150,7 +149,7 @@ std::string getDesktopDir()
char *xdg = getenv("XDG_CONFIG_HOME");
std::string file;
if (!xdg)
- file = std::string(PHYSFS_getUserDir()) + "/.config/user-dirs.dirs";
+ file = std::string(PhysFs::getUserDir()) + "/.config/user-dirs.dirs";
else
file = std::string(xdg) + "/user-dirs.dirs";
@@ -163,16 +162,16 @@ std::string getDesktopDir()
str = str.substr(0, str.size() - 1);
// use hack to replace $HOME var.
// if in string other vars, fallback to default path
- replaceAll(str, "$HOME/", PHYSFS_getUserDir());
+ replaceAll(str, "$HOME/", PhysFs::getUserDir());
str = getRealPath(str);
if (str.empty())
- str = std::string(PHYSFS_getUserDir()) + "Desktop";
+ str = std::string(PhysFs::getUserDir()) + "Desktop";
return str;
}
}
- return std::string(PHYSFS_getUserDir()) + "Desktop";
+ return std::string(PhysFs::getUserDir()) + "Desktop";
#else
- return std::string(PHYSFS_getUserDir()) + "Desktop";
+ return std::string(PhysFs::getUserDir()) + "Desktop";
#endif
}
diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp
index ba3dc45e7..36729401a 100644
--- a/src/utils/physfsrwops.cpp
+++ b/src/utils/physfsrwops.cpp
@@ -26,8 +26,6 @@
#include <stdio.h> /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
-#include "localconsts.h"
-
#include "debug.h"
static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
@@ -180,7 +178,7 @@ static bool checkFilePath(const char *fname)
{
if (!fname || !*fname)
return false;
- if (!PHYSFS_exists(fname) || PHYSFS_isDirectory(fname))
+ if (!PhysFs::exists(fname) || PhysFs::isDirectory(fname))
return false;
return true;
}
@@ -192,7 +190,7 @@ SDL_RWops *PHYSFSRWOPS_openRead(const char *fname)
if (!checkFilePath(fname))
return nullptr;
#endif
- return create_rwops(PHYSFS_openRead(fname));
+ return create_rwops(PhysFs::openRead(fname));
} /* PHYSFSRWOPS_openRead */
SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
@@ -201,7 +199,7 @@ SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
if (!checkFilePath(fname))
return nullptr;
#endif
- return create_rwops(PHYSFS_openWrite(fname));
+ return create_rwops(PhysFs::openWrite(fname));
} /* PHYSFSRWOPS_openWrite */
SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
@@ -210,7 +208,7 @@ SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
if (!checkFilePath(fname))
return nullptr;
#endif
- return create_rwops(PHYSFS_openAppend(fname));
+ return create_rwops(PhysFs::openAppend(fname));
} /* PHYSFSRWOPS_openAppend */
/* end of physfsrwops.c ... */
diff --git a/src/utils/physfsrwops.h b/src/utils/physfsrwops.h
index fbd1020dd..6faa52a0e 100644
--- a/src/utils/physfsrwops.h
+++ b/src/utils/physfsrwops.h
@@ -25,9 +25,10 @@
#ifndef UTILS_PHYSFSRWOPS_H
#define UTILS_PHYSFSRWOPS_H
-#include <physfs.h>
#include <SDL.h>
+#include "utils/physfstools.h"
+
#include "localconsts.h"
/**
diff --git a/src/utils/physfstools.cpp b/src/utils/physfstools.cpp
new file mode 100644
index 000000000..bf0dfead3
--- /dev/null
+++ b/src/utils/physfstools.cpp
@@ -0,0 +1,99 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "utils/physfstools.h"
+
+namespace PhysFs
+{
+ const char *getDirSeparator()
+ {
+ return PHYSFS_getDirSeparator();
+ }
+
+ const char *getBaseDir()
+ {
+ return PHYSFS_getBaseDir();
+ }
+
+ const char *getUserDir()
+ {
+ return PHYSFS_getUserDir();
+ }
+
+ bool exists(const char *fname)
+ {
+ return PHYSFS_exists(fname);
+ }
+
+ char **enumerateFiles(const char *dir)
+ {
+ return PHYSFS_enumerateFiles(dir);
+ }
+
+ bool isDirectory(const char *fname)
+ {
+ return PHYSFS_isDirectory(fname);
+ }
+
+ void freeList(void *listVar)
+ {
+ PHYSFS_freeList(listVar);
+ }
+
+ PHYSFS_File *openRead(const char *filename)
+ {
+ return PHYSFS_openRead(filename);
+ }
+
+ PHYSFS_File *openWrite(const char *filename)
+ {
+ return PHYSFS_openWrite(filename);
+ }
+
+ PHYSFS_File *openAppend(const char *filename)
+ {
+ return PHYSFS_openAppend(filename);
+ }
+
+ bool setWriteDir(const char *newDir)
+ {
+ return PHYSFS_setWriteDir(newDir);
+ }
+
+ bool addToSearchPath(const char *newDir, int appendToPath)
+ {
+ return PHYSFS_addToSearchPath(newDir, appendToPath);
+ }
+
+ bool removeFromSearchPath(const char *oldDir)
+ {
+ return PHYSFS_removeFromSearchPath(oldDir);
+ }
+
+ const char *getRealDir(const char *filename)
+ {
+ return PHYSFS_getRealDir(filename);
+ }
+
+ bool mkdir(const char *dirname)
+ {
+ return PHYSFS_mkdir(dirname);
+ }
+}
diff --git a/src/utils/physfstools.h b/src/utils/physfstools.h
new file mode 100644
index 000000000..8a6c70d25
--- /dev/null
+++ b/src/utils/physfstools.h
@@ -0,0 +1,45 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_PHYSFS_H
+#define UTILS_PHYSFS_H
+
+#include <physfs.h>
+
+namespace PhysFs
+{
+ const char *getDirSeparator();
+ const char *getBaseDir();
+ const char *getUserDir();
+ bool exists(const char *fname);
+ char **enumerateFiles(const char *dir);
+ bool isDirectory(const char *fname);
+ void freeList(void *listVar);
+ PHYSFS_File *openRead(const char *filename);
+ PHYSFS_File *openWrite(const char *filename);
+ PHYSFS_File *openAppend(const char *filename);
+ bool setWriteDir(const char *newDir);
+ bool addToSearchPath(const char *newDir, int appendToPath);
+ bool removeFromSearchPath(const char *oldDir);
+ const char *getRealDir(const char *filename);
+ bool mkdir(const char *dirName);
+}
+
+#endif // UTILS_PHYSFS_H