Fixed crash on non-latin instance name
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
90097f1309
commit
450b73328e
@ -74,16 +74,36 @@ QString shortPathName(const QString& file)
|
|||||||
auto input = file.toStdWString();
|
auto input = file.toStdWString();
|
||||||
std::wstring output;
|
std::wstring output;
|
||||||
long length = GetShortPathNameW(input.c_str(), NULL, 0);
|
long length = GetShortPathNameW(input.c_str(), NULL, 0);
|
||||||
|
if (length == 0)
|
||||||
|
return {};
|
||||||
// NOTE: this resizing might seem weird...
|
// NOTE: this resizing might seem weird...
|
||||||
// when GetShortPathNameW fails, it returns length including null character
|
// when GetShortPathNameW fails, it returns length including null character
|
||||||
// when it succeeds, it returns length excluding 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
|
// See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364989(v=vs.85).aspx
|
||||||
output.resize(length);
|
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);
|
output.resize(length - 1);
|
||||||
QString ret = QString::fromStdWString(output);
|
QString ret = QString::fromStdWString(output);
|
||||||
return ret;
|
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
|
#endif
|
||||||
|
|
||||||
// if the string survives roundtrip through local 8bit encoding...
|
// if the string survives roundtrip through local 8bit encoding...
|
||||||
@ -137,7 +157,7 @@ void LauncherPartLaunch::executeTask()
|
|||||||
auto natPath = minecraftInstance->getNativePath();
|
auto natPath = minecraftInstance->getNativePath();
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
if (!fitsInLocal8bit(natPath)) {
|
if (!fitsInLocal8bit(natPath)) {
|
||||||
args << "-Djava.library.path=" + shortPathName(natPath);
|
args << "-Djava.library.path=" + getShortPathName(natPath);
|
||||||
} else {
|
} else {
|
||||||
args << "-Djava.library.path=" + natPath;
|
args << "-Djava.library.path=" + natPath;
|
||||||
}
|
}
|
||||||
@ -150,7 +170,7 @@ void LauncherPartLaunch::executeTask()
|
|||||||
QStringList processed;
|
QStringList processed;
|
||||||
for (auto& item : classPath) {
|
for (auto& item : classPath) {
|
||||||
if (!fitsInLocal8bit(item)) {
|
if (!fitsInLocal8bit(item)) {
|
||||||
processed << shortPathName(item);
|
processed << getShortPathName(item);
|
||||||
} else {
|
} else {
|
||||||
processed << item;
|
processed << item;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user