summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-07-05 01:54:30 +0200
committerPetr Mrázek <peterix@gmail.com>2015-07-05 01:54:30 +0200
commit7f1320390c55e408a4b0081b2606eab3892a8148 (patch)
treee08183b17e551e6807939c5ad2932ae68e14f49b /logic
parent526a511f455234152ca9b5bc8c60d3c82cbfa417 (diff)
downloadMultiMC-7f1320390c55e408a4b0081b2606eab3892a8148.tar
MultiMC-7f1320390c55e408a4b0081b2606eab3892a8148.tar.gz
MultiMC-7f1320390c55e408a4b0081b2606eab3892a8148.tar.lz
MultiMC-7f1320390c55e408a4b0081b2606eab3892a8148.tar.xz
MultiMC-7f1320390c55e408a4b0081b2606eab3892a8148.zip
GH-1053 move launch process UI to a separate class
Diffstat (limited to 'logic')
-rw-r--r--logic/BaseLauncher.cpp122
-rw-r--r--logic/BaseLauncher.h47
2 files changed, 80 insertions, 89 deletions
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! */