diff --git a/client/src/main/java/com/fox2code/foxloader/loader/ClientModLoader.java b/client/src/main/java/com/fox2code/foxloader/loader/ClientModLoader.java index 1f43322..b0200ea 100644 --- a/client/src/main/java/com/fox2code/foxloader/loader/ClientModLoader.java +++ b/client/src/main/java/com/fox2code/foxloader/loader/ClientModLoader.java @@ -14,9 +14,7 @@ import net.minecraft.src.client.gui.StringTranslate; import java.io.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Properties; +import java.util.*; import java.util.function.Function; public final class ClientModLoader extends Mod { @@ -29,6 +27,7 @@ public final class ClientModLoader extends Mod { public static void launchModdedClient(String... args) { ModLoader.foxLoader.clientMod = new ClientModLoader(); ModLoader.foxLoader.clientMod.modContainer = ModLoader.foxLoader; + Objects.requireNonNull(ModLoader.foxLoader.getMod(), "WTF???"); ModLoader.initializeModdedInstance(true); Platform.getPlatform().setupLwjgl2(); ClientSelfTest.selfTest(); @@ -84,6 +83,7 @@ void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOExceptio File dest = null; String[] args; LauncherType launcherType = FoxLauncher.getLauncherType(); + getLogger().info("Updating to " + version + " from " + launcherType + " launcher"); switch (launcherType) { default: return; @@ -92,7 +92,7 @@ void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOExceptio dest = new File(libraries, "foxloader-" + version + ".jar"); case BETA_CRAFT: case VANILLA_LIKE: - args = new String[]{null, "--update", launcherType.name()}; + args = new String[]{null, "-jar", null, "--update", launcherType.name()}; } if (dest == null) { if (!ModLoader.updateTmp.exists() && !ModLoader.updateTmp.mkdirs()) { @@ -104,8 +104,26 @@ void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOExceptio try (FileOutputStream fileOutputStream = new FileOutputStream(dest)) { NetUtils.downloadTo(url, fileOutputStream); } - args[0] = dest.getAbsolutePath(); - new ProcessBuilder(args).inheritIO().directory(ModLoader.updateTmp).start(); + args[0] = Platform.getPlatform().javaBin.getPath(); + args[2] = dest.getAbsolutePath(); + getLogger().info("Command: " + Arrays.toString(args)); + final Process process = new ProcessBuilder(args).directory(dest.getParentFile()).start(); + if (process.isAlive()) { + new Thread(() -> { + Scanner scanner = new Scanner(process.getInputStream()); + String line; + while (process.isAlive() && + (line = scanner.next()) != null) { + System.out.println("Update: " + line); + Thread.yield(); + } + if (!process.isAlive()) { + System.out.println("Updated with exit code " + process.exitValue()); + } + }, "Output log thread"); + } else { + System.out.println("Updated with exit code " + process.exitValue()); + } } public static class Internal { diff --git a/common/src/main/java/com/fox2code/foxloader/launcher/utils/Platform.java b/common/src/main/java/com/fox2code/foxloader/launcher/utils/Platform.java index 28d45e3..fd9304c 100644 --- a/common/src/main/java/com/fox2code/foxloader/launcher/utils/Platform.java +++ b/common/src/main/java/com/fox2code/foxloader/launcher/utils/Platform.java @@ -9,9 +9,9 @@ import java.util.Locale; public enum Platform { - WINDOWS(new String[]{"lwjgl.dll", "lwjgl64.dll", "OpenAL32.dll", "OpenAL64.dll"}, "start"), - MACOS(new String[]{"liblwjgl.jnilib", "openal.dylib"}, "open"), - LINUX(new String[]{"liblwjgl.so", "liblwjgl64.so", "libopenal.so", "libopenal64.so"}, "xdg-open"); + WINDOWS(new String[]{"lwjgl.dll", "lwjgl64.dll", "OpenAL32.dll", "OpenAL64.dll"}, "start", "\\bin\\java.exe"), + MACOS(new String[]{"liblwjgl.jnilib", "openal.dylib"}, "open", "/bin/java"), + LINUX(new String[]{"liblwjgl.so", "liblwjgl64.so", "libopenal.so", "libopenal64.so"}, "xdg-open", "/bin/java"); private static final Platform platform; @@ -33,10 +33,12 @@ public enum Platform { private final String[] natives; public final String open; + public final File javaBin; - Platform(String[] natives, String open) { + Platform(String[] natives, String open, String javaBin) { this.natives = natives; this.open = open; + this.javaBin = new File(System.getProperty("java.home") + javaBin).getAbsoluteFile(); } public static Platform getPlatform() { diff --git a/common/src/main/java/com/fox2code/foxloader/loader/FLJitPackUpdater.java b/common/src/main/java/com/fox2code/foxloader/loader/FLJitPackUpdater.java index b5acd42..8c90bf2 100644 --- a/common/src/main/java/com/fox2code/foxloader/loader/FLJitPackUpdater.java +++ b/common/src/main/java/com/fox2code/foxloader/loader/FLJitPackUpdater.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; +import java.util.Objects; public final class FLJitPackUpdater extends JitPackUpdater { public FLJitPackUpdater() { @@ -24,12 +25,17 @@ protected String findLatestVersion() throws IOException { @Override protected void doUpdate() throws IOException { + Objects.requireNonNull(ModLoader.foxLoader.getMod(), "WTF???"); String latestVersion = this.getLatestVersion(); if (FoxLauncher.getLauncherType() == LauncherType.GRADLE) { System.out.println("Change the dev plugin version to " + latestVersion + " to update FoxLoader"); return; } - ModLoader.foxLoader.getMod().loaderHandleDoFoxLoaderUpdate( + System.out.println("Calling loaderHandleDoFoxLoaderUpdate"); + Mod mod = ModLoader.foxLoader.getMod(); + if (mod == null) + throw new AssertionError("mod == null"); + mod.loaderHandleDoFoxLoaderUpdate( latestVersion, this.getUrlForLatestJar()); } } \ No newline at end of file diff --git a/common/src/main/java/com/fox2code/foxloader/loader/Mod.java b/common/src/main/java/com/fox2code/foxloader/loader/Mod.java index c670ed8..cde35b8 100644 --- a/common/src/main/java/com/fox2code/foxloader/loader/Mod.java +++ b/common/src/main/java/com/fox2code/foxloader/loader/Mod.java @@ -167,7 +167,9 @@ public void registerShapelessRecipe(RegisteredItemStack result, GameRegistry.Ing // For internal use only void loaderHandleServerHello(NetworkPlayer networkPlayer, ServerHello serverHello) {} void loaderHandleClientHello(NetworkPlayer networkPlayer, ClientHello clientHello) {} - void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOException {} + void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOException { + System.err.println("Unhandled loaderHandleDoFoxLoaderUpdate()"); + } interface SidedMod { ModContainer getModContainer(); diff --git a/common/src/main/java/com/fox2code/foxloader/loader/ModContainer.java b/common/src/main/java/com/fox2code/foxloader/loader/ModContainer.java index 4f469c6..96e2d1d 100644 --- a/common/src/main/java/com/fox2code/foxloader/loader/ModContainer.java +++ b/common/src/main/java/com/fox2code/foxloader/loader/ModContainer.java @@ -123,12 +123,14 @@ void applyModMixins(boolean client) { } void applyMod(boolean client) throws ReflectiveOperationException { - if (client) { - this.clientMod = initializeMod(this.clientModCls); - } else { - this.serverMod = initializeMod(this.serverModCls); + if (!this.id.equals(ModLoader.FOX_LOADER_MOD_ID)) { + if (client) { + this.clientMod = initializeMod(this.clientModCls); + } else { + this.serverMod = initializeMod(this.serverModCls); + } + this.commonMod = initializeMod(this.commonModCls); } - this.commonMod = initializeMod(this.commonModCls); try (InputStream inputStream = ModContainer.class.getResourceAsStream("/assets/" + id + "/lang/en_US.lang")) { if (inputStream != null) { logger.log(Level.FINE, "Loaded /assets/" + id + "/lang/en_US.lang"); diff --git a/common/src/main/java/com/fox2code/foxloader/updater/UpdateManager.java b/common/src/main/java/com/fox2code/foxloader/updater/UpdateManager.java index 6b5f584..8982402 100644 --- a/common/src/main/java/com/fox2code/foxloader/updater/UpdateManager.java +++ b/common/src/main/java/com/fox2code/foxloader/updater/UpdateManager.java @@ -105,10 +105,10 @@ public synchronized void doUpdates() { abstractUpdater.updateConsumed = true; if (abstractUpdater.hasUpdate()) { try { - abstractUpdater.findLatestVersion(); + abstractUpdater.doUpdate(); } catch (IOException e) { ModLoader.getModContainer(ModLoader.FOX_LOADER_MOD_ID) - .logger.log(Level.WARNING, "Update check failed!"); + .logger.log(Level.WARNING, "Update failed!", e); } } } @@ -120,6 +120,12 @@ public synchronized void doUpdate(String modId) { if (abstractUpdater != null && abstractUpdater.hasUpdate() && !abstractUpdater.updateConsumed) { abstractUpdater.updateConsumed = true; + try { + abstractUpdater.doUpdate(); + } catch (IOException e) { + ModLoader.getModContainer(ModLoader.FOX_LOADER_MOD_ID) + .logger.log(Level.WARNING, "Update failed!", e); + } } } diff --git a/final/src/main/java/com/fox2code/foxloader/installer/InstallerGUI.java b/final/src/main/java/com/fox2code/foxloader/installer/InstallerGUI.java index 129ffea..dc768d2 100644 --- a/final/src/main/java/com/fox2code/foxloader/installer/InstallerGUI.java +++ b/final/src/main/java/com/fox2code/foxloader/installer/InstallerGUI.java @@ -113,6 +113,7 @@ public InstallerGUI(InstallerPlatform installerPlatform) { public InstallerGUI(InstallerPlatform installerPlatform, LauncherType launcherType) { this.installerPlatform = installerPlatform; this.launcherType = launcherType; + versionName = DEFAULT_VERSION_NAME; jFrame = null; minDimensions = null; globalContainer = null; diff --git a/final/src/main/java/com/fox2code/foxloader/installer/Main.java b/final/src/main/java/com/fox2code/foxloader/installer/Main.java index e961691..aa60fb8 100644 --- a/final/src/main/java/com/fox2code/foxloader/installer/Main.java +++ b/final/src/main/java/com/fox2code/foxloader/installer/Main.java @@ -74,13 +74,16 @@ public static void main(String[] args) throws ReflectiveOperationException, Malf installerPlatform = InstallerPlatform.valueOf(args[1].toUpperCase(Locale.ROOT)); } if (update) { + System.setErr(System.out); // Redirect errors to stdout LauncherType launcherType = LauncherType.valueOf(args[1].toUpperCase(Locale.ROOT)); try { + System.out.println("Updating..."); new InstallerGUI(installerPlatform, launcherType).doSilentInstall(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } + return; } new InstallerGUI(installerPlatform).show(); } diff --git a/gradle.properties b/gradle.properties index f458e5d..d365581 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.parallel=true org.gradle.jvmargs=-Xmx1024m -XX:-UseGCOverheadLimit -Dfile.encoding=UTF-8 # FoxLoader properties -foxloader.version=0.3.3 +foxloader.version=0.3.4 foxloader.lastReIndevTransformerChanges=0.3.0 # ReIndev properties diff --git a/server/src/main/java/com/fox2code/foxloader/loader/ServerModLoader.java b/server/src/main/java/com/fox2code/foxloader/loader/ServerModLoader.java index 8a69b0f..f4fdbea 100644 --- a/server/src/main/java/com/fox2code/foxloader/loader/ServerModLoader.java +++ b/server/src/main/java/com/fox2code/foxloader/loader/ServerModLoader.java @@ -10,10 +10,13 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.src.game.stats.StatList; +import java.util.Objects; + public final class ServerModLoader extends Mod { public static void launchModdedServer(String... args) { ModLoader.foxLoader.serverMod = new ServerModLoader(); ModLoader.foxLoader.serverMod.modContainer = ModLoader.foxLoader; + Objects.requireNonNull(ModLoader.foxLoader.getMod(), "WTF???"); ModLoader.initializeModdedInstance(false); ServerSelfTest.selfTest(); MinecraftServer.main(args);