summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/CMakeLists.txt4
-rw-r--r--application/ConsoleWindow.cpp27
-rw-r--r--application/ConsoleWindow.h4
-rw-r--r--application/LaunchController.cpp231
-rw-r--r--application/LaunchController.h49
-rw-r--r--application/MainWindow.cpp220
-rw-r--r--application/MainWindow.h21
-rw-r--r--logic/BaseLauncher.cpp122
-rw-r--r--logic/BaseLauncher.h47
9 files changed, 392 insertions, 333 deletions
diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt
index a9ee1da6..08099cae 100644
--- a/application/CMakeLists.txt
+++ b/application/CMakeLists.txt
@@ -136,6 +136,10 @@ SET(MULTIMC_SOURCES
ConsoleWindow.h
ConsoleWindow.cpp
+ # Processes
+ LaunchController.h
+ LaunchController.cpp
+
# page provider for instances
InstancePageProvider.h
InstancePageProvider.cpp
diff --git a/application/ConsoleWindow.cpp b/application/ConsoleWindow.cpp
index 98492414..84140516 100644
--- a/application/ConsoleWindow.cpp
+++ b/application/ConsoleWindow.cpp
@@ -129,12 +129,8 @@ ConsoleWindow::ConsoleWindow(std::shared_ptr<BaseLauncher> process, QWidget *par
}
// Set up signal connections
- connect(m_proc.get(), SIGNAL(ended(InstancePtr, int, QProcess::ExitStatus)), this,
- SLOT(onEnded(InstancePtr, int, QProcess::ExitStatus)));
- connect(m_proc.get(), SIGNAL(prelaunch_failed(InstancePtr, int, QProcess::ExitStatus)), this,
- SLOT(onEnded(InstancePtr, int, QProcess::ExitStatus)));
- connect(m_proc.get(), SIGNAL(launch_failed(InstancePtr)), this,
- SLOT(onLaunchFailed(InstancePtr)));
+ connect(m_proc.get(), &BaseLauncher::succeeded, this, &ConsoleWindow::onSucceeded);
+ connect(m_proc.get(), &BaseLauncher::failed, this, &ConsoleWindow::onFailed);
setMayClose(false);
@@ -220,18 +216,14 @@ void ConsoleWindow::on_btnKillMinecraft_clicked()
m_killButton->setEnabled(true);
}
-void ConsoleWindow::onEnded(InstancePtr instance, int code, QProcess::ExitStatus status)
+void ConsoleWindow::onSucceeded()
{
- bool peacefulExit = code == 0 && status != QProcess::CrashExit;
m_killButton->setEnabled(false);
setMayClose(true);
- if (instance->settings()->get("AutoCloseConsole").toBool())
+ if (m_proc->instance()->settings()->get("AutoCloseConsole").toBool())
{
- if (peacefulExit)
- {
- this->close();
- return;
- }
+ this->close();
+ return;
}
if (!isVisible())
{
@@ -245,15 +237,16 @@ void ConsoleWindow::onEnded(InstancePtr instance, int code, QProcess::ExitStatus
}
}
-void ConsoleWindow::onLaunchFailed(InstancePtr instance)
+void ConsoleWindow::onFailed(QString reason)
{
m_killButton->setEnabled(false);
-
setMayClose(true);
-
if (!isVisible())
+ {
show();
+ }
}
+
ConsoleWindow::~ConsoleWindow()
{
diff --git a/application/ConsoleWindow.h b/application/ConsoleWindow.h
index 33ae67c7..228b58e9 100644
--- a/application/ConsoleWindow.h
+++ b/application/ConsoleWindow.h
@@ -44,8 +44,8 @@ slots:
void on_closeButton_clicked();
void on_btnKillMinecraft_clicked();
- void onEnded(InstancePtr instance, int code, QProcess::ExitStatus status);
- void onLaunchFailed(InstancePtr instance);
+ void onSucceeded();
+ void onFailed(QString reason);
// FIXME: add handlers for the other MinecraftLauncher signals (pre/post launch command
// failures)
diff --git a/application/LaunchController.cpp b/application/LaunchController.cpp
new file mode 100644
index 00000000..8680e557
--- /dev/null
+++ b/application/LaunchController.cpp
@@ -0,0 +1,231 @@
+#include "LaunchController.h"
+#include <auth/MojangAccountList.h>
+#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 <QLineEdit>
+#include <QInputDialog>
+#include <tasks/Task.h>
+#include <auth/YggdrasilTask.h>
+
+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<MojangAccountList> 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.
+ //on_actionManageAccounts_triggered();
+ }
+ }
+ 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<AuthSession>();
+ 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;
+ }
+
+ m_launcher->setProfiler(m_profiler);
+
+ 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()
+{
+ auto profiler = m_launcher->getProfiler();
+
+ if (!profiler)
+ {
+ m_launcher->launch();
+ return;
+ }
+
+ QString error;
+ if (!profiler->check(&error))
+ {
+ m_launcher->abort();
+ QMessageBox::critical(m_parentWidget, tr("Error"), tr("Couldn't start profiler: %1").arg(error));
+ return;
+ }
+ BaseProfiler *profilerInstance = 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
new file mode 100644
index 00000000..f62d5124
--- /dev/null
+++ b/application/LaunchController.h
@@ -0,0 +1,49 @@
+#pragma once
+#include <QObject>
+#include <BaseInstance.h>
+#include <tools/BaseProfiler.h>
+
+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 <BaseLauncher> m_launcher;
+};
diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp
index eb258d20..e5961693 100644
--- a/application/MainWindow.cpp
+++ b/application/MainWindow.cpp
@@ -357,7 +357,6 @@ namespace Ui {
#include "pages/global/JavaPage.h"
#include "pages/global/MinecraftPage.h"
-#include "ConsoleWindow.h"
#include "pagedialog/PageDialog.h"
#include "InstanceList.h"
@@ -382,6 +381,7 @@ namespace Ui {
#include "java/JavaUtils.h"
#include "JavaCommon.h"
#include "InstancePageProvider.h"
+#include "LaunchController.h"
#include "minecraft/SkinUtils.h"
#include "resources/Resource.h"
@@ -719,7 +719,7 @@ void MainWindow::updateToolsMenu()
QAction *normalLaunch = launchMenu->addAction(tr("Launch"));
connect(normalLaunch, &QAction::triggered, [this]()
- { doLaunch(); });
+ { launch(m_selectedInstance); });
launchMenu->addSeparator()->setText(tr("Profilers"));
for (auto profiler : MMC->profilers().values())
{
@@ -734,7 +734,7 @@ void MainWindow::updateToolsMenu()
else
{
connect(profilerAction, &QAction::triggered, [this, profiler]()
- { doLaunch(true, profiler.get()); });
+ { launch(m_selectedInstance, true, profiler.get()); });
}
}
launchMenu->addSeparator()->setText(tr("Tools"));
@@ -1563,17 +1563,14 @@ void MainWindow::instanceActivated(QModelIndex index)
if (!inst)
return;
- JavaCommon::checkJVMArgs(inst->settings()->get("JvmArgs").toString(), this);
-
- doLaunch();
+ launch(inst);
}
void MainWindow::on_actionLaunchInstance_triggered()
{
if (m_selectedInstance)
{
- JavaCommon::checkJVMArgs(m_selectedInstance->settings()->get("JvmArgs").toString(), this);
- doLaunch();
+ launch(m_selectedInstance);
}
}
@@ -1581,207 +1578,21 @@ void MainWindow::on_actionLaunchInstanceOffline_triggered()
{
if (m_selectedInstance)
{
- JavaCommon::checkJVMArgs(m_selectedInstance->settings()->get("JvmArgs").toString(), this);
- doLaunch(false);
+ launch(m_selectedInstance, false);
}
}
-void MainWindow::doLaunch(bool online, BaseProfilerFactory *profiler)
+void MainWindow::launch(InstancePtr instance, bool online, BaseProfilerFactory* profiler)
{
- if (!m_selectedInstance)
- return;
-
- // Find an account to use.
- std::shared_ptr<MojangAccountList> 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(
- this, 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.
- on_actionManageAccounts_triggered();
- }
- }
- 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, this);
-
- 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)
- {
- AuthSessionPtr session(new AuthSession());
- session->wants_online = online;
- auto task = account->login(session, password);
- if (task)
- {
- // We'll need to validate the access token to make sure the account
- // is still logged in.
- ProgressDialog progDialog(this);
- if (online)
- progDialog.setSkipButton(true, tr("Play Offline"));
- progDialog.exec(task.get());
- if (!task->successful())
- {
- failReason = task->failReason();
- }
- }
- switch (session->status)
- {
- case AuthSession::Undetermined:
- {
- qCritical() << "Received undetermined session status during login. Bye.";
- tryagain = false;
- break;
- }
- case AuthSession::RequiresPassword:
- {
- EditAccountDialog passDialog(failReason, this, 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 = session->player_name;
- QString name = QInputDialog::getText(this, tr("Player name"),
- tr("Choose your offline mode player name."),
- QLineEdit::Normal, session->player_name, &ok);
- if (!ok)
- {
- tryagain = false;
- break;
- }
- if (name.length())
- {
- usedname = name;
- }
- session->MakeOffline(usedname);
- // offline flavored game from here :3
- }
- case AuthSession::PlayableOnline:
- {
- launchInstance(m_selectedInstance, session, profiler);
- tryagain = false;
- }
- }
- }
-}
-
-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");
-
- QString launchScript;
-
- if(!instance->reload())
- {
- QMessageBox::critical(this, tr("Error"), tr("Couldn't load the instance profile."));
- return;
- }
-
- 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->start();
+ m_launchController = std::make_shared<LaunchController>();
+ m_launchController->setInstance(instance);
+ m_launchController->setOnline(online);
+ m_launchController->setParentWidget(this);
+ m_launchController->setProfiler(profiler);
+ m_launchController->launch();
}
-void MainWindow::readyForLaunch(std::shared_ptr<BaseLauncher> launcher)
-{
- auto profiler = launcher->getProfiler();
-
- if (!profiler)
- {
- launcher->launch();
- return;
- }
- QString error;
- if (!profiler->check(&error))
- {
- launcher->abort();
- QMessageBox::critical(this, tr("Error"), tr("Couldn't start profiler: %1").arg(error));
- return;
- }
- BaseProfiler *profilerInstance = profiler->createProfiler(launcher->instance(), this);
-
- connect(profilerInstance, &BaseProfiler::readyToLaunch,
- [this, launcher](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();
- launcher->launch();
- });
- connect(profilerInstance, &BaseProfiler::abortLaunch,
- [this, launcher](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();
- launcher->abort();
- });
- profilerInstance->beginProfiling(launcher);
-}
/*
void MainWindow::onGameUpdateError(QString error)
{
@@ -1871,11 +1682,6 @@ void MainWindow::selectionBad()
setSelectedInstanceById(MMC->settings()->get("SelectedInstance").toString());
}
-void MainWindow::instanceEnded()
-{
- this->show();
-}
-
void MainWindow::checkSetDefaultJava()
{
const QString javaHack = "IntelHack";
diff --git a/application/MainWindow.h b/application/MainWindow.h
index 292a8d28..505e5f13 100644
--- a/application/MainWindow.h
+++ b/application/MainWindow.h
@@ -24,6 +24,7 @@
#include "net/NetJob.h"
#include "updater/GoUpdate.h"
+class LaunchController;
class NewsChecker;
class NotificationChecker;
class QToolButton;
@@ -31,7 +32,6 @@ class InstanceProxyModel;
class LabeledToolButton;
class QLabel;
class MinecraftLauncher;
-class ConsoleWindow;
class BaseProfilerFactory;
class GenericPageProvider;
@@ -116,25 +116,9 @@ slots:
void on_actionScreenshots_triggered();
- /*!
- * Launches the currently selected instance with the default account.
- * If no default account is selected, prompts the user to pick an account.
- */
- void doLaunch(bool online = true, BaseProfilerFactory *profiler = 0);
-
- /*!
- * Launches the given instance with the given account.
- * This function assumes that the given account has a valid, usable access token.
- */
- void launchInstance(InstancePtr instance, AuthSessionPtr session, BaseProfilerFactory *profiler = 0);
-
- void readyForLaunch(std::shared_ptr<BaseLauncher>);
-
void taskStart();
void taskEnd();
- void instanceEnded();
-
// called when an icon is changed in the icon model.
void iconUpdated(QString);
@@ -185,13 +169,13 @@ protected:
void instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version);
void instanceFromZipPack(QString instName, QString instGroup, QString instIcon, QUrl url);
void finalizeInstance(InstancePtr inst);
+ void launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr);
private:
Ui::MainWindow *ui;
class GroupView *view;
InstanceProxyModel *proxymodel;
NetJobPtr skin_download_job;
- ConsoleWindow *console;
LabeledToolButton *renameButton;
QToolButton *changeIconButton;
QToolButton *newsLabel;
@@ -199,6 +183,7 @@ private:
std::shared_ptr<GenericPageProvider> m_globalSettingsProvider;
std::shared_ptr<NewsChecker> m_newsChecker;
std::shared_ptr<NotificationChecker> m_notificationChecker;
+ std::shared_ptr<LaunchController> m_launchController;
InstancePtr m_selectedInstance;
QString m_currentInstIcon;
diff --git a/logic/BaseLauncher.cpp b/logic/BaseLauncher.cpp
index 991973e7..8dfb5f6d 100644
--- a/logic/BaseLauncher.cpp
+++ b/logic/BaseLauncher.cpp
@@ -297,16 +297,15 @@ void BaseLauncher::checkJavaFinished(JavaCheckResult result)
emit log(line, MessageLevel::Error);
}
emit log("\nCheck your MultiMC Java settings.", MessageLevel::MultiMC);
- m_instance->cleanupAfterRun();
- emit launch_failed(m_instance);
- // not running, failed
- m_instance->setRunning(false);
- return;
+ emitFailed(tr("Could not start java!"));
+ }
+ else
+ {
+ emit log(tr("Java version is %1!\n").arg(result.javaVersion), MessageLevel::MultiMC);
+ m_instance->settings()->set("JavaVersion", result.javaVersion);
+ m_instance->settings()->set("JavaTimestamp", m_javaUnixTime);
+ preLaunch();
}
- emit log(tr("Java version is %1!\n").arg(result.javaVersion), MessageLevel::MultiMC);
- m_instance->settings()->set("JavaVersion", result.javaVersion);
- m_instance->settings()->set("JavaTimestamp", m_javaUnixTime);
- preLaunch();
}
void BaseLauncher::executeTask()
@@ -401,13 +400,9 @@ void BaseLauncher::on_pre_state(LoggedProcess::State state)
case LoggedProcess::Crashed:
case LoggedProcess::FailedToStart:
{
- emit log(tr("Pre-Launch command failed with code %1.\n\n")
- .arg(m_prelaunchprocess.exitCode()),
- MessageLevel::Fatal);
- m_instance->cleanupAfterRun();
- emit prelaunch_failed(m_instance, m_prelaunchprocess.exitCode(), m_prelaunchprocess.exitStatus());
- // not running, failed
- m_instance->setRunning(false);
+ QString error = tr("Pre-Launch command failed with code %1.\n\n").arg(m_prelaunchprocess.exitCode());
+ emit log(error, MessageLevel::Fatal);
+ emitFailed(error);
return;
}
case LoggedProcess::Finished:
@@ -446,10 +441,7 @@ void BaseLauncher::updateFinished()
{
QString reason = tr("Instance update failed because: %1.\n\n").arg(m_updateTask->failReason());
emit log(reason, MessageLevel::Fatal);
- m_instance->cleanupAfterRun();
- emit update_failed(m_instance);
emitFailed(reason);
- m_instance->setRunning(false);
}
}
@@ -465,10 +457,9 @@ void BaseLauncher::makeReady()
auto realWrapperCommand = QStandardPaths::findExecutable(wrapperCommand);
if (realWrapperCommand.isEmpty())
{
- emit log(tr("The wrapper command \"%1\" couldn't be found.").arg(wrapperCommand), MessageLevel::Warning);
- m_instance->cleanupAfterRun();
- emit launch_failed(m_instance);
- m_instance->setRunning(false);
+ QString reason = tr("The wrapper command \"%1\" couldn't be found.").arg(wrapperCommand);
+ emit log(reason, MessageLevel::Fatal);
+ emitFailed(reason);
return;
}
emit log("Wrapper command is:\n" + wrapperCommand + "\n\n");
@@ -484,11 +475,9 @@ void BaseLauncher::makeReady()
if (!m_process.waitForStarted())
{
//: Error message displayed if instace can't start
- emit log(tr("Could not launch minecraft!"), MessageLevel::Error);
- m_instance->cleanupAfterRun();
- emit launch_failed(m_instance);
- // not running, failed
- m_instance->setRunning(false);
+ QString reason = tr("Could not launch minecraft!");
+ emit log(reason, MessageLevel::Fatal);
+ emitFailed(reason);
return;
}
@@ -497,7 +486,7 @@ void BaseLauncher::makeReady()
// send the launch script to the launcher part
m_process.write(launchScript.toUtf8());
- emit readyForLaunch(shared_from_this());
+ emit readyForLaunch();
}
void BaseLauncher::on_state(LoggedProcess::State state)
@@ -508,18 +497,17 @@ void BaseLauncher::on_state(LoggedProcess::State state)
case LoggedProcess::Aborted:
case LoggedProcess::Crashed:
case LoggedProcess::FailedToStart:
+ {
estat = QProcess::CrashExit;
+ emitFailed("Game crashed.");
+ return;
+ }
case LoggedProcess::Finished:
{
auto exitCode = m_process.exitCode();
m_postlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(exitCode));
-
// run post-exit
postLaunch();
- m_instance->cleanupAfterRun();
- // no longer running...
- m_instance->setRunning(false);
- emit ended(m_instance, exitCode, estat);
break;
}
case LoggedProcess::Skipped:
@@ -533,23 +521,6 @@ void BaseLauncher::on_state(LoggedProcess::State state)
}
}
-void BaseLauncher::on_post_state(LoggedProcess::State state)
-{
- switch(state)
- {
- case LoggedProcess::Aborted:
- case LoggedProcess::Crashed:
- case LoggedProcess::FailedToStart:
- case LoggedProcess::Finished:
- case LoggedProcess::Skipped:
- {
-
- }
- default:
- break;
- }
-}
-
void BaseLauncher::killProcess()
{
killed = true;
@@ -569,27 +540,58 @@ void BaseLauncher::killProcess()
void BaseLauncher::postLaunch()
{
+ if(killed)
+ return;
QString postlaunch_cmd = m_instance->settings()->get("PostExitCommand").toString();
if (!postlaunch_cmd.isEmpty())
{
postlaunch_cmd = substituteVariables(postlaunch_cmd);
emit log(tr("Running Post-Launch command: %1").arg(postlaunch_cmd));
m_postlaunchprocess.start(postlaunch_cmd);
- if (m_postlaunchprocess.exitStatus() != QProcess::NormalExit)
+ return;
+ }
+ emitSucceeded();
+}
+
+void BaseLauncher::on_post_state(LoggedProcess::State state)
+{
+ switch(state)
+ {
+ case LoggedProcess::Aborted:
+ case LoggedProcess::Crashed:
+ case LoggedProcess::FailedToStart:
{
- emit log(tr("Post-Launch command failed with code %1.\n\n")
- .arg(m_postlaunchprocess.exitCode()),
- MessageLevel::Error);
- emit postlaunch_failed(m_instance, m_postlaunchprocess.exitCode(),
- m_postlaunchprocess.exitStatus());
- // not running, failed
- m_instance->setRunning(false);
+ QString error = tr("Post-Launch command failed with code %1.\n\n").arg(m_postlaunchprocess.exitCode());
+ emit log(error, MessageLevel::Error);
+ emitFailed(error);
}
- else
+ case LoggedProcess::Finished:
+ {
emit log(tr("Post-Launch command ran successfully.\n\n"));
+ }
+ case LoggedProcess::Skipped:
+ {
+ emitSucceeded();
+ }
+ default:
+ break;
}
}
+void BaseLauncher::emitSucceeded()
+{
+ m_instance->cleanupAfterRun();
+ m_instance->setRunning(false);
+ Task::emitSucceeded();
+}
+
+void BaseLauncher::emitFailed(QString reason)
+{
+ m_instance->cleanupAfterRun();
+ m_instance->setRunning(false);
+ Task::emitFailed(reason);
+}
+
QString BaseLauncher::substituteVariables(const QString &cmd) const
{
QString out = cmd;
diff --git a/logic/BaseLauncher.h b/logic/BaseLauncher.h
index 076d664b..e233e4fd 100644
--- a/logic/BaseLauncher.h
+++ b/logic/BaseLauncher.h
@@ -26,8 +26,13 @@
#include "QObjectPtr.h"
#include "tasks/Task.h"
+class ProcessTask
+{
+
+};
+
class BaseProfilerFactory;
-class BaseLauncher: public Task, public std::enable_shared_from_this<BaseLauncher>
+class BaseLauncher: public Task
{
Q_OBJECT
protected:
@@ -102,6 +107,8 @@ protected: /* methods */
void updateInstance();
void makeReady();
void postLaunch();
+ virtual void emitFailed(QString reason);
+ virtual void emitSucceeded();
QString substituteVariables(const QString &cmd) const;
void initializeEnvironment();
@@ -113,34 +120,9 @@ protected: /* methods */
signals:
/**
- * @brief emitted when the Process immediately fails to run
- */
- void launch_failed(InstancePtr);
-
- /**
- * @brief emitted when the PreLaunchCommand fails
- */
- void prelaunch_failed(InstancePtr, int code, QProcess::ExitStatus status);
-
- /**
- * @brief emitted when the instance update fails
- */
- void update_failed(InstancePtr);
-
- /**
- * @brief emitted when the PostLaunchCommand fails
- */
- void postlaunch_failed(InstancePtr, int code, QProcess::ExitStatus status);
-
- /**
- * @brief emitted when the process has finished and the PostLaunchCommand was run
- */
- void ended(InstancePtr, int code, QProcess::ExitStatus status);
-
- /**
* @brief emitted when the launch preparations are done
*/
- void readyForLaunch(std::shared_ptr<BaseLauncher> launcher);
+ void readyForLaunch();
/**
* @brief emitted when we want to log something
@@ -158,7 +140,7 @@ protected slots:
void on_state(LoggedProcess::State state);
void on_post_state(LoggedProcess::State state);
- void checkJavaFinished(JavaCheckResult result);
+
protected:
InstancePtr m_instance;
@@ -172,15 +154,22 @@ protected:
bool killed = false;
QString m_header;
+/**
+ * java check step
+ */
+protected slots:
+ void checkJavaFinished(JavaCheckResult result);
+
+protected:
// for java checker and launch
QString m_javaPath;
qlonglong m_javaUnixTime;
+ std::shared_ptr<JavaChecker> m_JavaChecker;
protected: /* HACK: MINECRAFT: split! */
AuthSessionPtr m_session;
QString launchScript;
QString m_nativeFolder;
- std::shared_ptr<JavaChecker> m_JavaChecker;
std::shared_ptr<Task> m_updateTask;
protected: /* HACK: MINECRAFT: split! */