summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt3
-rw-r--r--gui/settingsdialog.cpp20
-rw-r--r--gui/settingsdialog.h4
-rw-r--r--gui/settingsdialog.ui37
-rw-r--r--logic/JavaUtils.cpp114
-rw-r--r--logic/JavaUtils.h26
6 files changed, 194 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7ecfb690..bf72efa4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -308,6 +308,9 @@ logic/tasks/ProgressProvider.h
logic/tasks/Task.h
logic/tasks/Task.cpp
+# Utilities
+logic/JavaUtils.h
+logic/JavaUtils.cpp
)
diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp
index 31fe2d96..c6fe893d 100644
--- a/gui/settingsdialog.cpp
+++ b/gui/settingsdialog.cpp
@@ -13,10 +13,11 @@
* limitations under the License.
*/
+#include <MultiMC.h>
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
+#include "logic/JavaUtils.h"
-#include <MultiMC.h>
#include <settingsobject.h>
#include <QFileDialog>
#include <QMessageBox>
@@ -180,3 +181,20 @@ void SettingsDialog::loadSettings(SettingsObject *s)
ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString());
ui->postExitCmdTextBox->setText(s->get("PostExitCommand").toString());
}
+
+void SettingsDialog::on_pushButton_clicked()
+{
+ JavaUtils jut;
+ QStringList paths = jut.FindJavaPath();
+
+ ui->javaPathTextBox->setText(paths.at(0));
+}
+
+void SettingsDialog::on_btnBrowse_clicked()
+{
+ QString dir = QFileDialog::getOpenFileName(this, tr("Find Java executable"));
+ if(!dir.isNull())
+ {
+ ui->javaPathTextBox->setText(dir);
+ }
+}
diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h
index b0a8c673..a8dfb1c6 100644
--- a/gui/settingsdialog.h
+++ b/gui/settingsdialog.h
@@ -53,6 +53,10 @@ private slots:
void on_buttonBox_accepted();
+ void on_pushButton_clicked();
+
+ void on_btnBrowse_clicked();
+
private:
Ui::SettingsDialog *ui;
};
diff --git a/gui/settingsdialog.ui b/gui/settingsdialog.ui
index 0d30e301..d7a134fb 100644
--- a/gui/settingsdialog.ui
+++ b/gui/settingsdialog.ui
@@ -33,7 +33,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
- <number>0</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="generalTab">
<attribute name="title">
@@ -379,26 +379,45 @@
</property>
</widget>
</item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="javaPathTextBox"/>
- </item>
- <item row="1" column="0">
+ <item row="2" column="0">
<widget class="QLabel" name="labelJVMArgs">
<property name="text">
<string>JVM arguments:</string>
</property>
</widget>
</item>
- <item row="0" column="2">
- <widget class="QPushButton" name="pushButton">
+ <item row="1" column="3">
+ <widget class="QPushButton" name="btnBrowse">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="text">
- <string>Auto-detect</string>
+ <string>Browse...</string>
</property>
</widget>
</item>
- <item row="1" column="1" colspan="2">
+ <item row="0" column="1" colspan="3">
+ <widget class="QLineEdit" name="javaPathTextBox"/>
+ </item>
+ <item row="2" column="1" colspan="3">
<widget class="QLineEdit" name="jvmArgsTextBox"/>
</item>
+ <item row="1" column="2">
+ <widget class="QPushButton" name="pushButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Auto-detect</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
diff --git a/logic/JavaUtils.cpp b/logic/JavaUtils.cpp
new file mode 100644
index 00000000..d89ab9c5
--- /dev/null
+++ b/logic/JavaUtils.cpp
@@ -0,0 +1,114 @@
+/* Copyright 2013 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 "JavaUtils.h"
+#include "osutils.h"
+#include "pathutils.h"
+
+#include <QStringList>
+#include <QString>
+#include <QDir>
+#include <QDebug>
+
+#if WINDOWS
+#include <windows.h>
+
+#endif
+
+JavaUtils::JavaUtils()
+{
+
+}
+
+#if WINDOWS
+QStringList JavaUtils::FindJavaPath()
+{
+ QStringList paths;
+
+ HKEY jreKey;
+ QString jreKeyName = "SOFTWARE\\JavaSoft\\Java Runtime Environment";
+ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, jreKeyName.toStdString().c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &jreKey) == ERROR_SUCCESS)
+ {
+ // Read the current JRE version from the registry.
+ // This will be used to find the key that contains the JavaHome value.
+ char *value = new char[0];
+ DWORD valueSz = 0;
+ if (RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE*)value, &valueSz) == ERROR_MORE_DATA)
+ {
+ value = new char[valueSz];
+ RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE*)value, &valueSz);
+ }
+
+ RegCloseKey(jreKey);
+
+ // Now open the registry key for the JRE version that we just got.
+ jreKeyName.append("\\").append(value);
+ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, jreKeyName.toStdString().c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &jreKey) == ERROR_SUCCESS)
+ {
+ // Read the JavaHome value to find where Java is installed.
+ value = new char[0];
+ valueSz = 0;
+ if (RegQueryValueExA(jreKey, "JavaHome", NULL, NULL, (BYTE*)value, &valueSz) == ERROR_MORE_DATA)
+ {
+ value = new char[valueSz];
+ RegQueryValueExA(jreKey, "JavaHome", NULL, NULL, (BYTE*)value, &valueSz);
+
+ paths << QDir(PathCombine(value, "bin")).absoluteFilePath("java.exe");
+ }
+
+ RegCloseKey(jreKey);
+ }
+ }
+
+ if(paths.length() <= 0)
+ {
+ qWarning() << "Failed to find Java in the Windows registry - defaulting to \"java\"";
+ paths << "java";
+ }
+
+ return paths;
+}
+#elif OSX
+QStringList JavaUtils::FindJavaPath()
+{
+ qWarning() << "OS X Java detection incomplete - defaulting to \"java\"";
+
+ QStringList paths;
+ paths << "java";
+
+ return paths;
+}
+
+#elif LINUX
+QStringList JavaUtils::FindJavaPath()
+{
+ qWarning() << "Linux Java detection incomplete - defaulting to \"java\"";
+
+ QStringList paths;
+ paths << "java";
+
+ return paths;
+}
+#else
+QStringList JavaUtils::FindJavaPath()
+{
+ qWarning() << "Unknown operating system build - defaulting to \"java\"";
+
+ QStringList paths;
+ paths << "java";
+
+ return paths;
+}
+#endif
diff --git a/logic/JavaUtils.h b/logic/JavaUtils.h
new file mode 100644
index 00000000..fef2a1bf
--- /dev/null
+++ b/logic/JavaUtils.h
@@ -0,0 +1,26 @@
+/* Copyright 2013 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 <QStringList>
+
+class JavaUtils
+{
+public:
+ JavaUtils();
+
+ QStringList FindJavaPath();
+};