Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into filters
This commit is contained in:
@@ -225,6 +225,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
|
||||
|
||||
// Don't quit on hiding the last window
|
||||
this->setQuitOnLastWindowClosed(false);
|
||||
this->setQuitLockEnabled(false);
|
||||
|
||||
// Commandline parsing
|
||||
QCommandLineParser parser;
|
||||
|
||||
@@ -801,15 +801,24 @@ QString NormalizePath(QString path)
|
||||
}
|
||||
}
|
||||
|
||||
QString badFilenameChars = "\"\\/?<>:;*|!+\r\n";
|
||||
static const QString BAD_PATH_CHARS = "\"?<>:;*|!+\r\n";
|
||||
static const QString BAD_FILENAME_CHARS = BAD_PATH_CHARS + "\\/";
|
||||
|
||||
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith)
|
||||
{
|
||||
for (int i = 0; i < string.length(); i++) {
|
||||
if (badFilenameChars.contains(string[i])) {
|
||||
for (int i = 0; i < string.length(); i++)
|
||||
if (string.at(i) < ' ' || BAD_FILENAME_CHARS.contains(string.at(i)))
|
||||
string[i] = replaceWith;
|
||||
}
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
QString RemoveInvalidPathChars(QString string, QChar replaceWith)
|
||||
{
|
||||
for (int i = 0; i < string.length(); i++)
|
||||
if (string.at(i) < ' ' || BAD_PATH_CHARS.contains(string.at(i)))
|
||||
string[i] = replaceWith;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@@ -1585,4 +1594,44 @@ uintmax_t hardLinkCount(const QString& path)
|
||||
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
|
||||
|
||||
@@ -342,6 +342,8 @@ QString NormalizePath(QString path);
|
||||
|
||||
QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-');
|
||||
|
||||
QString RemoveInvalidPathChars(QString string, QChar replaceWith = '-');
|
||||
|
||||
QString DirNameFromString(QString string, QString inDir = ".");
|
||||
|
||||
/// Checks if the a given Path contains "!"
|
||||
@@ -551,4 +553,8 @@ bool canLink(const QString& src, const QString& dst);
|
||||
|
||||
uintmax_t hardLinkCount(const QString& path);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QString getPathNameInLocal8bit(const QString& file);
|
||||
#endif
|
||||
|
||||
} // namespace FS
|
||||
|
||||
@@ -47,9 +47,6 @@
|
||||
#include <optional>
|
||||
|
||||
class QuaZip;
|
||||
namespace Flame {
|
||||
class FileResolvingTask;
|
||||
}
|
||||
|
||||
class InstanceImportTask : public InstanceTask {
|
||||
Q_OBJECT
|
||||
@@ -79,7 +76,6 @@ class InstanceImportTask : public InstanceTask {
|
||||
|
||||
private: /* data */
|
||||
NetJob::Ptr m_filesNetJob;
|
||||
shared_qobject_ptr<Flame::FileResolvingTask> m_modIdResolver;
|
||||
QUrl m_sourceUrl;
|
||||
QString m_archivePath;
|
||||
bool m_downloadRequired = false;
|
||||
|
||||
@@ -119,6 +119,7 @@ bool compressDirFiles(QuaZip* zip, QString dir, QFileInfoList files, bool follow
|
||||
bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files, bool followSymlinks)
|
||||
{
|
||||
QuaZip zip(fileCompressed);
|
||||
zip.setUtf8Enabled(true);
|
||||
QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
|
||||
if (!zip.open(QuaZip::mdCreate)) {
|
||||
QFile::remove(fileCompressed);
|
||||
@@ -141,6 +142,7 @@ bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files,
|
||||
bool createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod*>& mods)
|
||||
{
|
||||
QuaZip zipOut(targetJarPath);
|
||||
zipOut.setUtf8Enabled(true);
|
||||
if (!zipOut.open(QuaZip::mdCreate)) {
|
||||
QFile::remove(targetJarPath);
|
||||
qCritical() << "Failed to open the minecraft.jar for modding";
|
||||
@@ -286,10 +288,13 @@ std::optional<QStringList> extractSubDir(QuaZip* zip, const QString& subdir, con
|
||||
|
||||
do {
|
||||
QString file_name = zip->getCurrentFileName();
|
||||
#ifdef Q_OS_WIN
|
||||
file_name = FS::RemoveInvalidPathChars(file_name);
|
||||
#endif
|
||||
if (!file_name.startsWith(subdir))
|
||||
continue;
|
||||
|
||||
auto relative_file_name = QDir::fromNativeSeparators(file_name.remove(0, subdir.size()));
|
||||
auto relative_file_name = QDir::fromNativeSeparators(file_name.mid(subdir.size()));
|
||||
auto original_name = relative_file_name;
|
||||
|
||||
// Fix subdirs/files ending with a / getting transformed into absolute paths
|
||||
|
||||
@@ -163,6 +163,7 @@ class ExportToZipTask : public Task {
|
||||
, m_follow_symlinks(followSymlinks)
|
||||
{
|
||||
setAbortable(true);
|
||||
m_output.setUtf8Enabled(true);
|
||||
};
|
||||
ExportToZipTask(QString outputPath, QString dir, QFileInfoList files, QString destinationPrefix = "", bool followSymlinks = false)
|
||||
: ExportToZipTask(outputPath, QDir(dir), files, destinationPrefix, followSymlinks){};
|
||||
|
||||
@@ -55,6 +55,9 @@ void JavaChecker::performCheck()
|
||||
qDebug() << "Java checker library could not be found. Please check your installation.";
|
||||
return;
|
||||
}
|
||||
#ifdef Q_OS_WIN
|
||||
checkerJar = FS::getPathNameInLocal8bit(checkerJar);
|
||||
#endif
|
||||
|
||||
QStringList args;
|
||||
|
||||
|
||||
@@ -413,6 +413,8 @@ QList<QString> JavaUtils::FindJavaPaths()
|
||||
scanJavaDirs(FS::PathCombine(home, ".jdks"));
|
||||
// javas downloaded by sdkman
|
||||
scanJavaDirs(FS::PathCombine(home, ".sdkman/candidates/java"));
|
||||
// javas downloaded by gradle (toolchains)
|
||||
scanJavaDirs(FS::PathCombine(home, ".gradle/jdks"));
|
||||
|
||||
javas.append(getMinecraftJavaBundle());
|
||||
javas = addJavasFromEnv(javas);
|
||||
@@ -439,26 +441,25 @@ QString JavaUtils::getJavaCheckPath()
|
||||
|
||||
QStringList getMinecraftJavaBundle()
|
||||
{
|
||||
QString partialPath;
|
||||
QString executable = "java";
|
||||
QStringList processpaths;
|
||||
#if defined(Q_OS_OSX)
|
||||
partialPath = FS::PathCombine(QDir::homePath(), "Library/Application Support");
|
||||
processpaths << FS::PathCombine(QDir::homePath(), FS::PathCombine("Library", "Application Support", "minecraft", "runtime"));
|
||||
#elif defined(Q_OS_WIN32)
|
||||
partialPath = QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA", "");
|
||||
executable += "w.exe";
|
||||
|
||||
auto appDataPath = QProcessEnvironment::systemEnvironment().value("APPDATA", "");
|
||||
processpaths << FS::PathCombine(QFileInfo(appDataPath).absoluteFilePath(), ".minecraft", "runtime");
|
||||
|
||||
// add the microsoft store version of the launcher to the search. the current path is:
|
||||
// C:\Users\USERNAME\AppData\Local\Packages\Microsoft.4297127D64EC6_8wekyb3d8bbwe\LocalCache\Local\runtime
|
||||
auto localAppDataPath = QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA", "");
|
||||
auto minecraftMSStorePath =
|
||||
FS::PathCombine(QFileInfo(partialPath).absolutePath(), "Local", "Packages", "Microsoft.4297127D64EC6_8wekyb3d8bbwe");
|
||||
minecraftMSStorePath = FS::PathCombine(minecraftMSStorePath, "LocalCache", "Local", "runtime");
|
||||
processpaths << minecraftMSStorePath;
|
||||
FS::PathCombine(QFileInfo(localAppDataPath).absoluteFilePath(), "Packages", "Microsoft.4297127D64EC6_8wekyb3d8bbwe");
|
||||
processpaths << FS::PathCombine(minecraftMSStorePath, "LocalCache", "Local", "runtime");
|
||||
#else
|
||||
partialPath = QDir::homePath();
|
||||
processpaths << FS::PathCombine(QDir::homePath(), ".minecraft", "runtime");
|
||||
#endif
|
||||
auto minecraftDataPath = FS::PathCombine(partialPath, ".minecraft", "runtime");
|
||||
processpaths << minecraftDataPath;
|
||||
|
||||
QStringList javas;
|
||||
while (!processpaths.isEmpty()) {
|
||||
|
||||
@@ -79,6 +79,7 @@ void ExtractNatives::executeTask()
|
||||
auto settings = minecraftInstance->settings();
|
||||
|
||||
auto outputPath = minecraftInstance->getNativePath();
|
||||
FS::ensureFolderPathExists(outputPath);
|
||||
auto javaVersion = minecraftInstance->getJavaVersion();
|
||||
bool jniHackEnabled = javaVersion.major() >= 8;
|
||||
for (const auto& source : toExtract) {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <launch/LaunchStep.h>
|
||||
#include <memory>
|
||||
#include "minecraft/auth/AuthSession.h"
|
||||
|
||||
// FIXME: temporary wrapper for existing task.
|
||||
class ExtractNatives : public LaunchStep {
|
||||
|
||||
@@ -66,32 +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);
|
||||
// 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);
|
||||
output.resize(length - 1);
|
||||
QString ret = QString::fromStdWString(output);
|
||||
return ret;
|
||||
}
|
||||
#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");
|
||||
@@ -136,24 +110,15 @@ void LauncherPartLaunch::executeTask()
|
||||
|
||||
auto natPath = minecraftInstance->getNativePath();
|
||||
#ifdef Q_OS_WIN
|
||||
if (!fitsInLocal8bit(natPath)) {
|
||||
args << "-Djava.library.path=" + shortPathName(natPath);
|
||||
} else {
|
||||
args << "-Djava.library.path=" + natPath;
|
||||
}
|
||||
#else
|
||||
args << "-Djava.library.path=" + natPath;
|
||||
natPath = FS::getPathNameInLocal8bit(natPath);
|
||||
#endif
|
||||
args << "-Djava.library.path=" + natPath;
|
||||
|
||||
args << "-cp";
|
||||
#ifdef Q_OS_WIN
|
||||
QStringList processed;
|
||||
for (auto& item : classPath) {
|
||||
if (!fitsInLocal8bit(item)) {
|
||||
processed << shortPathName(item);
|
||||
} else {
|
||||
processed << item;
|
||||
}
|
||||
processed << FS::getPathNameInLocal8bit(item);
|
||||
}
|
||||
args << processed.join(';');
|
||||
#else
|
||||
|
||||
@@ -469,7 +469,7 @@ bool processZIP(Mod& mod, [[maybe_unused]] ProcessingLevel level)
|
||||
|
||||
QuaZipFile file(&zip);
|
||||
|
||||
if (zip.setCurrentFile("META-INF/mods.toml")) {
|
||||
if (zip.setCurrentFile("META-INF/mods.toml") || zip.setCurrentFile("META-INF/neoforge.mods.toml")) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
zip.close();
|
||||
return false;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "ui/pages/modplatform/OptionalModDialog.h"
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QFileInfo>
|
||||
#include <vector>
|
||||
|
||||
bool ModrinthCreationTask::abort()
|
||||
@@ -58,6 +59,7 @@ bool ModrinthCreationTask::updateInstance()
|
||||
return false;
|
||||
|
||||
auto version_name = inst->getManagedPackVersionName();
|
||||
m_root_path = QFileInfo(inst->gameRoot()).fileName();
|
||||
auto version_str = !version_name.isEmpty() ? tr(" (version %1)").arg(version_name) : "";
|
||||
|
||||
if (shouldConfirmUpdate()) {
|
||||
@@ -173,7 +175,7 @@ bool ModrinthCreationTask::createInstance()
|
||||
FS::ensureFilePathExists(new_index_place);
|
||||
QFile::rename(index_path, new_index_place);
|
||||
|
||||
auto mcPath = FS::PathCombine(m_stagingPath, "minecraft");
|
||||
auto mcPath = FS::PathCombine(m_stagingPath, m_root_path);
|
||||
|
||||
auto override_path = FS::PathCombine(m_stagingPath, "overrides");
|
||||
if (QFile::exists(override_path)) {
|
||||
@@ -234,7 +236,7 @@ bool ModrinthCreationTask::createInstance()
|
||||
|
||||
m_files_job.reset(new NetJob(tr("Mod Download Modrinth"), APPLICATION->network()));
|
||||
|
||||
auto root_modpack_path = FS::PathCombine(m_stagingPath, "minecraft");
|
||||
auto root_modpack_path = FS::PathCombine(m_stagingPath, m_root_path);
|
||||
auto root_modpack_url = QUrl::fromLocalFile(root_modpack_path);
|
||||
|
||||
for (auto file : m_files) {
|
||||
|
||||
@@ -46,4 +46,6 @@ class ModrinthCreationTask final : public InstanceCreationTask {
|
||||
NetJob::Ptr m_files_job;
|
||||
|
||||
std::optional<InstancePtr> m_instance;
|
||||
|
||||
QString m_root_path = "minecraft";
|
||||
};
|
||||
|
||||
@@ -123,6 +123,10 @@ void ImportPage::updateState()
|
||||
// need to find the download link for the modpack
|
||||
// format of url curseforge://install?addonId=IDHERE&fileId=IDHERE
|
||||
QUrlQuery query(url);
|
||||
if (query.allQueryItemValues("addonId").isEmpty() || query.allQueryItemValues("fileId").isEmpty()) {
|
||||
qDebug() << "Invalid curseforge link:" << url;
|
||||
return;
|
||||
}
|
||||
auto addonId = query.allQueryItemValues("addonId")[0];
|
||||
auto fileId = query.allQueryItemValues("fileId")[0];
|
||||
auto array = std::make_shared<QByteArray>();
|
||||
|
||||
Reference in New Issue
Block a user