mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Restore manual updater
This commit is contained in:
@@ -84,10 +84,9 @@ public enum VSubmenuDownloaders implements IVSubmenu<CSubmenuDownloaders> {
|
|||||||
pnlContent.setOpaque(false);
|
pnlContent.setOpaque(false);
|
||||||
|
|
||||||
if (javaRecentEnough()) {
|
if (javaRecentEnough()) {
|
||||||
// With Blacksmith we would upload the releases and the /latest would redirect to the right URL
|
// Github actions now uploading the latest version predictably. So we should be able to use this again.
|
||||||
// That currently doesn't happen so lets comment out this button for now
|
pnlContent.add(btnCheckForUpdates, constraintsBTN);
|
||||||
// pnlContent.add(btnCheckForUpdates, constraintsBTN);
|
pnlContent.add(_makeLabel(localizer.getMessage("lblCheckForUpdates")), constraintsLBL);
|
||||||
// pnlContent.add(_makeLabel(localizer.getMessage("lblCheckForUpdates")), constraintsLBL);
|
|
||||||
|
|
||||||
pnlContent.add(btnDownloadPics, constraintsBTN);
|
pnlContent.add(btnDownloadPics, constraintsBTN);
|
||||||
pnlContent.add(_makeLabel(localizer.getMessage("lblDownloadPics")), constraintsLBL);
|
pnlContent.add(_makeLabel(localizer.getMessage("lblDownloadPics")), constraintsLBL);
|
||||||
|
|||||||
@@ -31,22 +31,16 @@ import forge.util.WaitCallback;
|
|||||||
|
|
||||||
public class AutoUpdater {
|
public class AutoUpdater {
|
||||||
private final String SNAPSHOT_VERSION_INDEX = "https://downloads.cardforge.org/dailysnapshots/";
|
private final String SNAPSHOT_VERSION_INDEX = "https://downloads.cardforge.org/dailysnapshots/";
|
||||||
private final String SNAPSHOT_VERSION_URL = SNAPSHOT_VERSION_INDEX + "version.txt";
|
|
||||||
private final String SNAPSHOT_PACKAGE = SNAPSHOT_VERSION_INDEX + "latest/";
|
|
||||||
private final String RELEASE_VERSION_INDEX = "https://releases.cardforge.org/";
|
private final String RELEASE_VERSION_INDEX = "https://releases.cardforge.org/";
|
||||||
private final String RELEASE_VERSION_URL = RELEASE_VERSION_INDEX + "forge/forge-gui-desktop/version.txt";
|
|
||||||
private final String RELEASE_PACKAGE = RELEASE_VERSION_INDEX + "latest/";
|
|
||||||
private final String RELEASE_MAVEN_METADATA = RELEASE_VERSION_INDEX + "forge/forge-gui-desktop/maven-metadata.xml";
|
|
||||||
private static final boolean VERSION_FROM_METADATA = true;
|
private static final boolean VERSION_FROM_METADATA = true;
|
||||||
private static final String TMP_DIR = "tmp/";
|
|
||||||
private static final Localizer localizer = Localizer.getInstance();
|
private static final Localizer localizer = Localizer.getInstance();
|
||||||
|
|
||||||
public static String[] updateChannels = new String[]{ "none", "snapshot", "release"};
|
public static String[] updateChannels = new String[]{ "none", "snapshot", "release"};
|
||||||
|
|
||||||
private boolean isLoading;
|
private final boolean isLoading;
|
||||||
private String updateChannel;
|
private String updateChannel;
|
||||||
private String version;
|
private String version;
|
||||||
private String buildVersion;
|
private final String buildVersion;
|
||||||
private String versionUrlString;
|
private String versionUrlString;
|
||||||
private String packageUrl;
|
private String packageUrl;
|
||||||
private String packagePath;
|
private String packagePath;
|
||||||
@@ -58,6 +52,11 @@ public class AutoUpdater {
|
|||||||
buildVersion = BuildInfo.getVersionString();
|
buildVersion = BuildInfo.getVersionString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean updateAvailable() {
|
||||||
|
// TODO Check if an update is available, and add a UI element to notify the user.
|
||||||
|
return verifyUpdateable();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean attemptToUpdate() {
|
public boolean attemptToUpdate() {
|
||||||
if (!verifyUpdateable()) {
|
if (!verifyUpdateable()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -101,11 +100,13 @@ public class AutoUpdater {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
versionUrlString = SNAPSHOT_VERSION_URL;
|
versionUrlString = SNAPSHOT_VERSION_INDEX + "version.txt";
|
||||||
packageUrl = SNAPSHOT_PACKAGE;
|
|
||||||
} else {
|
} else {
|
||||||
versionUrlString = RELEASE_VERSION_URL;
|
if (!updateChannel.equals("release")) {
|
||||||
packageUrl = RELEASE_PACKAGE;
|
System.out.println("Release build versions must use release update channel to work");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
versionUrlString = RELEASE_VERSION_INDEX + "forge/forge-gui-desktop/version.txt";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the internet connection
|
// Check the internet connection
|
||||||
@@ -148,31 +149,21 @@ public class AutoUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void retrieveVersion() throws MalformedURLException {
|
private void retrieveVersion() throws MalformedURLException {
|
||||||
if (VERSION_FROM_METADATA) {
|
if (VERSION_FROM_METADATA && updateChannel.equals("release")) {
|
||||||
if (updateChannel.equals("release")) {
|
|
||||||
extractVersionFromMavenRelease();
|
extractVersionFromMavenRelease();
|
||||||
} else {
|
|
||||||
extractVersionFromSnapshotIndex();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
URL versionUrl = new URL(versionUrlString);
|
URL versionUrl = new URL(versionUrlString);
|
||||||
version = FileUtil.readFileToString(versionUrl);
|
version = FileUtil.readFileToString(versionUrl);
|
||||||
}
|
}
|
||||||
}
|
if (updateChannel.equals("release")) {
|
||||||
|
packageUrl = RELEASE_VERSION_INDEX + "forge/forge-gui-desktop/" + version + "/forge-gui-desktop-" + version + ".tar.bz2";
|
||||||
private void extractVersionFromSnapshotIndex() throws MalformedURLException {
|
} else {
|
||||||
URL metadataUrl = new URL(SNAPSHOT_VERSION_INDEX);
|
packageUrl = SNAPSHOT_VERSION_INDEX + "forge-gui-desktop-" + version + ".tar.bz2";
|
||||||
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 {
|
private void extractVersionFromMavenRelease() throws MalformedURLException {
|
||||||
|
String RELEASE_MAVEN_METADATA = RELEASE_VERSION_INDEX + "forge/forge-gui-desktop/maven-metadata.xml";
|
||||||
URL metadataUrl = new URL(RELEASE_MAVEN_METADATA);
|
URL metadataUrl = new URL(RELEASE_MAVEN_METADATA);
|
||||||
String xml = FileUtil.readFileToString(metadataUrl);
|
String xml = FileUtil.readFileToString(metadataUrl);
|
||||||
|
|
||||||
@@ -213,6 +204,7 @@ public class AutoUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean downloadFromForge() {
|
private boolean downloadFromForge() {
|
||||||
|
System.out.println("Downloading update from " + packageUrl + " to tmp/");
|
||||||
WaitCallback<Boolean> callback = new WaitCallback<Boolean>() {
|
WaitCallback<Boolean> callback = new WaitCallback<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -234,7 +226,7 @@ public class AutoUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void extractUpdate() {
|
private void extractUpdate() {
|
||||||
// TODOD Something like https://stackoverflow.com/questions/315618/how-do-i-extract-a-tar-file-in-java
|
// TODO Something like https://stackoverflow.com/questions/315618/how-do-i-extract-a-tar-file-in-java
|
||||||
final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
|
final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
|
||||||
if (desktop != null) {
|
if (desktop != null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import forge.card.CardType;
|
|||||||
import forge.deck.CardArchetypeLDAGenerator;
|
import forge.deck.CardArchetypeLDAGenerator;
|
||||||
import forge.deck.CardRelationMatrixGenerator;
|
import forge.deck.CardRelationMatrixGenerator;
|
||||||
import forge.deck.io.DeckPreferences;
|
import forge.deck.io.DeckPreferences;
|
||||||
import forge.download.AutoUpdater;
|
|
||||||
import forge.game.GameFormat;
|
import forge.game.GameFormat;
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.game.card.CardUtil;
|
import forge.game.card.CardUtil;
|
||||||
@@ -162,9 +161,7 @@ public final class FModel {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (new AutoUpdater(true).attemptToUpdate()) {
|
//if (new AutoUpdater(true).attemptToUpdate()) {}
|
||||||
//
|
|
||||||
}
|
|
||||||
// load types before loading cards
|
// load types before loading cards
|
||||||
loadDynamicGamedata();
|
loadDynamicGamedata();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user