mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-28 08:10:11 +02:00
fix download and start
java.nio allows to move a file also onto a different filesystem, besides throwing proper error messages.
This commit is contained in:
@@ -20,9 +20,14 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||||
|
|
||||||
public class UpdateUtils {
|
public class UpdateUtils {
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(UpdateUtils.class);
|
private static final Logger logger = LogManager.getLogger(UpdateUtils.class);
|
||||||
@@ -103,8 +108,7 @@ public class UpdateUtils {
|
|||||||
String latestVersion = ripmeJson.getString("latestVersion");
|
String latestVersion = ripmeJson.getString("latestVersion");
|
||||||
if (UpdateUtils.isNewerVersion(latestVersion)) {
|
if (UpdateUtils.isNewerVersion(latestVersion)) {
|
||||||
logger.info("Found newer version: " + latestVersion);
|
logger.info("Found newer version: " + latestVersion);
|
||||||
logger.info("Downloading new version...");
|
logger.info("Downloading" +getUpdateJarURL(latestVersion) + " ...");
|
||||||
logger.info("New version found, downloading...");
|
|
||||||
try {
|
try {
|
||||||
UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion), false);
|
UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion), false);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -157,7 +161,7 @@ public class UpdateUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
configUpdateLabel.setText("<html><font color=\"green\">Downloading new version...</font></html>");
|
configUpdateLabel.setText("<html><font color=\"green\">Downloading new version...</font></html>");
|
||||||
logger.info("New version found, downloading...");
|
logger.info("New version found, downloading " + getUpdateJarURL(latestVersion));
|
||||||
try {
|
try {
|
||||||
UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion), true);
|
UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion), true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -313,13 +317,13 @@ public class UpdateUtils {
|
|||||||
// Modifying file and launching it: *nix distributions don't have any issues
|
// Modifying file and launching it: *nix distributions don't have any issues
|
||||||
// with modifying/deleting files
|
// with modifying/deleting files
|
||||||
// while they are being run
|
// while they are being run
|
||||||
File mainFile = new File(mainFileName);
|
Path newFile = Paths.get(updateFileName);
|
||||||
String mainFilePath = mainFile.getAbsolutePath();
|
Path oldFile = Paths.get(mainFileName);
|
||||||
mainFile.delete();
|
Files.move(newFile, oldFile, REPLACE_EXISTING);
|
||||||
new File(updateFileName).renameTo(new File(mainFilePath));
|
|
||||||
if (shouldLaunch) {
|
if (shouldLaunch) {
|
||||||
// No need to do it during shutdown: the file used will indeed be the new one
|
// No need to do it during shutdown: the file used will indeed be the new one
|
||||||
Runtime.getRuntime().exec("java -jar " + mainFileName);
|
logger.info("Executing: " + oldFile);
|
||||||
|
Runtime.getRuntime().exec("java -jar " + oldFile);
|
||||||
}
|
}
|
||||||
logger.info("Update installed, newer version should be executed upon relaunch");
|
logger.info("Update installed, newer version should be executed upon relaunch");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
Reference in New Issue
Block a user