diff options
author | Petr Mrázek <peterix@gmail.com> | 2017-09-27 04:04:19 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2017-09-27 04:04:19 +0200 |
commit | 464bc0f770880737597954fee8d48035b3274d6d (patch) | |
tree | b58196730487ff1826b4dd542c797ea2f37e540f /api/logic | |
parent | 0595a0009039abcfe68536e23c8a383c36000225 (diff) | |
download | MultiMC-464bc0f770880737597954fee8d48035b3274d6d.tar MultiMC-464bc0f770880737597954fee8d48035b3274d6d.tar.gz MultiMC-464bc0f770880737597954fee8d48035b3274d6d.tar.lz MultiMC-464bc0f770880737597954fee8d48035b3274d6d.tar.xz MultiMC-464bc0f770880737597954fee8d48035b3274d6d.zip |
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.
Diffstat (limited to 'api/logic')
-rw-r--r-- | api/logic/minecraft/launch/LauncherPartLaunch.cpp | 60 |
1 files changed, 59 insertions, 1 deletions
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 <windows.h> +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()) |