Merge branch 'develop' of https://github.com/Drayshak/MultiMC5 into develop

This commit is contained in:
Petr Mrázek 2013-10-06 02:22:18 +02:00
commit 9cef16a47d
7 changed files with 202 additions and 14 deletions

View File

@ -1,7 +1,9 @@
cmake_minimum_required(VERSION 2.8.9) cmake_minimum_required(VERSION 2.8.9)
IF(WIN32)
# In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows # In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows
cmake_policy(SET CMP0020 OLD) cmake_policy(SET CMP0020 OLD)
ENDIF()
project(MultiMC) project(MultiMC)
@ -308,6 +310,9 @@ logic/tasks/ProgressProvider.h
logic/tasks/Task.h logic/tasks/Task.h
logic/tasks/Task.cpp logic/tasks/Task.cpp
# Utilities
logic/JavaUtils.h
logic/JavaUtils.cpp
) )

View File

@ -1,7 +1,9 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
IF(WIN32)
# In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows # In Qt 5.1+ we have our own main() function, don't autolink to qtmain on Windows
cmake_policy(SET CMP0020 OLD) cmake_policy(SET CMP0020 OLD)
ENDIF()
project(unpack200) project(unpack200)

View File

@ -13,10 +13,11 @@
* limitations under the License. * limitations under the License.
*/ */
#include <MultiMC.h>
#include "settingsdialog.h" #include "settingsdialog.h"
#include "ui_settingsdialog.h" #include "ui_settingsdialog.h"
#include "logic/JavaUtils.h"
#include <MultiMC.h>
#include <settingsobject.h> #include <settingsobject.h>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
@ -180,3 +181,20 @@ void SettingsDialog::loadSettings(SettingsObject *s)
ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString()); ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString());
ui->postExitCmdTextBox->setText(s->get("PostExitCommand").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);
}
}

View File

@ -53,6 +53,10 @@ private slots:
void on_buttonBox_accepted(); void on_buttonBox_accepted();
void on_pushButton_clicked();
void on_btnBrowse_clicked();
private: private:
Ui::SettingsDialog *ui; Ui::SettingsDialog *ui;
}; };

View File

@ -33,7 +33,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="generalTab"> <widget class="QWidget" name="generalTab">
<attribute name="title"> <attribute name="title">
@ -379,26 +379,45 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="2" column="0">
<widget class="QLineEdit" name="javaPathTextBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelJVMArgs"> <widget class="QLabel" name="labelJVMArgs">
<property name="text"> <property name="text">
<string>JVM arguments:</string> <string>JVM arguments:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <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>Browse...</string>
</property>
</widget>
</item>
<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"> <widget class="QPushButton" name="pushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Auto-detect</string> <string>Auto-detect</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="jvmArgsTextBox"/>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

114
logic/JavaUtils.cpp Normal file
View File

@ -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

26
logic/JavaUtils.h Normal file
View File

@ -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();
};