diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-07-26 17:55:29 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-07-26 17:55:29 +0200 |
commit | d8caab515aa641ec901592d40b5d30c6dfd282f5 (patch) | |
tree | 612b322374083309027204b656d4dc0a78780de8 /logic/launch/steps/LaunchMinecraft.cpp | |
parent | 6310f6569c2630f27ad72dc0a5fef9f9fec5a88c (diff) | |
download | MultiMC-d8caab515aa641ec901592d40b5d30c6dfd282f5.tar MultiMC-d8caab515aa641ec901592d40b5d30c6dfd282f5.tar.gz MultiMC-d8caab515aa641ec901592d40b5d30c6dfd282f5.tar.lz MultiMC-d8caab515aa641ec901592d40b5d30c6dfd282f5.tar.xz MultiMC-d8caab515aa641ec901592d40b5d30c6dfd282f5.zip |
GH-1053 add back update progress dialog
Diffstat (limited to 'logic/launch/steps/LaunchMinecraft.cpp')
-rw-r--r-- | logic/launch/steps/LaunchMinecraft.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/logic/launch/steps/LaunchMinecraft.cpp b/logic/launch/steps/LaunchMinecraft.cpp new file mode 100644 index 00000000..f01a584d --- /dev/null +++ b/logic/launch/steps/LaunchMinecraft.cpp @@ -0,0 +1,138 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LaunchMinecraft.h" +#include <launch/LaunchTask.h> +#include <minecraft/OneSixInstance.h> +#include <QStandardPaths> + +LaunchMinecraft::LaunchMinecraft(LaunchTask *parent) : LaunchStep(parent) +{ + connect(&m_process, &LoggedProcess::log, this, &LaunchMinecraft::logLines); + connect(&m_process, &LoggedProcess::stateChanged, this, &LaunchMinecraft::on_state); +} + +void LaunchMinecraft::executeTask() +{ + auto instance = m_parent->instance(); + std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance); + QStringList args = minecraftInstance->javaArguments(); + + QString allArgs = args.join(", "); + emit logLine("Java Arguments:\n[" + m_parent->censorPrivateInfo(allArgs) + "]\n\n", MessageLevel::MultiMC); + + auto javaPath = instance->settings()->get("JavaPath").toString(); + + m_process.setProcessEnvironment(instance->createEnvironment()); + + QString wrapperCommand = instance->getWrapperCommand(); + if(!wrapperCommand.isEmpty()) + { + auto realWrapperCommand = QStandardPaths::findExecutable(wrapperCommand); + if (realWrapperCommand.isEmpty()) + { + QString reason = tr("The wrapper command \"%1\" couldn't be found.").arg(wrapperCommand); + emit logLine(reason, MessageLevel::Fatal); + emitFailed(reason); + return; + } + emit logLine("Wrapper command is:\n" + wrapperCommand + "\n\n", MessageLevel::MultiMC); + args.prepend(javaPath); + m_process.start(wrapperCommand, args); + } + else + { + m_process.start(javaPath, args); + } +} + +void LaunchMinecraft::on_state(LoggedProcess::State state) +{ + switch(state) + { + case LoggedProcess::FailedToStart: + { + //: Error message displayed if instace can't start + QString reason = tr("Could not launch minecraft!"); + emit logLine(reason, MessageLevel::Fatal); + emitFailed(reason); + return; + } + case LoggedProcess::Aborted: + case LoggedProcess::Crashed: + + { + m_parent->setPid(-1); + emitFailed("Game crashed."); + return; + } + case LoggedProcess::Finished: + { + m_parent->setPid(-1); + auto exitCode = m_process.exitCode(); + //FIXME: make this work again + // m_postlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(exitCode)); + // run post-exit + emitSucceeded(); + break; + } + case LoggedProcess::Running: + emit logLine(tr("Minecraft process ID: %1\n\n").arg(m_process.processId()), MessageLevel::MultiMC); + m_parent->setPid(m_process.pid()); + m_parent->instance()->setLastLaunch(); + // send the launch script to the launcher part + m_process.write(m_launchScript.toUtf8()); + + mayProceed = true; + emit readyForLaunch(); + break; + default: + break; + } +} + +void LaunchMinecraft::setWorkingDirectory(const QString &wd) +{ + m_process.setWorkingDirectory(wd); +} + +void LaunchMinecraft::proceed() +{ + if(mayProceed) + { + QString launchString("launch\n"); + m_process.write(launchString.toUtf8()); + mayProceed = false; + } +} + +bool LaunchMinecraft::abort() +{ + if(mayProceed) + { + mayProceed = false; + QString launchString("abort\n"); + m_process.write(launchString.toUtf8()); + } + else + { + auto state = m_process.state(); + if (state == LoggedProcess::Running || state == LoggedProcess::Starting) + { + m_process.kill(); + } + } + return true; +} |