From a116778402bd98ee079488d8c5a27933369e9046 Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 1 Dec 2022 15:15:15 -0300 Subject: [PATCH] fix(Inst.Import): don't search inside 'overrides/' for the manifest It will never be there anyways, and saves a **bunch** of time when the overrides folder is big and we traverse all the tree when searching for the MMC 'instance.cfg' file. Signed-off-by: flow --- launcher/InstanceImportTask.cpp | 10 +++------- launcher/MMCZip.cpp | 27 ++++++++++++++++----------- launcher/MMCZip.h | 4 +++- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/launcher/InstanceImportTask.cpp b/launcher/InstanceImportTask.cpp index b490620d..5f459649 100644 --- a/launcher/InstanceImportTask.cpp +++ b/launcher/InstanceImportTask.cpp @@ -164,18 +164,14 @@ void InstanceImportTask::processZipPack() } else { - QString mmcRoot = MMCZip::findFolderOfFileInZip(m_packZip.get(), "instance.cfg"); - QString flameRoot = MMCZip::findFolderOfFileInZip(m_packZip.get(), "manifest.json"); + QStringList paths_to_ignore { "overrides/" }; - if (!mmcRoot.isNull()) - { + if (QString mmcRoot = MMCZip::findFolderOfFileInZip(m_packZip.get(), "instance.cfg", paths_to_ignore); !mmcRoot.isNull()) { // process as MultiMC instance/pack qDebug() << "MultiMC:" << mmcRoot; root = mmcRoot; m_modpackType = ModpackType::MultiMC; - } - else if(!flameRoot.isNull()) - { + } else if (QString flameRoot = MMCZip::findFolderOfFileInZip(m_packZip.get(), "manifest.json", paths_to_ignore); !flameRoot.isNull()) { // process as Flame pack qDebug() << "Flame:" << flameRoot; root = flameRoot; diff --git a/launcher/MMCZip.cpp b/launcher/MMCZip.cpp index 9f4e968f..f6600343 100644 --- a/launcher/MMCZip.cpp +++ b/launcher/MMCZip.cpp @@ -39,6 +39,7 @@ #include "MMCZip.h" #include "FileSystem.h" +#include #include // ours @@ -228,23 +229,27 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const } // ours -QString MMCZip::findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root) +QString MMCZip::findFolderOfFileInZip(QuaZip* zip, const QString& what, const QStringList& ignore_paths, const QString& root) { QuaZipDir rootDir(zip, root); - for(auto fileName: rootDir.entryList(QDir::Files)) - { - if(fileName == what) + for (auto&& fileName : rootDir.entryList(QDir::Files)) { + if (fileName == what) return root; + + QCoreApplication::processEvents(); } - for(auto fileName: rootDir.entryList(QDir::Dirs)) - { - QString result = findFolderOfFileInZip(zip, what, root + fileName); - if(!result.isEmpty()) - { + + // Recurse the search to non-ignored subfolders + for (auto&& fileName : rootDir.entryList(QDir::Dirs)) { + if (ignore_paths.contains(fileName)) + continue; + + QString result = findFolderOfFileInZip(zip, what, ignore_paths, root + fileName); + if (!result.isEmpty()) return result; - } } - return QString(); + + return {}; } // ours diff --git a/launcher/MMCZip.h b/launcher/MMCZip.h index ce9775bd..81f9cb90 100644 --- a/launcher/MMCZip.h +++ b/launcher/MMCZip.h @@ -80,9 +80,11 @@ namespace MMCZip /** * Find a single file in archive by file name (not path) * + * \param ignore_paths paths to skip when recursing the search + * * \return the path prefix where the file is */ - QString findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root = QString("")); + QString findFolderOfFileInZip(QuaZip * zip, const QString & what, const QStringList& ignore_paths = {}, const QString &root = QString("")); /** * Find a multiple files of the same name in archive by file name