From 1a9793197fadaa25520e2cbb7f5d26e23eca2572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 28 Feb 2016 19:33:05 +0100 Subject: [PATCH] GH-1502 move launch script generation to the Minecraft launch step --- logic/launch/steps/LaunchMinecraft.cpp | 3 ++ logic/launch/steps/LaunchMinecraft.h | 6 ++- logic/minecraft/MinecraftInstance.h | 3 ++ logic/minecraft/legacy/LegacyInstance.cpp | 48 ++++++++++++----------- logic/minecraft/legacy/LegacyInstance.h | 2 + logic/minecraft/onesix/OneSixInstance.cpp | 8 +++- logic/minecraft/onesix/OneSixInstance.h | 2 + 7 files changed, 46 insertions(+), 26 deletions(-) diff --git a/logic/launch/steps/LaunchMinecraft.cpp b/logic/launch/steps/LaunchMinecraft.cpp index b0fe056f9..77a89f178 100644 --- a/logic/launch/steps/LaunchMinecraft.cpp +++ b/logic/launch/steps/LaunchMinecraft.cpp @@ -29,6 +29,9 @@ void LaunchMinecraft::executeTask() { auto instance = m_parent->instance(); std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); + + m_launchScript = minecraftInstance->createLaunchScript(m_session); + QStringList args = minecraftInstance->javaArguments(); // HACK: this is a workaround for MCL-3732 - 'server-resource-packs' is created. diff --git a/logic/launch/steps/LaunchMinecraft.h b/logic/launch/steps/LaunchMinecraft.h index 808ec33b5..6b9f79193 100644 --- a/logic/launch/steps/LaunchMinecraft.h +++ b/logic/launch/steps/LaunchMinecraft.h @@ -17,6 +17,7 @@ #include #include +#include class LaunchMinecraft: public LaunchStep { @@ -31,9 +32,9 @@ public: return true; } void setWorkingDirectory(const QString &wd); - void setLaunchScript(const QString &ls) + void setAuthSession(AuthSessionPtr session) { - m_launchScript = ls; + m_session = session; } private slots: void on_state(LoggedProcess::State state); @@ -42,5 +43,6 @@ private: LoggedProcess m_process; QString m_command; QString m_launchScript; + AuthSessionPtr m_session; bool mayProceed = false; }; diff --git a/logic/minecraft/MinecraftInstance.h b/logic/minecraft/MinecraftInstance.h index 5381ce4f7..cd3a8d909 100644 --- a/logic/minecraft/MinecraftInstance.h +++ b/logic/minecraft/MinecraftInstance.h @@ -36,6 +36,9 @@ public: return QList(); } + /// get the launch script to be used with this + virtual QString createLaunchScript(AuthSessionPtr session) = 0; + //FIXME: nuke? virtual std::shared_ptr versionList() const override; diff --git a/logic/minecraft/legacy/LegacyInstance.cpp b/logic/minecraft/legacy/LegacyInstance.cpp index 056079f65..6650598d9 100644 --- a/logic/minecraft/legacy/LegacyInstance.cpp +++ b/logic/minecraft/legacy/LegacyInstance.cpp @@ -105,31 +105,10 @@ std::shared_ptr LegacyInstance::createUpdateTask() std::shared_ptr LegacyInstance::createLaunchTask(AuthSessionPtr session) { - QString launchScript; QIcon icon = ENV.icons()->getIcon(iconKey()); auto pixmap = icon.pixmap(128, 128); pixmap.save(FS::PathCombine(minecraftRoot(), "icon.png"), "PNG"); - // create the launch script - { - // window size - QString windowParams; - if (settings()->get("LaunchMaximized").toBool()) - windowParams = "max"; - else - windowParams = QString("%1x%2") - .arg(settings()->get("MinecraftWinWidth").toInt()) - .arg(settings()->get("MinecraftWinHeight").toInt()); - - QString lwjgl = QDir(m_lwjglFolderSetting->get().toString() + "/" + lwjglVersion()) - .absolutePath(); - 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())); auto pptr = process.get(); @@ -163,7 +142,7 @@ std::shared_ptr LegacyInstance::createLaunchTask(AuthSessionPtr sess { auto step = std::make_shared(pptr); step->setWorkingDirectory(minecraftRoot()); - step->setLaunchScript(launchScript); + step->setAuthSession(session); process->appendStep(step); } // run post-exit command if that's needed @@ -261,6 +240,31 @@ std::shared_ptr LegacyInstance::createJarModdingTask() return std::make_shared(std::dynamic_pointer_cast(shared_from_this())); } +QString LegacyInstance::createLaunchScript(AuthSessionPtr session) +{ + QString launchScript; + + // window size + QString windowParams; + if (settings()->get("LaunchMaximized").toBool()) + { + windowParams = "max"; + } + else + { + windowParams = QString("%1x%2").arg(settings()->get("MinecraftWinWidth").toInt()).arg(settings()->get("MinecraftWinHeight").toInt()); + } + + QString lwjgl = QDir(m_lwjglFolderSetting->get().toString() + "/" + lwjglVersion()).absolutePath(); + 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"; + return launchScript; +} + void LegacyInstance::cleanupAfterRun() { // FIXME: delete the launcher and icons and whatnot. diff --git a/logic/minecraft/legacy/LegacyInstance.h b/logic/minecraft/legacy/LegacyInstance.h index a2ab86dec..d88e2a718 100644 --- a/logic/minecraft/legacy/LegacyInstance.h +++ b/logic/minecraft/legacy/LegacyInstance.h @@ -118,6 +118,8 @@ public: virtual std::shared_ptr createJarModdingTask() override; + virtual QString createLaunchScript(AuthSessionPtr session) override; + virtual void cleanupAfterRun() override; virtual QString typeName() const override; diff --git a/logic/minecraft/onesix/OneSixInstance.cpp b/logic/minecraft/onesix/OneSixInstance.cpp index 54381a99f..2846640c6 100644 --- a/logic/minecraft/onesix/OneSixInstance.cpp +++ b/logic/minecraft/onesix/OneSixInstance.cpp @@ -150,7 +150,7 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session) return parts; } -std::shared_ptr OneSixInstance::createLaunchTask(AuthSessionPtr session) +QString OneSixInstance::createLaunchScript(AuthSessionPtr session) { QString launchScript; QIcon icon = ENV.icons()->getIcon(iconKey()); @@ -256,7 +256,11 @@ std::shared_ptr OneSixInstance::createLaunchTask(AuthSessionPtr sess launchScript += "traits " + trait + "\n"; } launchScript += "launcher onesix\n"; + return launchScript; +} +std::shared_ptr OneSixInstance::createLaunchTask(AuthSessionPtr session) +{ auto process = LaunchTask::create(std::dynamic_pointer_cast(getSharedPtr())); auto pptr = process.get(); @@ -290,7 +294,7 @@ std::shared_ptr OneSixInstance::createLaunchTask(AuthSessionPtr sess { auto step = std::make_shared(pptr); step->setWorkingDirectory(minecraftRoot()); - step->setLaunchScript(launchScript); + step->setAuthSession(session); process->appendStep(step); } // run post-exit command if that's needed diff --git a/logic/minecraft/onesix/OneSixInstance.h b/logic/minecraft/onesix/OneSixInstance.h index 824e37862..09150158b 100644 --- a/logic/minecraft/onesix/OneSixInstance.h +++ b/logic/minecraft/onesix/OneSixInstance.h @@ -56,6 +56,8 @@ public: virtual std::shared_ptr createLaunchTask(AuthSessionPtr account) override; virtual std::shared_ptr createJarModdingTask() override; + virtual QString createLaunchScript(AuthSessionPtr session) override; + virtual void cleanupAfterRun() override; virtual QString intendedVersionId() const override;