Merge pull request #1798 from Trial97/java

[Windows] Autodetect Java from the Microsoft Store version of the official launcher
This commit is contained in:
Tayou 2023-11-12 15:39:17 +01:00 committed by GitHub
commit a991d48c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,6 +34,7 @@
*/ */
#include <QDir> #include <QDir>
#include <QFileInfo>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
@ -440,18 +441,26 @@ QStringList getMinecraftJavaBundle()
{ {
QString partialPath; QString partialPath;
QString executable = "java"; QString executable = "java";
QStringList processpaths;
#if defined(Q_OS_OSX) #if defined(Q_OS_OSX)
partialPath = FS::PathCombine(QDir::homePath(), "Library/Application Support"); partialPath = FS::PathCombine(QDir::homePath(), "Library/Application Support");
#elif defined(Q_OS_WIN32) #elif defined(Q_OS_WIN32)
partialPath = QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA", ""); partialPath = QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA", "");
executable += "w.exe"; executable += "w.exe";
// add the microsoft store version of the launcher to the search. the current path is:
// C:\Users\USERNAME\AppData\Local\Packages\Microsoft.4297127D64EC6_8wekyb3d8bbwe\LocalCache\Local\runtime
auto minecraftMSStorePath =
FS::PathCombine(QFileInfo(partialPath).absolutePath(), "Local", "Packages", "Microsoft.4297127D64EC6_8wekyb3d8bbwe");
minecraftMSStorePath = FS::PathCombine(minecraftMSStorePath, "LocalCache", "Local", "runtime");
processpaths << minecraftMSStorePath;
#else #else
partialPath = QDir::homePath(); partialPath = QDir::homePath();
#endif #endif
auto minecraftPath = FS::PathCombine(partialPath, ".minecraft", "runtime"); auto minecraftDataPath = FS::PathCombine(partialPath, ".minecraft", "runtime");
QStringList javas; processpaths << minecraftDataPath;
QStringList processpaths{ minecraftPath };
QStringList javas;
while (!processpaths.isEmpty()) { while (!processpaths.isEmpty()) {
auto dirPath = processpaths.takeFirst(); auto dirPath = processpaths.takeFirst();
QDir dir(dirPath); QDir dir(dirPath);