summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-27 19:15:04 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-27 19:15:04 +0300
commit36c6674db35445d6c72f0f520b4abf9ef15b4da9 (patch)
treef42ad8dd480c57c3f3e18116dce19da9611d1316
parent6388446b85e1fa5deccc6d5c1683fba88ef53d99 (diff)
downloadmanaverse-36c6674db35445d6c72f0f520b4abf9ef15b4da9.tar.gz
manaverse-36c6674db35445d6c72f0f520b4abf9ef15b4da9.tar.bz2
manaverse-36c6674db35445d6c72f0f520b4abf9ef15b4da9.tar.xz
manaverse-36c6674db35445d6c72f0f520b4abf9ef15b4da9.zip
Add own base dir in VirtFsDir.
-rw-r--r--src/fs/virtfsdir.cpp21
-rw-r--r--src/fs/virtfsdir.h3
-rw-r--r--src/fs/virtfsdir_unittest.cc31
3 files changed, 41 insertions, 14 deletions
diff --git a/src/fs/virtfsdir.cpp b/src/fs/virtfsdir.cpp
index 3950aa18c..d27355d40 100644
--- a/src/fs/virtfsdir.cpp
+++ b/src/fs/virtfsdir.cpp
@@ -50,6 +50,7 @@ namespace
{
std::vector<VirtDirEntry*> mEntries;
std::string mWriteDir;
+ std::string mBaseDir;
bool mPermitLinks = false;
VirtFsFuncs funcs;
} // namespace
@@ -252,8 +253,21 @@ namespace VirtFsDir
mEntries.clear();
}
- void init()
+#if defined(__native_client__)
+ void init(const std::string &restrict name A_UNUSED)
{
+ mBaseDir = "/";
+#elif defined(ANDROID)
+ void init(const std::string &restrict name A_UNUSED)
+ {
+ mBaseDir = getRealPath(".");
+#else // defined(__native_client__)
+
+ void init(const std::string &restrict name)
+ {
+ mBaseDir = getRealPath(getFileDir(name));
+#endif // defined(__native_client__)
+
initFuncs(&funcs);
}
@@ -268,6 +282,11 @@ namespace VirtFsDir
ptr->eof = &VirtFsDir::eof;
}
+ const char *getBaseDir()
+ {
+ return mBaseDir.c_str();
+ }
+
std::string getRealDir(const std::string &restrict filename)
{
if (checkPath(filename) == false)
diff --git a/src/fs/virtfsdir.h b/src/fs/virtfsdir.h
index d090f5366..f528dad30 100644
--- a/src/fs/virtfsdir.h
+++ b/src/fs/virtfsdir.h
@@ -38,6 +38,7 @@ namespace VirtFsDir
{
VirtDirEntry *searchEntryByRoot(const std::string &restrict root);
VirtDirEntry *searchEntryByPath(const std::string &restrict path);
+ const char *getBaseDir();
bool addToSearchPath(const std::string &newDir,
const Append append);
bool addToSearchPathSilent(const std::string &newDir,
@@ -45,7 +46,7 @@ namespace VirtFsDir
const SkipError skipError);
bool removeFromSearchPath(std::string oldDir);
bool removeFromSearchPathSilent(std::string oldDir);
- void init();
+ void init(const std::string &restrict name);
void initFuncs(VirtFsFuncs *restrict const ptr);
void deinit();
std::vector<VirtDirEntry*> &getEntries();
diff --git a/src/fs/virtfsdir_unittest.cc b/src/fs/virtfsdir_unittest.cc
index a005341de..1f162a6e9 100644
--- a/src/fs/virtfsdir_unittest.cc
+++ b/src/fs/virtfsdir_unittest.cc
@@ -32,15 +32,22 @@
TEST_CASE("VirtFsDir getEntries")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
REQUIRE(VirtFsDir::getEntries().empty());
REQUIRE(VirtFsDir::searchEntryByRoot("test") == nullptr);
VirtFsDir::deinit();
}
+TEST_CASE("VirtFsDir getBaseDir")
+{
+ VirtFsDir::init(".");
+ REQUIRE(VirtFsDir::getBaseDir() != nullptr);
+ VirtFsDir::deinit();
+}
+
TEST_CASE("VirtFsDir addToSearchPath")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger();
SECTION("simple 1")
{
@@ -156,7 +163,7 @@ TEST_CASE("VirtFsDir addToSearchPath")
TEST_CASE("VirtFsDir removeFromSearchPath")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger();
SECTION("simple 1")
@@ -230,7 +237,7 @@ TEST_CASE("VirtFsDir removeFromSearchPath")
TEST_CASE("VirtFsDir exists")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger();
VirtFsDir::addToSearchPathSilent("data",
Append_false,
@@ -298,7 +305,7 @@ static void removeTemp(StringVect &restrict list)
TEST_CASE("VirtFsDir getRealDir")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger();
REQUIRE(VirtFsDir::getRealDir(".") == "");
REQUIRE(VirtFsDir::getRealDir("..") == "");
@@ -382,7 +389,7 @@ static bool inList(VirtList *list,
TEST_CASE("VirtFsDir enumerateFiles1")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger;
VirtFsDir::addToSearchPathSilent("data",
@@ -424,7 +431,7 @@ TEST_CASE("VirtFsDir enumerateFiles1")
TEST_CASE("VirtFsDir enumerateFiles2")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger;
VirtFsDir::addToSearchPathSilent("data/test/dir1",
@@ -448,7 +455,7 @@ TEST_CASE("VirtFsDir enumerateFiles2")
TEST_CASE("VirtFsDir enumerateFiles3")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger;
VirtFsDir::addToSearchPathSilent("data/test/dir1",
@@ -478,7 +485,7 @@ TEST_CASE("VirtFsDir enumerateFiles3")
TEST_CASE("VirtFsDir isDirectory")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger();
VirtFsDir::addToSearchPathSilent("data",
Append_false,
@@ -546,7 +553,7 @@ TEST_CASE("VirtFsDir isDirectory")
TEST_CASE("VirtFsDir openRead")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger();
VirtFsDir::addToSearchPathSilent("data",
Append_false,
@@ -613,7 +620,7 @@ TEST_CASE("VirtFsDir openRead")
TEST_CASE("VirtFsDir permitLinks")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger();
VirtFsDir::addToSearchPathSilent("data",
Append_false,
@@ -652,7 +659,7 @@ TEST_CASE("VirtFsDir permitLinks")
TEST_CASE("VirtFsDir read")
{
- VirtFsDir::init();
+ VirtFsDir::init(".");
logger = new Logger();
VirtFsDir::addToSearchPathSilent("data",
Append_false,