diff --git a/launcher/minecraft/launch/LauncherPartLaunch.cpp b/launcher/minecraft/launch/LauncherPartLaunch.cpp index aa94edb5d..dcfb3d148 100644 --- a/launcher/minecraft/launch/LauncherPartLaunch.cpp +++ b/launcher/minecraft/launch/LauncherPartLaunch.cpp @@ -74,16 +74,36 @@ QString shortPathName(const QString& file) auto input = file.toStdWString(); std::wstring output; long length = GetShortPathNameW(input.c_str(), NULL, 0); + if (length == 0) + return {}; // NOTE: this resizing might seem weird... // when GetShortPathNameW fails, it returns length including null character // when it succeeds, it returns length excluding null character // See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364989(v=vs.85).aspx output.resize(length); - GetShortPathNameW(input.c_str(), (LPWSTR)output.c_str(), length); + if (GetShortPathNameW(input.c_str(), (LPWSTR)output.c_str(), length) == 0) + return {}; output.resize(length - 1); QString ret = QString::fromStdWString(output); return ret; } + +QString getShortPathName(const QString& file) +{ + auto path = shortPathName(file); + if (!path.isEmpty()) + return path; + // the path can not be getted due to the file/folder not existing + // so create the parrent folder + // and assume that we can concatenate the short path of the parent folder with the file name + // usually the 8 bit characters are in the instance name not in the name of the end files/folders we need + FS::ensureFilePathExists(file); + QFileInfo a(file); + auto partialShortPath = shortPathName(a.path()); + if (!partialShortPath.isEmpty()) + return FS::PathCombine(partialShortPath, a.fileName()); + return file; +} #endif // if the string survives roundtrip through local 8bit encoding... @@ -137,7 +157,7 @@ void LauncherPartLaunch::executeTask() auto natPath = minecraftInstance->getNativePath(); #ifdef Q_OS_WIN if (!fitsInLocal8bit(natPath)) { - args << "-Djava.library.path=" + shortPathName(natPath); + args << "-Djava.library.path=" + getShortPathName(natPath); } else { args << "-Djava.library.path=" + natPath; } @@ -150,7 +170,7 @@ void LauncherPartLaunch::executeTask() QStringList processed; for (auto& item : classPath) { if (!fitsInLocal8bit(item)) { - processed << shortPathName(item); + processed << getShortPathName(item); } else { processed << item; }