aboutsummaryrefslogtreecommitdiff
path: root/launcher/LaunchController.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/LaunchController.cpp')
-rw-r--r--launcher/LaunchController.cpp244
1 files changed, 97 insertions, 147 deletions
diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp
index 5d84b3bf..380489e0 100644
--- a/launcher/LaunchController.cpp
+++ b/launcher/LaunchController.cpp
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
- * PolyMC - Minecraft Launcher
+ * Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
*
* This program is free software: you can redistribute it and/or modify
@@ -34,44 +34,41 @@
*/
#include "LaunchController.h"
-#include "minecraft/auth/AccountList.h"
#include "Application.h"
+#include "minecraft/auth/AccountList.h"
-#include "ui/MainWindow.h"
#include "ui/InstanceWindow.h"
+#include "ui/MainWindow.h"
#include "ui/dialogs/CustomMessageBox.h"
-#include "ui/dialogs/ProfileSelectDialog.h"
-#include "ui/dialogs/ProgressDialog.h"
#include "ui/dialogs/EditAccountDialog.h"
+#include "ui/dialogs/ProfileSelectDialog.h"
#include "ui/dialogs/ProfileSetupDialog.h"
+#include "ui/dialogs/ProgressDialog.h"
-#include <QLineEdit>
-#include <QInputDialog>
-#include <QStringList>
+#include <QHostAddress>
#include <QHostInfo>
+#include <QInputDialog>
+#include <QLineEdit>
#include <QList>
-#include <QHostAddress>
#include <QPushButton>
+#include <QStringList>
#include "BuildConfig.h"
#include "JavaCommon.h"
-#include "tasks/Task.h"
-#include "minecraft/auth/AccountTask.h"
#include "launch/steps/TextPrint.h"
+#include "minecraft/auth/AccountTask.h"
+#include "tasks/Task.h"
-LaunchController::LaunchController(QObject *parent) : Task(parent)
-{
-}
+LaunchController::LaunchController(QObject* parent) : Task(parent) {}
void LaunchController::executeTask()
{
- if (!m_instance)
- {
+ if (!m_instance) {
emitFailed(tr("No instance specified!"));
return;
}
- if(!JavaCommon::checkJVMArgs(m_instance->settings()->get("JvmArgs").toString(), m_parentWidget)) {
+ if (!JavaCommon::checkJVMArgs(m_instance->settings()->get("JvmArgs").toString(), m_parentWidget)) {
emitFailed(tr("Invalid Java arguments specified. Please fix this first."));
return;
}
@@ -81,32 +78,25 @@ void LaunchController::executeTask()
void LaunchController::decideAccount()
{
- if(m_accountToUse) {
+ if (m_accountToUse) {
return;
}
// Find an account to use.
auto accounts = APPLICATION->accounts();
- if (accounts->count() <= 0)
- {
+ 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 Microsoft or Mojang "
- "account logged in. Mojang accounts can only be used offline. "
- "Would you like to open the account manager to add an account now?"),
- QMessageBox::Information,
- QMessageBox::Yes | QMessageBox::No
- )->exec();
-
- if (reply == QMessageBox::Yes)
- {
+ auto reply = CustomMessageBox::selectable(m_parentWidget, tr("No Accounts"),
+ tr("In order to play Minecraft, you must have at least one Microsoft or Mojang "
+ "account logged in. Mojang accounts can only be used offline. "
+ "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.
APPLICATION->ShowGlobalSettings(m_parentWidget, "accounts");
- }
- else if (reply == QMessageBox::No)
- {
+ } else if (reply == QMessageBox::No) {
// Do not open "profile select" dialog.
return;
}
@@ -121,14 +111,10 @@ void LaunchController::decideAccount()
m_accountToUse = accounts->at(instanceAccountIndex);
}
- if (!m_accountToUse)
- {
+ if (!m_accountToUse) {
// If no default account is set, ask the user which one to use.
- ProfileSelectDialog selectDialog(
- tr("Which account would you like to use?"),
- ProfileSelectDialog::GlobalDefaultCheckbox,
- m_parentWidget
- );
+ ProfileSelectDialog selectDialog(tr("Which account would you like to use?"), ProfileSelectDialog::GlobalDefaultCheckbox,
+ m_parentWidget);
selectDialog.exec();
@@ -142,13 +128,12 @@ void LaunchController::decideAccount()
}
}
-
-void LaunchController::login() {
+void LaunchController::login()
+{
decideAccount();
// if no account is selected, we bail
- if (!m_accountToUse)
- {
+ if (!m_accountToUse) {
emitFailed(tr("No account selected for launch."));
return;
}
@@ -157,15 +142,11 @@ void LaunchController::login() {
bool tryagain = true;
unsigned int tries = 0;
- while (tryagain)
- {
+ while (tryagain) {
if (tries > 0 && tries % 3 == 0) {
- auto result = QMessageBox::question(
- m_parentWidget,
- tr("Continue launch?"),
- tr("It looks like we couldn't launch after %1 tries. Do you want to continue trying?")
- .arg(tries)
- );
+ auto result =
+ QMessageBox::question(m_parentWidget, tr("Continue launch?"),
+ tr("It looks like we couldn't launch after %1 tries. Do you want to continue trying?").arg(tries));
if (result == QMessageBox::No) {
emitAborted();
@@ -179,60 +160,48 @@ void LaunchController::login() {
m_accountToUse->fillSession(m_session);
// Launch immediately in true offline mode
- if(m_accountToUse->isOffline()) {
+ if (m_accountToUse->isOffline()) {
launchInstance();
return;
}
- switch(m_accountToUse->accountState()) {
+ switch (m_accountToUse->accountState()) {
case AccountState::Offline: {
m_session->wants_online = false;
}
/* fallthrough */
case AccountState::Online: {
- if(!m_session->wants_online) {
+ if (!m_session->wants_online) {
// we ask the user for a player name
bool ok = false;
QString message = tr("Choose your offline mode player name.");
- if(m_session->demo) {
+ if (m_session->demo) {
message = tr("Choose your demo mode player name.");
}
QString lastOfflinePlayerName = APPLICATION->settings()->get("LastOfflinePlayerName").toString();
QString usedname = lastOfflinePlayerName.isEmpty() ? m_session->player_name : lastOfflinePlayerName;
- QString name = QInputDialog::getText(
- m_parentWidget,
- tr("Player name"),
- message,
- QLineEdit::Normal,
- usedname,
- &ok
- );
- if (!ok)
- {
+ QString name = QInputDialog::getText(m_parentWidget, tr("Player name"), message, QLineEdit::Normal, usedname, &ok);
+ if (!ok) {
tryagain = false;
break;
}
- if (name.length())
- {
+ if (name.length()) {
usedname = name;
APPLICATION->settings()->set("LastOfflinePlayerName", usedname);
}
m_session->MakeOffline(usedname);
// offline flavored game from here :3
}
- if(m_accountToUse->ownsMinecraft()) {
- if(!m_accountToUse->hasProfile()) {
+ if (m_accountToUse->ownsMinecraft()) {
+ if (!m_accountToUse->hasProfile()) {
// Now handle setting up a profile name here...
ProfileSetupDialog dialog(m_accountToUse, m_parentWidget);
- if (dialog.exec() == QDialog::Accepted)
- {
+ if (dialog.exec() == QDialog::Accepted) {
tryagain = true;
continue;
- }
- else
- {
+ } else {
emitFailed(tr("Received undetermined session status during login."));
return;
}
@@ -240,24 +209,24 @@ void LaunchController::login() {
// we own Minecraft, there is a profile, it's all ready to go!
launchInstance();
return;
- }
- else {
+ } else {
// play demo ?
QMessageBox box(m_parentWidget);
box.setWindowTitle(tr("Play demo?"));
- box.setText(tr("This account does not own Minecraft.\nYou need to purchase the game first to play it.\n\nDo you want to play the demo?"));
+ box.setText(
+ tr("This account does not own Minecraft.\nYou need to purchase the game first to play it.\n\nDo you want to play "
+ "the demo?"));
box.setIcon(QMessageBox::Warning);
auto demoButton = box.addButton(tr("Play Demo"), QMessageBox::ButtonRole::YesRole);
auto cancelButton = box.addButton(tr("Cancel"), QMessageBox::ButtonRole::NoRole);
box.setDefaultButton(cancelButton);
box.exec();
- if(box.clickedButton() == demoButton) {
+ if (box.clickedButton() == demoButton) {
// play demo here
m_session->MakeDemo();
launchInstance();
- }
- else {
+ } else {
emitFailed(tr("Launch cancelled - account does not own Minecraft."));
}
}
@@ -272,8 +241,7 @@ void LaunchController::login() {
case AccountState::Working: {
// refresh is in progress, we need to wait for it to finish to proceed.
ProgressDialog progDialog(m_parentWidget);
- if (m_online)
- {
+ if (m_online) {
progDialog.setSkipButton(true, tr("Play Offline"));
}
auto task = m_accountToUse->currentTask();
@@ -288,37 +256,24 @@ void LaunchController::login() {
*/
case AccountState::Expired: {
auto errorString = tr("The account has expired and needs to be logged into manually again.");
- QMessageBox::warning(
- m_parentWidget,
- tr("Account refresh failed"),
- errorString,
- QMessageBox::StandardButton::Ok,
- QMessageBox::StandardButton::Ok
- );
+ QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), errorString, QMessageBox::StandardButton::Ok,
+ QMessageBox::StandardButton::Ok);
emitFailed(errorString);
return;
}
case AccountState::Disabled: {
auto errorString = tr("The launcher's client identification has changed. Please remove this account and add it again.");
- QMessageBox::warning(
- m_parentWidget,
- tr("Client identification changed"),
- errorString,
- QMessageBox::StandardButton::Ok,
- QMessageBox::StandardButton::Ok
- );
+ QMessageBox::warning(m_parentWidget, tr("Client identification changed"), errorString, QMessageBox::StandardButton::Ok,
+ QMessageBox::StandardButton::Ok);
emitFailed(errorString);
return;
}
case AccountState::Gone: {
- auto errorString = tr("The account no longer exists on the servers. It may have been migrated, in which case please add the new account you migrated this one to.");
- QMessageBox::warning(
- m_parentWidget,
- tr("Account gone"),
- errorString,
- QMessageBox::StandardButton::Ok,
- QMessageBox::StandardButton::Ok
- );
+ auto errorString =
+ tr("The account no longer exists on the servers. It may have been migrated, in which case please add the new account "
+ "you migrated this one to.");
+ QMessageBox::warning(m_parentWidget, tr("Account gone"), errorString, QMessageBox::StandardButton::Ok,
+ QMessageBox::StandardButton::Ok);
emitFailed(errorString);
return;
}
@@ -332,48 +287,45 @@ 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->reloadSettings())
- {
+ if (!m_instance->reloadSettings()) {
QMessageBox::critical(m_parentWidget, tr("Error!"), tr("Couldn't load the instance profile."));
emitFailed(tr("Couldn't load the instance profile."));
return;
}
m_launcher = m_instance->createLaunchTask(m_session, m_serverToJoin);
- if (!m_launcher)
- {
+ if (!m_launcher) {
emitFailed(tr("Couldn't instantiate a launcher."));
return;
}
- auto console = qobject_cast<InstanceWindow *>(m_parentWidget);
+ auto console = qobject_cast<InstanceWindow*>(m_parentWidget);
auto showConsole = m_instance->settings()->get("ShowConsole").toBool();
- if(!console && showConsole)
- {
+ if (!console && showConsole) {
APPLICATION->showInstanceWindow(m_instance);
}
connect(m_launcher.get(), &LaunchTask::readyForLaunch, this, &LaunchController::readyForLaunch);
connect(m_launcher.get(), &LaunchTask::succeeded, this, &LaunchController::onSucceeded);
- connect(m_launcher.get(), &LaunchTask::failed, this, &LaunchController::onFailed);
+ connect(m_launcher.get(), &LaunchTask::failed, this, &LaunchController::onFailed);
connect(m_launcher.get(), &LaunchTask::requestProgress, this, &LaunchController::onProgressRequested);
// Prepend Online and Auth Status
QString online_mode;
- if(m_session->wants_online) {
+ if (m_session->wants_online) {
online_mode = "online";
// Prepend Server Status
- QStringList servers = {"authserver.mojang.com", "session.minecraft.net", "textures.minecraft.net", "api.mojang.com"};
+ QStringList servers = { "authserver.mojang.com", "session.minecraft.net", "textures.minecraft.net", "api.mojang.com" };
QString resolved_servers = "";
QHostInfo host_info;
- for(QString server : servers) {
+ for (QString server : servers) {
host_info = QHostInfo::fromName(server);
resolved_servers = resolved_servers + server + " resolves to:\n [";
- if(!host_info.addresses().isEmpty()) {
- for(QHostAddress address : host_info.addresses()) {
+ if (!host_info.addresses().isEmpty()) {
+ for (QHostAddress address : host_info.addresses()) {
resolved_servers = resolved_servers + address.toString();
- if(!host_info.addresses().endsWith(address)) {
+ if (!host_info.addresses().endsWith(address)) {
resolved_servers = resolved_servers + ", ";
}
}
@@ -387,37 +339,40 @@ void LaunchController::launchInstance()
online_mode = m_demo ? "demo" : "offline";
}
- m_launcher->prependStep(makeShared<TextPrint>(m_launcher.get(), "Launched instance in " + online_mode + " mode\n", MessageLevel::Launcher));
+ m_launcher->prependStep(
+ makeShared<TextPrint>(m_launcher.get(), "Launched instance in " + online_mode + " mode\n", MessageLevel::Launcher));
// Prepend Version
- m_launcher->prependStep(makeShared<TextPrint>(m_launcher.get(), BuildConfig.LAUNCHER_DISPLAYNAME + " version: " + BuildConfig.printableVersionString() + "\n\n", MessageLevel::Launcher));
+ {
+ auto versionString = QString("%1 version: %2 (%3)")
+ .arg(BuildConfig.LAUNCHER_DISPLAYNAME, BuildConfig.printableVersionString(), BuildConfig.BUILD_PLATFORM);
+ m_launcher->prependStep(makeShared<TextPrint>(m_launcher.get(), versionString + "\n\n", MessageLevel::Launcher));
+ }
m_launcher->start();
}
void LaunchController::readyForLaunch()
{
- if (!m_profiler)
- {
+ if (!m_profiler) {
m_launcher->proceed();
return;
}
QString error;
- if (!m_profiler->check(&error))
- {
+ if (!m_profiler->check(&error)) {
m_launcher->abort();
QMessageBox::critical(m_parentWidget, tr("Error!"), tr("Couldn't start profiler: %1").arg(error));
emitFailed("Profiler startup failed!");
return;
}
- BaseProfiler *profilerInstance = m_profiler->createProfiler(m_launcher->instance(), this);
+ BaseProfiler* profilerInstance = m_profiler->createProfiler(m_launcher->instance(), this);
- connect(profilerInstance, &BaseProfiler::readyToLaunch, [this](const QString & message)
- {
+ 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));
+ "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);
@@ -425,8 +380,7 @@ void LaunchController::readyForLaunch()
msg.exec();
m_launcher->proceed();
});
- connect(profilerInstance, &BaseProfiler::abortLaunch, [this](const QString & message)
- {
+ 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"));
@@ -447,8 +401,7 @@ void LaunchController::onSucceeded()
void LaunchController::onFailed(QString reason)
{
- if(m_instance->settings()->get("ShowConsoleOnError").toBool())
- {
+ if (m_instance->settings()->get("ShowConsoleOnError").toBool()) {
APPLICATION->showInstanceWindow(m_instance, "console");
}
emitFailed(reason);
@@ -464,21 +417,18 @@ void LaunchController::onProgressRequested(Task* task)
bool LaunchController::abort()
{
- if(!m_launcher)
- {
+ if (!m_launcher) {
return true;
}
- if(!m_launcher->canAbort())
- {
+ if (!m_launcher->canAbort()) {
return false;
}
- auto response = CustomMessageBox::selectable(
- m_parentWidget, tr("Kill Minecraft?"),
- tr("This can cause the instance to get corrupted and should only be used if Minecraft "
- "is frozen for some reason"),
- QMessageBox::Question, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)->exec();
- if (response == QMessageBox::Yes)
- {
+ auto response = CustomMessageBox::selectable(m_parentWidget, tr("Kill Minecraft?"),
+ tr("This can cause the instance to get corrupted and should only be used if Minecraft "
+ "is frozen for some reason"),
+ QMessageBox::Question, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)
+ ->exec();
+ if (response == QMessageBox::Yes) {
return m_launcher->abort();
}
return false;