summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fs/virtfs/fsdir.cpp2
-rw-r--r--src/fs/virtfs/fszip.cpp14
-rw-r--r--src/fs/virtfs/virtfs1_unittest.cc74
3 files changed, 85 insertions, 5 deletions
diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp
index 966ab4025..37c5cc795 100644
--- a/src/fs/virtfs/fsdir.cpp
+++ b/src/fs/virtfs/fsdir.cpp
@@ -573,7 +573,7 @@ namespace FsDir
const std::string &dirName,
StringVect &names)
{
- const std::string path = entry->root + dirName;
+ const std::string path = entry->root + entry->subDir + dirName;
const struct dirent *next_file = nullptr;
DIR *const dir = opendir(path.c_str());
if (dir)
diff --git a/src/fs/virtfs/fszip.cpp b/src/fs/virtfs/fszip.cpp
index cc720f626..068b7ee45 100644
--- a/src/fs/virtfs/fszip.cpp
+++ b/src/fs/virtfs/fszip.cpp
@@ -317,7 +317,13 @@ namespace FsZip
StringVect &names)
{
ZipEntry *const zipEntry = static_cast<ZipEntry*>(entry);
- if (dirName == dirSeparator)
+ const std::string subDir = zipEntry->subDir;
+ std::string dirNameFull;
+ if (subDir != dirSeparator)
+ dirNameFull = pathJoin(subDir, dirName);
+ else
+ dirNameFull = dirName;
+ if (dirNameFull == dirSeparator)
{
FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
it2,
@@ -340,7 +346,7 @@ namespace FsZip
}
if (found == false)
{
- std::string dirName2 = pathJoin(dirName, fileName);
+ std::string dirName2 = pathJoin(dirNameFull, fileName);
if (findLast(dirName2, std::string(dirSeparator)) == false)
dirName2 += dirSeparator;
FOR_EACH (std::vector<std::string>::const_iterator,
@@ -366,7 +372,7 @@ namespace FsZip
{
ZipLocalHeader *const header = *it2;
std::string fileName = header->fileName;
- if (findCutFirst(fileName, dirName) == true)
+ if (findCutFirst(fileName, dirNameFull) == true)
{
// skip subdirs from enumeration
const size_t idx = fileName.find(dirSeparator);
@@ -383,7 +389,7 @@ namespace FsZip
}
if (found == false)
{
- std::string dirName2 = pathJoin(dirName, fileName);
+ std::string dirName2 = pathJoin(dirNameFull, fileName);
if (findLast(dirName2, std::string(dirSeparator)) ==
false)
{
diff --git a/src/fs/virtfs/virtfs1_unittest.cc b/src/fs/virtfs/virtfs1_unittest.cc
index c703e3717..a2c7f8590 100644
--- a/src/fs/virtfs/virtfs1_unittest.cc
+++ b/src/fs/virtfs/virtfs1_unittest.cc
@@ -3388,3 +3388,77 @@ TEST_CASE("VirtFs1 getFilesWithDir2")
VirtFs::deinit();
delete2(logger);
}
+
+TEST_CASE("VirtFs1 getFilesWithDir3")
+{
+ VirtFs::init(".");
+ logger = new Logger();
+ std::string name("data/test/test.zip");
+ std::string prefix;
+ if (Files::existsLocal(name) == false)
+ prefix = "../" + prefix;
+
+ VirtFs::mountZip2(prefix + "data/test/test2.zip",
+ "dir",
+ Append_false);
+
+ StringVect list;
+ VirtFs::getFilesWithDir("1", list);
+ REQUIRE(list.size() == 2);
+ REQUIRE(inList(list, "1", "file1.txt"));
+ REQUIRE(inList(list, "1", "test.txt"));
+ list.clear();
+
+ VirtFs::getFilesWithDir(dirSeparator, list);
+ REQUIRE(list.size() == 2);
+ REQUIRE(inList(list, dirSeparator, "dye.png"));
+ REQUIRE(inList(list, dirSeparator, "hide.png"));
+ list.clear();
+
+ VirtFs::unmountZip2(prefix + "data/test/test2.zip",
+ "dir");
+ VirtFs::deinit();
+ delete2(logger);
+}
+
+TEST_CASE("VirtFs1 getFilesWithDir4")
+{
+ VirtFs::init(".");
+ logger = new Logger();
+ std::string name("data/test/test.zip");
+ std::string prefix;
+ if (Files::existsLocal(name) == false)
+ prefix = "../" + prefix;
+ StringVect list;
+
+ SECTION("dir1")
+ {
+ VirtFs::mountDir2(prefix + "data/graphics",
+ "sprites",
+ Append_false);
+
+ VirtFs::getFilesWithDir("/", list);
+ REQUIRE(list.size() <= 16);
+ VirtFs::unmountDir2(prefix + "data/graphics",
+ "sprites");
+ }
+
+ SECTION("dir2")
+ {
+ VirtFs::mountDir2(prefix + "data",
+ "test",
+ Append_false);
+
+ VirtFs::getFilesWithDir("dir1", list);
+ REQUIRE(list.size() <= 6);
+ REQUIRE(list.size() >= 1);
+ REQUIRE(inList(list, "dir1", "file1.txt"));
+ list.clear();
+
+ VirtFs::unmountDir2(prefix + "data",
+ "test");
+ }
+
+ VirtFs::deinit();
+ delete2(logger);
+}