Splits the code for reading the software version into its own function

This commit is contained in:
Kristian Knarvik 2021-08-17 19:32:11 +02:00
parent b6baa9ad6f
commit a79300732d

View File

@ -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 <p>The URL used for checking for updates</p>
* @param updateChannel <p>The release channel to use</p>
* @throws IOException <p>If the update data cannot be read</p>
* @return <p>An array of Channel, Version</p>
* @throws FileNotFoundException <p>If unable to find or read currentversion.csv</p>
*/
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 <p>The URL used for checking for updates</p>
* @param updateChannel <p>The release channel to use</p>
* @throws IOException <p>If the update data cannot be read</p>
*/
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();