From 220971fadd8cc2def071818c17cda14bad0f6f45 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 6 Jul 2021 15:22:41 +0100 Subject: [PATCH] GH-1949 Allow ATLauncher pack downloads to be aborted --- .../modplatform/atlauncher/ATLPackInstallTask.cpp | 13 ++++++++++++- .../modplatform/atlauncher/ATLPackInstallTask.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/api/logic/modplatform/atlauncher/ATLPackInstallTask.cpp b/api/logic/modplatform/atlauncher/ATLPackInstallTask.cpp index dac80e8c..55087a27 100644 --- a/api/logic/modplatform/atlauncher/ATLPackInstallTask.cpp +++ b/api/logic/modplatform/atlauncher/ATLPackInstallTask.cpp @@ -28,7 +28,11 @@ PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString pack, bool PackInstallTask::abort() { - return true; + if(abortable) + { + return jobPtr->abort(); + } + return false; } void PackInstallTask::executeTask() @@ -418,16 +422,19 @@ void PackInstallTask::installConfigs() connect(jobPtr.get(), &NetJob::succeeded, this, [&]() { + abortable = false; jobPtr.reset(); extractConfigs(); }); connect(jobPtr.get(), &NetJob::failed, [&](QString reason) { + abortable = false; jobPtr.reset(); emitFailed(reason); }); connect(jobPtr.get(), &NetJob::progress, [&](qint64 current, qint64 total) { + abortable = true; setProgress(current, total); }); @@ -576,11 +583,13 @@ void PackInstallTask::downloadMods() connect(jobPtr.get(), &NetJob::succeeded, this, &PackInstallTask::onModsDownloaded); connect(jobPtr.get(), &NetJob::failed, [&](QString reason) { + abortable = false; jobPtr.reset(); emitFailed(reason); }); connect(jobPtr.get(), &NetJob::progress, [&](qint64 current, qint64 total) { + abortable = true; setProgress(current, total); }); @@ -588,6 +597,8 @@ void PackInstallTask::downloadMods() } void PackInstallTask::onModsDownloaded() { + abortable = false; + qDebug() << "PackInstallTask::onModsDownloaded: " << QThread::currentThreadId(); jobPtr.reset(); diff --git a/api/logic/modplatform/atlauncher/ATLPackInstallTask.h b/api/logic/modplatform/atlauncher/ATLPackInstallTask.h index 8233c376..15fd9b32 100644 --- a/api/logic/modplatform/atlauncher/ATLPackInstallTask.h +++ b/api/logic/modplatform/atlauncher/ATLPackInstallTask.h @@ -39,6 +39,7 @@ public: explicit PackInstallTask(UserInteractionSupport *support, QString pack, QString version); virtual ~PackInstallTask(){} + bool canAbort() const override { return true; } bool abort() override; protected: @@ -72,6 +73,8 @@ private: private: UserInteractionSupport *m_support; + bool abortable = false; + NetJobPtr jobPtr; QByteArray response;