mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-19 07:58:08 +00:00
configurable checking for updates
This commit is contained in:
@@ -40,7 +40,7 @@ public class ApplicationInfo {
|
||||
static {
|
||||
loadProperties();
|
||||
}
|
||||
|
||||
|
||||
private static void loadProperties() {
|
||||
Properties prop = new Properties();
|
||||
try {
|
||||
|
||||
@@ -224,6 +224,26 @@ public class Configuration {
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
public static final ConfigurationItem<Boolean> beginBlockOnNewLine = null;
|
||||
|
||||
@ConfigurationDefaultInt(1000 * 60 * 60 * 24)
|
||||
@ConfigurationDescription("Minimum time between automatic checks for updates on application start")
|
||||
@ConfigurationName("check.updates.delay")
|
||||
public static final ConfigurationItem<Integer> checkForUpdatesDelay = null;
|
||||
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
@ConfigurationDescription("Checking for stable version updates")
|
||||
@ConfigurationName("check.updates.stable")
|
||||
public static final ConfigurationItem<Boolean> checkForUpdatesStable = null;
|
||||
|
||||
@ConfigurationDefaultBoolean(false)
|
||||
@ConfigurationDescription("Checking for nightly version updates")
|
||||
@ConfigurationName("check.updates.nightly")
|
||||
public static final ConfigurationItem<Boolean> checkForUpdatesNightly = null;
|
||||
|
||||
@ConfigurationDefaultBoolean(true)
|
||||
@ConfigurationDescription("Automatic checking for updates on application start")
|
||||
@ConfigurationName("check.updates.enabled")
|
||||
public static final ConfigurationItem<Boolean> checkForUpdatesAuto = null;
|
||||
|
||||
private enum OSId {
|
||||
|
||||
WINDOWS, OSX, UNIX
|
||||
|
||||
@@ -1018,19 +1018,41 @@ public class Main {
|
||||
}
|
||||
|
||||
public static void autoCheckForUpdates() {
|
||||
Calendar lastUpdatesCheckDate = Configuration.lastUpdatesCheckDate.get();
|
||||
if ((lastUpdatesCheckDate == null) || (lastUpdatesCheckDate.getTime().getTime() < Calendar.getInstance().getTime().getTime() - 1000 * 60 * 60 * 24)) {
|
||||
checkForUpdates();
|
||||
if (Configuration.checkForUpdatesAuto.get()) {
|
||||
Calendar lastUpdatesCheckDate = Configuration.lastUpdatesCheckDate.get();
|
||||
if ((lastUpdatesCheckDate == null) || (lastUpdatesCheckDate.getTime().getTime() < Calendar.getInstance().getTime().getTime() - Configuration.checkForUpdatesDelay.get())) {
|
||||
checkForUpdates();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkForUpdates() {
|
||||
List<String> accepted = new ArrayList<>();
|
||||
if (Configuration.checkForUpdatesStable.get()) {
|
||||
accepted.add("stable");
|
||||
}
|
||||
if (Configuration.checkForUpdatesNightly.get()) {
|
||||
accepted.add("nightly");
|
||||
}
|
||||
|
||||
if (accepted.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String acceptVersions = "";
|
||||
for (String a : accepted) {
|
||||
if (!acceptVersions.equals("")) {
|
||||
acceptVersions += ",";
|
||||
}
|
||||
acceptVersions += a;
|
||||
}
|
||||
try {
|
||||
Socket sock = new Socket("www.free-decompiler.com", 80);
|
||||
OutputStream os = sock.getOutputStream();
|
||||
String currentLoc = Configuration.locale.get("en");
|
||||
os.write(("GET /flash/update.html?action=check¤tVersion=" + ApplicationInfo.version + " HTTP/1.1\r\n"
|
||||
os.write(("GET /flash/update.html?action=check¤tVersion=" + ApplicationInfo.version + "¤tBuild=" + ApplicationInfo.build + "¤tNightly=" + ApplicationInfo.nightly + " HTTP/1.1\r\n"
|
||||
+ "Host: www.free-decompiler.com\r\n"
|
||||
+ "X-Accept-Versions: " + acceptVersions + "\r\n"
|
||||
+ "User-Agent: " + ApplicationInfo.shortApplicationVerName + "\r\n"
|
||||
+ "Accept-Language: " + currentLoc + ("en".equals(currentLoc) ? "" : ", en;q=0.8") + "\r\n"
|
||||
+ "Connection: close\r\n"
|
||||
|
||||
Reference in New Issue
Block a user