use of se.light.assembly64.service.PlatformInfoService in project assembly64fx by freabemania.
the class Autoupgrade method doUpgrade.
public void doUpgrade() {
PlatformInfoService platformService = PlatformInfoService.getInstance();
String upgradeFile = platformService.getPlatformDBSetting("dist");
String script = platformService.getPlatformDBSetting("script");
try {
CancelableTask cancelTask = CancelableTask.of();
ProgressDBController controller = GuiUtils.showDialogOwnerNoWait("progressBarDbUpdate.fxml", "Progress", true, NullWindowOwner.of(), new Object[] { 4, cancelTask, "", "Will not really happen" });
controller.hideAllButtons();
ReturningTask<Void> upgradeTask = () -> {
GlobalRepoService.getInstance().put("upgrading", "true");
controller.increaseProgress();
controller.setProgressLabel("Downloading new files " + upgradeFile);
File downloaded = FTPService.getInstance().getFile("/artifacts", upgradeFile, new File(PathService.getInstance().getTmpFolderAsString() + upgradeFile), false);
controller.increaseProgress();
File currfolder = new File("..");
LOGGER.info("Unpack");
controller.setProgressLabel("Unpacking");
unzipService.extractZip(downloaded, new File(currfolder.getAbsolutePath() + "/tmp"));
controller.increaseProgress();
try {
FileUtils.copyFile(new File(currfolder.getAbsolutePath() + "/tmp/assembly64/update/update.bat"), new File(currfolder.getAbsolutePath() + "/update/update.bat"));
} catch (Exception e) {
}
LOGGER.info("Done! Restarting, please wait");
controller.increaseProgress();
controller.setProgressLabel("Restarting");
Thread.sleep(2000);
ReturningTask<Void> installTask = () -> {
String cmd = "\"" + currfolder.getAbsolutePath() + "/update/" + script + "\" \"" + currfolder.getAbsolutePath() + "/tmp/assembly64\" \"" + currfolder.getAbsolutePath() + "\" \"" + currfolder.getAbsolutePath() + "/assembly64.exe\"";
cmd = cmd.replace("/", "\\");
LOGGER.info("Launching external script " + cmd);
CommandLine commandLine = CommandLine.parse(cmd);
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(0);
executor.execute(commandLine);
return null;
};
ExecutorUtil.executeAsyncWithRetry(installTask);
Thread.sleep(2000);
System.exit(0);
return null;
};
ExecutorUtil.executeAsyncWithRetry(upgradeTask);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations