Merge pull request #1616 from LennyMcLennington/fix-hang

fix hang when importing certain modpacks
This commit is contained in:
Lenny McLennington 2023-11-25 02:03:38 +00:00 committed by GitHub
commit 385eaea709
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 29 deletions

View File

@ -164,23 +164,21 @@ void InstanceImportTask::processZipPack()
}
else
{
QString mmcRoot = MMCZip::findFolderOfFileInZip(m_packZip.get(), "instance.cfg");
QString flameRoot = MMCZip::findFolderOfFileInZip(m_packZip.get(), "manifest.json");
if (!mmcRoot.isNull())
{
// process as MultiMC instance/pack
qDebug() << "MultiMC:" << mmcRoot;
root = mmcRoot;
m_modpackType = ModpackType::MultiMC;
}
else if(!flameRoot.isNull())
auto [rootDirectory, fileName] = MMCZip::findFolderOfFileInZip(m_packZip.get(), {"manifest.json", "instance.cfg"});
if(fileName == "manifest.json")
{
// process as Flame pack
qDebug() << "Flame:" << flameRoot;
root = flameRoot;
qDebug() << "Flame:" << rootDirectory;
root = rootDirectory;
m_modpackType = ModpackType::Flame;
}
else if (fileName == "instance.cfg")
{
// process as MultiMC instance/pack
qDebug() << "MultiMC:" << rootDirectory;
root = rootDirectory;
m_modpackType = ModpackType::MultiMC;
}
}
if(m_modpackType == ModpackType::Unknown)
{

View File

@ -40,6 +40,7 @@
#include "FileSystem.h"
#include <QDebug>
#include <deque>
// ours
bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained, const FilterFunction filter)
@ -228,23 +229,27 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
}
// ours
QString MMCZip::findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root)
std::pair<QString, QString> MMCZip::findFolderOfFileInZip(QuaZip * zip, QSet<const QString> what, const QString &root)
{
QuaZipDir rootDir(zip, root);
for(auto fileName: rootDir.entryList(QDir::Files))
std::deque<QString> pathsToTraverse;
pathsToTraverse.push_back(root);
while (!pathsToTraverse.empty())
{
if(fileName == what)
return root;
}
for(auto fileName: rootDir.entryList(QDir::Dirs))
{
QString result = findFolderOfFileInZip(zip, what, root + fileName);
if(!result.isEmpty())
QString currentPath = pathsToTraverse.front();
pathsToTraverse.pop_front();
QuaZipDir rootDir(zip, currentPath);
for(auto fileName: rootDir.entryList(QDir::Files))
{
return result;
if (what.contains(fileName))
return {currentPath, fileName};
}
for(auto fileName: rootDir.entryList(QDir::Dirs))
{
pathsToTraverse.push_back(root);
}
}
return QString();
return {QString(), QString()};
}
// ours

View File

@ -78,11 +78,11 @@ namespace MMCZip
bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod*>& mods);
/**
* Find a single file in archive by file name (not path)
* Breath-first find a single file in archive by a list of file names (not path)
*
* \return the path prefix where the file is
* \return pair of {file parent directory, file name}
*/
QString findFolderOfFileInZip(QuaZip * zip, const QString & what, const QString &root = QString(""));
std::pair<QString, QString> findFolderOfFileInZip(QuaZip * zip, QSet<const QString> what, const QString &root = QString(""));
/**
* Find a multiple files of the same name in archive by file name

View File

@ -285,7 +285,7 @@ void World::readFromZip(const QFileInfo &file)
{
return;
}
auto location = MMCZip::findFolderOfFileInZip(&zip, "level.dat");
auto [location, _] = MMCZip::findFolderOfFileInZip(&zip, {"level.dat"});
is_valid = !location.isEmpty();
if (!is_valid)
{