ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/update/ThreadUpdateChecker.java

66 lines
2.8 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("ThreadUpdateChecker.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* <EFBFBD> 2015 Ellpeck
*/
package ellpeck.actuallyadditions.update;
import ellpeck.actuallyadditions.util.ModUtil;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class ThreadUpdateChecker extends Thread{
public ThreadUpdateChecker(){
2015-10-02 16:48:01 +02:00
this.setName(ModUtil.MOD_ID+" Update Checker");
this.setDaemon(true);
this.start();
}
@Override
public void run(){
ModUtil.LOGGER.info("Starting Update Check...");
try{
URL newestURL = new URL("https://raw.githubusercontent.com/Ellpeck/ActuallyAdditions/master/update/newestVersion.txt");
BufferedReader newestReader = new BufferedReader(new InputStreamReader(newestURL.openStream()));
UpdateChecker.updateVersionS = newestReader.readLine();
newestReader.close();
URL changeURL = new URL("https://raw.githubusercontent.com/Ellpeck/ActuallyAdditions/master/update/changelog.txt");
BufferedReader changeReader = new BufferedReader(new InputStreamReader(changeURL.openStream()));
UpdateChecker.changelog = changeReader.readLine();
changeReader.close();
ModUtil.LOGGER.info("Update Check done!");
2015-10-13 02:12:30 +02:00
UpdateChecker.updateVersion = Integer.parseInt(UpdateChecker.updateVersionS.replace("-", "").replace(".", ""));
UpdateChecker.clientVersion = Integer.parseInt(ModUtil.VERSION.replace("-", "").replace(".", ""));
}
catch(Exception e){
2015-07-10 21:19:52 +02:00
ModUtil.LOGGER.error("Update Check failed!", e);
UpdateChecker.checkFailed = true;
}
if(!UpdateChecker.checkFailed){
2015-10-13 02:12:30 +02:00
if(UpdateChecker.updateVersion > UpdateChecker.clientVersion){
ModUtil.LOGGER.info("There is an Update for "+ModUtil.MOD_ID+" available!");
ModUtil.LOGGER.info("The installed Version is "+ModUtil.VERSION+", but the newest Version is "+UpdateChecker.updateVersionS+"!");
ModUtil.LOGGER.info("The Changes are: "+UpdateChecker.changelog);
ModUtil.LOGGER.info("Download the newest Version at "+UpdateChecker.DOWNLOAD_LINK);
}
2015-10-13 02:12:30 +02:00
else{
ModUtil.LOGGER.info("There is no new Update for "+ModUtil.MOD_ID+" available!");
ModUtil.LOGGER.info("That's cool. You're really up to date, you have all of the latest awesome Features!");
}
}
UpdateChecker.doneChecking = true;
}
}