mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
update AtomReader, add support releaseTag on android
This commit is contained in:
@@ -12,12 +12,12 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class RSSReader {
|
||||
public static String getCommitLog(Date buildDateOriginal, Date maxDate) {
|
||||
public static String getCommitLog(String commitsAtom, Date buildDateOriginal, Date maxDate) {
|
||||
String message = "";
|
||||
SimpleDateFormat simpleDate = TextUtil.getSimpleDate();
|
||||
try {
|
||||
RssReader reader = new RssReader();
|
||||
URL url = new URL("https://github.com/Card-Forge/forge/commits/master.atom");
|
||||
URL url = new URL(commitsAtom);
|
||||
InputStream inputStream = url.openStream();
|
||||
List<Item> items = reader.read(inputStream).toList();
|
||||
StringBuilder logs = new StringBuilder();
|
||||
@@ -49,11 +49,11 @@ public class RSSReader {
|
||||
}
|
||||
return message;
|
||||
}
|
||||
public static String getLatestReleaseTag() {
|
||||
public static String getLatestReleaseTag(String releaseAtom) {
|
||||
String tag = "";
|
||||
try {
|
||||
RssReader reader = new RssReader();
|
||||
URL url = new URL("https://github.com/Card-Forge/forge/releases.atom");
|
||||
URL url = new URL(releaseAtom);
|
||||
InputStream inputStream = url.openStream();
|
||||
List<Item> items = reader.read(inputStream).toList();
|
||||
for (Item i : items) {
|
||||
|
||||
@@ -10,10 +10,10 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class GitLogs {
|
||||
public String getLatest(Date buildDateOriginal, Date maxDate) {
|
||||
public String getLatest(String commitsAtom, Date buildDateOriginal, Date maxDate) {
|
||||
String message = "";
|
||||
try {
|
||||
URL url = new URL("https://github.com/Card-Forge/forge/commits/master.atom");
|
||||
URL url = new URL(commitsAtom);
|
||||
InputStream inputStream = url.openStream();
|
||||
List<AtomReader.Entry> entries = new AtomReader().parse(inputStream);
|
||||
StringBuilder logs = new StringBuilder();
|
||||
@@ -47,10 +47,10 @@ public class GitLogs {
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getLatestReleaseTag() {
|
||||
public String getLatestReleaseTag(String releaseAtom) {
|
||||
String tag = "";
|
||||
try {
|
||||
URL url = new URL("https://github.com/Card-Forge/forge/releases.atom");
|
||||
URL url = new URL(releaseAtom);
|
||||
InputStream inputStream = url.openStream();
|
||||
List<AtomReader.Entry> entries = new AtomReader().parse(inputStream);
|
||||
for (AtomReader.Entry entry : entries) {
|
||||
|
||||
@@ -635,13 +635,13 @@ public class Main extends ForgeAndroidApplication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLatestChanges(Date buildDateOriginal, Date maxDate) {
|
||||
return new GitLogs().getLatest(buildDateOriginal, maxDate);
|
||||
public String getLatestChanges(String commitsAtom, Date buildDateOriginal, Date maxDate) {
|
||||
return new GitLogs().getLatest(commitsAtom, buildDateOriginal, maxDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReleaseTag() {
|
||||
return new GitLogs().getLatestReleaseTag();
|
||||
public String getReleaseTag(String releaseAtom) {
|
||||
return new GitLogs().getLatestReleaseTag(releaseAtom);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,8 @@ import forge.util.RSSReader;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static forge.localinstance.properties.ForgeConstants.GITHUB_COMMITS_URL_ATOM;
|
||||
|
||||
/**
|
||||
* Controls the utilities submenu in the home UI.
|
||||
*
|
||||
@@ -30,7 +32,7 @@ public enum CSubmenuDownloaders implements ICDoc {
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private final UiCommand cmdLicensing = VSubmenuDownloaders.SINGLETON_INSTANCE::showLicensing;
|
||||
private final UiCommand cmdCheckForUpdates = () -> new AutoUpdater(false).attemptToUpdate(CompletableFuture.supplyAsync(() -> RSSReader.getCommitLog(null, null)));
|
||||
private final UiCommand cmdCheckForUpdates = () -> new AutoUpdater(false).attemptToUpdate(CompletableFuture.supplyAsync(() -> RSSReader.getCommitLog(GITHUB_COMMITS_URL_ATOM, null, null)));
|
||||
|
||||
private final UiCommand cmdPicDownload = () -> new GuiDownloader(new GuiDownloadPicturesLQ()).show();
|
||||
private final UiCommand cmdPicDownloadHQ = () -> new GuiDownloader(new GuiDownloadPicturesHQ()).show();
|
||||
|
||||
@@ -29,6 +29,8 @@ import forge.util.BuildInfo;
|
||||
import forge.util.Localizer;
|
||||
import forge.util.RSSReader;
|
||||
|
||||
import static forge.localinstance.properties.ForgeConstants.GITHUB_COMMITS_URL_ATOM;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class FTitleBarBase extends SkinnedMenuBar {
|
||||
protected static final int visibleHeight = 27;
|
||||
@@ -431,7 +433,7 @@ public abstract class FTitleBarBase extends SkinnedMenuBar {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
try {
|
||||
new AutoUpdater(false).attemptToUpdate(CompletableFuture.supplyAsync(() -> RSSReader.getCommitLog(null, null)));
|
||||
new AutoUpdater(false).attemptToUpdate(CompletableFuture.supplyAsync(() -> RSSReader.getCommitLog(GITHUB_COMMITS_URL_ATOM, null, null)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -80,12 +80,12 @@ public class Main extends IOSApplication.Delegate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLatestChanges(Date buildDateOriginal, Date maxDate) {
|
||||
public String getLatestChanges(String commitsAtom, Date buildDateOriginal, Date maxDate) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReleaseTag() {
|
||||
public String getReleaseTag(String releaseAtom) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@@ -52,13 +52,13 @@ public class Main {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLatestChanges(Date buildDateOriginal, Date max) {
|
||||
return RSSReader.getCommitLog(buildDateOriginal, max);
|
||||
public String getLatestChanges(String commitsAtom, Date buildDateOriginal, Date max) {
|
||||
return RSSReader.getCommitLog(commitsAtom, buildDateOriginal, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReleaseTag() {
|
||||
return RSSReader.getLatestReleaseTag();
|
||||
public String getReleaseTag(String releaseAtom) {
|
||||
return RSSReader.getLatestReleaseTag(releaseAtom);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,9 @@ import forge.gui.util.SOptionPane;
|
||||
import forge.localinstance.properties.ForgeConstants;
|
||||
import forge.util.FileUtil;
|
||||
|
||||
import static forge.localinstance.properties.ForgeConstants.GITHUB_COMMITS_URL_ATOM;
|
||||
import static forge.localinstance.properties.ForgeConstants.GITHUB_RELEASES_URL_ATOM;
|
||||
|
||||
public class AssetsDownloader {
|
||||
private final static ImmutableList<String> downloadIgnoreExit = ImmutableList.of("Download", "Ignore", "Exit");
|
||||
private final static ImmutableList<String> downloadExit = ImmutableList.of("Download", "Exit");
|
||||
@@ -40,7 +43,7 @@ public class AssetsDownloader {
|
||||
}
|
||||
}
|
||||
//currently for desktop/mobile-dev release on github
|
||||
String releaseTag = Forge.getDeviceAdapter().getReleaseTag();
|
||||
final String releaseTag = Forge.getDeviceAdapter().getReleaseTag(GITHUB_RELEASES_URL_ATOM);
|
||||
final String packageSize = GuiBase.isAndroid() ? "160MB" : "270MB";
|
||||
final String apkSize = "12MB";
|
||||
|
||||
@@ -100,7 +103,7 @@ public class AssetsDownloader {
|
||||
message += " If so, you may want to connect to wifi first. The download is around " + (GuiBase.isAndroid() ? apkSize : packageSize) + ".";
|
||||
}
|
||||
if (!GuiBase.isAndroid()) {
|
||||
message += Forge.getDeviceAdapter().getLatestChanges(null, null);
|
||||
message += Forge.getDeviceAdapter().getLatestChanges(GITHUB_COMMITS_URL_ATOM, null, null);
|
||||
}
|
||||
//failed to grab latest github tag
|
||||
if (!isSnapshots && releaseTag.isEmpty()) {
|
||||
@@ -108,7 +111,7 @@ public class AssetsDownloader {
|
||||
run(runnable);
|
||||
} else if (SOptionPane.showConfirmDialog(message, "New Version Available", "Update Now", "Update Later", true, true)) {
|
||||
String installer = new GuiDownloadZipService("", "update", installerURL,
|
||||
Forge.getDeviceAdapter().getDownloadsDir(), null, Forge.getSplashScreen().getProgressBar()).download(filename);
|
||||
Forge.getDeviceAdapter().getDownloadsDir(), null, Forge.getSplashScreen().getProgressBar()).download(filename);
|
||||
if (installer != null) {
|
||||
Forge.getDeviceAdapter().openFile(installer);
|
||||
Forge.isMobileAdventureMode = Forge.advStartup;
|
||||
@@ -129,8 +132,7 @@ public class AssetsDownloader {
|
||||
if (!GuiBase.isAndroid())
|
||||
run(runnable);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (!GuiBase.isAndroid()) {
|
||||
run(runnable);
|
||||
@@ -167,8 +169,7 @@ public class AssetsDownloader {
|
||||
if (!versionFile.exists()) {
|
||||
try {
|
||||
versionFile.file().createNewFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Forge.isMobileAdventureMode = Forge.advStartup;
|
||||
Forge.exitAnimation(false); //can't continue if this fails
|
||||
@@ -202,7 +203,7 @@ public class AssetsDownloader {
|
||||
SimpleDateFormat simpleDate = TextUtil.getSimpleDate();
|
||||
simpleDate.setTimeZone(TimeZone.getDefault());
|
||||
build += "Installed resources date: " + simpleDate.format(calendar.getTime()) + "\n\n";
|
||||
log = Forge.getDeviceAdapter().getLatestChanges(null, null);
|
||||
log = Forge.getDeviceAdapter().getLatestChanges(GITHUB_COMMITS_URL_ATOM, null, null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -218,8 +219,7 @@ public class AssetsDownloader {
|
||||
message = "Updated resource files cannot be downloaded due to lack of internet connection.\n\n";
|
||||
if (canIgnoreDownload) {
|
||||
message += "You can continue without this download, but you may miss out on card fixes or experience other problems.";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
message += "You cannot start the app since you haven't previously downloaded these files.";
|
||||
}
|
||||
switch (SOptionPane.showOptionDialog(message, "No Internet Connection", null, ImmutableList.of("Ok"))) {
|
||||
@@ -238,8 +238,7 @@ public class AssetsDownloader {
|
||||
"This download is around " + packageSize + ", ";
|
||||
if (Forge.getDeviceAdapter().isConnectedToWifi()) {
|
||||
message += "which shouldn't take long if your wifi connection is good.";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
message += "so it's highly recommended that you connect to wifi first.";
|
||||
}
|
||||
final List<String> options;
|
||||
@@ -272,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();
|
||||
ForgeConstants.ASSETS_DIR, ForgeConstants.RES_DIR, Forge.getSplashScreen().getProgressBar(), allowDeletion).downloadAndUnzip();
|
||||
|
||||
if (allowDeletion)
|
||||
FSkinFont.deleteCachedFiles(); //delete cached font files in case any skin's .ttf file changed
|
||||
@@ -300,6 +299,7 @@ public class AssetsDownloader {
|
||||
Forge.isMobileAdventureMode = Forge.advStartup;
|
||||
Forge.exitAnimation(true);
|
||||
}
|
||||
|
||||
private static void run(Runnable toRun) {
|
||||
if (toRun != null) {
|
||||
if (!GuiBase.isAndroid()) {
|
||||
|
||||
@@ -14,8 +14,8 @@ public interface IDeviceAdapter {
|
||||
boolean isTablet();
|
||||
String getDownloadsDir();
|
||||
String getVersionString();
|
||||
String getLatestChanges(Date buildDateOriginal, Date maxDate);
|
||||
String getReleaseTag();
|
||||
String getLatestChanges(String commitsAtom, Date buildDateOriginal, Date maxDate);
|
||||
String getReleaseTag(String releaseAtom);
|
||||
boolean openFile(String filename);
|
||||
void setLandscapeMode(boolean landscapeMode);
|
||||
void preventSystemSleep(boolean preventSleep);
|
||||
|
||||
@@ -25,6 +25,8 @@ 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 PATH_SEPARATOR = File.separator;
|
||||
public static final String ASSETS_DIR = GuiBase.getInterface().getAssetsDir();
|
||||
public static final String PROFILE_FILE = ASSETS_DIR + "forge.profile.properties";
|
||||
|
||||
Reference in New Issue
Block a user