2022-05-26 22:18:54 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
2023-08-04 18:41:47 +01:00
|
|
|
* Prism Launcher - Minecraft Launcher
|
2022-05-26 22:18:54 +01:00
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
2013-10-05 01:08:13 +01:00
|
|
|
*
|
2022-05-26 22:18:54 +01:00
|
|
|
* 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.
|
2013-10-05 01:08:13 +01:00
|
|
|
*
|
2022-05-26 22:18:54 +01:00
|
|
|
* 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.
|
2013-10-05 01:08:13 +01:00
|
|
|
*
|
2022-05-26 22:18:54 +01:00
|
|
|
* 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.
|
2013-10-05 01:08:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QDir>
|
2023-11-07 08:20:53 +00:00
|
|
|
#include <QFileInfo>
|
2023-08-02 17:35:35 +01:00
|
|
|
#include <QString>
|
2014-01-22 17:28:56 +00:00
|
|
|
#include <QStringList>
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include <settings/Setting.h>
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2015-02-02 01:14:14 +00:00
|
|
|
#include <QDebug>
|
2022-06-14 21:00:24 +01:00
|
|
|
#include "Application.h"
|
2023-08-02 17:35:35 +01:00
|
|
|
#include "FileSystem.h"
|
|
|
|
#include "java/JavaInstallList.h"
|
|
|
|
#include "java/JavaUtils.h"
|
2013-10-05 01:08:13 +01:00
|
|
|
|
2017-08-22 23:23:35 +01:00
|
|
|
#define IBUS "@im=ibus"
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
JavaUtils::JavaUtils() {}
|
2013-10-05 01:08:13 +01:00
|
|
|
|
2022-06-24 16:54:01 +01:00
|
|
|
QString stripVariableEntries(QString name, QString target, QString remove)
|
2017-08-22 23:23:35 +01:00
|
|
|
{
|
2022-06-24 16:54:01 +01:00
|
|
|
char delimiter = ':';
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
delimiter = ';';
|
|
|
|
#endif
|
|
|
|
|
|
|
|
auto targetItems = target.split(delimiter);
|
|
|
|
auto toRemove = remove.split(delimiter);
|
|
|
|
|
|
|
|
for (QString item : toRemove) {
|
|
|
|
bool removed = targetItems.removeOne(item);
|
|
|
|
if (!removed)
|
2023-08-02 17:35:35 +01:00
|
|
|
qWarning() << "Entry" << item << "could not be stripped from variable" << name;
|
2017-08-22 23:23:35 +01:00
|
|
|
}
|
2022-06-24 16:54:01 +01:00
|
|
|
return targetItems.join(delimiter);
|
2017-08-22 23:23:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QProcessEnvironment CleanEnviroment()
|
|
|
|
{
|
|
|
|
// prepare the process environment
|
|
|
|
QProcessEnvironment rawenv = QProcessEnvironment::systemEnvironment();
|
|
|
|
QProcessEnvironment env;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
QStringList ignored = { "JAVA_ARGS", "CLASSPATH", "CONFIGPATH", "JAVA_HOME",
|
|
|
|
"JRE_HOME", "_JAVA_OPTIONS", "JAVA_OPTIONS", "JAVA_TOOL_OPTIONS" };
|
2022-06-24 16:54:01 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
QStringList stripped = {
|
2022-07-09 18:01:29 +01:00
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
|
2022-06-24 16:54:01 +01:00
|
|
|
"LD_LIBRARY_PATH",
|
|
|
|
"LD_PRELOAD",
|
|
|
|
#endif
|
|
|
|
"QT_PLUGIN_PATH",
|
|
|
|
"QT_FONTPATH"
|
|
|
|
};
|
2023-08-02 17:35:35 +01:00
|
|
|
for (auto key : rawenv.keys()) {
|
2017-08-22 23:23:35 +01:00
|
|
|
auto value = rawenv.value(key);
|
|
|
|
// filter out dangerous java crap
|
2023-08-02 17:35:35 +01:00
|
|
|
if (ignored.contains(key)) {
|
2017-08-22 23:23:35 +01:00
|
|
|
qDebug() << "Env: ignoring" << key << value;
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-24 16:54:01 +01:00
|
|
|
|
|
|
|
// These are used to strip the original variables
|
|
|
|
// If there is "LD_LIBRARY_PATH" and "LAUNCHER_LD_LIBRARY_PATH", we want to
|
|
|
|
// remove all values in "LAUNCHER_LD_LIBRARY_PATH" from "LD_LIBRARY_PATH"
|
2023-08-02 17:35:35 +01:00
|
|
|
if (key.startsWith("LAUNCHER_")) {
|
2017-08-22 23:23:35 +01:00
|
|
|
qDebug() << "Env: ignoring" << key << value;
|
|
|
|
continue;
|
|
|
|
}
|
2023-08-02 17:35:35 +01:00
|
|
|
if (stripped.contains(key)) {
|
2022-06-24 16:54:01 +01:00
|
|
|
QString newValue = stripVariableEntries(key, value, rawenv.value("LAUNCHER_" + key));
|
|
|
|
|
|
|
|
qDebug() << "Env: stripped" << key << value << "to" << newValue;
|
2017-08-22 23:23:35 +01:00
|
|
|
}
|
2022-07-09 18:01:29 +01:00
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
|
2017-08-22 23:23:35 +01:00
|
|
|
// Strip IBus
|
|
|
|
// IBus is a Linux IME framework. For some reason, it breaks MC?
|
2023-08-02 17:35:35 +01:00
|
|
|
if (key == "XMODIFIERS" && value.contains(IBUS)) {
|
2017-08-22 23:23:35 +01:00
|
|
|
QString save = value;
|
|
|
|
value.replace(IBUS, "");
|
|
|
|
qDebug() << "Env: stripped" << IBUS << "from" << save << ":" << value;
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-04 02:50:05 +00:00
|
|
|
// qDebug() << "Env: " << key << value;
|
2017-08-22 23:23:35 +01:00
|
|
|
env.insert(key, value);
|
|
|
|
}
|
|
|
|
#ifdef Q_OS_LINUX
|
2022-06-24 16:54:01 +01:00
|
|
|
// HACK: Workaround for QTBUG-42500
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!env.contains("LD_LIBRARY_PATH")) {
|
2017-08-22 23:23:35 +01:00
|
|
|
env.insert("LD_LIBRARY_PATH", "");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return env;
|
|
|
|
}
|
|
|
|
|
2016-01-01 23:35:54 +00:00
|
|
|
JavaInstallPtr JavaUtils::MakeJavaPtr(QString path, QString id, QString arch)
|
2013-12-11 03:54:39 +00:00
|
|
|
{
|
2016-01-01 23:35:54 +00:00
|
|
|
JavaInstallPtr javaVersion(new JavaInstall());
|
2013-12-11 03:54:39 +00:00
|
|
|
|
|
|
|
javaVersion->id = id;
|
|
|
|
javaVersion->arch = arch;
|
|
|
|
javaVersion->path = path;
|
|
|
|
|
|
|
|
return javaVersion;
|
|
|
|
}
|
|
|
|
|
2016-01-01 23:35:54 +00:00
|
|
|
JavaInstallPtr JavaUtils::GetDefaultJava()
|
2013-10-05 01:08:13 +01:00
|
|
|
{
|
2016-01-01 23:35:54 +00:00
|
|
|
JavaInstallPtr javaVersion(new JavaInstall());
|
2013-10-05 01:08:13 +01:00
|
|
|
|
2013-10-14 02:59:21 +01:00
|
|
|
javaVersion->id = "java";
|
|
|
|
javaVersion->arch = "unknown";
|
2017-01-05 13:20:37 +00:00
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
javaVersion->path = "javaw";
|
|
|
|
#else
|
2013-10-14 02:59:21 +01:00
|
|
|
javaVersion->path = "java";
|
2017-01-05 13:20:37 +00:00
|
|
|
#endif
|
2013-10-14 02:59:21 +01:00
|
|
|
|
|
|
|
return javaVersion;
|
2013-10-05 01:08:13 +01:00
|
|
|
}
|
|
|
|
|
2022-01-11 15:20:55 +00:00
|
|
|
QStringList addJavasFromEnv(QList<QString> javas)
|
|
|
|
{
|
2022-10-18 08:01:48 +01:00
|
|
|
auto env = qEnvironmentVariable("PRISMLAUNCHER_JAVA_PATHS"); // FIXME: use launcher name from buildconfig
|
2022-01-11 15:20:55 +00:00
|
|
|
#if defined(Q_OS_WIN32)
|
2022-08-18 22:16:50 +01:00
|
|
|
QList<QString> javaPaths = env.replace("\\", "/").split(QLatin1String(";"));
|
2023-08-02 17:35:35 +01:00
|
|
|
|
2022-08-18 22:16:50 +01:00
|
|
|
auto envPath = qEnvironmentVariable("PATH");
|
|
|
|
QList<QString> javaPathsfromPath = envPath.replace("\\", "/").split(QLatin1String(";"));
|
2022-08-18 17:19:28 +01:00
|
|
|
for (QString string : javaPathsfromPath) {
|
|
|
|
javaPaths.append(string + "/javaw.exe");
|
|
|
|
}
|
2022-01-11 15:20:55 +00:00
|
|
|
#else
|
2022-08-18 22:16:50 +01:00
|
|
|
QList<QString> javaPaths = env.split(QLatin1String(":"));
|
2022-01-11 15:20:55 +00:00
|
|
|
#endif
|
2023-08-02 17:35:35 +01:00
|
|
|
for (QString i : javaPaths) {
|
2022-01-11 15:20:55 +00:00
|
|
|
javas.append(i);
|
|
|
|
};
|
|
|
|
return javas;
|
|
|
|
}
|
|
|
|
|
2016-01-02 00:13:42 +00:00
|
|
|
#if defined(Q_OS_WIN32)
|
2021-06-18 16:02:41 +01:00
|
|
|
QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName, QString keyJavaDir, QString subkeySuffix)
|
2013-10-05 01:08:13 +01:00
|
|
|
{
|
2016-01-01 23:35:54 +00:00
|
|
|
QList<JavaInstallPtr> javas;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2013-10-06 19:54:52 +01:00
|
|
|
QString archType = "unknown";
|
2013-11-04 01:53:05 +00:00
|
|
|
if (keyType == KEY_WOW64_64KEY)
|
|
|
|
archType = "64";
|
|
|
|
else if (keyType == KEY_WOW64_32KEY)
|
|
|
|
archType = "32";
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2013-10-05 01:08:13 +01:00
|
|
|
HKEY jreKey;
|
2023-08-02 17:35:35 +01:00
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName.toStdWString().c_str(), 0, KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) ==
|
|
|
|
ERROR_SUCCESS) {
|
2013-10-06 19:54:52 +01:00
|
|
|
// Read the current type version from the registry.
|
|
|
|
// This will be used to find any key that contains the JavaHome value.
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2022-07-19 10:09:32 +01:00
|
|
|
WCHAR subKeyName[255];
|
2013-10-06 19:54:52 +01:00
|
|
|
DWORD subKeyNameSize, numSubKeys, retCode;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2013-10-06 19:54:52 +01:00
|
|
|
// Get the number of subkeys
|
2023-08-02 17:35:35 +01:00
|
|
|
RegQueryInfoKeyW(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2013-10-06 19:54:52 +01:00
|
|
|
// Iterate until RegEnumKeyEx fails
|
2023-08-02 17:35:35 +01:00
|
|
|
if (numSubKeys > 0) {
|
|
|
|
for (DWORD i = 0; i < numSubKeys; i++) {
|
2013-10-06 19:54:52 +01:00
|
|
|
subKeyNameSize = 255;
|
2023-08-02 17:35:35 +01:00
|
|
|
retCode = RegEnumKeyExW(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL, NULL);
|
2022-05-02 20:34:55 +01:00
|
|
|
QString newSubkeyName = QString::fromWCharArray(subKeyName);
|
2023-08-02 17:35:35 +01:00
|
|
|
if (retCode == ERROR_SUCCESS) {
|
2013-10-06 19:54:52 +01:00
|
|
|
// Now open the registry key for the version that we just got.
|
2022-05-02 20:34:55 +01:00
|
|
|
QString newKeyName = keyName + "\\" + newSubkeyName + subkeySuffix;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2013-10-06 19:54:52 +01:00
|
|
|
HKEY newKey;
|
2023-08-02 17:35:35 +01:00
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, newKeyName.toStdWString().c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &newKey) ==
|
|
|
|
ERROR_SUCCESS) {
|
2013-10-06 19:54:52 +01:00
|
|
|
// Read the JavaHome value to find where Java is installed.
|
2022-07-16 19:08:02 +01:00
|
|
|
DWORD valueSz = 0;
|
2023-08-02 17:35:35 +01:00
|
|
|
if (RegQueryValueExW(newKey, keyJavaDir.toStdWString().c_str(), NULL, NULL, NULL, &valueSz) == ERROR_SUCCESS) {
|
|
|
|
WCHAR* value = new WCHAR[valueSz];
|
|
|
|
RegQueryValueExW(newKey, keyJavaDir.toStdWString().c_str(), NULL, NULL, (BYTE*)value, &valueSz);
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2022-07-11 17:51:32 +01:00
|
|
|
QString newValue = QString::fromWCharArray(value);
|
2023-08-02 17:35:35 +01:00
|
|
|
delete[] value;
|
2022-07-11 17:51:32 +01:00
|
|
|
|
2013-10-14 02:59:21 +01:00
|
|
|
// Now, we construct the version object and add it to the list.
|
2016-01-01 23:35:54 +00:00
|
|
|
JavaInstallPtr javaVersion(new JavaInstall());
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2022-05-02 20:34:55 +01:00
|
|
|
javaVersion->id = newSubkeyName;
|
2013-10-14 02:59:21 +01:00
|
|
|
javaVersion->arch = archType;
|
2023-08-02 17:35:35 +01:00
|
|
|
javaVersion->path = QDir(FS::PathCombine(newValue, "bin")).absoluteFilePath("javaw.exe");
|
2013-10-14 02:59:21 +01:00
|
|
|
javas.append(javaVersion);
|
2013-10-06 19:54:52 +01:00
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2013-10-06 19:54:52 +01:00
|
|
|
RegCloseKey(newKey);
|
|
|
|
}
|
|
|
|
}
|
2013-10-05 01:08:13 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2013-10-06 19:54:52 +01:00
|
|
|
RegCloseKey(jreKey);
|
2013-10-05 01:08:13 +01:00
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2013-10-06 19:54:52 +01:00
|
|
|
return javas;
|
|
|
|
}
|
|
|
|
|
2013-12-12 14:56:32 +00:00
|
|
|
QList<QString> JavaUtils::FindJavaPaths()
|
2013-10-14 02:59:21 +01:00
|
|
|
{
|
2016-01-01 23:35:54 +00:00
|
|
|
QList<JavaInstallPtr> java_candidates;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2021-06-08 18:48:12 +01:00
|
|
|
// Oracle
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<JavaInstallPtr> JRE64s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment", "JavaHome");
|
|
|
|
QList<JavaInstallPtr> JDK64s = this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit", "JavaHome");
|
|
|
|
QList<JavaInstallPtr> JRE32s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment", "JavaHome");
|
|
|
|
QList<JavaInstallPtr> JDK32s = this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit", "JavaHome");
|
2021-06-08 18:48:12 +01:00
|
|
|
|
|
|
|
// Oracle for Java 9 and newer
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<JavaInstallPtr> NEWJRE64s = this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JRE", "JavaHome");
|
|
|
|
QList<JavaInstallPtr> NEWJDK64s = this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\JDK", "JavaHome");
|
|
|
|
QList<JavaInstallPtr> NEWJRE32s = this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\JRE", "JavaHome");
|
|
|
|
QList<JavaInstallPtr> NEWJDK32s = this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\JDK", "JavaHome");
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2021-06-08 18:48:12 +01:00
|
|
|
// AdoptOpenJDK
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<JavaInstallPtr> ADOPTOPENJRE32s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\AdoptOpenJDK\\JRE", "Path", "\\hotspot\\MSI");
|
|
|
|
QList<JavaInstallPtr> ADOPTOPENJRE64s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\AdoptOpenJDK\\JRE", "Path", "\\hotspot\\MSI");
|
|
|
|
QList<JavaInstallPtr> ADOPTOPENJDK32s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\AdoptOpenJDK\\JDK", "Path", "\\hotspot\\MSI");
|
|
|
|
QList<JavaInstallPtr> ADOPTOPENJDK64s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\AdoptOpenJDK\\JDK", "Path", "\\hotspot\\MSI");
|
2021-06-18 16:02:41 +01:00
|
|
|
|
2021-12-11 02:14:00 +00:00
|
|
|
// Eclipse Foundation
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<JavaInstallPtr> FOUNDATIONJDK32s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\Eclipse Foundation\\JDK", "Path", "\\hotspot\\MSI");
|
|
|
|
QList<JavaInstallPtr> FOUNDATIONJDK64s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\Eclipse Foundation\\JDK", "Path", "\\hotspot\\MSI");
|
2021-08-09 17:43:55 +01:00
|
|
|
|
2021-12-11 02:14:00 +00:00
|
|
|
// Eclipse Adoptium
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<JavaInstallPtr> ADOPTIUMJRE32s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\Eclipse Adoptium\\JRE", "Path", "\\hotspot\\MSI");
|
|
|
|
QList<JavaInstallPtr> ADOPTIUMJRE64s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\Eclipse Adoptium\\JRE", "Path", "\\hotspot\\MSI");
|
|
|
|
QList<JavaInstallPtr> ADOPTIUMJDK32s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\Eclipse Adoptium\\JDK", "Path", "\\hotspot\\MSI");
|
|
|
|
QList<JavaInstallPtr> ADOPTIUMJDK64s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\Eclipse Adoptium\\JDK", "Path", "\\hotspot\\MSI");
|
2021-11-08 02:35:43 +00:00
|
|
|
|
2021-06-18 16:02:41 +01:00
|
|
|
// Microsoft
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<JavaInstallPtr> MICROSOFTJDK64s =
|
|
|
|
this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\Microsoft\\JDK", "Path", "\\hotspot\\MSI");
|
2021-06-08 18:48:12 +01:00
|
|
|
|
2021-06-18 16:12:44 +01:00
|
|
|
// Azul Zulu
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<JavaInstallPtr> ZULU64s = this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\Azul Systems\\Zulu", "InstallationPath");
|
|
|
|
QList<JavaInstallPtr> ZULU32s = this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\Azul Systems\\Zulu", "InstallationPath");
|
2022-01-10 17:46:43 +00:00
|
|
|
|
2021-06-18 16:12:44 +01:00
|
|
|
// BellSoft Liberica
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<JavaInstallPtr> LIBERICA64s = this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\BellSoft\\Liberica", "InstallationPath");
|
|
|
|
QList<JavaInstallPtr> LIBERICA32s = this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\BellSoft\\Liberica", "InstallationPath");
|
2021-06-18 16:12:44 +01:00
|
|
|
|
2021-06-08 18:48:12 +01:00
|
|
|
// List x64 before x86
|
2013-12-12 14:56:32 +00:00
|
|
|
java_candidates.append(JRE64s);
|
2021-05-22 12:37:51 +01:00
|
|
|
java_candidates.append(NEWJRE64s);
|
2021-06-08 18:48:12 +01:00
|
|
|
java_candidates.append(ADOPTOPENJRE64s);
|
2021-12-11 02:14:00 +00:00
|
|
|
java_candidates.append(ADOPTIUMJRE64s);
|
2017-01-07 17:11:41 +00:00
|
|
|
java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre8/bin/javaw.exe"));
|
2014-06-27 23:05:00 +01:00
|
|
|
java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre7/bin/javaw.exe"));
|
|
|
|
java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre6/bin/javaw.exe"));
|
2013-12-12 14:56:32 +00:00
|
|
|
java_candidates.append(JDK64s);
|
2021-05-22 12:37:51 +01:00
|
|
|
java_candidates.append(NEWJDK64s);
|
2021-06-08 18:48:12 +01:00
|
|
|
java_candidates.append(ADOPTOPENJDK64s);
|
2021-11-08 02:35:43 +00:00
|
|
|
java_candidates.append(FOUNDATIONJDK64s);
|
|
|
|
java_candidates.append(ADOPTIUMJDK64s);
|
2021-06-18 16:02:41 +01:00
|
|
|
java_candidates.append(MICROSOFTJDK64s);
|
2021-06-18 16:12:44 +01:00
|
|
|
java_candidates.append(ZULU64s);
|
|
|
|
java_candidates.append(LIBERICA64s);
|
2021-06-08 18:48:12 +01:00
|
|
|
|
2013-12-12 14:56:32 +00:00
|
|
|
java_candidates.append(JRE32s);
|
2021-05-22 12:37:51 +01:00
|
|
|
java_candidates.append(NEWJRE32s);
|
2021-06-08 18:48:12 +01:00
|
|
|
java_candidates.append(ADOPTOPENJRE32s);
|
2021-12-11 02:14:00 +00:00
|
|
|
java_candidates.append(ADOPTIUMJRE32s);
|
2017-01-07 17:11:41 +00:00
|
|
|
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre8/bin/javaw.exe"));
|
2014-06-27 23:05:00 +01:00
|
|
|
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre7/bin/javaw.exe"));
|
|
|
|
java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre6/bin/javaw.exe"));
|
2013-12-12 14:56:32 +00:00
|
|
|
java_candidates.append(JDK32s);
|
2021-05-22 12:37:51 +01:00
|
|
|
java_candidates.append(NEWJDK32s);
|
2021-06-08 18:48:12 +01:00
|
|
|
java_candidates.append(ADOPTOPENJDK32s);
|
2021-11-08 02:35:43 +00:00
|
|
|
java_candidates.append(FOUNDATIONJDK32s);
|
|
|
|
java_candidates.append(ADOPTIUMJDK32s);
|
2021-06-18 16:12:44 +01:00
|
|
|
java_candidates.append(ZULU32s);
|
|
|
|
java_candidates.append(LIBERICA32s);
|
2022-01-10 17:46:43 +00:00
|
|
|
|
2013-12-12 15:25:02 +00:00
|
|
|
java_candidates.append(MakeJavaPtr(this->GetDefaultJava()->path));
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2013-12-12 14:56:32 +00:00
|
|
|
QList<QString> candidates;
|
2023-08-02 17:35:35 +01:00
|
|
|
for (JavaInstallPtr java_candidate : java_candidates) {
|
|
|
|
if (!candidates.contains(java_candidate->path)) {
|
2013-12-12 14:56:32 +00:00
|
|
|
candidates.append(java_candidate->path);
|
|
|
|
}
|
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-10-06 06:51:45 +01:00
|
|
|
candidates.append(getMinecraftJavaBundle());
|
2022-10-22 16:19:34 +01:00
|
|
|
candidates = addJavasFromEnv(candidates);
|
|
|
|
candidates.removeDuplicates();
|
|
|
|
return candidates;
|
2013-10-05 01:08:13 +01:00
|
|
|
}
|
2013-12-11 03:54:39 +00:00
|
|
|
|
2016-01-02 00:13:42 +00:00
|
|
|
#elif defined(Q_OS_MAC)
|
2013-12-12 15:04:24 +00:00
|
|
|
QList<QString> JavaUtils::FindJavaPaths()
|
2013-10-05 01:08:13 +01:00
|
|
|
{
|
2013-12-12 15:04:24 +00:00
|
|
|
QList<QString> javas;
|
|
|
|
javas.append(this->GetDefaultJava()->path);
|
2014-01-22 17:28:56 +00:00
|
|
|
javas.append("/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/MacOS/itms/java/bin/java");
|
2014-01-02 16:01:26 +00:00
|
|
|
javas.append("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java");
|
|
|
|
javas.append("/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java");
|
2014-01-22 17:28:56 +00:00
|
|
|
QDir libraryJVMDir("/Library/Java/JavaVirtualMachines/");
|
|
|
|
QStringList libraryJVMJavas = libraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
2023-08-02 17:35:35 +01:00
|
|
|
foreach (const QString& java, libraryJVMJavas) {
|
2014-01-22 17:28:56 +00:00
|
|
|
javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
|
|
|
|
javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/jre/bin/java");
|
|
|
|
}
|
|
|
|
QDir systemLibraryJVMDir("/System/Library/Java/JavaVirtualMachines/");
|
|
|
|
QStringList systemLibraryJVMJavas = systemLibraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
2023-08-02 17:35:35 +01:00
|
|
|
foreach (const QString& java, systemLibraryJVMJavas) {
|
2014-01-22 17:28:56 +00:00
|
|
|
javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
|
|
|
|
javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Commands/java");
|
|
|
|
}
|
2023-10-05 22:21:37 +01:00
|
|
|
javas.append(getMinecraftJavaBundle());
|
2022-10-22 15:40:31 +01:00
|
|
|
javas = addJavasFromEnv(javas);
|
|
|
|
javas.removeDuplicates();
|
|
|
|
return javas;
|
2013-10-05 01:08:13 +01:00
|
|
|
}
|
|
|
|
|
2016-01-02 00:13:42 +00:00
|
|
|
#elif defined(Q_OS_LINUX)
|
2013-12-12 15:04:24 +00:00
|
|
|
QList<QString> JavaUtils::FindJavaPaths()
|
2013-10-05 01:08:13 +01:00
|
|
|
{
|
2013-12-12 15:04:24 +00:00
|
|
|
QList<QString> javas;
|
|
|
|
javas.append(this->GetDefaultJava()->path);
|
2023-08-02 17:35:35 +01:00
|
|
|
auto scanJavaDir = [&](const QString& dirPath) {
|
2017-01-07 17:11:41 +00:00
|
|
|
QDir dir(dirPath);
|
2023-08-02 17:35:35 +01:00
|
|
|
if (!dir.exists())
|
2017-01-07 17:11:41 +00:00
|
|
|
return;
|
2023-02-04 14:48:06 +00:00
|
|
|
auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
2023-08-02 17:35:35 +01:00
|
|
|
for (auto& entry : entries) {
|
2017-01-07 17:11:41 +00:00
|
|
|
QString prefix;
|
2023-02-04 14:48:06 +00:00
|
|
|
prefix = entry.canonicalFilePath();
|
2017-01-07 17:11:41 +00:00
|
|
|
javas.append(FS::PathCombine(prefix, "jre/bin/java"));
|
|
|
|
javas.append(FS::PathCombine(prefix, "bin/java"));
|
|
|
|
}
|
|
|
|
};
|
2022-10-24 19:19:30 +01:00
|
|
|
// java installed in a snap is installed in the standard directory, but underneath $SNAP
|
|
|
|
auto snap = qEnvironmentVariable("SNAP");
|
2023-08-02 17:35:35 +01:00
|
|
|
auto scanJavaDirs = [&](const QString& dirPath) {
|
2022-10-24 19:19:30 +01:00
|
|
|
scanJavaDir(dirPath);
|
|
|
|
if (!snap.isNull()) {
|
|
|
|
scanJavaDir(snap + dirPath);
|
|
|
|
}
|
|
|
|
};
|
2017-01-07 17:11:41 +00:00
|
|
|
// oracle RPMs
|
2022-10-24 19:19:30 +01:00
|
|
|
scanJavaDirs("/usr/java");
|
2017-01-07 17:11:41 +00:00
|
|
|
// general locations used by distro packaging
|
2022-10-24 19:19:30 +01:00
|
|
|
scanJavaDirs("/usr/lib/jvm");
|
|
|
|
scanJavaDirs("/usr/lib64/jvm");
|
|
|
|
scanJavaDirs("/usr/lib32/jvm");
|
2022-10-18 15:37:04 +01:00
|
|
|
// javas stored in Prism Launcher's folder
|
2022-10-24 19:19:30 +01:00
|
|
|
scanJavaDirs("java");
|
2021-06-22 17:56:05 +01:00
|
|
|
// manually installed JDKs in /opt
|
2022-10-24 19:19:30 +01:00
|
|
|
scanJavaDirs("/opt/jdk");
|
|
|
|
scanJavaDirs("/opt/jdks");
|
2021-12-28 15:45:04 +00:00
|
|
|
// flatpak
|
2022-10-24 19:19:30 +01:00
|
|
|
scanJavaDirs("/app/jdk");
|
2023-10-04 20:20:59 +01:00
|
|
|
|
|
|
|
auto home = qEnvironmentVariable("HOME");
|
|
|
|
|
|
|
|
// javas downloaded by IntelliJ
|
|
|
|
scanJavaDirs(FS::PathCombine(home, ".jdks"));
|
|
|
|
// javas downloaded by sdkman
|
|
|
|
scanJavaDirs(FS::PathCombine(home, ".sdkman/candidates/java"));
|
|
|
|
|
2023-10-05 22:21:37 +01:00
|
|
|
javas.append(getMinecraftJavaBundle());
|
2022-10-22 15:40:31 +01:00
|
|
|
javas = addJavasFromEnv(javas);
|
|
|
|
javas.removeDuplicates();
|
|
|
|
return javas;
|
2013-10-05 01:08:13 +01:00
|
|
|
}
|
|
|
|
#else
|
2013-12-12 15:04:24 +00:00
|
|
|
QList<QString> JavaUtils::FindJavaPaths()
|
2013-10-05 01:08:13 +01:00
|
|
|
{
|
2015-02-02 01:14:14 +00:00
|
|
|
qDebug() << "Unknown operating system build - defaulting to \"java\"";
|
2013-10-05 01:08:13 +01:00
|
|
|
|
2013-12-12 15:04:24 +00:00
|
|
|
QList<QString> javas;
|
|
|
|
javas.append(this->GetDefaultJava()->path);
|
2013-10-15 00:30:33 +01:00
|
|
|
|
2023-10-05 22:21:37 +01:00
|
|
|
javas.append(getMinecraftJavaBundle());
|
2022-01-11 15:20:55 +00:00
|
|
|
return addJavasFromEnv(javas);
|
2013-10-05 01:08:13 +01:00
|
|
|
}
|
|
|
|
#endif
|
2022-06-14 21:00:24 +01:00
|
|
|
|
|
|
|
QString JavaUtils::getJavaCheckPath()
|
|
|
|
{
|
|
|
|
return APPLICATION->getJarPath("JavaCheck.jar");
|
|
|
|
}
|
2023-10-05 22:21:37 +01:00
|
|
|
|
|
|
|
QStringList getMinecraftJavaBundle()
|
|
|
|
{
|
|
|
|
QString partialPath;
|
|
|
|
QString executable = "java";
|
2023-11-07 08:20:53 +00:00
|
|
|
QStringList processpaths;
|
2023-10-05 22:21:37 +01:00
|
|
|
#if defined(Q_OS_OSX)
|
|
|
|
partialPath = FS::PathCombine(QDir::homePath(), "Library/Application Support");
|
|
|
|
#elif defined(Q_OS_WIN32)
|
|
|
|
partialPath = QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA", "");
|
|
|
|
executable += "w.exe";
|
2023-11-07 08:20:53 +00:00
|
|
|
|
|
|
|
// add the following to the search
|
|
|
|
// C:\Users\USERNAME\AppData\Local\Packages\Microsoft.4297127D64EC6_8wekyb3d8bbwe\LocalCache\Local\runtime
|
|
|
|
auto minecraftInstaltionPath =
|
|
|
|
FS::PathCombine(QFileInfo(partialPath).absolutePath(), "Local", "Packages", "Microsoft.4297127D64EC6_8wekyb3d8bbwe");
|
|
|
|
minecraftInstaltionPath = FS::PathCombine(minecraftInstaltionPath, "LocalCache", "Local", "runtime");
|
|
|
|
processpaths << minecraftInstaltionPath;
|
2023-10-05 22:21:37 +01:00
|
|
|
#else
|
|
|
|
partialPath = QDir::homePath();
|
|
|
|
#endif
|
2023-11-07 08:20:53 +00:00
|
|
|
auto minecraftDataPath = FS::PathCombine(partialPath, ".minecraft", "runtime");
|
|
|
|
processpaths << minecraftDataPath;
|
2023-10-05 22:21:37 +01:00
|
|
|
|
2023-11-07 08:20:53 +00:00
|
|
|
QStringList javas;
|
2023-10-05 22:21:37 +01:00
|
|
|
while (!processpaths.isEmpty()) {
|
|
|
|
auto dirPath = processpaths.takeFirst();
|
|
|
|
QDir dir(dirPath);
|
|
|
|
if (!dir.exists())
|
|
|
|
continue;
|
|
|
|
auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
auto binFound = false;
|
|
|
|
for (auto& entry : entries) {
|
|
|
|
if (entry.baseName() == "bin") {
|
|
|
|
javas.append(FS::PathCombine(entry.canonicalFilePath(), executable));
|
|
|
|
binFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!binFound) {
|
|
|
|
for (auto& entry : entries) {
|
|
|
|
processpaths << entry.canonicalFilePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return javas;
|
|
|
|
}
|