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

85 lines
3.6 KiB
Java
Raw Normal View History

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
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.update;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.util.Util;
2019-05-02 09:10:29 +02:00
public class ThreadUpdateChecker extends Thread {
2019-05-02 09:10:29 +02:00
public ThreadUpdateChecker() {
this.setName(ActuallyAdditions.NAME + " Update Checker");
this.setDaemon(true);
this.start();
}
@Override
2019-05-02 09:10:29 +02:00
public void run() {
2018-05-10 11:38:58 +02:00
ActuallyAdditions.LOGGER.info("Starting Update Check...");
2019-05-02 09:10:29 +02:00
try {
2020-11-07 14:38:30 +01:00
URL newestURL = new URL("https://raw.githubusercontent.com/Ellpeck/ActuallyAdditions/main/update/updateVersions.properties");
Properties updateProperties = new Properties();
updateProperties.load(new InputStreamReader(newestURL.openStream()));
String currentMcVersion = Util.getMcVersion();
2019-05-02 09:10:29 +02:00
if (ConfigBoolValues.UPDATE_CHECK_VERSION_SPECIFIC.isEnabled()) {
String newestVersionProp = updateProperties.getProperty(currentMcVersion);
UpdateChecker.updateVersionInt = Integer.parseInt(newestVersionProp);
2019-05-02 09:10:29 +02:00
UpdateChecker.updateVersionString = currentMcVersion + "-r" + newestVersionProp;
} else {
int highest = 0;
String highestString = "";
2019-05-02 09:10:29 +02:00
for (String updateMC : updateProperties.stringPropertyNames()) {
String updateVersion = updateProperties.getProperty(updateMC);
int update = Integer.parseInt(updateVersion);
2019-05-02 09:10:29 +02:00
if (highest < update) {
highest = update;
2019-05-02 09:10:29 +02:00
highestString = updateMC + "-r" + updateVersion;
}
}
UpdateChecker.updateVersionInt = highest;
UpdateChecker.updateVersionString = highestString;
}
String clientVersionString = Util.getMajorModVersion();
2016-01-11 22:15:50 +01:00
int clientVersion = Integer.parseInt(clientVersionString.contains("_") ? clientVersionString.substring(0, clientVersionString.indexOf("_")) : clientVersionString);
2019-05-02 09:10:29 +02:00
if (UpdateChecker.updateVersionInt > clientVersion) {
UpdateChecker.needsUpdateNotify = true;
}
2018-05-10 11:38:58 +02:00
ActuallyAdditions.LOGGER.info("Update Check done!");
2019-05-02 09:10:29 +02:00
} catch (Exception e) {
2018-05-10 11:38:58 +02:00
ActuallyAdditions.LOGGER.error("Update Check failed!", e);
2015-07-10 21:19:52 +02:00
UpdateChecker.checkFailed = true;
}
2019-05-02 09:10:29 +02:00
if (!UpdateChecker.checkFailed) {
if (UpdateChecker.needsUpdateNotify) {
ActuallyAdditions.LOGGER.info("There is an Update for " + ActuallyAdditions.NAME + " available!");
ActuallyAdditions.LOGGER.info("Current Version: " + ActuallyAdditions.VERSION + ", newest Version: " + UpdateChecker.updateVersionString + "!");
ActuallyAdditions.LOGGER.info("View the Changelog at " + UpdateChecker.CHANGELOG_LINK);
ActuallyAdditions.LOGGER.info("Download at " + UpdateChecker.DOWNLOAD_LINK);
} else {
ActuallyAdditions.LOGGER.info(ActuallyAdditions.NAME + " is up to date!");
}
}
UpdateChecker.threadFinished = true;
}
}