diff --git a/launcher/java/JavaInstallList.cpp b/launcher/java/JavaInstallList.cpp index 07f2bd8cb..a0a608713 100644 --- a/launcher/java/JavaInstallList.cpp +++ b/launcher/java/JavaInstallList.cpp @@ -120,8 +120,8 @@ void JavaInstallList::updateListData(QList versions) bool sortJavas(BaseVersionPtr left, BaseVersionPtr right) { - auto rleft = std::dynamic_pointer_cast(left); - auto rright = std::dynamic_pointer_cast(right); + auto rleft = std::dynamic_pointer_cast(right); + auto rright = std::dynamic_pointer_cast(left); return (*rleft) > (*rright); } diff --git a/launcher/java/JavaUtils.cpp b/launcher/java/JavaUtils.cpp index b5b1fd082..6e5dfeaed 100644 --- a/launcher/java/JavaUtils.cpp +++ b/launcher/java/JavaUtils.cpp @@ -149,6 +149,21 @@ JavaInstallPtr JavaUtils::GetDefaultJava() return javaVersion; } +QStringList addJavasFromEnv(QList javas) +{ + QByteArray env = qgetenv("POLYMC_JAVA_PATHS"); +#if defined(Q_OS_WIN32) + QList javaPaths = QString::fromLocal8Bit(env).split(QLatin1String(";")); +#else + QList javaPaths = QString::fromLocal8Bit(env).split(QLatin1String(":")); +#endif + for(QString i : javaPaths) + { + javas.append(i); + }; + return javas; +} + #if defined(Q_OS_WIN32) QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName, QString keyJavaDir, QString subkeySuffix) { @@ -363,7 +378,7 @@ QList JavaUtils::FindJavaPaths() javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java"); javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Commands/java"); } - return javas; + return addJavasFromEnv(javas); } #elif defined(Q_OS_LINUX) @@ -409,7 +424,7 @@ QList JavaUtils::FindJavaPaths() scanJavaDir("/opt/jdks"); // flatpak scanJavaDir("/app/jdk"); - return javas; + return addJavasFromEnv(javas); } #else QList JavaUtils::FindJavaPaths() @@ -419,6 +434,6 @@ QList JavaUtils::FindJavaPaths() QList javas; javas.append(this->GetDefaultJava()->path); - return javas; + return addJavasFromEnv(javas); } #endif