summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/virtfszip.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-04-24 17:04:47 +0300
committerAndrei Karas <akaras@inbox.ru>2017-04-24 17:04:47 +0300
commitd1b635ebf238fac5911fde8982d067ee4ffffe3a (patch)
tree788b6c6733550f5a54d5b3552a909a141af1223c /src/fs/virtfs/virtfszip.cpp
parent0835e09ee3a6c83ffa01454f2c05597e6195b07d (diff)
downloadmv-d1b635ebf238fac5911fde8982d067ee4ffffe3a.tar.gz
mv-d1b635ebf238fac5911fde8982d067ee4ffffe3a.tar.bz2
mv-d1b635ebf238fac5911fde8982d067ee4ffffe3a.tar.xz
mv-d1b635ebf238fac5911fde8982d067ee4ffffe3a.zip
Improve VirtFs::getDirs.
Diffstat (limited to 'src/fs/virtfs/virtfszip.cpp')
-rw-r--r--src/fs/virtfs/virtfszip.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp
index ae31f2606..bf7e8fba2 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->getDirs = &VirtFsZip::getDirs;
ptr->rwops_seek = &VirtFsZip::rwops_seek;
ptr->rwops_read = &VirtFsZip::rwops_read;
ptr->rwops_write = &VirtFsZip::rwops_write;
@@ -287,6 +288,98 @@ namespace VirtFsZip
}
}
+ void getDirs(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 == true)
+ 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 == true)
+ names.push_back(fileName);
+ }
+ }
+ }
+ }
+ }
+
bool isDirectory(VirtFsEntry *restrict const entry,
const std::string &dirName,
bool &isDirFlag)