TechWar v1.6.8版本的 MD5 值为:513ba4241f5234b566380e05da0f1813
以下内容为反编译后的 p05d8b0fd.java 源代码,内容仅作参考
package p54109b83.p40fa73c9;
import arc.Core;
import arc.files.Fi;
import arc.func.Boolc;
import arc.func.Boolf;
import arc.func.Boolp;
import arc.func.Cons;
import arc.func.ConsT;
import arc.func.Floatc;
import arc.func.Floatp;
import arc.func.Intc;
import arc.func.Prov;
import arc.graphics.Color;
import arc.scene.ui.layout.Table;
import arc.util.Http;
import arc.util.Log;
import arc.util.OS;
import arc.util.Strings;
import arc.util.Threads;
import arc.util.Timer;
import arc.util.io.Streams;
import arc.util.serialization.Jval;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Iterator;
import p54109b83.p40fa73c9.p7258e725;
import p54109b83.p40fa73c9.pb2f06238;
import p54109b83.p73b0472d.p1a578e9c;
import p54109b83.p7d5c009e.pddc35f88;
import p54109b83.p7d5c009e.pee74e2d6.p90d3e634;
import p54109b83.pa74ad8df.p34b6cd75;
import p54109b83.pa74ad8df.p70a22d80$pd41d8cd9$p95263d50;
import p54109b83.pb68187da;
import p54109b83.pdaffed34.p81743429;
import p54109b83.pf98ed07a.p0abe626b;
public class p05d8b0fd {
private static final int updateInterval = 60;
private boolean checkUpdates = true;
private boolean updateAvailable;
private int updateBuild;
private String updateUrl;
public boolean active() {
return p34b6cd75.type.equals("bleeding-edge");
}
public p05d8b0fd() {
if (active()) {
Timer.schedule(new Runnable() {
@Override
public final void run() {
p05d8b0fd.this.lambda$new$1();
}
}, 60.0f, 60.0f);
}
if (OS.hasProp("becopy")) {
try {
Fi dest = Fi.get(OS.prop("becopy"));
final Fi self = Fi.get(p05d8b0fd.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
Iterator<Fi> it = self.parent().findAll(new Boolf() {
@Override
public final boolean get(Object obj) {
boolean lambda$new$2;
lambda$new$2 = p05d8b0fd.lambda$new$2(Fi.this, (Fi) obj);
return lambda$new$2;
}
}).iterator();
while (it.hasNext()) {
Fi file = it.next();
file.delete();
}
self.copyTo(dest);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
public void lambda$new$1() {
if ((pb68187da.clientLoaded || pb68187da.headless) && this.checkUpdates && !pb68187da.mobile) {
checkUpdate(new Boolc() {
@Override
public final void get(boolean z) {
p05d8b0fd.lambda$new$0(z);
}
});
}
}
public static void lambda$new$0(boolean t) {
}
public static boolean lambda$new$2(Fi self, Fi f) {
return !f.equals(self);
}
public void checkUpdate(final Boolc done) {
Http.get("https://api.github.com/repos/Anuken/MindustryBuilds/releases/latest").error(new Cons() {
@Override
public final void get(Object obj) {
Boolc.this.get(false);
}
}).submit(new ConsT() {
@Override
public final void get(Object obj) {
p05d8b0fd.this.lambda$checkUpdate$7(done, (Http.HttpResponse) obj);
}
});
}
public void lambda$checkUpdate$7(final Boolc done, Http.HttpResponse res) throws Exception {
Jval val = Jval.read(res.getResultAsString());
int newBuild = Strings.parseInt(val.getString("tag_name", "0"));
if (newBuild > p34b6cd75.build) {
Jval asset = val.get("assets").asArray().find(new Boolf() {
@Override
public final boolean get(Object obj) {
boolean lambda$checkUpdate$4;
lambda$checkUpdate$4 = p05d8b0fd.lambda$checkUpdate$4((Jval) obj);
return lambda$checkUpdate$4;
}
});
String url = asset.getString("browser_download_url", "");
this.updateAvailable = true;
this.updateBuild = newBuild;
this.updateUrl = url;
Core.app.post(new Runnable() {
@Override
public final void run() {
p05d8b0fd.this.lambda$checkUpdate$5(done);
}
});
return;
}
Core.app.post(new Runnable() {
@Override
public final void run() {
Boolc.this.get(false);
}
});
}
public static boolean lambda$checkUpdate$4(Jval v) {
return v.getString("name", "").startsWith(pb68187da.headless ? "Mindustry-BE-Server" : "Mindustry-BE-Desktop");
}
public void lambda$checkUpdate$5(Boolc done) {
showUpdateDialog();
done.get(true);
}
public boolean isUpdateAvailable() {
return this.updateAvailable;
}
public void showUpdateDialog() {
if (this.updateAvailable) {
if (!pb68187da.headless) {
this.checkUpdates = false;
pb68187da.ui.showCustomConfirm(Core.bundle.format("be.update", "") + " " + this.updateBuild, "@be.update.confirm", "@ok", "@be.ignore", new Runnable() {
@Override
public final void run() {
p05d8b0fd.this.lambda$showUpdateDialog$17();
}
}, new Runnable() {
@Override
public final void run() {
p05d8b0fd.this.lambda$showUpdateDialog$18();
}
});
return;
}
Log.info("&lcA new update is available: &lyBleeding Edge build @", Integer.valueOf(this.updateBuild));
if (p7258e725.pfa535ffb.autoUpdate.bool()) {
Log.info("&lcAuto-downloading next version...");
try {
final Fi source = Fi.get(p05d8b0fd.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
final Fi dest = source.sibling("server-be-" + this.updateBuild + ".jar");
download(this.updateUrl, dest, new Intc() {
@Override
public final void get(int i) {
p05d8b0fd.lambda$showUpdateDialog$20(i);
}
}, new Floatc() {
@Override
public final void get(float f) {
p05d8b0fd.lambda$showUpdateDialog$21(f);
}
}, new Boolp() {
@Override
public final boolean get() {
boolean lambda$showUpdateDialog$22;
lambda$showUpdateDialog$22 = p05d8b0fd.lambda$showUpdateDialog$22();
return lambda$showUpdateDialog$22;
}
}, new Runnable() {
@Override
public final void run() {
p05d8b0fd.lambda$showUpdateDialog$24(Fi.this, source);
}
}, p70a22d80$pd41d8cd9$p95263d50.INSTANCE);
} catch (Exception e) {
e.printStackTrace();
}
}
this.checkUpdates = false;
}
}
public void lambda$showUpdateDialog$17() {
final Fi fileDest;
try {
final boolean[] cancel = {false};
final float[] progress = {0.0f};
final int[] length = {0};
final Fi file = pb68187da.bebuildDirectory.child("client-be-" + this.updateBuild + ".jar");
if (OS.hasProp("becopy")) {
fileDest = Fi.get(OS.prop("becopy"));
} else {
fileDest = Fi.get(p05d8b0fd.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
}
final p90d3e634 dialog = new p90d3e634("@be.updating");
download(this.updateUrl, file, new Intc() {
@Override
public final void get(int i) {
p05d8b0fd.lambda$showUpdateDialog$8(length, i);
}
}, new Floatc() {
@Override
public final void get(float f) {
p05d8b0fd.lambda$showUpdateDialog$9(progress, f);
}
}, new Boolp() {
@Override
public final boolean get() {
boolean lambda$showUpdateDialog$10;
lambda$showUpdateDialog$10 = p05d8b0fd.lambda$showUpdateDialog$10(cancel);
return lambda$showUpdateDialog$10;
}
}, new Runnable() {
@Override
public final void run() {
p05d8b0fd.lambda$showUpdateDialog$11(Fi.this, file);
}
}, new Cons() {
@Override
public final void get(Object obj) {
p05d8b0fd.lambda$showUpdateDialog$12(p90d3e634.this, (Throwable) obj);
}
});
dialog.cont.add((Table) new pddc35f88((Prov<CharSequence>) new Prov() {
@Override
public final Object get() {
CharSequence lambda$showUpdateDialog$13;
lambda$showUpdateDialog$13 = p05d8b0fd.lambda$showUpdateDialog$13(length, progress);
return lambda$showUpdateDialog$13;
}
}, new Prov() {
@Override
public final Object get() {
Color color;
color = p1a578e9c.accent;
return color;
}
}, new Floatp() {
@Override
public final float get() {
float lambda$showUpdateDialog$15;
lambda$showUpdateDialog$15 = p05d8b0fd.lambda$showUpdateDialog$15(progress);
return lambda$showUpdateDialog$15;
}
})).width(400.0f).height(70.0f);
dialog.buttons.button("@cancel", p81743429.cancel, new Runnable() {
@Override
public final void run() {
p05d8b0fd.lambda$showUpdateDialog$16(cancel, dialog);
}
}).size(210.0f, 64.0f);
dialog.setFillParent(false);
dialog.show();
} catch (Exception e) {
pb68187da.ui.showException(e);
}
}
public static boolean lambda$showUpdateDialog$10(boolean[] cancel) {
return cancel[0];
}
public static void lambda$showUpdateDialog$8(int[] length, int i) {
length[0] = i;
}
public static void lambda$showUpdateDialog$9(float[] progress, float v) {
progress[0] = v;
}
public static void lambda$showUpdateDialog$11(Fi fileDest, Fi file) {
String[] strArr;
try {
Runtime runtime = Runtime.getRuntime();
if (OS.isMac) {
strArr = new String[]{pb68187da.javaPath, "-XstartOnFirstThread", "-DlastBuild=" + p34b6cd75.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()};
} else {
strArr = new String[]{pb68187da.javaPath, "-DlastBuild=" + p34b6cd75.build, "-Dberestart", "-Dbecopy=" + fileDest.absolutePath(), "-jar", file.absolutePath()};
}
runtime.exec(strArr);
System.exit(0);
} catch (IOException e) {
pb68187da.ui.showException(e);
}
}
public static void lambda$showUpdateDialog$12(p90d3e634 dialog, Throwable e) {
dialog.hide();
pb68187da.ui.showException(e);
}
public static CharSequence lambda$showUpdateDialog$13(int[] length, float[] progress) {
if (length[0] == 0) {
return Core.bundle.get("be.updating");
}
return ((((int) (progress[0] * length[0])) / 1024) / 1024) + "/" + ((length[0] / 1024) / 1024) + " MB";
}
public static float lambda$showUpdateDialog$15(float[] progress) {
return progress[0];
}
public static void lambda$showUpdateDialog$16(boolean[] cancel, p90d3e634 dialog) {
cancel[0] = true;
dialog.hide();
}
public void lambda$showUpdateDialog$18() {
this.checkUpdates = false;
}
public static void lambda$showUpdateDialog$19(int len) {
Log.info("&ly| Size: @ MB.", Strings.fixed((len / 1024.0f) / 1024.0f, 2));
}
public static void lambda$showUpdateDialog$20(final int len) {
Core.app.post(new Runnable() {
@Override
public final void run() {
p05d8b0fd.lambda$showUpdateDialog$19(len);
}
});
}
public static void lambda$showUpdateDialog$21(float progress) {
}
public static boolean lambda$showUpdateDialog$22() {
return false;
}
public static void lambda$showUpdateDialog$24(final Fi dest, final Fi source) {
Core.app.post(new Runnable() {
@Override
public final void run() {
p05d8b0fd.lambda$showUpdateDialog$23(Fi.this, source);
}
});
}
public static void lambda$showUpdateDialog$23(Fi dest, Fi source) {
Log.info("&lcSaving...");
p0abe626b.save(pb68187da.saveDirectory.child("autosavebe.msav"));
Log.info("&lcAutosaved.");
pb68187da.netServer.kickAll(pb2f06238.pe8b40605.serverRestarting);
Threads.sleep(500L);
Log.info("&lcVersion downloaded, exiting. Note that if you are not using a auto-restart script, the server will not restart automatically.");
dest.copyTo(source);
dest.delete();
System.exit(2);
}
private void download(final String furl, final Fi dest, final Intc length, final Floatc progressor, final Boolp canceled, final Runnable done, final Cons<Throwable> error) {
pb68187da.mainExecutor.submit(new Runnable() {
@Override
public final void run() {
p05d8b0fd.lambda$download$25(furl, dest, length, canceled, progressor, done, error);
}
});
}
public static void lambda$download$25(String furl, Fi dest, Intc length, Boolp canceled, Floatc progressor, Runnable done, Cons error) {
BufferedInputStream in;
OutputStream out;
byte[] data;
long size;
long counter;
try {
try {
HttpURLConnection con = (HttpURLConnection) new URL(furl).openConnection();
in = new BufferedInputStream(con.getInputStream());
try {
out = dest.write(false, Streams.defaultBufferSize);
data = new byte[Streams.defaultBufferSize];
size = con.getContentLength();
counter = 0;
try {
length.get((int) size);
} catch (Throwable th) {
e = th;
error.get(e);
return;
}
} catch (Throwable th2) {
e = th2;
error.get(e);
return;
}
} catch (Throwable th3) {
e = th3;
error.get(e);
return;
}
} catch (Throwable th4) {
e = th4;
}
while (true) {
int x = in.read(data, 0, data.length);
if (x < 0 || canceled.get()) {
break;
}
counter += x;
try {
progressor.get(((float) counter) / ((float) size));
out.write(data, 0, x);
} catch (Throwable th5) {
e = th5;
}
e = th5;
error.get(e);
return;
}
out.close();
in.close();
if (!canceled.get()) {
done.run();
}
}
}