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