From 50b8412a2690e8b2cbbbbc5c8481e45df084603d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 25 May 2017 01:24:27 +0200 Subject: NOISSUE do not try to restore file permissions when importing modpacks --- api/logic/InstanceImportTask.cpp | 2 +- api/logic/MMCZip.cpp | 26 +++++++++++++++----------- api/logic/MMCZip.h | 30 ++++++++++++++++++------------ 3 files changed, 34 insertions(+), 24 deletions(-) (limited to 'api') diff --git a/api/logic/InstanceImportTask.cpp b/api/logic/InstanceImportTask.cpp index f1b3d5aa..13ad863e 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()); + m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, m_archivePath, extractDir.absolutePath(), MMCZip::Option::NoPermissions); connect(&m_extractFutureWatcher, &QFutureWatcher::finished, this, &InstanceImportTask::extractFinished); connect(&m_extractFutureWatcher, &QFutureWatcher::canceled, this, &InstanceImportTask::extractAborted); m_extractFutureWatcher.setFuture(m_extractFuture); diff --git a/api/logic/MMCZip.cpp b/api/logic/MMCZip.cpp index 50e352b4..6b4a9ff8 100644 --- a/api/logic/MMCZip.cpp +++ b/api/logic/MMCZip.cpp @@ -45,11 +45,6 @@ bool copyData(QIODevice &inFile, QIODevice &outFile) return true; } -QStringList MMCZip::extractDir(QString fileCompressed, QString dir) -{ - return JlCompress::extractDir(fileCompressed, dir); -} - bool compressFile(QuaZip *zip, QString fileName, QString fileDest) { if (!zip) @@ -394,7 +389,7 @@ bool removeFile(QStringList listFile) return ret; } -bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest) +bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest, MMCZip::Options opts) { if(!zip) return false; @@ -409,7 +404,6 @@ bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fi if (!inFile.open(QIODevice::ReadOnly) || inFile.getZipError() != UNZ_OK) return false; - // Controllo esistenza cartella file risultato QDir curDir; if (fileDest.endsWith('/')) { @@ -433,7 +427,7 @@ bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fi QFile::Permissions srcPerm = info.getPermissions(); if (fileDest.endsWith('/') && QFileInfo(fileDest).isDir()) { - if (srcPerm != 0) + if (!opts.testFlag(Option::NoPermissions) && srcPerm != 0) { QFile(fileDest).setPermissions(srcPerm); } @@ -460,14 +454,14 @@ bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fi return false; } - if (srcPerm != 0) + if (!opts.testFlag(Option::NoPermissions) && srcPerm != 0) { outFile.setPermissions(srcPerm); } return true; } -QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target) +QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target, MMCZip::Options opts) { QDir directory(target); QStringList extracted; @@ -488,7 +482,7 @@ QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QSt { absFilePath += "/"; } - if (!extractFile(zip, "", absFilePath)) + if (!MMCZip::extractFile(zip, "", absFilePath, opts)) { removeFile(extracted); return QStringList(); @@ -497,3 +491,13 @@ QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QSt } while (zip->goToNextFile()); return extracted; } + +QStringList MMCZip::extractDir(QString fileCompressed, QString dir, MMCZip::Options opts) +{ + QuaZip zip(fileCompressed); + if (!zip.open(QuaZip::mdUnzip)) + { + return {}; + } + return MMCZip::extractSubDir(&zip, "", dir, opts); +} diff --git a/api/logic/MMCZip.h b/api/logic/MMCZip.h index f350e668..7608352c 100644 --- a/api/logic/MMCZip.h +++ b/api/logic/MMCZip.h @@ -49,16 +49,6 @@ namespace MMCZip */ bool MULTIMC_LOGIC_EXPORT createModdedJar(QString sourceJarPath, QString targetJarPath, const QList& mods); - /** - * Extract a whole archive. - * - * \param fileCompressed The name of the archive. - * \param dir The directory to extract to, the current directory if - * left empty. - * \return The list of the full paths of the files extracted, empty on failure. - */ - QStringList MULTIMC_LOGIC_EXPORT extractDir(QString fileCompressed, QString dir = QString()); - /** * Find a single file in archive by file name (not path) * @@ -74,15 +64,31 @@ 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); + 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); + QStringList MULTIMC_LOGIC_EXPORT extractSubDir(QuaZip *zip, const QString & subdir, const QString &target, Options opts = 0); + + /** + * Extract a whole archive. + * + * \param fileCompressed The name of the archive. + * \param dir The directory to extract to, the current directory if left empty. + * \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); + } -- cgit v1.2.3