Skip to content

Commit

Permalink
Merge remote-tracking branch 'iris/master', release 1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Justsnoopy30 committed Nov 6, 2021
2 parents 624b18c + bcafffb commit ca3018b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {
implementation 'org.slf4j:slf4j-log4j12:1.7.32'
implementation "com.jcraft:jsch:0.1.55"

implementation "net.fabricmc:fabric-installer:0.7.4"
implementation "net.fabricmc:fabric-installer:0.9.0"
}

application {
Expand All @@ -46,7 +46,7 @@ class FileOutput extends DefaultTask {
File output
}

def bootstrapVersion = "0.1.2"
def bootstrapVersion = "0.2.0"
def bootstrapArch = "i686"

task downloadBootstrap(type: Download) {
Expand Down Expand Up @@ -99,4 +99,4 @@ tasks.withType(JavaCompile).configureEach {
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetVersion
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx1G

# Version and packaging info
version=1.2.2
version=1.2.3
maven_group=net.hypercubemc
archives_base_name=Universe-Installer

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ public void start() {
installDirectoryPanel.add(installDirectoryPicker);

useCustomLoaderCheckbox = new JCheckBox("Use Custom Loader (Recommended)", config.shouldUseCustomLoader());
useCustomLoaderCheckbox.setToolTipText("If you do not know what this does, leave it checked.");
useCustomLoaderCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
useCustomLoaderCheckbox.setAlignmentX(Component.CENTER_ALIGNMENT);
useCustomLoaderCheckbox.addActionListener(e -> {
config.setUseCustomLoader(useCustomLoaderCheckbox.isSelected());
config.setUseCustomLoader(useCustomLoaderCheckbox.isSelected());
readyAll();
});

Expand Down Expand Up @@ -246,7 +247,11 @@ public void start() {
try {
URL customLoaderVersionUrl = new URL("https://raw.githubusercontent.com/HyperCubeMC/Universe-Installer-Maven/master/latest-loader");
String loaderVersion = useCustomLoader ? Utils.readTextFile(customLoaderVersionUrl) : Main.LOADER_META.getLatestVersion(false).getVersion();
VanillaLauncherIntegration.installToLauncher(getVanillaGameDir(), getInstallDir(), useCustomLoader ? selectedEdition.displayName : "Fabric Loader " + selectedVersion, selectedVersion, loaderName, loaderVersion, useCustomLoader ? VanillaLauncherIntegration.Icon.UNIVERSE : VanillaLauncherIntegration.Icon.FABRIC);
boolean success = VanillaLauncherIntegration.installToLauncher(getVanillaGameDir(), getInstallDir(), useCustomLoader ? selectedEdition.displayName : "Fabric Loader " + selectedVersion, selectedVersion, loaderName, loaderVersion, useCustomLoader ? VanillaLauncherIntegration.Icon.UNIVERSE : VanillaLauncherIntegration.Icon.FABRIC);
if (!success) {
System.out.println("Failed to install to launcher, canceling!");
return;
}
} catch (IOException e) {
System.out.println("Failed to install version and profile to vanilla launcher!");
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
package net.hypercubemc.universe_installer;

import net.fabricmc.installer.client.ProfileInstaller;
import net.fabricmc.installer.util.Reference;
import net.fabricmc.installer.util.Utils;
import org.json.JSONObject;

import javax.swing.*;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

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

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

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

private static void installProfile(Path mcDir, Path instanceDir, String profileName, String versionId, Icon icon) throws IOException {
Path launcherProfiles = mcDir.resolve("launcher_profiles.json");
private static void installProfile(Path mcDir, Path instanceDir, String profileName, String versionId, Icon icon, ProfileInstaller.LauncherType launcherType) throws IOException {
Path launcherProfiles = mcDir.resolve(launcherType.profileJsonName);
if (!Files.exists(launcherProfiles)) {
System.out.println("Could not find launcher_profiles");
return;
Expand Down Expand Up @@ -130,6 +140,43 @@ private static String getProfileIcon(Icon icon) {
}
}


private static ProfileInstaller.LauncherType showLauncherTypeSelection() {
String[] options = new String[]{Utils.BUNDLE.getString("prompt.launcher.type.xbox"), Utils.BUNDLE.getString("prompt.launcher.type.win32")};
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]);
if (result == JOptionPane.CLOSED_OPTION) {
return null;
} else {
return result == JOptionPane.YES_OPTION ? ProfileInstaller.LauncherType.MICROSOFT_STORE : ProfileInstaller.LauncherType.WIN32;
}
}

public static ProfileInstaller.LauncherType getLauncherType(Path vanillaGameDir) {
ProfileInstaller.LauncherType launcherType;
List<ProfileInstaller.LauncherType> types = getInstalledLauncherTypes(vanillaGameDir);
if (types.size() == 0) {
// Default to WIN32, since nothing will happen anyway
System.out.println("No launchers found, profile installation will not take place!");
launcherType = ProfileInstaller.LauncherType.WIN32;
} else if (types.size() == 1) {
System.out.println("Found only one launcher (" + types.get(0) + "), will proceed with that!");
launcherType = types.get(0);
} else {
System.out.println("Multiple launchers found, showing selection screen!");
launcherType = showLauncherTypeSelection();
if (launcherType == null) {
System.out.println(Utils.BUNDLE.getString("prompt.ready.install"));
launcherType = ProfileInstaller.LauncherType.WIN32;
}
}

return launcherType;
}

public static List<ProfileInstaller.LauncherType> getInstalledLauncherTypes(Path mcDir) {
return Arrays.stream(ProfileInstaller.LauncherType.values()).filter((launcherType) -> Files.exists(mcDir.resolve(launcherType.profileJsonName))).collect(Collectors.toList());
}

public enum Icon {
UNIVERSE,
FABRIC
Expand Down

0 comments on commit ca3018b

Please sign in to comment.