fix: hook up setAbortStatus in instance import tasks

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-07-31 18:21:59 -03:00
parent 6a50fa35ec
commit 87002fb8f8
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
7 changed files with 30 additions and 7 deletions

View File

@ -2,11 +2,22 @@
#include <QDebug>
InstanceCreationTask::InstanceCreationTask() {}
InstanceCreationTask::InstanceCreationTask() = default;
void InstanceCreationTask::executeTask()
{
if (updateInstance() || createInstance()) {
if (updateInstance()) {
emitSucceeded();
return;
}
// If this is set, it means we're updating an instance. Since the previous step likely
// removed some old files, we'd better not let the user abort the next task, since it'd
// put the instance in an invalid state.
// TODO: Figure out an unexpensive way of making such file removal a recoverable transaction.
setAbortStatus(!shouldOverride());
if (createInstance()) {
emitSucceeded();
return;
}

View File

@ -63,15 +63,20 @@ InstanceImportTask::InstanceImportTask(const QUrl sourceUrl, QWidget* parent)
bool InstanceImportTask::abort()
{
if (!canAbort())
return false;
if (m_filesNetJob)
m_filesNetJob->abort();
m_extractFuture.cancel();
return false;
return Task::abort();
}
void InstanceImportTask::executeTask()
{
setAbortStatus(true);
if (m_sourceUrl.isLocalFile()) {
m_archivePath = m_sourceUrl.toLocalFile();
processZipPack();
@ -274,6 +279,7 @@ void InstanceImportTask::processFlame()
connect(inst_creation_task, &Task::finished, inst_creation_task, &InstanceCreationTask::deleteLater);
connect(this, &Task::aborted, inst_creation_task, &InstanceCreationTask::abort);
connect(inst_creation_task, &Task::abortStatusChanged, this, &Task::setAbortStatus);
inst_creation_task->start();
}
@ -336,6 +342,7 @@ void InstanceImportTask::processModrinth()
connect(inst_creation_task, &Task::finished, inst_creation_task, &InstanceCreationTask::deleteLater);
connect(this, &Task::aborted, inst_creation_task, &InstanceCreationTask::abort);
connect(inst_creation_task, &Task::abortStatusChanged, this, &Task::setAbortStatus);
inst_creation_task->start();
}

View File

@ -58,7 +58,6 @@ class InstanceImportTask : public InstanceTask
public:
explicit InstanceImportTask(const QUrl sourceUrl, QWidget* parent = nullptr);
bool canAbort() const override { return true; }
bool abort() override;
const QVector<Flame::File> &getBlockedFiles() const
{

View File

@ -785,6 +785,7 @@ class InstanceStaging : public Task {
connect(child, &Task::succeeded, this, &InstanceStaging::childSucceded);
connect(child, &Task::failed, this, &InstanceStaging::childFailed);
connect(child, &Task::aborted, this, &InstanceStaging::childAborted);
connect(child, &Task::abortStatusChanged, this, &InstanceStaging::setAbortStatus);
connect(child, &Task::status, this, &InstanceStaging::setStatus);
connect(child, &Task::progress, this, &InstanceStaging::setProgress);
connect(&m_backoffTimer, &QTimer::timeout, this, &InstanceStaging::childSucceded);

View File

@ -27,6 +27,9 @@ static const FlameAPI api;
bool FlameCreationTask::abort()
{
if (!canAbort())
return false;
if (m_process_update_file_info_job)
m_process_update_file_info_job->abort();
if (m_files_job)
@ -34,7 +37,7 @@ bool FlameCreationTask::abort()
if (m_mod_id_resolver)
m_mod_id_resolver->abort();
return true;
return Task::abort();
}
bool FlameCreationTask::updateInstance()

View File

@ -19,9 +19,12 @@
bool ModrinthCreationTask::abort()
{
if (!canAbort())
return false;
if (m_files_job)
return m_files_job->abort();
return true;
return Task::abort();
}
bool ModrinthCreationTask::updateInstance()

View File

@ -22,7 +22,6 @@ class ModrinthCreationTask final : public InstanceCreationTask {
}
bool abort() override;
bool canAbort() const override { return true; }
bool updateInstance() override;
bool createInstance() override;