Search in sources :

Example 11 with ReturningTask

use of se.light.assembly64.model.ReturningTask 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)7 Image (javafx.scene.image.Image)5 ReturningTask (se.light.assembly64.model.ReturningTask)5 ArrayList (java.util.ArrayList)4 Artifact (se.light.assembly64.model.Artifact)4 RandomAccessFile (java.io.RandomAccessFile)3 List (java.util.List)3 Set (java.util.Set)3 FadeTransition (javafx.animation.FadeTransition)3 ActionEvent (javafx.event.ActionEvent)3 EventHandler (javafx.event.EventHandler)3 ContextMenu (javafx.scene.control.ContextMenu)3 MouseEvent (javafx.scene.input.MouseEvent)3 ContentEntry (se.light.assembly64.model.ContentEntry)3 GuiLocation (se.light.assembly64.model.GuiLocation)3 PlatformInfoService (se.light.assembly64.service.PlatformInfoService)3 FileChannel (java.nio.channels.FileChannel)2 FileLock (java.nio.channels.FileLock)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2