From a74f3b553ab3294e153d73366294e7c8fbc2372f Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 15 Mar 2014 09:02:56 +0100 Subject: Remove the timeout for pre/post commands. Fixes #107 --- logic/MinecraftProcess.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'logic/MinecraftProcess.cpp') 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 MinecraftProcess::getVariables() const { QMap out; -- cgit v1.2.3