diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-04-24 19:27:07 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-04-24 19:27:07 +0300 |
commit | 6f58d1ee37041da28562d09757a9f653109f5677 (patch) | |
tree | 494b990338727f2adfdc7d7c6e46558be696aa29 /src/fs/virtfs/virtfszip.cpp | |
parent | d1b635ebf238fac5911fde8982d067ee4ffffe3a (diff) | |
download | manaverse-6f58d1ee37041da28562d09757a9f653109f5677.tar.gz manaverse-6f58d1ee37041da28562d09757a9f653109f5677.tar.bz2 manaverse-6f58d1ee37041da28562d09757a9f653109f5677.tar.xz manaverse-6f58d1ee37041da28562d09757a9f653109f5677.zip |
Improve VirtFs::getFilesWithDir.
Diffstat (limited to 'src/fs/virtfs/virtfszip.cpp')
-rw-r--r-- | src/fs/virtfs/virtfszip.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp index bf7e8fba2..9b53e86aa 100644 --- a/src/fs/virtfs/virtfszip.cpp +++ b/src/fs/virtfs/virtfszip.cpp @@ -75,6 +75,7 @@ namespace VirtFsZip ptr->openAppend = &VirtFsZip::openAppend; ptr->loadFile = &VirtFsZip::loadFile; ptr->getFiles = &VirtFsZip::getFiles; + ptr->getFilesWithDir = &VirtFsZip::getFilesWithDir; ptr->getDirs = &VirtFsZip::getDirs; ptr->rwops_seek = &VirtFsZip::rwops_seek; ptr->rwops_read = &VirtFsZip::rwops_read; @@ -288,6 +289,98 @@ namespace VirtFsZip } } + void getFilesWithDir(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(pathJoin(dirName, 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(pathJoin(dirName, fileName)); + } + } + } + } + } + void getDirs(VirtFsEntry *restrict const entry, const std::string &dirName, StringVect &names) |