diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-03-09 03:31:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-03-09 03:31:42 +0300 |
commit | 612873fa462d74a31bdd3977dac7919376038275 (patch) | |
tree | 86c7ce3cb5a0d334bcba5d463846a88e03a8669e /src/fs/physfs | |
parent | 8470d3c82d84a6bd7767de6763153aa9cdfb991b (diff) | |
download | mv-612873fa462d74a31bdd3977dac7919376038275.tar.gz mv-612873fa462d74a31bdd3977dac7919376038275.tar.bz2 mv-612873fa462d74a31bdd3977dac7919376038275.tar.xz mv-612873fa462d74a31bdd3977dac7919376038275.zip |
Simplify add/remove dirs and zips methods in virtfs.
Diffstat (limited to 'src/fs/physfs')
-rw-r--r-- | src/fs/physfs/virtfs.cpp | 30 | ||||
-rw-r--r-- | src/fs/physfs/virtfsphys.cpp | 28 | ||||
-rw-r--r-- | src/fs/physfs/virtfsphys.h | 12 | ||||
-rw-r--r-- | src/fs/physfs/virtfsphys_unittest.cc | 124 |
4 files changed, 97 insertions, 97 deletions
diff --git a/src/fs/physfs/virtfs.cpp b/src/fs/physfs/virtfs.cpp index e678e0224..c9fd34ba4 100644 --- a/src/fs/physfs/virtfs.cpp +++ b/src/fs/physfs/virtfs.cpp @@ -104,37 +104,37 @@ namespace VirtFs return VirtFsPhys::setWriteDir(newDir); } - bool addDirToSearchPath(std::string newDir, - const Append append) + bool mountDir(std::string newDir, + const Append append) { - return VirtFsPhys::addDirToSearchPath(newDir, append); + return VirtFsPhys::mountDir(newDir, append); } - bool addDirToSearchPathSilent(std::string newDir, - const Append append) + bool mountDirSilent(std::string newDir, + const Append append) { - return VirtFsPhys::addDirToSearchPath(newDir, append); + return VirtFsPhys::mountDir(newDir, append); } - bool removeDirFromSearchPath(std::string oldDir) + bool unmountDir(std::string oldDir) { - return VirtFsPhys::removeDirFromSearchPath(oldDir); + return VirtFsPhys::unmountDir(oldDir); } - bool removeDirFromSearchPathSilent(std::string oldDir) + bool unmountDirSilent(std::string oldDir) { - return VirtFsPhys::removeDirFromSearchPath(oldDir); + return VirtFsPhys::unmountDir(oldDir); } - bool addZipToSearchPath(std::string newDir, - const Append append) + bool mountZip(std::string newDir, + const Append append) { - return VirtFsPhys::addZipToSearchPath(newDir, append); + return VirtFsPhys::mountZip(newDir, append); } - bool removeZipFromSearchPath(std::string oldDir) + bool unmountZip(std::string oldDir) { - return VirtFsPhys::removeZipFromSearchPath(oldDir); + return VirtFsPhys::unmountZip(oldDir); } std::string getRealDir(std::string filename) diff --git a/src/fs/physfs/virtfsphys.cpp b/src/fs/physfs/virtfsphys.cpp index 439ed2890..f6d0abf47 100644 --- a/src/fs/physfs/virtfsphys.cpp +++ b/src/fs/physfs/virtfsphys.cpp @@ -180,73 +180,73 @@ namespace VirtFsPhys return PHYSFS_setWriteDir(newDir.c_str()); } - bool addDirToSearchPath(const std::string &restrict newDir, - const Append append) + bool mountDir(const std::string &restrict newDir, + const Append append) { logger->log("Add virtual directory: " + newDir); if (newDir.find(".zip") != std::string::npos) { - reportAlways("Called addDirToSearchPath with zip archive"); + reportAlways("Called mountDir with zip archive"); return false; } const int ret = PHYSFS_addToSearchPath(newDir.c_str(), append == Append_true ? 1 : 0); if (ret == 0) { - logger->log("addDirToSearchPath error: %s", + logger->log("mountDir error: %s", VirtFsPhys::getLastError()); } return ret; } - bool removeDirFromSearchPath(const std::string &restrict oldDir) + bool unmountDir(const std::string &restrict oldDir) { logger->log("Remove virtual directory: " + oldDir); if (oldDir.find(".zip") != std::string::npos) { - reportAlways("Called removeDirFromSearchPath with zip archive"); + reportAlways("Called unmountDir with zip archive"); return false; } const int ret = PHYSFS_removeFromSearchPath(oldDir.c_str()); if (ret == 0) { - logger->log("removeDirFromSearchPath error: %s", + logger->log("unmountDir error: %s", VirtFsPhys::getLastError()); } return ret; } - bool addZipToSearchPath(const std::string &restrict newDir, - const Append append) + bool mountZip(const std::string &restrict newDir, + const Append append) { logger->log("Add virtual zip: " + newDir); if (newDir.find(".zip") == std::string::npos) { - reportAlways("Called addZipToSearchPath without zip archive"); + reportAlways("Called mountZip without zip archive"); return false; } const int ret = PHYSFS_addToSearchPath(newDir.c_str(), append == Append_true ? 1 : 0); if (ret == 0) { - logger->log("addZipToSearchPath error: %s", + logger->log("mountZip error: %s", VirtFsPhys::getLastError()); } return ret; } - bool removeZipFromSearchPath(const std::string &restrict oldDir) + bool unmountZip(const std::string &restrict oldDir) { logger->log("Remove virtual zip: " + oldDir); if (oldDir.find(".zip") == std::string::npos) { - reportAlways("Called removeZipFromSearchPath without zip archive"); + reportAlways("Called unmountZip without zip archive"); return false; } const int ret = PHYSFS_removeFromSearchPath(oldDir.c_str()); if (ret == 0) { - logger->log("removeZipFromSearchPath error: %s", + logger->log("unmountZip error: %s", VirtFsPhys::getLastError()); } return ret; diff --git a/src/fs/physfs/virtfsphys.h b/src/fs/physfs/virtfsphys.h index 42394b56b..97b70aae6 100644 --- a/src/fs/physfs/virtfsphys.h +++ b/src/fs/physfs/virtfsphys.h @@ -50,12 +50,12 @@ namespace VirtFsPhys 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); - bool removeDirFromSearchPath(const std::string &restrict oldDir); - bool addZipToSearchPath(const std::string &restrict newDir, - const Append append); - bool removeZipFromSearchPath(const std::string &restrict oldDir); + bool mountDir(const std::string &restrict newDir, + const Append append); + bool unmountDir(const std::string &restrict oldDir); + bool mountZip(const std::string &restrict newDir, + const Append append); + bool unmountZip(const std::string &restrict oldDir); std::string getRealDir(const std::string &restrict filename); bool mkdir(const std::string &restrict dirName); bool remove(const std::string &restrict filename); diff --git a/src/fs/physfs/virtfsphys_unittest.cc b/src/fs/physfs/virtfsphys_unittest.cc index 8137cfb45..429579b05 100644 --- a/src/fs/physfs/virtfsphys_unittest.cc +++ b/src/fs/physfs/virtfsphys_unittest.cc @@ -61,32 +61,32 @@ TEST_CASE("VirtFsPhys exists") { VirtFsPhys::initFuncs(); logger = new Logger(); - VirtFsPhys::addDirToSearchPath("data", Append_false); - VirtFsPhys::addDirToSearchPath("../data", Append_false); + VirtFsPhys::mountDir("data", Append_false); + VirtFsPhys::mountDir("../data", Append_false); REQUIRE(VirtFsPhys::exists("test/units.xml") == true); REQUIRE(VirtFsPhys::exists("test/units123.xml") == false); REQUIRE(VirtFsPhys::exists("tesQ/units.xml") == false); REQUIRE(VirtFsPhys::exists("units.xml") == false); - VirtFsPhys::addDirToSearchPath("data/test", Append_false); - VirtFsPhys::addDirToSearchPath("../data/test", Append_false); + VirtFsPhys::mountDir("data/test", Append_false); + VirtFsPhys::mountDir("../data/test", Append_false); REQUIRE(VirtFsPhys::exists("test/units.xml") == true); REQUIRE(VirtFsPhys::exists("test/units123.xml") == false); REQUIRE(VirtFsPhys::exists("tesQ/units.xml") == false); REQUIRE(VirtFsPhys::exists("units.xml") == true); - VirtFsPhys::removeDirFromSearchPath("data/test"); - VirtFsPhys::removeDirFromSearchPath("../data/test"); + VirtFsPhys::unmountDir("data/test"); + VirtFsPhys::unmountDir("../data/test"); REQUIRE(VirtFsPhys::exists("test/units.xml") == true); REQUIRE(VirtFsPhys::exists("test/units123.xml") == false); REQUIRE(VirtFsPhys::exists("tesQ/units.xml") == false); REQUIRE(VirtFsPhys::exists("units.xml") == false); - VirtFsPhys::removeDirFromSearchPath("data"); - VirtFsPhys::removeDirFromSearchPath("../data"); + VirtFsPhys::unmountDir("data"); + VirtFsPhys::unmountDir("../data"); delete2(logger); } @@ -94,8 +94,8 @@ TEST_CASE("VirtFsPhys exists2") { VirtFsPhys::initFuncs(); logger = new Logger(); - VirtFsPhys::addZipToSearchPath("data/test/test2.zip", Append_false); - VirtFsPhys::addZipToSearchPath("../data/test/test2.zip", Append_false); + VirtFsPhys::mountZip("data/test/test2.zip", Append_false); + VirtFsPhys::mountZip("../data/test/test2.zip", Append_false); REQUIRE(VirtFsPhys::exists("test/units.xml") == false); REQUIRE(VirtFsPhys::exists("test.txt") == true); @@ -103,8 +103,8 @@ TEST_CASE("VirtFsPhys exists2") REQUIRE(VirtFsPhys::exists("tesQ/units.xml") == false); REQUIRE(VirtFsPhys::exists("units.xml") == true); - VirtFsPhys::removeZipFromSearchPath("data/test/test2.zip"); - VirtFsPhys::removeZipFromSearchPath("../data/test/test2.zip"); + VirtFsPhys::unmountZip("data/test/test2.zip"); + VirtFsPhys::unmountZip("../data/test/test2.zip"); delete2(logger); } @@ -139,8 +139,8 @@ TEST_CASE("VirtFsPhys enumerateFiles1") VirtFsPhys::initFuncs(); logger = new Logger; - VirtFsPhys::addDirToSearchPath("data", Append_false); - VirtFsPhys::addDirToSearchPath("../data", Append_false); + VirtFsPhys::mountDir("data", Append_false); + VirtFsPhys::mountDir("../data", Append_false); VirtList *list = nullptr; @@ -166,8 +166,8 @@ TEST_CASE("VirtFsPhys enumerateFiles1") REQUIRE(list->names.size() == cnt1); VirtFsPhys::freeList(list); - VirtFsPhys::removeDirFromSearchPath("data"); - VirtFsPhys::removeDirFromSearchPath("../data"); + VirtFsPhys::unmountDir("data"); + VirtFsPhys::unmountDir("../data"); delete2(logger); } @@ -176,9 +176,9 @@ TEST_CASE("VirtFsPhys enumerateFiles2") VirtFsPhys::initFuncs(); logger = new Logger; - VirtFsPhys::addDirToSearchPath("data/test/dir1", + VirtFsPhys::mountDir("data/test/dir1", Append_false); - VirtFsPhys::addDirToSearchPath("../data/test/dir1", + VirtFsPhys::mountDir("../data/test/dir1", Append_false); VirtList *list = nullptr; @@ -188,8 +188,8 @@ TEST_CASE("VirtFsPhys enumerateFiles2") REQUIRE(list->names.size() == 5); VirtFsPhys::freeList(list); - VirtFsPhys::removeDirFromSearchPath("data/test/dir1"); - VirtFsPhys::removeDirFromSearchPath("../data/test/dir1"); + VirtFsPhys::unmountDir("data/test/dir1"); + VirtFsPhys::unmountDir("../data/test/dir1"); delete2(logger); } @@ -209,9 +209,9 @@ TEST_CASE("VirtFsPhys enumerateFiles3") VirtFsPhys::initFuncs(); logger = new Logger; - VirtFsPhys::addZipToSearchPath("data/test/test.zip", + VirtFsPhys::mountZip("data/test/test.zip", Append_false); - VirtFsPhys::addZipToSearchPath("../data/test/test.zip", + VirtFsPhys::mountZip("../data/test/test.zip", Append_false); VirtList *list = nullptr; @@ -221,8 +221,8 @@ TEST_CASE("VirtFsPhys enumerateFiles3") REQUIRE(inList(list, "test.txt") == false); VirtFsPhys::freeList(list); - VirtFsPhys::removeZipFromSearchPath("data/test/test.zip"); - VirtFsPhys::removeZipFromSearchPath("../data/test/test.zip"); + VirtFsPhys::unmountZip("data/test/test.zip"); + VirtFsPhys::unmountZip("../data/test/test.zip"); delete2(logger); } @@ -231,9 +231,9 @@ TEST_CASE("VirtFsPhys enumerateFiles4") VirtFsPhys::initFuncs(); logger = new Logger; - VirtFsPhys::addZipToSearchPath("data/test/test2.zip", + VirtFsPhys::mountZip("data/test/test2.zip", Append_false); - VirtFsPhys::addZipToSearchPath("../data/test/test2.zip", + VirtFsPhys::mountZip("../data/test/test2.zip", Append_false); VirtList *list = nullptr; @@ -243,8 +243,8 @@ TEST_CASE("VirtFsPhys enumerateFiles4") REQUIRE(inList(list, "test.txt") == true); VirtFsPhys::freeList(list); - VirtFsPhys::removeZipFromSearchPath("data/test/test2.zip"); - VirtFsPhys::removeZipFromSearchPath("../data/test/test2.zip"); + VirtFsPhys::unmountZip("data/test/test2.zip"); + VirtFsPhys::unmountZip("../data/test/test2.zip"); delete2(logger); } @@ -252,8 +252,8 @@ TEST_CASE("VirtFsPhys isDirectory") { VirtFsPhys::initFuncs(); logger = new Logger(); - VirtFsPhys::addDirToSearchPath("data", Append_false); - VirtFsPhys::addDirToSearchPath("../data", Append_false); + VirtFsPhys::mountDir("data", Append_false); + VirtFsPhys::mountDir("../data", Append_false); REQUIRE(VirtFsPhys::isDirectory("test/units.xml") == false); REQUIRE(VirtFsPhys::isDirectory("test/units.xml/") == false); @@ -276,8 +276,8 @@ TEST_CASE("VirtFsPhys isDirectory") REQUIRE(VirtFsPhys::isDirectory("testQ/") == false); REQUIRE(VirtFsPhys::isDirectory("testQ//") == false); - VirtFsPhys::addDirToSearchPath("data/test", Append_false); - VirtFsPhys::addDirToSearchPath("../data/test", Append_false); + VirtFsPhys::mountDir("data/test", Append_false); + VirtFsPhys::mountDir("../data/test", Append_false); REQUIRE(VirtFsPhys::isDirectory("test/units.xml") == false); REQUIRE(VirtFsPhys::isDirectory("test/units.xml/") == false); @@ -289,8 +289,8 @@ TEST_CASE("VirtFsPhys isDirectory") REQUIRE(VirtFsPhys::isDirectory("testQ") == false); REQUIRE(VirtFsPhys::isDirectory("test/dir1") == true); - VirtFsPhys::removeDirFromSearchPath("data/test"); - VirtFsPhys::removeDirFromSearchPath("../data/test"); + VirtFsPhys::unmountDir("data/test"); + VirtFsPhys::unmountDir("../data/test"); REQUIRE(VirtFsPhys::isDirectory("test/units.xml") == false); REQUIRE(VirtFsPhys::isDirectory("test/units123.xml") == false); @@ -302,8 +302,8 @@ TEST_CASE("VirtFsPhys isDirectory") REQUIRE(VirtFsPhys::isDirectory("testQ") == false); REQUIRE(VirtFsPhys::isDirectory("test/dir1") == true); - VirtFsPhys::removeDirFromSearchPath("data"); - VirtFsPhys::removeDirFromSearchPath("../data"); + VirtFsPhys::unmountDir("data"); + VirtFsPhys::unmountDir("../data"); delete2(logger); } @@ -311,8 +311,8 @@ TEST_CASE("VirtFsPhys openRead") { VirtFsPhys::initFuncs(); logger = new Logger(); - VirtFsPhys::addDirToSearchPath("data", Append_false); - VirtFsPhys::addDirToSearchPath("../data", Append_false); + VirtFsPhys::mountDir("data", Append_false); + VirtFsPhys::mountDir("../data", Append_false); VirtFile *file = nullptr; @@ -330,8 +330,8 @@ TEST_CASE("VirtFsPhys openRead") file = VirtFsPhys::openRead("testQ"); REQUIRE(file == nullptr); - VirtFsPhys::addDirToSearchPath("data/test", Append_false); - VirtFsPhys::addDirToSearchPath("../data/test", Append_false); + VirtFsPhys::mountDir("data/test", Append_false); + VirtFsPhys::mountDir("../data/test", Append_false); file = VirtFsPhys::openRead("test/units.xml"); REQUIRE(file != nullptr); @@ -348,8 +348,8 @@ TEST_CASE("VirtFsPhys openRead") file = VirtFsPhys::openRead("testQ"); REQUIRE(file == nullptr); - VirtFsPhys::removeDirFromSearchPath("data/test"); - VirtFsPhys::removeDirFromSearchPath("../data/test"); + VirtFsPhys::unmountDir("data/test"); + VirtFsPhys::unmountDir("../data/test"); file = VirtFsPhys::openRead("test/units.xml"); REQUIRE(file != nullptr); @@ -365,17 +365,17 @@ TEST_CASE("VirtFsPhys openRead") file = VirtFsPhys::openRead("testQ"); REQUIRE(file == nullptr); - VirtFsPhys::removeDirFromSearchPath("data"); - VirtFsPhys::removeDirFromSearchPath("../data"); + VirtFsPhys::unmountDir("data"); + VirtFsPhys::unmountDir("../data"); delete2(logger); } -TEST_CASE("VirtFsPhys addZipToSearchPath") +TEST_CASE("VirtFsPhys mountZip") { // +++ need implement } -TEST_CASE("VirtFsPhys removeZipFromSearchPath") +TEST_CASE("VirtFsPhys unmountZip") { // +++ need implement } @@ -386,8 +386,8 @@ TEST_CASE("VirtFsPhys getRealDir") logger = new Logger(); REQUIRE(VirtFsPhys::getRealDir(".") == ""); REQUIRE(VirtFsPhys::getRealDir("..") == ""); - const bool dir1 = VirtFsPhys::addDirToSearchPath("data", Append_false); - REQUIRE((dir1 || VirtFsPhys::addDirToSearchPath( + const bool dir1 = VirtFsPhys::mountDir("data", Append_false); + REQUIRE((dir1 || VirtFsPhys::mountDir( "../data", Append_false)) == true); if (dir1 == true) { @@ -403,8 +403,8 @@ TEST_CASE("VirtFsPhys getRealDir") } REQUIRE(VirtFsPhys::getRealDir("zzz") == ""); - VirtFsPhys::addDirToSearchPath("data/test", Append_false); - VirtFsPhys::addDirToSearchPath("../data/test", Append_false); + VirtFsPhys::mountDir("data/test", Append_false); + VirtFsPhys::mountDir("../data/test", Append_false); if (dir1 == true) { REQUIRE(VirtFsPhys::getRealDir("test") == "data"); @@ -425,21 +425,21 @@ TEST_CASE("VirtFsPhys getRealDir") if (dir1 == true) { - VirtFsPhys::addZipToSearchPath("data/test/test.zip", Append_false); + VirtFsPhys::mountZip("data/test/test.zip", Append_false); REQUIRE(VirtFsPhys::getRealDir("dir/brimmedhat.png") == "data/test/test.zip"); REQUIRE(VirtFsPhys::getRealDir("hide.png") == "data/test"); } else { - VirtFsPhys::addZipToSearchPath("../data/test/test.zip", Append_false); + VirtFsPhys::mountZip("../data/test/test.zip", Append_false); REQUIRE(VirtFsPhys::getRealDir("dir/brimmedhat.png") == "../data/test/test.zip"); REQUIRE(VirtFsPhys::getRealDir("hide.png") == "../data/test"); } - VirtFsPhys::removeDirFromSearchPath("data/test"); - VirtFsPhys::removeDirFromSearchPath("../data/test"); + VirtFsPhys::unmountDir("data/test"); + VirtFsPhys::unmountDir("../data/test"); if (dir1 == true) { @@ -460,10 +460,10 @@ TEST_CASE("VirtFsPhys getRealDir") REQUIRE(VirtFsPhys::exists("dir/hide.png")); REQUIRE(VirtFsPhys::getRealDir("zzz") == ""); - VirtFsPhys::removeDirFromSearchPath("data"); - VirtFsPhys::removeDirFromSearchPath("../data"); - VirtFsPhys::removeZipFromSearchPath("data/test/test.zip"); - VirtFsPhys::removeZipFromSearchPath("../data/test/test.zip"); + VirtFsPhys::unmountDir("data"); + VirtFsPhys::unmountDir("../data"); + VirtFsPhys::unmountZip("data/test/test.zip"); + VirtFsPhys::unmountZip("../data/test/test.zip"); delete2(logger); } @@ -471,8 +471,8 @@ TEST_CASE("VirtFsPhys read") { VirtFsPhys::initFuncs(); logger = new Logger(); - VirtFsPhys::addDirToSearchPath("data", Append_false); - VirtFsPhys::addDirToSearchPath("../data", Append_false); + VirtFsPhys::mountDir("data", Append_false); + VirtFsPhys::mountDir("../data", Append_false); VirtFile *file = VirtFsPhys::openRead("test/test.txt"); REQUIRE(file != nullptr); @@ -499,8 +499,8 @@ TEST_CASE("VirtFsPhys read") VirtFsPhys::close(file); free(buffer); - VirtFsPhys::removeDirFromSearchPath("data"); - VirtFsPhys::removeDirFromSearchPath("../data"); + VirtFsPhys::unmountDir("data"); + VirtFsPhys::unmountDir("../data"); delete2(logger); } #endif // USE_PHYSFS |