Skip to content

Commit

Permalink
Update 0.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Apr 3, 2023
1 parent af1ddce commit 3fdc40c
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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()) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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());
}
}
4 changes: 3 additions & 1 deletion common/src/main/java/com/fox2code/foxloader/loader/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3fdc40c

Please sign in to comment.