From 5cbc152e1c04b09dc28e1f60bc617efabfc60ced Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sat, 2 Jun 2018 15:32:21 -0400 Subject: [PATCH 1/5] Change log is now displayed when updating from command line --- src/main/java/com/rarchives/ripme/ui/UpdateUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 95af45c6..8882c9af 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -68,8 +68,9 @@ public class UpdateUtils { if (change.startsWith(UpdateUtils.getThisJarVersion() + ":")) { break; } - changeList.append("
+ ").append(change); + changeList.append("\n").append(change); } + logger.info("Change log: \n" + changeList.toString()); String latestVersion = ripmeJson.getString("latestVersion"); if (UpdateUtils.isNewerVersion(latestVersion)) { From 10d256a6e5ef42399e8a922e29fe32b98a6eeb4c Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sat, 2 Jun 2018 15:39:27 -0400 Subject: [PATCH 2/5] Cut down on repeated code --- .../com/rarchives/ripme/ui/UpdateUtils.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 8882c9af..ebfa1428 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -39,6 +39,20 @@ public class UpdateUtils { } return thisVersion; } + + private static String getChangeList(JSONObject rj) { + JSONArray jsonChangeList = rj.getJSONArray("changeList"); + StringBuilder changeList = new StringBuilder(); + for (int i = 0; i < jsonChangeList.length(); i++) { + String change = jsonChangeList.getString(i); + if (change.startsWith(UpdateUtils.getThisJarVersion() + ":")) { + break; + } + changeList.append("\n").append(change); + } + return changeList.toString(); + } + public static void updateProgramCLI() { logger.info("Checking for update..."); @@ -61,16 +75,10 @@ public class UpdateUtils { } String jsonString = doc.body().html().replaceAll(""", "\""); ripmeJson = new JSONObject(jsonString); - JSONArray jsonChangeList = ripmeJson.getJSONArray("changeList"); - StringBuilder changeList = new StringBuilder(); - for (int i = 0; i < jsonChangeList.length(); i++) { - String change = jsonChangeList.getString(i); - if (change.startsWith(UpdateUtils.getThisJarVersion() + ":")) { - break; - } - changeList.append("\n").append(change); - } - logger.info("Change log: \n" + changeList.toString()); + + String changeList = getChangeList(ripmeJson); + + logger.info("Change log: \n" + changeList); String latestVersion = ripmeJson.getString("latestVersion"); if (UpdateUtils.isNewerVersion(latestVersion)) { @@ -112,15 +120,8 @@ public class UpdateUtils { } String jsonString = doc.body().html().replaceAll(""", "\""); ripmeJson = new JSONObject(jsonString); - JSONArray jsonChangeList = ripmeJson.getJSONArray("changeList"); - StringBuilder changeList = new StringBuilder(); - for (int i = 0; i < jsonChangeList.length(); i++) { - String change = jsonChangeList.getString(i); - if (change.startsWith(UpdateUtils.getThisJarVersion() + ":")) { - break; - } - changeList.append("
+ ").append(change); - } + + String changeList = getChangeList(ripmeJson); String latestVersion = ripmeJson.getString("latestVersion"); if (UpdateUtils.isNewerVersion(latestVersion)) { @@ -128,7 +129,7 @@ public class UpdateUtils { int result = JOptionPane.showConfirmDialog( null, "New version (" + latestVersion + ") is available!" - + "

Recent changes:" + changeList.toString() + + "

Recent changes:" + changeList + "

Do you want to download and run the newest version?", "RipMe Updater", JOptionPane.YES_NO_OPTION); From b0bcf506aa0dfac1b7cdced99c55117e245b93ba Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sat, 2 Jun 2018 16:02:52 -0400 Subject: [PATCH 3/5] Can now disable the update hash check --- .../com/rarchives/ripme/ui/UpdateUtils.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index ebfa1428..9b78a7c8 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -229,17 +229,20 @@ public class UpdateUtils { try (FileOutputStream out = new FileOutputStream(updateFileName)) { out.write(response.bodyAsBytes()); } - String updateHash = createSha256(new File(updateFileName)); - logger.info("Download of new version complete; saved to " + updateFileName); - logger.info("Checking hash of update"); + // Only check the hash if the user hasn't disabled hash checking + if (Utils.getConfigBoolean("security.check_update_hash", true)) { + String updateHash = createSha256(new File(updateFileName)); + logger.info("Download of new version complete; saved to " + updateFileName); + logger.info("Checking hash of update"); - if (!ripmeJson.getString("currentHash").equals(updateHash)) { - logger.error("Error: Update has bad hash"); - logger.debug("Expected hash: " + ripmeJson.getString("currentHash")); - logger.debug("Actual hash: " + updateHash); - throw new IOException("Got bad file hash"); - } else { - logger.info("Hash is good"); + if (!ripmeJson.getString("currentHash").equals(updateHash)) { + logger.error("Error: Update has bad hash"); + logger.debug("Expected hash: " + ripmeJson.getString("currentHash")); + logger.debug("Actual hash: " + updateHash); + throw new IOException("Got bad file hash"); + } else { + logger.info("Hash is good"); + } } if (shouldLaunch) { // Setup updater script From 1adc0a9bf75b204af1c6909de3e75f3db4afb865 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sat, 2 Jun 2018 16:08:49 -0400 Subject: [PATCH 4/5] Added config option to make ripme always try to update (for testing purposes) --- src/main/java/com/rarchives/ripme/ui/UpdateUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 9b78a7c8..868f00ac 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -159,6 +159,10 @@ public class UpdateUtils { } private static boolean isNewerVersion(String latestVersion) { + // If we're testing the update utils we want the program to always try to update + if (Utils.getConfigBoolean("testing.always_try_to_update", false)) { + return true; + } int[] oldVersions = versionStringToInt(getThisJarVersion()); int[] newVersions = versionStringToInt(latestVersion); if (oldVersions.length < newVersions.length) { From 9af46aad206a481324e245e802922454431c8e12 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sat, 2 Jun 2018 16:14:48 -0400 Subject: [PATCH 5/5] Ripme now logs when it's forcing an update for testing --- src/main/java/com/rarchives/ripme/ui/UpdateUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 868f00ac..b4659d9c 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -161,6 +161,7 @@ public class UpdateUtils { private static boolean isNewerVersion(String latestVersion) { // If we're testing the update utils we want the program to always try to update if (Utils.getConfigBoolean("testing.always_try_to_update", false)) { + logger.info("isNewerVersion is returning true because the key \"testing.always_try_to_update\" is true"); return true; } int[] oldVersions = versionStringToInt(getThisJarVersion());