diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-07-04 20:02:43 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-07-04 20:02:43 +0200 |
commit | 526a511f455234152ca9b5bc8c60d3c82cbfa417 (patch) | |
tree | dfc64e8d84fff503f646e7422d6b7939475a6dca /application | |
parent | 5628d3d379785c9c6f4a595c70392d9b1e9ea4df (diff) | |
download | MultiMC-526a511f455234152ca9b5bc8c60d3c82cbfa417.tar MultiMC-526a511f455234152ca9b5bc8c60d3c82cbfa417.tar.gz MultiMC-526a511f455234152ca9b5bc8c60d3c82cbfa417.tar.lz MultiMC-526a511f455234152ca9b5bc8c60d3c82cbfa417.tar.xz MultiMC-526a511f455234152ca9b5bc8c60d3c82cbfa417.zip |
GH-1053 move instance update into the launch task (BaseLauncher)
Diffstat (limited to 'application')
-rw-r--r-- | application/ConsoleWindow.cpp | 8 | ||||
-rw-r--r-- | application/ConsoleWindow.h | 4 | ||||
-rw-r--r-- | application/MainWindow.cpp | 61 | ||||
-rw-r--r-- | application/MainWindow.h | 8 | ||||
-rw-r--r-- | application/pages/LogPage.cpp | 4 | ||||
-rw-r--r-- | application/pages/LogPage.h | 4 |
6 files changed, 33 insertions, 56 deletions
diff --git a/application/ConsoleWindow.cpp b/application/ConsoleWindow.cpp index 6a3cd6b2..98492414 100644 --- a/application/ConsoleWindow.cpp +++ b/application/ConsoleWindow.cpp @@ -53,7 +53,7 @@ private: BasePage * m_log_page; }; -ConsoleWindow::ConsoleWindow(BaseLauncher *process, QWidget *parent) +ConsoleWindow::ConsoleWindow(std::shared_ptr<BaseLauncher> process, QWidget *parent) : QMainWindow(parent), m_proc(process) { MultiMCPlatform::fixWM_CLASS(this); @@ -129,11 +129,11 @@ ConsoleWindow::ConsoleWindow(BaseLauncher *process, QWidget *parent) } // Set up signal connections - connect(m_proc, SIGNAL(ended(InstancePtr, int, QProcess::ExitStatus)), this, + connect(m_proc.get(), SIGNAL(ended(InstancePtr, int, QProcess::ExitStatus)), this, SLOT(onEnded(InstancePtr, int, QProcess::ExitStatus))); - connect(m_proc, SIGNAL(prelaunch_failed(InstancePtr, int, QProcess::ExitStatus)), this, + connect(m_proc.get(), SIGNAL(prelaunch_failed(InstancePtr, int, QProcess::ExitStatus)), this, SLOT(onEnded(InstancePtr, int, QProcess::ExitStatus))); - connect(m_proc, SIGNAL(launch_failed(InstancePtr)), this, + connect(m_proc.get(), SIGNAL(launch_failed(InstancePtr)), this, SLOT(onLaunchFailed(InstancePtr))); setMayClose(false); diff --git a/application/ConsoleWindow.h b/application/ConsoleWindow.h index a5e9c3a4..33ae67c7 100644 --- a/application/ConsoleWindow.h +++ b/application/ConsoleWindow.h @@ -26,7 +26,7 @@ class ConsoleWindow : public QMainWindow Q_OBJECT public: - explicit ConsoleWindow(BaseLauncher *proc, QWidget *parent = 0); + explicit ConsoleWindow(std::shared_ptr<BaseLauncher> proc, QWidget *parent = 0); virtual ~ConsoleWindow(); /** @@ -56,7 +56,7 @@ protected: void closeEvent(QCloseEvent *); private: - BaseLauncher *m_proc = nullptr; + std::shared_ptr<BaseLauncher> m_proc; bool m_mayclose = true; QSystemTrayIcon *m_trayIcon = nullptr; PageContainer *m_container = nullptr; diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 8e43ff0e..eb258d20 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -1699,39 +1699,14 @@ void MainWindow::doLaunch(bool online, BaseProfilerFactory *profiler) } case AuthSession::PlayableOnline: { - // update first if the server actually responded - if (session->auth_server_online) - { - updateInstance(m_selectedInstance, session, profiler); - } - else - { - launchInstance(m_selectedInstance, session, profiler); - } + launchInstance(m_selectedInstance, session, profiler); tryagain = false; } } } } -void MainWindow::updateInstance(InstancePtr instance, AuthSessionPtr session, - BaseProfilerFactory *profiler) -{ - auto updateTask = instance->doUpdate(); - if (!updateTask) - { - launchInstance(instance, session, profiler); - return; - } - ProgressDialog tDialog(this); - connect(updateTask.get(), &Task::succeeded, [this, instance, session, profiler] - { launchInstance(instance, session, profiler); }); - connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); - tDialog.exec(updateTask.get()); -} - -void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, - BaseProfilerFactory *profiler) +void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, BaseProfilerFactory *profiler) { Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); Q_ASSERT_X(session.get() != nullptr, "launchInstance", "session is NULL"); @@ -1744,35 +1719,43 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, return; } - BaseLauncher *proc = instance->prepareForLaunch(session); + auto proc = instance->prepareForLaunch(session); if (!proc) return; + proc->setProfiler(profiler); + this->hide(); console = new ConsoleWindow(proc); connect(console, &ConsoleWindow::isClosing, this, &MainWindow::instanceEnded); + connect(proc.get(), &BaseLauncher::readyForLaunch, this, &MainWindow::readyForLaunch); proc->setHeader("MultiMC version: " + BuildConfig.printableVersionString() + "\n\n"); - proc->arm(); + proc->start(); +} + +void MainWindow::readyForLaunch(std::shared_ptr<BaseLauncher> launcher) +{ + auto profiler = launcher->getProfiler(); if (!profiler) { - proc->launch(); + launcher->launch(); return; } QString error; if (!profiler->check(&error)) { - proc->abort(); + launcher->abort(); QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error)); return; } - BaseProfiler *profilerInstance = profiler->createProfiler(instance, this); + BaseProfiler *profilerInstance = profiler->createProfiler(launcher->instance(), this); connect(profilerInstance, &BaseProfiler::readyToLaunch, - [this, proc](const QString & message) + [this, launcher](const QString & message) { QMessageBox msg; msg.setText(tr("The game launch is delayed until you press the " @@ -1783,10 +1766,10 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, msg.addButton(tr("Launch"), QMessageBox::AcceptRole); msg.setModal(true); msg.exec(); - proc->launch(); + launcher->launch(); }); connect(profilerInstance, &BaseProfiler::abortLaunch, - [this, proc](const QString & message) + [this, launcher](const QString & message) { QMessageBox msg; msg.setText(tr("Couldn't start the profiler: %1").arg(message)); @@ -1795,17 +1778,17 @@ void MainWindow::launchInstance(InstancePtr instance, AuthSessionPtr session, msg.addButton(QMessageBox::Ok); msg.setModal(true); msg.exec(); - proc->abort(); + launcher->abort(); }); - profilerInstance->beginProfiling(proc); + profilerInstance->beginProfiling(launcher); } - +/* void MainWindow::onGameUpdateError(QString error) { CustomMessageBox::selectable(this, tr("Error updating instance"), error, QMessageBox::Warning)->show(); } - +*/ void MainWindow::taskStart() { // Nothing to do here yet. diff --git a/application/MainWindow.h b/application/MainWindow.h index 010db55c..292a8d28 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -128,12 +128,7 @@ slots: */ void launchInstance(InstancePtr instance, AuthSessionPtr session, BaseProfilerFactory *profiler = 0); - /*! - * Prepares the given instance for launch with the given account. - */ - void updateInstance(InstancePtr instance, AuthSessionPtr account, BaseProfilerFactory *profiler = 0); - - void onGameUpdateError(QString error); + void readyForLaunch(std::shared_ptr<BaseLauncher>); void taskStart(); void taskEnd(); @@ -196,7 +191,6 @@ private: class GroupView *view; InstanceProxyModel *proxymodel; NetJobPtr skin_download_job; - MinecraftLauncher *proc; ConsoleWindow *console; LabeledToolButton *renameButton; QToolButton *changeIconButton; diff --git a/application/pages/LogPage.cpp b/application/pages/LogPage.cpp index 0b88193c..cdf6b345 100644 --- a/application/pages/LogPage.cpp +++ b/application/pages/LogPage.cpp @@ -11,12 +11,12 @@ #include <settings/Setting.h> #include "GuiUtil.h" -LogPage::LogPage(BaseLauncher *proc, QWidget *parent) +LogPage::LogPage(std::shared_ptr<BaseLauncher> proc, QWidget *parent) : QWidget(parent), ui(new Ui::LogPage), m_process(proc) { ui->setupUi(this); ui->tabWidget->tabBar()->hide(); - connect(m_process, SIGNAL(log(QString, MessageLevel::Enum)), this, + connect(m_process.get(), SIGNAL(log(QString, MessageLevel::Enum)), this, SLOT(write(QString, MessageLevel::Enum))); // create the format and set its font diff --git a/application/pages/LogPage.h b/application/pages/LogPage.h index a420a75f..0bd74846 100644 --- a/application/pages/LogPage.h +++ b/application/pages/LogPage.h @@ -33,7 +33,7 @@ class LogPage : public QWidget, public BasePage Q_OBJECT public: - explicit LogPage(BaseLauncher *proc, QWidget *parent = 0); + explicit LogPage(std::shared_ptr<BaseLauncher> proc, QWidget *parent = 0); virtual ~LogPage(); virtual QString displayName() const override { @@ -77,7 +77,7 @@ private slots: private: Ui::LogPage *ui; - BaseLauncher *m_process; + std::shared_ptr<BaseLauncher> m_process; int m_last_scroll_value = 0; bool m_scroll_active = true; int m_saved_offset = 0; |