summaryrefslogtreecommitdiffstats
path: root/logic/MMCZip.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-04-19 04:19:29 +0200
committerPetr Mrázek <peterix@gmail.com>2015-04-19 16:14:32 +0200
commitc7c81463fd3ab01c9e096f75e7e8ad8b50902a98 (patch)
treeab19d0316cd293bcc05bc6b1b6e937c858814b90 /logic/MMCZip.cpp
parent6cfac115b1f18b9ff5130b2b9a6d5e2fcf052e6c (diff)
downloadMultiMC-c7c81463fd3ab01c9e096f75e7e8ad8b50902a98.tar
MultiMC-c7c81463fd3ab01c9e096f75e7e8ad8b50902a98.tar.gz
MultiMC-c7c81463fd3ab01c9e096f75e7e8ad8b50902a98.tar.lz
MultiMC-c7c81463fd3ab01c9e096f75e7e8ad8b50902a98.tar.xz
MultiMC-c7c81463fd3ab01c9e096f75e7e8ad8b50902a98.zip
GH-885 export dialog for filtering exported files
Includes implementation of a separator based prefix tree and some related bits
Diffstat (limited to 'logic/MMCZip.cpp')
-rw-r--r--logic/MMCZip.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/logic/MMCZip.cpp b/logic/MMCZip.cpp
index e2c6d1f5..75f49ced 100644
--- a/logic/MMCZip.cpp
+++ b/logic/MMCZip.cpp
@@ -89,7 +89,7 @@ bool compressFile(QuaZip *zip, QString fileName, QString fileDest)
return true;
}
-bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QString>& added, QString prefix)
+bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QString>& added, QString prefix, const SeparatorPrefixTree <'/'> * blacklist)
{
if (!zip) return false;
if (zip->getMode()!=QuaZip::mdCreate && zip->getMode()!=QuaZip::mdAppend && zip->getMode()!=QuaZip::mdAdd)
@@ -106,13 +106,17 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QStr
QDir origDirectory(origDir);
if (dir != origDir)
{
- QuaZipFile dirZipFile(zip);
- auto dirPrefix = PathCombine(prefix, origDirectory.relativeFilePath(dir)) + "/";
- if (!dirZipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(dirPrefix, dir), 0, 0, 0))
+ QString internalDirName = origDirectory.relativeFilePath(dir);
+ if(!blacklist || !blacklist->covers(internalDirName))
{
- return false;
+ QuaZipFile dirZipFile(zip);
+ auto dirPrefix = PathCombine(prefix, origDirectory.relativeFilePath(dir)) + "/";
+ if (!dirZipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(dirPrefix, dir), 0, 0, 0))
+ {
+ return false;
+ }
+ dirZipFile.close();
}
- dirZipFile.close();
}
QFileInfoList files = directory.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden);
@@ -122,7 +126,7 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QStr
{
continue;
}
- if(!compressSubDir(zip,file.absoluteFilePath(),origDir, added, prefix))
+ if(!compressSubDir(zip,file.absoluteFilePath(),origDir, added, prefix, blacklist))
{
return false;
}
@@ -142,6 +146,10 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QStr
}
QString filename = origDirectory.relativeFilePath(file.absoluteFilePath());
+ if(blacklist && blacklist->covers(filename))
+ {
+ continue;
+ }
if(prefix.size())
{
filename = PathCombine(prefix, filename);
@@ -305,7 +313,7 @@ bool MMCZip::metaInfFilter(QString key)
return true;
}
-bool MMCZip::compressDir(QString zipFile, QString dir, QString prefix)
+bool MMCZip::compressDir(QString zipFile, QString dir, QString prefix, const SeparatorPrefixTree <'/'> * blacklist)
{
QuaZip zip(zipFile);
QDir().mkpath(QFileInfo(zipFile).absolutePath());
@@ -316,7 +324,7 @@ bool MMCZip::compressDir(QString zipFile, QString dir, QString prefix)
}
QSet<QString> added;
- if (!compressSubDir(&zip, dir, dir, added, prefix))
+ if (!compressSubDir(&zip, dir, dir, added, prefix, blacklist))
{
QFile::remove(zipFile);
return false;