diff --git a/build.gradle b/build.gradle index 4b57383..866986d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,21 +1,20 @@ plugins { id 'java' - id 'maven-publish' id "com.github.johnrengelman.shadow" version "7.0.0" id "de.undercouch.download" version "4.1.2" } +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 + group = 'com.nexia' -version = '1.0-SNAPSHOT' +version = '1.0.0' repositories { mavenCentral() } dependencies { - testImplementation platform('org.junit:junit-bom:5.9.1') - testImplementation 'org.junit.jupiter:junit-jupiter' - implementation ('org.sharegov:mjson:1.4.1') { transitive false } @@ -33,9 +32,4 @@ shadowJar { exclude('icon.ico') } -build.dependsOn shadowJar -test { - useJUnitPlatform() -} -sourceCompatibility = JavaVersion.VERSION_11 -targetCompatibility = JavaVersion.VERSION_11 +build.dependsOn shadowJar \ No newline at end of file diff --git a/src/main/java/com/nexia/installer/InstallerGUI.java b/src/main/java/com/nexia/installer/InstallerGUI.java index 13c0169..f723353 100644 --- a/src/main/java/com/nexia/installer/InstallerGUI.java +++ b/src/main/java/com/nexia/installer/InstallerGUI.java @@ -11,9 +11,8 @@ public class InstallerGUI extends JFrame { public static InstallerGUI instance; - private InstallerHelper helper = new InstallerHelper(); - public InstallerGUI() { + InstallerHelper helper = new InstallerHelper(); JPanel panel = helper.setPanel(this); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); @@ -46,7 +45,7 @@ public static void load() throws UnsupportedLookAndFeelException, ClassNotFoundE InstallerGUI gui = new InstallerGUI(); gui.updateSize(true); gui.setTitle(Main.BUNDLE.getString("installer.title")); - gui.setIconImage(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemClassLoader().getResource("icon.png"))); + gui.setIconImage(Main.icon); gui.setLocationRelativeTo(null); gui.setVisible(true); } diff --git a/src/main/java/com/nexia/installer/Main.java b/src/main/java/com/nexia/installer/Main.java index 617d730..d28abf0 100644 --- a/src/main/java/com/nexia/installer/Main.java +++ b/src/main/java/com/nexia/installer/Main.java @@ -1,6 +1,7 @@ package com.nexia.installer; import javax.swing.*; +import java.awt.*; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -13,6 +14,8 @@ public class Main { public static OS os = null; + public static Image icon; + public static final ResourceBundle BUNDLE = ResourceBundle.getBundle("lang/installer", Locale.getDefault(), new ResourceBundle.Control() { @Override public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { @@ -44,6 +47,7 @@ public static void main(String[] args) throws UnsupportedLookAndFeelException, C if(System.getProperty("os.name").startsWith("mac")) os = OS.MAC; + icon = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemClassLoader().getResource("icon.png")); InstallerGUI.load(); } diff --git a/src/main/java/com/nexia/installer/game/VersionHandler.java b/src/main/java/com/nexia/installer/game/VersionHandler.java index 62e354b..57e7a3d 100644 --- a/src/main/java/com/nexia/installer/game/VersionHandler.java +++ b/src/main/java/com/nexia/installer/game/VersionHandler.java @@ -1,15 +1,28 @@ package com.nexia.installer.game; + import java.util.ArrayList; import java.util.List; public class VersionHandler { public static List versions = new ArrayList<>(); - public static GameVersion CombatTest8c = new GameVersion("Combat Test 8c", "1.16_combat-6", new Download("9879e6ba375eda28ab8fc3b83ca9febe5c11d54b", (long) 7.463, "https://www.rizecookey.net/dl/file/combat-test-patched/1_16_combat-6.zip")); + public static GameVersion CombatTest8c = new GameVersion("Combat Test 8c", "1.16_combat-6", new Download("f76157734ee0611fbef7d636156f20fa67c34514", 7463, "https://www.rizecookey.net/dl/file/combat-test-patched/1_16_combat-6.zip")); + + public static GameVersion CombatTest8b = new GameVersion("Combat Test 8b", "1.16_combat-5", new Download("9b2b984d635d373564b50803807225c75d7fd447", 7044, "https://launcher.mojang.com/experiments/combat/9b2b984d635d373564b50803807225c75d7fd447/1_16_combat-5.zip")); + + public static GameVersion CombatTest8 = new GameVersion("Combat Test 8", "1.16_combat-4", new Download("b4306b421183bd084b2831bd8d33a5db05ae9f9c", 7046, "https://cdn.discordapp.com/attachments/369990015096455168/947864881028272198/1_16_combat-4.zip")); + + public static GameVersion CombatTest7c = new GameVersion("Combat Test 7c", "1.16_combat-3", new Download("2557b99d95588505e988886220779087d7d6b1e9", 7049, "https://piston-data.mojang.com/experiments/combat/2557b99d95588505e988886220779087d7d6b1e9/1_16_combat-3.zip")); - public static GameVersion CombatTest8b = new GameVersion("Combat Test 8b", "1.16_combat-5", new Download("05b81ee7c117524580c477900277c316d3436e94", (long) 7.044, "https://launcher.mojang.com/experiments/combat/9b2b984d635d373564b50803807225c75d7fd447/1_16_combat-5.zip")); + public static GameVersion CombatTest7b = new GameVersion("Combat Test 7b", "1.16_combat-2", new Download("43266ea8f2c20601d9fb264d5aa85df8052abc9e", 7051, "https://archive.org/download/Combat_Test_7ab/1_16_combat-2.zip")); + public static GameVersion CombatTest7 = new GameVersion("Combat Test 7", "1.16_combat-1", new Download("47bb5be6cb3ba215539ee97dfae66724c73c3dd5", 7045, "https://archive.org/download/Combat_Test_7ab/1_16_combat-1.zip")); - public static GameVersion CombatTest8 = new GameVersion("Combat Test 8", "1.16_combat-4", new Download("d8d9dd198d0a46435c3d1eac75633a387392d793", (long) 7.046, "https://cdn.discordapp.com/attachments/369990015096455168/947864881028272198/1_16_combat-4.zip")); + public static GameVersion CombatTest6 = new GameVersion("Combat Test 6", "1.16_combat-0", new Download("5a8ceec8681ed96ab6ecb9607fb5d19c8a755559", 7049, "https://piston-data.mojang.com/experiments/combat/5a8ceec8681ed96ab6ecb9607fb5d19c8a755559/1_16_combat-0.zip")); + public static GameVersion CombatTest5 = new GameVersion("Combat Test 5", "1.15_combat-6", new Download("52263d42a626b40c947e523128f7a195ec5af76a", 7061, "https://piston-data.mojang.com/experiments/combat/52263d42a626b40c947e523128f7a195ec5af76a/1_15_combat-6.zip")); + public static GameVersion CombatTest4 = new GameVersion("Combat Test 4", "1.15_combat-1", new Download("ac11ea96f3bb2fa2b9b76ab1d20cacb1b1f7ef60", 7059, "https://piston-data.mojang.com/experiments/combat/ac11ea96f3bb2fa2b9b76ab1d20cacb1b1f7ef60/1_15_combat-1.zip")); + public static GameVersion CombatTest3 = new GameVersion("Combat Test 3", "1.14_combat-3", new Download("0f209c9c84b81c7d4c88b4632155b9ae550beb89", 6433, "https://piston-data.mojang.com/experiments/combat/0f209c9c84b81c7d4c88b4632155b9ae550beb89/1_14_combat-3.zip")); + public static GameVersion CombatTest2 = new GameVersion("Combat Test 2", "1.14_combat-0", new Download("d164bb6ecc5fca9ac02878c85f11befae61ac1ca", 6287, "https://piston-data.mojang.com/experiments/combat/d164bb6ecc5fca9ac02878c85f11befae61ac1ca/1_14_combat-0.zip")); + public static GameVersion CombatTest1 = new GameVersion("1.14.3 - Combat Test", "1.14_combat-212796", new Download("610f5c9874ba8926d5ae1bcce647e5f0e6e7c889",4843, "https://piston-data.mojang.com/experiments/combat/610f5c9874ba8926d5ae1bcce647e5f0e6e7c889/1_14_combat-212796.zip")); public static class GameVersion { String version; diff --git a/src/main/java/com/nexia/installer/util/InstallerUtils.java b/src/main/java/com/nexia/installer/util/InstallerUtils.java index 407f2a5..1cd2f81 100644 --- a/src/main/java/com/nexia/installer/util/InstallerUtils.java +++ b/src/main/java/com/nexia/installer/util/InstallerUtils.java @@ -4,18 +4,17 @@ import com.nexia.installer.game.VersionHandler; import javax.swing.*; +import java.awt.*; import java.io.File; +import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.FileAttribute; -import java.nio.file.attribute.FileAttributeView; -import java.nio.file.attribute.PosixFilePermission; -import java.nio.file.attribute.PosixFilePermissions; +import java.text.MessageFormat; import java.util.List; -import java.util.Set; public class InstallerUtils { public static Path findDefaultInstallDir() { @@ -73,20 +72,31 @@ public static void install(Path mcDir, VersionHandler.GameVersion gameVersion) { String alternativeCodeName = gameVersion.getCodeName().replaceAll("\\.", "_"); + System.out.println("Installing " + gameVersion.getVersion() + " (" + gameVersion.getCodeName() + ")"); + Path versionsDir = mcDir.resolve("versions"); - Path profileDir = versionsDir.resolve(alternativeCodeName); - Path profileJson = profileDir.resolve(alternativeCodeName + ".json"); + Path profileDir = versionsDir.resolve(gameVersion.getCodeName()); + Path profileJson = profileDir.resolve(gameVersion.getCodeName() + ".json"); - if (!Files.exists(profileDir)) { - Files.createDirectory(profileDir); - Files.createFile(profileJson); - } + Path aProfileDir = versionsDir.resolve(alternativeCodeName); + Path aProfileJson = aProfileDir.resolve(alternativeCodeName + ".json"); + + if(!Files.exists(profileDir)) Files.createDirectory(profileDir); + if(!Files.exists(profileJson)) Files.createFile(profileJson); + + if(!Files.exists(aProfileDir)) Files.createDirectory(aProfileDir); + if(!Files.exists(aProfileJson)) Files.createFile(aProfileJson); File zipFile = new File(versionsDir + "/" + gameVersion.getCodeName() + ".zip"); Utils.downloadFile(URI.create(gameVersion.getDownload().url).toURL(), zipFile.toPath()); Utils.extractZip(zipFile.toPath(), versionsDir); + Files.copy(aProfileJson, profileJson, StandardCopyOption.REPLACE_EXISTING); + + + aProfileJson.toFile().delete(); + aProfileDir.toFile().delete(); zipFile.delete(); if (InstallerHelper.createProfile.isSelected()) { @@ -96,6 +106,7 @@ public static void install(Path mcDir, VersionHandler.GameVersion gameVersion) { profileInstaller.setupProfile(gameVersion.getCodeName(), gameVersion.getVersion(), launcherType); } + showDone(gameVersion); } catch (Exception e) { e.printStackTrace(); } finally { @@ -123,4 +134,19 @@ private static ProfileInstaller.LauncherType showLauncherTypeSelection() { return result == JOptionPane.YES_OPTION ? ProfileInstaller.LauncherType.MICROSOFT_STORE : ProfileInstaller.LauncherType.WIN32; } + + private static void showDone(VersionHandler.GameVersion gameVersion) throws URISyntaxException, IOException { + Object[] options = {"OK", "Install Fabric"}; + int result = JOptionPane.showOptionDialog(null, + MessageFormat.format(Main.BUNDLE.getString("installer.prompt.install.done"), gameVersion.getVersion()), + Main.BUNDLE.getString("installer.title"), + JOptionPane.YES_NO_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + options, + options[0] + ); + + if(result == JOptionPane.NO_OPTION && Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) Desktop.getDesktop().browse(new URI("https://github.com/rizecookey/fabric-installer/releases")); + } } diff --git a/src/main/java/com/nexia/installer/util/ProfileInstaller.java b/src/main/java/com/nexia/installer/util/ProfileInstaller.java index 06609fe..9d73d40 100644 --- a/src/main/java/com/nexia/installer/util/ProfileInstaller.java +++ b/src/main/java/com/nexia/installer/util/ProfileInstaller.java @@ -58,16 +58,14 @@ public void setupProfile(String name, String gameVersion, LauncherType launcherT jsonObject.set("profiles", profiles); } - String profileName = "pending " + name; - - Json profile = profiles.at(profileName); + Json profile = profiles.at(name); if (profile == null) { profile = createProfile(gameVersion); - profiles.set(profileName, profile); + profiles.set(name, profile); } - profile.set("lastVersionId", profileName); + profile.set("lastVersionId", name); Utils.writeToFile(launcherProfiles, jsonObject.toString()); } diff --git a/src/main/java/com/nexia/installer/util/Utils.java b/src/main/java/com/nexia/installer/util/Utils.java index 3bcbb62..6539ed3 100644 --- a/src/main/java/com/nexia/installer/util/Utils.java +++ b/src/main/java/com/nexia/installer/util/Utils.java @@ -20,13 +20,8 @@ public class Utils { public static final DateFormat ISO_8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); - public static String readString(URL url) throws IOException { - try (InputStream is = openUrl(url)) { - return readString(is); - } - } - public static File extractZip(Path file, Path path) throws IOException { + public static void extractZip(Path file, Path path) throws IOException { ZipInputStream zipIn = new ZipInputStream(Files.newInputStream(Paths.get(file.toString()))); ZipEntry entry = zipIn.getNextEntry(); String filePath = ""; @@ -50,33 +45,12 @@ public static File extractZip(Path file, Path path) throws IOException { entry = zipIn.getNextEntry(); } zipIn.close(); - return new File(filePath); } public static String readString(Path path) throws IOException { return new String(Files.readAllBytes(path), StandardCharsets.UTF_8); } - public static String readString(InputStream is) throws IOException { - byte[] data = new byte[Math.max(1000, is.available())]; - int offset = 0; - int len; - - while ((len = is.read(data, offset, data.length - offset)) >= 0) { - offset += len; - - if (offset == data.length) { - int next = is.read(); - if (next < 0) break; - - data = Arrays.copyOf(data, data.length * 2); - data[offset++] = (byte) next; - } - } - - return new String(data, 0, offset, StandardCharsets.UTF_8); - } - public static void writeToFile(Path path, String string) throws IOException { Files.write(path, string.getBytes(StandardCharsets.UTF_8)); } diff --git a/src/main/resources/lang/installer.properties b/src/main/resources/lang/installer.properties index c4f0ec5..2ccf6d1 100644 --- a/src/main/resources/lang/installer.properties +++ b/src/main/resources/lang/installer.properties @@ -1,6 +1,7 @@ installer.prompt.game.version=Minecraft Version: installer.prompt.select.location=Select Install Location: installer.button.install=Install +installer.prompt.install.done={0} has been installed, if you want to install fabric then click on the "Install Fabric" button. installer.exception.no.launcher.directory=No launcher directory found! installer.prompt.launcher.type.body=The Combat Test Installer has detected 2 different installations of the Minecraft Launcher, which launcher do you wish to install Fabric to?\n\n- Select Microsoft Store if you are playing Minecraft through the Xbox App or the Windows Store.\n- Select Standalone if you downloaded the Minecraft launcher directly from the Minecraft.net website.\n\nIf you are unsure try the Microsoft Store option first, you can always re-run the installer. installer.prompt.launcher.type.xbox=Microsoft Store / Xbox