Skip to content

Commit 2820780

Browse files
author
IMS
authored
Microsoft Store launcher support (IrisShaders#15)
* Experimental game pass support * Only run the Microsoft Store check on Windows * Misc fixes, update to 2.0.1 * Log launcher installed * Finalize some code, add better logging * Clean code, remove redundant cast * Fix more issues * Fix even more issues Made installToLauncher a boolean so we can pass the success result. * Fix punctuation, use enum
1 parent c07648e commit 2820780

4 files changed

Lines changed: 62 additions & 11 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies {
2424
implementation "org.json:json:20210307"
2525
implementation "com.formdev:flatlaf:1.1.2"
2626

27-
implementation "net.fabricmc:fabric-installer:0.7.3"
27+
implementation "net.fabricmc:fabric-installer:0.9.0"
2828
}
2929

3030
application {
@@ -36,7 +36,7 @@ class FileOutput extends DefaultTask {
3636
File output
3737
}
3838

39-
def bootstrapVersion = "0.1.2"
39+
def bootstrapVersion = "0.2.0"
4040
def bootstrapArch = "i686"
4141

4242
task downloadBootstrap(type: Download) {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
org.gradle.jvmargs=-Xmx1G
33

44
# Version and packaging info
5-
version=2.0.0
5+
version=2.0.1
66
maven_group=net.hypercubemc
77
archives_base_name=Iris-Installer
88

src/main/java/net/hypercubemc/iris_installer/Installer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ public void start() {
215215
try {
216216
URL loaderVersionUrl = new URL("https://raw.githubusercontent.com/IrisShaders/Iris-Installer-Maven/master/latest-loader");
217217
String loaderVersion = installAsMod ? Main.LOADER_META.getLatestVersion(false).getVersion() : Utils.readTextFile(loaderVersionUrl);
218-
VanillaLauncherIntegration.installToLauncher(getVanillaGameDir(), getInstallDir(), installAsMod ? "Fabric Loader " + selectedVersion : selectedEditionDisplayName, selectedVersion, loaderName, loaderVersion, installAsMod ? VanillaLauncherIntegration.Icon.FABRIC: VanillaLauncherIntegration.Icon.IRIS);
218+
boolean success = VanillaLauncherIntegration.installToLauncher(getVanillaGameDir(), getInstallDir(), installAsMod ? "Fabric Loader " + selectedVersion : selectedEditionDisplayName, selectedVersion, loaderName, loaderVersion, installAsMod ? VanillaLauncherIntegration.Icon.FABRIC: VanillaLauncherIntegration.Icon.IRIS);
219+
if (!success) {
220+
System.out.println("Failed to install to launcher, canceling!");
221+
return;
222+
}
219223
} catch (IOException e) {
220224
System.out.println("Failed to install version and profile to vanilla launcher!");
221225
e.printStackTrace();

src/main/java/net/hypercubemc/iris_installer/VanillaLauncherIntegration.java

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
package net.hypercubemc.iris_installer;
22

3+
import net.fabricmc.installer.client.ProfileInstaller;
34
import net.fabricmc.installer.util.Reference;
45
import net.fabricmc.installer.util.Utils;
56
import org.json.JSONObject;
67

8+
import javax.swing.*;
79
import java.io.IOException;
810
import java.io.InputStream;
911
import java.net.URL;
1012
import java.nio.file.Files;
1113
import java.nio.file.Path;
1214
import java.util.*;
15+
import java.util.List;
16+
import java.util.stream.Collectors;
1317

1418
public class VanillaLauncherIntegration {
15-
public static void installToLauncher(Path vanillaGameDir, Path instanceDir, String profileName, String gameVersion, String loaderName, String loaderVersion, Icon icon) throws IOException {
19+
public static boolean installToLauncher(Path vanillaGameDir, Path instanceDir, String profileName, String gameVersion, String loaderName, String loaderVersion, Icon icon) throws IOException {
1620
String versionId = String.format("%s-%s-%s", loaderName, loaderVersion, gameVersion);
1721

18-
installVersion(vanillaGameDir, gameVersion, loaderName, loaderVersion);
19-
installProfile(vanillaGameDir, instanceDir, profileName, versionId, icon);
22+
ProfileInstaller.LauncherType launcherType = System.getProperty("os.name").contains("Windows") ? getLauncherType(vanillaGameDir) : /* Return standalone if we aren't on Windows.*/ ProfileInstaller.LauncherType.WIN32;
23+
if (launcherType == null) {
24+
// The installation has been canceled via closing the window, most likely.
25+
return false;
26+
}
27+
installVersion(vanillaGameDir, gameVersion, loaderName, loaderVersion, launcherType);
28+
installProfile(vanillaGameDir, instanceDir, profileName, versionId, icon, launcherType);
29+
return true;
2030
}
2131

22-
public static void installVersion(Path mcDir, String gameVersion, String loaderName, String loaderVersion) throws IOException {
23-
System.out.println("Installing " + gameVersion + " with fabric " + loaderVersion);
32+
public static void installVersion(Path mcDir, String gameVersion, String loaderName, String loaderVersion, ProfileInstaller.LauncherType launcherType) throws IOException {
33+
System.out.println("Installing " + gameVersion + " with fabric " + loaderVersion + " to launcher " + launcherType);
2434
String versionId = String.format("%s-%s-%s", loaderName, loaderVersion, gameVersion);
2535
Path versionsDir = mcDir.resolve("versions");
2636
Path profileDir = versionsDir.resolve(versionId);
@@ -36,8 +46,8 @@ public static void installVersion(Path mcDir, String gameVersion, String loaderN
3646
Utils.downloadFile(profileUrl, profileJson);
3747
}
3848

39-
private static void installProfile(Path mcDir, Path instanceDir, String profileName, String versionId, Icon icon) throws IOException {
40-
Path launcherProfiles = mcDir.resolve("launcher_profiles.json");
49+
private static void installProfile(Path mcDir, Path instanceDir, String profileName, String versionId, Icon icon, ProfileInstaller.LauncherType launcherType) throws IOException {
50+
Path launcherProfiles = mcDir.resolve(launcherType.profileJsonName);
4151
if (!Files.exists(launcherProfiles)) {
4252
System.out.println("Could not find launcher_profiles");
4353
return;
@@ -129,6 +139,43 @@ private static String getProfileIcon(Icon icon) {
129139
}
130140
}
131141

142+
143+
private static ProfileInstaller.LauncherType showLauncherTypeSelection() {
144+
String[] options = new String[]{Utils.BUNDLE.getString("prompt.launcher.type.xbox"), Utils.BUNDLE.getString("prompt.launcher.type.win32")};
145+
int result = JOptionPane.showOptionDialog(null, Utils.BUNDLE.getString("prompt.launcher.type.body"), Utils.BUNDLE.getString("installer.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
146+
if (result == JOptionPane.CLOSED_OPTION) {
147+
return null;
148+
} else {
149+
return result == JOptionPane.YES_OPTION ? ProfileInstaller.LauncherType.MICROSOFT_STORE : ProfileInstaller.LauncherType.WIN32;
150+
}
151+
}
152+
153+
public static ProfileInstaller.LauncherType getLauncherType(Path vanillaGameDir) {
154+
ProfileInstaller.LauncherType launcherType;
155+
List<ProfileInstaller.LauncherType> types = getInstalledLauncherTypes(vanillaGameDir);
156+
if (types.size() == 0) {
157+
// Default to WIN32, since nothing will happen anyway
158+
System.out.println("No launchers found, profile installation will not take place!");
159+
launcherType = ProfileInstaller.LauncherType.WIN32;
160+
} else if (types.size() == 1) {
161+
System.out.println("Found only one launcher (" + types.get(0) + "), will proceed with that!");
162+
launcherType = types.get(0);
163+
} else {
164+
System.out.println("Multiple launchers found, showing selection screen!");
165+
launcherType = showLauncherTypeSelection();
166+
if (launcherType == null) {
167+
System.out.println(Utils.BUNDLE.getString("prompt.ready.install"));
168+
launcherType = ProfileInstaller.LauncherType.WIN32;
169+
}
170+
}
171+
172+
return launcherType;
173+
}
174+
175+
public static List<ProfileInstaller.LauncherType> getInstalledLauncherTypes(Path mcDir) {
176+
return Arrays.stream(ProfileInstaller.LauncherType.values()).filter((launcherType) -> Files.exists(mcDir.resolve(launcherType.profileJsonName))).collect(Collectors.toList());
177+
}
178+
132179
public enum Icon {
133180
IRIS,
134181
FABRIC

0 commit comments

Comments
 (0)