From 2620687e2d99cdbb447673792e4cedb554431350 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 10 Jan 2016 20:59:13 +0100 Subject: [PATCH] Added the new update checker for 1.8 as well --- .../mod/config/values/ConfigBoolValues.java | 4 +- .../mod/update/ThreadUpdateChecker.java | 41 +++++++++++++++---- .../mod/update/UpdateChecker.java | 5 ++- update/updateVersion.txt | 3 +- update/updateVersions.properties | 2 + 5 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 update/updateVersions.properties diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java index 617d3f79d..be7b70a34 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java @@ -23,6 +23,8 @@ public enum ConfigBoolValues{ GENERATE_QUARTZ("Black Quartz", ConfigCategories.WORLD_GEN, true, "If the Black Quartz generates in the world"), DO_UPDATE_CHECK("Do Update Check", ConfigCategories.OTHER, true, "If Actually Additions should check for an Update on joining a World"), + UPDATE_CHECK_VERSION_SPECIFIC("Version Specific Update Checker", ConfigCategories.OTHER, false, "If Actually Additions' Update Check should only search for updates for the Minecraft Version you currently have"), + DO_CAT_DROPS("Do Cat Drops", ConfigCategories.OTHER, true, "If Cats drop Hairy Balls on Occasion"), TF_PAXELS("Thermal Foundation Paxels", ConfigCategories.OTHER, true, "If Paxels made of Thermal Foundation Materials should exist"), @@ -73,4 +75,4 @@ public enum ConfigBoolValues{ return this.currentValue; } -} +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/update/ThreadUpdateChecker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/update/ThreadUpdateChecker.java index f82eab39c..2d6bff7b0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/update/ThreadUpdateChecker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/update/ThreadUpdateChecker.java @@ -10,11 +10,12 @@ package de.ellpeck.actuallyadditions.mod.update; +import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.util.ModUtil; -import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; +import java.util.Properties; public class ThreadUpdateChecker extends Thread{ @@ -28,14 +29,36 @@ public class ThreadUpdateChecker extends Thread{ public void run(){ ModUtil.LOGGER.info("Starting Update Check..."); try{ - URL newestURL = new URL("https://raw.githubusercontent.com/Ellpeck/ActuallyAdditions/master/update/updateVersion.txt"); - BufferedReader newestReader = new BufferedReader(new InputStreamReader(newestURL.openStream())); - UpdateChecker.updateVersion = newestReader.readLine(); - newestReader.close(); + URL newestURL = new URL("https://raw.githubusercontent.com/Ellpeck/ActuallyAdditions/master/update/updateVersions.properties"); + Properties updateProperties = new Properties(); + updateProperties.load(new InputStreamReader(newestURL.openStream())); - int updateVersion = Integer.parseInt(UpdateChecker.updateVersion.replace("-", "").replace(".", "").replace("r", "")); - int clientVersion = Integer.parseInt(ModUtil.VERSION.replace("-", "").replace(".", "").replace("r", "")); - if(updateVersion > clientVersion){ + String currentMcVersion = ModUtil.VERSION.split("-")[0]; + if(ConfigBoolValues.UPDATE_CHECK_VERSION_SPECIFIC.isEnabled()){ + String newestVersionProp = updateProperties.getProperty(currentMcVersion); + + UpdateChecker.updateVersionInt = Integer.parseInt(newestVersionProp); + UpdateChecker.updateVersionString = currentMcVersion+"-r"+newestVersionProp; + } + else{ + int highest = 0; + String highestString = ""; + + for(String updateMC : updateProperties.stringPropertyNames()){ + String updateVersion = updateProperties.getProperty(updateMC); + int update = Integer.parseInt(updateVersion); + if(highest < update){ + highest = update; + highestString = updateMC+"-r"+updateVersion; + } + } + + UpdateChecker.updateVersionInt = highest; + UpdateChecker.updateVersionString = highestString; + } + + int clientVersion = Integer.parseInt(ModUtil.VERSION.substring(ModUtil.VERSION.indexOf("r")+1)); + if(UpdateChecker.updateVersionInt > clientVersion){ UpdateChecker.needsUpdateNotify = true; } @@ -49,7 +72,7 @@ public class ThreadUpdateChecker extends Thread{ if(!UpdateChecker.checkFailed){ if(UpdateChecker.needsUpdateNotify){ ModUtil.LOGGER.info("There is an Update for "+ModUtil.NAME+" available!"); - ModUtil.LOGGER.info("Current Version: "+ModUtil.VERSION+", newest Version: "+UpdateChecker.updateVersion+"!"); + ModUtil.LOGGER.info("Current Version: "+ModUtil.VERSION+", newest Version: "+UpdateChecker.updateVersionString+"!"); ModUtil.LOGGER.info("View the Changelog at "+UpdateChecker.CHANGELOG_LINK); ModUtil.LOGGER.info("Download at "+UpdateChecker.DOWNLOAD_LINK); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateChecker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateChecker.java index 046bcaca7..75cab1a33 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateChecker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateChecker.java @@ -20,7 +20,8 @@ public class UpdateChecker{ public static final String CHANGELOG_LINK = "http://ellpeck.de/actaddchangelog/"; public static boolean checkFailed; public static boolean needsUpdateNotify; - public static String updateVersion; + public static int updateVersionInt; + public static String updateVersionString; public static void init(){ if(ConfigBoolValues.DO_UPDATE_CHECK.isEnabled() && !Util.isDevVersion()){ @@ -28,4 +29,4 @@ public class UpdateChecker{ new ThreadUpdateChecker(); } } -} +} \ No newline at end of file diff --git a/update/updateVersion.txt b/update/updateVersion.txt index 42392d70f..7d90cb450 100644 --- a/update/updateVersion.txt +++ b/update/updateVersion.txt @@ -1 +1,2 @@ -1.7.10-r20 \ No newline at end of file +1.7.10-r21 +(This is a fallback for old versions which don't have the new update checker. Don't change.) \ No newline at end of file diff --git a/update/updateVersions.properties b/update/updateVersions.properties new file mode 100644 index 000000000..0ec2048c7 --- /dev/null +++ b/update/updateVersions.properties @@ -0,0 +1,2 @@ +1.7.10=21 +1.8.9=22 \ No newline at end of file