Skip downloading existing files, exit without tripping the SecurityManager

This commit is contained in:
Raven Szewczyk committed 2024-02-10 18:47:55 +00:00
1 parent b5d4849931
commit 8a860fa64e
3 files changed
+38 -4

No files matched your search

@@ -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);
}
}
@@ -15,6 +15,7 @@ import java.nio.file.Path;
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;
@@ -114,6 +115,14 @@ public class Downloader {
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);
}
@@ -21,6 +21,7 @@ import org.apache.logging.log4j.LogManager;
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 {
@@ -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;
@@ -180,8 +185,7 @@ public class Relauncher {
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()) {
@@ -192,7 +196,6 @@ public class Relauncher {
continue;
}
}
FMLCommonHandler.instance()
.exitJava(p.exitValue(), false);
runtimeExit(p.exitValue());
}
}