From c902e62a118e28a7b9b48060eaee8d4af36f4194 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Fri, 4 Jan 2019 13:45:42 +0400 Subject: [PATCH] Removed updater. I had no idea how to realise it. --- .../ru/gravit/launchserver/LaunchServer.java | 8 -- .../ru/gravit/launchserver/UpdateManager.java | 104 ------------------ modules | 2 +- 3 files changed, 1 insertion(+), 113 deletions(-) delete mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/UpdateManager.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index bf120793..d6657645 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -91,10 +91,6 @@ public static final class Config { public String projectName; public String[] mirrors; - - public String updateMirror; - - public boolean criticalCallbacks; public String binaryName; @@ -310,7 +306,6 @@ public static void main(String... args) throws Throwable { public final CommandHandler commandHandler; - public final ServerSocketHandler serverSocketHandler; private final AtomicBoolean started = new AtomicBoolean(false); @@ -476,7 +471,6 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE // post init modules modulesManager.postInitModules(); - new UpdateManager(this); } public static void initGson() @@ -550,8 +544,6 @@ private void generateConfigIfNotExists() throws IOException { LogHelper.info("Creating LaunchServer config"); Config newConfig = new Config(); newConfig.mirrors = new String[]{"http://mirror.gravitlauncher.ml/"}; - newConfig.updateMirror = "gravitlauncher.ml:7245"; - newConfig.criticalCallbacks = false; newConfig.launch4j = new ExeConf(); newConfig.launch4j.copyright = "© GravitLauncher Team"; newConfig.launch4j.fileDesc = "GravitLauncher ".concat(Launcher.getVersion().getVersionString()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/UpdateManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/UpdateManager.java deleted file mode 100644 index 7de0fe2f..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/UpdateManager.java +++ /dev/null @@ -1,104 +0,0 @@ -package ru.gravit.launchserver; - -import java.io.IOException; -import java.net.Socket; -import java.util.Timer; -import java.util.TimerTask; - -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.utils.Version; -import ru.gravit.utils.helper.LogHelper; - -public final class UpdateManager extends TimerTask { - private final LaunchServer srv; - private final FCL cl; - public final Timer t; - private final String updUH; - private final int updUP; - private int lastNum = 0; - - public interface Callback { - void prep(LaunchServer lsrv); - void define(FCL loader); - void post(LaunchServer lsrv); - } - - UpdateManager(LaunchServer lsrv) { - this.srv = lsrv; - this.cl = srv.config.criticalCallbacks ? new FCL(srv) : null; - t = srv.config.criticalCallbacks ? new Timer("Updater", true) : null; - if (srv.config.criticalCallbacks) t.schedule(this, 60000, 60000); - String[] updU = lsrv.config.updateMirror.split(":"); - updUH = updU[0]; - updUP = Integer.parseInt(updU[1]); - checkVer(); - } - - public static class FCL extends ClassLoader { - private FCL(LaunchServer lsrv) { - super(lsrv.modulesManager.classloader); - } - - public Class define(String name, byte[] data) { - return defineClass(name, data, 0, data.length); - } - } - - @Override - public void run() { - try { - Socket s = getSocket(); - s.getOutputStream().write(2); - @SuppressWarnings("resource") // s.close() closes it. - HInput in = new HInput(s.getInputStream()); - int num = in.readInt(); - if (num == lastNum) return; - for (int i = 0; i < num; i++) { - if (i >= lastNum) { - String classN = in.readString(1024); - byte[] classB = in.readByteArray(256*1024); - try { - Callback c = (Callback)cl.define(classN, classB).newInstance(); - c.prep(srv); - c.define(cl); - c.post(srv); - } catch (InstantiationException | IllegalAccessException e) { - LogHelper.error(e); - } - } - if (num != lastNum) lastNum = num; - - } - s.close(); - } catch (IOException e) { - } - - } - - private Socket getSocket() throws IOException { - return new Socket(updUH, updUP); - } - - private void checkVer() { - try { - Socket s = getSocket(); - s.getOutputStream().write(1); - @SuppressWarnings("resource") // s.close() closes it. - HInput in = new HInput(s.getInputStream()); - int major = in.readInt(); - int minor = in.readInt(); - int patch = in.readInt(); - int build = in.readInt(); - Version launcher = Launcher.getVersion(); - if ((major > launcher.major || minor > launcher.minor || patch > launcher.patch || build > launcher.build) && in.readBoolean()) { - LogHelper.info("Updates avaliable download it from github."); - LogHelper.info("New version: " + new Version(major, minor, patch, build, Version.Type.valueOf(in.readString(128))).toString()); - } - s.close(); - } catch (IOException e) { - LogHelper.error("Can not check version."); - LogHelper.error(e); - } - } -} diff --git a/modules b/modules index e1e3b0d5..ec143160 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit e1e3b0d50bbb4a8ed5239df38690de69f92e2cc4 +Subproject commit ec1431605c4951ace5cbd2ab392b67cea25bddd5