summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-02 04:28:19 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-02 04:55:18 +0300
commit4b1ca08f26152fbcfb5eb838d271fdd88c381eca (patch)
treea005f6414ead9ae4ee287e6d198bab68ad6bdf63
parentce9dd5dfa8e49e5204f25e079c1283ab6173b7cb (diff)
downloadManaVerse-4b1ca08f26152fbcfb5eb838d271fdd88c381eca.tar.gz
ManaVerse-4b1ca08f26152fbcfb5eb838d271fdd88c381eca.tar.bz2
ManaVerse-4b1ca08f26152fbcfb5eb838d271fdd88c381eca.tar.xz
ManaVerse-4b1ca08f26152fbcfb5eb838d271fdd88c381eca.zip
Add base class for VirtDirEntry and VirtZipEntry.
-rw-r--r--src/Makefile.am3
-rw-r--r--src/enums/fs/fsentrytype.h33
-rw-r--r--src/fs/virtfs/virtdirentry.cpp5
-rw-r--r--src/fs/virtfs/virtdirentry.h5
-rw-r--r--src/fs/virtfs/virtfs.cpp6
-rw-r--r--src/fs/virtfs/virtfsdir.cpp20
-rw-r--r--src/fs/virtfs/virtfsdir_unittest.cc38
-rw-r--r--src/fs/virtfs/virtfszip.cpp8
-rw-r--r--src/fs/virtfs/virtfszip_unittest.cc38
-rw-r--r--src/fs/virtfs/virtzipentry.cpp3
-rw-r--r--src/fs/virtfs/virtzipentry.h6
-rw-r--r--src/fs/virtfs/zip.cpp10
-rw-r--r--src/fs/virtfs/zip_unittest.cc16
13 files changed, 118 insertions, 73 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 22ef18bee..be0ca689b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -832,6 +832,7 @@ BASE_SRC += \
fs/physfs/virtfsphys.h
else
BASE_SRC += \
+ enums/fs/fsentrytype.h \
fs/virtfs/virtdirentry.cpp \
fs/virtfs/virtdirentry.h \
fs/virtfs/virtfileprivate.cpp \
@@ -839,6 +840,8 @@ BASE_SRC += \
fs/virtfs/virtfs.cpp \
fs/virtfs/virtfsdir.cpp \
fs/virtfs/virtfsdir.h \
+ fs/virtfs/virtfsentry.cpp \
+ fs/virtfs/virtfsentry.h \
fs/virtfs/virtfszip.cpp \
fs/virtfs/virtfszip.h \
fs/virtfs/virtzipentry.cpp \
diff --git a/src/enums/fs/fsentrytype.h b/src/enums/fs/fsentrytype.h
new file mode 100644
index 000000000..3bced6099
--- /dev/null
+++ b/src/enums/fs/fsentrytype.h
@@ -0,0 +1,33 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2017 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 ENUMS_FS_FSENTRYTYPE_H
+#define ENUMS_FS_FSENTRYTYPE_H
+
+#include "enums/simpletypes/enumdefines.h"
+
+enumStart(FsEntryType)
+{
+ Dir = 0,
+ Zip = 1,
+}
+enumEnd(FsEntryType);
+
+#endif // ENUMS_FS_FSENTRYTYPE_H
diff --git a/src/fs/virtfs/virtdirentry.cpp b/src/fs/virtfs/virtdirentry.cpp
index 1364bca8a..7481e2a29 100644
--- a/src/fs/virtfs/virtdirentry.cpp
+++ b/src/fs/virtfs/virtdirentry.cpp
@@ -25,9 +25,10 @@
VirtDirEntry::VirtDirEntry(const std::string &userDir,
const std::string &rootDir) :
- mUserDir(userDir),
- mRootDir(rootDir)
+ VirtFsEntry(FsEntryType::Dir),
+ mUserDir(userDir)
{
+ root = rootDir;
}
VirtDirEntry::~VirtDirEntry()
diff --git a/src/fs/virtfs/virtdirentry.h b/src/fs/virtfs/virtdirentry.h
index 88ab89366..013c63a6e 100644
--- a/src/fs/virtfs/virtdirentry.h
+++ b/src/fs/virtfs/virtdirentry.h
@@ -22,11 +22,13 @@
#define UTILS_VIRTDIRENTRY_H
#ifndef USE_PHYSFS
+#include "fs/virtfs/virtfsentry.h"
+
#include <string>
#include "localconsts.h"
-struct VirtDirEntry final
+struct VirtDirEntry final : public VirtFsEntry
{
VirtDirEntry(const std::string &userDir,
const std::string &rootDir);
@@ -36,7 +38,6 @@ struct VirtDirEntry final
~VirtDirEntry();
std::string mUserDir;
- std::string mRootDir;
};
#endif // USE_PHYSFS
diff --git a/src/fs/virtfs/virtfs.cpp b/src/fs/virtfs/virtfs.cpp
index 1069b8f7e..aa2f4d57c 100644
--- a/src/fs/virtfs/virtfs.cpp
+++ b/src/fs/virtfs/virtfs.cpp
@@ -28,6 +28,7 @@
#include "fs/virtlist.h"
#include "fs/virtfs/virtdirentry.h"
+#include "fs/virtfs/virtfsentry.h"
#include "fs/virtfs/virtfsdir.h"
#include "fs/virtfs/virtfszip.h"
@@ -37,6 +38,11 @@
const char *dirSeparator = nullptr;
+namespace
+{
+ std::vector<VirtFsEntry*> mEntries;
+} // namespace
+
namespace VirtFs
{
void init(const std::string &restrict name)
diff --git a/src/fs/virtfs/virtfsdir.cpp b/src/fs/virtfs/virtfsdir.cpp
index fcb433d64..a269d7bec 100644
--- a/src/fs/virtfs/virtfsdir.cpp
+++ b/src/fs/virtfs/virtfsdir.cpp
@@ -77,7 +77,7 @@ namespace VirtFsDir
if (entry == nullptr)
return nullptr;
- const std::string path = entry->mRootDir + filename;
+ const std::string path = entry->root + filename;
const int fd = open(path.c_str(),
mode,
S_IRUSR | S_IWUSR);
@@ -97,7 +97,7 @@ namespace VirtFsDir
VirtFile *openReadDirEntry(VirtDirEntry *const entry,
const std::string &filename)
{
- const std::string path = entry->mRootDir + filename;
+ const std::string path = entry->root + filename;
const int fd = open(path.c_str(),
O_RDONLY,
S_IRUSR | S_IWUSR);
@@ -117,7 +117,7 @@ namespace VirtFsDir
{
FOR_EACH (std::vector<VirtDirEntry*>::const_iterator, it, mEntries)
{
- if ((*it)->mRootDir == root)
+ if ((*it)->root == root)
return *it;
}
return nullptr;
@@ -128,7 +128,7 @@ namespace VirtFsDir
FOR_EACH (std::vector<VirtDirEntry*>::const_iterator, it, mEntries)
{
VirtDirEntry *const entry = *it;
- if (Files::existsLocal(entry->mRootDir + path))
+ if (Files::existsLocal(entry->root + path))
return entry;
}
return nullptr;
@@ -229,7 +229,7 @@ namespace VirtFsDir
FOR_EACH (std::vector<VirtDirEntry*>::iterator, it, mEntries)
{
VirtDirEntry *const entry = *it;
- if (entry->mRootDir == oldDir)
+ if (entry->root == oldDir)
{
logger->log("Remove virtual directory: " + oldDir);
mEntries.erase(it);
@@ -256,7 +256,7 @@ namespace VirtFsDir
FOR_EACH (std::vector<VirtDirEntry*>::iterator, it, mEntries)
{
VirtDirEntry *const entry = *it;
- if (entry->mRootDir == oldDir)
+ if (entry->root == oldDir)
{
logger->log("Remove virtual directory: " + oldDir);
mEntries.erase(it);
@@ -335,7 +335,7 @@ namespace VirtFsDir
FOR_EACH (std::vector<VirtDirEntry*>::iterator, it, mEntries)
{
VirtDirEntry *const entry = *it;
- const std::string path = entry->mRootDir + filename;
+ const std::string path = entry->root + filename;
if (Files::existsLocal(path))
return entry->mUserDir;
}
@@ -354,7 +354,7 @@ namespace VirtFsDir
FOR_EACH (std::vector<VirtDirEntry*>::iterator, it, mEntries)
{
VirtDirEntry *const entry = *it;
- if (Files::existsLocal(entry->mRootDir + name))
+ if (Files::existsLocal(entry->root + name))
return true;
}
return false;
@@ -381,7 +381,7 @@ namespace VirtFsDir
{
VirtDirEntry *const entry = *it;
StringVect files;
- std::string path = entry->mRootDir + dirName;
+ std::string path = entry->root + dirName;
if (findLast(path, std::string(dirSeparator)) == false)
path += dirSeparator;
const struct dirent *next_file = nullptr;
@@ -437,7 +437,7 @@ namespace VirtFsDir
FOR_EACH (std::vector<VirtDirEntry*>::iterator, it, mEntries)
{
VirtDirEntry *const entry = *it;
- std::string path = entry->mRootDir + dirName;
+ std::string path = entry->root + dirName;
if (findLast(path, std::string(dirSeparator)) == false)
path += dirSeparator;
diff --git a/src/fs/virtfs/virtfsdir_unittest.cc b/src/fs/virtfs/virtfsdir_unittest.cc
index c70d9cc52..4923c105c 100644
--- a/src/fs/virtfs/virtfsdir_unittest.cc
+++ b/src/fs/virtfs/virtfsdir_unittest.cc
@@ -59,7 +59,7 @@ TEST_CASE("VirtFsDir addToSearchPath")
REQUIRE(VirtFsDir::searchEntryByRoot("dir1/") != nullptr);
REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir1/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir1");
}
@@ -71,7 +71,7 @@ TEST_CASE("VirtFsDir addToSearchPath")
REQUIRE(VirtFsDir::searchEntryByRoot("dir1/") != nullptr);
REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir1/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir1/");
}
@@ -87,8 +87,8 @@ TEST_CASE("VirtFsDir addToSearchPath")
REQUIRE(VirtFsDir::searchEntryByRoot("dir2/") != nullptr);
REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
REQUIRE(VirtFsDir::getEntries().size() == 2);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir2/");
- REQUIRE(VirtFsDir::getEntries()[1]->mRootDir == "dir1/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir2/");
+ REQUIRE(VirtFsDir::getEntries()[1]->root == "dir1/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir2");
REQUIRE(VirtFsDir::getEntries()[1]->mUserDir == "dir1");
}
@@ -105,8 +105,8 @@ TEST_CASE("VirtFsDir addToSearchPath")
REQUIRE(VirtFsDir::searchEntryByRoot("dir2/") != nullptr);
REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
REQUIRE(VirtFsDir::getEntries().size() == 2);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir1/");
- REQUIRE(VirtFsDir::getEntries()[1]->mRootDir == "dir2/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
+ REQUIRE(VirtFsDir::getEntries()[1]->root == "dir2/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir1/");
REQUIRE(VirtFsDir::getEntries()[1]->mUserDir == "dir2");
}
@@ -127,11 +127,11 @@ TEST_CASE("VirtFsDir addToSearchPath")
REQUIRE(VirtFsDir::searchEntryByRoot("dir3/test/") != nullptr);
REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
REQUIRE(VirtFsDir::getEntries().size() == 3);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir1/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir1");
- REQUIRE(VirtFsDir::getEntries()[1]->mRootDir == "dir2/");
+ REQUIRE(VirtFsDir::getEntries()[1]->root == "dir2/");
REQUIRE(VirtFsDir::getEntries()[1]->mUserDir == "dir2");
- REQUIRE(VirtFsDir::getEntries()[2]->mRootDir == "dir3/test/");
+ REQUIRE(VirtFsDir::getEntries()[2]->root == "dir3/test/");
REQUIRE(VirtFsDir::getEntries()[2]->mUserDir == "dir3/test");
}
@@ -151,11 +151,11 @@ TEST_CASE("VirtFsDir addToSearchPath")
REQUIRE(VirtFsDir::searchEntryByRoot("dir3/test/") != nullptr);
REQUIRE(VirtFsDir::searchEntryByRoot("test/") == nullptr);
REQUIRE(VirtFsDir::getEntries().size() == 3);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir3/test/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir3/test/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir3/test");
- REQUIRE(VirtFsDir::getEntries()[1]->mRootDir == "dir1/");
+ REQUIRE(VirtFsDir::getEntries()[1]->root == "dir1/");
REQUIRE(VirtFsDir::getEntries()[1]->mUserDir == "dir1");
- REQUIRE(VirtFsDir::getEntries()[2]->mRootDir == "dir2/");
+ REQUIRE(VirtFsDir::getEntries()[2]->root == "dir2/");
REQUIRE(VirtFsDir::getEntries()[2]->mUserDir == "dir2");
}
@@ -198,20 +198,20 @@ TEST_CASE("VirtFsDir removeFromSearchPath")
REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir2"));
REQUIRE(VirtFsDir::removeFromSearchPath("dir1"));
REQUIRE(VirtFsDir::getEntries().size() == 2);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir3/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir3/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir3");
- REQUIRE(VirtFsDir::getEntries()[1]->mRootDir == "dir2/dir3/");
+ REQUIRE(VirtFsDir::getEntries()[1]->root == "dir2/dir3/");
REQUIRE(VirtFsDir::getEntries()[1]->mUserDir == "dir2/dir3");
REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir1"));
REQUIRE(VirtFsDir::getEntries().size() == 2);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir3/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir3/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir3");
- REQUIRE(VirtFsDir::getEntries()[1]->mRootDir == "dir2/dir3/");
+ REQUIRE(VirtFsDir::getEntries()[1]->root == "dir2/dir3/");
REQUIRE(VirtFsDir::getEntries()[1]->mUserDir == "dir2/dir3");
REQUIRE(VirtFsDir::removeFromSearchPath("dir2/dir3"));
REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir2/dir3/"));
REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir3/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir3/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir3");
}
@@ -221,7 +221,7 @@ TEST_CASE("VirtFsDir removeFromSearchPath")
Append_true,
SkipError_true));
REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir1/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir1");
REQUIRE_THROWS(VirtFsDir::removeFromSearchPath("dir2"));
REQUIRE(VirtFsDir::removeFromSearchPath("dir1"));
@@ -230,7 +230,7 @@ TEST_CASE("VirtFsDir removeFromSearchPath")
Append_true,
SkipError_true));
REQUIRE(VirtFsDir::getEntries().size() == 1);
- REQUIRE(VirtFsDir::getEntries()[0]->mRootDir == "dir1/");
+ REQUIRE(VirtFsDir::getEntries()[0]->root == "dir1/");
REQUIRE(VirtFsDir::getEntries()[0]->mUserDir == "dir1");
}
diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp
index 437a81466..8ee39a8d9 100644
--- a/src/fs/virtfs/virtfszip.cpp
+++ b/src/fs/virtfs/virtfszip.cpp
@@ -53,7 +53,7 @@ namespace VirtFsZip
{
FOR_EACH (std::vector<VirtZipEntry*>::const_iterator, it, mEntries)
{
- if ((*it)->mArchiveName == archiveName)
+ if ((*it)->root == archiveName)
return *it;
}
return nullptr;
@@ -195,7 +195,7 @@ namespace VirtFsZip
FOR_EACH (std::vector<VirtZipEntry*>::iterator, it, mEntries)
{
VirtZipEntry *const entry = *it;
- if (entry->mArchiveName == oldDir)
+ if (entry->root == oldDir)
{
logger->log("Remove virtual zip: " + oldDir);
mEntries.erase(it);
@@ -220,7 +220,7 @@ namespace VirtFsZip
FOR_EACH (std::vector<VirtZipEntry*>::iterator, it, mEntries)
{
VirtZipEntry *const entry = *it;
- if (entry->mArchiveName == oldDir)
+ if (entry->root == oldDir)
{
logger->log("Remove virtual zip: " + oldDir);
mEntries.erase(it);
@@ -278,7 +278,7 @@ namespace VirtFsZip
VirtZipEntry *restrict const entry = searchZipEntryByNameWithDir(
filename);
if (entry != nullptr)
- return entry->mArchiveName;
+ return entry->root;
return std::string();
}
diff --git a/src/fs/virtfs/virtfszip_unittest.cc b/src/fs/virtfs/virtfszip_unittest.cc
index 59974e32e..9a3f9a491 100644
--- a/src/fs/virtfs/virtfszip_unittest.cc
+++ b/src/fs/virtfs/virtfszip_unittest.cc
@@ -60,7 +60,7 @@ TEST_CASE("VirtFsZip addToSearchPath")
REQUIRE(VirtFsZip::searchEntryByArchive(
prefix + "file2.zip") == nullptr);
REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test.zip");
}
@@ -73,7 +73,7 @@ TEST_CASE("VirtFsZip addToSearchPath")
REQUIRE(VirtFsZip::searchEntryByArchive(
prefix + "file2.zip") == nullptr);
REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test.zip");
}
@@ -90,9 +90,9 @@ TEST_CASE("VirtFsZip addToSearchPath")
REQUIRE(VirtFsZip::searchEntryByArchive(
prefix + "test3.zip") == nullptr);
REQUIRE(VirtFsZip::getEntries().size() == 2);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test2.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[1]->root ==
prefix + "test.zip");
}
@@ -109,9 +109,9 @@ TEST_CASE("VirtFsZip addToSearchPath")
REQUIRE(VirtFsZip::searchEntryByArchive(
prefix + "test3.zip") == nullptr);
REQUIRE(VirtFsZip::getEntries().size() == 2);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[1]->root ==
prefix + "test2.zip");
}
@@ -132,11 +132,11 @@ TEST_CASE("VirtFsZip addToSearchPath")
REQUIRE(VirtFsZip::searchEntryByArchive(
prefix + "test4.zip") == nullptr);
REQUIRE(VirtFsZip::getEntries().size() == 3);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[1]->root ==
prefix + "test2.zip");
- REQUIRE(VirtFsZip::getEntries()[2]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[2]->root ==
prefix + "test3.zip");
}
@@ -157,11 +157,11 @@ TEST_CASE("VirtFsZip addToSearchPath")
REQUIRE(VirtFsZip::searchEntryByArchive(
prefix + "test4.zip") == nullptr);
REQUIRE(VirtFsZip::getEntries().size() == 3);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test3.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[1]->root ==
prefix + "test.zip");
- REQUIRE(VirtFsZip::getEntries()[2]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[2]->root ==
prefix + "test2.zip");
}
@@ -205,20 +205,20 @@ TEST_CASE("VirtFsZip removeFromSearchPath")
REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(prefix + "test4.zip"));
REQUIRE(VirtFsZip::removeFromSearchPath(prefix + "test.zip"));
REQUIRE(VirtFsZip::getEntries().size() == 2);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test3.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[1]->root ==
prefix + "test2.zip");
REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(prefix + "test.zip"));
REQUIRE(VirtFsZip::getEntries().size() == 2);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test3.zip");
- REQUIRE(VirtFsZip::getEntries()[1]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[1]->root ==
prefix + "test2.zip");
REQUIRE(VirtFsZip::removeFromSearchPath(prefix + "//test2.zip"));
REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(prefix + "test2.zip"));
REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test3.zip");
}
@@ -227,7 +227,7 @@ TEST_CASE("VirtFsZip removeFromSearchPath")
REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "\\test.zip",
Append_true));
REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test.zip");
REQUIRE_THROWS(VirtFsZip::removeFromSearchPath(prefix + "test2.zip"));
REQUIRE(VirtFsZip::removeFromSearchPath(prefix + "\\test.zip"));
@@ -235,7 +235,7 @@ TEST_CASE("VirtFsZip removeFromSearchPath")
REQUIRE(VirtFsZip::addToSearchPathSilent(prefix + "test.zip",
Append_true));
REQUIRE(VirtFsZip::getEntries().size() == 1);
- REQUIRE(VirtFsZip::getEntries()[0]->mArchiveName ==
+ REQUIRE(VirtFsZip::getEntries()[0]->root ==
prefix + "test.zip");
}
diff --git a/src/fs/virtfs/virtzipentry.cpp b/src/fs/virtfs/virtzipentry.cpp
index fffe4fc5f..68b44ef4d 100644
--- a/src/fs/virtfs/virtzipentry.cpp
+++ b/src/fs/virtfs/virtzipentry.cpp
@@ -29,9 +29,10 @@
#include "debug.h"
VirtZipEntry::VirtZipEntry(const std::string &restrict archiveName) :
- mArchiveName(archiveName),
+ VirtFsEntry(FsEntryType::Zip),
mHeaders()
{
+ root = archiveName;
}
VirtZipEntry::~VirtZipEntry()
diff --git a/src/fs/virtfs/virtzipentry.h b/src/fs/virtfs/virtzipentry.h
index 6cd29f76e..5114d99bf 100644
--- a/src/fs/virtfs/virtzipentry.h
+++ b/src/fs/virtfs/virtzipentry.h
@@ -22,6 +22,8 @@
#define UTILS_VIRTZIPENTRY_H
#ifndef USE_PHYSFS
+#include "fs/virtfs/virtfsentry.h"
+
#include <string>
#include <vector>
@@ -29,7 +31,7 @@
struct ZipLocalHeader;
-struct VirtZipEntry final
+struct VirtZipEntry final : public VirtFsEntry
{
explicit VirtZipEntry(const std::string &restrict archiveName);
@@ -37,8 +39,6 @@ struct VirtZipEntry final
~VirtZipEntry();
- std::string mArchiveName;
-
std::vector<ZipLocalHeader*> mHeaders;
std::vector<std::string> mDirs;
};
diff --git a/src/fs/virtfs/zip.cpp b/src/fs/virtfs/zip.cpp
index b1bc45439..3a4e349dc 100644
--- a/src/fs/virtfs/zip.cpp
+++ b/src/fs/virtfs/zip.cpp
@@ -57,7 +57,7 @@ namespace Zip
reportAlways("Entry is null.");
return false;
}
- const std::string archiveName = entry->mArchiveName;
+ const std::string archiveName = entry->root;
std::vector<ZipLocalHeader*> &restrict headers = entry->mHeaders;
std::vector<std::string> &restrict dirs = entry->mDirs;
FILE *restrict const arcFile = fopen(archiveName.c_str(),
@@ -215,12 +215,12 @@ namespace Zip
return nullptr;
}
FILE *restrict const arcFile = fopen(
- header->zipEntry->mArchiveName.c_str(),
+ header->zipEntry->root.c_str(),
"r");
if (arcFile == nullptr)
{
reportAlways("Can't open zip file %s",
- header->zipEntry->mArchiveName.c_str());
+ header->zipEntry->root.c_str());
return nullptr;
}
@@ -231,7 +231,7 @@ namespace Zip
compressSize)
{
reportAlways("Read zip compressed file error from archive: %s",
- header->zipEntry->mArchiveName.c_str());
+ header->zipEntry->root.c_str());
fclose(arcFile);
delete [] buf;
return nullptr;
@@ -269,7 +269,7 @@ namespace Zip
int ret = inflateInit2(&strm, -MAX_WBITS);
if (ret != Z_OK)
{
- reportZlibError(header->zipEntry->mArchiveName, ret);
+ reportZlibError(header->zipEntry->root, ret);
delete [] in;
delete [] out;
return nullptr;
diff --git a/src/fs/virtfs/zip_unittest.cc b/src/fs/virtfs/zip_unittest.cc
index 763bcc2bd..35d4b1f8e 100644
--- a/src/fs/virtfs/zip_unittest.cc
+++ b/src/fs/virtfs/zip_unittest.cc
@@ -51,7 +51,7 @@ TEST_CASE("Zip readArchiveInfo")
REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 2);
- REQUIRE(entry->mArchiveName == name);
+ REQUIRE(entry->root == name);
REQUIRE(headers[0]->fileName == "dir/hide.png");
REQUIRE(headers[0]->compressSize == 365);
REQUIRE(headers[0]->uncompressSize == 368);
@@ -71,7 +71,7 @@ TEST_CASE("Zip readArchiveInfo")
REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 11);
- REQUIRE(entry->mArchiveName == name);
+ REQUIRE(entry->root == name);
REQUIRE(headers[0]->fileName == "test.txt");
REQUIRE(headers[0]->compressSize == 17);
REQUIRE(headers[0]->uncompressSize == 23);
@@ -128,7 +128,7 @@ TEST_CASE("Zip readArchiveInfo")
REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 2);
- REQUIRE(entry->mArchiveName == name);
+ REQUIRE(entry->root == name);
REQUIRE(headers[0]->fileName == "test.txt");
REQUIRE(headers[0]->compressSize == 17);
REQUIRE(headers[0]->uncompressSize == 23);
@@ -147,7 +147,7 @@ TEST_CASE("Zip readArchiveInfo")
std::vector<ZipLocalHeader*> &headers = entry->mHeaders;
REQUIRE(Zip::readArchiveInfo(entry));
- REQUIRE(entry->mArchiveName == name);
+ REQUIRE(entry->root == name);
REQUIRE(headers.size() == 0);
delete entry;
@@ -178,7 +178,7 @@ TEST_CASE("Zip readCompressedFile")
REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 11);
- REQUIRE(entry->mArchiveName == name);
+ REQUIRE(entry->root == name);
// test.txt
uint8_t *const buf = Zip::readCompressedFile(headers[0]);
REQUIRE(buf != nullptr);
@@ -211,7 +211,7 @@ TEST_CASE("Zip readFile")
REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 2);
- REQUIRE(entry->mArchiveName == name);
+ REQUIRE(entry->root == name);
for (int f = 0; f < 2; f ++)
{
logger->log("test header: %s, %u, %u",
@@ -234,7 +234,7 @@ TEST_CASE("Zip readFile")
REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 11);
- REQUIRE(entry->mArchiveName == name);
+ REQUIRE(entry->root == name);
// test.txt
uint8_t *buf = Zip::readFile(headers[0]);
REQUIRE(buf != nullptr);
@@ -264,7 +264,7 @@ TEST_CASE("Zip readFile")
REQUIRE(Zip::readArchiveInfo(entry));
REQUIRE(headers.size() == 2);
- REQUIRE(entry->mArchiveName == name);
+ REQUIRE(entry->root == name);
for (int f = 0; f < 2; f ++)
{
logger->log("test header: %s, %u, %u",