| 45 | #include "minecraft/PackProfile.h" |
| 46 | |
| 47 | void VerifyJavaInstall::executeTask() |
| 48 | { |
| 49 | auto instance = m_parent->instance(); |
| 50 | auto packProfile = instance->getPackProfile(); |
| 51 | auto settings = instance->settings(); |
| 52 | auto storedVersion = settings->get("JavaVersion").toString(); |
| 53 | auto ignoreCompatibility = settings->get("IgnoreJavaCompatibility").toBool(); |
| 54 | auto javaArchitecture = settings->get("JavaArchitecture").toString(); |
| 55 | auto maxMemAlloc = settings->get("MaxMemAlloc").toInt(); |
| 56 | |
| 57 | if (javaArchitecture == "32" && maxMemAlloc > 2048) { |
| 58 | emit logLine(tr("Max memory allocation exceeds the supported value.\n" |
| 59 | "The selected installation of Java is 32-bit and doesn't support more than 2048MiB of RAM.\n" |
| 60 | "The instance may not start due to this."), |
| 61 | MessageLevel::Error); |
| 62 | } |
| 63 | |
| 64 | auto compatibleMajors = packProfile->getProfile()->getCompatibleJavaMajors(); |
| 65 | |
| 66 | JavaVersion javaVersion(storedVersion); |
| 67 | |
| 68 | if (compatibleMajors.isEmpty() || compatibleMajors.contains(javaVersion.major())) { |
| 69 | emitSucceeded(); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (ignoreCompatibility) { |
| 74 | emit logLine(tr("Java major version is incompatible. Things might break."), MessageLevel::Warning); |
| 75 | emitSucceeded(); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | emit logLine(tr("This instance is not compatible with Java version %1.\n" |
| 80 | "Please switch to one of the following Java versions for this instance:") |
| 81 | .arg(javaVersion.major()), |
| 82 | MessageLevel::Error); |
| 83 | for (auto major : compatibleMajors) { |
| 84 | emit logLine(tr("Java version %1").arg(major), MessageLevel::Error); |
| 85 | } |
| 86 | emit logLine(tr("Go to instance Java settings to change your Java version or disable the Java compatibility check if you know what " |
| 87 | "you're doing."), |
| 88 | MessageLevel::Error); |
| 89 | |
| 90 | emitFailed(QString("Incompatible Java major version")); |
| 91 | } |
nothing calls this directly
no test coverage detected