Skip to content

Commit

Permalink
Skip downloading existing files, exit without tripping the SecurityMa…
Browse files Browse the repository at this point in the history
…nager
  • Loading branch information
eigenraven committed Feb 10, 2024
1 parent b5d4849 commit 8a860fa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cpw.mods.fml.common.fakelwjgl3ify;

/** Safe runtime exit class to not trip the FML security manager. */
public class SafeRuntimeExit {

public static void exitRuntime(int code) {
nest0(code);
}

private static void nest0(int code) {
nest1(code);
}

private static void nest1(int code) {
nest2(code);
}

private static void nest2(int code) {
Runtime.getRuntime()
.exit(code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -114,6 +115,14 @@ public void loadTasks() {
tasks.add(new DownloadTask(url, null, path));
}
}

for (Iterator<DownloadTask> it = tasks.iterator(); it.hasNext();) {
final DownloadTask task = it.next();
if (Files.exists(task.targetLocation)) {
// already downloaded, skip
it.remove();
}
}
} catch (Exception e) {
throw Throwables.propagate(e);
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/me/eigenraven/lwjgl3ify/relauncher/Relauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.logging.log4j.Logger;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.fakelwjgl3ify.SafeRuntimeExit;
import me.eigenraven.lwjgl3ify.Tags;

public class Relauncher {
Expand All @@ -34,6 +35,10 @@ public class Relauncher {
final String[] args;
final String gameVersion;

private void runtimeExit(int exitCode) {
SafeRuntimeExit.exitRuntime(exitCode);
}

public Relauncher(String[] args, String gameVersion) {
this.args = args;
this.gameVersion = gameVersion;
Expand Down Expand Up @@ -180,8 +185,7 @@ public void run() throws IOException {

final ProcessBuilder pb = new ProcessBuilder(bootstrapCmd);
logger.info("Starting relaunched process using args {}", bootstrapCmd);
FMLCommonHandler.instance()
.exitJava(0, false);
runtimeExit(0);
final Process p = pb.inheritIO()
.start();
while (p.isAlive()) {
Expand All @@ -192,7 +196,6 @@ public void run() throws IOException {
continue;
}
}
FMLCommonHandler.instance()
.exitJava(p.exitValue(), false);
runtimeExit(p.exitValue());
}
}

0 comments on commit 8a860fa

Please sign in to comment.