move hardcoded url to ForgeConstants

This commit is contained in:
Anthony Calosa
2024-10-28 19:27:41 +08:00
parent 0b5c3c54bd
commit ad9b6e57bd
5 changed files with 39 additions and 25 deletions

View File

@@ -72,6 +72,8 @@ import forge.util.TextUtil;
import forge.view.FFrame;
import forge.view.FView;
import static forge.localinstance.properties.ForgeConstants.DAILY_SNAPSHOT_URL;
/**
* <p>
* FControl.
@@ -244,9 +246,9 @@ public enum FControl implements KeyEventDispatcher {
//get version string
try {
if (isSnapshot && prefs.getPrefBoolean(FPref.CHECK_SNAPSHOT_AT_STARTUP)) {
URL url = new URL("https://downloads.cardforge.org/dailysnapshots/version.txt");
URL url = new URL(DAILY_SNAPSHOT_URL + "version.txt");
snapsVersion = FileUtil.readFileToString(url);
url = new URL("https://downloads.cardforge.org/dailysnapshots/build.txt");
url = new URL(DAILY_SNAPSHOT_URL + "build.txt");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
snapsTimestamp = simpleDateFormat.parse(FileUtil.readFileToString(url));
buildTimeStamp = BuildInfo.getTimestamp();

View File

@@ -16,6 +16,8 @@ import forge.util.BuildInfo;
import forge.util.FileUtil;
import forge.util.Localizer;
import static forge.localinstance.properties.ForgeConstants.GITHUB_FORGE_URL;
public final class HelpMenu {
private HelpMenu() { }
@@ -71,8 +73,8 @@ public final class HelpMenu {
JMenu mnu = new JMenu(localizer.getMessage("lblGettingStarted"));
mnu.add(getMenuItem_HowToPlayFile());
mnu.addSeparator();
mnu.add(getMenuItem_UrlLink("Forge Wiki", "https://github.com/Card-Forge/forge/wiki", KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)));
mnu.add(getMenuItem_UrlLink("What is Forge?", "https://github.com/Card-Forge/forge/wiki#what-is-forge"));
mnu.add(getMenuItem_UrlLink("Forge Wiki", GITHUB_FORGE_URL + "wiki", KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)));
mnu.add(getMenuItem_UrlLink("What is Forge?", GITHUB_FORGE_URL + "wiki#what-is-forge"));
return mnu;
}

View File

@@ -18,11 +18,17 @@ import forge.Forge;
import forge.gui.FThreads;
import forge.gui.download.GuiDownloadZipService;
import forge.gui.util.SOptionPane;
import forge.localinstance.properties.ForgeConstants;
import forge.util.FileUtil;
import static forge.localinstance.properties.ForgeConstants.ADV_TEXTURE_BG_FILE;
import static forge.localinstance.properties.ForgeConstants.ASSETS_DIR;
import static forge.localinstance.properties.ForgeConstants.DAILY_SNAPSHOT_URL;
import static forge.localinstance.properties.ForgeConstants.DEFAULT_SKINS_DIR;
import static forge.localinstance.properties.ForgeConstants.GITHUB_COMMITS_URL_ATOM;
import static forge.localinstance.properties.ForgeConstants.GITHUB_FORGE_URL;
import static forge.localinstance.properties.ForgeConstants.GITHUB_RELEASES_URL_ATOM;
import static forge.localinstance.properties.ForgeConstants.RELEASE_URL;
import static forge.localinstance.properties.ForgeConstants.RES_DIR;
public class AssetsDownloader {
private final static ImmutableList<String> downloadIgnoreExit = ImmutableList.of("Download", "Ignore", "Exit");
@@ -44,11 +50,11 @@ public class AssetsDownloader {
final String apkSize = "12MB";
final boolean isSnapshots = versionString.contains("SNAPSHOT");
final String snapsURL = "https://downloads.cardforge.org/dailysnapshots/";
final String releaseURL = "https://releases.cardforge.org/forge/forge-gui-android/";
final String snapsURL = DAILY_SNAPSHOT_URL;
final String releaseURL = RELEASE_URL + "forge/forge-gui-android/";
final String versionText = isSnapshots ? snapsURL + "version.txt" : releaseURL + "version.txt";
FileHandle assetsDir = Gdx.files.absolute(ForgeConstants.ASSETS_DIR);
FileHandle resDir = Gdx.files.absolute(ForgeConstants.RES_DIR);
FileHandle assetsDir = Gdx.files.absolute(ASSETS_DIR);
FileHandle resDir = Gdx.files.absolute(RES_DIR);
FileHandle buildTxtFileHandle = Gdx.files.classpath("build.txt");
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
boolean verifyUpdatable = false;
@@ -71,8 +77,8 @@ public class AssetsDownloader {
} else {
//current release on github is tar.bz2, update this to jar installer in the future...
filename = isSnapshots ? "forge-installer-" + version + ".jar" : releaseTag.replace("forge-", "forge-gui-desktop-") + ".tar.bz2";
String releaseBZ2URL = "https://github.com/Card-Forge/forge/releases/download/" + releaseTag + "/" + filename;
String snapsBZ2URL = "https://downloads.cardforge.org/dailysnapshots/";
String releaseBZ2URL = GITHUB_FORGE_URL + "releases/download/" + releaseTag + "/" + filename;
String snapsBZ2URL = DAILY_SNAPSHOT_URL;
installerURL = isSnapshots ? snapsBZ2URL : releaseBZ2URL;
}
String snapsBuildDate = "", buildDate = "";
@@ -97,8 +103,8 @@ public class AssetsDownloader {
if (verifyUpdatable) {
Forge.getSplashScreen().prepareForDialogs();
message = "A new version of Forge is available. - v." + version + "\n" + snapsBuildDate + "\n" +
"You are currently on an older version. - v." + versionString + "\n" + buildDate + "\n" +
message = "A new version of Forge is available.\n(v." + version + " | " + snapsBuildDate + ")\n" +
"You are currently on an older version.\n(v." + versionString + " | " + buildDate + ")\n" +
"Would you like to update to the new version now?";
if (!Forge.getDeviceAdapter().isConnectedToWifi()) {
message += " If so, you may want to connect to wifi first. The download is around " + (GuiBase.isAndroid() ? apkSize : packageSize) + ".";
@@ -158,7 +164,7 @@ public class AssetsDownloader {
String log = "";
//see if assets need updating
FileHandle advBG = Gdx.files.absolute(ForgeConstants.DEFAULT_SKINS_DIR).child(ForgeConstants.ADV_TEXTURE_BG_FILE);
FileHandle advBG = Gdx.files.absolute(DEFAULT_SKINS_DIR).child(ADV_TEXTURE_BG_FILE);
if (!advBG.exists()) {
FileHandle deleteVersion = assetsDir.child("version.txt");
if (deleteVersion.exists())
@@ -265,7 +271,7 @@ public class AssetsDownloader {
boolean allowDeletion = Forge.androidVersion < 30 || GuiBase.isUsingAppDirectory();
String assetURL = isSnapshots ? snapsURL + "assets.zip" : releaseURL + versionString + "/" + "assets.zip";
new GuiDownloadZipService("", "resource files", assetURL,
ForgeConstants.ASSETS_DIR, ForgeConstants.RES_DIR, Forge.getSplashScreen().getProgressBar(), allowDeletion).downloadAndUnzip();
ASSETS_DIR, RES_DIR, Forge.getSplashScreen().getProgressBar(), allowDeletion).downloadAndUnzip();
if (allowDeletion)
FSkinFont.deleteCachedFiles(); //delete cached font files in case any skin's .ttf file changed

View File

@@ -34,9 +34,10 @@ import forge.util.Localizer;
import forge.util.TextUtil;
import forge.util.WaitCallback;
import static forge.localinstance.properties.ForgeConstants.DAILY_SNAPSHOT_URL;
import static forge.localinstance.properties.ForgeConstants.RELEASE_URL;
public class AutoUpdater {
private final String SNAPSHOT_VERSION_INDEX = "https://downloads.cardforge.org/dailysnapshots/";
private final String RELEASE_VERSION_INDEX = "https://releases.cardforge.org/";
private static final boolean VERSION_FROM_METADATA = true;
private static final Localizer localizer = Localizer.getInstance();
@@ -107,13 +108,13 @@ public class AutoUpdater {
return false;
}
versionUrlString = SNAPSHOT_VERSION_INDEX + "version.txt";
versionUrlString = DAILY_SNAPSHOT_URL + "version.txt";
} else {
if (!updateChannel.equalsIgnoreCase(localizer.getMessageorUseDefault("lblRelease", "Release"))) {
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";
versionUrlString = RELEASE_URL + "forge/forge-gui-desktop/version.txt";
}
// Check the internet connection
@@ -139,7 +140,7 @@ public class AutoUpdater {
try {
retrieveVersion();
if (buildVersion.contains("SNAPSHOT")) {
URL url = new URL("https://downloads.cardforge.org/dailysnapshots/build.txt");
URL url = new URL(DAILY_SNAPSHOT_URL + "build.txt");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date snapsTimestamp = simpleDateFormat.parse(FileUtil.readFileToString(url));
snapsBuildDate = snapsTimestamp.toString();
@@ -170,14 +171,14 @@ public class AutoUpdater {
version = FileUtil.readFileToString(versionUrl);
}
if (updateChannel.equalsIgnoreCase(localizer.getMessageorUseDefault("lblRelease", "Release"))) {
packageUrl = RELEASE_VERSION_INDEX + "forge/forge-gui-desktop/" + version + "/forge-gui-desktop-" + version + ".tar.bz2";
packageUrl = RELEASE_URL + "forge/forge-gui-desktop/" + version + "/forge-gui-desktop-" + version + ".tar.bz2";
} else {
packageUrl = SNAPSHOT_VERSION_INDEX + "forge-installer-" + version + ".jar";
packageUrl = DAILY_SNAPSHOT_URL + "forge-installer-" + version + ".jar";
}
}
private void extractVersionFromMavenRelease() throws MalformedURLException {
String RELEASE_MAVEN_METADATA = RELEASE_VERSION_INDEX + "forge/forge-gui-desktop/maven-metadata.xml";
String RELEASE_MAVEN_METADATA = RELEASE_URL + "forge/forge-gui-desktop/maven-metadata.xml";
URL metadataUrl = new URL(RELEASE_MAVEN_METADATA);
String xml = FileUtil.readFileToString(metadataUrl);

View File

@@ -25,8 +25,11 @@ import java.util.Collections;
import java.util.Map;
public final class ForgeConstants {
public static final String GITHUB_RELEASES_URL_ATOM = "https://github.com/Card-Forge/forge/releases.atom";
public static final String GITHUB_COMMITS_URL_ATOM = "https://github.com/Card-Forge/forge/commits/master.atom";
public static final String GITHUB_FORGE_URL = "https://github.com/Card-Forge/forge/";
public static final String GITHUB_RELEASES_URL_ATOM = GITHUB_FORGE_URL + "releases.atom";
public static final String GITHUB_COMMITS_URL_ATOM = GITHUB_FORGE_URL + "commits/master.atom";
public static final String DAILY_SNAPSHOT_URL = "https://downloads.cardforge.org/dailysnapshots/";
public static final String RELEASE_URL = "https://releases.cardforge.org/";
public static final String PATH_SEPARATOR = File.separator;
public static final String ASSETS_DIR = GuiBase.getInterface().getAssetsDir();
public static final String PROFILE_FILE = ASSETS_DIR + "forge.profile.properties";