WIP some work on platform/java architecture detection

It's not just 32 vs 64, it's also different CPU instruction sets.
This commit is contained in:
Petr Mrázek 2022-08-20 11:09:30 +02:00
parent b5e81bbb0d
commit 010981799e
3 changed files with 59 additions and 13 deletions

View File

@ -88,7 +88,7 @@ void CheckJava::checkJavaFinished(JavaCheckResult result)
emit logLine(QString("Could not start java:"), MessageLevel::Error); emit logLine(QString("Could not start java:"), MessageLevel::Error);
emit logLines(result.errorLog.split('\n'), MessageLevel::Error); emit logLines(result.errorLog.split('\n'), MessageLevel::Error);
emit logLine("\nCheck your MultiMC Java settings.", MessageLevel::Launcher); emit logLine("\nCheck your MultiMC Java settings.", MessageLevel::Launcher);
printSystemInfo(false, false); printSystemInfo(Sys::Architecture());
emitFailed(QString("Could not start java!")); emitFailed(QString("Could not start java!"));
return; 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 logLine(QString("Java checker returned some invalid data MultiMC doesn't understand:"), MessageLevel::Error);
emit logLines(result.outLog.split('\n'), MessageLevel::Warning); emit logLines(result.outLog.split('\n'), MessageLevel::Warning);
emit logLine("\nMinecraft might not start properly.", MessageLevel::Launcher); emit logLine("\nMinecraft might not start properly.", MessageLevel::Launcher);
printSystemInfo(false, false); printSystemInfo(Sys::Architecture());
emitSucceeded(); emitSucceeded();
return; 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); emit logLine(QString("Java is version %1, using %2 architecture, from %3.\n\n").arg(version, architecture.name, vendor), MessageLevel::Launcher);
printSystemInfo(true, architecture == "64"); printSystemInfo(architecture);
} }
void CheckJava::printSystemInfo(bool javaIsKnown, bool javaIs64bit) void CheckJava::printSystemInfo(Sys::Architecture javaArch)
{ {
auto cpu64 = Sys::isCPU64bit(); auto cpuArch = Sys::cpuArchitecture();
auto system64 = Sys::isSystem64bit(); auto systemArch = Sys::systemArchitecture();
if(cpu64 != system64) 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); 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); 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);
} }

View File

@ -19,6 +19,8 @@
#include <LoggedProcess.h> #include <LoggedProcess.h>
#include <java/JavaChecker.h> #include <java/JavaChecker.h>
#include <sys.h>
class CheckJava: public LaunchStep class CheckJava: public LaunchStep
{ {
Q_OBJECT Q_OBJECT
@ -35,8 +37,8 @@ private slots:
void checkJavaFinished(JavaCheckResult result); void checkJavaFinished(JavaCheckResult result);
private: private:
void printJavaInfo(const QString & version, const QString & architecture, const QString & vendor); void printJavaInfo(const QString & version, const Sys::Architecture &architecture, const QString & vendor);
void printSystemInfo(bool javaIsKnown, bool javaIs64bit); void printSystemInfo(Sys::Architecture javaArch);
private: private:
QString m_javaPath; QString m_javaPath;

View File

@ -12,6 +12,46 @@ enum class KernelType {
Linux 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 struct KernelInfo
{ {
QString kernelName; QString kernelName;
@ -61,5 +101,9 @@ bool isSystem64bit();
bool isCPU64bit(); bool isCPU64bit();
Architecture systemArchitecture();
Architecture cpuArchitecture();
bool lookupSystemStatusCode(uint64_t code, std::string &name, std::string &description); bool lookupSystemStatusCode(uint64_t code, std::string &name, std::string &description);
} }