mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
I think this should be working now!
This commit is contained in:
@@ -13,19 +13,24 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class AutoUpdater {
|
public class AutoUpdater {
|
||||||
|
private final String SNAPSHOT_VERSION_INDEX = "https://snapshots.cardforge.org/";
|
||||||
private final String SNAPSHOT_VERSION_URL = "https://snapshots.cardforge.org/version.txt";
|
private final String SNAPSHOT_VERSION_URL = "https://snapshots.cardforge.org/version.txt";
|
||||||
private final String SNAPSHOT_PACKAGE = "https://snapshots.cardforge.org/latest/";
|
private final String SNAPSHOT_PACKAGE = "https://snapshots.cardforge.org/latest/";
|
||||||
private final String RELEASE_VERSION_URL = "https://releases.cardforge.org/forge/forge-gui-desktop/version.txt";
|
private final String RELEASE_VERSION_URL = "https://releases.cardforge.org/forge/forge-gui-desktop/version.txt";
|
||||||
private final String RELEASE_PACKAGE = "https://releases.cardforge.org/latest/";
|
private final String RELEASE_PACKAGE = "https://releases.cardforge.org/latest/";
|
||||||
|
private final String RELEASE_MAVEN_METADATA = "https://releases.cardforge.org/forge/forge-gui-desktop/maven-metadata.xml";
|
||||||
|
private static final boolean VERSION_FROM_METADATA = true;
|
||||||
|
|
||||||
public static String[] updateChannels = new String[]{ "None", "Snapshot", "Release"};
|
public static String[] updateChannels = new String[]{ "None", "Snapshot", "Release"};
|
||||||
|
|
||||||
private boolean isLoading;
|
private boolean isLoading;
|
||||||
|
private String updateChannel;
|
||||||
private String version;
|
private String version;
|
||||||
private String buildVersion;
|
private String buildVersion;
|
||||||
private String versionUrlString;
|
private String versionUrlString;
|
||||||
@@ -35,6 +40,8 @@ public class AutoUpdater {
|
|||||||
public AutoUpdater(boolean loading) {
|
public AutoUpdater(boolean loading) {
|
||||||
// What do I need? Preferences? Splashscreen? UI? Skins?
|
// What do I need? Preferences? Splashscreen? UI? Skins?
|
||||||
isLoading = loading;
|
isLoading = loading;
|
||||||
|
final ForgePreferences.FPref updatePreference = ForgePreferences.FPref.AUTO_UPDATE;
|
||||||
|
updateChannel = "release"; //this.prefs.getPref(updatePreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean attemptToUpdate() {
|
public boolean attemptToUpdate() {
|
||||||
@@ -55,10 +62,6 @@ public class AutoUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean verifyUpdateable() {
|
private boolean verifyUpdateable() {
|
||||||
// Check the preferences
|
|
||||||
final ForgePreferences.FPref updatePreference = ForgePreferences.FPref.AUTO_UPDATE;
|
|
||||||
final String updateChannel = "release"; //this.prefs.getPref(updatePreference);
|
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
// TODO This doesn't work yet, because FSkin isn't loaded at the time.
|
// TODO This doesn't work yet, because FSkin isn't loaded at the time.
|
||||||
return false;
|
return false;
|
||||||
@@ -95,14 +98,17 @@ public class AutoUpdater {
|
|||||||
|
|
||||||
private boolean compareBuildWithLatestChannelVersion() {
|
private boolean compareBuildWithLatestChannelVersion() {
|
||||||
try {
|
try {
|
||||||
URL versionUrl = new URL(versionUrlString);
|
retrieveVersion();
|
||||||
version = FileUtil.readFileToString(versionUrl);
|
|
||||||
|
|
||||||
buildVersion = BuildInfo.getVersionString();
|
buildVersion = BuildInfo.getVersionString();
|
||||||
|
|
||||||
// Return false if buildVersion == GIT
|
if (buildVersion.contains("SNAPSHOT") && !updateChannel.equals("snapshot")) {
|
||||||
|
System.out.println("Snapshot build versions must use snapshot update channel to work");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (buildVersion.equalsIgnoreCase("GIT") || StringUtils.isEmpty(version) ) {
|
if (buildVersion.equalsIgnoreCase("GIT") || StringUtils.isEmpty(version) ) {
|
||||||
// return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buildVersion.equals(version)) {
|
if (buildVersion.equals(version)) {
|
||||||
@@ -116,6 +122,42 @@ public class AutoUpdater {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void retrieveVersion() throws MalformedURLException {
|
||||||
|
if (VERSION_FROM_METADATA) {
|
||||||
|
if (!updateChannel.equals("release")) {
|
||||||
|
extractVersionFromMavenRelease();
|
||||||
|
} else {
|
||||||
|
extractVersionFromSnapshotIndex();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
URL versionUrl = new URL(versionUrlString);
|
||||||
|
version = FileUtil.readFileToString(versionUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void extractVersionFromSnapshotIndex() throws MalformedURLException {
|
||||||
|
URL metadataUrl = new URL(SNAPSHOT_VERSION_INDEX);
|
||||||
|
String index = FileUtil.readFileToString(metadataUrl);
|
||||||
|
|
||||||
|
System.out.println(index);
|
||||||
|
Pattern p = Pattern.compile(">forge-(.*SNAPSHOT)");
|
||||||
|
Matcher m = p.matcher(index);
|
||||||
|
while(m.find()){
|
||||||
|
version = m.group(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void extractVersionFromMavenRelease() throws MalformedURLException {
|
||||||
|
URL metadataUrl = new URL(RELEASE_MAVEN_METADATA);
|
||||||
|
String xml = FileUtil.readFileToString(metadataUrl);
|
||||||
|
|
||||||
|
Pattern p = Pattern.compile("<release>(.*)</release>");
|
||||||
|
Matcher m = p.matcher(xml);
|
||||||
|
while(m.find()){
|
||||||
|
version = m.group(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean downloadUpdate() throws URISyntaxException, IOException {
|
private boolean downloadUpdate() throws URISyntaxException, IOException {
|
||||||
// We need to preload enough of a Skins to show a dialog and a button if we're in loading
|
// We need to preload enough of a Skins to show a dialog and a button if we're in loading
|
||||||
// splashScreen.prepareForDialogs();
|
// splashScreen.prepareForDialogs();
|
||||||
@@ -126,7 +168,7 @@ public class AutoUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String message = "A new version of Forge is available (" + version + ").\n" +
|
String message = "A new version of Forge is available (" + version + ").\n" +
|
||||||
"You are currently on an older version (" + buildVersion + ").\n\n" +
|
"You are currently on version (" + buildVersion + ").\n\n" +
|
||||||
"Would you like to update to the new version now?";
|
"Would you like to update to the new version now?";
|
||||||
|
|
||||||
final List<String> options = ImmutableList.of("Update Now", "Update Later");
|
final List<String> options = ImmutableList.of("Update Now", "Update Later");
|
||||||
|
|||||||
Reference in New Issue
Block a user