diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-04-24 03:35:02 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-04-24 04:35:35 +0300 |
commit | 0835e09ee3a6c83ffa01454f2c05597e6195b07d (patch) | |
tree | b3b79b7a8f58f2ff18ec66b17d1c39ddad085e11 /src/fs/virtfs/virtfszip.cpp | |
parent | 55458f743c3ff7e42288bc08033481d8464dca62 (diff) | |
download | plus-0835e09ee3a6c83ffa01454f2c05597e6195b07d.tar.gz plus-0835e09ee3a6c83ffa01454f2c05597e6195b07d.tar.bz2 plus-0835e09ee3a6c83ffa01454f2c05597e6195b07d.tar.xz plus-0835e09ee3a6c83ffa01454f2c05597e6195b07d.zip |
Improve VirtFs::getFiles.
Diffstat (limited to 'src/fs/virtfs/virtfszip.cpp')
-rw-r--r-- | src/fs/virtfs/virtfszip.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
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<VirtZipEntry*>(entry); + if (dirName == dirSeparator) + { + FOR_EACH (std::vector<ZipLocalHeader*>::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<std::string>::const_iterator, + it, + zipEntry->mDirs) + { + if (*it == dirName2) + { + found = true; + break; + } + } + if (found == false) + names.push_back(fileName); + } + } + } + else + { + FOR_EACH (std::vector<ZipLocalHeader*>::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<std::string>::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) |