From 10d256a6e5ef42399e8a922e29fe32b98a6eeb4c Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sat, 2 Jun 2018 15:39:27 -0400 Subject: [PATCH] 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);