fix(ComponentUpdateTask): allow aborting

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2026-02-02 13:08:45 +05:00
parent 2338455076
commit f007d90076
No known key found for this signature in database
GPG key ID: B77C34313AEE1FFF
4 changed files with 31 additions and 6 deletions

View file

@ -59,9 +59,7 @@ bool TaskStepWrapper::canAbort() const
bool TaskStepWrapper::abort()
{
if (m_task && m_task->canAbort()) {
auto status = m_task->abort();
emitFailed("Aborted.");
return status;
return m_task->abort();
}
return Task::abort();
}

View file

@ -38,6 +38,9 @@
* If the component list changes, start over.
*/
/*
* TODO: This task launches multiple other tasks. As such it should be converted to a ConcurrentTask
*/
ComponentUpdateTask::ComponentUpdateTask(Mode mode, Net::Mode netmode, PackProfile* list) : Task()
{
d.reset(new ComponentUpdateTaskData);
@ -48,6 +51,29 @@ ComponentUpdateTask::ComponentUpdateTask(Mode mode, Net::Mode netmode, PackProfi
ComponentUpdateTask::~ComponentUpdateTask() {}
bool ComponentUpdateTask::canAbort() const
{
for (const auto& status : d->remoteLoadStatusList) {
if (status.task && !status.task->canAbort()) {
return false;
}
}
return true;
}
bool ComponentUpdateTask::abort()
{
bool aborted = true;
for (const auto& status : d->remoteLoadStatusList) {
if (status.task && !status.task->abort()) {
aborted = false;
}
}
return aborted;
}
void ComponentUpdateTask::executeTask()
{
qCDebug(instanceProfileResolveC) << "Loading components";

View file

@ -17,6 +17,9 @@ class ComponentUpdateTask : public Task {
explicit ComponentUpdateTask(Mode mode, Net::Mode netmode, PackProfile* list);
virtual ~ComponentUpdateTask();
bool canAbort() const override;
bool abort() override;
protected:
void executeTask();

View file

@ -38,9 +38,7 @@ bool MinecraftLoadAndCheck::canAbort() const
bool MinecraftLoadAndCheck::abort()
{
if (m_task && m_task->canAbort()) {
auto status = m_task->abort();
emitFailed("Aborted.");
return status;
return m_task->abort();
}
return Task::abort();
}