mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 05:07:46 +02:00
@ -34,7 +34,11 @@
|
||||
*/
|
||||
|
||||
#include "VerifyJavaInstall.h"
|
||||
#include <memory>
|
||||
|
||||
#include "Application.h"
|
||||
#include "java/JavaInstall.h"
|
||||
#include "java/JavaInstallList.h"
|
||||
#include "java/JavaVersion.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
@ -46,6 +50,7 @@ void VerifyJavaInstall::executeTask()
|
||||
auto settings = instance->settings();
|
||||
auto storedVersion = settings->get("JavaVersion").toString();
|
||||
auto ignoreCompatibility = settings->get("IgnoreJavaCompatibility").toBool();
|
||||
auto automaticJavaSwitch = settings->get("AutomaticJavaSwitch").toBool();
|
||||
|
||||
auto compatibleMajors = packProfile->getProfile()->getCompatibleJavaMajors();
|
||||
|
||||
@ -62,16 +67,38 @@ void VerifyJavaInstall::executeTask()
|
||||
return;
|
||||
}
|
||||
|
||||
emit logLine(tr("This instance is not compatible with Java version %1.\n"
|
||||
"Please switch to one of the following Java versions for this instance:")
|
||||
.arg(javaVersion.major()),
|
||||
MessageLevel::Error);
|
||||
for (auto major : compatibleMajors) {
|
||||
emit logLine(tr("Java version %1").arg(major), MessageLevel::Error);
|
||||
}
|
||||
emit logLine(tr("Go to instance Java settings to change your Java version or disable the Java compatibility check if you know what "
|
||||
"you're doing."),
|
||||
MessageLevel::Error);
|
||||
auto logFail = [this, &javaVersion, compatibleMajors] {
|
||||
emit logLine(tr("This instance is not compatible with Java version %1.\n"
|
||||
"Please switch to one of the following Java versions for this instance:")
|
||||
.arg(javaVersion.major()),
|
||||
MessageLevel::Error);
|
||||
for (auto major : compatibleMajors) {
|
||||
emit logLine(tr("Java version %1").arg(major), MessageLevel::Error);
|
||||
}
|
||||
emit logLine(tr("Go to instance Java settings to change your Java version or disable the Java compatibility check if you know what "
|
||||
"you're doing."),
|
||||
MessageLevel::Error);
|
||||
|
||||
emitFailed(QString("Incompatible Java major version"));
|
||||
emitFailed(QString("Incompatible Java major version"));
|
||||
};
|
||||
|
||||
if (automaticJavaSwitch || true) {
|
||||
settings->set("OverrideJava", true);
|
||||
auto javas = APPLICATION->javalist().get();
|
||||
auto task = javas->getLoadTask();
|
||||
connect(task.get(), &Task::finished, this, [this, javas, compatibleMajors, settings, &logFail] {
|
||||
for (auto i = 0; i < javas->count(); i++) {
|
||||
auto java = std::dynamic_pointer_cast<JavaInstall>(javas->at(i));
|
||||
if (java && compatibleMajors.contains(java->id.major())) {
|
||||
settings->set("OverrideJavaLocation", true);
|
||||
settings->set("JavaPath", java->path);
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
}
|
||||
logFail();
|
||||
});
|
||||
} else {
|
||||
logFail();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user