mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 06:31:17 +00:00
Checking new versions on Github
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.gui;
|
||||
|
||||
import com.eclipsesource.json.Json;
|
||||
import com.eclipsesource.json.JsonArray;
|
||||
import com.eclipsesource.json.JsonObject;
|
||||
import com.eclipsesource.json.JsonValue;
|
||||
import com.jpexs.debugger.flash.Debugger;
|
||||
import com.jpexs.debugger.flash.DebuggerCommands;
|
||||
import com.jpexs.debugger.flash.Variable;
|
||||
@@ -2168,29 +2172,10 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkForUpdates() {
|
||||
String currentVersion = ApplicationInfo.version;
|
||||
if (currentVersion.equals("unknown")) {
|
||||
// sometimes during development the version information is not available
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> accepted = new ArrayList<>();
|
||||
if (Configuration.checkForUpdatesStable.get()) {
|
||||
accepted.add("stable");
|
||||
}
|
||||
if (Configuration.checkForUpdatesNightly.get()) {
|
||||
accepted.add("nightly");
|
||||
}
|
||||
|
||||
if (accepted.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String acceptVersions = String.join(",", accepted);
|
||||
private static JsonValue urlGetJson(String getUrl) {
|
||||
try {
|
||||
String proxyAddress = Configuration.updateProxyAddress.get();
|
||||
URL url = new URL(ApplicationInfo.updateCheckUrl);
|
||||
URL url = new URL(getUrl);
|
||||
|
||||
URLConnection uc;
|
||||
if (proxyAddress != null && !proxyAddress.isEmpty()) {
|
||||
@@ -2205,114 +2190,88 @@ public class Main {
|
||||
} else {
|
||||
uc = url.openConnection();
|
||||
}
|
||||
uc.setRequestProperty("X-Accept-Versions", acceptVersions);
|
||||
uc.setRequestProperty("X-Update-Major", "" + UPDATE_SYSTEM_MAJOR);
|
||||
uc.setRequestProperty("X-Update-Minor", "" + UPDATE_SYSTEM_MINOR);
|
||||
uc.setRequestProperty("User-Agent", ApplicationInfo.shortApplicationVerName);
|
||||
String currentLoc = Configuration.locale.get("en");
|
||||
uc.setRequestProperty("Accept-Language", currentLoc + ("en".equals(currentLoc) ? "" : ", en;q=0.8"));
|
||||
|
||||
uc.connect();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
|
||||
String s;
|
||||
final java.util.List<Version> versions = new ArrayList<>();
|
||||
String header = "";
|
||||
Pattern headerPat = Pattern.compile("\\[([a-zA-Z0-9]+)\\]");
|
||||
int updateMajor;
|
||||
int updateMinor;
|
||||
Version ver = null;
|
||||
while ((s = br.readLine()) != null) {
|
||||
|
||||
Matcher m = headerPat.matcher(s);
|
||||
if (m.matches()) {
|
||||
header = m.group(1);
|
||||
if (header.equals("version")) {
|
||||
ver = new Version();
|
||||
versions.add(ver);
|
||||
}
|
||||
if (header.equals("noversion")) {
|
||||
break;
|
||||
}
|
||||
} else if (s.contains("=")) {
|
||||
String key = s.substring(0, s.indexOf('='));
|
||||
String val = s.substring(s.indexOf('=') + 1);
|
||||
if ("updateSystem".equals(header)) {
|
||||
if (key.equals("majorVersion")) {
|
||||
updateMajor = Integer.parseInt(val);
|
||||
if (updateMajor > UPDATE_SYSTEM_MAJOR) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (key.equals("minorVersion")) {
|
||||
updateMinor = Integer.parseInt(val);
|
||||
}
|
||||
}
|
||||
if ("version".equals(header) && (ver != null)) {
|
||||
if (key.equals("versionId")) {
|
||||
ver.versionId = Integer.parseInt(val);
|
||||
}
|
||||
if (key.equals("versionName")) {
|
||||
ver.versionName = val;
|
||||
}
|
||||
if (key.equals("nightly")) {
|
||||
ver.nightly = val.equals("true");
|
||||
}
|
||||
if (key.equals("revision")) {
|
||||
ver.revision = val;
|
||||
}
|
||||
if (key.equals("build")) {
|
||||
ver.build = Integer.parseInt(val);
|
||||
}
|
||||
if (key.equals("major")) {
|
||||
ver.major = Integer.parseInt(val);
|
||||
}
|
||||
if (key.equals("minor")) {
|
||||
ver.minor = Integer.parseInt(val);
|
||||
}
|
||||
if (key.equals("release")) {
|
||||
ver.release = Integer.parseInt(val);
|
||||
}
|
||||
if (key.equals("longVersionName")) {
|
||||
ver.longVersionName = val;
|
||||
}
|
||||
if (key.equals("releaseDate")) {
|
||||
ver.releaseDate = val;
|
||||
}
|
||||
if (key.equals("appName")) {
|
||||
ver.appName = val;
|
||||
}
|
||||
if (key.equals("appFullName")) {
|
||||
ver.appFullName = val;
|
||||
}
|
||||
if (key.equals("updateLink")) {
|
||||
ver.updateLink = val;
|
||||
}
|
||||
if (key.equals("change[]")) {
|
||||
String changeType = val.substring(0, val.indexOf('|'));
|
||||
String change = val.substring(val.indexOf('|') + 1);
|
||||
if (!ver.changes.containsKey(changeType)) {
|
||||
ver.changes.put(changeType, new ArrayList<>());
|
||||
}
|
||||
List<String> chlist = ver.changes.get(changeType);
|
||||
chlist.add(change);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!versions.isEmpty()) {
|
||||
View.execInEventDispatch(() -> {
|
||||
NewVersionDialog newVersionDialog = new NewVersionDialog(versions);
|
||||
newVersionDialog.setVisible(true);
|
||||
Configuration.lastUpdatesCheckDate.set(Calendar.getInstance());
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
JsonValue value = Json.parse(new InputStreamReader(uc.getInputStream()));
|
||||
return value;
|
||||
} catch (IOException | NumberFormatException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkForUpdates() {
|
||||
String currentVersion = ApplicationInfo.version;
|
||||
if (currentVersion.equals("unknown")) {
|
||||
// sometimes during development the version information is not available
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean showStable = Configuration.checkForUpdatesStable.get();
|
||||
boolean showNightly = Configuration.checkForUpdatesNightly.get();
|
||||
|
||||
if (!showStable && !showNightly) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String currentTagName;
|
||||
if (ApplicationInfo.nightly) {
|
||||
currentTagName = "nightly" + ApplicationInfo.version_build;
|
||||
} else {
|
||||
currentTagName = "version" + ApplicationInfo.version_major + "." + ApplicationInfo.version_minor + "." + ApplicationInfo.version_release;
|
||||
}
|
||||
|
||||
if (!showNightly) {
|
||||
//prereleases are not shown as latest, when checking latest nightly, this is useless
|
||||
JsonValue latestVersionInfoJson = urlGetJson(ApplicationInfo.GITHUB_RELEASES_LATEST_URL);
|
||||
if (latestVersionInfoJson == null) {
|
||||
return false;
|
||||
}
|
||||
String latestTagName = latestVersionInfoJson.asObject().get("tag_name").asString();
|
||||
if (currentTagName.equals(latestTagName)) {
|
||||
//no new version
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
JsonValue allChangesInfoJson = urlGetJson(ApplicationInfo.GITHUB_RELEASES_URL);
|
||||
if (allChangesInfoJson == null) {
|
||||
return false;
|
||||
}
|
||||
JsonArray arr = allChangesInfoJson.asArray();
|
||||
final java.util.List<Version> versions = new ArrayList<>();
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
JsonObject versionObj = arr.get(i).asObject();
|
||||
String tagName = versionObj.get("tag_name").asString();
|
||||
if (currentVersion.equals(tagName)) {
|
||||
//Stop at current version, do not display more
|
||||
break;
|
||||
}
|
||||
Version v = new Version();
|
||||
v.versionName = versionObj.get("name").asString();
|
||||
v.description = versionObj.get("body").asString();
|
||||
v.releaseDate = versionObj.get("published_at").asString();
|
||||
boolean isNightly = versionObj.get("prerelease").asBoolean();
|
||||
if (isNightly && !showNightly) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isNightly && !showStable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
versions.add(v);
|
||||
}
|
||||
|
||||
if (!versions.isEmpty()) {
|
||||
View.execInEventDispatch(() -> {
|
||||
NewVersionDialog newVersionDialog = new NewVersionDialog(versions);
|
||||
newVersionDialog.setVisible(true);
|
||||
Configuration.lastUpdatesCheckDate.set(Calendar.getInstance());
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Configuration.lastUpdatesCheckDate.set(Calendar.getInstance());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class NewVersionDialog extends AppDialog {
|
||||
JEditorPane changesText = new JEditorPane();
|
||||
changesText.setEditable(false);
|
||||
changesText.setFont(UIManager.getFont("TextField.font"));
|
||||
SimpleDateFormat serverFormatter = new SimpleDateFormat("MM/dd/yyyy");
|
||||
SimpleDateFormat serverFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
DateFormat formatter;
|
||||
String customFormat = translate("customDateFormat");
|
||||
if (customFormat.equals("default")) {
|
||||
@@ -72,7 +72,7 @@ public class NewVersionDialog extends AppDialog {
|
||||
changesStr.append("<hr />");
|
||||
}
|
||||
first = false;
|
||||
changesStr.append("<b>").append(translate("version")).append(" ").append(v.versionName).append("</b><br />");
|
||||
changesStr.append("<b>").append(v.versionName).append("</b><br />");
|
||||
String releaseDate = v.releaseDate;
|
||||
try {
|
||||
Date date = serverFormatter.parse(releaseDate);
|
||||
@@ -81,17 +81,10 @@ public class NewVersionDialog extends AppDialog {
|
||||
Logger.getLogger(NewVersionDialog.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
changesStr.append(translate("releasedate")).append(" ").append(releaseDate);
|
||||
if (!v.changes.isEmpty()) {
|
||||
changesStr.append("<br />");
|
||||
changesStr.append("<pre>");
|
||||
for (String type : v.changes.keySet()) {
|
||||
changesStr.append(type).append(":" + "<br />");
|
||||
for (String ch : v.changes.get(type)) {
|
||||
changesStr.append(" - ").append(ch).append("<br />");
|
||||
}
|
||||
}
|
||||
changesStr.append("</pre>");
|
||||
}
|
||||
changesStr.append("<br />");
|
||||
changesStr.append("<pre>");
|
||||
changesStr.append(v.description);
|
||||
changesStr.append("</pre>");
|
||||
}
|
||||
|
||||
changesStr.append("</html>");
|
||||
@@ -102,7 +95,7 @@ public class NewVersionDialog extends AppDialog {
|
||||
changesText.setContentType("text/html");
|
||||
changesText.setText(changesStr.toString());
|
||||
if (latestVersion != null) {
|
||||
JLabel newAvailableLabel = new JLabel("<html><b><center>" + translate("newversionavailable") + " " + latestVersion.appName + " " + translate("version") + " " + latestVersion.versionName + "</center></b></html>", SwingConstants.CENTER);
|
||||
JLabel newAvailableLabel = new JLabel("<html><b><center>" + translate("newversionavailable") + " " + latestVersion.versionName + "</center></b></html>", SwingConstants.CENTER);
|
||||
newAvailableLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
|
||||
cnt.add(newAvailableLabel);
|
||||
}
|
||||
@@ -140,16 +133,11 @@ public class NewVersionDialog extends AppDialog {
|
||||
}
|
||||
|
||||
private void okButtonActionPerformed(ActionEvent evt) {
|
||||
String url;
|
||||
if (latestVersion.updateLink != null) {
|
||||
url = latestVersion.updateLink;
|
||||
} else {
|
||||
url = ApplicationInfo.updateUrl;
|
||||
}
|
||||
String url = ApplicationInfo.UPDATE_URL;
|
||||
if (View.navigateUrl(url)) {
|
||||
Main.exit();
|
||||
} else {
|
||||
View.showMessageDialog(null, translate("newvermessage").replace("%oldAppName%", ApplicationInfo.SHORT_APPLICATION_NAME).replace("%newAppName%", latestVersion.appName).replace("%projectPage%", ApplicationInfo.PROJECT_PAGE), translate("newversion"), JOptionPane.INFORMATION_MESSAGE);
|
||||
View.showMessageDialog(null, translate("newvermessage").replace("%oldAppName%", ApplicationInfo.SHORT_APPLICATION_NAME).replace("%newAppName%", latestVersion.versionName).replace("%projectPage%", ApplicationInfo.PROJECT_PAGE), translate("newversion"), JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
setVisible(false);
|
||||
|
||||
Reference in New Issue
Block a user