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;
|
2015-07-10 20:04:07 +02:00
|
|
|
|
2017-06-29 18:36:33 +02:00
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
2018-05-10 11:40:16 +02:00
|
|
|
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 {
|
2015-07-10 20:04:07 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public ThreadUpdateChecker() {
|
|
|
|
this.setName(ActuallyAdditions.NAME + " Update Checker");
|
2015-07-10 20:04:07 +02:00
|
|
|
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");
|
2016-01-10 20:59:13 +01:00
|
|
|
Properties updateProperties = new Properties();
|
|
|
|
updateProperties.load(new InputStreamReader(newestURL.openStream()));
|
|
|
|
|
2016-08-01 16:29:35 +02:00
|
|
|
String currentMcVersion = Util.getMcVersion();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (ConfigBoolValues.UPDATE_CHECK_VERSION_SPECIFIC.isEnabled()) {
|
2016-01-10 20:59:13 +01:00
|
|
|
String newestVersionProp = updateProperties.getProperty(currentMcVersion);
|
|
|
|
|
|
|
|
UpdateChecker.updateVersionInt = Integer.parseInt(newestVersionProp);
|
2019-05-02 09:10:29 +02:00
|
|
|
UpdateChecker.updateVersionString = currentMcVersion + "-r" + newestVersionProp;
|
|
|
|
} else {
|
2016-01-10 20:59:13 +01:00
|
|
|
int highest = 0;
|
|
|
|
String highestString = "";
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
for (String updateMC : updateProperties.stringPropertyNames()) {
|
2016-01-10 20:59:13 +01:00
|
|
|
String updateVersion = updateProperties.getProperty(updateMC);
|
|
|
|
int update = Integer.parseInt(updateVersion);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (highest < update) {
|
2016-01-10 20:59:13 +01:00
|
|
|
highest = update;
|
2019-05-02 09:10:29 +02:00
|
|
|
highestString = updateMC + "-r" + updateVersion;
|
2016-01-10 20:59:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (UpdateChecker.updateVersionInt > clientVersion) {
|
2015-10-28 18:28:30 +01:00
|
|
|
UpdateChecker.needsUpdateNotify = true;
|
|
|
|
}
|
2015-07-10 20:04:07 +02:00
|
|
|
|
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;
|
2015-07-10 20:04:07 +02:00
|
|
|
}
|
|
|
|
|
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!");
|
2015-07-10 20:04:07 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-11 01:10:26 +02:00
|
|
|
|
|
|
|
UpdateChecker.threadFinished = true;
|
2015-07-10 20:04:07 +02:00
|
|
|
}
|
|
|
|
}
|