Further reduce buggy behaviour
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
970ec8187c
commit
5d5fcae501
@ -19,6 +19,7 @@
|
||||
#include "ModrinthPackExportTask.h"
|
||||
|
||||
#include <qcryptographichash.h>
|
||||
#include <qtconcurrentrun.h>
|
||||
#include <QFileInfo>
|
||||
#include <QFileInfoList>
|
||||
#include <QMessageBox>
|
||||
@ -56,13 +57,17 @@ void ModrinthPackExportTask::executeTask()
|
||||
|
||||
bool ModrinthPackExportTask::abort()
|
||||
{
|
||||
if (!task.isNull() && task->abort()) {
|
||||
if (task != nullptr) {
|
||||
if (!task->abort())
|
||||
return false;
|
||||
|
||||
task = nullptr;
|
||||
emitFailed(tr("Aborted"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
pendingAbort = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ModrinthPackExportTask::collectFiles()
|
||||
@ -106,6 +111,8 @@ void ModrinthPackExportTask::collectFiles()
|
||||
|
||||
void ModrinthPackExportTask::parseApiResponse(QByteArray* response)
|
||||
{
|
||||
task = nullptr;
|
||||
|
||||
try {
|
||||
QJsonDocument doc = Json::requireDocument(*response);
|
||||
|
||||
@ -137,6 +144,7 @@ void ModrinthPackExportTask::parseApiResponse(QByteArray* response)
|
||||
|
||||
void ModrinthPackExportTask::buildZip()
|
||||
{
|
||||
QtConcurrent::run(QThreadPool::globalInstance(), [this]() {
|
||||
setStatus("Adding files...");
|
||||
QuaZip zip(output);
|
||||
if (!zip.open(QuaZip::mdCreate)) {
|
||||
@ -145,6 +153,11 @@ void ModrinthPackExportTask::buildZip()
|
||||
return;
|
||||
}
|
||||
|
||||
if (pendingAbort) {
|
||||
emitFailed(tr("Aborted"));
|
||||
return;
|
||||
}
|
||||
|
||||
QuaZipFile indexFile(&zip);
|
||||
if (!indexFile.open(QIODevice::WriteOnly, QuaZipNewInfo("modrinth.index.json"))) {
|
||||
QFile::remove(output);
|
||||
@ -156,6 +169,12 @@ void ModrinthPackExportTask::buildZip()
|
||||
QDir mc(instance->gameRoot());
|
||||
size_t i = 0;
|
||||
for (const QFileInfo& file : files) {
|
||||
if (pendingAbort) {
|
||||
QFile::remove(output);
|
||||
emitFailed(tr("Aborted"));
|
||||
return;
|
||||
}
|
||||
|
||||
setProgress(i, files.length());
|
||||
QString relative = mc.relativeFilePath(file.absoluteFilePath());
|
||||
if (!resolvedFiles.contains(relative) && !JlCompress::compressFile(&zip, file.absoluteFilePath(), "overrides/" + relative))
|
||||
@ -172,6 +191,7 @@ void ModrinthPackExportTask::buildZip()
|
||||
}
|
||||
|
||||
emitSucceeded();
|
||||
});
|
||||
}
|
||||
|
||||
QByteArray ModrinthPackExportTask::generateIndex()
|
||||
|
@ -55,6 +55,7 @@ class ModrinthPackExportTask : public Task {
|
||||
QMap<QString, QString> pendingHashes;
|
||||
QMap<QString, ResolvedFile> resolvedFiles;
|
||||
Task::Ptr task;
|
||||
bool pendingAbort = false;
|
||||
|
||||
void collectFiles();
|
||||
void parseApiResponse(QByteArray* response);
|
||||
|
Loading…
Reference in New Issue
Block a user