mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
check snapshot update by timestamp
This commit is contained in:
@@ -20,10 +20,17 @@ package forge.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Provides access to information about the current version and build ID.
|
||||
*/
|
||||
public class BuildInfo {
|
||||
private static Date timestamp = null;
|
||||
// disable instantiation
|
||||
private BuildInfo() { }
|
||||
|
||||
@@ -46,6 +53,27 @@ public class BuildInfo {
|
||||
StringUtils.containsIgnoreCase(forgeVersion, "snapshot");
|
||||
}
|
||||
|
||||
public static Date getTimestamp() {
|
||||
if (timestamp != null)
|
||||
return timestamp;
|
||||
try {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String b = Files.readString(
|
||||
Paths.get(BuildInfo.class.getClassLoader().getResource("build.txt").toURI()),
|
||||
Charset.defaultCharset());
|
||||
timestamp = simpleDateFormat.parse(b);
|
||||
} catch (Exception ignored) {}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public static boolean verifyTimestamp(Date updateTimestamp) {
|
||||
if (updateTimestamp == null)
|
||||
return false;
|
||||
if (getTimestamp() == null)
|
||||
return false;
|
||||
System.err.println("Update Timestamp: " + updateTimestamp + "\nBuild Timestamp: " + getTimestamp());
|
||||
return updateTimestamp.after(getTimestamp());
|
||||
}
|
||||
public static String getUserAgent() {
|
||||
return "Forge/" + getVersionString();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@ import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
@@ -88,7 +90,8 @@ public enum FControl implements KeyEventDispatcher {
|
||||
private CloseAction closeAction;
|
||||
private final List<HostedMatch> currentMatches = Lists.newArrayList();
|
||||
private String snapsVersion = "", currentVersion = "";
|
||||
private boolean isSnapshot;
|
||||
private Date snapsTimestamp = null;
|
||||
private boolean isSnapshot, hasSnapsUpdate;
|
||||
private Localizer localizer;
|
||||
|
||||
public enum CloseAction {
|
||||
@@ -229,6 +232,10 @@ public enum FControl implements KeyEventDispatcher {
|
||||
if (isSnapshot && prefs.getPrefBoolean(FPref.CHECK_SNAPSHOT_AT_STARTUP)) {
|
||||
URL url = new URL("https://downloads.cardforge.org/dailysnapshots/version.txt");
|
||||
snapsVersion = FileUtil.readFileToString(url);
|
||||
url = new URL("https://downloads.cardforge.org/dailysnapshots/build.txt");
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
snapsTimestamp = simpleDateFormat.parse(FileUtil.readFileToString(url));
|
||||
hasSnapsUpdate = BuildInfo.verifyTimestamp(snapsTimestamp);
|
||||
}
|
||||
|
||||
} catch (Exception ignored) {}
|
||||
@@ -288,7 +295,7 @@ public enum FControl implements KeyEventDispatcher {
|
||||
return isSnapshot;
|
||||
}
|
||||
public String getSnapshotNotification() {
|
||||
if (!isSnapshot || snapsVersion.isEmpty() || currentVersion.equalsIgnoreCase(snapsVersion))
|
||||
if (!isSnapshot || !hasSnapsUpdate || snapsVersion.isEmpty() || currentVersion.equalsIgnoreCase(snapsVersion))
|
||||
return "";
|
||||
return getLocalizer().getMessage("lblNewSnapshotVersion", snapsVersion);
|
||||
}
|
||||
|
||||
@@ -455,6 +455,7 @@ public abstract class FTitleBarBase extends SkinnedMenuBar {
|
||||
}
|
||||
private void updateVisibility() {
|
||||
setVisible(!isVisible());
|
||||
setEnabled(isVisible());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.net.Socket;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -147,6 +149,16 @@ public class AutoUpdater {
|
||||
return false;
|
||||
}
|
||||
// If version doesn't match, it's assummably newer.
|
||||
if (buildVersion.contains("SNAPSHOT")) {
|
||||
try {
|
||||
URL url = new URL("https://downloads.cardforge.org/dailysnapshots/build.txt");
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date snapsTimestamp = simpleDateFormat.parse(FileUtil.readFileToString(url));
|
||||
return snapsTimestamp.after(BuildInfo.getTimestamp());
|
||||
} catch (Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user