From 2fc18921b04536285ad82e49d61faaeb599c6d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 21 Jul 2015 09:21:59 +0200 Subject: [PATCH] GH-1053 add launch step creation to legacy instances --- logic/launch/steps/LaunchCommand.cpp | 2 +- logic/minecraft/LegacyInstance.cpp | 71 +++++++++++++++++++++++++--- logic/minecraft/LegacyUpdate.cpp | 2 +- 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/logic/launch/steps/LaunchCommand.cpp b/logic/launch/steps/LaunchCommand.cpp index 8b133dea4..2cbb37853 100644 --- a/logic/launch/steps/LaunchCommand.cpp +++ b/logic/launch/steps/LaunchCommand.cpp @@ -27,7 +27,7 @@ LaunchCommand::LaunchCommand(LaunchTask *parent) : LaunchStep(parent) void LaunchCommand::executeTask() { auto instance = m_parent->instance(); - std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); + std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); QStringList args = minecraftInstance->javaArguments(); QString allArgs = args.join(", "); diff --git a/logic/minecraft/LegacyInstance.cpp b/logic/minecraft/LegacyInstance.cpp index a0af19dc8..4648ce592 100644 --- a/logic/minecraft/LegacyInstance.cpp +++ b/logic/minecraft/LegacyInstance.cpp @@ -25,6 +25,12 @@ #include "minecraft/LegacyUpdate.h" #include "icons/IconList.h" #include "launch/LaunchTask.h" +#include +#include +#include +#include +#include +#include #include "minecraft/ModList.h" #include @@ -96,7 +102,7 @@ std::shared_ptr LegacyInstance::createUpdateTask() return std::shared_ptr(new LegacyUpdate(this, this)); } -std::shared_ptr LegacyInstance::createLaunchTask(AuthSessionPtr account) +std::shared_ptr LegacyInstance::createLaunchTask(AuthSessionPtr session) { QString launchScript; QIcon icon = ENV.icons()->getIcon(iconKey()); @@ -116,17 +122,70 @@ std::shared_ptr LegacyInstance::createLaunchTask(AuthSessionPtr acco QString lwjgl = QDir(m_lwjglFolderSetting->get().toString() + "/" + lwjglVersion()) .absolutePath(); - launchScript += "userName " + account->player_name + "\n"; - launchScript += "sessionId " + account->session + "\n"; + launchScript += "userName " + session->player_name + "\n"; + launchScript += "sessionId " + session->session + "\n"; launchScript += "windowTitle " + windowTitle() + "\n"; launchScript += "windowParams " + windowParams + "\n"; launchScript += "lwjgl " + lwjgl + "\n"; launchScript += "launcher legacy\n"; } auto process = LaunchTask::create(std::dynamic_pointer_cast(getSharedPtr())); - // process->setLaunchScript(launchScript); - // process->setWorkdir(minecraftRoot()); - // process->setLogin(account); + auto pptr = process.get(); + + // print a header + { + process->appendStep(std::make_shared(pptr, "Minecraft folder is:\n" + minecraftRoot() + "\n\n", MessageLevel::MultiMC)); + } + // run pre-launch command if that's needed + if(getPreLaunchCommand().size()) + { + auto step = std::make_shared(pptr); + step->setWorkingDirectory(minecraftRoot()); + process->appendStep(step); + } + // if we aren't in offline mode,. + if(session->status != AuthSession::PlayableOffline) + { + process->appendStep(std::make_shared(pptr)); + } + // if there are any jar mods + if(getJarMods().size()) + { + auto step = std::make_shared(pptr); + process->appendStep(step); + } + // actually launch the game + { + auto step = std::make_shared(pptr); + step->setWorkingDirectory(minecraftRoot()); + step->setLaunchScript(launchScript); + process->appendStep(step); + } + // run post-exit command if that's needed + if(getPostExitCommand().size()) + { + auto step = std::make_shared(pptr); + step->setWorkingDirectory(minecraftRoot()); + process->appendStep(step); + } + if (session) + { + QMap filter; + if (session->session != "-") + filter[session->session] = tr(""); + filter[session->access_token] = tr(""); + filter[session->client_token] = tr(""); + filter[session->uuid] = tr(""); + filter[session->player_name] = tr(""); + + auto i = session->u.properties.begin(); + while (i != session->u.properties.end()) + { + filter[i.value()] = "<" + i.key().toUpper() + ">"; + ++i; + } + process->setCensorFilter(filter); + } return process; } diff --git a/logic/minecraft/LegacyUpdate.cpp b/logic/minecraft/LegacyUpdate.cpp index 7ea20ad81..e136deece 100644 --- a/logic/minecraft/LegacyUpdate.cpp +++ b/logic/minecraft/LegacyUpdate.cpp @@ -326,7 +326,7 @@ void LegacyUpdate::extractLwjgl() setStatus(tr("Installing new LWJGL - extracting ") + name + "..."); QFile output(destFileName); output.open(QIODevice::WriteOnly); - output.write(file.readAll()); // FIXME: wste of memory!? + output.write(file.readAll()); output.close(); } file.close(); // do not forget to close!