Skip to content

Commit 3fdc40c

Browse files
committed
Update 0.3.4
1 parent af1ddce commit 3fdc40c

File tree

10 files changed

+63
-20
lines changed

10 files changed

+63
-20
lines changed

client/src/main/java/com/fox2code/foxloader/loader/ClientModLoader.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import net.minecraft.src.client.gui.StringTranslate;
1515

1616
import java.io.*;
17-
import java.util.ArrayList;
18-
import java.util.HashMap;
19-
import java.util.Properties;
17+
import java.util.*;
2018
import java.util.function.Function;
2119

2220
public final class ClientModLoader extends Mod {
@@ -29,6 +27,7 @@ public final class ClientModLoader extends Mod {
2927
public static void launchModdedClient(String... args) {
3028
ModLoader.foxLoader.clientMod = new ClientModLoader();
3129
ModLoader.foxLoader.clientMod.modContainer = ModLoader.foxLoader;
30+
Objects.requireNonNull(ModLoader.foxLoader.getMod(), "WTF???");
3231
ModLoader.initializeModdedInstance(true);
3332
Platform.getPlatform().setupLwjgl2();
3433
ClientSelfTest.selfTest();
@@ -84,6 +83,7 @@ void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOExceptio
8483
File dest = null;
8584
String[] args;
8685
LauncherType launcherType = FoxLauncher.getLauncherType();
86+
getLogger().info("Updating to " + version + " from " + launcherType + " launcher");
8787
switch (launcherType) {
8888
default:
8989
return;
@@ -92,7 +92,7 @@ void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOExceptio
9292
dest = new File(libraries, "foxloader-" + version + ".jar");
9393
case BETA_CRAFT:
9494
case VANILLA_LIKE:
95-
args = new String[]{null, "--update", launcherType.name()};
95+
args = new String[]{null, "-jar", null, "--update", launcherType.name()};
9696
}
9797
if (dest == null) {
9898
if (!ModLoader.updateTmp.exists() && !ModLoader.updateTmp.mkdirs()) {
@@ -104,8 +104,26 @@ void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOExceptio
104104
try (FileOutputStream fileOutputStream = new FileOutputStream(dest)) {
105105
NetUtils.downloadTo(url, fileOutputStream);
106106
}
107-
args[0] = dest.getAbsolutePath();
108-
new ProcessBuilder(args).inheritIO().directory(ModLoader.updateTmp).start();
107+
args[0] = Platform.getPlatform().javaBin.getPath();
108+
args[2] = dest.getAbsolutePath();
109+
getLogger().info("Command: " + Arrays.toString(args));
110+
final Process process = new ProcessBuilder(args).directory(dest.getParentFile()).start();
111+
if (process.isAlive()) {
112+
new Thread(() -> {
113+
Scanner scanner = new Scanner(process.getInputStream());
114+
String line;
115+
while (process.isAlive() &&
116+
(line = scanner.next()) != null) {
117+
System.out.println("Update: " + line);
118+
Thread.yield();
119+
}
120+
if (!process.isAlive()) {
121+
System.out.println("Updated with exit code " + process.exitValue());
122+
}
123+
}, "Output log thread");
124+
} else {
125+
System.out.println("Updated with exit code " + process.exitValue());
126+
}
109127
}
110128

111129
public static class Internal {

common/src/main/java/com/fox2code/foxloader/launcher/utils/Platform.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import java.util.Locale;
1010

1111
public enum Platform {
12-
WINDOWS(new String[]{"lwjgl.dll", "lwjgl64.dll", "OpenAL32.dll", "OpenAL64.dll"}, "start"),
13-
MACOS(new String[]{"liblwjgl.jnilib", "openal.dylib"}, "open"),
14-
LINUX(new String[]{"liblwjgl.so", "liblwjgl64.so", "libopenal.so", "libopenal64.so"}, "xdg-open");
12+
WINDOWS(new String[]{"lwjgl.dll", "lwjgl64.dll", "OpenAL32.dll", "OpenAL64.dll"}, "start", "\\bin\\java.exe"),
13+
MACOS(new String[]{"liblwjgl.jnilib", "openal.dylib"}, "open", "/bin/java"),
14+
LINUX(new String[]{"liblwjgl.so", "liblwjgl64.so", "libopenal.so", "libopenal64.so"}, "xdg-open", "/bin/java");
1515

1616
private static final Platform platform;
1717

@@ -33,10 +33,12 @@ public enum Platform {
3333

3434
private final String[] natives;
3535
public final String open;
36+
public final File javaBin;
3637

37-
Platform(String[] natives, String open) {
38+
Platform(String[] natives, String open, String javaBin) {
3839
this.natives = natives;
3940
this.open = open;
41+
this.javaBin = new File(System.getProperty("java.home") + javaBin).getAbsoluteFile();
4042
}
4143

4244
public static Platform getPlatform() {

common/src/main/java/com/fox2code/foxloader/loader/FLJitPackUpdater.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.jetbrains.annotations.Nullable;
77

88
import java.io.IOException;
9+
import java.util.Objects;
910

1011
public final class FLJitPackUpdater extends JitPackUpdater {
1112
public FLJitPackUpdater() {
@@ -24,12 +25,17 @@ protected String findLatestVersion() throws IOException {
2425

2526
@Override
2627
protected void doUpdate() throws IOException {
28+
Objects.requireNonNull(ModLoader.foxLoader.getMod(), "WTF???");
2729
String latestVersion = this.getLatestVersion();
2830
if (FoxLauncher.getLauncherType() == LauncherType.GRADLE) {
2931
System.out.println("Change the dev plugin version to " + latestVersion + " to update FoxLoader");
3032
return;
3133
}
32-
ModLoader.foxLoader.getMod().loaderHandleDoFoxLoaderUpdate(
34+
System.out.println("Calling loaderHandleDoFoxLoaderUpdate");
35+
Mod mod = ModLoader.foxLoader.getMod();
36+
if (mod == null)
37+
throw new AssertionError("mod == null");
38+
mod.loaderHandleDoFoxLoaderUpdate(
3339
latestVersion, this.getUrlForLatestJar());
3440
}
3541
}

common/src/main/java/com/fox2code/foxloader/loader/Mod.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ public void registerShapelessRecipe(RegisteredItemStack result, GameRegistry.Ing
167167
// For internal use only
168168
void loaderHandleServerHello(NetworkPlayer networkPlayer, ServerHello serverHello) {}
169169
void loaderHandleClientHello(NetworkPlayer networkPlayer, ClientHello clientHello) {}
170-
void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOException {}
170+
void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOException {
171+
System.err.println("Unhandled loaderHandleDoFoxLoaderUpdate()");
172+
}
171173

172174
interface SidedMod {
173175
ModContainer getModContainer();

common/src/main/java/com/fox2code/foxloader/loader/ModContainer.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ void applyModMixins(boolean client) {
123123
}
124124

125125
void applyMod(boolean client) throws ReflectiveOperationException {
126-
if (client) {
127-
this.clientMod = initializeMod(this.clientModCls);
128-
} else {
129-
this.serverMod = initializeMod(this.serverModCls);
126+
if (!this.id.equals(ModLoader.FOX_LOADER_MOD_ID)) {
127+
if (client) {
128+
this.clientMod = initializeMod(this.clientModCls);
129+
} else {
130+
this.serverMod = initializeMod(this.serverModCls);
131+
}
132+
this.commonMod = initializeMod(this.commonModCls);
130133
}
131-
this.commonMod = initializeMod(this.commonModCls);
132134
try (InputStream inputStream = ModContainer.class.getResourceAsStream("/assets/" + id + "/lang/en_US.lang")) {
133135
if (inputStream != null) {
134136
logger.log(Level.FINE, "Loaded /assets/" + id + "/lang/en_US.lang");

common/src/main/java/com/fox2code/foxloader/updater/UpdateManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ public synchronized void doUpdates() {
105105
abstractUpdater.updateConsumed = true;
106106
if (abstractUpdater.hasUpdate()) {
107107
try {
108-
abstractUpdater.findLatestVersion();
108+
abstractUpdater.doUpdate();
109109
} catch (IOException e) {
110110
ModLoader.getModContainer(ModLoader.FOX_LOADER_MOD_ID)
111-
.logger.log(Level.WARNING, "Update check failed!");
111+
.logger.log(Level.WARNING, "Update failed!", e);
112112
}
113113
}
114114
}
@@ -120,6 +120,12 @@ public synchronized void doUpdate(String modId) {
120120
if (abstractUpdater != null && abstractUpdater.hasUpdate()
121121
&& !abstractUpdater.updateConsumed) {
122122
abstractUpdater.updateConsumed = true;
123+
try {
124+
abstractUpdater.doUpdate();
125+
} catch (IOException e) {
126+
ModLoader.getModContainer(ModLoader.FOX_LOADER_MOD_ID)
127+
.logger.log(Level.WARNING, "Update failed!", e);
128+
}
123129
}
124130
}
125131

final/src/main/java/com/fox2code/foxloader/installer/InstallerGUI.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public InstallerGUI(InstallerPlatform installerPlatform) {
113113
public InstallerGUI(InstallerPlatform installerPlatform, LauncherType launcherType) {
114114
this.installerPlatform = installerPlatform;
115115
this.launcherType = launcherType;
116+
versionName = DEFAULT_VERSION_NAME;
116117
jFrame = null;
117118
minDimensions = null;
118119
globalContainer = null;

final/src/main/java/com/fox2code/foxloader/installer/Main.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,16 @@ public static void main(String[] args) throws ReflectiveOperationException, Malf
7474
installerPlatform = InstallerPlatform.valueOf(args[1].toUpperCase(Locale.ROOT));
7575
}
7676
if (update) {
77+
System.setErr(System.out); // Redirect errors to stdout
7778
LauncherType launcherType = LauncherType.valueOf(args[1].toUpperCase(Locale.ROOT));
7879
try {
80+
System.out.println("Updating...");
7981
new InstallerGUI(installerPlatform, launcherType).doSilentInstall();
8082
} catch (IOException e) {
8183
e.printStackTrace();
8284
System.exit(-1);
8385
}
86+
return;
8487
}
8588
new InstallerGUI(installerPlatform).show();
8689
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.gradle.parallel=true
33
org.gradle.jvmargs=-Xmx1024m -XX:-UseGCOverheadLimit -Dfile.encoding=UTF-8
44

55
# FoxLoader properties
6-
foxloader.version=0.3.3
6+
foxloader.version=0.3.4
77
foxloader.lastReIndevTransformerChanges=0.3.0
88

99
# ReIndev properties

server/src/main/java/com/fox2code/foxloader/loader/ServerModLoader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
import net.minecraft.server.MinecraftServer;
1111
import net.minecraft.src.game.stats.StatList;
1212

13+
import java.util.Objects;
14+
1315
public final class ServerModLoader extends Mod {
1416
public static void launchModdedServer(String... args) {
1517
ModLoader.foxLoader.serverMod = new ServerModLoader();
1618
ModLoader.foxLoader.serverMod.modContainer = ModLoader.foxLoader;
19+
Objects.requireNonNull(ModLoader.foxLoader.getMod(), "WTF???");
1720
ModLoader.initializeModdedInstance(false);
1821
ServerSelfTest.selfTest();
1922
MinecraftServer.main(args);

0 commit comments

Comments
 (0)