From 28bc787d918cc43ee202eeac65048d5264fa2342 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 8 May 2025 22:40:21 +0300 Subject: [PATCH] feat(java): add default java majors profiles Signed-off-by: Trial97 --- launcher/Application.cpp | 33 ++ launcher/Application.h | 2 + launcher/CMakeLists.txt | 3 + launcher/minecraft/MinecraftInstance.cpp | 74 ++++ launcher/minecraft/MinecraftInstance.h | 1 + launcher/minecraft/launch/AutoInstallJava.cpp | 20 +- launcher/settings/OverrideSetting.cpp | 12 + launcher/settings/OverrideSetting.h | 3 + launcher/settings/PassthroughSetting.cpp | 13 + launcher/settings/PassthroughSetting.h | 3 + launcher/settings/SettingsObject.cpp | 26 ++ launcher/settings/SettingsObject.h | 2 + .../ui/widgets/JavaProfileSettingsWidget.cpp | 292 +++++++++++++++ .../ui/widgets/JavaProfileSettingsWidget.h | 70 ++++ .../ui/widgets/JavaProfileSettingsWidget.ui | 310 +++++++++++++++ launcher/ui/widgets/JavaSettingsWidget.cpp | 259 ++----------- launcher/ui/widgets/JavaSettingsWidget.h | 14 +- launcher/ui/widgets/JavaSettingsWidget.ui | 352 +----------------- .../ui/widgets/MinecraftSettingsWidget.cpp | 20 +- launcher/ui/widgets/MinecraftSettingsWidget.h | 4 +- 20 files changed, 932 insertions(+), 581 deletions(-) create mode 100644 launcher/ui/widgets/JavaProfileSettingsWidget.cpp create mode 100644 launcher/ui/widgets/JavaProfileSettingsWidget.h create mode 100644 launcher/ui/widgets/JavaProfileSettingsWidget.ui diff --git a/launcher/Application.cpp b/launcher/Application.cpp index d7182c48d..e190d50ee 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -44,6 +44,7 @@ #include "BuildConfig.h" #include "DataMigrationTask.h" +#include "Json.h" #include "java/JavaInstallList.h" #include "net/PasteUpload.h" #include "pathmatcher/MultiMatcher.h" @@ -757,6 +758,13 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) m_settings->registerSetting("AutomaticJavaDownload", defaultEnableAutoJava); m_settings->registerSetting("UserAskedAboutAutomaticJavaDownload", false); + m_settings->registerSetting("SupportedJavaMajors", Json::fromStringList({ "8", "16", "17", "21" })); + + for (auto major : + Json::toStringList(m_settings->get("SupportedJavaMajors").toString())) { // dynamically registers posible settings + registerJavaMajorSettings(major); + } + // Legacy settings m_settings->registerSetting("OnlineFixes", false); @@ -2067,3 +2075,28 @@ bool Application::checkQSavePath(QString path) } return false; } + +void Application::registerJavaMajorSettings(QString major) +{ + auto locationOverride = m_settings->registerSetting(QString("OverrideJava%1Location").arg(major), false); + auto argsOverride = m_settings->registerSetting(QString("OverrideJava%1Args").arg(major), false); + auto memorySetting = m_settings->registerSetting(QString("OverrideMemory%1").arg(major), false); + + m_settings->registerOverride(QString("Java%1Path").arg(major), m_settings->getSetting("JavaPath"), locationOverride); + m_settings->registerOverride(QString("Jvm%1Args").arg(major), m_settings->getSetting("JvmArgs"), argsOverride); + + m_settings->registerOverride(QString("MinMemAlloc%1").arg(major), m_settings->getSetting("MinMemAlloc"), memorySetting); + m_settings->registerOverride(QString("MaxMemAlloc%1").arg(major), m_settings->getSetting("MaxMemAlloc"), memorySetting); + m_settings->registerOverride(QString("PermGen%1").arg(major), m_settings->getSetting("PermGen"), memorySetting); + + m_settings->registerOverride(QString("IgnoreJava%1Compatibility").arg(major), m_settings->getSetting("IgnoreJavaCompatibility"), + locationOverride); + + // special! + m_settings->registerPassthrough(QString("Java%1Signature").arg(major), m_settings->getSetting("JavaSignature"), locationOverride); + m_settings->registerPassthrough(QString("Java%1Architecture").arg(major), m_settings->getSetting("JavaArchitecture"), locationOverride); + m_settings->registerPassthrough(QString("Java%1RealArchitecture").arg(major), m_settings->getSetting("JavaRealArchitecture"), + locationOverride); + m_settings->registerPassthrough(QString("Java%1Version").arg(major), m_settings->getSetting("JavaVersion"), locationOverride); + m_settings->registerPassthrough(QString("Java%1Vendor").arg(major), m_settings->getSetting("JavaVendor"), locationOverride); +} diff --git a/launcher/Application.h b/launcher/Application.h index 52a84b461..bd6733c36 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -142,6 +142,8 @@ class Application : public QApplication { void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password); + void registerJavaMajorSettings(QString major); + shared_qobject_ptr network(); shared_qobject_ptr metacache(); diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 194694d7f..9e8e54e29 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1165,6 +1165,8 @@ SET(LAUNCHER_SOURCES ui/widgets/MinecraftSettingsWidget.cpp ui/widgets/JavaSettingsWidget.h ui/widgets/JavaSettingsWidget.cpp + ui/widgets/JavaProfileSettingsWidget.h + ui/widgets/JavaProfileSettingsWidget.cpp # GUI - instance group view ui/instanceview/InstanceProxyModel.cpp @@ -1244,6 +1246,7 @@ qt_wrap_ui(LAUNCHER_UI ui/widgets/AppearanceWidget.ui ui/widgets/MinecraftSettingsWidget.ui ui/widgets/JavaSettingsWidget.ui + ui/widgets/JavaProfileSettingsWidget.ui ui/dialogs/CopyInstanceDialog.ui ui/dialogs/CreateShortcutDialog.ui ui/dialogs/ProfileSetupDialog.ui diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 7749d0f6b..2e49acfb1 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -47,6 +47,8 @@ #include "minecraft/update/AssetUpdateTask.h" #include "minecraft/update/FMLLibrariesTask.h" #include "minecraft/update/LibrariesTask.h" +#include "settings/OverrideSetting.h" +#include "settings/PassthroughSetting.h" #include "settings/Setting.h" #include "settings/SettingsObject.h" @@ -1308,4 +1310,76 @@ QList MinecraftInstance::getJarMods() const return mods; } +// will set the correct override java settings for the current instance +// needs to be called after the minecraft index is loaded +QString MinecraftInstance::updateOverrideJavaSettings() +{ + auto settings = this->settings(); + auto appSettings = APPLICATION->settings(); + auto packProfile = getPackProfile(); + if (!packProfile) { + return {}; // the profile is not there yet + } + auto neededJavaMajors = packProfile->getProfile()->getCompatibleJavaMajors(); + if (neededJavaMajors.isEmpty()) { + return {}; // the info is not there yet + } + auto supportedJavaMajors = Json::toStringList(appSettings->get("SupportedJavaMajors").toString()); + QStringList unsupportedJavas; + auto overideSetting = [settings, appSettings](QString id, QString overide) { + auto pathS = settings->getSetting(id); + if (auto s = dynamic_cast(pathS.get())) { + s->switchOveride(appSettings->getSetting(overide)); + } + }; + auto passSetting = [settings, appSettings](QString id, QString overide) { + auto pathS = settings->getSetting(id); + if (auto s = dynamic_cast(pathS.get())) { + s->switchOveride(appSettings->getSetting(overide)); + } + }; + for (auto major : neededJavaMajors) { + auto majorStr = QString::number(major); + if (!supportedJavaMajors.contains(majorStr)) { + unsupportedJavas << majorStr; + continue; + } + + if (appSettings->get(QString("OverrideJava%1Location").arg(major)) + .toBool()) { // only consider the profile if it has the java location overriden + overideSetting("JavaPath", QString("Java%1Path").arg(major)); + overideSetting("IgnoreJavaCompatibility", QString("IgnoreJava%1Compatibility").arg(major)); + + // special! + passSetting("JavaSignature", QString("Java%1Signature").arg(major)); + passSetting("JavaArchitecture", QString("Java%1Architecture").arg(major)); + passSetting("JavaRealArchitecture", QString("Java%1RealArchitecture").arg(major)); + passSetting("JavaVersion", QString("Java%1Version").arg(major)); + passSetting("JavaVendor", QString("Java%1Vendor").arg(major)); + + overideSetting("JvmArgs", QString("Jvm%1Args").arg(major)); + + overideSetting("MinMemAlloc", QString("MinMemAlloc%1").arg(major)); + overideSetting("MaxMemAlloc", QString("MaxMemAlloc%1").arg(major)); + overideSetting("PermGen", QString("PermGen%1").arg(major)); + return majorStr; + } + } + // save missing profiles and register the new settings + // this shhould not ussually happen + if (!unsupportedJavas.isEmpty()) { + auto nextSupported = supportedJavaMajors; + for (auto major : unsupportedJavas) { + if (!nextSupported.contains(major)) { + APPLICATION->registerJavaMajorSettings(major); + nextSupported << major; + } + } + std::sort(nextSupported.begin(), nextSupported.end(), [](const QString& a, const QString& b) { return a.toInt() < b.toInt(); }); + + appSettings->set("SupportedJavaMajors", nextSupported); + } + return {}; +} + #include "MinecraftInstance.moc" diff --git a/launcher/minecraft/MinecraftInstance.h b/launcher/minecraft/MinecraftInstance.h index c6e519dd2..4a211301b 100644 --- a/launcher/minecraft/MinecraftInstance.h +++ b/launcher/minecraft/MinecraftInstance.h @@ -61,6 +61,7 @@ class MinecraftInstance : public BaseInstance { virtual void saveNow() override; void loadSpecificSettings() override; + QString updateOverrideJavaSettings(); // FIXME: remove QString typeName() const override; diff --git a/launcher/minecraft/launch/AutoInstallJava.cpp b/launcher/minecraft/launch/AutoInstallJava.cpp index 854590dd2..bec0d8568 100644 --- a/launcher/minecraft/launch/AutoInstallJava.cpp +++ b/launcher/minecraft/launch/AutoInstallJava.cpp @@ -62,8 +62,24 @@ AutoInstallJava::AutoInstallJava(LaunchTask* parent) void AutoInstallJava::executeTask() { auto settings = m_instance->settings(); - if (!APPLICATION->settings()->get("AutomaticJavaSwitch").toBool() || - (settings->get("OverrideJavaLocation").toBool() && QFileInfo::exists(settings->get("JavaPath").toString()))) { + if (!APPLICATION->settings()->get("AutomaticJavaSwitch").toBool()) { + emitSucceeded(); + return; + } + // link the instance settings with the correct java profile + // this will make the sure the profile settings are considered before global defaults + // instance>global profile>global default + auto profile = m_instance->updateOverrideJavaSettings(); + if ((settings->get("OverrideJavaLocation").toBool() && QFileInfo::exists(settings->get("JavaPath").toString()))) { + // user already overriden the path so the profile will only be used for other settings + emitSucceeded(); + return; + } + if (!profile.isEmpty()) { + // profile was found and user did not manage the java path so print a message about it + // this will also make sure we prioritizate the global profiles instead of selecting + // from users java or downloading new javas + emit logLine(tr("Using Java profile for Java %1.").arg(profile), MessageLevel::Launcher); emitSucceeded(); return; } diff --git a/launcher/settings/OverrideSetting.cpp b/launcher/settings/OverrideSetting.cpp index fee65b8db..d3f674232 100644 --- a/launcher/settings/OverrideSetting.cpp +++ b/launcher/settings/OverrideSetting.cpp @@ -23,6 +23,14 @@ OverrideSetting::OverrideSetting(std::shared_ptr other, std::shared_ptr m_gate = gate; } +OverrideSetting::OverrideSetting(QString id, std::shared_ptr other, std::shared_ptr gate) : Setting({ id }, QVariant()) +{ + Q_ASSERT(other); + Q_ASSERT(gate); + m_other = other; + m_gate = gate; +} + bool OverrideSetting::isOverriding() const { return m_gate->get().toBool(); @@ -50,3 +58,7 @@ void OverrideSetting::set(QVariant value) { Setting::set(value); } +void OverrideSetting::switchOveride(std::shared_ptr overridden) +{ + m_other = overridden; +} diff --git a/launcher/settings/OverrideSetting.h b/launcher/settings/OverrideSetting.h index 3763b5717..62e9ecc5d 100644 --- a/launcher/settings/OverrideSetting.h +++ b/launcher/settings/OverrideSetting.h @@ -30,12 +30,15 @@ class OverrideSetting : public Setting { Q_OBJECT public: explicit OverrideSetting(std::shared_ptr overridden, std::shared_ptr gate); + OverrideSetting(QString id, std::shared_ptr overridden, std::shared_ptr gate); virtual QVariant defValue() const; virtual QVariant get() const; virtual void set(QVariant value); virtual void reset(); + void switchOveride(std::shared_ptr overridden); + private: bool isOverriding() const; diff --git a/launcher/settings/PassthroughSetting.cpp b/launcher/settings/PassthroughSetting.cpp index 86bb861e4..b6ef1503c 100644 --- a/launcher/settings/PassthroughSetting.cpp +++ b/launcher/settings/PassthroughSetting.cpp @@ -23,6 +23,14 @@ PassthroughSetting::PassthroughSetting(std::shared_ptr other, std::shar m_gate = gate; } +PassthroughSetting::PassthroughSetting(QString id, std::shared_ptr other, std::shared_ptr gate) + : Setting({ id }, QVariant()) +{ + Q_ASSERT(other); + m_other = other; + m_gate = gate; +} + bool PassthroughSetting::isOverriding() const { if (!m_gate) { @@ -62,3 +70,8 @@ void PassthroughSetting::set(QVariant value) } m_other->set(value); } + +void PassthroughSetting::switchOveride(std::shared_ptr overridden) +{ + m_other = overridden; +} diff --git a/launcher/settings/PassthroughSetting.h b/launcher/settings/PassthroughSetting.h index 3f3474003..d12a3eb0f 100644 --- a/launcher/settings/PassthroughSetting.h +++ b/launcher/settings/PassthroughSetting.h @@ -29,12 +29,15 @@ class PassthroughSetting : public Setting { Q_OBJECT public: explicit PassthroughSetting(std::shared_ptr overridden, std::shared_ptr gate); + PassthroughSetting(QString id, std::shared_ptr overridden, std::shared_ptr gate); virtual QVariant defValue() const; virtual QVariant get() const; virtual void set(QVariant value); virtual void reset(); + void switchOveride(std::shared_ptr overridden); + private: bool isOverriding() const; diff --git a/launcher/settings/SettingsObject.cpp b/launcher/settings/SettingsObject.cpp index 7501d6748..e4feecffc 100644 --- a/launcher/settings/SettingsObject.cpp +++ b/launcher/settings/SettingsObject.cpp @@ -41,6 +41,19 @@ std::shared_ptr SettingsObject::registerOverride(std::shared_ptr SettingsObject::registerOverride(QString id, std::shared_ptr original, std::shared_ptr gate) +{ + if (contains(id)) { + qCritical() << QString("Failed to register setting %1. ID already exists.").arg(id); + return nullptr; // Fail + } + auto override = std::make_shared(id, original, gate); + override->m_storage = this; + connectSignals(*override); + m_settings.insert(override->id(), override); + return override; +} + std::shared_ptr SettingsObject::registerPassthrough(std::shared_ptr original, std::shared_ptr gate) { if (contains(original->id())) { @@ -54,6 +67,19 @@ std::shared_ptr SettingsObject::registerPassthrough(std::shared_ptr SettingsObject::registerPassthrough(QString id, std::shared_ptr original, std::shared_ptr gate) +{ + if (contains(id)) { + qCritical() << QString("Failed to register setting %1. ID already exists.").arg(id); + return nullptr; // Fail + } + auto passthrough = std::make_shared(id, original, gate); + passthrough->m_storage = this; + connectSignals(*passthrough); + m_settings.insert(passthrough->id(), passthrough); + return passthrough; +} + std::shared_ptr SettingsObject::registerSetting(QStringList synonyms, QVariant defVal) { if (synonyms.empty()) diff --git a/launcher/settings/SettingsObject.h b/launcher/settings/SettingsObject.h index bd3f71b36..26c7cff00 100644 --- a/launcher/settings/SettingsObject.h +++ b/launcher/settings/SettingsObject.h @@ -65,6 +65,7 @@ class SettingsObject : public QObject { * \return A valid Setting shared pointer if successful. */ std::shared_ptr registerOverride(std::shared_ptr original, std::shared_ptr gate); + std::shared_ptr registerOverride(QString id, std::shared_ptr original, std::shared_ptr gate); /*! * Registers a passthorugh setting for the given original setting in this settings object @@ -75,6 +76,7 @@ class SettingsObject : public QObject { * \return A valid Setting shared pointer if successful. */ std::shared_ptr registerPassthrough(std::shared_ptr original, std::shared_ptr gate); + std::shared_ptr registerPassthrough(QString id, std::shared_ptr original, std::shared_ptr gate); /*! * Registers the given setting with this SettingsObject and connects the necessary signals. diff --git a/launcher/ui/widgets/JavaProfileSettingsWidget.cpp b/launcher/ui/widgets/JavaProfileSettingsWidget.cpp new file mode 100644 index 000000000..8f4d43887 --- /dev/null +++ b/launcher/ui/widgets/JavaProfileSettingsWidget.cpp @@ -0,0 +1,292 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (c) 2022 Jamie Mansfield + * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2024 TheKodeToad + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "JavaProfileSettingsWidget.h" + +#include +#include +#include "Application.h" +#include "BuildConfig.h" +#include "FileSystem.h" +#include "JavaCommon.h" +#include "java/JavaInstallList.h" +#include "java/JavaUtils.h" +#include "settings/Setting.h" +#include "sys.h" +#include "ui/dialogs/CustomMessageBox.h" +#include "ui/dialogs/VersionSelectDialog.h" +#include "ui/java/InstallJavaDialog.h" + +#include "ui_JavaProfileSettingsWidget.h" + +JavaProfileSettingsWidget::JavaProfileSettingsWidget(QString major, QWidget* parent) : JavaProfileSettingsWidget(nullptr, major, parent) {} +JavaProfileSettingsWidget::JavaProfileSettingsWidget(InstancePtr instance, QWidget* parent) + : JavaProfileSettingsWidget(instance, {}, parent) +{} + +JavaProfileSettingsWidget::JavaProfileSettingsWidget(InstancePtr instance, QString major, QWidget* parent) + + : QWidget(parent), m_major(major), m_instance(instance), m_ui(new Ui::JavaProfileSettingsWidget) +{ + m_ui->setupUi(this); + + auto overide = m_major.isEmpty() && m_instance == nullptr; + m_ui->javaInstallationGroupBox->setCheckable(!overide); + m_ui->memoryGroupBox->setCheckable(!overide); + m_ui->javaArgumentsGroupBox->setCheckable(!overide); + if (m_instance == nullptr) { + m_ui->javaDownloadBtn->hide(); + if (!m_major.isEmpty()) { + m_ui->javaInstallationGroupBox->setTitle(tr("Java %1 Insta&llation").arg(m_major)); + } + } else { + m_ui->javaDownloadBtn->setVisible(BuildConfig.JAVA_DOWNLOADER_ENABLED); + + SettingsObjectPtr settings = m_instance->settings(); + + connect(settings->getSetting("OverrideJavaLocation").get(), &Setting::SettingChanged, m_ui->javaInstallationGroupBox, + [this, settings] { m_ui->javaInstallationGroupBox->setChecked(settings->get("OverrideJavaLocation").toBool()); }); + connect(settings->getSetting("JavaPath").get(), &Setting::SettingChanged, m_ui->javaInstallationGroupBox, + [this, settings] { m_ui->javaPathTextBox->setText(settings->get("JavaPath").toString()); }); + connect(m_ui->javaDownloadBtn, &QPushButton::clicked, this, [this] { + auto javaDialog = new Java::InstallDialog({}, m_instance.get(), this); + javaDialog->exec(); + }); + connect(m_ui->javaPathTextBox, &QLineEdit::textChanged, [this](QString newValue) { + if (m_instance->settings()->get("JavaPath").toString() != newValue) { + m_instance->settings()->set("AutomaticJava", false); + } + }); + } + + connect(m_ui->javaTestBtn, &QPushButton::clicked, this, &JavaProfileSettingsWidget::onJavaTest); + connect(m_ui->javaDetectBtn, &QPushButton::clicked, this, &JavaProfileSettingsWidget::onJavaAutodetect); + connect(m_ui->javaBrowseBtn, &QPushButton::clicked, this, &JavaProfileSettingsWidget::onJavaBrowse); + + connect(m_ui->maxMemSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &JavaProfileSettingsWidget::updateThresholds); + connect(m_ui->minMemSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &JavaProfileSettingsWidget::updateThresholds); + + loadSettings(); + updateThresholds(); +} + +JavaProfileSettingsWidget::~JavaProfileSettingsWidget() +{ + delete m_ui; +} + +void JavaProfileSettingsWidget::loadSettings() +{ + SettingsObjectPtr settings; + + if (m_instance != nullptr) + settings = m_instance->settings(); + else + settings = APPLICATION->settings(); + auto overide = m_major.isEmpty() && m_instance == nullptr; + + // Java Settings + m_ui->javaInstallationGroupBox->setChecked(overide || settings->get(QString("OverrideJava%1Location").arg(m_major)).toBool()); + m_ui->javaPathTextBox->setText(settings->get(QString("Java%1Path").arg(m_major)).toString()); + + m_ui->skipCompatibilityCheckBox->setChecked(settings->get(QString("IgnoreJava%1Compatibility").arg(m_major)).toBool()); + + m_ui->javaArgumentsGroupBox->setChecked(overide || settings->get(QString("OverrideJava%1Args").arg(m_major)).toBool()); + m_ui->jvmArgsTextBox->setPlainText(settings->get(QString("Jvm%1Args").arg(m_major)).toString()); + + // Memory + m_ui->memoryGroupBox->setChecked(overide || settings->get(QString("OverrideMemory%1").arg(m_major)).toBool()); + int min = settings->get(QString("MinMemAlloc%1").arg(m_major)).toInt(); + int max = settings->get(QString("MaxMemAlloc%1").arg(m_major)).toInt(); + if (min < max) { + m_ui->minMemSpinBox->setValue(min); + m_ui->maxMemSpinBox->setValue(max); + } else { + m_ui->minMemSpinBox->setValue(max); + m_ui->maxMemSpinBox->setValue(min); + } + m_ui->permGenSpinBox->setValue(settings->get(QString("PermGen%1").arg(m_major)).toInt()); + + // Java arguments + m_ui->javaArgumentsGroupBox->setChecked(overide || settings->get(QString("OverrideJava%1Args").arg(m_major)).toBool()); + m_ui->jvmArgsTextBox->setPlainText(settings->get(QString("Jvm%1Args").arg(m_major)).toString()); +} + +void JavaProfileSettingsWidget::saveSettings() +{ + SettingsObjectPtr settings; + + if (m_instance != nullptr) + settings = m_instance->settings(); + else + settings = APPLICATION->settings(); + + SettingsObject::Lock lock(settings); + + // Java Install Settings + auto overide = m_major.isEmpty() && m_instance == nullptr; + bool javaInstall = overide || m_ui->javaInstallationGroupBox->isChecked(); + + if (!overide) + settings->set(QString("OverrideJava%1Location").arg(m_major), javaInstall); + + if (javaInstall) { + settings->set(QString("Java%1Path").arg(m_major), m_ui->javaPathTextBox->text()); + settings->set(QString("IgnoreJava%1Compatibility").arg(m_major), m_ui->skipCompatibilityCheckBox->isChecked()); + } else { + settings->reset(QString("Java%1Path").arg(m_major)); + settings->reset(QString("IgnoreJava%1Compatibility").arg(m_major)); + } + + // Memory + bool memory = overide || m_ui->memoryGroupBox->isChecked(); + + if (!overide) + settings->set(QString("OverrideMemory%1").arg(m_major), memory); + + if (memory) { + int min = m_ui->minMemSpinBox->value(); + int max = m_ui->maxMemSpinBox->value(); + if (min < max) { + settings->set(QString("MinMemAlloc%1").arg(m_major), min); + settings->set(QString("MaxMemAlloc%1").arg(m_major), max); + } else { + settings->set(QString("MinMemAlloc%1").arg(m_major), max); + settings->set(QString("MaxMemAlloc%1").arg(m_major), min); + } + settings->set(QString("PermGen%1").arg(m_major), m_ui->permGenSpinBox->value()); + } else { + settings->reset(QString("MinMemAlloc%1").arg(m_major)); + settings->reset(QString("MaxMemAlloc%1").arg(m_major)); + settings->reset(QString("PermGen%1").arg(m_major)); + } + + // Java arguments + bool javaArgs = overide || m_ui->javaArgumentsGroupBox->isChecked(); + + if (!overide) + settings->set(QString("OverrideJava%1Args").arg(m_major), javaArgs); + + if (javaArgs) { + settings->set(QString("Jvm%1Args").arg(m_major), m_ui->jvmArgsTextBox->toPlainText().replace("\n", " ")); + } else { + settings->reset(QString("Jvm%1Args").arg(m_major)); + } +} + +void JavaProfileSettingsWidget::onJavaBrowse() +{ + QString rawPath = QFileDialog::getOpenFileName(this, tr("Find Java executable")); + + // do not allow current dir - it's dirty. Do not allow dirs that don't exist + if (rawPath.isEmpty()) { + return; + } + + QString cookedPath = FS::NormalizePath(rawPath); + QFileInfo javaInfo(cookedPath); + if (!javaInfo.exists() || !javaInfo.isExecutable()) { + return; + } + m_ui->javaPathTextBox->setText(cookedPath); +} + +void JavaProfileSettingsWidget::onJavaTest() +{ + if (m_checker != nullptr) + return; + + QString jvmArgs; + + if (m_major.isEmpty() || m_ui->javaArgumentsGroupBox->isChecked()) + jvmArgs = m_ui->jvmArgsTextBox->toPlainText().replace("\n", " "); + else + jvmArgs = APPLICATION->settings()->get("JvmArgs").toString(); + + m_checker.reset(new JavaCommon::TestCheck(this, m_ui->javaPathTextBox->text(), jvmArgs, m_ui->minMemSpinBox->value(), + m_ui->maxMemSpinBox->value(), m_ui->permGenSpinBox->value())); + connect(m_checker.get(), &JavaCommon::TestCheck::finished, this, [this] { m_checker.reset(); }); + m_checker->run(); +} + +void JavaProfileSettingsWidget::onJavaAutodetect() +{ + if (JavaUtils::getJavaCheckPath().isEmpty()) { + JavaCommon::javaCheckNotFound(this); + return; + } + + VersionSelectDialog versionDialog(APPLICATION->javalist().get(), tr("Select a Java version"), this, true); + versionDialog.setResizeOn(2); + versionDialog.exec(); + + if (versionDialog.result() == QDialog::Accepted && versionDialog.selectedVersion()) { + JavaInstallPtr java = std::dynamic_pointer_cast(versionDialog.selectedVersion()); + m_ui->javaPathTextBox->setText(java->path); + + if (!java->is_64bit && m_ui->maxMemSpinBox->value() > 2048) { + CustomMessageBox::selectable(this, tr("Confirm Selection"), + tr("You selected a 32-bit version of Java.\n" + "This installation does not support more than 2048MiB of RAM.\n" + "Please make sure that the maximum memory value is lower."), + QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Ok) + ->exec(); + } + } +} +void JavaProfileSettingsWidget::updateThresholds() +{ + auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; + unsigned int maxMem = m_ui->maxMemSpinBox->value(); + unsigned int minMem = m_ui->minMemSpinBox->value(); + + const QString warningColour(QStringLiteral("%1")); + + if (maxMem >= sysMiB) { + m_ui->labelMaxMemNotice->setText( + QString("%1").arg(tr("Your maximum memory allocation exceeds your system memory capacity."))); + m_ui->labelMaxMemNotice->show(); + } else if (maxMem > (sysMiB * 0.9)) { + m_ui->labelMaxMemNotice->setText(warningColour.arg(tr("Your maximum memory allocation is close to your system memory capacity."))); + m_ui->labelMaxMemNotice->show(); + } else if (maxMem < minMem) { + m_ui->labelMaxMemNotice->setText(warningColour.arg(tr("Your maximum memory allocation is below the minimum memory allocation."))); + m_ui->labelMaxMemNotice->show(); + } else { + m_ui->labelMaxMemNotice->hide(); + } +} diff --git a/launcher/ui/widgets/JavaProfileSettingsWidget.h b/launcher/ui/widgets/JavaProfileSettingsWidget.h new file mode 100644 index 000000000..f733deff5 --- /dev/null +++ b/launcher/ui/widgets/JavaProfileSettingsWidget.h @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (c) 2022 Jamie Mansfield + * Copyright (C) 2024 TheKodeToad + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include "BaseInstance.h" +#include "JavaCommon.h" + +namespace Ui { +class JavaProfileSettingsWidget; +} + +class JavaProfileSettingsWidget : public QWidget { + Q_OBJECT + + public: + explicit JavaProfileSettingsWidget(InstancePtr instance, QString major, QWidget* parent = nullptr); + explicit JavaProfileSettingsWidget(QString major, QWidget* parent = nullptr); + explicit JavaProfileSettingsWidget(InstancePtr instance, QWidget* parent = nullptr); + ~JavaProfileSettingsWidget() override; + + void loadSettings(); + void saveSettings(); + + private slots: + void onJavaBrowse(); + void onJavaAutodetect(); + void onJavaTest(); + void updateThresholds(); + + private: + QString m_major; + InstancePtr m_instance; + Ui::JavaProfileSettingsWidget* m_ui; + unique_qobject_ptr m_checker; +}; \ No newline at end of file diff --git a/launcher/ui/widgets/JavaProfileSettingsWidget.ui b/launcher/ui/widgets/JavaProfileSettingsWidget.ui new file mode 100644 index 000000000..30e40f4cc --- /dev/null +++ b/launcher/ui/widgets/JavaProfileSettingsWidget.ui @@ -0,0 +1,310 @@ + + + JavaProfileSettingsWidget + + + + 0 + 0 + 500 + 597 + + + + Form + + + + + + true + + + Java Insta&llation + + + false + + + false + + + + + + + + + Java &Executable + + + javaPathTextBox + + + + + + + + + &Detect + + + + + + + &Browse + + + + + + + Test S&ettings + + + + + + + Open Java &Downloader + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + If enabled, the launcher will not check if an instance is compatible with the selected Java version. + + + Skip Java compatibility checks + + + + + + + + + + true + + + Memor&y + + + false + + + false + + + + + + Memory Notice + + + + + + + (-XX:PermSize) + + + + + + + + 0 + 0 + + + + The amount of memory available to store loaded Java classes. + + + MiB + + + 4 + + + 1048576 + + + 8 + + + 64 + + + + + + + + 0 + 0 + + + + The maximum amount of memory Minecraft is allowed to use. + + + MiB + + + 8 + + + 1048576 + + + 128 + + + 1024 + + + + + + + (-Xmx) + + + + + + + + 0 + 0 + + + + The amount of memory Minecraft is started with. + + + MiB + + + 8 + + + 1048576 + + + 128 + + + 256 + + + + + + + &PermGen Size: + + + permGenSpinBox + + + + + + + (-Xms) + + + + + + + Ma&ximum Memory Usage: + + + maxMemSpinBox + + + + + + + M&inimum Memory Usage: + + + minMemSpinBox + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + + + + true + + + Java Argumen&ts + + + false + + + false + + + + + + + + + + + + javaPathTextBox + javaDetectBtn + javaBrowseBtn + minMemSpinBox + maxMemSpinBox + permGenSpinBox + jvmArgsTextBox + + + + diff --git a/launcher/ui/widgets/JavaSettingsWidget.cpp b/launcher/ui/widgets/JavaSettingsWidget.cpp index 0a0d1968b..8bbf2e562 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.cpp +++ b/launcher/ui/widgets/JavaSettingsWidget.cpp @@ -39,73 +39,38 @@ #include #include +#include #include "Application.h" #include "BuildConfig.h" -#include "FileSystem.h" #include "JavaCommon.h" -#include "java/JavaInstallList.h" -#include "java/JavaUtils.h" -#include "settings/Setting.h" -#include "sys.h" -#include "ui/dialogs/CustomMessageBox.h" -#include "ui/dialogs/VersionSelectDialog.h" -#include "ui/java/InstallJavaDialog.h" +#include "Json.h" +#include "ui/widgets/JavaProfileSettingsWidget.h" #include "ui_JavaSettingsWidget.h" -JavaSettingsWidget::JavaSettingsWidget(InstancePtr instance, QWidget* parent) - : QWidget(parent), m_instance(std::move(instance)), m_ui(new Ui::JavaSettingsWidget) +JavaSettingsWidget::JavaSettingsWidget(QWidget* parent) : QWidget(parent), m_ui(new Ui::JavaSettingsWidget) { m_ui->setupUi(this); - if (m_instance == nullptr) { - m_ui->javaDownloadBtn->hide(); - if (BuildConfig.JAVA_DOWNLOADER_ENABLED) { - connect(m_ui->autodetectJavaCheckBox, &QCheckBox::stateChanged, this, [this](bool state) { - m_ui->autodownloadJavaCheckBox->setEnabled(state); - if (!state) - m_ui->autodownloadJavaCheckBox->setChecked(false); - }); - } else { - m_ui->autodownloadJavaCheckBox->hide(); - } + auto defaultProfile = new JavaProfileSettingsWidget("", m_ui->javaProfiles); + m_ui->javaProfiles->addTab(defaultProfile, "Default"); + m_profiles << defaultProfile; + if (BuildConfig.JAVA_DOWNLOADER_ENABLED) { + connect(m_ui->autodetectJavaCheckBox, &QCheckBox::stateChanged, this, [this](bool state) { + m_ui->autodownloadJavaCheckBox->setEnabled(state); + if (!state) + m_ui->autodownloadJavaCheckBox->setChecked(false); + }); } else { - m_ui->javaDownloadBtn->setVisible(BuildConfig.JAVA_DOWNLOADER_ENABLED); - m_ui->skipWizardCheckBox->hide(); - m_ui->autodetectJavaCheckBox->hide(); m_ui->autodownloadJavaCheckBox->hide(); - - m_ui->javaInstallationGroupBox->setCheckable(true); - m_ui->memoryGroupBox->setCheckable(true); - m_ui->javaArgumentsGroupBox->setCheckable(true); - - SettingsObjectPtr settings = m_instance->settings(); - - connect(settings->getSetting("OverrideJavaLocation").get(), &Setting::SettingChanged, m_ui->javaInstallationGroupBox, - [this, settings] { m_ui->javaInstallationGroupBox->setChecked(settings->get("OverrideJavaLocation").toBool()); }); - connect(settings->getSetting("JavaPath").get(), &Setting::SettingChanged, m_ui->javaInstallationGroupBox, - [this, settings] { m_ui->javaPathTextBox->setText(settings->get("JavaPath").toString()); }); - - connect(m_ui->javaDownloadBtn, &QPushButton::clicked, this, [this] { - auto javaDialog = new Java::InstallDialog({}, m_instance.get(), this); - javaDialog->exec(); - }); - connect(m_ui->javaPathTextBox, &QLineEdit::textChanged, [this](QString newValue) { - if (m_instance->settings()->get("JavaPath").toString() != newValue) { - m_instance->settings()->set("AutomaticJava", false); - } - }); + } + for (auto major : Json::toStringList(APPLICATION->settings()->get("SupportedJavaMajors").toString())) { + auto profileSetting = new JavaProfileSettingsWidget(major, m_ui->javaProfiles); + m_ui->javaProfiles->addTab(profileSetting, tr("Java %1").arg(major)); + m_profiles << profileSetting; } - connect(m_ui->javaTestBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaTest); - connect(m_ui->javaDetectBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaAutodetect); - connect(m_ui->javaBrowseBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaBrowse); - - connect(m_ui->maxMemSpinBox, &QSpinBox::valueChanged, this, &JavaSettingsWidget::updateThresholds); - connect(m_ui->minMemSpinBox, &QSpinBox::valueChanged, this, &JavaSettingsWidget::updateThresholds); - loadSettings(); - updateThresholds(); } JavaSettingsWidget::~JavaSettingsWidget() @@ -115,192 +80,26 @@ JavaSettingsWidget::~JavaSettingsWidget() void JavaSettingsWidget::loadSettings() { - SettingsObjectPtr settings; - - if (m_instance != nullptr) - settings = m_instance->settings(); - else - settings = APPLICATION->settings(); + auto settings = APPLICATION->settings(); // Java Settings - m_ui->javaInstallationGroupBox->setChecked(settings->get("OverrideJavaLocation").toBool()); - m_ui->javaPathTextBox->setText(settings->get("JavaPath").toString()); - - m_ui->skipCompatibilityCheckBox->setChecked(settings->get("IgnoreJavaCompatibility").toBool()); - - m_ui->javaArgumentsGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideJavaArgs").toBool()); - m_ui->jvmArgsTextBox->setPlainText(settings->get("JvmArgs").toString()); - - if (m_instance == nullptr) { - m_ui->skipWizardCheckBox->setChecked(settings->get("IgnoreJavaWizard").toBool()); - m_ui->autodetectJavaCheckBox->setChecked(settings->get("AutomaticJavaSwitch").toBool()); - m_ui->autodetectJavaCheckBox->stateChanged(m_ui->autodetectJavaCheckBox->isChecked()); - m_ui->autodownloadJavaCheckBox->setChecked(settings->get("AutomaticJavaDownload").toBool()); - } - - // Memory - m_ui->memoryGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideMemory").toBool()); - int min = settings->get("MinMemAlloc").toInt(); - int max = settings->get("MaxMemAlloc").toInt(); - if (min < max) { - m_ui->minMemSpinBox->setValue(min); - m_ui->maxMemSpinBox->setValue(max); - } else { - m_ui->minMemSpinBox->setValue(max); - m_ui->maxMemSpinBox->setValue(min); - } - m_ui->permGenSpinBox->setValue(settings->get("PermGen").toInt()); - - // Java arguments - m_ui->javaArgumentsGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideJavaArgs").toBool()); - m_ui->jvmArgsTextBox->setPlainText(settings->get("JvmArgs").toString()); + m_ui->skipWizardCheckBox->setChecked(settings->get("IgnoreJavaWizard").toBool()); + m_ui->autodetectJavaCheckBox->setChecked(settings->get("AutomaticJavaSwitch").toBool()); + m_ui->autodetectJavaCheckBox->stateChanged(m_ui->autodetectJavaCheckBox->isChecked()); + m_ui->autodownloadJavaCheckBox->setChecked(settings->get("AutomaticJavaDownload").toBool()); } void JavaSettingsWidget::saveSettings() { - SettingsObjectPtr settings; - - if (m_instance != nullptr) - settings = m_instance->settings(); - else - settings = APPLICATION->settings(); + auto settings = APPLICATION->settings(); SettingsObject::Lock lock(settings); // Java Install Settings - bool javaInstall = m_instance == nullptr || m_ui->javaInstallationGroupBox->isChecked(); - - if (m_instance != nullptr) - settings->set("OverrideJavaLocation", javaInstall); - - if (javaInstall) { - settings->set("JavaPath", m_ui->javaPathTextBox->text()); - settings->set("IgnoreJavaCompatibility", m_ui->skipCompatibilityCheckBox->isChecked()); - } else { - settings->reset("JavaPath"); - settings->reset("IgnoreJavaCompatibility"); - } - - if (m_instance == nullptr) { - settings->set("IgnoreJavaWizard", m_ui->skipWizardCheckBox->isChecked()); - settings->set("AutomaticJavaSwitch", m_ui->autodetectJavaCheckBox->isChecked()); - settings->set("AutomaticJavaDownload", m_ui->autodownloadJavaCheckBox->isChecked()); - } - - // Memory - bool memory = m_instance == nullptr || m_ui->memoryGroupBox->isChecked(); - - if (m_instance != nullptr) - settings->set("OverrideMemory", memory); - - if (memory) { - int min = m_ui->minMemSpinBox->value(); - int max = m_ui->maxMemSpinBox->value(); - if (min < max) { - settings->set("MinMemAlloc", min); - settings->set("MaxMemAlloc", max); - } else { - settings->set("MinMemAlloc", max); - settings->set("MaxMemAlloc", min); - } - settings->set("PermGen", m_ui->permGenSpinBox->value()); - } else { - settings->reset("MinMemAlloc"); - settings->reset("MaxMemAlloc"); - settings->reset("PermGen"); - } - - // Java arguments - bool javaArgs = m_instance == nullptr || m_ui->javaArgumentsGroupBox->isChecked(); - - if (m_instance != nullptr) - settings->set("OverrideJavaArgs", javaArgs); - - if (javaArgs) { - settings->set("JvmArgs", m_ui->jvmArgsTextBox->toPlainText().replace("\n", " ")); - } else { - settings->reset("JvmArgs"); - } -} - -void JavaSettingsWidget::onJavaBrowse() -{ - QString rawPath = QFileDialog::getOpenFileName(this, tr("Find Java executable")); - - // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if (rawPath.isEmpty()) { - return; - } - - QString cookedPath = FS::NormalizePath(rawPath); - QFileInfo javaInfo(cookedPath); - if (!javaInfo.exists() || !javaInfo.isExecutable()) { - return; - } - m_ui->javaPathTextBox->setText(cookedPath); -} - -void JavaSettingsWidget::onJavaTest() -{ - if (m_checker != nullptr) - return; - - QString jvmArgs; - - if (m_instance == nullptr || m_ui->javaArgumentsGroupBox->isChecked()) - jvmArgs = m_ui->jvmArgsTextBox->toPlainText().replace("\n", " "); - else - jvmArgs = APPLICATION->settings()->get("JvmArgs").toString(); - - m_checker.reset(new JavaCommon::TestCheck(this, m_ui->javaPathTextBox->text(), jvmArgs, m_ui->minMemSpinBox->value(), - m_ui->maxMemSpinBox->value(), m_ui->permGenSpinBox->value())); - connect(m_checker.get(), &JavaCommon::TestCheck::finished, this, [this] { m_checker.reset(); }); - m_checker->run(); -} - -void JavaSettingsWidget::onJavaAutodetect() -{ - if (JavaUtils::getJavaCheckPath().isEmpty()) { - JavaCommon::javaCheckNotFound(this); - return; - } - - VersionSelectDialog versionDialog(APPLICATION->javalist().get(), tr("Select a Java version"), this, true); - versionDialog.setResizeOn(2); - versionDialog.exec(); - - if (versionDialog.result() == QDialog::Accepted && versionDialog.selectedVersion()) { - JavaInstallPtr java = std::dynamic_pointer_cast(versionDialog.selectedVersion()); - m_ui->javaPathTextBox->setText(java->path); - - if (!java->is_64bit && m_ui->maxMemSpinBox->value() > 2048) { - CustomMessageBox::selectable(this, tr("Confirm Selection"), - tr("You selected a 32-bit version of Java.\n" - "This installation does not support more than 2048MiB of RAM.\n" - "Please make sure that the maximum memory value is lower."), - QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Ok) - ->exec(); - } - } -} -void JavaSettingsWidget::updateThresholds() -{ - auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; - unsigned int maxMem = m_ui->maxMemSpinBox->value(); - unsigned int minMem = m_ui->minMemSpinBox->value(); - - const QString warningColour(QStringLiteral("%1")); - - if (maxMem >= sysMiB) { - m_ui->labelMaxMemNotice->setText(QString("%1").arg(tr("Your maximum memory allocation exceeds your system memory capacity."))); - m_ui->labelMaxMemNotice->show(); - } else if (maxMem > (sysMiB * 0.9)) { - m_ui->labelMaxMemNotice->setText(warningColour.arg(tr("Your maximum memory allocation is close to your system memory capacity."))); - m_ui->labelMaxMemNotice->show(); - } else if (maxMem < minMem) { - m_ui->labelMaxMemNotice->setText(warningColour.arg(tr("Your maximum memory allocation is below the minimum memory allocation."))); - m_ui->labelMaxMemNotice->show(); - } else { - m_ui->labelMaxMemNotice->hide(); + settings->set("IgnoreJavaWizard", m_ui->skipWizardCheckBox->isChecked()); + settings->set("AutomaticJavaSwitch", m_ui->autodetectJavaCheckBox->isChecked()); + settings->set("AutomaticJavaDownload", m_ui->autodownloadJavaCheckBox->isChecked()); + for (auto p : m_profiles) { + p->saveSettings(); } } diff --git a/launcher/ui/widgets/JavaSettingsWidget.h b/launcher/ui/widgets/JavaSettingsWidget.h index 85266bc2b..d0a8f97de 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.h +++ b/launcher/ui/widgets/JavaSettingsWidget.h @@ -37,8 +37,8 @@ #pragma once #include -#include "BaseInstance.h" #include "JavaCommon.h" +#include "ui/widgets/JavaProfileSettingsWidget.h" namespace Ui { class JavaSettingsWidget; @@ -48,21 +48,13 @@ class JavaSettingsWidget : public QWidget { Q_OBJECT public: - explicit JavaSettingsWidget(QWidget* parent = nullptr) : JavaSettingsWidget(nullptr, nullptr) {} - explicit JavaSettingsWidget(InstancePtr instance, QWidget* parent = nullptr); + explicit JavaSettingsWidget(QWidget* parent = nullptr); ~JavaSettingsWidget() override; void loadSettings(); void saveSettings(); - private slots: - void onJavaBrowse(); - void onJavaAutodetect(); - void onJavaTest(); - void updateThresholds(); - private: - InstancePtr m_instance; Ui::JavaSettingsWidget* m_ui; - unique_qobject_ptr m_checker; + QList m_profiles; }; \ No newline at end of file diff --git a/launcher/ui/widgets/JavaSettingsWidget.ui b/launcher/ui/widgets/JavaSettingsWidget.ui index fb974570f..544ff0e64 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.ui +++ b/launcher/ui/widgets/JavaSettingsWidget.ui @@ -13,14 +13,17 @@ Form - + + + + true - Java Insta&llation + Extra false @@ -29,125 +32,7 @@ false - - - - Auto-&detect Java version - - - - - - - - - &Detect - - - - - - - &Browse - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Test S&ettings - - - - - - - Open Java &Downloader - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 0 - 6 - - - - - - - - Automatically downloads and selects the Java build recommended by Mojang. - - - Auto-download &Mojang Java - - - - - - - If enabled, the launcher will not check if an instance is compatible with the selected Java version. - - - Skip Java compatibility checks - - - - - - - - - Java &Executable - - - javaPathTextBox - - - - If enabled, the launcher won't prompt you to choose a Java version if one is not found on startup. @@ -157,235 +42,32 @@ + + + + Automatically downloads and selects the Java build recommended by Mojang. + + + Auto-download &Mojang Java + + + - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 0 - 6 - - - - - - - - - - - true - - - Memor&y - - - false - - - false - - - - + - Memory Notice + Auto-&detect Java version - - - - (-XX:PermSize) - - - - - - - - 0 - 0 - - - - The amount of memory available to store loaded Java classes. - - - MiB - - - 4 - - - 1048576 - - - 8 - - - 64 - - - - - - - - 0 - 0 - - - - The maximum amount of memory Minecraft is allowed to use. - - - MiB - - - 8 - - - 1048576 - - - 128 - - - 1024 - - - - - - - (-Xmx) - - - - - - - - 0 - 0 - - - - The amount of memory Minecraft is started with. - - - MiB - - - 8 - - - 1048576 - - - 128 - - - 256 - - - - - - - &PermGen Size: - - - permGenSpinBox - - - - - - - (-Xms) - - - - - - - Ma&ximum Memory Usage: - - - maxMemSpinBox - - - - - - - M&inimum Memory Usage: - - - minMemSpinBox - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - - - - true - - - Java Argumen&ts - - - false - - - false - - - - - - javaPathTextBox - javaDetectBtn - javaBrowseBtn - skipCompatibilityCheckBox skipWizardCheckBox autodetectJavaCheckBox autodownloadJavaCheckBox - javaTestBtn - javaDownloadBtn - minMemSpinBox - maxMemSpinBox - permGenSpinBox - jvmArgsTextBox diff --git a/launcher/ui/widgets/MinecraftSettingsWidget.cpp b/launcher/ui/widgets/MinecraftSettingsWidget.cpp index f46786518..ebd940b66 100644 --- a/launcher/ui/widgets/MinecraftSettingsWidget.cpp +++ b/launcher/ui/widgets/MinecraftSettingsWidget.cpp @@ -46,6 +46,8 @@ #include "minecraft/WorldList.h" #include "minecraft/auth/AccountList.h" #include "settings/Setting.h" +#include "ui/widgets/JavaProfileSettingsWidget.h" +#include "ui_MinecraftSettingsWidget.h" MinecraftSettingsWidget::MinecraftSettingsWidget(MinecraftInstancePtr instance, QWidget* parent) : QWidget(parent), m_instance(std::move(instance)), m_ui(new Ui::MinecraftSettingsWidget) @@ -61,7 +63,7 @@ MinecraftSettingsWidget::MinecraftSettingsWidget(MinecraftInstancePtr instance, m_ui->globalDataPacksGroupBox->hide(); m_ui->loaderGroup->hide(); } else { - m_javaSettings = new JavaSettingsWidget(m_instance, this); + m_javaSettings = new JavaProfileSettingsWidget(m_instance, this); m_ui->javaScrollArea->setWidget(m_javaSettings); m_ui->showGameTime->setText(tr("Show time &playing this instance")); @@ -119,6 +121,22 @@ MinecraftSettingsWidget::MinecraftSettingsWidget(MinecraftInstancePtr instance, connect(m_ui->fabric, &QCheckBox::stateChanged, this, &MinecraftSettingsWidget::saveSelectedLoaders); connect(m_ui->quilt, &QCheckBox::stateChanged, this, &MinecraftSettingsWidget::saveSelectedLoaders); connect(m_ui->liteLoader, &QCheckBox::stateChanged, this, &MinecraftSettingsWidget::saveSelectedLoaders); + // just to update the settings to correct overrides + // needs "net.minecraft" to be loaded + auto version = m_instance->getPackProfile(); + if (version && version->getComponent("net.minecraft")) { + auto minecraftCmp = version->getComponent("net.minecraft"); + if (!minecraftCmp->m_loaded) { + version->reload(Net::Mode::Offline); + auto update = version->getCurrentTask(); + if (update) { + connect(update.get(), &Task::finished, this, [this] { m_instance->updateOverrideJavaSettings(); }); + update->start(); + } + } else { + m_instance->updateOverrideJavaSettings(); + } + } } m_ui->maximizedWarning->hide(); diff --git a/launcher/ui/widgets/MinecraftSettingsWidget.h b/launcher/ui/widgets/MinecraftSettingsWidget.h index 9e3e7afb2..5f1ef7c90 100644 --- a/launcher/ui/widgets/MinecraftSettingsWidget.h +++ b/launcher/ui/widgets/MinecraftSettingsWidget.h @@ -37,7 +37,7 @@ #pragma once #include -#include "JavaSettingsWidget.h" +#include "JavaProfileSettingsWidget.h" #include "minecraft/MinecraftInstance.h" namespace Ui { @@ -63,6 +63,6 @@ class MinecraftSettingsWidget : public QWidget { MinecraftInstancePtr m_instance; Ui::MinecraftSettingsWidget* m_ui; - JavaSettingsWidget* m_javaSettings = nullptr; + JavaProfileSettingsWidget* m_javaSettings = nullptr; bool m_quickPlaySingleplayer = false; };