@ -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};
|
||||
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;
|
||||
@ -125,12 +122,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
|
||||
@ -140,14 +134,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;
|
||||
}
|
||||
}
|
||||
@ -160,14 +150,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;
|
||||
@ -175,18 +163,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);
|
||||
}
|
||||
}
|
||||
@ -195,25 +179,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();
|
||||
@ -221,14 +201,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;
|
||||
}
|
||||
@ -247,15 +226,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;
|
||||
@ -264,17 +242,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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user