diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ApplicationInfo.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ApplicationInfo.java index baad815c5..2ca5772cb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ApplicationInfo.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/ApplicationInfo.java @@ -49,11 +49,17 @@ public class ApplicationInfo { public static String shortApplicationVerName; - public static final String PROJECT_PAGE = "http://www.free-decompiler.com/flash"; + public static final String PROJECT_PAGE = "https://www.free-decompiler.com/flash"; - public static String updatePageStub = "http://www.free-decompiler.com/flash/update.html?currentVersion="; - - public static String updatePage; + /** + * URL for checking new updates + */ + public static String updateCheckUrl = "https://www.free-decompiler.com/flash/update.html?currentVersion=¤tRevision=¤tVersionMajor=¤tVersionMinor=¤tVersionRelease=¤tVersionBuild=¤tNightly="; + + /** + * URL for doing update + */ + public static String updateUrl = "https://www.free-decompiler.com/flash/update.html?action=check¤tVersion=¤tRevision=¤tVersionMajor=¤tVersionMinor=¤tVersionRelease=¤tVersionBuild=¤tNightly="; static { loadProperties(); @@ -77,9 +83,25 @@ public class ApplicationInfo { // ignore version = "unknown"; } - - applicationVerName = APPLICATION_NAME + " v." + version; - updatePage = updatePageStub + version; + updateCheckUrl = updateCheckUrl + .replace("", revision) + .replace("", version) + .replace("", ""+version_major) + .replace("", ""+version_minor) + .replace("", ""+version_release) + .replace("", ""+version_build) + .replace("", nightly?"1":"0") + ; + updateUrl = updateUrl + .replace("", revision) + .replace("", version) + .replace("", ""+version_major) + .replace("", ""+version_minor) + .replace("", ""+version_release) + .replace("", ""+version_build) + .replace("", nightly?"1":"0") + ; + applicationVerName = APPLICATION_NAME + " v." + version; shortApplicationVerName = SHORT_APPLICATION_NAME + " v." + version; } } diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index c84153efd..41050ca89 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -73,7 +73,12 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.lang.reflect.Field; +import java.net.InetSocketAddress; +import java.net.Proxy; import java.net.Socket; +import java.net.SocketAddress; +import java.net.URL; +import java.net.URLConnection; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -125,7 +130,7 @@ public class Main { public static final int UPDATE_SYSTEM_MAJOR = 1; - public static final int UPDATE_SYSTEM_MINOR = 2; + public static final int UPDATE_SYSTEM_MINOR = 3; private static LoadFromMemoryFrame loadFromMemoryFrame; @@ -1374,7 +1379,9 @@ public class Main { String acceptVersions = String.join(",", accepted); try { String proxyAddress = Configuration.updateProxyAddress.get(); - Socket sock; + URL url = new URL(ApplicationInfo.updateCheckUrl); + + URLConnection uc = null; if (proxyAddress != null) { int port = 8080; if (proxyAddress.contains(":")) { @@ -1383,30 +1390,21 @@ public class Main { proxyAddress = parts[0]; } - sock = new Socket(proxyAddress, port); + uc = url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyAddress, port))); } else { - sock = new Socket("www.free-decompiler.com", 80); + uc = url.openConnection(); } - OutputStream os = sock.getOutputStream(); + 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"); - os.write(("GET /flash/update.html?action=check¤tVersion=" + URLEncoder.encode(currentVersion, "UTF-8") - + "¤tRevision=" + URLEncoder.encode(ApplicationInfo.revision, "UTF-8") - + "¤tVersionMajor=" + URLEncoder.encode("" + ApplicationInfo.version_major, "UTF-8") - + "¤tVersionMinor=" + URLEncoder.encode("" + ApplicationInfo.version_minor, "UTF-8") - + "¤tVersionRelease=" + URLEncoder.encode("" + ApplicationInfo.version_release, "UTF-8") - + "¤tVersionBuild=" + URLEncoder.encode("" + ApplicationInfo.version_build, "UTF-8") - + "¤tNightly=" + (ApplicationInfo.nightly ? "1" : "0") + " HTTP/1.1\r\n" - + "Host: www.free-decompiler.com\r\n" - + "X-Accept-Versions: " + acceptVersions + "\r\n" - + "X-Update-Major: " + UPDATE_SYSTEM_MAJOR + "\r\n" - + "X-Update-Minor: " + UPDATE_SYSTEM_MINOR + "\r\n" - + "User-Agent: " + ApplicationInfo.shortApplicationVerName + "\r\n" - + "Accept-Language: " + currentLoc + ("en".equals(currentLoc) ? "" : ", en;q=0.8") + "\r\n" - + "Connection: close\r\n" - + "\r\n").getBytes()); - BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream())); + uc.setRequestProperty("Accept-Language", currentLoc + ("en".equals(currentLoc) ? "" : ", en;q=0.8")); + + uc.connect(); + + BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream())); String s; - boolean start = false; final java.util.List versions = new ArrayList<>(); String header = ""; Pattern headerPat = Pattern.compile("\\[([a-zA-Z0-9]+)\\]"); @@ -1414,98 +1412,91 @@ public class Main { int updateMinor; Version ver = null; while ((s = br.readLine()) != null) { - if (start) { - 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); + + 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 ("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 chlist = ver.changes.get(changeType); - chlist.add(change); + 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 chlist = ver.changes.get(changeType); + chlist.add(change); } } } } - if (s.isEmpty()) { - start = true; - } } if (!versions.isEmpty()) { - View.execInEventDispatch(new Runnable() { - @Override - public void run() { - NewVersionDialog newVersionDialog = new NewVersionDialog(versions); - newVersionDialog.setVisible(true); - Configuration.lastUpdatesCheckDate.set(Calendar.getInstance()); - } + View.execInEventDispatch(() -> { + NewVersionDialog newVersionDialog = new NewVersionDialog(versions); + newVersionDialog.setVisible(true); + Configuration.lastUpdatesCheckDate.set(Calendar.getInstance()); }); return true; diff --git a/src/com/jpexs/decompiler/flash/gui/NewVersionDialog.java b/src/com/jpexs/decompiler/flash/gui/NewVersionDialog.java index db41baeed..2823f93a5 100644 --- a/src/com/jpexs/decompiler/flash/gui/NewVersionDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/NewVersionDialog.java @@ -148,7 +148,7 @@ public class NewVersionDialog extends AppDialog implements ActionListener { if (latestVersion.updateLink != null) { url = latestVersion.updateLink; } else { - url = ApplicationInfo.updatePage; + url = ApplicationInfo.updateUrl; } if (View.navigateUrl(url)) { Main.exit();