From 464bc0f770880737597954fee8d48035b3274d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 27 Sep 2017 04:04:19 +0200 Subject: GH-1997 replace use of weird hacks with normal java arguments This affects classpath and java.library.path. The catch is that if the strings cannot be expressed in system codepage on Windows, it tries to use 8.3 paths. --- api/logic/minecraft/launch/LauncherPartLaunch.cpp | 60 ++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'api/logic/minecraft') diff --git a/api/logic/minecraft/launch/LauncherPartLaunch.cpp b/api/logic/minecraft/launch/LauncherPartLaunch.cpp index b641968c..3f9cf05a 100644 --- a/api/logic/minecraft/launch/LauncherPartLaunch.cpp +++ b/api/logic/minecraft/launch/LauncherPartLaunch.cpp @@ -28,6 +28,27 @@ LauncherPartLaunch::LauncherPartLaunch(LaunchTask *parent) : LaunchStep(parent) connect(&m_process, &LoggedProcess::stateChanged, this, &LauncherPartLaunch::on_state); } +#ifdef Q_OS_WIN +// returns 8.3 file format from long path +#include +QString shortPathName(const QString & file) +{ + auto input = file.toStdWString(); + std::wstring output; + long length = GetShortPathNameW(input, NULL, 0); + output.resize(length); + GetShortPathNameW(input,output,length); + QString ret = QString::fromStdWString(output); + return ret; +} +#endif + +// if the string survives roundtrip through local 8bit encoding... +bool fitsInLocal8bit(const QString & string) +{ + return string == QString::fromLocal8Bit(string.toLocal8Bit()); +} + void LauncherPartLaunch::executeTask() { auto instance = m_parent->instance(); @@ -45,7 +66,44 @@ void LauncherPartLaunch::executeTask() // make detachable - this will keep the process running even if the object is destroyed m_process.setDetachable(true); - args << "-jar" << FS::PathCombine(ENV.getJarsPath(), "NewLaunch.jar"); + auto classPath = minecraftInstance->getClassPath(); + classPath.prepend(FS::PathCombine(ENV.getJarsPath(), "NewLaunch.jar")); + + auto natPath = minecraftInstance->getNativePath(); +#ifdef Q_OS_WIN + if (!fitsInLocal8bit(natPath)) + { + args << "-Djava.library.path=" + shortPathName(natPath); + } + else + { + args << "-Djava.library.path=" + natPath; + } +#else + args << "-Djava.library.path=" + natPath; +#endif + + args << "-cp"; +#ifdef Q_OS_WIN + QStringList processed; + for(auto & item: classPath) + { + if (!fitsInLocal8bit(item)) + { + processed << shortPathName(item); + } + else + { + processed << item; + } + } + args << processed.join(';'); +#else + args << classPath.join(':'); +#endif + args << "org.multimc.EntryPoint"; + + qDebug() << args.join(' '); QString wrapperCommandStr = instance->getWrapperCommand().trimmed(); if(!wrapperCommandStr.isEmpty()) -- cgit v1.2.3