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