diff options
author | Petr Mrázek <peterix@gmail.com> | 2017-05-29 01:32:28 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2017-05-31 09:20:24 +0200 |
commit | cdc9bed83f9110bdf41133a3489ed2fca543ee32 (patch) | |
tree | 19fe215b438f1b6d63b6b45a31b587496d8c4d8a | |
parent | 7acf1998eb0683860dc21fc740f1e6bd42f54169 (diff) | |
download | MultiMC-cdc9bed83f9110bdf41133a3489ed2fca543ee32.tar MultiMC-cdc9bed83f9110bdf41133a3489ed2fca543ee32.tar.gz MultiMC-cdc9bed83f9110bdf41133a3489ed2fca543ee32.tar.lz MultiMC-cdc9bed83f9110bdf41133a3489ed2fca543ee32.tar.xz MultiMC-cdc9bed83f9110bdf41133a3489ed2fca543ee32.zip |
NOISSUE move some zip utility functions back to quazip
It's not entirely clean yet.
-rw-r--r-- | api/logic/InstanceImportTask.cpp | 2 | ||||
-rw-r--r-- | api/logic/MMCZip.cpp | 163 | ||||
-rw-r--r-- | api/logic/MMCZip.h | 18 | ||||
-rw-r--r-- | api/logic/minecraft/launch/ExtractNatives.cpp | 3 | ||||
m--------- | libraries/quazip | 0 |
5 files changed, 18 insertions, 168 deletions
diff --git a/api/logic/InstanceImportTask.cpp b/api/logic/InstanceImportTask.cpp index 13ad863e..f1b3d5aa 100644 --- a/api/logic/InstanceImportTask.cpp +++ b/api/logic/InstanceImportTask.cpp @@ -99,7 +99,7 @@ void InstanceImportTask::extractAndTweak() QDir extractDir(m_stagingPath); qDebug() << "Attempting to create instance from" << m_archivePath; - m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, m_archivePath, extractDir.absolutePath(), MMCZip::Option::NoPermissions); + m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, m_archivePath, extractDir.absolutePath()); connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &InstanceImportTask::extractFinished); connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &InstanceImportTask::extractAborted); m_extractFutureWatcher.setFuture(m_extractFuture); diff --git a/api/logic/MMCZip.cpp b/api/logic/MMCZip.cpp index 6b4a9ff8..725aea71 100644 --- a/api/logic/MMCZip.cpp +++ b/api/logic/MMCZip.cpp @@ -24,67 +24,14 @@ see quazip/(un)MMCZip.h files for details. Basically it's the zlib license. */ #include <quazip.h> -#include <JlCompress.h> #include <quazipdir.h> +#include <quazipfile.h> +#include <JlCompress.h> #include "MMCZip.h" #include "FileSystem.h" #include <QDebug> -bool copyData(QIODevice &inFile, QIODevice &outFile) -{ - while (!inFile.atEnd()) - { - char buf[4096]; - qint64 readLen = inFile.read(buf, 4096); - if (readLen <= 0) - return false; - if (outFile.write(buf, readLen) != readLen) - return false; - } - return true; -} - -bool compressFile(QuaZip *zip, QString fileName, QString fileDest) -{ - if (!zip) - { - return false; - } - if (zip->getMode() != QuaZip::mdCreate && zip->getMode() != QuaZip::mdAppend && - zip->getMode() != QuaZip::mdAdd) - { - return false; - } - - QFile inFile; - inFile.setFileName(fileName); - if (!inFile.open(QIODevice::ReadOnly)) - { - return false; - } - - QuaZipFile outFile(zip); - if (!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileDest, inFile.fileName()))) - { - return false; - } - - if (!copyData(inFile, outFile) || outFile.getZipError() != UNZ_OK) - { - return false; - } - - outFile.close(); - if (outFile.getZipError() != UNZ_OK) - { - return false; - } - inFile.close(); - - return true; -} - bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QString>& added, QString prefix, const SeparatorPrefixTree <'/'> * blacklist) { if (!zip) return false; @@ -151,7 +98,7 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QStr filename = FS::PathCombine(prefix, filename); } added.insert(filename); - if (!compressFile(zip,file.absoluteFilePath(),filename)) + if (!JlCompress::compressFile(zip,file.absoluteFilePath(),filename)) { return false; } @@ -160,8 +107,7 @@ bool MMCZip::compressSubDir(QuaZip* zip, QString dir, QString origDir, QSet<QStr return true; } -bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained, - std::function<bool(QString)> filter) +bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained, std::function<bool(QString)> filter) { QuaZip modZip(from.filePath()); modZip.open(QuaZip::mdUnzip); @@ -199,7 +145,7 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &containe fileInsideMod.close(); return false; } - if (!copyData(fileInsideMod, zipOutFile)) + if (!JlCompress::copyData(fileInsideMod, zipOutFile)) { zipOutFile.close(); fileInsideMod.close(); @@ -247,8 +193,7 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const else if (mod.type() == Mod::MOD_SINGLEFILE) { auto filename = mod.filename(); - if (!compressFile(&zipOut, filename.absoluteFilePath(), - filename.fileName())) + if (!JlCompress::compressFile(&zipOut, filename.absoluteFilePath(), filename.fileName())) { zipOut.close(); QFile::remove(targetJarPath); @@ -264,7 +209,7 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QDir dir(what_to_zip); dir.cdUp(); QString parent_dir = dir.absolutePath(); - if (!compressSubDir(&zipOut, what_to_zip, parent_dir, addedFiles)) + if (!MMCZip::compressSubDir(&zipOut, what_to_zip, parent_dir, addedFiles)) { zipOut.close(); QFile::remove(targetJarPath); @@ -328,7 +273,7 @@ bool MMCZip::compressDir(QString zipFile, QString dir, QString prefix, const Sep } QSet<QString> added; - if (!compressSubDir(&zip, dir, dir, added, prefix, blacklist)) + if (!MMCZip::compressSubDir(&zip, dir, dir, added, prefix, blacklist)) { QFile::remove(zipFile); return false; @@ -379,89 +324,7 @@ bool MMCZip::findFilesInZip(QuaZip * zip, const QString & what, QStringList & re return !result.isEmpty(); } -bool removeFile(QStringList listFile) -{ - bool ret = true; - for (int i = 0; i < listFile.count(); i++) - { - ret &= QFile::remove(listFile.at(i)); - } - return ret; -} - -bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest, MMCZip::Options opts) -{ - if(!zip) - return false; - - if (zip->getMode() != QuaZip::mdUnzip) - return false; - - if (!fileName.isEmpty()) - zip->setCurrentFile(fileName); - - QuaZipFile inFile(zip); - if (!inFile.open(QIODevice::ReadOnly) || inFile.getZipError() != UNZ_OK) - return false; - - QDir curDir; - if (fileDest.endsWith('/')) - { - if (!curDir.mkpath(fileDest)) - { - return false; - } - } - else - { - if (!curDir.mkpath(QFileInfo(fileDest).absolutePath())) - { - return false; - } - } - - QuaZipFileInfo64 info; - if (!zip->getCurrentFileInfo(&info)) - return false; - - QFile::Permissions srcPerm = info.getPermissions(); - if (fileDest.endsWith('/') && QFileInfo(fileDest).isDir()) - { - if (!opts.testFlag(Option::NoPermissions) && srcPerm != 0) - { - QFile(fileDest).setPermissions(srcPerm); - } - return true; - } - - QFile outFile; - outFile.setFileName(fileDest); - if (!outFile.open(QIODevice::WriteOnly)) - return false; - - if (!copyData(inFile, outFile) || inFile.getZipError() != UNZ_OK) - { - outFile.close(); - removeFile(QStringList(fileDest)); - return false; - } - outFile.close(); - - inFile.close(); - if (inFile.getZipError() != UNZ_OK) - { - removeFile(QStringList(fileDest)); - return false; - } - - if (!opts.testFlag(Option::NoPermissions) && srcPerm != 0) - { - outFile.setPermissions(srcPerm); - } - return true; -} - -QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target, MMCZip::Options opts) +QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target) { QDir directory(target); QStringList extracted; @@ -482,9 +345,9 @@ QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QSt { absFilePath += "/"; } - if (!MMCZip::extractFile(zip, "", absFilePath, opts)) + if (!JlCompress::extractFile(zip, "", absFilePath)) { - removeFile(extracted); + JlCompress::removeFile(extracted); return QStringList(); } extracted.append(absFilePath); @@ -492,12 +355,12 @@ QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QSt return extracted; } -QStringList MMCZip::extractDir(QString fileCompressed, QString dir, MMCZip::Options opts) +QStringList MMCZip::extractDir(QString fileCompressed, QString dir) { QuaZip zip(fileCompressed); if (!zip.open(QuaZip::mdUnzip)) { return {}; } - return MMCZip::extractSubDir(&zip, "", dir, opts); + return MMCZip::extractSubDir(&zip, "", dir); } diff --git a/api/logic/MMCZip.h b/api/logic/MMCZip.h index 7608352c..ca8b349f 100644 --- a/api/logic/MMCZip.h +++ b/api/logic/MMCZip.h @@ -9,7 +9,7 @@ #include "multimc_logic_export.h" -class QuaZip; +#include <JlCompress.h> namespace MMCZip { @@ -64,22 +64,10 @@ namespace MMCZip */ bool MULTIMC_LOGIC_EXPORT findFilesInZip(QuaZip * zip, const QString & what, QStringList & result, const QString &root = QString()); - enum Option { - NoPermissions = 1 - }; - Q_DECLARE_FLAGS(Options, Option) - - /** - * Extract a single file to a destination - * - * \return true if it succeeds - */ - bool MULTIMC_LOGIC_EXPORT extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest, Options opts = 0); - /** * Extract a subdirectory from an archive */ - QStringList MULTIMC_LOGIC_EXPORT extractSubDir(QuaZip *zip, const QString & subdir, const QString &target, Options opts = 0); + QStringList MULTIMC_LOGIC_EXPORT extractSubDir(QuaZip *zip, const QString & subdir, const QString &target); /** * Extract a whole archive. @@ -89,6 +77,6 @@ namespace MMCZip * \param opts Extra options. * \return The list of the full paths of the files extracted, empty on failure. */ - QStringList MULTIMC_LOGIC_EXPORT extractDir(QString fileCompressed, QString dir, Options opts = 0); + QStringList MULTIMC_LOGIC_EXPORT extractDir(QString fileCompressed, QString dir); } diff --git a/api/logic/minecraft/launch/ExtractNatives.cpp b/api/logic/minecraft/launch/ExtractNatives.cpp index 9f36f8f4..f30dea89 100644 --- a/api/logic/minecraft/launch/ExtractNatives.cpp +++ b/api/logic/minecraft/launch/ExtractNatives.cpp @@ -18,7 +18,6 @@ #include <launch/LaunchTask.h> #include <quazip.h> -#include <JlCompress.h> #include <quazipdir.h> #include "MMCZip.h" #include "FileSystem.h" @@ -54,7 +53,7 @@ static bool unzipNatives(QString source, QString targetFolder, bool applyJnilibH name = replaceSuffix(name, ".jnilib", ".dylib"); } QString absFilePath = directory.absoluteFilePath(name); - if (!MMCZip::extractFile(&zip, "", absFilePath)) + if (!JlCompress::extractFile(&zip, "", absFilePath)) { return false; } diff --git a/libraries/quazip b/libraries/quazip -Subproject 2c40fc85b465b9af33424322de30e4fd09c5c0b +Subproject 8837555312a7f95dc5c4ce6474860b1c159d810 |