Skip to content

Commit

Permalink
finally fixed UpdaterUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
XDjackieXD committed Mar 6, 2016
1 parent 354f6c4 commit 1d0ebb8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
Binary file modified ExamplePack/ExamplePack-MultiMC-Instance.zip
Binary file not shown.
24 changes: 24 additions & 0 deletions UpdaterUpdater/src/at/chaosfield/updaterUpdater/JarRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package at.chaosfield.updaterUpdater;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class JarRunner {

private static final Class<?>[] parameters = new Class[]{URL.class};

public static void addFile(File file) throws IOException {
URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
Class<?> sysclass = URLClassLoader.class;
try {
Method method = sysclass.getDeclaredMethod("addURL",parameters);
method.setAccessible(true);
method.invoke(sysloader,new Object[]{ file.toURI().toURL() });
} catch (Throwable t) {
t.printStackTrace();
throw new IOException("Error, could not add File to system classloader");
}
}
}
29 changes: 10 additions & 19 deletions UpdaterUpdater/src/at/chaosfield/updaterUpdater/UpdaterUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.json.JSONObject;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.jar.JarFile;
Expand All @@ -19,6 +21,10 @@ public class UpdaterUpdater{


public static void main(String[] args){
new UpdaterUpdater(args);
}

public UpdaterUpdater(String[] args){
if(args.length != 4){
System.out.println("4 Parameters are required (link to online pack config, location of the local pack config inside modpack root, modpack root, location of PackUpdate jar inside modpack root)");
}
Expand Down Expand Up @@ -47,29 +53,14 @@ public static void main(String[] args){
}

try{
runPackUpdate(args[2] + File.separator + args[3], "\"" + args[0] + "\" \"" + args[1] + "\" \"" + args[2] + "\"");
}catch(IOException e){
JarRunner.addFile(new File(args[2] + File.separator + args[3]));
Method mainMethod = ClassLoader.getSystemClassLoader().loadClass("at.chaosfield.packupdate.PackUpdate").getDeclaredMethod("main", String[].class);
mainMethod.invoke(null, (Object)new String[]{args[0], args[1], args[2]});
}catch(IOException | InvocationTargetException | NoSuchMethodException | IllegalAccessException | ClassNotFoundException e){
System.out.println("[PackUpdate Updater] Execution of PackUpdater failed");
e.printStackTrace();
}
}

public static void runPackUpdate(String path, String args) throws IOException{
String command = "\"" + System.getProperty("java.home") + File.separator + "bin" + File.separator + "java\" -jar \"" + path + "\" " + args;
String[] runCmd;
if(System.getProperty("os.name").toLowerCase().contains("win")){
runCmd = new String[]{"cmd", "/c", command};
}else{
runCmd = new String[]{"/bin/sh", "-c", command};
}

try{
Runtime.getRuntime().exec(runCmd).waitFor();
}catch(InterruptedException e){
e.printStackTrace();
}

System.out.printf("Ran command. Exiting now.");
}

public static boolean hasUpdate(String version) throws IOException{
Expand Down

0 comments on commit 1d0ebb8

Please sign in to comment.