Search in sources :

Example 1 with ProgressDBController

use of se.light.assembly64.fx.ProgressDBController in project assembly64fx by freabemania.

the class SearchViewFilesController method downloadFilesAsync.

private void downloadFilesAsync(List<ContentEntry> selectedItems, String customPath) {
    CancelableTask cancelTask = CancelableTask.of();
    ProgressDBController controller = GuiUtils.showDialogOwnerNoWait("progressBarDbUpdate.fxml", "Progress", true, getStage(), new Object[] { selectedItems.size(), cancelTask, customPath + searchedItem.getCategoryShortName() + "/" + searchedItem.getName(), "Files were installed to " + customPath + searchedItem.getName() });
    ReturningTask<Void> task = () -> {
        int failureCtr = 0;
        for (ContentEntry selectedItem : selectedItems) {
            if (cancelTask.isCancelled()) {
                break;
            }
            try {
                downloadService.downloadItem(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), searchedItem.getName(), selectedItem.getName(), searchedItem.getCategoryShortName(), FILE_ACTION.DOWNLOAD, customPath);
            } catch (Exception e) {
                failureCtr++;
            }
            controller.setProgressLabel("Installing " + selectedItem.getName());
            controller.increaseProgress();
        }
        if (failureCtr == 0) {
            controller.progressDone();
        } else {
            controller.progressDone(failureCtr + " of " + selectedItems.size() + " could not be installed to " + customPath);
        }
        return null;
    };
    ExecutorUtil.executeAsyncWithRetry(task, 3);
}
Also used : ContentEntry(se.light.assembly64.model.ContentEntry) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 2 with ProgressDBController

use of se.light.assembly64.fx.ProgressDBController in project assembly64fx by freabemania.

the class SidifyExportPlaylistController method export.

public void export() throws Exception {
    int idx = locations.getSelectionModel().getSelectedIndex();
    List<String> exportLocations = new ArrayList<>();
    if (idx != 0) {
        exportLocations.addAll(Collections.singletonList(locations.getSelectionModel().getSelectedItem()));
    } else {
        exportLocations.addAll(locations.getItems().stream().filter(item -> !item.equals(ALL_LOCATIONS)).collect(Collectors.toList()));
    }
    int items = playlists.stream().map(item -> playlistService.getSongsForPlaylist(item)).map(item -> item.size()).mapToInt(i -> i.intValue()).sum() * exportLocations.size();
    CancelableTask cancelTask = CancelableTask.of();
    ProgressDBController controller = GuiUtils.showDialogOwnerNoWait("progressBarDbUpdate.fxml", "Progress", true, NullWindowOwner.of(), new Object[] { items, cancelTask, exportLocations.get(0) + MUSIC_SIDIFY, "Playlist exported to <location>/Music/Sidify" });
    NonReturningTask t = () -> {
        try {
            for (PlaylistInfo playlist : playlists) {
                List<PlaylistEntry> songsForPlaylist = playlistService.getSongsForPlaylist(playlist);
                int padding = Integer.valueOf(String.valueOf(songsForPlaylist.size()).length());
                for (String dir : exportLocations) {
                    File exportDir = new File(dir + MUSIC_SIDIFY + playlist.getName());
                    FileUtils.deleteQuietly(exportDir);
                    FileUtils.forceMkdir(exportDir);
                    int ctr = 1;
                    for (PlaylistEntry entry : playlistService.getSongsForPlaylist(playlist)) {
                        String pos = String.format("%0" + padding + "d", ctr);
                        try {
                            controller.increaseProgress();
                            controller.setProgressLabel("Exporting " + entry.getNameMasked());
                            FileUtils.copyFile(downloadService.getSid(entry), new File(exportDir + "/" + pos + "_" + entry.getNameMasked() + ".sid"));
                            ctr++;
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (cancelTask.isCancelled()) {
                            FileUtils.deleteQuietly(exportDir);
                            break;
                        }
                    }
                }
                if (cancelTask.isCancelled()) {
                    break;
                }
            }
        } finally {
            controller.progressDone();
        }
    };
    ExecutorUtil.executeAsync(t);
}
Also used : NonReturningTask(se.light.assembly64.model.NonReturningTask) PlaylistEntry(se.light.assembly64.model.PlaylistEntry) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) FileUtils(org.apache.commons.io.FileUtils) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) Collectors(java.util.stream.Collectors) File(java.io.File) ChoiceBox(javafx.scene.control.ChoiceBox) UserService(se.light.assembly64.service.UserService) ArrayList(java.util.ArrayList) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GuiUtils(se.light.assembly64.util.GuiUtils) CancelableTask(se.light.assembly64.model.CancelableTask) WorkLocation(se.light.assembly64.model.WorkLocation) DownloadArtifactsService(se.light.assembly64.service.DownloadArtifactsService) PlaylistService(se.light.assembly64.service.PlaylistService) Collections(java.util.Collections) BaseGuiController(se.light.assembly64.model.BaseGuiController) ArrayList(java.util.ArrayList) NonReturningTask(se.light.assembly64.model.NonReturningTask) ArrayList(java.util.ArrayList) List(java.util.List) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) PlaylistEntry(se.light.assembly64.model.PlaylistEntry) File(java.io.File) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 3 with ProgressDBController

