summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-05-04 01:20:48 +0200
committerPetr Mrázek <peterix@gmail.com>2015-05-04 01:20:48 +0200
commit1b884d0a9dc28d8bca38fe8756482d991d0ea850 (patch)
treefabe4350a3d64123ad0801fe7c285c2150f9562b
parent8e9d5f56b592fd0dd0f54e747a835391a775120d (diff)
downloadMultiMC-1b884d0a9dc28d8bca38fe8756482d991d0ea850.tar
MultiMC-1b884d0a9dc28d8bca38fe8756482d991d0ea850.tar.gz
MultiMC-1b884d0a9dc28d8bca38fe8756482d991d0ea850.tar.lz
MultiMC-1b884d0a9dc28d8bca38fe8756482d991d0ea850.tar.xz
MultiMC-1b884d0a9dc28d8bca38fe8756482d991d0ea850.zip
GH-907 improve Java testing and PermGen deprecation handling
-rw-r--r--application/CMakeLists.txt7
-rw-r--r--application/JavaCommon.cpp107
-rw-r--r--application/JavaCommon.h46
-rw-r--r--application/MainWindow.cpp8
-rw-r--r--application/MultiMC.cpp2
-rw-r--r--application/NagUtils.cpp38
-rw-r--r--application/NagUtils.h23
-rw-r--r--application/pages/InstanceSettingsPage.cpp41
-rw-r--r--application/pages/InstanceSettingsPage.h11
-rw-r--r--application/pages/global/JavaPage.cpp43
-rw-r--r--application/pages/global/JavaPage.h9
-rw-r--r--application/pages/global/JavaPage.ui80
-rw-r--r--application/pages/global/MinecraftPage.cpp12
-rw-r--r--application/pages/global/MultiMCPage.cpp15
-rw-r--r--logic/CMakeLists.txt2
-rw-r--r--logic/java/JavaChecker.cpp69
-rw-r--r--logic/java/JavaChecker.h13
-rw-r--r--logic/java/JavaVersionList.cpp4
-rw-r--r--logic/minecraft/MinecraftInstance.cpp6
-rw-r--r--logic/minecraft/MinecraftProcess.cpp70
-rw-r--r--logic/settings/PassthroughSetting.cpp66
-rw-r--r--logic/settings/PassthroughSetting.h45
-rw-r--r--logic/settings/SettingsObject.cpp17
-rw-r--r--logic/settings/SettingsObject.h10
24 files changed, 514 insertions, 230 deletions
diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt
index 2518e52e..7ec96e5d 100644
--- a/application/CMakeLists.txt
+++ b/application/CMakeLists.txt
@@ -156,10 +156,9 @@ SET(MULTIMC_SOURCES
InstancePageProvider.h
InstancePageProvider.cpp
- # Annoying nag screen logic
- NagUtils.h
- NagUtils.cpp
-
+ # Common java checking UI
+ JavaCommon.h
+ JavaCommon.cpp
# GUI - page dialog pages
pages/BasePage.h
diff --git a/application/JavaCommon.cpp b/application/JavaCommon.cpp
new file mode 100644
index 00000000..d0a3cba3
--- /dev/null
+++ b/application/JavaCommon.cpp
@@ -0,0 +1,107 @@
+#include "JavaCommon.h"
+#include "dialogs/CustomMessageBox.h"
+#include <MMCStrings.h>
+
+bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget *parent)
+{
+ if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(QRegExp("-Xm[sx]")))
+ {
+ CustomMessageBox::selectable(
+ parent, QObject::tr("JVM arguments warning"),
+ QObject::tr("You tried to manually set a JVM memory option (using "
+ " \"-XX:PermSize\", \"-Xmx\" or \"-Xms\") - there"
+ " are dedicated boxes for these in the settings (Java"
+ " tab, in the Memory group at the top).\n"
+ "Your manual settings will be overridden by the"
+ " dedicated options.\n"
+ "This message will be displayed until you remove them"
+ " from the JVM arguments."),
+ QMessageBox::Warning)->exec();
+ return false;
+ }
+ return true;
+}
+
+void JavaCommon::TestCheck::javaWasOk(JavaCheckResult result)
+{
+ QString text;
+ text += tr("Java test succeeded!<br />Platform reported: %1<br />Java version "
+ "reported: %2<br />").arg(result.realPlatform, result.javaVersion);
+ if (result.stderr.size())
+ {
+ auto htmlError = result.stderr;
+ htmlError.replace('\n', "<br />");
+ text += tr("<br />Warnings:<br /><font color=\"orange\">%1</font>").arg(htmlError);
+ }
+ CustomMessageBox::selectable(m_parent, tr("Java test success"), text,
+ QMessageBox::Information)->show();
+}
+
+void JavaCommon::TestCheck::javaArgsWereBad(JavaCheckResult result)
+{
+ auto htmlError = result.stderr;
+ QString text;
+ htmlError.replace('\n', "<br />");
+ text += tr("The specified java binary didn't work with the arguments you provided:<br />");
+ text += tr("<font color=\"red\">%1</font>").arg(htmlError);
+ CustomMessageBox::selectable(m_parent, tr("Java test failure"), text, QMessageBox::Warning)
+ ->show();
+}
+
+void JavaCommon::TestCheck::javaBinaryWasBad(JavaCheckResult result)
+{
+ QString text;
+ text += tr(
+ "The specified java binary didn't work.<br />You should use the auto-detect feature, "
+ "or set the path to the java executable.<br />");
+ CustomMessageBox::selectable(m_parent, tr("Java test failure"), text, QMessageBox::Warning)
+ ->show();
+}
+
+void JavaCommon::TestCheck::run()
+{
+ if (!JavaCommon::checkJVMArgs(m_args, m_parent))
+ {
+ emit finished();
+ return;
+ }
+ checker.reset(new JavaChecker());
+ connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this,
+ SLOT(checkFinished(JavaCheckResult)));
+ checker->m_path = m_path;
+ checker->performCheck();
+}
+
+void JavaCommon::TestCheck::checkFinished(JavaCheckResult result)
+{
+ if (!result.valid)
+ {
+ javaBinaryWasBad(result);
+ emit finished();
+ return;
+ }
+ checker.reset(new JavaChecker());
+ connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this,
+ SLOT(checkFinishedWithArgs(JavaCheckResult)));
+ checker->m_path = m_path;
+ checker->m_args = m_args;
+ checker->m_minMem = m_minMem;
+ checker->m_maxMem = m_maxMem;
+ if (Strings::naturalCompare(result.javaVersion, "1.8", Qt::CaseInsensitive) < 0)
+ {
+ checker->m_permGen = m_permGen;
+ }
+ checker->performCheck();
+}
+
+void JavaCommon::TestCheck::checkFinishedWithArgs(JavaCheckResult result)
+{
+ if (result.valid)
+ {
+ javaWasOk(result);
+ emit finished();
+ return;
+ }
+ javaArgsWereBad(result);
+ emit finished();
+}
diff --git a/application/JavaCommon.h b/application/JavaCommon.h
new file mode 100644
index 00000000..b100c213
--- /dev/null
+++ b/application/JavaCommon.h
@@ -0,0 +1,46 @@
+#pragma once
+#include <java/JavaChecker.h>
+
+class QWidget;
+
+/**
+ * Common UI bits for the java pages to use.
+ */
+namespace JavaCommon
+{
+ bool checkJVMArgs(QString args, QWidget *parent);
+
+ class TestCheck : public QObject
+ {
+ Q_OBJECT
+ public:
+ TestCheck(QWidget *parent, QString path, QString args, int minMem, int maxMem, int permGen)
+ :m_parent(parent), m_path(path), m_args(args), m_minMem(minMem), m_maxMem(maxMem), m_permGen(permGen)
+ {
+ }
+ virtual ~TestCheck() {};
+
+ void run();
+
+ signals:
+ void finished();
+
+ private:
+ void javaBinaryWasBad(JavaCheckResult result);
+ void javaArgsWereBad(JavaCheckResult result);
+ void javaWasOk(JavaCheckResult result);
+
+ private slots:
+ void checkFinished(JavaCheckResult result);
+ void checkFinishedWithArgs(JavaCheckResult result);
+
+ private:
+ std::shared_ptr<JavaChecker> checker;
+ QWidget *m_parent = nullptr;
+ QString m_path;
+ QString m_args;
+ int m_minMem = 0;
+ int m_maxMem = 0;
+ int m_permGen = 64;
+ };
+}
diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp
index 055a38c9..608aca9c 100644
--- a/application/MainWindow.cpp
+++ b/application/MainWindow.cpp
@@ -381,7 +381,7 @@ namespace Ui {
#include "BaseInstance.h"
#include "BaseProcess.h"
#include "java/JavaUtils.h"
-#include "NagUtils.h"
+#include "JavaCommon.h"
#include "InstancePageProvider.h"
#include "minecraft/SkinUtils.h"
@@ -1545,7 +1545,7 @@ void MainWindow::instanceActivated(QModelIndex index)
if (!inst)
return;
- NagUtils::checkJVMArgs(inst->settings().get("JvmArgs").toString(), this);
+ JavaCommon::checkJVMArgs(inst->settings().get("JvmArgs").toString(), this);
doLaunch();
}
@@ -1554,7 +1554,7 @@ void MainWindow::on_actionLaunchInstance_triggered()
{
if (m_selectedInstance)
{
- NagUtils::checkJVMArgs(m_selectedInstance->settings().get("JvmArgs").toString(), this);
+ JavaCommon::checkJVMArgs(m_selectedInstance->settings().get("JvmArgs").toString(), this);
doLaunch();
}
}
@@ -1563,7 +1563,7 @@ void MainWindow::on_actionLaunchInstanceOffline_triggered()
{
if (m_selectedInstance)
{
- NagUtils::checkJVMArgs(m_selectedInstance->settings().get("JvmArgs").toString(), this);
+ JavaCommon::checkJVMArgs(m_selectedInstance->settings().get("JvmArgs").toString(), this);
doLaunch(false);
}
}
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp
index b993aa5e..aae8d154 100644
--- a/application/MultiMC.cpp
+++ b/application/MultiMC.cpp
@@ -453,6 +453,8 @@ void MultiMC::initGlobalSettings(bool test_mode)
// Java Settings
m_settings->registerSetting("JavaPath", "");
+ m_settings->registerSetting("JavaTimestamp", 0);
+ m_settings->registerSetting("JavaVersion", "");
m_settings->registerSetting("LastHostname", "");
m_settings->registerSetting("JavaDetectionHack", "");
m_settings->registerSetting("JvmArgs", "");
diff --git a/application/NagUtils.cpp b/application/NagUtils.cpp
deleted file mode 100644
index 41e2f63e..00000000
--- a/application/NagUtils.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Copyright 2013-2015 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 "NagUtils.h"
-#include "dialogs/CustomMessageBox.h"
-
-namespace NagUtils
-{
-void checkJVMArgs(QString jvmargs, QWidget *parent)
-{
- if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(QRegExp("-Xm[sx]")))
- {
- CustomMessageBox::selectable(
- parent, QObject::tr("JVM arguments warning"),
- QObject::tr("You tried to manually set a JVM memory option (using "
- " \"-XX:PermSize\", \"-Xmx\" or \"-Xms\") - there"
- " are dedicated boxes for these in the settings (Java"
- " tab, in the Memory group at the top).\n"
- "Your manual settings will be overridden by the"
- " dedicated options.\n"
- "This message will be displayed until you remove them"
- " from the JVM arguments."),
- QMessageBox::Warning)->exec();
- }
-}
-}
diff --git a/application/NagUtils.h b/application/NagUtils.h
deleted file mode 100644
index d757703a..00000000
--- a/application/NagUtils.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Copyright 2013-2015 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>
-
-namespace NagUtils
-{
-void checkJVMArgs(QString args, QWidget *parent);
-}
diff --git a/application/pages/InstanceSettingsPage.cpp b/application/pages/InstanceSettingsPage.cpp
index 1e571eff..4fc812b2 100644
--- a/application/pages/InstanceSettingsPage.cpp
+++ b/application/pages/InstanceSettingsPage.cpp
@@ -6,10 +6,11 @@
#include <QMessageBox>
#include "dialogs/VersionSelectDialog.h"
-#include "NagUtils.h"
-#include "java/JavaVersionList.h"
+#include "JavaCommon.h"
#include "MultiMC.h"
+#include <java/JavaVersionList.h>
+
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
{
@@ -100,7 +101,7 @@ void InstanceSettingsPage::applySettings()
if(javaArgs)
{
m_settings->set("JvmArgs", ui->jvmArgsTextBox->toPlainText().replace("\n", " "));
- NagUtils::checkJVMArgs(m_settings->get("JvmArgs").toString(), this->parentWidget());
+ JavaCommon::checkJVMArgs(m_settings->get("JvmArgs").toString(), this->parentWidget());
}
else
{
@@ -187,30 +188,18 @@ void InstanceSettingsPage::on_javaBrowseBtn_clicked()
void InstanceSettingsPage::on_javaTestBtn_clicked()
{
- checker.reset(new JavaChecker());
- connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this,
- SLOT(checkFinished(JavaCheckResult)));
- checker->path = ui->javaPathTextBox->text();
- checker->performCheck();
+ 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();
}
-void InstanceSettingsPage::checkFinished(JavaCheckResult result)
+void InstanceSettingsPage::checkerFinished()
{
- if (result.valid)
- {
- QString text;
- text += "Java test succeeded!\n";
- if (result.is_64bit)
- text += "Using 64bit java.\n";
- text += "\n";
- text += "Platform reported: " + result.realPlatform;
- QMessageBox::information(this, tr("Java test success"), text);
- }
- else
- {
- QMessageBox::warning(
- this, tr("Java test failure"),
- tr("The specified java binary didn't work. You should use the auto-detect feature, "
- "or set the path to the java executable."));
- }
+ checker.reset();
}
diff --git a/application/pages/InstanceSettingsPage.h b/application/pages/InstanceSettingsPage.h
index 60cc1898..55ae69db 100644
--- a/application/pages/InstanceSettingsPage.h
+++ b/application/pages/InstanceSettingsPage.h
@@ -19,7 +19,9 @@
#include "java/JavaChecker.h"
#include "BaseInstance.h"
+#include <QObjectPtr.h>
#include "BasePage.h"
+#include "JavaCommon.h"
#include "MultiMC.h"
class JavaChecker;
@@ -53,21 +55,20 @@ public:
return "Instance-settings";
}
virtual bool shouldDisplay() const;
+
private slots:
void on_javaDetectBtn_clicked();
-
void on_javaTestBtn_clicked();
-
void on_javaBrowseBtn_clicked();
- void checkFinished(JavaCheckResult result);
-
void applySettings();
void loadSettings();
+ void checkerFinished();
+
private:
Ui::InstanceSettingsPage *ui;
BaseInstance *m_instance;
SettingsObject *m_settings;
- std::shared_ptr<JavaChecker> checker;
+ QObjectPtr<JavaCommon::TestCheck> checker;
};
diff --git a/application/pages/global/JavaPage.cpp b/application/pages/global/JavaPage.cpp
index 1b480376..3daf35dc 100644
--- a/application/pages/global/JavaPage.cpp
+++ b/application/pages/global/JavaPage.cpp
@@ -14,6 +14,7 @@
*/
#include "JavaPage.h"
+#include "JavaCommon.h"
#include "ui_JavaPage.h"
#include <QFileDialog>
@@ -22,15 +23,11 @@
#include <pathutils.h>
-#include "NagUtils.h"
-
-#include "Platform.h"
#include "dialogs/VersionSelectDialog.h"
#include <ColumnResizer.h>
#include "java/JavaUtils.h"
#include "java/JavaVersionList.h"
-#include "java/JavaChecker.h"
#include "settings/SettingsObject.h"
#include "MultiMC.h"
@@ -69,7 +66,7 @@ void JavaPage::applySettings()
// Java Settings
s->set("JavaPath", ui->javaPathTextBox->text());
s->set("JvmArgs", ui->jvmArgsTextBox->text());
- NagUtils::checkJVMArgs(s->get("JvmArgs").toString(), this->parentWidget());
+ JavaCommon::checkJVMArgs(s->get("JvmArgs").toString(), this->parentWidget());
// Custom Commands
s->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text());
@@ -113,33 +110,21 @@ void JavaPage::on_javaBrowseBtn_clicked()
ui->javaPathTextBox->setText(dir);
}
}
+
void JavaPage::on_javaTestBtn_clicked()
{
- checker.reset(new JavaChecker());
- connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this,
- SLOT(checkFinished(JavaCheckResult)));
- checker->path = ui->javaPathTextBox->text();
- checker->performCheck();
+ if(checker)
+ {
+ return;
+ }
+ checker.reset(new JavaCommon::TestCheck(
+ this, ui->javaPathTextBox->text(), ui->jvmArgsTextBox->text(),
+ ui->minMemSpinBox->value(), ui->maxMemSpinBox->value(), ui->permGenSpinBox->value()));
+ connect(checker.get(), SIGNAL(finished()), SLOT(checkerFinished()));
+ checker->run();
}
-void JavaPage::checkFinished(JavaCheckResult result)
+void JavaPage::checkerFinished()
{
- if (result.valid)
- {
- QString text;
- text += "Java test succeeded!\n";
- if (result.is_64bit)
- text += "Using 64bit java.\n";
- text += "\n";
- text += "Platform reported: " + result.realPlatform + "\n";
- text += "Java version reported: " + result.javaVersion;
- QMessageBox::information(this, tr("Java test success"), text);
- }
- else
- {
- QMessageBox::warning(
- this, tr("Java test failure"),
- tr("The specified java binary didn't work. You should use the auto-detect feature, "
- "or set the path to the java executable."));
- }
+ checker.reset();
}
diff --git a/application/pages/global/JavaPage.h b/application/pages/global/JavaPage.h
index 2af85280..4dd2b306 100644
--- a/application/pages/global/JavaPage.h
+++ b/application/pages/global/JavaPage.h
@@ -17,10 +17,10 @@
#include <memory>
#include <QDialog>
-
-#include "java/JavaChecker.h"
#include "pages/BasePage.h"
+#include "JavaCommon.h"
#include <MultiMC.h>
+#include <QObjectPtr.h>
class SettingsObject;
@@ -64,10 +64,9 @@ slots:
void on_javaDetectBtn_clicked();
void on_javaTestBtn_clicked();
void on_javaBrowseBtn_clicked();
-
- void checkFinished(JavaCheckResult result);
+ void checkerFinished();
private:
Ui::JavaPage *ui;
- std::shared_ptr<JavaChecker> checker;
+ QObjectPtr<JavaCommon::TestCheck> checker;
};
diff --git a/application/pages/global/JavaPage.ui b/application/pages/global/JavaPage.ui
index 6ae41a49..f9c629c2 100644
--- a/application/pages/global/JavaPage.ui
+++ b/application/pages/global/JavaPage.ui
@@ -161,45 +161,6 @@
</property>
</widget>
</item>
- <item row="1" column="1">
- <widget class="QPushButton" name="javaDetectBtn">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Auto-detect...</string>
- </property>
- </widget>
- </item>
- <item row="1" column="2">
- <widget class="QPushButton" name="javaTestBtn">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Test</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="labelJVMArgs">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>JVM arguments:</string>
- </property>
- </widget>
- </item>
<item row="0" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@@ -229,6 +190,45 @@
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="jvmArgsTextBox"/>
</item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="labelJVMArgs">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>JVM arguments:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QPushButton" name="javaDetectBtn">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Auto-detect...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2">
+ <widget class="QPushButton" name="javaTestBtn">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Test</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
@@ -292,8 +292,6 @@
<tabstop>permGenSpinBox</tabstop>
<tabstop>javaPathTextBox</tabstop>
<tabstop>javaBrowseBtn</tabstop>
- <tabstop>javaDetectBtn</tabstop>
- <tabstop>javaTestBtn</tabstop>
<tabstop>jvmArgsTextBox</tabstop>
<tabstop>preLaunchCmdTextBox</tabstop>
<tabstop>postExitCmdTextBox</tabstop>
diff --git a/application/pages/global/MinecraftPage.cpp b/application/pages/global/MinecraftPage.cpp
index f5e7e57f..d1f1fb08 100644
--- a/application/pages/global/MinecraftPage.cpp
+++ b/application/pages/global/MinecraftPage.cpp
@@ -23,18 +23,6 @@
#include <pathutils.h>
#include "Platform.h"
-#include "dialogs/VersionSelectDialog.h"
-#include "dialogs/CustomMessageBox.h"
-
-#include "NagUtils.h"
-
-#include "java/JavaUtils.h"
-#include "java/JavaVersionList.h"
-#include "java/JavaChecker.h"
-
-#include "updater/UpdateChecker.h"
-
-#include "tools/BaseProfiler.h"
#include "settings/SettingsObject.h"
#include "MultiMC.h"
diff --git a/application/pages/global/MultiMCPage.cpp b/application/pages/global/MultiMCPage.cpp
index 5f56fb89..83c1ccd5 100644
--- a/application/pages/global/MultiMCPage.cpp
+++ b/application/pages/global/MultiMCPage.cpp
@@ -22,22 +22,9 @@
#include <QTextCharFormat>
#include <pathutils.h>
-
-#include "Platform.h"
-#include "dialogs/VersionSelectDialog.h"
-#include "dialogs/CustomMessageBox.h"
#include <ColumnResizer.h>
-
-#include "NagUtils.h"
-
-#include "java/JavaUtils.h"
-#include "java/JavaVersionList.h"
-#include "java/JavaChecker.h"
-
#include "updater/UpdateChecker.h"
-#include "tools/BaseProfiler.h"
-
#include "settings/SettingsObject.h"
#include "MultiMC.h"
@@ -456,4 +443,4 @@ void MultiMCPage::refreshFontPreview()
workCursor.insertText(tr("[Something/WARN] A not so spooky warning."), format);
workCursor.insertBlock();
}
-} \ No newline at end of file
+}
diff --git a/logic/CMakeLists.txt b/logic/CMakeLists.txt
index f22078c1..de1940ad 100644
--- a/logic/CMakeLists.txt
+++ b/logic/CMakeLists.txt
@@ -191,6 +191,8 @@ SET(LOGIC_SOURCES
settings/INISettingsObject.h
settings/OverrideSetting.cpp
settings/OverrideSetting.h
+ settings/PassthroughSetting.cpp
+ settings/PassthroughSetting.h
settings/Setting.cpp
settings/Setting.h
settings/SettingsObject.cpp
diff --git a/logic/java/JavaChecker.cpp b/logic/java/JavaChecker.cpp
index b62ddfbe..18877898 100644
--- a/logic/java/JavaChecker.cpp
+++ b/logic/java/JavaChecker.cpp
@@ -1,5 +1,6 @@
#include "JavaChecker.h"
#include <pathutils.h>
+#include <cmdutils.h>
#include <QFile>
#include <QProcess>
#include <QMap>
@@ -15,26 +16,59 @@ void JavaChecker::performCheck()
{
QString checkerJar = PathCombine(QCoreApplication::applicationDirPath(), "jars", "JavaCheck.jar");
- QStringList args = {"-jar", checkerJar};
+ QStringList args;
process.reset(new QProcess());
+ if(m_args.size())
+ {
+ auto extraArgs = Util::Commandline::splitArgs(m_args);
+ args.append(extraArgs);
+ }
+ if(m_minMem != 0)
+ {
+ args << QString("-Xms%1m").arg(m_minMem);
+ }
+ if(m_maxMem != 0)
+ {
+ args << QString("-Xmx%1m").arg(m_maxMem);
+ }
+ if(m_permGen != 64)
+ {
+ args << QString("-XX:PermSize=%1m").arg(m_permGen);
+ }
+
+ args.append({"-jar", checkerJar});
process->setArguments(args);
- process->setProgram(path);
+ process->setProgram(m_path);
process->setProcessChannelMode(QProcess::SeparateChannels);
- qDebug() << "Running java checker!";
- qDebug() << "Java: " + path;
- qDebug() << "Args: {" + args.join("|") + "}";
-
- connect(process.get(), SIGNAL(finished(int, QProcess::ExitStatus)), this,
- SLOT(finished(int, QProcess::ExitStatus)));
- connect(process.get(), SIGNAL(error(QProcess::ProcessError)), this,
- SLOT(error(QProcess::ProcessError)));
+ qDebug() << "Running java checker: " + m_path + args.join(" ");;
+
+ connect(process.get(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus)));
+ connect(process.get(), SIGNAL(error(QProcess::ProcessError)), this, SLOT(error(QProcess::ProcessError)));
+ connect(process.get(), SIGNAL(readyReadStandardOutput()), this, SLOT(stdoutReady()));
+ connect(process.get(), SIGNAL(readyReadStandardError()), this, SLOT(stderrReady()));
connect(&killTimer, SIGNAL(timeout()), SLOT(timeout()));
killTimer.setSingleShot(true);
killTimer.start(15000);
process->start();
}
+void JavaChecker::stdoutReady()
+{
+ QByteArray data = process->readAllStandardOutput();
+ QString added = QString::fromLocal8Bit(data);
+ added.remove('\r');
+ m_stdout += added;
+}
+
+void JavaChecker::stderrReady()
+{
+ QByteArray data = process->readAllStandardError();
+ QString added = QString::fromLocal8Bit(data);
+ added.remove('\r');
+ m_stderr += added;
+}
+
void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
{
killTimer.stop();
@@ -43,9 +77,12 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
JavaCheckResult result;
{
- result.path = path;
- result.id = id;
+ result.path = m_path;
+ result.id = m_id;
}
+ result.stderr = m_stderr;
+ qDebug() << "STDOUT" << m_stdout;
+ qWarning() << "STDERR" << m_stderr;
qDebug() << "Java checker finished with status " << status << " exit code " << exitcode;
if (status == QProcess::CrashExit || exitcode == 1)
@@ -56,11 +93,9 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
}
bool success = true;
- QString p_stdout = _process->readAllStandardOutput();
- qDebug() << p_stdout;
QMap<QString, QString> results;
- QStringList lines = p_stdout.split("\n", QString::SkipEmptyParts);
+ QStringList lines = m_stdout.split("\n", QString::SkipEmptyParts);
for(QString line : lines)
{
line = line.trimmed();
@@ -105,8 +140,8 @@ void JavaChecker::error(QProcess::ProcessError err)
qDebug() << "Java checker has failed to start.";
JavaCheckResult result;
{
- result.path = path;
- result.id = id;
+ result.path = m_path;
+ result.id = m_id;
}
emit checkFinished(result);
diff --git a/logic/java/JavaChecker.h b/logic/java/JavaChecker.h
index e19895f7..29598aa4 100644
--- a/logic/java/JavaChecker.h
+++ b/logic/java/JavaChecker.h
@@ -12,6 +12,7 @@ struct JavaCheckResult
QString mojangPlatform;
QString realPlatform;
QString javaVersion;
+ QString stderr;
bool valid = false;
bool is_64bit = false;
int id;
@@ -26,17 +27,25 @@ public:
explicit JavaChecker(QObject *parent = 0);
void performCheck();
- QString path;
- int id;
+ QString m_path;
+ QString m_args;
+ int m_id = 0;
+ int m_minMem = 0;
+ int m_maxMem = 0;
+ int m_permGen = 64;
signals:
void checkFinished(JavaCheckResult result);
private:
QProcessPtr process;
QTimer killTimer;
+ QString m_stdout;
+ QString m_stderr;
public
slots:
void timeout();
void finished(int exitcode, QProcess::ExitStatus);
void error(QProcess::ProcessError);
+ void stdoutReady();
+ void stderrReady();
};
diff --git a/logic/java/JavaVersionList.cpp b/logic/java/JavaVersionList.cpp
index 7889853b..52f2e62f 100644
--- a/logic/java/JavaVersionList.cpp
+++ b/logic/java/JavaVersionList.cpp
@@ -171,8 +171,8 @@ void JavaListLoadTask::executeTask()
qDebug() << " " << candidate;
auto candidate_checker = new JavaChecker();
- candidate_checker->path = candidate;
- candidate_checker->id = id;
+ candidate_checker->m_path = candidate;
+ candidate_checker->m_id = id;
m_job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker));
id++;
diff --git a/logic/minecraft/MinecraftInstance.cpp b/logic/minecraft/MinecraftInstance.cpp
index e4273cb9..2813a609 100644
--- a/logic/minecraft/MinecraftInstance.cpp
+++ b/logic/minecraft/MinecraftInstance.cpp
@@ -9,11 +9,15 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO
{
// Java Settings
m_settings->registerSetting("OverrideJava", false);
- m_settings->registerSetting("OverrideJavaLocation", false);
+ auto locationOverride = m_settings->registerSetting("OverrideJavaLocation", false);
m_settings->registerSetting("OverrideJavaArgs", false);
m_settings->registerOverride(globalSettings->getSetting("JavaPath"));
m_settings->registerOverride(globalSettings->getSetting("JvmArgs"));
+ // special!
+ m_settings->registerPassthrough(globalSettings->getSetting("JavaTimestamp"), locationOverride);
+ m_settings->registerPassthrough(globalSettings->getSetting("JavaVersion"), locationOverride);
+
// Window Size
m_settings->registerSetting("OverrideWindow", false);
m_settings->registerOverride(globalSettings->getSetting("LaunchMaximized"));
diff --git a/logic/minecraft/MinecraftProcess.cpp b/logic/minecraft/MinecraftProcess.cpp
index 9d18ad90..10d30b73 100644
--- a/logic/minecraft/MinecraftProcess.cpp
+++ b/logic/minecraft/MinecraftProcess.cpp
@@ -16,6 +16,8 @@
*/
#include "minecraft/MinecraftProcess.h"
#include "BaseInstance.h"
+#include <java/JavaChecker.h>
+#include <MMCStrings.h>
#include <QDataStream>
#include <QFile>
@@ -141,11 +143,18 @@ QStringList MinecraftProcess::javaArguments() const
args << QString("-Xms%1m").arg(m_instance->settings().get("MinMemAlloc").toInt());
args << QString("-Xmx%1m").arg(m_instance->settings().get("MaxMemAlloc").toInt());
- auto permgen = m_instance->settings().get("PermGen").toInt();
- if (permgen != 64)
+
+ // No PermGen in newer java.
+ auto javaVersion = m_instance->settings().get("JavaVersion");
+ if(Strings::naturalCompare(javaVersion.toString(), "1.8.0", Qt::CaseInsensitive) < 0)
{
- args << QString("-XX:PermSize=%1m").arg(permgen);
+ auto permgen = m_instance->settings().get("PermGen").toInt();
+ if (permgen != 64)
+ {
+ args << QString("-XX:PermSize=%1m").arg(permgen);
+ }
}
+
args << "-Duser.language=en";
if (!m_nativeFolder.isEmpty())
args << QString("-Djava.library.path=%1").arg(m_nativeFolder);
@@ -167,12 +176,8 @@ void MinecraftProcess::arm()
m_instance->setLastLaunch();
- QStringList args = javaArguments();
-
QString JavaPath = m_instance->settings().get("JavaPath").toString();
emit log("Java path is:\n" + JavaPath + "\n\n");
- QString allArgs = args.join(", ");
- emit log("Java Arguments:\n[" + censorPrivateInfo(allArgs) + "]\n\n");
auto realJavaPath = QStandardPaths::findExecutable(JavaPath);
if (realJavaPath.isEmpty())
@@ -182,6 +187,57 @@ void MinecraftProcess::arm()
MessageLevel::Warning);
}
+ // check java version here.
+ {
+ QFileInfo javaInfo(realJavaPath);
+ qlonglong javaUnixTime = javaInfo.lastModified().toMSecsSinceEpoch();
+ auto storedUnixTime = m_instance->settings().get("JavaTimestamp").toLongLong();
+ // if they are not the same, check!
+ if(javaUnixTime != storedUnixTime)
+ {
+ QEventLoop ev;
+ auto checker = std::make_shared<JavaChecker>();
+ bool successful = false;
+ QString errorLog;
+ QString version;
+ emit log(tr("Checking Java version..."), MessageLevel::MultiMC);
+ connect(checker.get(), &JavaChecker::checkFinished,
+ [&](JavaCheckResult result)
+ {
+ successful = result.valid;
+ errorLog = result.stderr;
+ version = result.javaVersion;
+ ev.exit();
+ });
+ checker->m_path = realJavaPath;
+ checker->performCheck();
+ ev.exec();
+ if(!successful)
+ {
+ // Error message displayed if java can't start
+ emit log(tr("Could not start java:"), MessageLevel::Error);
+ auto lines = errorLog.split('\n');
+ for(auto line: lines)
+ {
+ emit log(line, MessageLevel::Error);
+ }
+ emit log("\nCheck your MultiMC Java settings.", MessageLevel::MultiMC);
+ m_instance->cleanupAfterRun();
+ emit launch_failed(m_instance);
+ // not running, failed
+ m_instance->setRunning(false);
+ return;
+ }
+ emit log(tr("Java version is %1!\n").arg(version), MessageLevel::MultiMC);
+ m_instance->settings().set("JavaVersion", version);
+ m_instance->settings().set("JavaTimestamp", javaUnixTime);
+ }
+ }
+
+ QStringList args = javaArguments();
+ QString allArgs = args.join(", ");
+ emit log("Java Arguments:\n[" + censorPrivateInfo(allArgs) + "]\n\n");
+
// instantiate the launcher part
start(JavaPath, args);
if (!waitForStarted())
diff --git a/logic/settings/PassthroughSetting.cpp b/logic/settings/PassthroughSetting.cpp
new file mode 100644
index 00000000..45a560de
--- /dev/null
+++ b/logic/settings/PassthroughSetting.cpp
@@ -0,0 +1,66 @@
+/* Copyright 2013-2015 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 "PassthroughSetting.h"
+
+PassthroughSetting::PassthroughSetting(std::shared_ptr<Setting> other, std::shared_ptr<Setting> gate)
+ : Setting(other->configKeys(), QVariant())
+{
+ Q_ASSERT(other);
+ Q_ASSERT(gate);
+ m_other = other;
+ m_gate = gate;
+}
+
+bool PassthroughSetting::isOverriding() const
+{
+ return m_gate->get().toBool();
+}
+
+QVariant PassthroughSetting::defValue() const
+{
+ if(isOverriding())
+ {
+ return m_other->get();
+ }
+ return m_other->defValue();
+}
+
+QVariant PassthroughSetting::get() const
+{
+ if(isOverriding())
+ {
+ return Setting::get();
+ }
+ return m_other->get();
+}
+
+void PassthroughSetting::reset()
+{
+ if(isOverriding())
+ {
+ Setting::reset();
+ }
+ m_other->reset();
+}
+
+void PassthroughSetting::set(QVariant value)
+{
+ if(isOverriding())
+ {
+ Setting::set(value);
+ }
+ m_other->set(value);
+}
diff --git a/logic/settings/PassthroughSetting.h b/logic/settings/PassthroughSetting.h
new file mode 100644
index 00000000..c4dc646c
--- /dev/null
+++ b/logic/settings/PassthroughSetting.h
@@ -0,0 +1,45 @@
+/* Copyright 2013-2015 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 <QObject>
+#include <memory>
+
+#include "Setting.h"
+
+/*!
+ * \brief A setting that 'overrides another.' based on the value of a 'gate' setting
+ * If 'gate' evaluates to true, the override stores and returns data
+ * If 'gate' evaluates to false, the original does,
+ */
+class PassthroughSetting : public Setting
+{
+ Q_OBJECT
+public:
+ explicit PassthroughSetting(std::shared_ptr<Setting> overriden, std::shared_ptr<Setting> gate);
+
+ virtual QVariant defValue() const;
+ virtual QVariant get() const;
+ virtual void set (QVariant value);
+ virtual void reset();
+
+private:
+ bool isOverriding() const;
+
+protected:
+ std::shared_ptr<Setting> m_other;
+ std::shared_ptr<Setting> m_gate;
+};
diff --git a/logic/settings/SettingsObject.cpp b/logic/settings/SettingsObject.cpp
index e88eae49..5e682cbf 100644
--- a/logic/settings/SettingsObject.cpp
+++ b/logic/settings/SettingsObject.cpp
@@ -16,6 +16,7 @@
#include "settings/SettingsObject.h"
#include "settings/Setting.h"
#include "settings/OverrideSetting.h"
+#include "PassthroughSetting.h"
#include <QDebug>
#include <QVariant>
@@ -44,6 +45,22 @@ std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Settin
return override;
}
+std::shared_ptr<Setting> SettingsObject::registerPassthrough(std::shared_ptr<Setting> original,
+ std::shared_ptr<Setting> gate)
+{
+ if (contains(original->id()))
+ {
+ qCritical() << QString("Failed to register setting %1. ID already exists.")
+ .arg(original->id());
+ return nullptr; // Fail
+ }
+ auto passthrough = std::make_shared<PassthroughSetting>(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())
diff --git a/logic/settings/SettingsObject.h b/logic/settings/SettingsObject.h
index ac8419e8..99782a01 100644
--- a/logic/settings/SettingsObject.h
+++ b/logic/settings/SettingsObject.h
@@ -51,6 +51,16 @@ public:
std::shared_ptr<Setting> registerOverride(std::shared_ptr<Setting> original);
/*!
+ * Registers a passthorugh setting for the given original setting in this settings object
+ * gate decides if the passthrough (true) or the original (false) is used for value
+ *
+ * This will fail if there is already a setting with the same ID as
+ * the one that is being registered.
+ * \return A valid Setting shared pointer if successful.
+ */
+ std::shared_ptr<Setting> registerPassthrough(std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate);
+
+ /*!
* Registers the given setting with this SettingsObject and connects the necessary signals.
*
* This will fail if there is already a setting with the same ID as