Moved getPathNameInLocal8bit inside FileSystem namespace

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2024-04-04 18:01:24 +03:00
parent 8ecab305ac
commit 3ddcadcdd1
5 changed files with 49 additions and 47 deletions

View File

@ -66,47 +66,6 @@ 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.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);
if (GetShortPathNameW(input.c_str(), (LPWSTR)output.c_str(), length) == 0)
return {};
output.resize(length - 1);
QString ret = QString::fromStdWString(output);
return ret;
}
QString getPathNameInLocal8bit(const QString& file)
{
if (!fitsInLocal8bit(file)) {
auto path = shortPathName(file);
if (!path.isEmpty()) {
return path;
}
// in case shortPathName fails just return the path as is
}
return file;
}
#endif
// if the string survives roundtrip through local 8bit encoding...
bool fitsInLocal8bit(const QString& string)
{
return string == QString::fromLocal8Bit(string.toLocal8Bit());
}
void LauncherPartLaunch::executeTask()
{
QString jarPath = APPLICATION->getJarPath("NewLaunch.jar");
@ -151,7 +110,7 @@ void LauncherPartLaunch::executeTask()
auto natPath = minecraftInstance->getNativePath();
#ifdef Q_OS_WIN
natPath = getPathNameInLocal8bit(natPath);
natPath = FS::getPathNameInLocal8bit(natPath);
#endif
args << "-Djava.library.path=" + natPath;
@ -159,7 +118,7 @@ void LauncherPartLaunch::executeTask()
#ifdef Q_OS_WIN
QStringList processed;
for (auto& item : classPath) {
processed << getPathNameInLocal8bit(item);
processed << FS::getPathNameInLocal8bit(item);
}
args << processed.join(';');
#else