summaryrefslogtreecommitdiffstats
path: root/api/logic/launch
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-08-14 02:33:31 +0200
committerPetr Mrázek <peterix@gmail.com>2016-08-14 23:22:54 +0200
commit042f3ef55c0b469f438542152c4eb02b0789ea3c (patch)
tree03e0c15b200786558babd0fe58edac88ed1bfd1e /api/logic/launch
parent2f0441b3c1cd9fc3bcb176d2852da8f92a6e6777 (diff)
downloadMultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar.gz
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar.lz
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar.xz
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.zip
GH-352 Make OneSix instance update downloads cancellable
Diffstat (limited to 'api/logic/launch')
-rw-r--r--api/logic/launch/steps/Update.cpp32
-rw-r--r--api/logic/launch/steps/Update.h16
2 files changed, 40 insertions, 8 deletions
diff --git a/api/logic/launch/steps/Update.cpp b/api/logic/launch/steps/Update.cpp
index 4901f001..ad0c4fc4 100644
--- a/api/logic/launch/steps/Update.cpp
+++ b/api/logic/launch/steps/Update.cpp
@@ -18,7 +18,12 @@
void Update::executeTask()
{
- m_updateTask = m_parent->instance()->createUpdateTask();
+ if(m_aborted)
+ {
+ emitFailed(tr("Task aborted."));
+ return;
+ }
+ m_updateTask.reset(m_parent->instance()->createUpdateTask());
if(m_updateTask)
{
connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished()));
@@ -39,12 +44,37 @@ void Update::updateFinished()
{
if(m_updateTask->successful())
{
+ m_updateTask.reset();
emitSucceeded();
}
else
{
QString reason = tr("Instance update failed because: %1.\n\n").arg(m_updateTask->failReason());
+ m_updateTask.reset();
emit logLine(reason, MessageLevel::Fatal);
emitFailed(reason);
}
}
+
+bool Update::canAbort() const
+{
+ if(m_updateTask)
+ {
+ return m_updateTask->canAbort();
+ }
+ return true;
+}
+
+
+bool Update::abort()
+{
+ m_aborted = true;
+ if(m_updateTask)
+ {
+ if(m_updateTask->canAbort())
+ {
+ return m_updateTask->abort();
+ }
+ }
+ return true;
+}
diff --git a/api/logic/launch/steps/Update.h b/api/logic/launch/steps/Update.h
index 14928253..1739de47 100644
--- a/api/logic/launch/steps/Update.h
+++ b/api/logic/launch/steps/Update.h
@@ -16,6 +16,7 @@
#pragma once
#include <launch/LaunchStep.h>
+#include <QObjectPtr.h>
#include <launch/LoggedProcess.h>
#include <java/JavaChecker.h>
@@ -27,15 +28,16 @@ public:
explicit Update(LaunchTask *parent):LaunchStep(parent) {};
virtual ~Update() {};
- virtual void executeTask();
- virtual bool canAbort() const
- {
- return false;
- }
- virtual void proceed();
+ void executeTask() override;
+ bool canAbort() const override;
+ void proceed() override;
+public slots:
+ bool abort() override;
+
private slots:
void updateFinished();
private:
- std::shared_ptr<Task> m_updateTask;
+ shared_qobject_ptr<Task> m_updateTask;
+ bool m_aborted = false;
};