From 64f865fa47725eb964978ea6275d9c83b0fa04a9 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 13 Mar 2019 17:09:27 +0700 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?Updater=20=D0=B8=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LaunchServer/build.gradle | 1 - .../ru/gravit/launchserver/LaunchServer.java | 3 +- .../java/ru/gravit/launchserver/Updater.java | 92 ------------------- 3 files changed, 1 insertion(+), 95 deletions(-) delete mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 0f2209c1..9f58b2b9 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -48,7 +48,6 @@ pack project(':libLauncher') bundle 'commons-codec:commons-codec:1.11' bundle 'org.javassist:javassist:3.24.1-GA' bundle 'io.netty:netty-all:4.1.32.Final' - bundle 'org.kohsuke:github-api:1.95' bundle 'org.slf4j:slf4j-simple:1.7.25' bundle 'org.slf4j:slf4j-api:1.7.25' diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 95bb6f39..dc630df0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -352,7 +352,6 @@ public static void main(String... args) throws Throwable { public volatile Map> updatesDirMap; public final Timer taskPool; - public final Updater updater; public static Gson gson; public static GsonBuilder gsonBuilder; @@ -379,6 +378,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE HWIDHandler.registerHandlers(); PermissionsHandler.registerHandlers(); Response.registerResponses(); + Component.registerComponents(); LaunchServer.server = this; // Set command handler @@ -533,7 +533,6 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE LogHelper.debug("PostInit components successful"); } // start updater - this.updater = new Updater(this); if(config.netty != null) nettyServerSocketHandler = new NettyServerSocketHandler(this); else diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java b/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java deleted file mode 100644 index a6d57254..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/Updater.java +++ /dev/null @@ -1,92 +0,0 @@ -package ru.gravit.launchserver; - -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.Locale; -import java.util.TimerTask; -import java.util.concurrent.atomic.AtomicReference; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.kohsuke.github.GHRelease; -import org.kohsuke.github.GHRepository; -import org.kohsuke.github.GitHub; - -import ru.gravit.launcher.Launcher; -import ru.gravit.utils.Version; -import ru.gravit.utils.Version.Type; -import ru.gravit.utils.helper.LogHelper; - -public class Updater extends TimerTask { - private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss", Locale.US); - private static final long period = 1000*3600; - private static final Version VERSION = Launcher.getVersion(); - private final GHRepository gravitLauncher; - private Version parent = VERSION; - - public Updater(LaunchServer srv) { - - GHRepository gravitLauncherTmp = null; - try { - gravitLauncherTmp = GitHub.connectAnonymously().getOrganization("GravitLauncher").getRepository("Launcher"); - } catch (Throwable e) { - LogHelper.error(e); - } - this.gravitLauncher = gravitLauncherTmp; - run(); - if (srv.config.updatesNotify) srv.taskPool.schedule(this, new Date(System.currentTimeMillis()+period), period); - } - - @Override - public void run() { - try { - GHRelease rel = gravitLauncher.getLatestRelease(); - Version relV = parseVer(rel.getTagName()); - if (relV == null) { - LogHelper.debug("Updater: parsing version error."); - return; - } - if (!parent.equals(relV)) parent = relV; - if (VERSION.major >= relV.major && VERSION.minor >= relV.minor - && VERSION.patch >= relV.patch && VERSION.build >= relV.build) return; - if (relV.release.equals(Type.STABLE) || relV.release.equals(Type.LTS)) { - LogHelper.warning("New %s release: %s", relV.getReleaseStatus(), relV.getVersionString()); - LogHelper.warning("You can download it: " + rel.getHtmlUrl().toString()); - LogHelper.warning("It`s published at: " + DATE_TIME_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(rel.getPublished_at().getTime()), ZoneId.systemDefault()))); - } else { - LogHelper.debug("New %s release: %s", relV.getReleaseStatus(), relV.getVersionString()); - LogHelper.debug("You can download it: " + rel.getHtmlUrl()); - LogHelper.debug("It`s published at: " + DATE_TIME_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(rel.getPublished_at().getTime()), ZoneId.systemDefault()))); - } - } catch (Throwable e) { - LogHelper.error(e); - } - } - - private static final Pattern startingVerPattern = Pattern.compile("\\d+\\.\\d+\\.\\d+\\.?\\d*"); - private static final Pattern pointPatternSpltitter = Pattern.compile("\\."); - - private static Version parseVer(String relS) { - Matcher verMatcher = startingVerPattern.matcher(relS); - if (!verMatcher.find()) return VERSION; - String[] ver = pointPatternSpltitter.split(relS.substring(verMatcher.start(), verMatcher.end())); - if (ver.length < 3) return VERSION; - return new Version(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]), - Integer.parseInt(ver[2]), ver.length > 3 ? Integer.parseInt(ver[3]) : 0, findRelType(relS.substring(verMatcher.end()))); - } - - private static Type findRelType(String substring) { - if (substring.isEmpty()) return Type.UNKNOWN; - String tS = substring; - if (tS.startsWith("-")) tS = tS.substring(1); - final String wrk = tS.toLowerCase(Locale.ENGLISH); - final AtomicReference t = new AtomicReference(Type.UNKNOWN); - Type.unModTypes.forEach((s, type) -> { - if (wrk.startsWith(s)) t.set(type); - }); - return t.get(); - } -}