-
Notifications
You must be signed in to change notification settings - Fork 0
Idea of self update function
ᗺ0B edited this page Jul 25, 2019
·
1 revision
Using this method does not need updater
private void selfup() throws IOException {
URL website[] = new URL[4];
website[0] = new URL("https://raw.githubusercontent.com/frychicken/");
website[1] = new URL("https://raw.githubusercontent.com/frychicken/");
website[2] = new URL("https://raw.githubusercontent.com/frychicken/");
website[3] = new URL("https://raw.githubusercontent.com/frychicken/");
String af[] = new String[4];
af[0] = "1.class";
af[1] = "2.class";
af[2] = "3.class";
af[3] = "4.class";
for(int a=0; a<4; a++) {
try {
ReadableByteChannel ok = Channels.newChannel(website[a].openStream());
FileOutputStream okay = new FileOutputStream(System.getProperty("user.dir")+af[a]);
okay.getChannel().transferFrom(ok, 0, Long.MAX_VALUE);
okay.close();
ok.close();
} catch (Exception e) {
JOptionPane.showConfirmDialog((Component) null, "Update failed",
"Update", JOptionPane.CLOSED_OPTION);
System.out.println("Update failed");
wl.writeLog(e.toString());
wl.writeLog("update failed");
e.printStackTrace();
}
Runtime r= Runtime.getRuntime();
Process proc = r.exec("jar uf PoolSimulator.jar 1.class 2$1.class 3.class 4$1.class");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));
String s1 = null;
while ((s1 = stdInput.readLine()) != null) {
todis = s1;
System.out.println(s1);
}
while ((s1 = stdError.readLine()) != null) {
todis = s1;
System.out.println(s1);
}
}
}