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 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);
}

View File

@ -19,6 +19,8 @@
#include <LoggedProcess.h>
#include <java/JavaChecker.h>
#include <sys.h>
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;

View File

@ -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);
}