From 0835e09ee3a6c83ffa01454f2c05597e6195b07d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 24 Apr 2017 03:35:02 +0300 Subject: Improve VirtFs::getFiles. --- src/fs/virtfs/virtfszip.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'src/fs/virtfs/virtfszip.cpp') diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp index f2cacc34f..ae31f2606 100644 --- a/src/fs/virtfs/virtfszip.cpp +++ b/src/fs/virtfs/virtfszip.cpp @@ -21,6 +21,7 @@ #include "fs/virtfs/virtfszip.h" #include "fs/virtfs/virtfile.h" +#include "fs/virtfs/virtfs.h" #include "fs/virtfs/virtfsfuncs.h" #include "fs/virtfs/virtfsziprwops.h" #include "fs/virtfs/virtlist.h" @@ -73,6 +74,7 @@ namespace VirtFsZip ptr->openWrite = &VirtFsZip::openWrite; ptr->openAppend = &VirtFsZip::openAppend; ptr->loadFile = &VirtFsZip::loadFile; + ptr->getFiles = &VirtFsZip::getFiles; ptr->rwops_seek = &VirtFsZip::rwops_seek; ptr->rwops_read = &VirtFsZip::rwops_read; ptr->rwops_write = &VirtFsZip::rwops_write; @@ -193,6 +195,98 @@ namespace VirtFsZip } } + void getFiles(VirtFsEntry *restrict const entry, + const std::string &dirName, + StringVect &names) + { + VirtZipEntry *const zipEntry = static_cast(entry); + if (dirName == dirSeparator) + { + FOR_EACH (std::vector::const_iterator, + it2, + zipEntry->mHeaders) + { + ZipLocalHeader *const header = *it2; + std::string fileName = header->fileName; + // skip subdirs from enumeration + const size_t idx = fileName.find(dirSeparator); + if (idx != std::string::npos) + fileName.erase(idx); + bool found(false); + FOR_EACH (StringVectCIter, itn, names) + { + if (*itn == fileName) + { + found = true; + break; + } + } + if (found == false) + { + std::string dirName2 = pathJoin(dirName, fileName); + if (findLast(dirName2, std::string(dirSeparator)) == false) + dirName2 += dirSeparator; + FOR_EACH (std::vector::const_iterator, + it, + zipEntry->mDirs) + { + if (*it == dirName2) + { + found = true; + break; + } + } + if (found == false) + names.push_back(fileName); + } + } + } + else + { + FOR_EACH (std::vector::const_iterator, + it2, + zipEntry->mHeaders) + { + ZipLocalHeader *const header = *it2; + std::string fileName = header->fileName; + if (findCutFirst(fileName, dirName) == true) + { + // skip subdirs from enumeration + const size_t idx = fileName.find(dirSeparator); + if (idx != std::string::npos) + fileName.erase(idx); + bool found(false); + FOR_EACH (StringVectCIter, itn, names) + { + if (*itn == fileName) + { + found = true; + break; + } + } + if (found == false) + { + std::string dirName2 = pathJoin(dirName, fileName); + if (findLast(dirName2, std::string(dirSeparator)) == false) + dirName2 += dirSeparator; + FOR_EACH (std::vector::const_iterator, + it, + zipEntry->mDirs) + { + if (*it == dirName2) + { + found = true; + break; + } + } + if (found == false) + names.push_back(fileName); + } + } + } + } + } + bool isDirectory(VirtFsEntry *restrict const entry, const std::string &dirName, bool &isDirFlag) -- cgit v1.2.3-70-g09d2