Search in sources :

Example 11 with ExecutorUtil.executeAsyncWithRetry

use of se.light.assembly64.util.ExecutorUtil.executeAsyncWithRetry in project assembly64fx by freabemania.

the class InstallationService method housekeep.

public void housekeep(File base) {
    GenericMessageDialogController.withInfoProps("Scan was started", "Scanning " + base.getAbsolutePath()).show();
    ReturningTask<Void> task = () -> {
        final AtomicInteger emptyDirs = new AtomicInteger();
        final AtomicInteger emptyFiles = new AtomicInteger();
        for (Artifact entry : artifactsService.getArtifactsDb()) {
            if (artifactsService.isInstalled(base, entry)) {
                boolean emptyDirFound = true;
                while (emptyDirFound) {
                    emptyDirFound = false;
                    for (File f : FileUtils.listFilesAndDirs(LocalStorageUtil.getSubdirOrFile(base, entry), TrueFileFilter.TRUE, TrueFileFilter.TRUE)) {
                        if (!f.isDirectory()) {
                            if (f.length() == 0) {
                                emptyFiles.incrementAndGet();
                                FileUtils.deleteQuietly(f);
                                emptyDirFound = true;
                            }
                        } else {
                            if (f.list().length == 0 || f.getName().toUpperCase().equals("__MACOSX")) {
                                emptyDirs.incrementAndGet();
                                FileUtils.deleteQuietly(f);
                                emptyDirFound = true;
                            }
                        }
                    }
                }
            }
        }
        GenericMessageDialogController.withInfoProps("Housekeeping finished", "Removed " + emptyFiles.get() + " empty files and " + emptyDirs.get() + " dirs", true).showAndWait();
        return null;
    };
    ExecutorUtil.executeAsyncWithRetry(task, 3);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) Support.isRemoteArtifact(se.light.assembly64.Support.isRemoteArtifact) Artifact(se.light.assembly64.model.Artifact)

Example 12 with ExecutorUtil.executeAsyncWithRetry

use of se.light.assembly64.util.ExecutorUtil.executeAsyncWithRetry 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 ArrayList (java.util.ArrayList)5 Image (javafx.scene.image.Image)5 ReturningTask (se.light.assembly64.model.ReturningTask)5 MouseEvent (javafx.scene.input.MouseEvent)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 ObservableValue (javafx.beans.value.ObservableValue)3 ActionEvent (javafx.event.ActionEvent)3 EventHandler (javafx.event.EventHandler)3 ContextMenu (javafx.scene.control.ContextMenu)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