Regrab a few changes on SysInfo

Signed-off-by: timoreo <contact@timoreo.fr>
This commit is contained in:
timoreo 2022-07-10 20:21:52 +02:00
parent 53ddba8077
commit f946964490
No known key found for this signature in database
GPG Key ID: 121A72C3512BA288
5 changed files with 102 additions and 14 deletions

View File

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

View File

@ -1,6 +1,6 @@
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include "settings/SettingsObject.h" #include "minecraft/LaunchContext.h"
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
@ -68,18 +68,24 @@ QString useQTForArch(){
return qtArch; return qtArch;
} }
QString runCheckerForArch(const SettingsObjectPtr& settingsObj){ QString runCheckerForArch(LaunchContext launchContext){
QString checkerJar = FS::PathCombine(APPLICATION->getJarsPath(), "JavaCheck.jar"); QString checkerJar = JavaUtils::getJavaCheckPath();
if (checkerJar.isEmpty())
{
qDebug() << "Java checker library could not be found. Please check your installation.";
return useQTForArch();
}
QStringList args; QStringList args;
QProcessPtr process = new QProcess(); QProcessPtr process = new QProcess();
args.append({"-jar", checkerJar}); args.append({"-jar", checkerJar});
process->setArguments(args); process->setArguments(args);
process->setProgram(settingsObj->get("JavaPath").toString()); process->setProgram(launchContext.getJavaPath().toString());
process->setProcessChannelMode(QProcess::SeparateChannels); process->setProcessChannelMode(QProcess::SeparateChannels);
process->setProcessEnvironment(CleanEnviroment()); process->setProcessEnvironment(CleanEnviroment());
qDebug() << "Running java checker: " + settingsObj->get("JavaPath").toString() + args.join(" ");; qDebug() << "Running java checker: " + launchContext.getJavaPath().toString() + args.join(" ");;
process->start(); process->start();
if(!process->waitForFinished(15000)){ if(!process->waitForFinished(15000)){
@ -105,7 +111,11 @@ QString runCheckerForArch(const SettingsObjectPtr& settingsObj){
stderr_javaChecker += added; stderr_javaChecker += added;
QMap<QString, QString> results; 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); QStringList lines = stdout_javaChecker.split("\n", QString::SkipEmptyParts);
#endif
for(QString line : lines) for(QString line : lines)
{ {
line = line.trimmed(); line = line.trimmed();
@ -114,7 +124,11 @@ QString runCheckerForArch(const SettingsObjectPtr& settingsObj){
continue; continue;
} }
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
auto parts = line.split('=', Qt::SkipEmptyParts);
#else
auto parts = line.split('=', QString::SkipEmptyParts); auto parts = line.split('=', QString::SkipEmptyParts);
#endif
if(parts.size() != 2 || parts[0].isEmpty() || parts[1].isEmpty()) if(parts.size() != 2 || parts[0].isEmpty() || parts[1].isEmpty())
{ {
continue; continue;
@ -136,13 +150,13 @@ QString runCheckerForArch(const SettingsObjectPtr& settingsObj){
} }
} }
QString currentArch(const SettingsObjectPtr& settingsObj) { QString currentArch(LaunchContext launchContext) {
auto realJavaArchitecture = settingsObj->get("JavaRealArchitecture").toString(); auto realJavaArchitecture = launchContext.getRealJavaArch().toString();
if(realJavaArchitecture == ""){ if(realJavaArchitecture == ""){
//BRO WHY NOW I HAVE TO USE A JAVA CHECKER >:( //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"; qDebug() << "SysInfo: BRO I HAVE TO USE A JAVA CHECKER WHY IS JAVA ARCH BORKED";
settingsObj->set("JavaRealArchitecture", runCheckerForArch(settingsObj)); launchContext.setRealJavaArch(runCheckerForArch(launchContext));
realJavaArchitecture = settingsObj->get("JavaRealArchitecture").toString(); realJavaArchitecture = launchContext.getRealJavaArch().toString();
} }
//qDebug() << "SysInfo: realJavaArch = " << realJavaArchitecture; //qDebug() << "SysInfo: realJavaArch = " << realJavaArchitecture;
if(realJavaArchitecture == "aarch64"){ if(realJavaArchitecture == "aarch64"){

View File

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

View File

@ -0,0 +1,39 @@
// 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

@ -0,0 +1,34 @@
// 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;
};