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);
}
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);
}
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);
}
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);
}
}
Aggregations