Moved getPathNameInLocal8bit inside FileSystem namespace

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
(cherry picked from commit 3ddcadcdd1)
This commit is contained in:
Trial97 2024-04-04 18:01:24 +03:00 committed by github-actions[bot]
parent 3e5e131a94
commit b2cca30cd9
5 changed files with 49 additions and 47 deletions

View File

@ -1594,4 +1594,44 @@ uintmax_t hardLinkCount(const QString& path)
return count; return count;
} }
#ifdef Q_OS_WIN
// returns 8.3 file format from long path
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;
}
// if the string survives roundtrip through local 8bit encoding...
bool fitsInLocal8bit(const QString& string)
{
return string == QString::fromLocal8Bit(string.toLocal8Bit());
}
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
} // namespace FS } // namespace FS

View File

@ -553,4 +553,8 @@ bool canLink(const QString& src, const QString& dst);
uintmax_t hardLinkCount(const QString& path); uintmax_t hardLinkCount(const QString& path);
#ifdef Q_OS_WIN
QString getPathNameInLocal8bit(const QString& file);
#endif
} // namespace FS } // namespace FS

View File

@ -47,9 +47,6 @@
#include <optional> #include <optional>
class QuaZip; class QuaZip;
namespace Flame {
class FileResolvingTask;
}
class InstanceImportTask : public InstanceTask { class InstanceImportTask : public InstanceTask {
Q_OBJECT Q_OBJECT
@ -79,7 +76,6 @@ class InstanceImportTask : public InstanceTask {
private: /* data */ private: /* data */
NetJob::Ptr m_filesNetJob; NetJob::Ptr m_filesNetJob;
shared_qobject_ptr<Flame::FileResolvingTask> m_modIdResolver;
QUrl m_sourceUrl; QUrl m_sourceUrl;
QString m_archivePath; QString m_archivePath;
bool m_downloadRequired = false; bool m_downloadRequired = false;

View File

@ -55,6 +55,9 @@ void JavaChecker::performCheck()
qDebug() << "Java checker library could not be found. Please check your installation."; qDebug() << "Java checker library could not be found. Please check your installation.";
return; return;
} }
#ifdef Q_OS_WIN
checkerJar = FS::getPathNameInLocal8bit(checkerJar);
#endif
QStringList args; QStringList args;

View File

@ -66,47 +66,6 @@ LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent) : LaunchStep(parent)
connect(&m_process, &LoggedProcess::stateChanged, this, &LauncherPartLaunch::on_state); 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() void LauncherPartLaunch::executeTask()
{ {
QString jarPath = APPLICATION->getJarPath("NewLaunch.jar"); QString jarPath = APPLICATION->getJarPath("NewLaunch.jar");
@ -151,7 +110,7 @@ void LauncherPartLaunch::executeTask()
auto natPath = minecraftInstance->getNativePath(); auto natPath = minecraftInstance->getNativePath();
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
natPath = getPathNameInLocal8bit(natPath); natPath = FS::getPathNameInLocal8bit(natPath);
#endif #endif
args << "-Djava.library.path=" + natPath; args << "-Djava.library.path=" + natPath;
@ -159,7 +118,7 @@ void LauncherPartLaunch::executeTask()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QStringList processed; QStringList processed;
for (auto& item : classPath) { for (auto& item : classPath) {
processed << getPathNameInLocal8bit(item); processed << FS::getPathNameInLocal8bit(item);
} }
args << processed.join(';'); args << processed.join(';');
#else #else