Merge remote-tracking branch 'upstream/develop' into skinfix

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad
2023-09-02 22:13:50 +01:00
765 changed files with 21366 additions and 19387 deletions

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* PolyMC - Minecraft Launcher
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
*
* This program is free software: you can redistribute it and/or modify
@ -35,29 +35,27 @@
#include "LauncherPartLaunch.h"
#include <QStandardPaths>
#include <QRegularExpression>
#include <QStandardPaths>
#include "Application.h"
#include "Commandline.h"
#include "FileSystem.h"
#include "launch/LaunchTask.h"
#include "minecraft/MinecraftInstance.h"
#include "FileSystem.h"
#include "Commandline.h"
#include "Application.h"
#ifdef Q_OS_LINUX
#include "gamemode_client.h"
#endif
LauncherPartLaunch::LauncherPartLaunch(LaunchTask *parent) : LaunchStep(parent)
LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent) : LaunchStep(parent)
{
auto instance = parent->instance();
if (instance->settings()->get("CloseAfterLaunch").toBool())
{
std::shared_ptr<QMetaObject::Connection> connection{new QMetaObject::Connection};
*connection = connect(&m_process, &LoggedProcess::log, this, [=](QStringList lines, MessageLevel::Enum level) {
if (instance->settings()->get("CloseAfterLaunch").toBool()) {
std::shared_ptr<QMetaObject::Connection> connection{ new QMetaObject::Connection };
*connection = connect(&m_process, &LoggedProcess::log, this, [=](QStringList lines, [[maybe_unused]] MessageLevel::Enum level) {
qDebug() << lines;
if (lines.filter(QRegularExpression(".*Setting user.+", QRegularExpression::CaseInsensitiveOption)).length() != 0)
{
if (lines.filter(QRegularExpression(".*Setting user.+", QRegularExpression::CaseInsensitiveOption)).length() != 0) {
APPLICATION->closeAllWindows();
disconnect(*connection);
}
@ -71,7 +69,7 @@ LauncherPartLaunch::LauncherPartLaunch(LaunchTask *parent) : LaunchStep(parent)
#ifdef Q_OS_WIN
// returns 8.3 file format from long path
#include <windows.h>
QString shortPathName(const QString & file)
QString shortPathName(const QString& file)
{
auto input = file.toStdWString();
std::wstring output;
@ -81,15 +79,15 @@ QString shortPathName(const QString & file)
// 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);
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)
bool fitsInLocal8bit(const QString& string)
{
return string == QString::fromLocal8Bit(string.toLocal8Bit());
}
@ -97,9 +95,8 @@ bool fitsInLocal8bit(const QString & string)
void LauncherPartLaunch::executeTask()
{
QString jarPath = APPLICATION->getJarPath("NewLaunch.jar");
if (jarPath.isEmpty())
{
const char *reason = QT_TR_NOOP("Launcher library could not be found. Please check your installation.");
if (jarPath.isEmpty()) {
const char* reason = QT_TR_NOOP("Launcher library could not be found. Please check your installation.");
emit logLine(tr(reason), MessageLevel::Fatal);
emitFailed(tr(reason));
return;
@ -109,12 +106,10 @@ void LauncherPartLaunch::executeTask()
std::shared_ptr<MinecraftInstance> minecraftInstance = std::dynamic_pointer_cast<MinecraftInstance>(instance);
QString legacyJarPath;
if (minecraftInstance->getLauncher() == "legacy" || minecraftInstance->shouldApplyOnlineFixes())
{
if (minecraftInstance->getLauncher() == "legacy" || minecraftInstance->shouldApplyOnlineFixes()) {
legacyJarPath = APPLICATION->getJarPath("NewLaunchLegacy.jar");
if (legacyJarPath.isEmpty())
{
const char *reason = QT_TR_NOOP("Legacy launcher library could not be found. Please check your installation.");
if (legacyJarPath.isEmpty()) {
const char* reason = QT_TR_NOOP("Legacy launcher library could not be found. Please check your installation.");
emit logLine(tr(reason), MessageLevel::Fatal);
emitFailed(tr(reason));
return;
@ -141,12 +136,9 @@ void LauncherPartLaunch::executeTask()
auto natPath = minecraftInstance->getNativePath();
#ifdef Q_OS_WIN
if (!fitsInLocal8bit(natPath))
{
if (!fitsInLocal8bit(natPath)) {
args << "-Djava.library.path=" + shortPathName(natPath);
}
else
{
} else {
args << "-Djava.library.path=" + natPath;
}
#else
@ -156,14 +148,10 @@ void LauncherPartLaunch::executeTask()
args << "-cp";
#ifdef Q_OS_WIN
QStringList processed;
for(auto & item: classPath)
{
if (!fitsInLocal8bit(item))
{
for (auto& item : classPath) {
if (!fitsInLocal8bit(item)) {
processed << shortPathName(item);
}
else
{
} else {
processed << item;
}
}
@ -176,14 +164,12 @@ void LauncherPartLaunch::executeTask()
qDebug() << args.join(' ');
QString wrapperCommandStr = instance->getWrapperCommand().trimmed();
if(!wrapperCommandStr.isEmpty())
{
if (!wrapperCommandStr.isEmpty()) {
auto wrapperArgs = Commandline::splitArgs(wrapperCommandStr);
auto wrapperCommand = wrapperArgs.takeFirst();
auto realWrapperCommand = QStandardPaths::findExecutable(wrapperCommand);
if (realWrapperCommand.isEmpty())
{
const char *reason = QT_TR_NOOP("The wrapper command \"%1\" couldn't be found.");
if (realWrapperCommand.isEmpty()) {
const char* reason = QT_TR_NOOP("The wrapper command \"%1\" couldn't be found.");
emit logLine(QString(reason).arg(wrapperCommand), MessageLevel::Fatal);
emitFailed(tr(reason).arg(wrapperCommand));
return;
@ -191,18 +177,14 @@ void LauncherPartLaunch::executeTask()
emit logLine("Wrapper command is:\n" + wrapperCommandStr + "\n\n", MessageLevel::Launcher);
args.prepend(javaPath);
m_process.start(wrapperCommand, wrapperArgs + args);
}
else
{
} else {
m_process.start(javaPath, args);
}
#ifdef Q_OS_LINUX
if (instance->settings()->get("EnableFeralGamemode").toBool() && APPLICATION->capabilities() & Application::SupportsGameMode)
{
if (instance->settings()->get("EnableFeralGamemode").toBool() && APPLICATION->capabilities() & Application::SupportsGameMode) {
auto pid = m_process.processId();
if (pid)
{
if (pid) {
gamemode_request_start_for(pid);
}
}
@ -211,25 +193,21 @@ void LauncherPartLaunch::executeTask()
void LauncherPartLaunch::on_state(LoggedProcess::State state)
{
switch(state)
{
case LoggedProcess::FailedToStart:
{
switch (state) {
case LoggedProcess::FailedToStart: {
//: Error message displayed if instace can't start
const char *reason = QT_TR_NOOP("Could not launch Minecraft!");
const char* reason = QT_TR_NOOP("Could not launch Minecraft!");
emit logLine(reason, MessageLevel::Fatal);
emitFailed(tr(reason));
return;
}
case LoggedProcess::Aborted:
case LoggedProcess::Crashed:
{
case LoggedProcess::Crashed: {
m_parent->setPid(-1);
emitFailed(tr("Game crashed."));
return;
}
case LoggedProcess::Finished:
{
case LoggedProcess::Finished: {
auto instance = m_parent->instance();
if (instance->settings()->get("CloseAfterLaunch").toBool())
APPLICATION->showMainWindow();
@ -237,14 +215,13 @@ void LauncherPartLaunch::on_state(LoggedProcess::State state)
m_parent->setPid(-1);
// if the exit code wasn't 0, report this as a crash
auto exitCode = m_process.exitCode();
if(exitCode != 0)
{
if (exitCode != 0) {
emitFailed(tr("Game crashed."));
return;
}
//FIXME: make this work again
// m_postlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(exitCode));
// run post-exit
// FIXME: make this work again
// m_postlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(exitCode));
// run post-exit
emitSucceeded();
break;
}
@ -263,15 +240,14 @@ void LauncherPartLaunch::on_state(LoggedProcess::State state)
}
}
void LauncherPartLaunch::setWorkingDirectory(const QString &wd)
void LauncherPartLaunch::setWorkingDirectory(const QString& wd)
{
m_process.setWorkingDirectory(wd);
}
void LauncherPartLaunch::proceed()
{
if(mayProceed)
{
if (mayProceed) {
QString launchString("launch\n");
m_process.write(launchString.toUtf8());
mayProceed = false;
@ -280,17 +256,13 @@ void LauncherPartLaunch::proceed()
bool LauncherPartLaunch::abort()
{
if(mayProceed)
{
if (mayProceed) {
mayProceed = false;
QString launchString("abort\n");
m_process.write(launchString.toUtf8());
}
else
{
} else {
auto state = m_process.state();
if (state == LoggedProcess::Running || state == LoggedProcess::Starting)
{
if (state == LoggedProcess::Running || state == LoggedProcess::Starting) {
m_process.kill();
}
}