From a79300732db43a3bc61050523adfcac5ee53c20c Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 17 Aug 2021 19:32:11 +0200 Subject: [PATCH] Splits the code for reading the software version into its own function --- .../utility/Updater.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/utility/Updater.java b/src/main/java/net/knarcraft/minecraftserverlauncher/utility/Updater.java index a44e104..741999e 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/utility/Updater.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/utility/Updater.java @@ -29,13 +29,12 @@ public final class Updater { private static final String targetFile = "minecraft-server-launcher.jar"; /** - * Checks if a newer version is available + * Gets the version channel and version of this software instance * - * @param updateURL

The URL used for checking for updates

- * @param updateChannel

The release channel to use

- * @throws IOException

If the update data cannot be read

+ * @return

An array of Channel, Version

+ * @throws FileNotFoundException

If unable to find or read currentversion.csv

*/ - public static void checkForUpdate(String updateURL, String updateChannel) throws IOException { + public static String[] getCurrentVersion() throws FileNotFoundException { Scanner file = getResourceAsScanner("currentversion.csv"); if (!file.hasNextLine()) { throw new FileNotFoundException("File currentversion.csv is invalid"); @@ -46,6 +45,20 @@ public final class Updater { } String oldVer = file.nextLine(); file.close(); + return new String[]{oldType, oldVer}; + } + + /** + * Checks if a newer version is available + * + * @param updateURL

The URL used for checking for updates

+ * @param updateChannel

The release channel to use

+ * @throws IOException

If the update data cannot be read

+ */ + public static void checkForUpdate(String updateURL, String updateChannel) throws IOException { + String[] oldData = getCurrentVersion(); + String oldType = oldData[0]; + String oldVer = oldData[1]; String data = readRemoteFile(updateURL); JsonObject jsonObject = new JsonParser().parse(data).getAsJsonObject();