From 5dd48e89f5a7facf8355641d0caf8deaec2a03ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 10 Jul 2015 00:06:05 +0200 Subject: GH-1034 do jar modding separate from update --- application/CMakeLists.txt | 4 +- application/LaunchController.cpp | 228 ------------------------------------- application/LaunchController.h | 49 -------- application/LaunchInteraction.cpp | 229 ++++++++++++++++++++++++++++++++++++++ application/LaunchInteraction.h | 49 ++++++++ application/MainWindow.cpp | 4 +- application/pages/VersionPage.cpp | 2 +- 7 files changed, 283 insertions(+), 282 deletions(-) delete mode 100644 application/LaunchController.cpp delete mode 100644 application/LaunchController.h create mode 100644 application/LaunchInteraction.cpp create mode 100644 application/LaunchInteraction.h (limited to 'application') diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 281f402a..ae4c0a88 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -141,8 +141,8 @@ SET(MULTIMC_SOURCES SettingsUI.cpp # Processes - LaunchController.h - LaunchController.cpp + LaunchInteraction.h + LaunchInteraction.cpp # page provider for instances InstancePageProvider.h diff --git a/application/LaunchController.cpp b/application/LaunchController.cpp deleted file mode 100644 index b1116e07..00000000 --- a/application/LaunchController.cpp +++ /dev/null @@ -1,228 +0,0 @@ -#include "LaunchController.h" -#include -#include "MultiMC.h" -#include "dialogs/CustomMessageBox.h" -#include "dialogs/AccountSelectDialog.h" -#include "dialogs/ProgressDialog.h" -#include "dialogs/EditAccountDialog.h" -#include "ConsoleWindow.h" -#include "BuildConfig.h" -#include "JavaCommon.h" -#include "SettingsUI.h" -#include -#include -#include -#include - -LaunchController::LaunchController(QObject *parent) : QObject(parent) -{ -} - -void LaunchController::launch() -{ - login(); -} - -void LaunchController::login() -{ - if (!m_instance) - return; - - JavaCommon::checkJVMArgs(m_instance->settings()->get("JvmArgs").toString(), m_parentWidget); - - // Find an account to use. - std::shared_ptr accounts = MMC->accounts(); - MojangAccountPtr account = accounts->activeAccount(); - if (accounts->count() <= 0) - { - // Tell the user they need to log in at least one account in order to play. - auto reply = CustomMessageBox::selectable( - m_parentWidget, tr("No Accounts"), - tr("In order to play Minecraft, you must have at least one Mojang or Minecraft " - "account logged in to MultiMC." - "Would you like to open the account manager to add an account now?"), - QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec(); - - if (reply == QMessageBox::Yes) - { - // Open the account manager. - SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), m_parentWidget, "accounts"); - } - } - else if (account.get() == nullptr) - { - // If no default account is set, ask the user which one to use. - AccountSelectDialog selectDialog(tr("Which account would you like to use?"), - AccountSelectDialog::GlobalDefaultCheckbox, m_parentWidget); - - selectDialog.exec(); - - // Launch the instance with the selected account. - account = selectDialog.selectedAccount(); - - // If the user said to use the account as default, do that. - if (selectDialog.useAsGlobalDefault() && account.get() != nullptr) - accounts->setActiveAccount(account->username()); - } - - // if no account is selected, we bail - if (!account.get()) - return; - - // we try empty password first :) - QString password; - // we loop until the user succeeds in logging in or gives up - bool tryagain = true; - // the failure. the default failure. - QString failReason = tr("Your account is currently not logged in. Please enter " - "your password to log in again."); - - while (tryagain) - { - m_session = std::make_shared(); - m_session->wants_online = m_online; - auto task = account->login(m_session, password); - if (task) - { - // We'll need to validate the access token to make sure the account - // is still logged in. - ProgressDialog progDialog(m_parentWidget); - if (m_online) - progDialog.setSkipButton(true, tr("Play Offline")); - progDialog.exec(task.get()); - if (!task->successful()) - { - failReason = task->failReason(); - } - } - switch (m_session->status) - { - case AuthSession::Undetermined: - { - qCritical() << "Received undetermined session status during login. Bye."; - tryagain = false; - break; - } - case AuthSession::RequiresPassword: - { - EditAccountDialog passDialog(failReason, m_parentWidget, EditAccountDialog::PasswordField); - if (passDialog.exec() == QDialog::Accepted) - { - password = passDialog.password(); - } - else - { - tryagain = false; - } - break; - } - case AuthSession::PlayableOffline: - { - // we ask the user for a player name - bool ok = false; - QString usedname = m_session->player_name; - QString name = QInputDialog::getText(m_parentWidget, tr("Player name"), - tr("Choose your offline mode player name."), - QLineEdit::Normal, m_session->player_name, &ok); - if (!ok) - { - tryagain = false; - break; - } - if (name.length()) - { - usedname = name; - } - m_session->MakeOffline(usedname); - // offline flavored game from here :3 - } - case AuthSession::PlayableOnline: - { - launchInstance(); - tryagain = false; - } - } - } -} - -void LaunchController::launchInstance() -{ - Q_ASSERT_X(m_instance != NULL, "launchInstance", "instance is NULL"); - Q_ASSERT_X(m_session.get() != nullptr, "launchInstance", "session is NULL"); - - if(!m_instance->reload()) - { - QMessageBox::critical(m_parentWidget, tr("Error"), tr("Couldn't load the instance profile.")); - return; - } - - m_launcher = m_instance->prepareForLaunch(m_session); - if (!m_launcher) - { - return; - } - - if(m_parentWidget) - { - m_parentWidget->hide(); - } - - m_console = new ConsoleWindow(m_launcher); - connect(m_console, &ConsoleWindow::isClosing, this, &LaunchController::instanceEnded); - connect(m_launcher.get(), &BaseLauncher::readyForLaunch, this, &LaunchController::readyForLaunch); - - m_launcher->setHeader("MultiMC version: " + BuildConfig.printableVersionString() + "\n\n"); - m_launcher->start(); -} - -void LaunchController::readyForLaunch() -{ - if (!m_profiler) - { - m_launcher->launch(); - return; - } - - QString error; - if (!m_profiler->check(&error)) - { - m_launcher->abort(); - QMessageBox::critical(m_parentWidget, tr("Error"), tr("Couldn't start profiler: %1").arg(error)); - return; - } - BaseProfiler *profilerInstance = m_profiler->createProfiler(m_launcher->instance(), this); - - connect(profilerInstance, &BaseProfiler::readyToLaunch, [this](const QString & message) - { - QMessageBox msg; - msg.setText(tr("The game launch is delayed until you press the " - "button. This is the right time to setup the profiler, as the " - "profiler server is running now.\n\n%1").arg(message)); - msg.setWindowTitle(tr("Waiting")); - msg.setIcon(QMessageBox::Information); - msg.addButton(tr("Launch"), QMessageBox::AcceptRole); - msg.setModal(true); - msg.exec(); - m_launcher->launch(); - }); - connect(profilerInstance, &BaseProfiler::abortLaunch, [this](const QString & message) - { - QMessageBox msg; - msg.setText(tr("Couldn't start the profiler: %1").arg(message)); - msg.setWindowTitle(tr("Error")); - msg.setIcon(QMessageBox::Critical); - msg.addButton(QMessageBox::Ok); - msg.setModal(true); - msg.exec(); - m_launcher->abort(); - }); - profilerInstance->beginProfiling(m_launcher); -} - -void LaunchController::instanceEnded() -{ - if(m_parentWidget) - { - m_parentWidget->show(); - } -} diff --git a/application/LaunchController.h b/application/LaunchController.h deleted file mode 100644 index f62d5124..00000000 --- a/application/LaunchController.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once -#include -#include -#include - -class ConsoleWindow; -class LaunchController: public QObject -{ - Q_OBJECT -public: - LaunchController(QObject * parent = nullptr); - virtual ~LaunchController(){}; - - void setInstance(InstancePtr instance) - { - m_instance = instance; - } - void setOnline(bool online) - { - m_online = online; - } - void setProfiler(BaseProfilerFactory *profiler) - { - m_profiler = profiler; - } - void setParentWidget(QWidget * widget) - { - m_parentWidget = widget; - } - - void launch(); - -private: - void login(); - void launchInstance(); - -private slots: - void readyForLaunch(); - void instanceEnded(); - -private: - BaseProfilerFactory *m_profiler = nullptr; - bool m_online = true; - InstancePtr m_instance; - QWidget * m_parentWidget = nullptr; - ConsoleWindow *m_console = nullptr; - AuthSessionPtr m_session; - std::shared_ptr m_launcher; -}; diff --git a/application/LaunchInteraction.cpp b/application/LaunchInteraction.cpp new file mode 100644 index 00000000..ea966129 --- /dev/null +++ b/application/LaunchInteraction.cpp @@ -0,0 +1,229 @@ +#include "LaunchInteraction.h" +#include +#include "MultiMC.h" +#include "dialogs/CustomMessageBox.h" +#include "dialogs/AccountSelectDialog.h" +#include "dialogs/ProgressDialog.h" +#include "dialogs/EditAccountDialog.h" +#include "ConsoleWindow.h" +#include "BuildConfig.h" +#include "JavaCommon.h" +#include "SettingsUI.h" +#include +#include +#include +#include + +LaunchController::LaunchController(QObject *parent) : QObject(parent) +{ +} + +void LaunchController::launch() +{ + login(); +} + +// FIXME: minecraft specific +void LaunchController::login() +{ + if (!m_instance) + return; + + JavaCommon::checkJVMArgs(m_instance->settings()->get("JvmArgs").toString(), m_parentWidget); + + // Find an account to use. + std::shared_ptr accounts = MMC->accounts(); + MojangAccountPtr account = accounts->activeAccount(); + if (accounts->count() <= 0) + { + // Tell the user they need to log in at least one account in order to play. + auto reply = CustomMessageBox::selectable( + m_parentWidget, tr("No Accounts"), + tr("In order to play Minecraft, you must have at least one Mojang or Minecraft " + "account logged in to MultiMC." + "Would you like to open the account manager to add an account now?"), + QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec(); + + if (reply == QMessageBox::Yes) + { + // Open the account manager. + SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), m_parentWidget, "accounts"); + } + } + else if (account.get() == nullptr) + { + // If no default account is set, ask the user which one to use. + AccountSelectDialog selectDialog(tr("Which account would you like to use?"), + AccountSelectDialog::GlobalDefaultCheckbox, m_parentWidget); + + selectDialog.exec(); + + // Launch the instance with the selected account. + account = selectDialog.selectedAccount(); + + // If the user said to use the account as default, do that. + if (selectDialog.useAsGlobalDefault() && account.get() != nullptr) + accounts->setActiveAccount(account->username()); + } + + // if no account is selected, we bail + if (!account.get()) + return; + + // we try empty password first :) + QString password; + // we loop until the user succeeds in logging in or gives up + bool tryagain = true; + // the failure. the default failure. + QString failReason = tr("Your account is currently not logged in. Please enter " + "your password to log in again."); + + while (tryagain) + { + m_session = std::make_shared(); + m_session->wants_online = m_online; + auto task = account->login(m_session, password); + if (task) + { + // We'll need to validate the access token to make sure the account + // is still logged in. + ProgressDialog progDialog(m_parentWidget); + if (m_online) + progDialog.setSkipButton(true, tr("Play Offline")); + progDialog.exec(task.get()); + if (!task->successful()) + { + failReason = task->failReason(); + } + } + switch (m_session->status) + { + case AuthSession::Undetermined: + { + qCritical() << "Received undetermined session status during login. Bye."; + tryagain = false; + break; + } + case AuthSession::RequiresPassword: + { + EditAccountDialog passDialog(failReason, m_parentWidget, EditAccountDialog::PasswordField); + if (passDialog.exec() == QDialog::Accepted) + { + password = passDialog.password(); + } + else + { + tryagain = false; + } + break; + } + case AuthSession::PlayableOffline: + { + // we ask the user for a player name + bool ok = false; + QString usedname = m_session->player_name; + QString name = QInputDialog::getText(m_parentWidget, tr("Player name"), + tr("Choose your offline mode player name."), + QLineEdit::Normal, m_session->player_name, &ok); + if (!ok) + { + tryagain = false; + break; + } + if (name.length()) + { + usedname = name; + } + m_session->MakeOffline(usedname); + // offline flavored game from here :3 + } + case AuthSession::PlayableOnline: + { + launchInstance(); + tryagain = false; + } + } + } +} + +void LaunchController::launchInstance() +{ + Q_ASSERT_X(m_instance != NULL, "launchInstance", "instance is NULL"); + Q_ASSERT_X(m_session.get() != nullptr, "launchInstance", "session is NULL"); + + if(!m_instance->reload()) + { + QMessageBox::critical(m_parentWidget, tr("Error"), tr("Couldn't load the instance profile.")); + return; + } + + m_launcher = m_instance->createLaunchTask(m_session); + if (!m_launcher) + { + return; + } + + if(m_parentWidget) + { + m_parentWidget->hide(); + } + + m_console = new ConsoleWindow(m_launcher); + connect(m_console, &ConsoleWindow::isClosing, this, &LaunchController::instanceEnded); + connect(m_launcher.get(), &BaseLauncher::readyForLaunch, this, &LaunchController::readyForLaunch); + + m_launcher->setHeader("MultiMC version: " + BuildConfig.printableVersionString() + "\n\n"); + m_launcher->start(); +} + +void LaunchController::readyForLaunch() +{ + if (!m_profiler) + { + m_launcher->launch(); + return; + } + + QString error; + if (!m_profiler->check(&error)) + { + m_launcher->abort(); + QMessageBox::critical(m_parentWidget, tr("Error"), tr("Couldn't start profiler: %1").arg(error)); + return; + } + BaseProfiler *profilerInstance = m_profiler->createProfiler(m_launcher->instance(), this); + + connect(profilerInstance, &BaseProfiler::readyToLaunch, [this](const QString & message) + { + QMessageBox msg; + msg.setText(tr("The game launch is delayed until you press the " + "button. This is the right time to setup the profiler, as the " + "profiler server is running now.\n\n%1").arg(message)); + msg.setWindowTitle(tr("Waiting")); + msg.setIcon(QMessageBox::Information); + msg.addButton(tr("Launch"), QMessageBox::AcceptRole); + msg.setModal(true); + msg.exec(); + m_launcher->launch(); + }); + connect(profilerInstance, &BaseProfiler::abortLaunch, [this](const QString & message) + { + QMessageBox msg; + msg.setText(tr("Couldn't start the profiler: %1").arg(message)); + msg.setWindowTitle(tr("Error")); + msg.setIcon(QMessageBox::Critical); + msg.addButton(QMessageBox::Ok); + msg.setModal(true); + msg.exec(); + m_launcher->abort(); + }); + profilerInstance->beginProfiling(m_launcher); +} + +void LaunchController::instanceEnded() +{ + if(m_parentWidget) + { + m_parentWidget->show(); + } +} diff --git a/application/LaunchInteraction.h b/application/LaunchInteraction.h new file mode 100644 index 00000000..f62d5124 --- /dev/null +++ b/application/LaunchInteraction.h @@ -0,0 +1,49 @@ +#pragma once +#include +#include +#include + +class ConsoleWindow; +class LaunchController: public QObject +{ + Q_OBJECT +public: + LaunchController(QObject * parent = nullptr); + virtual ~LaunchController(){}; + + void setInstance(InstancePtr instance) + { + m_instance = instance; + } + void setOnline(bool online) + { + m_online = online; + } + void setProfiler(BaseProfilerFactory *profiler) + { + m_profiler = profiler; + } + void setParentWidget(QWidget * widget) + { + m_parentWidget = widget; + } + + void launch(); + +private: + void login(); + void launchInstance(); + +private slots: + void readyForLaunch(); + void instanceEnded(); + +private: + BaseProfilerFactory *m_profiler = nullptr; + bool m_online = true; + InstancePtr m_instance; + QWidget * m_parentWidget = nullptr; + ConsoleWindow *m_console = nullptr; + AuthSessionPtr m_session; + std::shared_ptr m_launcher; +}; diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 4be80492..bd50e06d 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -372,7 +372,7 @@ namespace Ui { #include "java/JavaUtils.h" #include "JavaCommon.h" #include "InstancePageProvider.h" -#include "LaunchController.h" +#include "LaunchInteraction.h" #include "SettingsUI.h" #include "minecraft/SkinUtils.h" #include "resources/Resource.h" @@ -1184,7 +1184,7 @@ void MainWindow::finalizeInstance(InstancePtr inst) if (MMC->accounts()->anyAccountIsValid()) { ProgressDialog loadDialog(this); - auto update = inst->doUpdate(); + auto update = inst->createUpdateTask(); connect(update.get(), &Task::failed, [this](QString reason) { QString error = QString("Instance load failed: %1").arg(reason); diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp index efc0b446..81da0180 100644 --- a/application/pages/VersionPage.cpp +++ b/application/pages/VersionPage.cpp @@ -269,7 +269,7 @@ void VersionPage::on_changeVersionBtn_clicked() int VersionPage::doUpdate() { - auto updateTask = m_inst->doUpdate(); + auto updateTask = m_inst->createUpdateTask(); if (!updateTask) { return 1; -- cgit v1.2.3