Make some changes

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2023-05-13 18:24:01 +01:00
parent 5b8d025440
commit e1b6020b76
2 changed files with 11 additions and 5 deletions

View File

@ -67,11 +67,15 @@ bool ModrinthPackExportTask::abort()
// NOTE: Here we don't do `emitAborted()` because it will be done when `buildZipFuture` actually cancels, which may not occur immediately. // NOTE: Here we don't do `emitAborted()` because it will be done when `buildZipFuture` actually cancels, which may not occur immediately.
return true; return true;
} }
return false; return false;
} }
void ModrinthPackExportTask::collectFiles() void ModrinthPackExportTask::collectFiles()
{ {
setAbortable(false);
QCoreApplication::processEvents();
files.clear(); files.clear();
if (!MMCZip::collectFileListRecursively(instance->gameRoot(), nullptr, &files, filter)) { if (!MMCZip::collectFileListRecursively(instance->gameRoot(), nullptr, &files, filter)) {
emitFailed(tr("Could not search for files")); emitFailed(tr("Could not search for files"));
@ -91,6 +95,8 @@ void ModrinthPackExportTask::collectFiles()
void ModrinthPackExportTask::collectHashes() void ModrinthPackExportTask::collectHashes()
{ {
for (const QFileInfo& file : files) { for (const QFileInfo& file : files) {
QCoreApplication::processEvents();
const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath()); const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath());
// require sensible file types // require sensible file types
if (!std::any_of(PREFIXES.begin(), PREFIXES.end(), if (!std::any_of(PREFIXES.begin(), PREFIXES.end(),
@ -149,6 +155,8 @@ void ModrinthPackExportTask::collectHashes()
void ModrinthPackExportTask::makeApiRequest() void ModrinthPackExportTask::makeApiRequest()
{ {
setAbortable(true);
if (pendingHashes.isEmpty()) if (pendingHashes.isEmpty())
buildZip(); buildZip();
else { else {
@ -186,7 +194,8 @@ void ModrinthPackExportTask::parseApiResponse(const QByteArray* response)
} }
} }
} catch (const Json::JsonException& e) { } catch (const Json::JsonException& e) {
qWarning() << "Failed to parse versions response" << e.what(); emitFailed(tr("Failed to parse versions response: %1").arg(e.what()));
return;
} }
pendingHashes.clear(); pendingHashes.clear();
buildZip(); buildZip();
@ -194,7 +203,7 @@ void ModrinthPackExportTask::parseApiResponse(const QByteArray* response)
void ModrinthPackExportTask::buildZip() void ModrinthPackExportTask::buildZip()
{ {
setStatus("Adding files..."); setStatus(tr("Adding files..."));
buildZipFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this]() { buildZipFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this]() {
QuaZip zip(output); QuaZip zip(output);

View File

@ -45,7 +45,6 @@
#include <QDebug> #include <QDebug>
#include <QSaveFile> #include <QSaveFile>
#include <QStack> #include <QStack>
#include "StringUtils.h"
#include "SeparatorPrefixTree.h" #include "SeparatorPrefixTree.h"
#include "Application.h" #include "Application.h"
#include <icons/IconList.h> #include <icons/IconList.h>
@ -218,5 +217,3 @@ void ExportInstanceDialog::savePackIgnore()
qWarning() << e.cause(); qWarning() << e.cause();
} }
} }
#include "ExportInstanceDialog.moc"