Search in sources :

Example 1 with PlatformInfoService

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);
    }
}
Also used : ProgressDBController(se.light.assembly64.fx.ProgressDBController) CommandLine(org.apache.commons.exec.CommandLine) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ReturningTask(se.light.assembly64.model.ReturningTask) File(java.io.File) PlatformInfoService(se.light.assembly64.service.PlatformInfoService) CancelableTask(se.light.assembly64.model.CancelableTask)

Aggregations

File (java.io.File)1 CommandLine (org.apache.commons.exec.CommandLine)1 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1 ProgressDBController (se.light.assembly64.fx.ProgressDBController)1 CancelableTask (se.light.assembly64.model.CancelableTask)1 ReturningTask (se.light.assembly64.model.ReturningTask)1 PlatformInfoService (se.light.assembly64.service.PlatformInfoService)1