From d8caab515aa641ec901592d40b5d30c6dfd282f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 26 Jul 2015 17:55:29 +0200 Subject: GH-1053 add back update progress dialog --- application/ConsoleWindow.cpp | 9 ++ application/ConsoleWindow.h | 1 + application/dialogs/ProgressDialog.cpp | 37 ++++++++- application/dialogs/ProgressDialog.h | 3 + logic/CMakeLists.txt | 4 +- logic/forge/ForgeInstaller.cpp | 6 +- logic/forge/ForgeMirrors.cpp | 2 +- logic/forge/ForgeXzDownload.cpp | 2 +- logic/java/JavaCheckerJob.h | 2 +- logic/java/JavaVersionList.cpp | 8 +- logic/java/JavaVersionList.h | 1 - logic/launch/LaunchStep.cpp | 1 + logic/launch/LaunchStep.h | 1 + logic/launch/LaunchTask.cpp | 6 ++ logic/launch/LaunchTask.h | 5 ++ logic/launch/steps/LaunchCommand.cpp | 138 ------------------------------- logic/launch/steps/LaunchCommand.h | 46 ----------- logic/launch/steps/LaunchMinecraft.cpp | 138 +++++++++++++++++++++++++++++++ logic/launch/steps/LaunchMinecraft.h | 46 +++++++++++ logic/launch/steps/Update.cpp | 11 ++- logic/launch/steps/Update.h | 1 + logic/minecraft/LegacyInstance.cpp | 4 +- logic/minecraft/LegacyUpdate.cpp | 3 +- logic/minecraft/OneSixInstance.cpp | 4 +- logic/net/ByteArrayDownload.cpp | 2 +- logic/net/CacheDownload.cpp | 2 +- logic/net/MD5EtagDownload.cpp | 2 +- logic/net/NetAction.h | 2 +- logic/net/NetJob.cpp | 4 +- logic/net/NetJob.h | 4 +- logic/net/PasteUpload.cpp | 6 +- logic/screenshots/ImgurAlbumCreation.cpp | 2 +- logic/screenshots/ImgurUpload.cpp | 2 +- logic/tasks/SequentialTask.cpp | 8 +- logic/tasks/Task.cpp | 19 ++++- logic/tasks/Task.h | 26 +++++- logic/updater/DownloadTask.cpp | 2 +- 37 files changed, 324 insertions(+), 236 deletions(-) delete mode 100644 logic/launch/steps/LaunchCommand.cpp delete mode 100644 logic/launch/steps/LaunchCommand.h create mode 100644 logic/launch/steps/LaunchMinecraft.cpp create mode 100644 logic/launch/steps/LaunchMinecraft.h diff --git a/application/ConsoleWindow.cpp b/application/ConsoleWindow.cpp index 9dc5874d..8f3f20bd 100644 --- a/application/ConsoleWindow.cpp +++ b/application/ConsoleWindow.cpp @@ -131,6 +131,7 @@ ConsoleWindow::ConsoleWindow(std::shared_ptr proc, QWidget *parent) // Set up signal connections connect(m_proc.get(), &LaunchTask::succeeded, this, &ConsoleWindow::onSucceeded); connect(m_proc.get(), &LaunchTask::failed, this, &ConsoleWindow::onFailed); + connect(m_proc.get(), &LaunchTask::requestProgress, this, &ConsoleWindow::onProgressRequested); setMayClose(false); @@ -247,6 +248,14 @@ void ConsoleWindow::onFailed(QString reason) } } +void ConsoleWindow::onProgressRequested(Task* task) +{ + ProgressDialog progDialog(this); + m_proc->proceed(); + progDialog.exec(task); +} + + ConsoleWindow::~ConsoleWindow() { diff --git a/application/ConsoleWindow.h b/application/ConsoleWindow.h index f9e4c89e..ac5a6fd1 100644 --- a/application/ConsoleWindow.h +++ b/application/ConsoleWindow.h @@ -46,6 +46,7 @@ slots: void onSucceeded(); void onFailed(QString reason); + void onProgressRequested(Task *task); // FIXME: add handlers for the other MinecraftLauncher signals (pre/post launch command // failures) diff --git a/application/dialogs/ProgressDialog.cpp b/application/dialogs/ProgressDialog.cpp index 9a437d7a..939c5870 100644 --- a/application/dialogs/ProgressDialog.cpp +++ b/application/dialogs/ProgressDialog.cpp @@ -57,6 +57,12 @@ void ProgressDialog::updateSize() int ProgressDialog::exec(Task *task) { this->task = task; + QDialog::DialogCode result; + + if(handleImmediateResult(result)) + { + return result; + } // Connect signals. connect(task, SIGNAL(started()), SLOT(onTaskStarted())); @@ -67,11 +73,40 @@ int ProgressDialog::exec(Task *task) // if this didn't connect to an already running task, invoke start if(!task->isRunning()) + { task->start(); + } if(task->isRunning()) + { + changeProgress(task->getProgress(), task->getTotalProgress()); + changeStatus(task->getStatus()); return QDialog::exec(); + } + else if(handleImmediateResult(result)) + { + return result; + } else - return QDialog::Accepted; + { + return QDialog::Rejected; + } +} + +bool ProgressDialog::handleImmediateResult(QDialog::DialogCode &result) +{ + if(task->isFinished()) + { + if(task->successful()) + { + result = QDialog::Accepted; + } + else + { + result = QDialog::Rejected; + } + return true; + } + return false; } Task *ProgressDialog::getTask() diff --git a/application/dialogs/ProgressDialog.h b/application/dialogs/ProgressDialog.h index fb80d0ce..44cbbe88 100644 --- a/application/dialogs/ProgressDialog.h +++ b/application/dialogs/ProgressDialog.h @@ -58,6 +58,9 @@ protected: virtual void keyPressEvent(QKeyEvent *e); virtual void closeEvent(QCloseEvent *e); +private: + bool handleImmediateResult(QDialog::DialogCode &result); + private: Ui::ProgressDialog *ui; diff --git a/logic/CMakeLists.txt b/logic/CMakeLists.txt index 7afc0213..fe445c05 100644 --- a/logic/CMakeLists.txt +++ b/logic/CMakeLists.txt @@ -95,8 +95,8 @@ set(LOGIC_SOURCES # Game launch logic launch/steps/CheckJava.cpp launch/steps/CheckJava.h - launch/steps/LaunchCommand.cpp - launch/steps/LaunchCommand.h + launch/steps/LaunchMinecraft.cpp + launch/steps/LaunchMinecraft.h launch/steps/ModMinecraftJar.cpp launch/steps/ModMinecraftJar.h launch/steps/PostLaunchCommand.cpp diff --git a/logic/forge/ForgeInstaller.cpp b/logic/forge/ForgeInstaller.cpp index 32ce5788..60dce822 100644 --- a/logic/forge/ForgeInstaller.cpp +++ b/logic/forge/ForgeInstaller.cpp @@ -381,10 +381,8 @@ protected: { NetJob *fjob = new NetJob("Forge download"); fjob->addNetAction(CacheDownload::make(forgeVersion->url(), entry)); - connect(fjob, &NetJob::progress, [this](qint64 current, qint64 total) - { setProgress(100 * current / qMax((qint64)1, total)); }); - connect(fjob, &NetJob::status, [this](const QString & msg) - { setStatus(msg); }); + connect(fjob, &NetJob::progress, this, &Task::setProgress); + connect(fjob, &NetJob::status, this, &Task::setStatus); connect(fjob, &NetJob::failed, [this](QString reason) { emitFailed(tr("Failure to download Forge:\n%1").arg(reason)); }); connect(fjob, &NetJob::succeeded, installFunction); diff --git a/logic/forge/ForgeMirrors.cpp b/logic/forge/ForgeMirrors.cpp index 0dea0826..a2fc2c62 100644 --- a/logic/forge/ForgeMirrors.cpp +++ b/logic/forge/ForgeMirrors.cpp @@ -110,7 +110,7 @@ void ForgeMirrors::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { m_total_progress = bytesTotal; m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); + emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); } void ForgeMirrors::downloadReadyRead() diff --git a/logic/forge/ForgeXzDownload.cpp b/logic/forge/ForgeXzDownload.cpp index 712deb33..56320ced 100644 --- a/logic/forge/ForgeXzDownload.cpp +++ b/logic/forge/ForgeXzDownload.cpp @@ -83,7 +83,7 @@ void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { m_total_progress = bytesTotal; m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); + emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); } void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error) diff --git a/logic/java/JavaCheckerJob.h b/logic/java/JavaCheckerJob.h index 4e2038ca..23003a03 100644 --- a/logic/java/JavaCheckerJob.h +++ b/logic/java/JavaCheckerJob.h @@ -36,7 +36,7 @@ public: // if this is already running, the action needs to be started right away! if (isRunning()) { - emit progress(current_progress, total_progress); + setProgress(current_progress, total_progress); connect(base.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult))); base->performCheck(); diff --git a/logic/java/JavaVersionList.cpp b/logic/java/JavaVersionList.cpp index 52f2e62f..a463ca6c 100644 --- a/logic/java/JavaVersionList.cpp +++ b/logic/java/JavaVersionList.cpp @@ -162,7 +162,7 @@ void JavaListLoadTask::executeTask() m_job = std::shared_ptr(new JavaCheckerJob("Java detection")); connect(m_job.get(), SIGNAL(finished(QList)), this, SLOT(javaCheckerFinished(QList))); - connect(m_job.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(checkerProgress(qint64, qint64))); + connect(m_job.get(), &Task::progress, this, &Task::setProgress); qDebug() << "Probing the following Java paths: "; int id = 0; @@ -181,12 +181,6 @@ void JavaListLoadTask::executeTask() m_job->start(); } -void JavaListLoadTask::checkerProgress(qint64 current, qint64 total) -{ - float progress = (current * 100.0) / total; - this->setProgress((int) progress); -} - void JavaListLoadTask::javaCheckerFinished(QList results) { QList candidates; diff --git a/logic/java/JavaVersionList.h b/logic/java/JavaVersionList.h index f0176673..d78f9e7c 100644 --- a/logic/java/JavaVersionList.h +++ b/logic/java/JavaVersionList.h @@ -89,7 +89,6 @@ public: virtual void executeTask(); public slots: void javaCheckerFinished(QList results); - void checkerProgress(qint64 current, qint64 total); protected: std::shared_ptr m_job; diff --git a/logic/launch/LaunchStep.cpp b/logic/launch/LaunchStep.cpp index 9799d767..3078043b 100644 --- a/logic/launch/LaunchStep.cpp +++ b/logic/launch/LaunchStep.cpp @@ -23,4 +23,5 @@ void LaunchStep::bind(LaunchTask *parent) connect(this, &LaunchStep::logLine, parent, &LaunchTask::onLogLine); connect(this, &LaunchStep::logLines, parent, &LaunchTask::onLogLines); connect(this, &LaunchStep::finished, parent, &LaunchTask::onStepFinished); + connect(this, &LaunchStep::progressReportingRequest, parent, &LaunchTask::onProgressReportingRequested); } diff --git a/logic/launch/LaunchStep.h b/logic/launch/LaunchStep.h index 9b9631cb..ea472c0d 100644 --- a/logic/launch/LaunchStep.h +++ b/logic/launch/LaunchStep.h @@ -38,6 +38,7 @@ signals: void logLines(QStringList lines, MessageLevel::Enum level); void logLine(QString line, MessageLevel::Enum level); void readyForLaunch(); + void progressReportingRequest(); public slots: virtual void proceed() {}; diff --git a/logic/launch/LaunchTask.cpp b/logic/launch/LaunchTask.cpp index 66502020..1defeba3 100644 --- a/logic/launch/LaunchTask.cpp +++ b/logic/launch/LaunchTask.cpp @@ -103,6 +103,12 @@ void LaunchTask::onStepFinished() } } +void LaunchTask::onProgressReportingRequested() +{ + state = LaunchTask::Waiting; + emit requestProgress(m_steps[currentStep].get()); +} + void LaunchTask::setCensorFilter(QMap filter) { m_censorFilter = filter; diff --git a/logic/launch/LaunchTask.h b/logic/launch/LaunchTask.h index 24139ea8..bd0485c8 100644 --- a/logic/launch/LaunchTask.h +++ b/logic/launch/LaunchTask.h @@ -92,6 +92,10 @@ signals: */ void readyForLaunch(); + void requestProgress(Task *task); + + void requestLogging(); + /** * @brief emitted when we want to log something * @param text the text to log @@ -104,6 +108,7 @@ public slots: void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::MultiMC); void onReadyForLaunch(); void onStepFinished(); + void onProgressReportingRequested(); protected: /* data */ InstancePtr m_instance; diff --git a/logic/launch/steps/LaunchCommand.cpp b/logic/launch/steps/LaunchCommand.cpp deleted file mode 100644 index 2cbb3785..00000000 --- a/logic/launch/steps/LaunchCommand.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "LaunchCommand.h" -#include -#include -#include - -LaunchCommand::LaunchCommand(LaunchTask *parent) : LaunchStep(parent) -{ - connect(&m_process, &LoggedProcess::log, this, &LaunchCommand::logLines); - connect(&m_process, &LoggedProcess::stateChanged, this, &LaunchCommand::on_state); -} - -void LaunchCommand::executeTask() -{ - auto instance = m_parent->instance(); - std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); - QStringList args = minecraftInstance->javaArguments(); - - QString allArgs = args.join(", "); - emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::MultiMC); - - auto javaPath = instance->settings()->get("JavaPath").toString(); - - m_process.setProcessEnvironment(instance->createEnvironment()); - - QString wrapperCommand = instance->getWrapperCommand(); - if(!wrapperCommand.isEmpty()) - { - auto realWrapperCommand = QStandardPaths::findExecutable(wrapperCommand); - if (realWrapperCommand.isEmpty()) - { - QString reason = tr("The wrapper command \"%1\" couldn't be found.").arg(wrapperCommand); - emit logLine(reason, MessageLevel::Fatal); - emitFailed(reason); - return; - } - emit logLine("Wrapper command is:\n" + wrapperCommand + "\n\n", MessageLevel::MultiMC); - args.prepend(javaPath); - m_process.start(wrapperCommand, args); - } - else - { - m_process.start(javaPath, args); - } -} - -void LaunchCommand::on_state(LoggedProcess::State state) -{ - switch(state) - { - case LoggedProcess::FailedToStart: - { - //: Error message displayed if instace can't start - QString reason = tr("Could not launch minecraft!"); - emit logLine(reason, MessageLevel::Fatal); - emitFailed(reason); - return; - } - case LoggedProcess::Aborted: - case LoggedProcess::Crashed: - - { - m_parent->setPid(-1); - emitFailed("Game crashed."); - return; - } - case LoggedProcess::Finished: - { - m_parent->setPid(-1); - auto exitCode = m_process.exitCode(); - //FIXME: make this work again - // m_postlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(exitCode)); - // run post-exit - emitSucceeded(); - break; - } - case LoggedProcess::Running: - emit logLine(tr("Minecraft process ID: %1\n\n").arg(m_process.processId()), MessageLevel::MultiMC); - m_parent->setPid(m_process.pid()); - m_parent->instance()->setLastLaunch(); - // send the launch script to the launcher part - m_process.write(m_launchScript.toUtf8()); - - mayProceed = true; - emit readyForLaunch(); - break; - default: - break; - } -} - -void LaunchCommand::setWorkingDirectory(const QString &wd) -{ - m_process.setWorkingDirectory(wd); -} - -void LaunchCommand::proceed() -{ - if(mayProceed) - { - QString launchString("launch\n"); - m_process.write(launchString.toUtf8()); - mayProceed = false; - } -} - -bool LaunchCommand::abort() -{ - if(mayProceed) - { - mayProceed = false; - QString launchString("abort\n"); - m_process.write(launchString.toUtf8()); - } - else - { - auto state = m_process.state(); - if (state == LoggedProcess::Running || state == LoggedProcess::Starting) - { - m_process.kill(); - } - } - return true; -} diff --git a/logic/launch/steps/LaunchCommand.h b/logic/launch/steps/LaunchCommand.h deleted file mode 100644 index 4a631054..00000000 --- a/logic/launch/steps/LaunchCommand.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -class LaunchCommand: public LaunchStep -{ - Q_OBJECT -public: - explicit LaunchCommand(LaunchTask *parent); - virtual void executeTask(); - virtual bool abort(); - virtual void proceed(); - virtual bool canAbort() const - { - return true; - } - void setWorkingDirectory(const QString &wd); - void setLaunchScript(const QString &ls) - { - m_launchScript = ls; - } -private slots: - void on_state(LoggedProcess::State state); - -private: - LoggedProcess m_process; - QString m_command; - QString m_launchScript; - bool mayProceed = false; -}; diff --git a/logic/launch/steps/LaunchMinecraft.cpp b/logic/launch/steps/LaunchMinecraft.cpp new file mode 100644 index 00000000..f01a584d --- /dev/null +++ b/logic/launch/steps/LaunchMinecraft.cpp @@ -0,0 +1,138 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LaunchMinecraft.h" +#include +#include +#include + +LaunchMinecraft::LaunchMinecraft(LaunchTask *parent) : LaunchStep(parent) +{ + connect(&m_process, &LoggedProcess::log, this, &LaunchMinecraft::logLines); + connect(&m_process, &LoggedProcess::stateChanged, this, &LaunchMinecraft::on_state); +} + +void LaunchMinecraft::executeTask() +{ + auto instance = m_parent->instance(); + std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); + QStringList args = minecraftInstance->javaArguments(); + + QString allArgs = args.join(", "); + emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::MultiMC); + + auto javaPath = instance->settings()->get("JavaPath").toString(); + + m_process.setProcessEnvironment(instance->createEnvironment()); + + QString wrapperCommand = instance->getWrapperCommand(); + if(!wrapperCommand.isEmpty()) + { + auto realWrapperCommand = QStandardPaths::findExecutable(wrapperCommand); + if (realWrapperCommand.isEmpty()) + { + QString reason = tr("The wrapper command \"%1\" couldn't be found.").arg(wrapperCommand); + emit logLine(reason, MessageLevel::Fatal); + emitFailed(reason); + return; + } + emit logLine("Wrapper command is:\n" + wrapperCommand + "\n\n", MessageLevel::MultiMC); + args.prepend(javaPath); + m_process.start(wrapperCommand, args); + } + else + { + m_process.start(javaPath, args); + } +} + +void LaunchMinecraft::on_state(LoggedProcess::State state) +{ + switch(state) + { + case LoggedProcess::FailedToStart: + { + //: Error message displayed if instace can't start + QString reason = tr("Could not launch minecraft!"); + emit logLine(reason, MessageLevel::Fatal); + emitFailed(reason); + return; + } + case LoggedProcess::Aborted: + case LoggedProcess::Crashed: + + { + m_parent->setPid(-1); + emitFailed("Game crashed."); + return; + } + case LoggedProcess::Finished: + { + m_parent->setPid(-1); + auto exitCode = m_process.exitCode(); + //FIXME: make this work again + // m_postlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(exitCode)); + // run post-exit + emitSucceeded(); + break; + } + case LoggedProcess::Running: + emit logLine(tr("Minecraft process ID: %1\n\n").arg(m_process.processId()), MessageLevel::MultiMC); + m_parent->setPid(m_process.pid()); + m_parent->instance()->setLastLaunch(); + // send the launch script to the launcher part + m_process.write(m_launchScript.toUtf8()); + + mayProceed = true; + emit readyForLaunch(); + break; + default: + break; + } +} + +void LaunchMinecraft::setWorkingDirectory(const QString &wd) +{ + m_process.setWorkingDirectory(wd); +} + +void LaunchMinecraft::proceed() +{ + if(mayProceed) + { + QString launchString("launch\n"); + m_process.write(launchString.toUtf8()); + mayProceed = false; + } +} + +bool LaunchMinecraft::abort() +{ + if(mayProceed) + { + mayProceed = false; + QString launchString("abort\n"); + m_process.write(launchString.toUtf8()); + } + else + { + auto state = m_process.state(); + if (state == LoggedProcess::Running || state == LoggedProcess::Starting) + { + m_process.kill(); + } + } + return true; +} diff --git a/logic/launch/steps/LaunchMinecraft.h b/logic/launch/steps/LaunchMinecraft.h new file mode 100644 index 00000000..808ec33b --- /dev/null +++ b/logic/launch/steps/LaunchMinecraft.h @@ -0,0 +1,46 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +class LaunchMinecraft: public LaunchStep +{ + Q_OBJECT +public: + explicit LaunchMinecraft(LaunchTask *parent); + virtual void executeTask(); + virtual bool abort(); + virtual void proceed(); + virtual bool canAbort() const + { + return true; + } + void setWorkingDirectory(const QString &wd); + void setLaunchScript(const QString &ls) + { + m_launchScript = ls; + } +private slots: + void on_state(LoggedProcess::State state); + +private: + LoggedProcess m_process; + QString m_command; + QString m_launchScript; + bool mayProceed = false; +}; diff --git a/logic/launch/steps/Update.cpp b/logic/launch/steps/Update.cpp index 069b4f41..4901f001 100644 --- a/logic/launch/steps/Update.cpp +++ b/logic/launch/steps/Update.cpp @@ -22,12 +22,19 @@ void Update::executeTask() if(m_updateTask) { connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished())); - m_updateTask->start(); + connect(m_updateTask.get(), &Task::progress, this, &Task::setProgress); + connect(m_updateTask.get(), &Task::status, this, &Task::setStatus); + emit progressReportingRequest(); return; } emitSucceeded(); } +void Update::proceed() +{ + m_updateTask->start(); +} + void Update::updateFinished() { if(m_updateTask->successful()) @@ -40,4 +47,4 @@ void Update::updateFinished() emit logLine(reason, MessageLevel::Fatal); emitFailed(reason); } -} \ No newline at end of file +} diff --git a/logic/launch/steps/Update.h b/logic/launch/steps/Update.h index 3ad07264..14928253 100644 --- a/logic/launch/steps/Update.h +++ b/logic/launch/steps/Update.h @@ -32,6 +32,7 @@ public: { return false; } + virtual void proceed(); private slots: void updateFinished(); diff --git a/logic/minecraft/LegacyInstance.cpp b/logic/minecraft/LegacyInstance.cpp index 4648ce59..ed0b1001 100644 --- a/logic/minecraft/LegacyInstance.cpp +++ b/logic/minecraft/LegacyInstance.cpp @@ -25,7 +25,7 @@ #include "minecraft/LegacyUpdate.h" #include "icons/IconList.h" #include "launch/LaunchTask.h" -#include +#include #include #include #include @@ -156,7 +156,7 @@ std::shared_ptr LegacyInstance::createLaunchTask(AuthSessionPtr sess } // actually launch the game { - auto step = std::make_shared(pptr); + auto step = std::make_shared(pptr); step->setWorkingDirectory(minecraftRoot()); step->setLaunchScript(launchScript); process->appendStep(step); diff --git a/logic/minecraft/LegacyUpdate.cpp b/logic/minecraft/LegacyUpdate.cpp index e136deec..c48984c4 100644 --- a/logic/minecraft/LegacyUpdate.cpp +++ b/logic/minecraft/LegacyUpdate.cpp @@ -24,7 +24,8 @@ #include "net/URLConstants.h" #include "MMCZip.h" -#include "minecraft/LegacyUpdate.h" +#include "LegacyUpdate.h" + #include "minecraft/LwjglVersionList.h" #include "minecraft/MinecraftVersionList.h" #include "minecraft/ModList.h" diff --git a/logic/minecraft/OneSixInstance.cpp b/logic/minecraft/OneSixInstance.cpp index 5e2f5c64..3b2ff750 100644 --- a/logic/minecraft/OneSixInstance.cpp +++ b/logic/minecraft/OneSixInstance.cpp @@ -25,7 +25,7 @@ #include "launch/LaunchTask.h" #include #include -#include +#include #include #include #include @@ -263,7 +263,7 @@ std::shared_ptr OneSixInstance::createLaunchTask(AuthSessionPtr sess } // actually launch the game { - auto step = std::make_shared(pptr); + auto step = std::make_shared(pptr); step->setWorkingDirectory(minecraftRoot()); step->setLaunchScript(launchScript); process->appendStep(step); diff --git a/logic/net/ByteArrayDownload.cpp b/logic/net/ByteArrayDownload.cpp index 151487f0..21990eeb 100644 --- a/logic/net/ByteArrayDownload.cpp +++ b/logic/net/ByteArrayDownload.cpp @@ -44,7 +44,7 @@ void ByteArrayDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal { m_total_progress = bytesTotal; m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); + emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); } void ByteArrayDownload::downloadError(QNetworkReply::NetworkError error) diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp index a4fac6ef..b125a3d9 100644 --- a/logic/net/CacheDownload.cpp +++ b/logic/net/CacheDownload.cpp @@ -90,7 +90,7 @@ void CacheDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { m_total_progress = bytesTotal; m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); + emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); } void CacheDownload::downloadError(QNetworkReply::NetworkError error) diff --git a/logic/net/MD5EtagDownload.cpp b/logic/net/MD5EtagDownload.cpp index 651ab602..7593c87e 100644 --- a/logic/net/MD5EtagDownload.cpp +++ b/logic/net/MD5EtagDownload.cpp @@ -99,7 +99,7 @@ void MD5EtagDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { m_total_progress = bytesTotal; m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); + emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); } void MD5EtagDownload::downloadError(QNetworkReply::NetworkError error) diff --git a/logic/net/NetAction.h b/logic/net/NetAction.h index 7c5bd5de..85eac8e3 100644 --- a/logic/net/NetAction.h +++ b/logic/net/NetAction.h @@ -81,7 +81,7 @@ public: signals: void started(int index); - void progress(int index, qint64 current, qint64 total); + void netActionProgress(int index, qint64 current, qint64 total); void succeeded(int index); void failed(int index); diff --git a/logic/net/NetJob.cpp b/logic/net/NetJob.cpp index 40d2d1c9..52307e2a 100644 --- a/logic/net/NetJob.cpp +++ b/logic/net/NetJob.cpp @@ -61,7 +61,7 @@ void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal) total_progress -= slot.total_progress; slot.total_progress = bytesTotal; total_progress += slot.total_progress; - emit progress(current_progress, total_progress); + setProgress(current_progress, total_progress); } void NetJob::executeTask() @@ -107,7 +107,7 @@ void NetJob::startMoreParts() // connect signals :D connect(part.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); connect(part.get(), SIGNAL(failed(int)), SLOT(partFailed(int))); - connect(part.get(), SIGNAL(progress(int, qint64, qint64)), + connect(part.get(), SIGNAL(netActionProgress(int, qint64, qint64)), SLOT(partProgress(int, qint64, qint64))); part->start(); } diff --git a/logic/net/NetJob.h b/logic/net/NetJob.h index 4ac6d769..9e4656c7 100644 --- a/logic/net/NetJob.h +++ b/logic/net/NetJob.h @@ -49,10 +49,10 @@ public: // if this is already running, the action needs to be started right away! if (isRunning()) { - emit progress(current_progress, total_progress); + setProgress(current_progress, total_progress); connect(base.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); connect(base.get(), SIGNAL(failed(int)), SLOT(partFailed(int))); - connect(base.get(), SIGNAL(progress(int, qint64, qint64)), + connect(base.get(), SIGNAL(netActionProgress(int, qint64, qint64)), SLOT(partProgress(int, qint64, qint64))); base->start(); } diff --git a/logic/net/PasteUpload.cpp b/logic/net/PasteUpload.cpp index b780194f..cfbc561d 100644 --- a/logic/net/PasteUpload.cpp +++ b/logic/net/PasteUpload.cpp @@ -30,10 +30,8 @@ void PasteUpload::executeTask() m_reply = std::shared_ptr(rep); setStatus(tr("Uploading to paste.ee")); - connect(rep, &QNetworkReply::downloadProgress, [&](qint64 value, qint64 max) - { setProgress(value / qMax((qint64)1, max) * 100); }); - connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, - SLOT(downloadError(QNetworkReply::NetworkError))); + connect(rep, &QNetworkReply::downloadProgress, this, &Task::setProgress); + connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError))); connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished())); } diff --git a/logic/screenshots/ImgurAlbumCreation.cpp b/logic/screenshots/ImgurAlbumCreation.cpp index f332c220..e009ef4d 100644 --- a/logic/screenshots/ImgurAlbumCreation.cpp +++ b/logic/screenshots/ImgurAlbumCreation.cpp @@ -86,5 +86,5 @@ void ImgurAlbumCreation::downloadProgress(qint64 bytesReceived, qint64 bytesTota { m_total_progress = bytesTotal; m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); + emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); } diff --git a/logic/screenshots/ImgurUpload.cpp b/logic/screenshots/ImgurUpload.cpp index abb695b3..48e0ec18 100644 --- a/logic/screenshots/ImgurUpload.cpp +++ b/logic/screenshots/ImgurUpload.cpp @@ -110,5 +110,5 @@ void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) { m_total_progress = bytesTotal; m_progress = bytesReceived; - emit progress(m_index_within_job, bytesReceived, bytesTotal); + emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal); } diff --git a/logic/tasks/SequentialTask.cpp b/logic/tasks/SequentialTask.cpp index f744d273..ac0e7820 100644 --- a/logic/tasks/SequentialTask.cpp +++ b/logic/tasks/SequentialTask.cpp @@ -48,12 +48,8 @@ void SequentialTask::subTaskProgress(qint64 current, qint64 total) { if(total == 0) { - setProgress(0); + setProgress(0, 100); return; } - auto dcurrent = (double) current; - auto dtotal = (double) total; - auto partial = ((dcurrent / dtotal) * 100.0f)/* / double(m_queue.size())*/; - // auto bigpartial = double(m_currentIndex) * 100.0f / double(m_queue.size()); - setProgress(partial); + setProgress(current, total); } diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp index eaeff4c2..3c4e3188 100644 --- a/logic/tasks/Task.cpp +++ b/logic/tasks/Task.cpp @@ -23,12 +23,18 @@ Task::Task(QObject *parent) : QObject(parent) void Task::setStatus(const QString &new_status) { - emit status(new_status); + if(m_status != new_status) + { + m_status = new_status; + emit status(m_status); + } } -void Task::setProgress(int new_progress) +void Task::setProgress(qint64 current, qint64 total) { - emit progress(new_progress, 100); + m_progress = current; + m_progressTotal = total; + emit progress(m_progress, m_progressTotal); } void Task::start() @@ -41,6 +47,7 @@ void Task::start() void Task::emitFailed(QString reason) { m_running = false; + m_finished = true; m_succeeded = false; m_failReason = reason; qCritical() << "Task failed: " << reason; @@ -52,6 +59,7 @@ void Task::emitSucceeded() { if (!m_running) { return; } // Don't succeed twice. m_running = false; + m_finished = true; m_succeeded = true; qDebug() << "Task succeeded"; emit succeeded(); @@ -63,6 +71,11 @@ bool Task::isRunning() const return m_running; } +bool Task::isFinished() const +{ + return m_finished; +} + bool Task::successful() const { return m_succeeded; diff --git a/logic/tasks/Task.h b/logic/tasks/Task.h index 9362348a..04899c69 100644 --- a/logic/tasks/Task.h +++ b/logic/tasks/Task.h @@ -27,6 +27,8 @@ public: virtual bool isRunning() const; + virtual bool isFinished() const; + /*! * True if this task was successful. * If the task failed or is still running, returns false. @@ -41,6 +43,21 @@ public: virtual bool canAbort() const { return false; } + QString getStatus() + { + return m_status; + } + + qint64 getProgress() + { + return m_progress; + } + + qint64 getTotalProgress() + { + return m_progressTotal; + } + signals: void started(); void progress(qint64 current, qint64 total); @@ -61,14 +78,17 @@ protected slots: virtual void emitSucceeded(); virtual void emitFailed(QString reason); -protected -slots: +public slots: void setStatus(const QString &status); - void setProgress(int progress); + void setProgress(qint64 current, qint64 total); protected: bool m_running = false; + bool m_finished = false; bool m_succeeded = false; QString m_failReason = ""; + QString m_status; + int m_progress = 0; + int m_progressTotal = 100; }; diff --git a/logic/updater/DownloadTask.cpp b/logic/updater/DownloadTask.cpp index 76741748..1bbb0edf 100644 --- a/logic/updater/DownloadTask.cpp +++ b/logic/updater/DownloadTask.cpp @@ -154,7 +154,7 @@ void DownloadTask::fileDownloadFailed(QString reason) void DownloadTask::fileDownloadProgressChanged(qint64 current, qint64 total) { - setProgress((int)(((float)current / (float)total) * 100)); + setProgress(current, total); } QString DownloadTask::updateFilesDir() -- cgit v1.2.3