summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-11 19:08:11 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-11 19:19:38 +0300
commit245fb04a1e112cc8d0918a8660474299d5ce223c (patch)
treeeb5ab6266a4ff9551d2e08b9c14b61e353cd127f
parentf978c1bed85961e102951340669ca873328bcef3 (diff)
downloadManaVerse-245fb04a1e112cc8d0918a8660474299d5ce223c.tar.gz
ManaVerse-245fb04a1e112cc8d0918a8660474299d5ce223c.tar.bz2
ManaVerse-245fb04a1e112cc8d0918a8660474299d5ce223c.tar.xz
ManaVerse-245fb04a1e112cc8d0918a8660474299d5ce223c.zip
Split virtfs api for add directories and archives.
Also remove useless resourcemanager functions for add/remove virtfs entries.
-rw-r--r--src/client.cpp9
-rw-r--r--src/dirs.cpp18
-rw-r--r--src/dyetool/client.cpp8
-rw-r--r--src/dyetool/dyemain.cpp4
-rw-r--r--src/gui/widgets/browserbox_unittest.cc6
-rw-r--r--src/gui/windowmanager_unittest.cc8
-rw-r--r--src/gui/windows/updaterwindow.cpp26
-rw-r--r--src/integrity_unittest.cc76
-rw-r--r--src/resources/dye/dye_unittest.cc4
-rw-r--r--src/resources/dye/dyepalette_unittest.cc4
-rw-r--r--src/resources/map/maplayer_unittest.cc14
-rw-r--r--src/resources/map/speciallayer_unittest.cc9
-rw-r--r--src/resources/resourcemanager/resourcemanager.cpp33
-rw-r--r--src/resources/resourcemanager/resourcemanager.h17
-rw-r--r--src/resources/resourcemanager/resourcemanager_unittest.cc4
-rw-r--r--src/resources/sprite/animatedsprite_unittest.cc4
-rw-r--r--src/utils/chatutils_unittest.cc4
-rw-r--r--src/utils/files.cpp8
-rw-r--r--src/utils/files_unittest.cc24
-rw-r--r--src/utils/stringutils_unittest.cc8
-rw-r--r--src/utils/translation/poparser_unittest.cc4
-rw-r--r--src/utils/virtfs.cpp22
-rw-r--r--src/utils/virtfs.h10
-rw-r--r--src/utils/xml_unittest.cc4
-rw-r--r--src/utils/xmlutils_unittest.cc12
25 files changed, 164 insertions, 176 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 1b7f1a1da..38870b50f 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -414,12 +414,13 @@ void Client::gameInit()
// Add the main data directories to our PhysicsFS search path
if (!settings.options.dataPath.empty())
{
- resourceManager->addToSearchPath(settings.options.dataPath,
+ VirtFs::addDirToSearchPath(settings.options.dataPath,
Append_false);
}
// Add the local data directory to PhysicsFS search path
- resourceManager->addToSearchPath(settings.localDataDir, Append_false);
+ VirtFs::addDirToSearchPath(settings.localDataDir,
+ Append_false);
TranslationManager::loadCurrentLang();
#ifdef ENABLE_CUSTOMNLS
TranslationManager::loadGettextLang();
@@ -1091,7 +1092,7 @@ int Client::gameExec()
"/local/",
"zip");
- resourceManager->removeFromSearchPath(
+ VirtFs::removeDirFromSearchPath(
settings.localDataDir +
dirSeparator +
settings.updatesDir +
@@ -1314,7 +1315,7 @@ int Client::gameExec()
"zip",
Append_false);
- resourceManager->addToSearchPath(
+ VirtFs::addDirToSearchPath(
settings.localDataDir +
dirSeparator +
settings.updatesDir +
diff --git a/src/dirs.cpp b/src/dirs.cpp
index f27bc76f9..ce20923b4 100644
--- a/src/dirs.cpp
+++ b/src/dirs.cpp
@@ -190,9 +190,9 @@ void Dirs::extractDataDir()
void Dirs::mountDataDir()
{
- resourceManager->addToSearchPath(PKG_DATADIR "data/perserver/default",
+ VirtFs::addDirToSearchPath(PKG_DATADIR "data/perserver/default",
Append_false);
- resourceManager->addToSearchPath("data/perserver/default",
+ VirtFs::addDirToSearchPath("data/perserver/default",
Append_false);
#if defined __APPLE__
@@ -209,29 +209,29 @@ void Dirs::mountDataDir()
CFRelease(resourcesURL);
// possible crash
strncat(path, "/data", PATH_MAX - 1);
- resourceManager->addToSearchPath(path, Append_false);
+ VirtFs::addDirToSearchPath(path, Append_false);
// possible this need for support run client from dmg images.
// mPackageDir = path;
#endif // defined __APPLE__
- resourceManager->addToSearchPath(PKG_DATADIR "data", Append_false);
+ VirtFs::addDirToSearchPath(PKG_DATADIR "data", Append_false);
setPackageDir(PKG_DATADIR "data");
- resourceManager->addToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
#ifdef ANDROID
#ifdef USE_SDL2
if (getenv("APPDIR"))
{
const std::string appDir = getenv("APPDIR");
- resourceManager->addToSearchPath(appDir + "/data", Append_false);
- resourceManager->addToSearchPath(appDir + "/data/perserver/default",
+ VirtFs::addDirToSearchPath(appDir + "/data", Append_false);
+ VirtFs::addDirToSearchPath(appDir + "/data/perserver/default",
Append_false);
}
#endif // USE_SDL2
#endif // ANDROID
#if defined __native_client__
- resourceManager->addToSearchPath("/http/data.zip", Append_false);
+ VirtFs::addZipToSearchPath("/http/data.zip", Append_false);
#endif // defined __native_client__
// Add branding/data to PhysFS search path
@@ -251,7 +251,7 @@ void Dirs::mountDataDir()
if (loc > 0)
{
- resourceManager->addToSearchPath(path.substr(
+ VirtFs::addDirToSearchPath(path.substr(
0, loc + 1).append("data"),
Append_false);
}
diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp
index d32a08493..d2ace1a36 100644
--- a/src/dyetool/client.cpp
+++ b/src/dyetool/client.cpp
@@ -266,12 +266,13 @@ void Client::gameInit()
// Add the main data directories to our PhysicsFS search path
if (!settings.options.dataPath.empty())
{
- resourceManager->addToSearchPath(settings.options.dataPath,
+ VirtFs::addDirToSearchPath(settings.options.dataPath,
Append_false);
}
// Add the local data directory to PhysicsFS search path
- resourceManager->addToSearchPath(settings.localDataDir, Append_false);
+ VirtFs::addDirToSearchPath(settings.localDataDir,
+ Append_false);
TranslationManager::loadCurrentLang();
#ifdef ENABLE_CUSTOMNLS
TranslationManager::loadGettextLang();
@@ -640,7 +641,8 @@ int Client::gameExec()
"zip",
Append_false);
- resourceManager->addToSearchPath(settings.localDataDir
+ VirtFs::addDirToSearchPath(
+ settings.localDataDir
+ dirSeparator + settings.updatesDir + "/local/",
Append_false);
}
diff --git a/src/dyetool/dyemain.cpp b/src/dyetool/dyemain.cpp
index 7e0ed94a4..27b159a70 100644
--- a/src/dyetool/dyemain.cpp
+++ b/src/dyetool/dyemain.cpp
@@ -88,8 +88,8 @@ int main(int argc, char **argv)
ResourceManager::init();
resourceManager->setWriteDir(".");
- resourceManager->addToSearchPath(".", Append_false);
- resourceManager->addToSearchPath("/", Append_false);
+ VirtFs::addDirToSearchPath(".", Append_false);
+ VirtFs::addDirToSearchPath("/", Append_false);
std::string src = argv[1];
std::string dst;
if (argc == 4)
diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc
index dfa9757b5..3978c309d 100644
--- a/src/gui/widgets/browserbox_unittest.cc
+++ b/src/gui/widgets/browserbox_unittest.cc
@@ -30,6 +30,8 @@
#include "gui/widgets/browserbox.h"
+#include "utils/virtfs.h"
+
#include "render/sdlgraphics.h"
#include "resources/resourcemanager/resourcemanager.h"
@@ -47,8 +49,8 @@ TEST_CASE("BrowserBox tests", "browserbox")
logger = new Logger();
imageHelper = new SDLImageHelper();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper;
diff --git a/src/gui/windowmanager_unittest.cc b/src/gui/windowmanager_unittest.cc
index d3dc57b3e..392e6e872 100644
--- a/src/gui/windowmanager_unittest.cc
+++ b/src/gui/windowmanager_unittest.cc
@@ -138,10 +138,10 @@ TEST_CASE("Windows tests", "windowmanager")
resourceManager = nullptr;
ResourceManager::init();
resourceManager->cleanOrphans(true);
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
- resourceManager->addToSearchPath("data/test", Append_false);
- resourceManager->addToSearchPath("../data/test", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data/test", Append_false);
+ VirtFs::addDirToSearchPath("../data/test", Append_false);
paths.setDefaultValues(getPathsDefaults());
branding.setValue("onlineServerFile", "test/serverlistplus.xml");
mainGraphics = new SDLGraphics;
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index 645ec0e84..70ddd6897 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -754,7 +754,10 @@ void UpdaterWindow::loadManaPlusUpdates(const std::string &dir)
std::string fileName = std::string(fixPath).append(
"/").append(name);
if (!stat(fileName.c_str(), &statbuf))
- resourceManager->addToSearchPath(fileName, Append_false);
+ {
+ VirtFs::addZipToSearchPath(fileName,
+ Append_false);
+ }
}
}
}
@@ -777,7 +780,7 @@ void UpdaterWindow::unloadManaPlusUpdates(const std::string &dir)
const std::string file = std::string(
fixPath).append("/").append(name);
if (!stat(file.c_str(), &statbuf))
- resourceManager->removeFromSearchPath(file);
+ VirtFs::removeZipFromSearchPath(file);
}
}
}
@@ -789,27 +792,27 @@ void UpdaterWindow::addUpdateFile(const std::string &restrict path,
{
const std::string tmpPath = std::string(path).append("/").append(file);
if (append == Append_false)
- resourceManager->addToSearchPath(tmpPath, append);
+ VirtFs::addZipToSearchPath(tmpPath, append);
const std::string fixFile = std::string(fixPath).append("/").append(file);
struct stat statbuf;
if (!stat(fixFile.c_str(), &statbuf))
- resourceManager->addToSearchPath(fixFile, append);
+ VirtFs::addZipToSearchPath(fixFile, append);
if (append == Append_false)
- resourceManager->addToSearchPath(tmpPath, append);
+ VirtFs::addZipToSearchPath(tmpPath, append);
}
void UpdaterWindow::removeUpdateFile(const std::string &restrict path,
const std::string &restrict fixPath,
const std::string &restrict file)
{
- resourceManager->removeFromSearchPath(
+ VirtFs::removeZipFromSearchPath(
std::string(path).append("/").append(file));
const std::string fixFile = std::string(fixPath).append("/").append(file);
struct stat statbuf;
if (!stat(fixFile.c_str(), &statbuf))
- resourceManager->removeFromSearchPath(fixFile);
+ VirtFs::removeZipFromSearchPath(fixFile);
}
void UpdaterWindow::logic()
@@ -1134,7 +1137,10 @@ void UpdaterWindow::loadMods(const std::string &dir,
std::string fileName = std::string(fixPath).append(
"/").append(name);
if (!stat(fileName.c_str(), &statbuf))
- resourceManager->addToSearchPath(fileName, Append_false);
+ {
+ VirtFs::addZipToSearchPath(fileName,
+ Append_false);
+ }
}
}
}
@@ -1162,7 +1168,7 @@ void UpdaterWindow::loadDirMods(const std::string &dir)
const std::string &localDir = mod->getLocalDir();
if (!localDir.empty())
{
- resourceManager->addToSearchPath(dir + "/" + localDir,
+ VirtFs::addDirToSearchPath(dir + "/" + localDir,
Append_false);
}
}
@@ -1186,7 +1192,7 @@ void UpdaterWindow::unloadMods(const std::string &dir)
{
const std::string &localDir = mod->getLocalDir();
if (!localDir.empty())
- resourceManager->removeFromSearchPath(dir + "/" + localDir);
+ VirtFs::removeDirFromSearchPath(dir + "/" + localDir);
}
}
}
diff --git a/src/integrity_unittest.cc b/src/integrity_unittest.cc
index 67ab1c027..fe6ccc6f4 100644
--- a/src/integrity_unittest.cc
+++ b/src/integrity_unittest.cc
@@ -108,8 +108,8 @@ TEST_CASE("integrity tests", "integrity")
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
#ifdef USE_SDL2
imageHelper = new SurfaceImageHelper;
@@ -213,12 +213,12 @@ TEST_CASE("integrity tests", "integrity")
SECTION("integrity Loader::getImage test 2")
{
- resourceManager->addToSearchPath("data/test/test.zip", Append_false);
- resourceManager->addToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
Image *const image = Loader::getImage(
"hide.png");
- resourceManager->removeFromSearchPath("data/test/test.zip");
- resourceManager->removeFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
REQUIRE(image != nullptr);
REQUIRE(image->getSDLSurface() != nullptr);
image->decRef();
@@ -226,12 +226,12 @@ TEST_CASE("integrity tests", "integrity")
SECTION("integrity Loader::getImage test 3")
{
- resourceManager->addToSearchPath("data/test/test.zip", Append_false);
- resourceManager->addToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
Image *const image = Loader::getImage(
"dir/brimmedhat.png");
- resourceManager->removeFromSearchPath("data/test/test.zip");
- resourceManager->removeFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
REQUIRE(image != nullptr);
REQUIRE(image->getSDLSurface() != nullptr);
image->decRef();
@@ -239,14 +239,14 @@ TEST_CASE("integrity tests", "integrity")
SECTION("integrity Loader::getImage test 4")
{
- resourceManager->addToSearchPath("data/test/test.zip", Append_false);
- resourceManager->addToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
SDL_RWops *const rw = VirtFs::RWopsOpenRead(name1);
if (!rw)
logger->log("Physfs error: %s", VirtFs::getLastError());
- resourceManager->removeFromSearchPath("data/test/test.zip");
- resourceManager->removeFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
REQUIRE(rw != nullptr);
unsigned char buf[size1];
const size_t sz = SDL_RWread(rw, buf, 1, size1);
@@ -259,8 +259,8 @@ TEST_CASE("integrity tests", "integrity")
SECTION("integrity Loader::getImage test 5")
{
- resourceManager->addToSearchPath("data/test/test.zip", Append_false);
- resourceManager->addToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
PHYSFS_file *handle = PHYSFS_openRead(name1);
REQUIRE(handle != nullptr);
@@ -315,14 +315,14 @@ TEST_CASE("integrity tests", "integrity")
// rw->close(rw);
REQUIRE(PHYSFS_close(handle) != 0);
- resourceManager->removeFromSearchPath("data/test/test.zip");
- resourceManager->removeFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
}
SECTION("integrity Loader::getImage test 6")
{
- resourceManager->addToSearchPath("data/test/test.zip", Append_false);
- resourceManager->addToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
PHYSFS_file *handle = PHYSFS_openRead(name1);
REQUIRE(handle != nullptr);
@@ -395,15 +395,15 @@ TEST_CASE("integrity tests", "integrity")
// rw->close(rw);
REQUIRE(PHYSFS_close(handle) != 0);
- resourceManager->removeFromSearchPath("data/test/test.zip");
- resourceManager->removeFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
REQUIRE(compareBuffers(buf) == true);
}
SECTION("integrity Loader::getImage test 7")
{
- resourceManager->addToSearchPath("data/test/test.zip", Append_false);
- resourceManager->addToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
SDL_RWops *const rw = VirtFs::RWopsOpenRead(name1);
if (!rw)
@@ -430,15 +430,15 @@ TEST_CASE("integrity tests", "integrity")
REQUIRE(sz == size1);
SDL_RWclose(rw);
- resourceManager->removeFromSearchPath("data/test/test.zip");
- resourceManager->removeFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
REQUIRE(compareBuffers(buf) == true);
}
SECTION("integrity Loader::getImage test 8")
{
- resourceManager->addToSearchPath("data/test/test.zip", Append_false);
- resourceManager->addToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
SDL_RWops *const rw = VirtFs::RWopsOpenRead(name1);
if (!rw)
@@ -451,36 +451,36 @@ TEST_CASE("integrity tests", "integrity")
}
SDL_Surface *const tmpImage = IMG_LoadPNG_RW(rw);
SDL_RWclose(rw);
- resourceManager->removeFromSearchPath("data/test/test.zip");
- resourceManager->removeFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
REQUIRE(tmpImage != nullptr);
SDL_FreeSurface(tmpImage);
}
SECTION("integrity Loader::getImage test 9")
{
- resourceManager->addToSearchPath("data/test/test.zip", Append_false);
- resourceManager->addToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
SDL_RWops *const rw = VirtFs::RWopsOpenRead(name1);
if (!rw)
logger->log("Physfs error: %s", VirtFs::getLastError());
REQUIRE(rw != nullptr);
Resource *const res = imageHelper->load(rw);
- resourceManager->removeFromSearchPath("data/test/test.zip");
- resourceManager->removeFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
REQUIRE(res != nullptr);
res->decRef();
}
SECTION("integrity Loader::getImage test 10")
{
- resourceManager->addToSearchPath("data/test/test.zip", Append_false);
- resourceManager->addToSearchPath("../data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("data/test/test.zip", Append_false);
+ VirtFs::addZipToSearchPath("../data/test/test.zip", Append_false);
Image *const image = Loader::getImage(
name1);
- resourceManager->removeFromSearchPath("data/test/test.zip");
- resourceManager->removeFromSearchPath("../data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("data/test/test.zip");
+ VirtFs::removeZipFromSearchPath("../data/test/test.zip");
REQUIRE(image != nullptr);
REQUIRE(image->getSDLSurface() != nullptr);
image->decRef();
diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc
index f3d4fe3ba..57892c3a9 100644
--- a/src/resources/dye/dye_unittest.cc
+++ b/src/resources/dye/dye_unittest.cc
@@ -2358,8 +2358,8 @@ TEST_CASE("Dye real dye")
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data/test", Append_false);
- resourceManager->addToSearchPath("../data/test", Append_false);
+ VirtFs::addDirToSearchPath("data/test", Append_false);
+ VirtFs::addDirToSearchPath("../data/test", Append_false);
#ifdef USE_SDL2
imageHelper = new SurfaceImageHelper;
diff --git a/src/resources/dye/dyepalette_unittest.cc b/src/resources/dye/dyepalette_unittest.cc
index 42770e878..88bffe824 100644
--- a/src/resources/dye/dyepalette_unittest.cc
+++ b/src/resources/dye/dyepalette_unittest.cc
@@ -59,8 +59,8 @@ TEST_CASE("DyePalette tests")
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data/test", Append_false);
- resourceManager->addToSearchPath("../data/test", Append_false);
+ VirtFs::addDirToSearchPath("data/test", Append_false);
+ VirtFs::addDirToSearchPath("../data/test", Append_false);
mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper();
diff --git a/src/resources/map/maplayer_unittest.cc b/src/resources/map/maplayer_unittest.cc
index bd58d998c..75bd20219 100644
--- a/src/resources/map/maplayer_unittest.cc
+++ b/src/resources/map/maplayer_unittest.cc
@@ -28,6 +28,8 @@
#include "gui/theme.h"
+#include "utils/virtfs.h"
+
#include "render/mockgraphics.h"
#include "resources/sdlimagehelper.h"
@@ -1645,8 +1647,8 @@ TEST_CASE("MapLayer draw")
TEST_CASE("MapLayer drawSpecialLayer (specialLayer)")
{
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
imageHelper = new SDLImageHelper;
#ifdef USE_SDL2
@@ -1993,8 +1995,8 @@ TEST_CASE("MapLayer drawSpecialLayer (specialLayer)")
TEST_CASE("MapLayer drawSpecialLayer (tempLayer)")
{
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
imageHelper = new SDLImageHelper;
#ifdef USE_SDL2
@@ -2347,8 +2349,8 @@ TEST_CASE("MapLayer drawSpecialLayer (tempLayer)")
TEST_CASE("MapLayer drawFringe")
{
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
logger = new Logger;
imageHelper = new SDLImageHelper;
diff --git a/src/resources/map/speciallayer_unittest.cc b/src/resources/map/speciallayer_unittest.cc
index b74ade7dc..6c6772332 100644
--- a/src/resources/map/speciallayer_unittest.cc
+++ b/src/resources/map/speciallayer_unittest.cc
@@ -27,22 +27,23 @@
#include "enums/resources/map/mapitemtype.h"
+#include "utils/delete2.h"
+#include "utils/virtfs.h"
+
#include "resources/sdlimagehelper.h"
#include "resources/map/speciallayer.h"
#include "resources/resourcemanager/resourcemanager.h"
-#include "utils/delete2.h"
-
#include "debug.h"
TEST_CASE("SpecialLayer updateCache")
{
client = new Client;
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
imageHelper = new SDLImageHelper;
#ifdef USE_SDL2
diff --git a/src/resources/resourcemanager/resourcemanager.cpp b/src/resources/resourcemanager/resourcemanager.cpp
index 322b119a1..86158776d 100644
--- a/src/resources/resourcemanager/resourcemanager.cpp
+++ b/src/resources/resourcemanager/resourcemanager.cpp
@@ -340,35 +340,6 @@ bool ResourceManager::setWriteDir(const std::string &path) const
return static_cast<bool>(VirtFs::setWriteDir(path.c_str()));
}
-bool ResourceManager::addToSearchPath(const std::string &path,
- const Append append) const
-{
- logger->log("Adding to PhysicsFS: %s (%s)", path.c_str(),
- append == Append_true ? "append" : "prepend");
- if (!VirtFs::addToSearchPath(path.c_str(),
- append == Append_true ? 1 : 0))
- {
- logger->log("Error: %s: addToSearchPath failed: %s",
- path.c_str(),
- VirtFs::getLastError());
- return false;
- }
- return true;
-}
-
-bool ResourceManager::removeFromSearchPath(const std::string &path) const
-{
- logger->log("Removing from PhysicsFS: %s", path.c_str());
- if (!VirtFs::removeFromSearchPath(path.c_str()))
- {
- logger->log("Error: %s: removeFromSearchPath failed: %s",
- path.c_str(),
- VirtFs::getLastError());
- return false;
- }
- return true;
-}
-
void ResourceManager::searchAndAddArchives(const std::string &restrict path,
const std::string &restrict ext,
const Append append) const
@@ -385,7 +356,7 @@ void ResourceManager::searchAndAddArchives(const std::string &restrict path,
const std::string file = path + (*i);
const std::string realPath = std::string(
VirtFs::getRealDir(file.c_str()));
- addToSearchPath(std::string(realPath).append(
+ VirtFs::addZipToSearchPath(std::string(realPath).append(
dirSep).append(file), append);
}
}
@@ -408,7 +379,7 @@ void ResourceManager::searchAndRemoveArchives(const std::string &restrict path,
const std::string file = path + (*i);
const std::string realPath = std::string(
VirtFs::getRealDir(file.c_str()));
- removeFromSearchPath(std::string(realPath).append(
+ VirtFs::removeZipFromSearchPath(std::string(realPath).append(
dirSep).append(file));
}
}
diff --git a/src/resources/resourcemanager/resourcemanager.h b/src/resources/resourcemanager/resourcemanager.h
index 58e74967f..6f6875361 100644
--- a/src/resources/resourcemanager/resourcemanager.h
+++ b/src/resources/resourcemanager/resourcemanager.h
@@ -68,23 +68,6 @@ class ResourceManager final : public MemoryCounter
bool setWriteDir(const std::string &path) const;
/**
- * Adds a directory or archive to the search path. If append is true
- * then the directory is added to the end of the search path, otherwise
- * it is added at the front.
- *
- * @return <code>true</code> on success, <code>false</code> otherwise.
- */
- bool addToSearchPath(const std::string &path,
- const Append append) const;
-
- /**
- * Remove a directory or archive from the search path.
- *
- * @return <code>true</code> on success, <code>false</code> otherwise.
- */
- bool removeFromSearchPath(const std::string &path) const;
-
- /**
* Searches for zip files and adds them to the search path.
*/
void searchAndAddArchives(const std::string &restrict path,
diff --git a/src/resources/resourcemanager/resourcemanager_unittest.cc b/src/resources/resourcemanager/resourcemanager_unittest.cc
index 684f2d839..98ed0ca2f 100644
--- a/src/resources/resourcemanager/resourcemanager_unittest.cc
+++ b/src/resources/resourcemanager/resourcemanager_unittest.cc
@@ -94,8 +94,8 @@ TEST_CASE("resourcemanager", "resourcemanager")
logger = new Logger();
ResourceManager::init();
ResourceManager *safeResman = resourceManager;
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
imageHelper = new SDLImageHelper();
#ifdef USE_SDL2
diff --git a/src/resources/sprite/animatedsprite_unittest.cc b/src/resources/sprite/animatedsprite_unittest.cc
index 17746f65c..9505e7d24 100644
--- a/src/resources/sprite/animatedsprite_unittest.cc
+++ b/src/resources/sprite/animatedsprite_unittest.cc
@@ -60,8 +60,8 @@ TEST_CASE("AnimatedSprite tests", "animatedsprite")
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper();
#ifdef USE_SDL2
diff --git a/src/utils/chatutils_unittest.cc b/src/utils/chatutils_unittest.cc
index 233d02bf6..b28bd94da 100644
--- a/src/utils/chatutils_unittest.cc
+++ b/src/utils/chatutils_unittest.cc
@@ -54,8 +54,8 @@ TEST_CASE("chatutils replaceVars")
SDL_Init(SDL_INIT_VIDEO);
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
theme = new Theme;
Theme::selectSkin();
imageHelper = new SDLImageHelper();
diff --git a/src/utils/files.cpp b/src/utils/files.cpp
index e875af770..51674751b 100644
--- a/src/utils/files.cpp
+++ b/src/utils/files.cpp
@@ -46,7 +46,7 @@ void Files::extractLocale()
const std::string fileName2 = std::string(getenv(
"APPDIR")).append("/locale.zip");
- resourceManager->addToSearchPath(fileName2, Append_false);
+ VirtFs::addZipToSearchPath(fileName2, Append_false);
const std::string localDir = std::string(getenv("APPDIR")).append("/");
char **rootDirs = VirtFs::enumerateFiles("locale");
@@ -66,7 +66,7 @@ void Files::extractLocale()
}
}
VirtFs::freeList(rootDirs);
- resourceManager->removeFromSearchPath(fileName2);
+ VirtFs::removeZipFromSearchPath(fileName2);
remove(fileName2.c_str());
}
#endif // ANDROID
@@ -126,9 +126,9 @@ void Files::extractZip(const std::string &restrict zipName,
const std::string &restrict inDir,
const std::string &restrict outDir)
{
- resourceManager->addToSearchPath(zipName, Append_false);
+ VirtFs::addZipToSearchPath(zipName, Append_false);
copyPhysFsDir(inDir, outDir);
- resourceManager->removeFromSearchPath(zipName);
+ VirtFs::removeZipFromSearchPath(zipName);
remove(zipName.c_str());
}
diff --git a/src/utils/files_unittest.cc b/src/utils/files_unittest.cc
index 01996bd74..71e6e89c7 100644
--- a/src/utils/files_unittest.cc
+++ b/src/utils/files_unittest.cc
@@ -34,8 +34,8 @@ TEST_CASE("Files renameFile")
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
const int sz = 1234567;
char *buf = new char[sz];
@@ -71,8 +71,8 @@ TEST_CASE("Files existsLocal")
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
REQUIRE(Files::existsLocal(Files::getPath("help/about.txt")) == true);
REQUIRE_FALSE(Files::existsLocal(Files::getPath("help/about1.txt")));
REQUIRE_FALSE(Files::existsLocal(Files::getPath("help1/about.txt")));
@@ -85,8 +85,8 @@ TEST_CASE("Files loadTextFileString")
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
REQUIRE(Files::loadTextFileString("test/simplefile.txt") ==
"this is test \nfile.");
ResourceManager::deleteInstance();
@@ -98,8 +98,8 @@ TEST_CASE("Files loadTextFile")
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
StringVect lines;
Files::loadTextFile("test/simplefile.txt", lines);
@@ -115,8 +115,8 @@ TEST_CASE("Files saveTextFile")
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
const std::string dir = Files::getPath("test");
REQUIRE(dir.size() > 0);
@@ -133,8 +133,8 @@ TEST_CASE("Files getFilesInDir")
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
StringVect list;
Files::getFilesInDir("test",
diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc
index 46c1b352c..3354da89c 100644
--- a/src/utils/stringutils_unittest.cc
+++ b/src/utils/stringutils_unittest.cc
@@ -1264,10 +1264,10 @@ TEST_CASE("stringuntils replaceItemLinks")
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
- resourceManager->addToSearchPath("data/test", Append_false);
- resourceManager->addToSearchPath("../data/test", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data/test", Append_false);
+ VirtFs::addDirToSearchPath("../data/test", Append_false);
ItemDB::NamedItemInfos &namedInfos = ItemDB::getNamedItemInfosTest();
ItemDB::ItemInfos &infos = ItemDB::getItemInfosTest();
diff --git a/src/utils/translation/poparser_unittest.cc b/src/utils/translation/poparser_unittest.cc
index b59b1e098..e7928c8b5 100644
--- a/src/utils/translation/poparser_unittest.cc
+++ b/src/utils/translation/poparser_unittest.cc
@@ -50,8 +50,8 @@ TEST_CASE("PoParser tests", "PoParser")
dirSeparator = "/";
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper();
diff --git a/src/utils/virtfs.cpp b/src/utils/virtfs.cpp
index 6d3d18ba9..ef70d119e 100644
--- a/src/utils/virtfs.cpp
+++ b/src/utils/virtfs.cpp
@@ -136,14 +136,28 @@ namespace VirtFs
return PHYSFS_setWriteDir(newDir);
}
- bool addToSearchPath(const char *const newDir, const int appendToPath)
+ bool addDirToSearchPath(const std::string &newDir,
+ const Append append)
{
- return PHYSFS_addToSearchPath(newDir, appendToPath);
+ return PHYSFS_addToSearchPath(newDir.c_str(),
+ append == Append_true ? 1 : 0);
}
- bool removeFromSearchPath(const char *const oldDir)
+ bool removeDirFromSearchPath(const std::string &oldDir)
{
- return PHYSFS_removeFromSearchPath(oldDir);
+ return PHYSFS_removeFromSearchPath(oldDir.c_str());
+ }
+
+ bool addZipToSearchPath(const std::string &newDir,
+ const Append append)
+ {
+ return PHYSFS_addToSearchPath(newDir.c_str(),
+ append == Append_true ? 1 : 0);
+ }
+
+ bool removeZipFromSearchPath(const std::string &oldDir)
+ {
+ return PHYSFS_removeFromSearchPath(oldDir.c_str());
}
const char *getRealDir(const char *const filename)
diff --git a/src/utils/virtfs.h b/src/utils/virtfs.h
index e2db24e44..3bb98c046 100644
--- a/src/utils/virtfs.h
+++ b/src/utils/virtfs.h
@@ -21,6 +21,8 @@
#ifndef UTILS_PHYSFSTOOLS_H
#define UTILS_PHYSFSTOOLS_H
+#include "enums/simpletypes/append.h"
+
#include "localconsts.h"
#include <string>
@@ -42,8 +44,12 @@ namespace VirtFs
VirtFile *openWrite(const char *const filename);
VirtFile *openAppend(const char *const filename);
bool setWriteDir(const char *const newDir);
- bool addToSearchPath(const char *const newDir, const int appendToPath);
- bool removeFromSearchPath(const char *const oldDir);
+ bool addDirToSearchPath(const std::string &newDir,
+ const Append append);
+ bool removeDirFromSearchPath(const std::string &oldDir);
+ bool addZipToSearchPath(const std::string &newDir,
+ const Append append);
+ bool removeZipFromSearchPath(const std::string &oldDir);
const char *getRealDir(const char *const filename);
bool mkdir(const char *const dirName);
void *loadFile(const std::string &fileName, int &fileSize);
diff --git a/src/utils/xml_unittest.cc b/src/utils/xml_unittest.cc
index 575c61a5c..e6198a597 100644
--- a/src/utils/xml_unittest.cc
+++ b/src/utils/xml_unittest.cc
@@ -51,8 +51,8 @@ TEST_CASE("xml doc")
XML::initXML();
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
mainGraphics = new SDLGraphics;
imageHelper = new SDLImageHelper();
#ifdef USE_SDL2
diff --git a/src/utils/xmlutils_unittest.cc b/src/utils/xmlutils_unittest.cc
index ab70b7ec1..dbb571429 100644
--- a/src/utils/xmlutils_unittest.cc
+++ b/src/utils/xmlutils_unittest.cc
@@ -38,8 +38,8 @@ TEST_CASE("xmlutils readXmlIntVector 1")
XML::initXML();
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
std::vector<int> arr;
@@ -68,8 +68,8 @@ TEST_CASE("xmlutils readXmlStringMap 1")
XML::initXML();
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data", Append_false);
- resourceManager->addToSearchPath("../data", Append_false);
+ VirtFs::addDirToSearchPath("data", Append_false);
+ VirtFs::addDirToSearchPath("../data", Append_false);
std::map<std::string, std::string> arr;
@@ -97,8 +97,8 @@ TEST_CASE("xmlutils readXmlIntMap 1")
XML::initXML();
logger = new Logger();
ResourceManager::init();
- resourceManager->addToSearchPath("data/test", Append_false);
- resourceManager->addToSearchPath("../data/test", Append_false);
+ VirtFs::addDirToSearchPath("data/test", Append_false);
+ VirtFs::addDirToSearchPath("../data/test", Append_false);
std::map<int32_t, int32_t> arr;