From b0558681d14a297125f8ee20b266861af4d38219 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 10 Jan 2016 20:51:29 +0100 Subject: [PATCH] Added new update checker that can be version-specific or not --- .../mod/booklet/GuiBooklet.java | 2 +- .../mod/config/values/ConfigBoolValues.java | 2 + .../mod/update/ThreadUpdateChecker.java | 42 +++++++++++++++---- .../mod/update/UpdateChecker.java | 3 +- .../UpdateCheckerClientNotificationEvent.java | 2 +- update/updateVersion.txt | 3 +- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java index dec0ba126..f6a49689a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java @@ -287,7 +287,7 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{ } else if(UpdateChecker.needsUpdateNotify){ updateHover.add(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.generic")).getFormattedText()); - updateHover.add(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID_LOWER+".update.versionCompare", ModUtil.VERSION, UpdateChecker.updateVersion)).getFormattedText()); + updateHover.add(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID_LOWER+".update.versionCompare", ModUtil.VERSION, UpdateChecker.updateVersionString)).getFormattedText()); updateHover.add(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.buttonOptions")); } this.buttonUpdate = new TexturedButton(4, this.guiLeft-11, this.guiTop-11, 245, 0, 11, 11, updateHover); 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..5e065ee18 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"), 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..3b47e63be 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,13 @@ package de.ellpeck.actuallyadditions.mod.update; +import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.util.ModUtil; +import de.ellpeck.actuallyadditions.mod.util.StringUtil; -import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; +import java.util.Properties; public class ThreadUpdateChecker extends Thread{ @@ -28,14 +30,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 +73,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..639fe0b39 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()){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateCheckerClientNotificationEvent.java b/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateCheckerClientNotificationEvent.java index 5b321bbe9..e4897f19e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateCheckerClientNotificationEvent.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/update/UpdateCheckerClientNotificationEvent.java @@ -36,7 +36,7 @@ public class UpdateCheckerClientNotificationEvent{ } else if(UpdateChecker.needsUpdateNotify){ player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.generic"))); - player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID_LOWER+".update.versionCompare", ModUtil.VERSION, UpdateChecker.updateVersion))); + player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID_LOWER+".update.versionCompare", ModUtil.VERSION, UpdateChecker.updateVersionString))); player.addChatComponentMessage(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID_LOWER+".update.buttons", UpdateChecker.CHANGELOG_LINK, UpdateChecker.DOWNLOAD_LINK))); notified = true; } 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