From d1a142f040d66b6c6dafc243d98f97b53473455c Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 6 Jul 2021 15:10:35 +0100 Subject: [PATCH 1/4] GH-1949 Allow Legacy FTB pack downloads to be aborted It looks like this was just an mistake when implementing support for legacy FTB. --- api/logic/modplatform/legacy_ftb/PackInstallTask.h | 1 + 1 file changed, 1 insertion(+) diff --git a/api/logic/modplatform/legacy_ftb/PackInstallTask.h b/api/logic/modplatform/legacy_ftb/PackInstallTask.h index 7868d1c4..f3515781 100644 --- a/api/logic/modplatform/legacy_ftb/PackInstallTask.h +++ b/api/logic/modplatform/legacy_ftb/PackInstallTask.h @@ -20,6 +20,7 @@ public: explicit PackInstallTask(Modpack pack, QString version); virtual ~PackInstallTask(){} + bool canAbort() const override { return true; } bool abort() override; protected: From db392b49943d7f575cef29ec26e2490d49eb60a7 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 6 Jul 2021 15:12:07 +0100 Subject: [PATCH 2/4] GH-1949 Allow modpacks.ch pack downloads to be aborted --- api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp | 9 ++++++++- api/logic/modplatform/modpacksch/FTBPackInstallTask.h | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp b/api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp index 6067c56a..f22373bc 100644 --- a/api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/api/logic/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -19,7 +19,11 @@ PackInstallTask::PackInstallTask(Modpack pack, QString version) bool PackInstallTask::abort() { - return true; + if(abortable) + { + return jobPtr->abort(); + } + return false; } void PackInstallTask::executeTask() @@ -117,16 +121,19 @@ void PackInstallTask::downloadPack() connect(jobPtr.get(), &NetJob::succeeded, this, [&]() { + abortable = false; jobPtr.reset(); install(); }); 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); }); diff --git a/api/logic/modplatform/modpacksch/FTBPackInstallTask.h b/api/logic/modplatform/modpacksch/FTBPackInstallTask.h index 3b2d60de..55db3d3c 100644 --- a/api/logic/modplatform/modpacksch/FTBPackInstallTask.h +++ b/api/logic/modplatform/modpacksch/FTBPackInstallTask.h @@ -16,6 +16,7 @@ public: explicit PackInstallTask(Modpack pack, QString version); virtual ~PackInstallTask(){} + bool canAbort() const override { return true; } bool abort() override; protected: @@ -30,6 +31,8 @@ private: void install(); private: + bool abortable = false; + NetJobPtr jobPtr; QByteArray response; From d5c448931344a6cee5f89fddf9a8e64dec1f8da6 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 6 Jul 2021 15:12:39 +0100 Subject: [PATCH 3/4] GH-1949 Allow Technic pack downloads to be aborted This supports both 'single zip' modpacks and Solder packs, through the Technic mod platform page. --- .../modplatform/technic/SingleZipPackInstallTask.cpp | 12 ++++++++++++ .../modplatform/technic/SingleZipPackInstallTask.h | 5 +++++ .../modplatform/technic/SolderPackInstallTask.cpp | 12 ++++++++++++ .../modplatform/technic/SolderPackInstallTask.h | 5 +++++ 4 files changed, 34 insertions(+) diff --git a/api/logic/modplatform/technic/SingleZipPackInstallTask.cpp b/api/logic/modplatform/technic/SingleZipPackInstallTask.cpp index 96e1804d..dbce8e53 100644 --- a/api/logic/modplatform/technic/SingleZipPackInstallTask.cpp +++ b/api/logic/modplatform/technic/SingleZipPackInstallTask.cpp @@ -28,6 +28,14 @@ Technic::SingleZipPackInstallTask::SingleZipPackInstallTask(const QUrl &sourceUr m_minecraftVersion = minecraftVersion; } +bool Technic::SingleZipPackInstallTask::abort() { + if(m_abortable) + { + return m_filesNetJob->abort(); + } + return false; +} + void Technic::SingleZipPackInstallTask::executeTask() { setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString())); @@ -47,6 +55,8 @@ void Technic::SingleZipPackInstallTask::executeTask() void Technic::SingleZipPackInstallTask::downloadSucceeded() { + m_abortable = false; + setStatus(tr("Extracting modpack")); QDir extractDir(FS::PathCombine(m_stagingPath, ".minecraft")); qDebug() << "Attempting to create instance from" << m_archivePath; @@ -67,12 +77,14 @@ void Technic::SingleZipPackInstallTask::downloadSucceeded() void Technic::SingleZipPackInstallTask::downloadFailed(QString reason) { + m_abortable = false; emitFailed(reason); m_filesNetJob.reset(); } void Technic::SingleZipPackInstallTask::downloadProgressChanged(qint64 current, qint64 total) { + m_abortable = true; setProgress(current / 2, total); } diff --git a/api/logic/modplatform/technic/SingleZipPackInstallTask.h b/api/logic/modplatform/technic/SingleZipPackInstallTask.h index c56b9e46..ec2ff605 100644 --- a/api/logic/modplatform/technic/SingleZipPackInstallTask.h +++ b/api/logic/modplatform/technic/SingleZipPackInstallTask.h @@ -36,6 +36,9 @@ class MULTIMC_LOGIC_EXPORT SingleZipPackInstallTask : public InstanceTask public: SingleZipPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion); + bool canAbort() const override { return true; } + bool abort() override; + protected: void executeTask() override; @@ -48,6 +51,8 @@ private slots: void extractAborted(); private: + bool m_abortable = false; + QUrl m_sourceUrl; QString m_minecraftVersion; QString m_archivePath; diff --git a/api/logic/modplatform/technic/SolderPackInstallTask.cpp b/api/logic/modplatform/technic/SolderPackInstallTask.cpp index 1d17073c..1b4186d4 100644 --- a/api/logic/modplatform/technic/SolderPackInstallTask.cpp +++ b/api/logic/modplatform/technic/SolderPackInstallTask.cpp @@ -27,6 +27,14 @@ Technic::SolderPackInstallTask::SolderPackInstallTask(const QUrl &sourceUrl, con m_minecraftVersion = minecraftVersion; } +bool Technic::SolderPackInstallTask::abort() { + if(m_abortable) + { + return m_filesNetJob->abort(); + } + return false; +} + void Technic::SolderPackInstallTask::executeTask() { setStatus(tr("Finding recommended version:\n%1").arg(m_sourceUrl.toString())); @@ -106,6 +114,8 @@ void Technic::SolderPackInstallTask::fileListSucceeded() void Technic::SolderPackInstallTask::downloadSucceeded() { + m_abortable = false; + setStatus(tr("Extracting modpack")); m_filesNetJob.reset(); m_extractFuture = QtConcurrent::run([this]() @@ -132,12 +142,14 @@ void Technic::SolderPackInstallTask::downloadSucceeded() void Technic::SolderPackInstallTask::downloadFailed(QString reason) { + m_abortable = false; emitFailed(reason); m_filesNetJob.reset(); } void Technic::SolderPackInstallTask::downloadProgressChanged(qint64 current, qint64 total) { + m_abortable = true; setProgress(current / 2, total); } diff --git a/api/logic/modplatform/technic/SolderPackInstallTask.h b/api/logic/modplatform/technic/SolderPackInstallTask.h index 0fe6cb83..9f0f20a9 100644 --- a/api/logic/modplatform/technic/SolderPackInstallTask.h +++ b/api/logic/modplatform/technic/SolderPackInstallTask.h @@ -29,6 +29,9 @@ namespace Technic public: explicit SolderPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion); + bool canAbort() const override { return true; } + bool abort() override; + protected: //! Entry point for tasks. virtual void executeTask() override; @@ -43,6 +46,8 @@ namespace Technic void extractAborted(); private: + bool m_abortable = false; + NetJobPtr m_filesNetJob; QUrl m_sourceUrl; QString m_minecraftVersion; From 220971fadd8cc2def071818c17cda14bad0f6f45 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 6 Jul 2021 15:22:41 +0100 Subject: [PATCH 4/4] 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;