2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("ThreadUpdateChecker.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.update;
|
2015-07-10 20:04:07 +02:00
|
|
|
|
2016-01-10 20:59:13 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
2016-08-01 16:29:35 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
2015-07-10 20:04:07 +02:00
|
|
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.URL;
|
2016-01-10 20:59:13 +01:00
|
|
|
import java.util.Properties;
|
2015-07-10 20:04:07 +02:00
|
|
|
|
|
|
|
public class ThreadUpdateChecker extends Thread{
|
|
|
|
|
|
|
|
public ThreadUpdateChecker(){
|
2016-05-03 08:45:01 +02:00
|
|
|
this.setName(ModUtil.NAME+" Update Checker");
|
2015-07-10 20:04:07 +02:00
|
|
|
this.setDaemon(true);
|
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run(){
|
|
|
|
ModUtil.LOGGER.info("Starting Update Check...");
|
|
|
|
try{
|
2016-01-10 20:59:13 +01:00
|
|
|
URL newestURL = new URL("https://raw.githubusercontent.com/Ellpeck/ActuallyAdditions/master/update/updateVersions.properties");
|
|
|
|
Properties updateProperties = new Properties();
|
|
|
|
updateProperties.load(new InputStreamReader(newestURL.openStream()));
|
|
|
|
|
2016-08-01 16:29:35 +02:00
|
|
|
String currentMcVersion = Util.getMcVersion();
|
2016-01-10 20:59:13 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-01 16:29:35 +02:00
|
|
|
String clientVersionString = Util.getMajorModVersion();
|
2016-01-11 22:15:50 +01:00
|
|
|
int clientVersion = Integer.parseInt(clientVersionString.contains("_") ? clientVersionString.substring(0, clientVersionString.indexOf("_")) : clientVersionString);
|
2016-01-10 20:59:13 +01:00
|
|
|
if(UpdateChecker.updateVersionInt > clientVersion){
|
2015-10-28 18:28:30 +01:00
|
|
|
UpdateChecker.needsUpdateNotify = true;
|
|
|
|
}
|
2015-07-10 20:04:07 +02:00
|
|
|
|
|
|
|
ModUtil.LOGGER.info("Update Check done!");
|
|
|
|
}
|
|
|
|
catch(Exception e){
|
2015-07-10 21:19:52 +02:00
|
|
|
ModUtil.LOGGER.error("Update Check failed!", e);
|
|
|
|
UpdateChecker.checkFailed = true;
|
2015-07-10 20:04:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!UpdateChecker.checkFailed){
|
2015-10-28 18:28:30 +01:00
|
|
|
if(UpdateChecker.needsUpdateNotify){
|
|
|
|
ModUtil.LOGGER.info("There is an Update for "+ModUtil.NAME+" available!");
|
2016-01-10 20:59:13 +01:00
|
|
|
ModUtil.LOGGER.info("Current Version: "+ModUtil.VERSION+", newest Version: "+UpdateChecker.updateVersionString+"!");
|
2015-10-28 18:28:30 +01:00
|
|
|
ModUtil.LOGGER.info("View the Changelog at "+UpdateChecker.CHANGELOG_LINK);
|
|
|
|
ModUtil.LOGGER.info("Download at "+UpdateChecker.DOWNLOAD_LINK);
|
2015-07-10 20:04:07 +02:00
|
|
|
}
|
2015-10-13 02:12:30 +02:00
|
|
|
else{
|
2015-10-28 18:28:30 +01:00
|
|
|
ModUtil.LOGGER.info(ModUtil.NAME+" is up to date!");
|
2015-07-10 20:04:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|