GH-352 Make OneSix instance update downloads cancellable
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user