From 6c29cf56a8f654dffd5e8bca40d197df4f1253ae Mon Sep 17 00:00:00 2001 From: Chaos Date: Tue, 11 Jan 2022 22:25:31 +0100 Subject: [PATCH] More KT --- .../java/de/chaos/swlnmngr/UpdateChecker.kt | 32 ++++++++++++------- .../de/chaos/swlnmngr/config/CLIConfig.java | 5 +++ .../java/de/chaos/swlnmngr/route/Router.kt | 2 +- .../swlnmngr/route/routes/UpdateJarRoute.kt | 11 +++++++ 4 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 src/main/java/de/chaos/swlnmngr/route/routes/UpdateJarRoute.kt diff --git a/src/main/java/de/chaos/swlnmngr/UpdateChecker.kt b/src/main/java/de/chaos/swlnmngr/UpdateChecker.kt index 98c6190..7d16c70 100644 --- a/src/main/java/de/chaos/swlnmngr/UpdateChecker.kt +++ b/src/main/java/de/chaos/swlnmngr/UpdateChecker.kt @@ -1,8 +1,6 @@ package de.chaos.swlnmngr -import org.apache.http.client.methods.CloseableHttpResponse import org.apache.http.client.methods.HttpGet -import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients import java.io.IOException import java.net.URI @@ -11,14 +9,17 @@ import kotlin.system.exitProcess class UpdateChecker { companion object { @JvmStatic - val repoURL :URI = URI.create("https://steamwar.de/devlabs/repos/Chaoscaot/SteamwarLinkManager/releases") + val repoURL :URI = URI.create("https://steamwar.de/devlabs/Chaoscaot/SteamwarLinkManager/releases/latest") @JvmStatic - public val CURRENT_VERSION :String; + val download = URI.create("$repoURL/download/") + + @JvmStatic + public val CURRENT_VERSION :String init { try { - CURRENT_VERSION = String(UpdateChecker::class.java.getResourceAsStream("/jar.version").readAllBytes()); + CURRENT_VERSION = String(UpdateChecker::class.java.getResourceAsStream("/jar.version").readAllBytes()) } catch (e :IOException) { Main.getLogger().error("Could not read Version", e) exitProcess(1) @@ -28,14 +29,21 @@ class UpdateChecker { @JvmStatic fun checkForUpdates() { - val client :CloseableHttpClient = HttpClients.createMinimal() - client.use { client: CloseableHttpClient -> { - val get = HttpGet(repoURL); - val response :CloseableHttpResponse = client.execute(get) - response.use { response: CloseableHttpResponse -> { + val client = HttpClients.custom().disableRedirectHandling().build() + Main.getLogger().debug("Checking for Updates...") + val get = HttpGet(repoURL) + Main.getLogger().debug(get) + val response = client.execute(get) - }} - }} + Main.getLogger().debug(response.statusLine.toString()) + val latest = response.getFirstHeader("Location").value.replaceFirst(".*/".toRegex(), "") + if (latest != CURRENT_VERSION) { + Main.getLogger().info("The Running Jar is not the Latest release Version\n\tYour Version: {}\n\tLatest Release Version: {}", CURRENT_VERSION, latest) + Main.getLogger().info("Download the Latest Jar here: https://steamwar.de/devlabs/Chaoscaot/SteamwarLinkManager/releases/latest") + } + + response.close() + client.close() } } } diff --git a/src/main/java/de/chaos/swlnmngr/config/CLIConfig.java b/src/main/java/de/chaos/swlnmngr/config/CLIConfig.java index 058ece6..dc486ba 100644 --- a/src/main/java/de/chaos/swlnmngr/config/CLIConfig.java +++ b/src/main/java/de/chaos/swlnmngr/config/CLIConfig.java @@ -1,6 +1,7 @@ package de.chaos.swlnmngr.config; import de.chaos.swlnmngr.Main; +import de.chaos.swlnmngr.route.Router; import org.apache.commons.cli.*; import java.io.File; @@ -23,6 +24,7 @@ public class CLIConfig { options.addOption(new Option("c", "config", true, "Use another Config File")); options.addOption(new Option("i", "installdir", true, "Use other Install Dir")); options.addOption(new Option("u", "update-checker", false, "Enable the Auto-Update Checker")); + options.addOption(new Option(null, "update-the-fucking-jar-please", false, "Self Describing")); CommandLine cli = null; CommandLineParser parser = new DefaultParser(); @@ -67,5 +69,8 @@ public class CLIConfig { } else { CONFIG = new File(INSTALL_DIR, "config.json"); } + if(cli.hasOption("update-the-fucking-jar-please")) { + Router.route(new String[] {"update-jar"}); + } } } diff --git a/src/main/java/de/chaos/swlnmngr/route/Router.kt b/src/main/java/de/chaos/swlnmngr/route/Router.kt index ab295df..4cb08b1 100644 --- a/src/main/java/de/chaos/swlnmngr/route/Router.kt +++ b/src/main/java/de/chaos/swlnmngr/route/Router.kt @@ -9,7 +9,7 @@ class Router { companion object { @JvmStatic - val ROUTES :List = listOf(InstallRoute(), UpdateRoute(), LinkRoute(), NewRoute()) + val ROUTES :List = listOf(InstallRoute(), UpdateRoute(), LinkRoute(), NewRoute(), UpdateJarRoute()) @JvmStatic fun route(args: Array) { diff --git a/src/main/java/de/chaos/swlnmngr/route/routes/UpdateJarRoute.kt b/src/main/java/de/chaos/swlnmngr/route/routes/UpdateJarRoute.kt new file mode 100644 index 0000000..34e874a --- /dev/null +++ b/src/main/java/de/chaos/swlnmngr/route/routes/UpdateJarRoute.kt @@ -0,0 +1,11 @@ +package de.chaos.swlnmngr.route.routes + +class UpdateJarRoute :Route { + override fun getName(): String { + return "update-jar" + } + + override fun route(args: Array?): Boolean { + TODO("Not yet implemented") + } +} \ No newline at end of file