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