summaryrefslogtreecommitdiff
path: root/src/utils
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 /src/utils
parentf978c1bed85961e102951340669ca873328bcef3 (diff)
downloadplus-245fb04a1e112cc8d0918a8660474299d5ce223c.tar.gz
plus-245fb04a1e112cc8d0918a8660474299d5ce223c.tar.bz2
plus-245fb04a1e112cc8d0918a8660474299d5ce223c.tar.xz
plus-245fb04a1e112cc8d0918a8660474299d5ce223c.zip
Split virtfs api for add directories and archives.
Also remove useless resourcemanager functions for add/remove virtfs entries.
Diffstat (limited to 'src/utils')
-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
9 files changed, 58 insertions, 38 deletions
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;