mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-08-03 11:27:33 -04:00
feat(java): add default java majors profiles
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
078de50951
commit
28bc787d91
@ -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);
|
||||
}
|
||||
|
@ -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<QNetworkAccessManager> network();
|
||||
|
||||
shared_qobject_ptr<HttpMetaCache> metacache();
|
||||
|
@ -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
|
||||
|
@ -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<Mod*> 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<OverrideSetting*>(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<PassthroughSetting*>(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"
|
||||
|
@ -61,6 +61,7 @@ class MinecraftInstance : public BaseInstance {
|
||||
virtual void saveNow() override;
|
||||
|
||||
void loadSpecificSettings() override;
|
||||
QString updateOverrideJavaSettings();
|
||||
|
||||
// FIXME: remove
|
||||
QString typeName() const override;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -23,6 +23,14 @@ OverrideSetting::OverrideSetting(std::shared_ptr<Setting> other, std::shared_ptr
|
||||
m_gate = gate;
|
||||
}
|
||||
|
||||
OverrideSetting::OverrideSetting(QString id, std::shared_ptr<Setting> other, std::shared_ptr<Setting> 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<Setting> overridden)
|
||||
{
|
||||
m_other = overridden;
|
||||
}
|
||||
|
@ -30,12 +30,15 @@ class OverrideSetting : public Setting {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OverrideSetting(std::shared_ptr<Setting> overridden, std::shared_ptr<Setting> gate);
|
||||
OverrideSetting(QString id, std::shared_ptr<Setting> overridden, std::shared_ptr<Setting> gate);
|
||||
|
||||
virtual QVariant defValue() const;
|
||||
virtual QVariant get() const;
|
||||
virtual void set(QVariant value);
|
||||
virtual void reset();
|
||||
|
||||
void switchOveride(std::shared_ptr<Setting> overridden);
|
||||
|
||||
private:
|
||||
bool isOverriding() const;
|
||||
|
||||
|
@ -23,6 +23,14 @@ PassthroughSetting::PassthroughSetting(std::shared_ptr<Setting> other, std::shar
|
||||
m_gate = gate;
|
||||
}
|
||||
|
||||
PassthroughSetting::PassthroughSetting(QString id, std::shared_ptr<Setting> other, std::shared_ptr<Setting> 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<Setting> overridden)
|
||||
{
|
||||
m_other = overridden;
|
||||
}
|
||||
|
@ -29,12 +29,15 @@ class PassthroughSetting : public Setting {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PassthroughSetting(std::shared_ptr<Setting> overridden, std::shared_ptr<Setting> gate);
|
||||
PassthroughSetting(QString id, std::shared_ptr<Setting> overridden, std::shared_ptr<Setting> gate);
|
||||
|
||||
virtual QVariant defValue() const;
|
||||
virtual QVariant get() const;
|
||||
virtual void set(QVariant value);
|
||||
virtual void reset();
|
||||
|
||||
void switchOveride(std::shared_ptr<Setting> overridden);
|
||||
|
||||
private:
|
||||
bool isOverriding() const;
|
||||
|
||||
|
@ -41,6 +41,19 @@ std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Settin
|
||||
return override;
|
||||
}
|
||||
|
||||
std::shared_ptr<Setting> SettingsObject::registerOverride(QString id, std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate)
|
||||
{
|
||||
if (contains(id)) {
|
||||
qCritical() << QString("Failed to register setting %1. ID already exists.").arg(id);
|
||||
return nullptr; // Fail
|
||||
}
|
||||
auto override = std::make_shared<OverrideSetting>(id, original, gate);
|
||||
override->m_storage = this;
|
||||
connectSignals(*override);
|
||||
m_settings.insert(override->id(), override);
|
||||
return override;
|
||||
}
|
||||
|
||||
std::shared_ptr<Setting> SettingsObject::registerPassthrough(std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate)
|
||||
{
|
||||
if (contains(original->id())) {
|
||||
@ -54,6 +67,19 @@ std::shared_ptr<Setting> SettingsObject::registerPassthrough(std::shared_ptr<Set
|
||||
return passthrough;
|
||||
}
|
||||
|
||||
std::shared_ptr<Setting> SettingsObject::registerPassthrough(QString id, std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate)
|
||||
{
|
||||
if (contains(id)) {
|
||||
qCritical() << QString("Failed to register setting %1. ID already exists.").arg(id);
|
||||
return nullptr; // Fail
|
||||
}
|
||||
auto passthrough = std::make_shared<PassthroughSetting>(id, original, gate);
|
||||
passthrough->m_storage = this;
|
||||
connectSignals(*passthrough);
|
||||
m_settings.insert(passthrough->id(), passthrough);
|
||||
return passthrough;
|
||||
}
|
||||
|
||||
std::shared_ptr<Setting> SettingsObject::registerSetting(QStringList synonyms, QVariant defVal)
|
||||
{
|
||||
if (synonyms.empty())
|
||||
|
@ -65,6 +65,7 @@ class SettingsObject : public QObject {
|
||||
* \return A valid Setting shared pointer if successful.
|
||||
*/
|
||||
std::shared_ptr<Setting> registerOverride(std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate);
|
||||
std::shared_ptr<Setting> registerOverride(QString id, std::shared_ptr<Setting> original, std::shared_ptr<Setting> 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<Setting> registerPassthrough(std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate);
|
||||
std::shared_ptr<Setting> registerPassthrough(QString id, std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate);
|
||||
|
||||
/*!
|
||||
* Registers the given setting with this SettingsObject and connects the necessary signals.
|
||||
|
292
launcher/ui/widgets/JavaProfileSettingsWidget.cpp
Normal file
292
launcher/ui/widgets/JavaProfileSettingsWidget.cpp
Normal file
@ -0,0 +1,292 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
* Copyright (C) 2024 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#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<int>::of(&QSpinBox::valueChanged), this, &JavaProfileSettingsWidget::updateThresholds);
|
||||
connect(m_ui->minMemSpinBox, QOverload<int>::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<JavaInstall>(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("<span style='color:#f5c211'>%1</span>"));
|
||||
|
||||
if (maxMem >= sysMiB) {
|
||||
m_ui->labelMaxMemNotice->setText(
|
||||
QString("<span style='color:red'>%1</span>").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();
|
||||
}
|
||||
}
|
70
launcher/ui/widgets/JavaProfileSettingsWidget.h
Normal file
70
launcher/ui/widgets/JavaProfileSettingsWidget.h
Normal file
@ -0,0 +1,70 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright (C) 2024 TheKodeToad <TheKodeToad@proton.me>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 <QWidget>
|
||||
#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<JavaCommon::TestCheck> m_checker;
|
||||
};
|
310
launcher/ui/widgets/JavaProfileSettingsWidget.ui
Normal file
310
launcher/ui/widgets/JavaProfileSettingsWidget.ui
Normal file
@ -0,0 +1,310 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>JavaProfileSettingsWidget</class>
|
||||
<widget class="QWidget" name="JavaProfileSettingsWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>597</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="javaInstallationGroupBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Java Insta&llation</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLineEdit" name="javaPathTextBox"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Java &Executable</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>javaPathTextBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="javaDetectBtn">
|
||||
<property name="text">
|
||||
<string>&Detect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="javaBrowseBtn">
|
||||
<property name="text">
|
||||
<string>&Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="javaTestBtn">
|
||||
<property name="text">
|
||||
<string>Test S&ettings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="javaDownloadBtn">
|
||||
<property name="text">
|
||||
<string>Open Java &Downloader</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="skipCompatibilityCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Skip Java compatibility checks</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="memoryGroupBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Memor&y</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labelMaxMemNotice">
|
||||
<property name="text">
|
||||
<string>Memory Notice</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>(-XX:PermSize)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="permGenSpinBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The amount of memory available to store loaded Java classes.</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string notr="true"> MiB</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1048576</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>64</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="maxMemSpinBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The maximum amount of memory Minecraft is allowed to use.</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string notr="true"> MiB</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1048576</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>128</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1024</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>(-Xmx)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="minMemSpinBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The amount of memory Minecraft is started with.</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string notr="true"> MiB</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1048576</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>128</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>256</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>&PermGen Size:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>permGenSpinBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>(-Xms)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelMaxMem">
|
||||
<property name="text">
|
||||
<string>Ma&ximum Memory Usage:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>maxMemSpinBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelMinMem">
|
||||
<property name="text">
|
||||
<string>M&inimum Memory Usage:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>minMemSpinBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="javaArgumentsGroupBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Java Argumen&ts</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPlainTextEdit" name="jvmArgsTextBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>javaPathTextBox</tabstop>
|
||||
<tabstop>javaDetectBtn</tabstop>
|
||||
<tabstop>javaBrowseBtn</tabstop>
|
||||
<tabstop>minMemSpinBox</tabstop>
|
||||
<tabstop>maxMemSpinBox</tabstop>
|
||||
<tabstop>permGenSpinBox</tabstop>
|
||||
<tabstop>jvmArgsTextBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -39,73 +39,38 @@
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QTabBar>
|
||||
#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<JavaInstall>(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("<span style='color:#f5c211'>%1</span>"));
|
||||
|
||||
if (maxMem >= sysMiB) {
|
||||
m_ui->labelMaxMemNotice->setText(QString("<span style='color:red'>%1</span>").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();
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#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<JavaCommon::TestCheck> m_checker;
|
||||
QList<JavaProfileSettingsWidget*> m_profiles;
|
||||
};
|
@ -13,14 +13,17 @@
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="javaProfiles"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="javaInstallationGroupBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Java Insta&llation</string>
|
||||
<string>Extra</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
@ -29,125 +32,7 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="autodetectJavaCheckBox">
|
||||
<property name="text">
|
||||
<string>Auto-&detect Java version</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="javaDetectBtn">
|
||||
<property name="text">
|
||||
<string>&Detect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="javaBrowseBtn">
|
||||
<property name="text">
|
||||
<string>&Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="javaTestBtn">
|
||||
<property name="text">
|
||||
<string>Test S&ettings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="javaDownloadBtn">
|
||||
<property name="text">
|
||||
<string>Open Java &Downloader</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_7">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>6</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QCheckBox" name="autodownloadJavaCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>Automatically downloads and selects the Java build recommended by Mojang.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Auto-download &Mojang Java</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="skipCompatibilityCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Skip Java compatibility checks</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLineEdit" name="javaPathTextBox"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Java &Executable</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>javaPathTextBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="skipWizardCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>If enabled, the launcher won't prompt you to choose a Java version if one is not found on startup.</string>
|
||||
@ -157,235 +42,32 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="autodownloadJavaCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>Automatically downloads and selects the Java build recommended by Mojang.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Auto-download &Mojang Java</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>6</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="memoryGroupBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Memor&y</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labelMaxMemNotice">
|
||||
<widget class="QCheckBox" name="autodetectJavaCheckBox">
|
||||
<property name="text">
|
||||
<string>Memory Notice</string>
|
||||
<string>Auto-&detect Java version</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>(-XX:PermSize)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="permGenSpinBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The amount of memory available to store loaded Java classes.</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string notr="true"> MiB</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1048576</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>64</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="maxMemSpinBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The maximum amount of memory Minecraft is allowed to use.</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string notr="true"> MiB</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1048576</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>128</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1024</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>(-Xmx)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="minMemSpinBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The amount of memory Minecraft is started with.</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string notr="true"> MiB</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1048576</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>128</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>256</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>&PermGen Size:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>permGenSpinBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>(-Xms)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelMaxMem">
|
||||
<property name="text">
|
||||
<string>Ma&ximum Memory Usage:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>maxMemSpinBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelMinMem">
|
||||
<property name="text">
|
||||
<string>M&inimum Memory Usage:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>minMemSpinBox</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="javaArgumentsGroupBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Java Argumen&ts</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPlainTextEdit" name="jvmArgsTextBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>javaPathTextBox</tabstop>
|
||||
<tabstop>javaDetectBtn</tabstop>
|
||||
<tabstop>javaBrowseBtn</tabstop>
|
||||
<tabstop>skipCompatibilityCheckBox</tabstop>
|
||||
<tabstop>skipWizardCheckBox</tabstop>
|
||||
<tabstop>autodetectJavaCheckBox</tabstop>
|
||||
<tabstop>autodownloadJavaCheckBox</tabstop>
|
||||
<tabstop>javaTestBtn</tabstop>
|
||||
<tabstop>javaDownloadBtn</tabstop>
|
||||
<tabstop>minMemSpinBox</tabstop>
|
||||
<tabstop>maxMemSpinBox</tabstop>
|
||||
<tabstop>permGenSpinBox</tabstop>
|
||||
<tabstop>jvmArgsTextBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -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();
|
||||
|
@ -37,7 +37,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user