aboutsummaryrefslogtreecommitdiff
path: root/launcher/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/tasks')
-rw-r--r--launcher/tasks/ConcurrentTask.cpp13
-rw-r--r--launcher/tasks/Task.cpp50
-rw-r--r--launcher/tasks/Task.h44
3 files changed, 44 insertions, 63 deletions
diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp
index 9aada5e6..88492346 100644
--- a/launcher/tasks/ConcurrentTask.cpp
+++ b/launcher/tasks/ConcurrentTask.cpp
@@ -194,7 +194,7 @@ void ConcurrentTask::subTaskStatus(Task::Ptr task, const QString& msg)
auto task_progress = m_task_progress.value(task->getUid());
task_progress->status = msg;
task_progress->state = TaskStepState::Running;
-
+
emit stepProgress(*task_progress);
if (totalSize() == 1) {
@@ -207,7 +207,7 @@ void ConcurrentTask::subTaskDetails(Task::Ptr task, const QString& msg)
auto task_progress = m_task_progress.value(task->getUid());
task_progress->details = msg;
task_progress->state = TaskStepState::Running;
-
+
emit stepProgress(*task_progress);
if (totalSize() == 1) {
@@ -220,7 +220,7 @@ void ConcurrentTask::subTaskProgress(Task::Ptr task, qint64 current, qint64 tota
auto task_progress = m_task_progress.value(task->getUid());
task_progress->update(current, total);
-
+
emit stepProgress(*task_progress);
updateStepProgress(*task_progress, Operation::CHANGED);
updateState();
@@ -233,7 +233,7 @@ void ConcurrentTask::subTaskProgress(Task::Ptr task, qint64 current, qint64 tota
void ConcurrentTask::subTaskStepProgress(Task::Ptr task, TaskStepProgress const& task_progress)
{
Operation op = Operation::ADDED;
-
+
if (!m_task_progress.contains(task_progress.uid)) {
m_task_progress.insert(task_progress.uid, std::make_shared<TaskStepProgress>(task_progress));
op = Operation::ADDED;
@@ -254,12 +254,10 @@ void ConcurrentTask::subTaskStepProgress(Task::Ptr task, TaskStepProgress const&
emit stepProgress(*tp.get());
updateStepProgress(*tp.get(), op);
}
-
}
void ConcurrentTask::updateStepProgress(TaskStepProgress const& changed_progress, Operation op)
{
-
switch (op) {
case Operation::ADDED:
m_stepProgress += changed_progress.current;
@@ -274,9 +272,8 @@ void ConcurrentTask::updateStepProgress(TaskStepProgress const& changed_progress
m_stepTotalProgress -= changed_progress.old_total;
m_stepProgress += changed_progress.current;
m_stepTotalProgress += changed_progress.total;
- break;
+ break;
}
-
}
void ConcurrentTask::updateState()
diff --git a/launcher/tasks/Task.cpp b/launcher/tasks/Task.cpp
index fd82ec00..b17096ca 100644
--- a/launcher/tasks/Task.cpp
+++ b/launcher/tasks/Task.cpp
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
+ * Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
* Copyright (c) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
*
@@ -40,16 +40,15 @@
Q_LOGGING_CATEGORY(taskLogC, "launcher.task")
-Task::Task(QObject *parent, bool show_debug) : QObject(parent), m_show_debug(show_debug)
+Task::Task(QObject* parent, bool show_debug) : QObject(parent), m_show_debug(show_debug)
{
m_uid = QUuid::createUuid();
setAutoDelete(false);
}
-void Task::setStatus(const QString &new_status)
+void Task::setStatus(const QString& new_status)
{
- if(m_status != new_status)
- {
+ if (m_status != new_status) {
m_status = new_status;
emit status(m_status);
}
@@ -57,8 +56,7 @@ void Task::setStatus(const QString &new_status)
void Task::setDetails(const QString& new_details)
{
- if (m_details != new_details)
- {
+ if (m_details != new_details) {
m_details = new_details;
emit details(m_details);
}
@@ -69,41 +67,35 @@ void Task::setProgress(qint64 current, qint64 total)
if ((m_progress != current) || (m_progressTotal != total)) {
m_progress = current;
m_progressTotal = total;
-
+
emit progress(m_progress, m_progressTotal);
- }
+ }
}
void Task::start()
{
- switch(m_state)
- {
- case State::Inactive:
- {
+ switch (m_state) {
+ case State::Inactive: {
if (m_show_debug)
qCDebug(taskLogC) << "Task" << describe() << "starting for the first time";
break;
}
- case State::AbortedByUser:
- {
+ case State::AbortedByUser: {
if (m_show_debug)
qCDebug(taskLogC) << "Task" << describe() << "restarting for after being aborted by user";
break;
}
- case State::Failed:
- {
+ case State::Failed: {
if (m_show_debug)
qCDebug(taskLogC) << "Task" << describe() << "restarting for after failing at first";
break;
}
- case State::Succeeded:
- {
+ case State::Succeeded: {
if (m_show_debug)
qCDebug(taskLogC) << "Task" << describe() << "restarting for after succeeding at first";
break;
}
- case State::Running:
- {
+ case State::Running: {
if (m_show_debug)
qCWarning(taskLogC) << "The launcher tried to start task" << describe() << "while it was already running!";
return;
@@ -118,8 +110,7 @@ void Task::start()
void Task::emitFailed(QString reason)
{
// Don't fail twice.
- if (!isRunning())
- {
+ if (!isRunning()) {
qCCritical(taskLogC) << "Task" << describe() << "failed while not running!!!!: " << reason;
return;
}
@@ -133,8 +124,7 @@ void Task::emitFailed(QString reason)
void Task::emitAborted()
{
// Don't abort twice.
- if (!isRunning())
- {
+ if (!isRunning()) {
qCCritical(taskLogC) << "Task" << describe() << "aborted while not running!!!!";
return;
}
@@ -149,8 +139,7 @@ void Task::emitAborted()
void Task::emitSucceeded()
{
// Don't succeed twice.
- if (!isRunning())
- {
+ if (!isRunning()) {
qCCritical(taskLogC) << "Task" << describe() << "succeeded while not running!!!!";
return;
}
@@ -172,12 +161,9 @@ QString Task::describe()
QTextStream out(&outStr);
out << metaObject()->className() << QChar('(');
auto name = objectName();
- if(name.isEmpty())
- {
+ if (name.isEmpty()) {
out << QString("0x%1").arg(reinterpret_cast<quintptr>(this), 0, 16);
- }
- else
- {
+ } else {
out << name;
}
out << " ID: " << m_uid.toString(QUuid::WithoutBraces);
diff --git a/launcher/tasks/Task.h b/launcher/tasks/Task.h
index 57177697..7e1defd8 100644
--- a/launcher/tasks/Task.h
+++ b/launcher/tasks/Task.h
@@ -36,25 +36,20 @@
#pragma once
+#include <QLoggingCategory>
#include <QRunnable>
#include <QUuid>
-#include <QLoggingCategory>
#include "QObjectPtr.h"
Q_DECLARE_LOGGING_CATEGORY(taskLogC)
-enum class TaskStepState {
- Waiting,
- Running,
- Failed,
- Succeeded
-};
+enum class TaskStepState { Waiting, Running, Failed, Succeeded };
Q_DECLARE_METATYPE(TaskStepState)
struct TaskStepProgress {
- QUuid uid;
+ QUuid uid;
qint64 current = 0;
qint64 total = -1;
@@ -64,14 +59,11 @@ struct TaskStepProgress {
QString status = "";
QString details = "";
TaskStepState state = TaskStepState::Waiting;
- TaskStepProgress() {
- this->uid = QUuid::createUuid();
- }
- TaskStepProgress(QUuid uid) {
- this->uid = uid;
- }
+ TaskStepProgress() { this->uid = QUuid::createUuid(); }
+ TaskStepProgress(QUuid uid) { this->uid = uid; }
bool isDone() const { return (state == TaskStepState::Failed) || (state == TaskStepState::Succeeded); }
- void update(qint64 current, qint64 total) {
+ void update(qint64 current, qint64 total)
+ {
this->old_current = this->current;
this->old_total = this->total;
@@ -100,8 +92,8 @@ class Task : public QObject, public QRunnable {
bool isFinished() const;
bool wasSuccessful() const;
- /*!
- * MultiStep tasks are combinations of multiple tasks into a single logical task.
+ /*!
+ * MultiStep tasks are combinations of multiple tasks into a single logical task.
* The main usage of this is in SequencialTask.
*/
virtual auto isMultiStep() const -> bool { return false; }
@@ -125,8 +117,6 @@ class Task : public QObject, public QRunnable {
qint64 getTotalProgress() { return m_progressTotal; }
virtual auto getStepProgress() const -> TaskStepProgressList { return {}; }
-
-
QUuid getUid() { return m_uid; }
protected:
@@ -155,9 +145,18 @@ class Task : public QObject, public QRunnable {
void run() override { start(); }
virtual void start();
- virtual bool abort() { if(canAbort()) emitAborted(); return canAbort(); };
-
- void setAbortable(bool can_abort) { m_can_abort = can_abort; emit abortStatusChanged(can_abort); }
+ virtual bool abort()
+ {
+ if (canAbort())
+ emitAborted();
+ return canAbort();
+ };
+
+ void setAbortable(bool can_abort)
+ {
+ m_can_abort = can_abort;
+ emit abortStatusChanged(can_abort);
+ }
protected:
virtual void executeTask() = 0;
@@ -190,5 +189,4 @@ class Task : public QObject, public QRunnable {
// Change using setAbortStatus
bool m_can_abort = false;
QUuid m_uid;
-
};