From 010981799ed87182d739849f1edf0abce38ac909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 20 Aug 2022 11:09:30 +0200 Subject: [PATCH] WIP some work on platform/java architecture detection It's not just 32 vs 64, it's also different CPU instruction sets. --- launcher/launch/steps/CheckJava.cpp | 22 +++++++-------- launcher/launch/steps/CheckJava.h | 6 ++-- libraries/systeminfo/include/sys.h | 44 +++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/launcher/launch/steps/CheckJava.cpp b/launcher/launch/steps/CheckJava.cpp index fb338231..6e1659c0 100644 --- a/launcher/launch/steps/CheckJava.cpp +++ b/launcher/launch/steps/CheckJava.cpp @@ -88,7 +88,7 @@ void CheckJava::checkJavaFinished(JavaCheckResult result) emit logLine(QString("Could not start java:"), MessageLevel::Error); emit logLines(result.errorLog.split('\n'), MessageLevel::Error); emit logLine("\nCheck your MultiMC Java settings.", MessageLevel::Launcher); - printSystemInfo(false, false); + printSystemInfo(Sys::Architecture()); emitFailed(QString("Could not start java!")); return; } @@ -97,7 +97,7 @@ void CheckJava::checkJavaFinished(JavaCheckResult result) emit logLine(QString("Java checker returned some invalid data MultiMC doesn't understand:"), MessageLevel::Error); emit logLines(result.outLog.split('\n'), MessageLevel::Warning); emit logLine("\nMinecraft might not start properly.", MessageLevel::Launcher); - printSystemInfo(false, false); + printSystemInfo(Sys::Architecture()); emitSucceeded(); return; } @@ -115,23 +115,23 @@ void CheckJava::checkJavaFinished(JavaCheckResult result) } } -void CheckJava::printJavaInfo(const QString& version, const QString& architecture, const QString & vendor) +void CheckJava::printJavaInfo(const QString& version, const Sys::Architecture &architecture, const QString & vendor) { - emit logLine(QString("Java is version %1, using %2-bit architecture, from %3.\n\n").arg(version, architecture, vendor), MessageLevel::Launcher); - printSystemInfo(true, architecture == "64"); + emit logLine(QString("Java is version %1, using %2 architecture, from %3.\n\n").arg(version, architecture.name, vendor), MessageLevel::Launcher); + printSystemInfo(architecture); } -void CheckJava::printSystemInfo(bool javaIsKnown, bool javaIs64bit) +void CheckJava::printSystemInfo(Sys::Architecture javaArch) { - auto cpu64 = Sys::isCPU64bit(); - auto system64 = Sys::isSystem64bit(); - if(cpu64 != system64) + auto cpuArch = Sys::cpuArchitecture(); + auto systemArch = Sys::systemArchitecture(); + if(cpuArch != systemArch) { emit logLine(QString("Your CPU architecture is not matching your system architecture. You might want to install a 64bit Operating System.\n\n"), MessageLevel::Error); } - if(javaIsKnown) + if(javaArch.isKnown()) { - if(javaIs64bit != system64) + if(javaArch != systemArch) { emit logLine(QString("Your Java architecture is not matching your system architecture. You might want to install a 64bit Java version.\n\n"), MessageLevel::Error); } diff --git a/launcher/launch/steps/CheckJava.h b/launcher/launch/steps/CheckJava.h index 68cd618b..704f77ac 100644 --- a/launcher/launch/steps/CheckJava.h +++ b/launcher/launch/steps/CheckJava.h @@ -19,6 +19,8 @@ #include #include +#include + class CheckJava: public LaunchStep { Q_OBJECT @@ -35,8 +37,8 @@ private slots: void checkJavaFinished(JavaCheckResult result); private: - void printJavaInfo(const QString & version, const QString & architecture, const QString & vendor); - void printSystemInfo(bool javaIsKnown, bool javaIs64bit); + void printJavaInfo(const QString & version, const Sys::Architecture &architecture, const QString & vendor); + void printSystemInfo(Sys::Architecture javaArch); private: QString m_javaPath; diff --git a/libraries/systeminfo/include/sys.h b/libraries/systeminfo/include/sys.h index c1d4ecf8..f09c5363 100644 --- a/libraries/systeminfo/include/sys.h +++ b/libraries/systeminfo/include/sys.h @@ -12,6 +12,46 @@ enum class KernelType { Linux }; +enum class ArchitectureType { + Intel32, + Amd64, + Arm64, + Unknown +}; + +struct Architecture { + Architecture() { + name = "unknown"; + type = ArchitectureType::Unknown; + } + Architecture(QString name) { + this->name = name; + type = ArchitectureType::Unknown; + } + Architecture(ArchitectureType type, QString name) { + this->name = name; + this->type = type; + } + + bool operator==(const Architecture &other) const { + if(type == ArchitectureType::Unknown && other.type == ArchitectureType::Unknown) { + return name == other.name; + } + return type == other.type; + } + + bool operator!=(const Architecture &other) const { + return !(*this == other); + } + + bool isKnown() const { + return type != ArchitectureType::Unknown; + } + + QString name; + ArchitectureType type; +}; + struct KernelInfo { QString kernelName; @@ -61,5 +101,9 @@ bool isSystem64bit(); bool isCPU64bit(); +Architecture systemArchitecture(); + +Architecture cpuArchitecture(); + bool lookupSystemStatusCode(uint64_t code, std::string &name, std::string &description); }