use of se.light.assembly64.fx.ProgressDBController in project assembly64fx by freabemania.

the class SearchController method downloadFiles.

private void downloadFiles(List<SearchResultItem> selectedItems, String downloadPath) {
    if (selectedItems.size() > MAX_DOWNLOADSPAN) {
        GenericMessageDialogController.withErrorProps("Ooops...", "Please narrow downloadspan").showAndWait();
        return;
    }
    CancelableTask cancelTask = CancelableTask.of();
    ProgressDBController controller = GuiUtils.showDialogOwnerNoWait("progressBarDbUpdate.fxml", "Progress", true, getStage(), new Object[] { selectedItems.size(), cancelTask, downloadPath, "Files were installed to " + downloadPath });
    ReturningTask<Void> task = () -> {
        int failureCtr = 0;
        for (SearchResultItem item : selectedItems) {
            if (cancelTask.isCancelled()) {
                break;
            }
            controller.setProgressLabel("Installing " + item.getName());
            controller.increaseProgress();
            boolean res = downloadEntryAndSubItems(item, downloadPath);
            if (!res) {
                failureCtr++;
            }
        }
        if (failureCtr == 0) {
            controller.progressDone();
        } else {
            controller.progressDone(failureCtr + " of " + selectedItems.size() + " could not be installed to " + downloadPath);
        }
        return null;
    };
    ExecutorUtil.executeAsyncWithRetry(task, 3);
}
Also used : SearchResultItem(se.light.assembly64.model.SearchResultItem) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 4 with ProgressDBController

use of se.light.assembly64.fx.ProgressDBController 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

CancelableTask (se.light.assembly64.model.CancelableTask)4 File (java.io.File)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Platform (javafx.application.Platform)1 FXML (javafx.fxml.FXML)1 ChoiceBox (javafx.scene.control.ChoiceBox)1 CommandLine (org.apache.commons.exec.CommandLine)1 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1 FileUtils (org.apache.commons.io.FileUtils)1 ProgressDBController (se.light.assembly64.fx.ProgressDBController)1 BaseGuiController (se.light.assembly64.model.BaseGuiController)1 ContentEntry (se.light.assembly64.model.ContentEntry)1 NonReturningTask (se.light.assembly64.model.NonReturningTask)1 PlaylistEntry (se.light.assembly64.model.PlaylistEntry)1 PlaylistInfo (se.light.assembly64.model.PlaylistInfo)1 ReturningTask (se.light.assembly64.model.ReturningTask)1