Delete out non-needed functions from SysInfo

Delete LaunchContext

Signed-off-by: timoreo <contact@timoreo.fr>
This commit is contained in:
timoreo 2022-09-12 15:00:31 +02:00
parent dc84a61999
commit 89f1b60538
No known key found for this signature in database
GPG Key ID: 121A72C3512BA288
5 changed files with 1 additions and 185 deletions

View File

@ -271,8 +271,6 @@ set(MINECRAFT_SOURCES
minecraft/GradleSpecifier.h
minecraft/MinecraftInstance.cpp
minecraft/MinecraftInstance.h
minecraft/LaunchContext.cpp
minecraft/LaunchContext.h
minecraft/LaunchProfile.cpp
minecraft/LaunchProfile.h
minecraft/Component.cpp

View File

@ -1,18 +1,13 @@
#include <QString>
#include <QDebug>
#include "minecraft/LaunchContext.h"
#ifdef Q_OS_MACOS
#include <sys/sysctl.h>
#endif
#include <FileSystem.h>
#include <QStandardPaths>
#include <QFileInfo>
#include "MessageLevel.h"
#include <QFile>
#include <QProcess>
#include <QMap>
#include "java/JavaUtils.h"
#include "FileSystem.h"
#include "Commandline.h"
#include "Application.h"
@ -67,103 +62,5 @@ QString useQTForArch(){
#endif
return qtArch;
}
QString runCheckerForArch(LaunchContext launchContext){
QString checkerJar = JavaUtils::getJavaCheckPath();
if (checkerJar.isEmpty())
{
qDebug() << "Java checker library could not be found. Please check your installation.";
return useQTForArch();
}
QStringList args;
QProcessPtr process = new QProcess();
args.append({"-jar", checkerJar});
process->setArguments(args);
process->setProgram(launchContext.getJavaPath().toString());
process->setProcessChannelMode(QProcess::SeparateChannels);
process->setProcessEnvironment(CleanEnviroment());
qDebug() << "Running java checker: " + launchContext.getJavaPath().toString() + args.join(" ");;
process->start();
if(!process->waitForFinished(15000)){
// we've been waiting for 15 seconds! wtf! OR... it already finished. But HOW WOULD THAT HAPPEN?
process->kill(); // die. BUUURNNNN
// fallback to using polymc arch
return useQTForArch();
} else {
// yay we can use the java arch
QString stdout_javaChecker;
QString stderr_javaChecker;
// process stdout
QByteArray data = process->readAllStandardOutput();
QString added = QString::fromLocal8Bit(data);
added.remove('\r');
stdout_javaChecker += added;
// process stderr
data = process->readAllStandardError();
added = QString::fromLocal8Bit(data);
added.remove('\r');
stderr_javaChecker += added;
QMap<QString, QString> results;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QStringList lines = stdout_javaChecker.split("\n", Qt::SkipEmptyParts);
#else
QStringList lines = stdout_javaChecker.split("\n", QString::SkipEmptyParts);
#endif
for(QString line : lines)
{
line = line.trimmed();
// NOTE: workaround for GH-4125, where garbage is getting printed into stdout on bedrock linux
if (line.contains("/bedrock/strata")) {
continue;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
auto parts = line.split('=', Qt::SkipEmptyParts);
#else
auto parts = line.split('=', QString::SkipEmptyParts);
#endif
if(parts.size() != 2 || parts[0].isEmpty() || parts[1].isEmpty())
{
continue;
}
else
{
results.insert(parts[0], parts[1]);
}
}
if(!results.contains("os.arch") || !results.contains("java.version") || !results.contains("java.vendor"))
{
// wtf man why
// fallback to using polymc arch
return useQTForArch();
}
return results["os.arch"];
}
}
QString currentArch(LaunchContext launchContext) {
auto realJavaArchitecture = launchContext.getRealJavaArch().toString();
if(realJavaArchitecture == ""){
//BRO WHY NOW I HAVE TO USE A JAVA CHECKER >:(
qDebug() << "SysInfo: BRO I HAVE TO USE A JAVA CHECKER WHY IS JAVA ARCH BORKED";
launchContext.setRealJavaArch(runCheckerForArch(launchContext));
realJavaArchitecture = launchContext.getRealJavaArch().toString();
}
//qDebug() << "SysInfo: realJavaArch = " << realJavaArchitecture;
if(realJavaArchitecture == "aarch64"){
return "arm64";
} else {
return realJavaArchitecture;
}
}
}

View File

@ -1,12 +1,6 @@
#include <QString>
#include "minecraft/LaunchContext.h"
#ifdef Q_OS_MACOS
#include <sys/sysctl.h>
#endif
namespace SysInfo {
QString currentSystem();
QString currentArch(LaunchContext launchContext);
QString runCheckerForArch(LaunchContext launchContext);
QString useQTForArch();
}

View File

@ -1,39 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* PolyMC - Minecraft Launcher
* Copyright (C) 2022 Toshit Chawda <r58playz@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "LaunchContext.h"
LaunchContext::LaunchContext(SettingsObjectPtr instanceSettings){
m_instanceSettings = instanceSettings;
}
void LaunchContext::setRealJavaArch(QVariant realJavaArch)
{
m_instanceSettings->set("JavaRealArchitecture", realJavaArch);
}
QVariant LaunchContext::getRealJavaArch()
{
return m_instanceSettings->get("JavaRealArchitecture");
}
QVariant LaunchContext::getJavaPath()
{
return m_instanceSettings->get("JavaPath");
}

View File

@ -1,34 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* PolyMC - Minecraft Launcher
* Copyright (C) 2022 Toshit Chawda <r58playz@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include <QVariant>
#include "settings/SettingsObject.h"
#pragma once
class LaunchContext
{
public:
LaunchContext(SettingsObjectPtr instanceSettings);
void setRealJavaArch(QVariant realJavaArch);
QVariant getRealJavaArch();
QVariant getJavaPath();
private:
SettingsObjectPtr m_instanceSettings;
};