Can now update ripme using the -j flag
This commit is contained in:
parent
30a2d015aa
commit
7dc8b23aae
@ -198,7 +198,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
||||
if (!configurationPanel.isVisible()) {
|
||||
optionConfiguration.doClick();
|
||||
}
|
||||
Runnable r = () -> UpdateUtils.updateProgram(configUpdateLabel);
|
||||
Runnable r = () -> UpdateUtils.updateProgramGUI(configUpdateLabel);
|
||||
new Thread(r).start();
|
||||
}
|
||||
|
||||
@ -786,7 +786,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
||||
}
|
||||
});
|
||||
configUpdateButton.addActionListener(arg0 -> {
|
||||
Thread t = new Thread(() -> UpdateUtils.updateProgram(configUpdateLabel));
|
||||
Thread t = new Thread(() -> UpdateUtils.updateProgramGUI(configUpdateLabel));
|
||||
t.start();
|
||||
});
|
||||
configLogLevelCombobox.addActionListener(arg0 -> {
|
||||
|
@ -20,7 +20,7 @@ import com.rarchives.ripme.utils.Utils;
|
||||
public class UpdateUtils {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(UpdateUtils.class);
|
||||
private static final String DEFAULT_VERSION = "1.7.50";
|
||||
private static final String DEFAULT_VERSION = "1.7.49";
|
||||
private static final String REPO_NAME = "ripmeapp/ripme";
|
||||
private static final String updateJsonURL = "https://raw.githubusercontent.com/" + REPO_NAME + "/master/ripme.json";
|
||||
private static final String mainFileName = "ripme.jar";
|
||||
@ -39,8 +39,57 @@ public class UpdateUtils {
|
||||
}
|
||||
return thisVersion;
|
||||
}
|
||||
public static void updateProgramCLI() {
|
||||
logger.info("Checking for update...");
|
||||
|
||||
public static void updateProgram(JLabel configUpdateLabel) {
|
||||
Document doc = null;
|
||||
try {
|
||||
logger.debug("Retrieving " + UpdateUtils.updateJsonURL);
|
||||
doc = Jsoup.connect(UpdateUtils.updateJsonURL)
|
||||
.timeout(10 * 1000)
|
||||
.ignoreContentType(true)
|
||||
.get();
|
||||
} catch (IOException e) {
|
||||
logger.error("Error while fetching update: ", e);
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"<html><font color=\"red\">Error while fetching update: " + e.getMessage() + "</font></html>",
|
||||
"RipMe Updater",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
} finally {
|
||||
logger.info("Current version: " + getThisJarVersion());
|
||||
}
|
||||
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("<br> + ").append(change);
|
||||
}
|
||||
|
||||
String latestVersion = ripmeJson.getString("latestVersion");
|
||||
if (UpdateUtils.isNewerVersion(latestVersion)) {
|
||||
logger.info("Found newer version: " + latestVersion);
|
||||
logger.info("Downloading new version...");
|
||||
logger.info("New version found, downloading...");
|
||||
try {
|
||||
UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion), false);
|
||||
} catch (IOException e) {
|
||||
logger.error("Error while updating: ", e);
|
||||
}
|
||||
} else {
|
||||
logger.debug("This version (" + UpdateUtils.getThisJarVersion() +
|
||||
") is the same or newer than the website's version (" + latestVersion + ")");
|
||||
logger.info("v" + UpdateUtils.getThisJarVersion() + " is the latest version");
|
||||
logger.debug("Running latest version: " + UpdateUtils.getThisJarVersion());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateProgramGUI(JLabel configUpdateLabel) {
|
||||
configUpdateLabel.setText("Checking for update...");
|
||||
|
||||
Document doc = null;
|
||||
@ -90,7 +139,7 @@ public class UpdateUtils {
|
||||
configUpdateLabel.setText("<html><font color=\"green\">Downloading new version...</font></html>");
|
||||
logger.info("New version found, downloading...");
|
||||
try {
|
||||
UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion));
|
||||
UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion), true);
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Error while updating: " + e.getMessage(),
|
||||
@ -166,7 +215,7 @@ public class UpdateUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void downloadJarAndLaunch(String updateJarURL)
|
||||
private static void downloadJarAndLaunch(String updateJarURL, Boolean shouldLaunch)
|
||||
throws IOException {
|
||||
Response response;
|
||||
response = Jsoup.connect(updateJarURL)
|
||||
@ -190,7 +239,7 @@ public class UpdateUtils {
|
||||
} else {
|
||||
logger.info("Hash is good");
|
||||
}
|
||||
|
||||
if (shouldLaunch) {
|
||||
// Setup updater script
|
||||
final String batchFile, script;
|
||||
final String[] batchExec;
|
||||
@ -205,10 +254,9 @@ public class UpdateUtils {
|
||||
+ "del " + updateFileName + "\r\n"
|
||||
+ "ripme.jar" + "\r\n"
|
||||
+ "del " + batchPath + "\r\n";
|
||||
batchExec = new String[] { batchPath };
|
||||
batchExec = new String[]{batchPath};
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Mac / Linux
|
||||
batchFile = "update_ripme.sh";
|
||||
String batchPath = new File(batchFile).getAbsolutePath();
|
||||
@ -220,7 +268,7 @@ public class UpdateUtils {
|
||||
+ "java -jar \"" + new File(mainFileName).getAbsolutePath() + "\" &\n"
|
||||
+ "sleep 1" + "\n"
|
||||
+ "rm -f " + batchPath + "\n";
|
||||
batchExec = new String[] { "sh", batchPath };
|
||||
batchExec = new String[]{"sh", batchPath};
|
||||
}
|
||||
|
||||
// Create updater script
|
||||
@ -242,6 +290,10 @@ public class UpdateUtils {
|
||||
}));
|
||||
logger.info("Exiting older version, should execute update script (" + batchFile + ") during exit");
|
||||
System.exit(0);
|
||||
} else {
|
||||
new File(mainFileName).delete();
|
||||
new File(updateFileName).renameTo(new File(mainFileName));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user