From 5ecaed21b5412b0e4b9b9ecf5547ca8225c541a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 20 Jan 2016 03:23:19 +0100 Subject: GH-1411 fail if pre-launch and post-exit commands return non-zero values --- logic/launch/steps/PostLaunchCommand.cpp | 22 ++++++++++++++++++---- logic/launch/steps/PreLaunchCommand.cpp | 19 ++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) (limited to 'logic/launch/steps') diff --git a/logic/launch/steps/PostLaunchCommand.cpp b/logic/launch/steps/PostLaunchCommand.cpp index c7342188..29a45f1b 100644 --- a/logic/launch/steps/PostLaunchCommand.cpp +++ b/logic/launch/steps/PostLaunchCommand.cpp @@ -34,20 +34,34 @@ void PostLaunchCommand::executeTask() void PostLaunchCommand::on_state(LoggedProcess::State state) { + auto getError = [&]() + { + return tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); + }; switch(state) { case LoggedProcess::Aborted: case LoggedProcess::Crashed: case LoggedProcess::FailedToStart: { - QString error = tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); - emit logLine(error, MessageLevel::Error); + auto error = getError(); + emit logLine(error, MessageLevel::Fatal); emitFailed(error); + return; } case LoggedProcess::Finished: { - emit logLine(tr("Post-Launch command ran successfully.\n\n"), MessageLevel::MultiMC); - emitSucceeded(); + if(m_process.exitCode() != 0) + { + auto error = getError(); + emit logLine(error, MessageLevel::Fatal); + emitFailed(error); + } + else + { + emit logLine(tr("Post-Launch command ran successfully.\n\n"), MessageLevel::MultiMC); + emitSucceeded(); + } } default: break; diff --git a/logic/launch/steps/PreLaunchCommand.cpp b/logic/launch/steps/PreLaunchCommand.cpp index 5d5862d8..47197a82 100644 --- a/logic/launch/steps/PreLaunchCommand.cpp +++ b/logic/launch/steps/PreLaunchCommand.cpp @@ -35,21 +35,34 @@ void PreLaunchCommand::executeTask() void PreLaunchCommand::on_state(LoggedProcess::State state) { + auto getError = [&]() + { + return tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); + }; switch(state) { case LoggedProcess::Aborted: case LoggedProcess::Crashed: case LoggedProcess::FailedToStart: { - QString error = tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); + auto error = getError(); emit logLine(error, MessageLevel::Fatal); emitFailed(error); return; } case LoggedProcess::Finished: { - emit logLine(tr("Pre-Launch command ran successfully.\n\n"), MessageLevel::MultiMC); - emitSucceeded(); + if(m_process.exitCode() != 0) + { + auto error = getError(); + emit logLine(error, MessageLevel::Fatal); + emitFailed(error); + } + else + { + emit logLine(tr("Pre-Launch command ran successfully.\n\n"), MessageLevel::MultiMC); + emitSucceeded(); + } } default: break; -- cgit v1.2.3