summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-03-19 22:26:50 +0100
committerPetr Mrázek <peterix@gmail.com>2014-03-19 22:26:50 +0100
commit4623c1b34f35dd896a9ccacd9b982bca9dc0b880 (patch)
tree44ff87e0029dbc8cf5f6a839359414ffeb1ff180 /logic
parent39d37394423dc204efe774920a59ce010781b28c (diff)
parenta74f3b553ab3294e153d73366294e7c8fbc2372f (diff)
downloadMultiMC-4623c1b34f35dd896a9ccacd9b982bca9dc0b880.tar
MultiMC-4623c1b34f35dd896a9ccacd9b982bca9dc0b880.tar.gz
MultiMC-4623c1b34f35dd896a9ccacd9b982bca9dc0b880.tar.lz
MultiMC-4623c1b34f35dd896a9ccacd9b982bca9dc0b880.tar.xz
MultiMC-4623c1b34f35dd896a9ccacd9b982bca9dc0b880.zip
Merge remote-tracking branch 'origin/feature_fix_timeout' into develop
Diffstat (limited to 'logic')
-rw-r--r--logic/MinecraftProcess.cpp37
-rw-r--r--logic/MinecraftProcess.h1
2 files changed, 34 insertions, 4 deletions
diff --git a/logic/MinecraftProcess.cpp b/logic/MinecraftProcess.cpp
index effa1095..2dd40e99 100644
--- a/logic/MinecraftProcess.cpp
+++ b/logic/MinecraftProcess.cpp
@@ -259,7 +259,14 @@ void MinecraftProcess::finish(int code, ExitStatus status)
void MinecraftProcess::killMinecraft()
{
killed = true;
- kill();
+ if (m_prepostlaunchprocess.state() == QProcess::Running)
+ {
+ m_prepostlaunchprocess.kill();
+ }
+ else
+ {
+ kill();
+ }
}
bool MinecraftProcess::preLaunch()
@@ -271,8 +278,10 @@ bool MinecraftProcess::preLaunch()
// Launch
emit log(tr("Running Pre-Launch command: %1").arg(prelaunch_cmd));
m_prepostlaunchprocess.start(prelaunch_cmd);
- // Wait
- m_prepostlaunchprocess.waitForFinished();
+ if (!waitForPrePost())
+ {
+ return false;
+ }
// Flush console window
if (!m_err_leftover.isEmpty())
{
@@ -310,7 +319,10 @@ bool MinecraftProcess::postLaunch()
postlaunch_cmd = substituteVariables(postlaunch_cmd);
emit log(tr("Running Post-Launch command: %1").arg(postlaunch_cmd));
m_prepostlaunchprocess.start(postlaunch_cmd);
- m_prepostlaunchprocess.waitForFinished();
+ if (!waitForPrePost())
+ {
+ return false;
+ }
// Flush console window
if (!m_err_leftover.isEmpty())
{
@@ -338,6 +350,23 @@ bool MinecraftProcess::postLaunch()
return true;
}
+bool MinecraftProcess::waitForPrePost()
+{
+ m_prepostlaunchprocess.waitForStarted();
+ QEventLoop eventLoop;
+ auto finisher = [this, &eventLoop](QProcess::ProcessState state)
+ {
+ if (state == QProcess::NotRunning)
+ {
+ eventLoop.quit();
+ }
+ };
+ auto connection = connect(&m_prepostlaunchprocess, &QProcess::stateChanged, finisher);
+ int ret = eventLoop.exec();
+ disconnect(connection);
+ return ret == 0;
+}
+
QMap<QString, QString> MinecraftProcess::getVariables() const
{
QMap<QString, QString> out;
diff --git a/logic/MinecraftProcess.h b/logic/MinecraftProcess.h
index d91dad56..d47a6cd2 100644
--- a/logic/MinecraftProcess.h
+++ b/logic/MinecraftProcess.h
@@ -133,6 +133,7 @@ protected:
bool preLaunch();
bool postLaunch();
+ bool waitForPrePost();
QMap<QString, QString> getVariables() const;
QString substituteVariables(const QString &cmd) const;