Skip to content

Commit

Permalink
Merge pull request #1798 from Trial97/java
Browse files Browse the repository at this point in the history
[Windows] Autodetect Java from the Microsoft Store version of the official launcher
  • Loading branch information
TayouVR committed Nov 12, 2023
2 parents 94d67b8 + 7313630 commit a991d48
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions launcher/java/JavaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

#include <QDir>
#include <QFileInfo>
#include <QString>
#include <QStringList>

Expand Down Expand Up @@ -440,18 +441,26 @@ QStringList getMinecraftJavaBundle()
{
QString partialPath;
QString executable = "java";
QStringList processpaths;
#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";

// 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
partialPath = QDir::homePath();
#endif
auto minecraftPath = FS::PathCombine(partialPath, ".minecraft", "runtime");
QStringList javas;
QStringList processpaths{ minecraftPath };
auto minecraftDataPath = FS::PathCombine(partialPath, ".minecraft", "runtime");
processpaths << minecraftDataPath;

QStringList javas;
while (!processpaths.isEmpty()) {
auto dirPath = processpaths.takeFirst();
QDir dir(dirPath);
Expand Down

0 comments on commit a991d48

Please sign in to comment.