1
0
Dieser Commit ist enthalten in:
Chaos 2022-01-11 22:25:31 +01:00
Ursprung 5c2ffde227
Commit 6c29cf56a8
4 geänderte Dateien mit 37 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -1,8 +1,6 @@
package de.chaos.swlnmngr package de.chaos.swlnmngr
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpGet import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClients import org.apache.http.impl.client.HttpClients
import java.io.IOException import java.io.IOException
import java.net.URI import java.net.URI
@ -11,14 +9,17 @@ import kotlin.system.exitProcess
class UpdateChecker { class UpdateChecker {
companion object { companion object {
@JvmStatic @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 @JvmStatic
public val CURRENT_VERSION :String; val download = URI.create("$repoURL/download/")
@JvmStatic
public val CURRENT_VERSION :String
init { init {
try { try {
CURRENT_VERSION = String(UpdateChecker::class.java.getResourceAsStream("/jar.version").readAllBytes()); CURRENT_VERSION = String(UpdateChecker::class.java.getResourceAsStream("/jar.version").readAllBytes())
} catch (e :IOException) { } catch (e :IOException) {
Main.getLogger().error("Could not read Version", e) Main.getLogger().error("Could not read Version", e)
exitProcess(1) exitProcess(1)
@ -28,14 +29,21 @@ class UpdateChecker {
@JvmStatic @JvmStatic
fun checkForUpdates() { fun checkForUpdates() {
val client :CloseableHttpClient = HttpClients.createMinimal() val client = HttpClients.custom().disableRedirectHandling().build()
client.use { client: CloseableHttpClient -> { Main.getLogger().debug("Checking for Updates...")
val get = HttpGet(repoURL); val get = HttpGet(repoURL)
val response :CloseableHttpResponse = client.execute(get) Main.getLogger().debug(get)
response.use { response: CloseableHttpResponse -> { 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()
} }
} }
} }

Datei anzeigen

@ -1,6 +1,7 @@
package de.chaos.swlnmngr.config; package de.chaos.swlnmngr.config;
import de.chaos.swlnmngr.Main; import de.chaos.swlnmngr.Main;
import de.chaos.swlnmngr.route.Router;
import org.apache.commons.cli.*; import org.apache.commons.cli.*;
import java.io.File; 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("c", "config", true, "Use another Config File"));
options.addOption(new Option("i", "installdir", true, "Use other Install Dir")); 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("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; CommandLine cli = null;
CommandLineParser parser = new DefaultParser(); CommandLineParser parser = new DefaultParser();
@ -67,5 +69,8 @@ public class CLIConfig {
} else { } else {
CONFIG = new File(INSTALL_DIR, "config.json"); CONFIG = new File(INSTALL_DIR, "config.json");
} }
if(cli.hasOption("update-the-fucking-jar-please")) {
Router.route(new String[] {"update-jar"});
}
} }
} }

Datei anzeigen

@ -9,7 +9,7 @@ class Router {
companion object { companion object {
@JvmStatic @JvmStatic
val ROUTES :List<Route> = listOf(InstallRoute(), UpdateRoute(), LinkRoute(), NewRoute()) val ROUTES :List<Route> = listOf(InstallRoute(), UpdateRoute(), LinkRoute(), NewRoute(), UpdateJarRoute())
@JvmStatic @JvmStatic
fun route(args: Array<String>) { fun route(args: Array<String>) {

Datei anzeigen

@ -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<out String>?): Boolean {
TODO("Not yet implemented")
}
}