Merge pull request #656 from cyian-1756/updateImprovements
Various update improvements
This commit is contained in:
commit
53b22f8535
@ -39,6 +39,20 @@ public class UpdateUtils {
|
|||||||
}
|
}
|
||||||
return thisVersion;
|
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() {
|
public static void updateProgramCLI() {
|
||||||
logger.info("Checking for update...");
|
logger.info("Checking for update...");
|
||||||
|
|
||||||
@ -61,15 +75,10 @@ public class UpdateUtils {
|
|||||||
}
|
}
|
||||||
String jsonString = doc.body().html().replaceAll(""", "\"");
|
String jsonString = doc.body().html().replaceAll(""", "\"");
|
||||||
ripmeJson = new JSONObject(jsonString);
|
ripmeJson = new JSONObject(jsonString);
|
||||||
JSONArray jsonChangeList = ripmeJson.getJSONArray("changeList");
|
|
||||||
StringBuilder changeList = new StringBuilder();
|
String changeList = getChangeList(ripmeJson);
|
||||||
for (int i = 0; i < jsonChangeList.length(); i++) {
|
|
||||||
String change = jsonChangeList.getString(i);
|
logger.info("Change log: \n" + changeList);
|
||||||
if (change.startsWith(UpdateUtils.getThisJarVersion() + ":")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
changeList.append("<br> + ").append(change);
|
|
||||||
}
|
|
||||||
|
|
||||||
String latestVersion = ripmeJson.getString("latestVersion");
|
String latestVersion = ripmeJson.getString("latestVersion");
|
||||||
if (UpdateUtils.isNewerVersion(latestVersion)) {
|
if (UpdateUtils.isNewerVersion(latestVersion)) {
|
||||||
@ -111,15 +120,8 @@ public class UpdateUtils {
|
|||||||
}
|
}
|
||||||
String jsonString = doc.body().html().replaceAll(""", "\"");
|
String jsonString = doc.body().html().replaceAll(""", "\"");
|
||||||
ripmeJson = new JSONObject(jsonString);
|
ripmeJson = new JSONObject(jsonString);
|
||||||
JSONArray jsonChangeList = ripmeJson.getJSONArray("changeList");
|
|
||||||
StringBuilder changeList = new StringBuilder();
|
String changeList = getChangeList(ripmeJson);
|
||||||
for (int i = 0; i < jsonChangeList.length(); i++) {
|
|
||||||
String change = jsonChangeList.getString(i);
|
|
||||||
if (change.startsWith(UpdateUtils.getThisJarVersion() + ":")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
changeList.append("<br> + ").append(change);
|
|
||||||
}
|
|
||||||
|
|
||||||
String latestVersion = ripmeJson.getString("latestVersion");
|
String latestVersion = ripmeJson.getString("latestVersion");
|
||||||
if (UpdateUtils.isNewerVersion(latestVersion)) {
|
if (UpdateUtils.isNewerVersion(latestVersion)) {
|
||||||
@ -127,7 +129,7 @@ public class UpdateUtils {
|
|||||||
int result = JOptionPane.showConfirmDialog(
|
int result = JOptionPane.showConfirmDialog(
|
||||||
null,
|
null,
|
||||||
"<html><font color=\"green\">New version (" + latestVersion + ") is available!</font>"
|
"<html><font color=\"green\">New version (" + latestVersion + ") is available!</font>"
|
||||||
+ "<br><br>Recent changes:" + changeList.toString()
|
+ "<br><br>Recent changes:" + changeList
|
||||||
+ "<br><br>Do you want to download and run the newest version?</html>",
|
+ "<br><br>Do you want to download and run the newest version?</html>",
|
||||||
"RipMe Updater",
|
"RipMe Updater",
|
||||||
JOptionPane.YES_NO_OPTION);
|
JOptionPane.YES_NO_OPTION);
|
||||||
@ -157,6 +159,11 @@ public class UpdateUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNewerVersion(String latestVersion) {
|
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());
|
int[] oldVersions = versionStringToInt(getThisJarVersion());
|
||||||
int[] newVersions = versionStringToInt(latestVersion);
|
int[] newVersions = versionStringToInt(latestVersion);
|
||||||
if (oldVersions.length < newVersions.length) {
|
if (oldVersions.length < newVersions.length) {
|
||||||
@ -227,17 +234,20 @@ public class UpdateUtils {
|
|||||||
try (FileOutputStream out = new FileOutputStream(updateFileName)) {
|
try (FileOutputStream out = new FileOutputStream(updateFileName)) {
|
||||||
out.write(response.bodyAsBytes());
|
out.write(response.bodyAsBytes());
|
||||||
}
|
}
|
||||||
String updateHash = createSha256(new File(updateFileName));
|
// Only check the hash if the user hasn't disabled hash checking
|
||||||
logger.info("Download of new version complete; saved to " + updateFileName);
|
if (Utils.getConfigBoolean("security.check_update_hash", true)) {
|
||||||
logger.info("Checking hash of update");
|
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)) {
|
if (!ripmeJson.getString("currentHash").equals(updateHash)) {
|
||||||
logger.error("Error: Update has bad hash");
|
logger.error("Error: Update has bad hash");
|
||||||
logger.debug("Expected hash: " + ripmeJson.getString("currentHash"));
|
logger.debug("Expected hash: " + ripmeJson.getString("currentHash"));
|
||||||
logger.debug("Actual hash: " + updateHash);
|
logger.debug("Actual hash: " + updateHash);
|
||||||
throw new IOException("Got bad file hash");
|
throw new IOException("Got bad file hash");
|
||||||
} else {
|
} else {
|
||||||
logger.info("Hash is good");
|
logger.info("Hash is good");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (shouldLaunch) {
|
if (shouldLaunch) {
|
||||||
// Setup updater script
|
// Setup updater script
|
||||||
|
Loading…
Reference in New Issue
Block a user