Added new update checker that can be version-specific or not

This commit is contained in:
Ellpeck 2016-01-10 20:51:29 +01:00
parent f575b4f8c1
commit b0558681d1
6 changed files with 41 additions and 13 deletions

View file

@ -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);

View file

@ -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"),

View file

@ -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);
}

View file

@ -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()){

View file

@ -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;
}

View file

@ -1 +1,2 @@
1.7.10-r20
1.7.10-r21
(This is a fallback for old versions which don't have the new update checker. Don't change.)