Info and error dialogs
TODO: is there a better approach? Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
2cc9b0df06
commit
ddca838e46
@ -18,8 +18,7 @@
|
||||
|
||||
#include "ModrinthPackExportTask.h"
|
||||
|
||||
#include <qcryptographichash.h>
|
||||
#include <qtconcurrentrun.h>
|
||||
#include <QCryptographicHash>
|
||||
#include <QFileInfo>
|
||||
#include <QFileInfoList>
|
||||
#include <QMessageBox>
|
||||
@ -28,7 +27,6 @@
|
||||
#include "MMCZip.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "minecraft/mod/Mod.h"
|
||||
#include "modplatform/modrinth/ModrinthAPI.h"
|
||||
|
||||
const QStringList ModrinthPackExportTask::PREFIXES = QStringList({ "mods", "coremods", "resourcepacks", "texturepacks", "shaderpacks" });
|
||||
@ -62,7 +60,7 @@ bool ModrinthPackExportTask::abort()
|
||||
return false;
|
||||
|
||||
task = nullptr;
|
||||
emitFailed(tr("Aborted"));
|
||||
emitAborted();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -154,14 +152,16 @@ void ModrinthPackExportTask::buildZip()
|
||||
}
|
||||
|
||||
if (pendingAbort) {
|
||||
emitFailed(tr("Aborted"));
|
||||
QMetaObject::invokeMethod(
|
||||
this, [this]() { emitAborted(); }, Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
QuaZipFile indexFile(&zip);
|
||||
if (!indexFile.open(QIODevice::WriteOnly, QuaZipNewInfo("modrinth.index.json"))) {
|
||||
QFile::remove(output);
|
||||
emitFailed(tr("Could not create index"));
|
||||
QMetaObject::invokeMethod(
|
||||
this, [this]() { emitFailed(tr("Could not create index")); }, Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
indexFile.write(generateIndex());
|
||||
@ -171,7 +171,8 @@ void ModrinthPackExportTask::buildZip()
|
||||
for (const QFileInfo& file : files) {
|
||||
if (pendingAbort) {
|
||||
QFile::remove(output);
|
||||
emitFailed(tr("Aborted"));
|
||||
QMetaObject::invokeMethod(
|
||||
this, [this]() { emitAborted(); }, Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -186,11 +187,13 @@ void ModrinthPackExportTask::buildZip()
|
||||
|
||||
if (zip.getZipError() != 0) {
|
||||
QFile::remove(output);
|
||||
emitFailed(tr("A zip error occured"));
|
||||
QMetaObject::invokeMethod(
|
||||
this, [this]() { emitFailed(tr("A zip error occurred")); }, Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
emitSucceeded();
|
||||
QMetaObject::invokeMethod(
|
||||
this, [this]() { emitSucceeded(); }, Qt::QueuedConnection);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
|
||||
#include "ExportMrPackDialog.h"
|
||||
#include "Application.h"
|
||||
#include "ui/dialogs/CustomMessageBox.h"
|
||||
#include "ui/dialogs/ProgressDialog.h"
|
||||
#include "ui_ExportMrPackDialog.h"
|
||||
|
||||
@ -82,6 +84,20 @@ void ExportMrPackDialog::done(int result)
|
||||
|
||||
ModrinthPackExportTask task(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
|
||||
[this](const QString& path) { return proxy->blockedPaths().covers(path); });
|
||||
|
||||
connect(&task, &Task::failed,
|
||||
[this](const QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
|
||||
|
||||
connect(&task, &Task::succeeded, [this, &task]() {
|
||||
QStringList warnings = task.warnings();
|
||||
if (warnings.count() > 0)
|
||||
CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'), QMessageBox::Warning)->show();
|
||||
});
|
||||
connect(&task, &Task::aborted, [this] {
|
||||
CustomMessageBox::selectable(this, tr("Task aborted"), tr("The task has been aborted by the user."), QMessageBox::Information)
|
||||
->show();
|
||||
});
|
||||
|
||||
ProgressDialog progress(this);
|
||||
progress.setSkipButton(true, tr("Abort"));
|
||||
if (progress.execWithTask(&task) != QDialog::Accepted)
|
||||
|
Loading…
Reference in New Issue
Block a user