Fixed crash on non-latin instance name
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
(cherry picked from commit 450b73328e
)
This commit is contained in:
parent
5b168dd7b1
commit
1e5a29c423
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user