2014-06-09 04:59:18 +05:30
|
|
|
#include "InstanceSettingsPage.h"
|
|
|
|
#include "ui_InstanceSettingsPage.h"
|
|
|
|
|
2014-07-13 02:32:52 +05:30
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QMessageBox>
|
2014-06-09 04:59:18 +05:30
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "dialogs/VersionSelectDialog.h"
|
2015-05-04 04:50:48 +05:30
|
|
|
#include "JavaCommon.h"
|
2014-07-13 02:32:52 +05:30
|
|
|
#include "MultiMC.h"
|
2014-06-09 04:59:18 +05:30
|
|
|
|
2016-01-02 05:05:54 +05:30
|
|
|
#include <java/JavaInstallList.h>
|
2015-10-05 05:17:27 +05:30
|
|
|
#include <FileSystem.h>
|
2017-07-12 02:13:35 +05:30
|
|
|
#include <sys.h>
|
2018-02-17 04:30:06 +05:30
|
|
|
#include <widgets/CustomCommands.h>
|
2015-05-04 04:50:48 +05:30
|
|
|
|
2014-06-30 05:32:57 +05:30
|
|
|
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
2018-07-15 18:21:05 +05:30
|
|
|
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
|
2014-06-09 04:59:18 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
m_settings = inst->settings();
|
|
|
|
ui->setupUi(this);
|
|
|
|
auto sysMB = Sys::getSystemRam() / Sys::megabyte;
|
|
|
|
ui->maxMemSpinBox->setMaximum(sysMB);
|
2019-06-01 15:58:53 +05:30
|
|
|
connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);
|
|
|
|
connect(MMC, &MultiMC::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
|
|
|
|
connect(MMC, &MultiMC::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
|
2018-07-15 18:21:05 +05:30
|
|
|
loadSettings();
|
2014-06-09 04:59:18 +05:30
|
|
|
}
|
|
|
|
|
2014-07-12 21:28:23 +05:30
|
|
|
bool InstanceSettingsPage::shouldDisplay() const
|
2014-06-30 05:32:57 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return !m_instance->isRunning();
|
2014-06-30 05:32:57 +05:30
|
|
|
}
|
|
|
|
|
2014-06-09 04:59:18 +05:30
|
|
|
InstanceSettingsPage::~InstanceSettingsPage()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
delete ui;
|
2014-06-09 04:59:18 +05:30
|
|
|
}
|
|
|
|
|
2019-06-01 15:58:53 +05:30
|
|
|
void InstanceSettingsPage::globalSettingsButtonClicked(bool)
|
|
|
|
{
|
2019-06-01 21:35:42 +05:30
|
|
|
switch(ui->settingsTabs->currentIndex()) {
|
|
|
|
case 0:
|
|
|
|
MMC->ShowGlobalSettings(this, "java-settings");
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
MMC->ShowGlobalSettings(this, "minecraft-settings");
|
|
|
|
return;
|
|
|
|
case 2:
|
|
|
|
MMC->ShowGlobalSettings(this, "custom-commands");
|
|
|
|
return;
|
|
|
|
}
|
2019-06-01 15:58:53 +05:30
|
|
|
}
|
|
|
|
|
2014-06-09 04:59:18 +05:30
|
|
|
bool InstanceSettingsPage::apply()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
applySettings();
|
|
|
|
return true;
|
2014-06-09 04:59:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::applySettings()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
SettingsObject::Lock lock(m_settings);
|
|
|
|
|
|
|
|
// Console
|
|
|
|
bool console = ui->consoleSettingsBox->isChecked();
|
|
|
|
m_settings->set("OverrideConsole", console);
|
|
|
|
if (console)
|
|
|
|
{
|
|
|
|
m_settings->set("ShowConsole", ui->showConsoleCheck->isChecked());
|
|
|
|
m_settings->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
|
|
|
|
m_settings->set("ShowConsoleOnError", ui->showConsoleErrorCheck->isChecked());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("ShowConsole");
|
|
|
|
m_settings->reset("AutoCloseConsole");
|
|
|
|
m_settings->reset("ShowConsoleOnError");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window Size
|
|
|
|
bool window = ui->windowSizeGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideWindow", window);
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
m_settings->set("LaunchMaximized", ui->maximizedCheckBox->isChecked());
|
|
|
|
m_settings->set("MinecraftWinWidth", ui->windowWidthSpinBox->value());
|
|
|
|
m_settings->set("MinecraftWinHeight", ui->windowHeightSpinBox->value());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("LaunchMaximized");
|
|
|
|
m_settings->reset("MinecraftWinWidth");
|
|
|
|
m_settings->reset("MinecraftWinHeight");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Memory
|
|
|
|
bool memory = ui->memoryGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideMemory", memory);
|
|
|
|
if (memory)
|
|
|
|
{
|
|
|
|
int min = ui->minMemSpinBox->value();
|
|
|
|
int max = ui->maxMemSpinBox->value();
|
|
|
|
if(min < max)
|
|
|
|
{
|
|
|
|
m_settings->set("MinMemAlloc", min);
|
|
|
|
m_settings->set("MaxMemAlloc", max);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->set("MinMemAlloc", max);
|
|
|
|
m_settings->set("MaxMemAlloc", min);
|
|
|
|
}
|
|
|
|
m_settings->set("PermGen", ui->permGenSpinBox->value());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("MinMemAlloc");
|
|
|
|
m_settings->reset("MaxMemAlloc");
|
|
|
|
m_settings->reset("PermGen");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Java Install Settings
|
|
|
|
bool javaInstall = ui->javaSettingsGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideJavaLocation", javaInstall);
|
|
|
|
if (javaInstall)
|
|
|
|
{
|
|
|
|
m_settings->set("JavaPath", ui->javaPathTextBox->text());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("JavaPath");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Java arguments
|
|
|
|
bool javaArgs = ui->javaArgumentsGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideJavaArgs", javaArgs);
|
|
|
|
if(javaArgs)
|
|
|
|
{
|
|
|
|
m_settings->set("JvmArgs", ui->jvmArgsTextBox->toPlainText().replace("\n", " "));
|
|
|
|
JavaCommon::checkJVMArgs(m_settings->get("JvmArgs").toString(), this->parentWidget());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("JvmArgs");
|
|
|
|
}
|
|
|
|
|
|
|
|
// old generic 'override both' is removed.
|
|
|
|
m_settings->reset("OverrideJava");
|
|
|
|
|
|
|
|
// Custom Commands
|
|
|
|
bool custcmd = ui->customCommands->checked();
|
|
|
|
m_settings->set("OverrideCommands", custcmd);
|
|
|
|
if (custcmd)
|
|
|
|
{
|
|
|
|
m_settings->set("PreLaunchCommand", ui->customCommands->prelaunchCommand());
|
|
|
|
m_settings->set("WrapperCommand", ui->customCommands->wrapperCommand());
|
|
|
|
m_settings->set("PostExitCommand", ui->customCommands->postexitCommand());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("PreLaunchCommand");
|
|
|
|
m_settings->reset("WrapperCommand");
|
|
|
|
m_settings->reset("PostExitCommand");
|
|
|
|
}
|
2020-09-11 02:40:17 +05:30
|
|
|
|
|
|
|
// Workarounds
|
|
|
|
bool workarounds = ui->nativeWorkaroundsGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideNativeWorkarounds", workarounds);
|
|
|
|
if(workarounds)
|
|
|
|
{
|
|
|
|
m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
|
|
|
|
m_settings->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("UseNativeOpenAL");
|
|
|
|
m_settings->reset("UseNativeGLFW");
|
|
|
|
}
|
2020-12-10 03:46:01 +05:30
|
|
|
|
|
|
|
// Game time
|
|
|
|
bool gameTime = ui->gameTimeGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideGameTime", gameTime);
|
|
|
|
if (gameTime)
|
|
|
|
{
|
|
|
|
m_settings->set("ShowGameTime", ui->showGameTime->isChecked());
|
|
|
|
m_settings->set("RecordGameTime", ui->recordGameTime->isChecked());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("ShowGameTime");
|
|
|
|
m_settings->reset("RecordGameTime");
|
|
|
|
}
|
2021-05-22 16:58:23 +05:30
|
|
|
|
|
|
|
// Join server on launch
|
|
|
|
bool joinServerOnLaunch = ui->serverJoinGroupBox->isChecked();
|
|
|
|
m_settings->set("JoinServerOnLaunch", joinServerOnLaunch);
|
|
|
|
if (joinServerOnLaunch)
|
|
|
|
{
|
|
|
|
m_settings->set("JoinServerOnLaunchAddress", ui->serverJoinAddress->text());
|
|
|
|
m_settings->set("JoinServerOnLaunchPort", ui->serverJoinPort->value());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("JoinServerOnLaunchAddress");
|
|
|
|
m_settings->reset("JoinServerOnLaunchPort");
|
|
|
|
}
|
2014-06-09 04:59:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::loadSettings()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
// Console
|
|
|
|
ui->consoleSettingsBox->setChecked(m_settings->get("OverrideConsole").toBool());
|
|
|
|
ui->showConsoleCheck->setChecked(m_settings->get("ShowConsole").toBool());
|
|
|
|
ui->autoCloseConsoleCheck->setChecked(m_settings->get("AutoCloseConsole").toBool());
|
|
|
|
ui->showConsoleErrorCheck->setChecked(m_settings->get("ShowConsoleOnError").toBool());
|
|
|
|
|
|
|
|
// Window Size
|
|
|
|
ui->windowSizeGroupBox->setChecked(m_settings->get("OverrideWindow").toBool());
|
|
|
|
ui->maximizedCheckBox->setChecked(m_settings->get("LaunchMaximized").toBool());
|
|
|
|
ui->windowWidthSpinBox->setValue(m_settings->get("MinecraftWinWidth").toInt());
|
|
|
|
ui->windowHeightSpinBox->setValue(m_settings->get("MinecraftWinHeight").toInt());
|
|
|
|
|
|
|
|
// Memory
|
|
|
|
ui->memoryGroupBox->setChecked(m_settings->get("OverrideMemory").toBool());
|
|
|
|
int min = m_settings->get("MinMemAlloc").toInt();
|
|
|
|
int max = m_settings->get("MaxMemAlloc").toInt();
|
|
|
|
if(min < max)
|
|
|
|
{
|
|
|
|
ui->minMemSpinBox->setValue(min);
|
|
|
|
ui->maxMemSpinBox->setValue(max);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->minMemSpinBox->setValue(max);
|
|
|
|
ui->maxMemSpinBox->setValue(min);
|
|
|
|
}
|
|
|
|
ui->permGenSpinBox->setValue(m_settings->get("PermGen").toInt());
|
2018-11-10 02:15:55 +05:30
|
|
|
bool permGenVisible = m_settings->get("PermGenVisible").toBool();
|
|
|
|
ui->permGenSpinBox->setVisible(permGenVisible);
|
|
|
|
ui->labelPermGen->setVisible(permGenVisible);
|
|
|
|
ui->labelPermgenNote->setVisible(permGenVisible);
|
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
|
|
|
|
// Java Settings
|
|
|
|
bool overrideJava = m_settings->get("OverrideJava").toBool();
|
|
|
|
bool overrideLocation = m_settings->get("OverrideJavaLocation").toBool() || overrideJava;
|
|
|
|
bool overrideArgs = m_settings->get("OverrideJavaArgs").toBool() || overrideJava;
|
|
|
|
|
|
|
|
ui->javaSettingsGroupBox->setChecked(overrideLocation);
|
|
|
|
ui->javaPathTextBox->setText(m_settings->get("JavaPath").toString());
|
|
|
|
|
|
|
|
ui->javaArgumentsGroupBox->setChecked(overrideArgs);
|
|
|
|
ui->jvmArgsTextBox->setPlainText(m_settings->get("JvmArgs").toString());
|
|
|
|
|
|
|
|
// Custom commands
|
|
|
|
ui->customCommands->initialize(
|
|
|
|
true,
|
|
|
|
m_settings->get("OverrideCommands").toBool(),
|
|
|
|
m_settings->get("PreLaunchCommand").toString(),
|
|
|
|
m_settings->get("WrapperCommand").toString(),
|
|
|
|
m_settings->get("PostExitCommand").toString()
|
|
|
|
);
|
2020-09-11 02:40:17 +05:30
|
|
|
|
|
|
|
// Workarounds
|
|
|
|
ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool());
|
|
|
|
ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool());
|
|
|
|
ui->useNativeOpenALCheck->setChecked(m_settings->get("UseNativeOpenAL").toBool());
|
2020-12-10 03:46:01 +05:30
|
|
|
|
|
|
|
// Miscellanous
|
|
|
|
ui->gameTimeGroupBox->setChecked(m_settings->get("OverrideGameTime").toBool());
|
|
|
|
ui->showGameTime->setChecked(m_settings->get("ShowGameTime").toBool());
|
|
|
|
ui->recordGameTime->setChecked(m_settings->get("RecordGameTime").toBool());
|
2021-05-22 16:58:23 +05:30
|
|
|
|
|
|
|
ui->serverJoinGroupBox->setChecked(m_settings->get("JoinServerOnLaunch").toBool());
|
|
|
|
ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString());
|
|
|
|
ui->serverJoinPort->setValue(m_settings->get("JoinServerOnLaunchPort").toInt());
|
2014-06-09 04:59:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
JavaInstallPtr java;
|
2014-06-09 04:59:18 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
VersionSelectDialog vselect(MMC->javalist().get(), tr("Select a Java version"), this, true);
|
|
|
|
vselect.setResizeOn(2);
|
|
|
|
vselect.exec();
|
2014-06-09 04:59:18 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
if (vselect.result() == QDialog::Accepted && vselect.selectedVersion())
|
|
|
|
{
|
|
|
|
java = std::dynamic_pointer_cast<JavaInstall>(vselect.selectedVersion());
|
|
|
|
ui->javaPathTextBox->setText(java->path);
|
2018-11-10 02:15:55 +05:30
|
|
|
bool visible = java->id.requiresPermGen() && m_settings->get("OverrideMemory").toBool();
|
|
|
|
ui->permGenSpinBox->setVisible(visible);
|
|
|
|
ui->labelPermGen->setVisible(visible);
|
|
|
|
ui->labelPermgenNote->setVisible(visible);
|
|
|
|
m_settings->set("PermGenVisible", visible);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
2014-06-09 04:59:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::on_javaBrowseBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable"));
|
|
|
|
|
|
|
|
// do not allow current dir - it's dirty. Do not allow dirs that don't exist
|
|
|
|
if(raw_path.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString cooked_path = FS::NormalizePath(raw_path);
|
|
|
|
|
2018-11-10 02:15:55 +05:30
|
|
|
QFileInfo javaInfo(cooked_path);
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!javaInfo.exists() || !javaInfo.isExecutable())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui->javaPathTextBox->setText(cooked_path);
|
2018-11-10 02:15:55 +05:30
|
|
|
|
|
|
|
// custom Java could be anything... enable perm gen option
|
|
|
|
ui->permGenSpinBox->setVisible(true);
|
|
|
|
ui->labelPermGen->setVisible(true);
|
|
|
|
ui->labelPermgenNote->setVisible(true);
|
|
|
|
m_settings->set("PermGenVisible", true);
|
2014-06-09 04:59:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::on_javaTestBtn_clicked()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(checker)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
checker.reset(new JavaCommon::TestCheck(
|
|
|
|
this, ui->javaPathTextBox->text(), ui->jvmArgsTextBox->toPlainText().replace("\n", " "),
|
|
|
|
ui->minMemSpinBox->value(), ui->maxMemSpinBox->value(), ui->permGenSpinBox->value()));
|
|
|
|
connect(checker.get(), SIGNAL(finished()), SLOT(checkerFinished()));
|
|
|
|
checker->run();
|
2014-06-09 04:59:18 +05:30
|
|
|
}
|
|
|
|
|
2015-05-04 04:50:48 +05:30
|
|
|
void InstanceSettingsPage::checkerFinished()
|
2014-06-09 04:59:18 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
checker.reset();
|
2014-06-09 04:59:18 +05:30
|
|
|
}
|