GH-1502 move launch script generation to the Minecraft launch step

This commit is contained in:
Petr Mrázek 2016-02-28 19:33:05 +01:00
parent 9497b7e96c
commit 1a9793197f
7 changed files with 46 additions and 26 deletions

View File

@ -29,6 +29,9 @@ void LaunchMinecraft::executeTask()
{ {
auto instance = m_parent->instance(); auto instance = m_parent->instance();
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance); std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
m_launchScript = minecraftInstance->createLaunchScript(m_session);
QStringList args = minecraftInstance->javaArguments(); QStringList args = minecraftInstance->javaArguments();
// HACK: this is a workaround for MCL-3732 - 'server-resource-packs' is created. // HACK: this is a workaround for MCL-3732 - 'server-resource-packs' is created.

View File

@ -17,6 +17,7 @@
#include <launch/LaunchStep.h> #include <launch/LaunchStep.h>
#include <launch/LoggedProcess.h> #include <launch/LoggedProcess.h>
#include <minecraft/auth/AuthSession.h>
class LaunchMinecraft: public LaunchStep class LaunchMinecraft: public LaunchStep
{ {
@ -31,9 +32,9 @@ public:
return true; return true;
} }
void setWorkingDirectory(const QString &wd); void setWorkingDirectory(const QString &wd);
void setLaunchScript(const QString &ls) void setAuthSession(AuthSessionPtr session)
{ {
m_launchScript = ls; m_session = session;
} }
private slots: private slots:
void on_state(LoggedProcess::State state); void on_state(LoggedProcess::State state);
@ -42,5 +43,6 @@ private:
LoggedProcess m_process; LoggedProcess m_process;
QString m_command; QString m_command;
QString m_launchScript; QString m_launchScript;
AuthSessionPtr m_session;
bool mayProceed = false; bool mayProceed = false;
}; };

View File

@ -36,6 +36,9 @@ public:
return QList<Mod>(); return QList<Mod>();
} }
/// get the launch script to be used with this
virtual QString createLaunchScript(AuthSessionPtr session) = 0;
//FIXME: nuke? //FIXME: nuke?
virtual std::shared_ptr<BaseVersionList> versionList() const override; virtual std::shared_ptr<BaseVersionList> versionList() const override;

View File

@ -105,31 +105,10 @@ std::shared_ptr<Task> LegacyInstance::createUpdateTask()
std::shared_ptr<LaunchTask> LegacyInstance::createLaunchTask(AuthSessionPtr session) std::shared_ptr<LaunchTask> LegacyInstance::createLaunchTask(AuthSessionPtr session)
{ {
QString launchScript;
QIcon icon = ENV.icons()->getIcon(iconKey()); QIcon icon = ENV.icons()->getIcon(iconKey());
auto pixmap = icon.pixmap(128, 128); auto pixmap = icon.pixmap(128, 128);
pixmap.save(FS::PathCombine(minecraftRoot(), "icon.png"), "PNG"); 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<MinecraftInstance>(getSharedPtr())); auto process = LaunchTask::create(std::dynamic_pointer_cast<MinecraftInstance>(getSharedPtr()));
auto pptr = process.get(); auto pptr = process.get();
@ -163,7 +142,7 @@ std::shared_ptr<LaunchTask> LegacyInstance::createLaunchTask(AuthSessionPtr sess
{ {
auto step = std::make_shared<LaunchMinecraft>(pptr); auto step = std::make_shared<LaunchMinecraft>(pptr);
step->setWorkingDirectory(minecraftRoot()); step->setWorkingDirectory(minecraftRoot());
step->setLaunchScript(launchScript); step->setAuthSession(session);
process->appendStep(step); process->appendStep(step);
} }
// run post-exit command if that's needed // run post-exit command if that's needed
@ -261,6 +240,31 @@ std::shared_ptr<Task> LegacyInstance::createJarModdingTask()
return std::make_shared<JarModTask>(std::dynamic_pointer_cast<LegacyInstance>(shared_from_this())); return std::make_shared<JarModTask>(std::dynamic_pointer_cast<LegacyInstance>(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() void LegacyInstance::cleanupAfterRun()
{ {
// FIXME: delete the launcher and icons and whatnot. // FIXME: delete the launcher and icons and whatnot.

View File

@ -118,6 +118,8 @@ public:
virtual std::shared_ptr<Task> createJarModdingTask() override; virtual std::shared_ptr<Task> createJarModdingTask() override;
virtual QString createLaunchScript(AuthSessionPtr session) override;
virtual void cleanupAfterRun() override; virtual void cleanupAfterRun() override;
virtual QString typeName() const override; virtual QString typeName() const override;

View File

@ -150,7 +150,7 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session)
return parts; return parts;
} }
std::shared_ptr<LaunchTask> OneSixInstance::createLaunchTask(AuthSessionPtr session) QString OneSixInstance::createLaunchScript(AuthSessionPtr session)
{ {
QString launchScript; QString launchScript;
QIcon icon = ENV.icons()->getIcon(iconKey()); QIcon icon = ENV.icons()->getIcon(iconKey());
@ -256,7 +256,11 @@ std::shared_ptr<LaunchTask> OneSixInstance::createLaunchTask(AuthSessionPtr sess
launchScript += "traits " + trait + "\n"; launchScript += "traits " + trait + "\n";
} }
launchScript += "launcher onesix\n"; launchScript += "launcher onesix\n";
return launchScript;
}
std::shared_ptr<LaunchTask> OneSixInstance::createLaunchTask(AuthSessionPtr session)
{
auto process = LaunchTask::create(std::dynamic_pointer_cast<MinecraftInstance>(getSharedPtr())); auto process = LaunchTask::create(std::dynamic_pointer_cast<MinecraftInstance>(getSharedPtr()));
auto pptr = process.get(); auto pptr = process.get();
@ -290,7 +294,7 @@ std::shared_ptr<LaunchTask> OneSixInstance::createLaunchTask(AuthSessionPtr sess
{ {
auto step = std::make_shared<LaunchMinecraft>(pptr); auto step = std::make_shared<LaunchMinecraft>(pptr);
step->setWorkingDirectory(minecraftRoot()); step->setWorkingDirectory(minecraftRoot());
step->setLaunchScript(launchScript); step->setAuthSession(session);
process->appendStep(step); process->appendStep(step);
} }
// run post-exit command if that's needed // run post-exit command if that's needed

View File

@ -56,6 +56,8 @@ public:
virtual std::shared_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account) override; virtual std::shared_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account) override;
virtual std::shared_ptr<Task> createJarModdingTask() override; virtual std::shared_ptr<Task> createJarModdingTask() override;
virtual QString createLaunchScript(AuthSessionPtr session) override;
virtual void cleanupAfterRun() override; virtual void cleanupAfterRun() override;
virtual QString intendedVersionId() const override; virtual QString intendedVersionId() const override;