| 60 | : LaunchStep(parent), m_instance(m_parent->instance()), m_supported_arch(SysInfo::getSupportedJavaArchitecture()) {}; |
| 61 | |
| 62 | void AutoInstallJava::executeTask() |
| 63 | { |
| 64 | auto settings = m_instance->settings(); |
| 65 | if (!APPLICATION->settings()->get("AutomaticJavaSwitch").toBool() || |
| 66 | (settings->get("OverrideJavaLocation").toBool() && QFileInfo::exists(settings->get("JavaPath").toString()))) { |
| 67 | emitSucceeded(); |
| 68 | return; |
| 69 | } |
| 70 | auto packProfile = m_instance->getPackProfile(); |
| 71 | if (!APPLICATION->settings()->get("AutomaticJavaDownload").toBool()) { |
| 72 | auto javas = APPLICATION->javalist(); |
| 73 | m_current_task = javas->getLoadTask(); |
| 74 | connect(m_current_task.get(), &Task::finished, this, [this, javas, packProfile] { |
| 75 | for (auto i = 0; i < javas->count(); i++) { |
| 76 | auto java = std::dynamic_pointer_cast<JavaInstall>(javas->at(i)); |
| 77 | if (java && packProfile->getProfile()->getCompatibleJavaMajors().contains(java->id.major())) { |
| 78 | if (!java->is_64bit) { |
| 79 | emit logLine(tr("The automatic Java mechanism detected a 32-bit installation of Java."), MessageLevel::Launcher); |
| 80 | } |
| 81 | setJavaPath(java->path); |
| 82 | return; |
| 83 | } |
| 84 | } |
| 85 | emit logLine(tr("No compatible Java version was found. Using the default one."), MessageLevel::Warning); |
| 86 | emitSucceeded(); |
| 87 | }); |
| 88 | connect(m_current_task.get(), &Task::progress, this, &AutoInstallJava::setProgress); |
| 89 | connect(m_current_task.get(), &Task::stepProgress, this, &AutoInstallJava::propagateStepProgress); |
| 90 | connect(m_current_task.get(), &Task::status, this, &AutoInstallJava::setStatus); |
| 91 | connect(m_current_task.get(), &Task::details, this, &AutoInstallJava::setDetails); |
| 92 | emit progressReportingRequest(); |
| 93 | return; |
| 94 | } |
| 95 | if (m_supported_arch.isEmpty()) { |
| 96 | emit logLine(tr("Your system (%1-%2) is not compatible with automatic Java installation. Using the default Java path.") |
| 97 | .arg(SysInfo::currentSystem(), SysInfo::useQTForArch()), |
| 98 | MessageLevel::Warning); |
| 99 | emitSucceeded(); |
| 100 | return; |
| 101 | } |
| 102 | auto wantedJavaName = packProfile->getProfile()->getCompatibleJavaName(); |
| 103 | if (wantedJavaName.isEmpty()) { |
| 104 | emit logLine(tr("Your meta information is out of date or doesn't have the information necessary to determine what installation of " |
| 105 | "Java should be used. " |
| 106 | "Using the default Java path."), |
| 107 | MessageLevel::Warning); |
| 108 | emitSucceeded(); |
| 109 | return; |
| 110 | } |
| 111 | QDir javaDir(APPLICATION->javaPath()); |
| 112 | auto wantedJavaPath = javaDir.absoluteFilePath(wantedJavaName); |
| 113 | if (QFileInfo::exists(wantedJavaPath)) { |
| 114 | setJavaPathFromPartial(); |
| 115 | return; |
| 116 | } |
| 117 | auto versionList = APPLICATION->metadataIndex()->get("net.minecraft.java"); |
| 118 | m_current_task = versionList->getLoadTask(); |
| 119 | connect(m_current_task.get(), &Task::succeeded, this, &AutoInstallJava::tryNextMajorJava); |
nothing calls this directly
no test coverage detected