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 "ModrinthPackExportTask.h"
|
||||||
|
|
||||||
#include <qcryptographichash.h>
|
#include <QCryptographicHash>
|
||||||
#include <qtconcurrentrun.h>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QFileInfoList>
|
#include <QFileInfoList>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -28,7 +27,6 @@
|
|||||||
#include "MMCZip.h"
|
#include "MMCZip.h"
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "minecraft/PackProfile.h"
|
#include "minecraft/PackProfile.h"
|
||||||
#include "minecraft/mod/Mod.h"
|
|
||||||
#include "modplatform/modrinth/ModrinthAPI.h"
|
#include "modplatform/modrinth/ModrinthAPI.h"
|
||||||
|
|
||||||
const QStringList ModrinthPackExportTask::PREFIXES = QStringList({ "mods", "coremods", "resourcepacks", "texturepacks", "shaderpacks" });
|
const QStringList ModrinthPackExportTask::PREFIXES = QStringList({ "mods", "coremods", "resourcepacks", "texturepacks", "shaderpacks" });
|
||||||
@ -62,7 +60,7 @@ bool ModrinthPackExportTask::abort()
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
task = nullptr;
|
task = nullptr;
|
||||||
emitFailed(tr("Aborted"));
|
emitAborted();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,14 +152,16 @@ void ModrinthPackExportTask::buildZip()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pendingAbort) {
|
if (pendingAbort) {
|
||||||
emitFailed(tr("Aborted"));
|
QMetaObject::invokeMethod(
|
||||||
|
this, [this]() { emitAborted(); }, Qt::QueuedConnection);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QuaZipFile indexFile(&zip);
|
QuaZipFile indexFile(&zip);
|
||||||
if (!indexFile.open(QIODevice::WriteOnly, QuaZipNewInfo("modrinth.index.json"))) {
|
if (!indexFile.open(QIODevice::WriteOnly, QuaZipNewInfo("modrinth.index.json"))) {
|
||||||
QFile::remove(output);
|
QFile::remove(output);
|
||||||
emitFailed(tr("Could not create index"));
|
QMetaObject::invokeMethod(
|
||||||
|
this, [this]() { emitFailed(tr("Could not create index")); }, Qt::QueuedConnection);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
indexFile.write(generateIndex());
|
indexFile.write(generateIndex());
|
||||||
@ -171,7 +171,8 @@ void ModrinthPackExportTask::buildZip()
|
|||||||
for (const QFileInfo& file : files) {
|
for (const QFileInfo& file : files) {
|
||||||
if (pendingAbort) {
|
if (pendingAbort) {
|
||||||
QFile::remove(output);
|
QFile::remove(output);
|
||||||
emitFailed(tr("Aborted"));
|
QMetaObject::invokeMethod(
|
||||||
|
this, [this]() { emitAborted(); }, Qt::QueuedConnection);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,11 +187,13 @@ void ModrinthPackExportTask::buildZip()
|
|||||||
|
|
||||||
if (zip.getZipError() != 0) {
|
if (zip.getZipError() != 0) {
|
||||||
QFile::remove(output);
|
QFile::remove(output);
|
||||||
emitFailed(tr("A zip error occured"));
|
QMetaObject::invokeMethod(
|
||||||
|
this, [this]() { emitFailed(tr("A zip error occurred")); }, Qt::QueuedConnection);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emitSucceeded();
|
QMetaObject::invokeMethod(
|
||||||
|
this, [this]() { emitSucceeded(); }, Qt::QueuedConnection);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ExportMrPackDialog.h"
|
#include "ExportMrPackDialog.h"
|
||||||
|
#include "Application.h"
|
||||||
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
#include "ui/dialogs/ProgressDialog.h"
|
#include "ui/dialogs/ProgressDialog.h"
|
||||||
#include "ui_ExportMrPackDialog.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,
|
ModrinthPackExportTask task(ui->name->text(), ui->version->text(), ui->summary->text(), instance, output,
|
||||||
[this](const QString& path) { return proxy->blockedPaths().covers(path); });
|
[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);
|
ProgressDialog progress(this);
|
||||||
progress.setSkipButton(true, tr("Abort"));
|
progress.setSkipButton(true, tr("Abort"));
|
||||||
if (progress.execWithTask(&task) != QDialog::Accepted)
|
if (progress.execWithTask(&task) != QDialog::Accepted)
|
||||||
|
Loading…
Reference in New Issue
Block a user