use of se.light.assembly64.model.Artifact 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.model.Artifact in project assembly64fx by freabemania.
the class InstallationService method installDelta.
private void installDelta(LocationAndInstallationStatus location, Artifact entry) throws Exception {
LOGGER.info("Updating " + entry.getName());
if (entry.isCreateDelta()) {
Integer latestUpdated = getVersionAsInteger(artifactsService.getLatestVersion(artifactsService.resolveDB(location, entry)));
List<ArtifactDelta> entries = entry.getDeltas().stream().filter(item -> {
return getVersionAsInteger(item.getVersion()) > latestUpdated;
}).collect(Collectors.toList());
CancelableTask cancelTask = CancelableTask.of();
for (ArtifactDelta e : entries) {
if (cancelTask.isRunning()) {
if (entry.isDynamicImport()) {
File file = installEntry(location, entry, entry.getBaseDir() + "/delta", e.getFile(), e.getVersion(), true, true);
unpackDynamic(file, location, entry, e);
if (!cancelTask.isCancelled()) {
updateDb(location, entry, e.getVersion());
} else {
break;
}
} else {
installEntry(location, entry, entry.getBaseDir() + "/delta", e.getFile(), e.getVersion());
}
} else {
ProgressControlWrapper.getInstance().setProgressLabel("Cancelling");
return;
}
}
} else {
ProgressControlWrapper.getInstance().setProgressLabel("Will delete current folder " + entry.getName() + ", please wait...");
FileUtils.deleteQuietly(LocalStorageUtil.getSubdirOrFile(location.getLocation(), entry.getAbsoluteInstallationPath()));
ProgressControlWrapper.getInstance().setProgressLabel("Installing new version");
installEntry(location, entry, entry.getBaseDir(), entry.getFile(), entry.getVersion());
}
}
use of se.light.assembly64.model.Artifact in project assembly64fx by freabemania.
the class InstallationService method install.
public void install(LocationAndInstallationStatus location, Artifact entry, boolean updateProgressWindow) throws Exception {
CancelableTask cancelTask = CancelableTask.of();
if (isRemoteArtifact(entry)) {
if (!artifactsService.isInstalled(location, entry)) {
Analytics.sendEvent("install_item", "artifact_" + entry.getName());
installFull(location, entry);
} else if (artifactsService.needsUpdate(location, entry)) {
Analytics.sendEvent("update_item", "artifact_" + entry.getName());
installDelta(location, entry);
}
} else {
ProgressControlWrapper.getInstance().setProgressLabel("Installing local folder!!!");
artifactsService.updateChecksumInPrivateFolder();
FileUtils.copyDirectory(new File(localDbService.getPrivateDir()), LocalStorageUtil.getSubdirOrFile(LocalStorageUtil.getSubdirOrFile(location.getLocation(), "Misc"), localDbService.getPrivateDirName()));
artifactsService.updateChecksumInInstallation(location);
}
if (updateProgressWindow) {
updateProgressDialog(cancelTask);
}
}
use of se.light.assembly64.model.Artifact in project assembly64fx by freabemania.
the class InstallationService method installEntry.
private File installEntry(LocationAndInstallationStatus installLocation, Artifact entry, String remotePath, String remoteName, String version, Boolean skipUnpack, Boolean updateProgressBar) throws Exception {
CancelableTask cancelTask = CancelableTask.of();
int ctr = 0;
// to keep track of the progressupdates if something fails
int progressUpdated = 0;
if (entry.getType() == ArtifactType.REMOTE) {
while (ctr < 3 && cancelTask.isRunning()) {
LOGGER.info("Installing " + entry.getName());
ProgressMessageBox.setMessage("Fetching " + entry.getName());
ProgressControlWrapper.getInstance().setProgressLabel("Fetching file " + remoteName);
File target = new File(pathService.getTmpFolderAsString() + remoteName);
if (target.exists() && ftpService.registerDownload(remoteName, DOWNLOAD_STATUS.CHECK)) {
ProgressControlWrapper.getInstance().setProgressLabel("Waiting for other worker to finish downloading " + remoteName);
ProgressControlWrapper.getInstance().increaseCurrentProgressStep(1);
while (true) {
if (!ftpService.registerDownload(remoteName, DOWNLOAD_STATUS.CHECK)) {
LOGGER.info(remoteName + " was downloaded by another thread");
break;
} else if (cancelTask.isCancelled()) {
return null;
}
Thread.sleep(500);
}
} else if (!target.exists()) {
if (!ftpService.registerDownload(remoteName, DOWNLOAD_STATUS.ADD)) {
ftpService.getFile(remotePath, remoteName, target);
if (cancelTask.isCancelled()) {
return null;
}
} else {
ProgressControlWrapper.getInstance().setProgressLabel("Waiting for other worker to finish downloading " + remoteName);
ProgressControlWrapper.getInstance().increaseCurrentProgressStep(1);
while (true) {
if (!ftpService.registerDownload(remoteName, DOWNLOAD_STATUS.CHECK)) {
LOGGER.info(remoteName + " was downloaded by another thread");
break;
} else if (cancelTask.isCancelled()) {
return null;
}
Thread.sleep(1000);
}
}
} else if (target.exists()) {
LOGGER.info("Target " + target.getAbsolutePath() + " was already downloaded");
}
if (progressUpdated < 2 && updateProgressBar) {
ProgressControlWrapper.getInstance().increaseProgress();
}
progressUpdated++;
if (cancelTask.isCancelled()) {
return null;
}
if (!skipUnpack) {
try {
ProgressMessageBox.setMessage("Installing file " + entry.getName() + "at " + LocalStorageUtil.getSubdirOrFile(installLocation.getLocation(), entry.getPrefix()));
unzipService.extractZip(target, LocalStorageUtil.getSubdirOrFile(installLocation.getLocation(), entry.getPrefix()), entry);
// unzipService.extractZip(target, installLocation.getLocation(), entry);
ProgressControlWrapper.getInstance().increaseProgress();
if (progressUpdated < 2 && updateProgressBar) {
ProgressControlWrapper.getInstance().setProgressLabel("Fetched file " + remoteName);
}
progressUpdated++;
if (!cancelTask.isCancelled()) {
updateDb(installLocation, entry, version);
}
ProgressControlWrapper.getInstance().setProgressLabel("Done");
return target;
} catch (Exception e) {
LOGGER.error("Something bad", e);
Analytics.sendEvent("invalid_zip", entry.getName());
FileUtils.forceDelete(target);
ctr++;
}
} else {
ProgressControlWrapper.getInstance().setProgressLabel("Done");
return target;
}
}
}
throw new IllegalStateException("U1nable to install entry " + remoteName);
}
use of se.light.assembly64.model.Artifact in project assembly64fx by freabemania.
the class Scheduler method addToQueue.
public void addToQueue(Integer installation, Artifact entry) {
File location = UserService.getInstance().getLocation(installation).asFile();
Optional<LocationAndArtifactToInstall> itemPossiblyAlreadyInList = workQueue.stream().filter(item -> item.getArtifact().getName().equals(entry.getName())).findFirst();
LocationAndInstallationStatus tmp = LocationAndInstallationStatus.builder().location(location).id(installation).build();
if (itemPossiblyAlreadyInList.isPresent()) {
LOGGER.info("Adding " + entry.getName() + " " + installation + " to already in queue");
ProgressControlWrapper.getInstance().addProgressSteps(countNofItems(tmp, entry));
itemPossiblyAlreadyInList.get().addLocationAndInstallationStatus(tmp);
} else if (currentlyInstalling.containsKey(entry.getName())) {
LOGGER.info("Adding " + entry.getName() + " to current worker");
ProgressControlWrapper.getInstance().addProgressSteps(countNofItems(tmp, entry));
currentlyInstalling.get(entry.getName()).addLocationAndInstallationStatus(tmp);
} else {
Optional<Artifact> first = artifactsService.getArtifactsDb().stream().filter(item -> item.isMarkedForUpdate() || item.isUpdating()).findFirst();
LocationAndInstallationStatus locationAndInstallation = LocationAndInstallationStatus.builder().location(location).id(installation).build();
if (!first.isPresent()) {
ProgressControlWrapper.getInstance().resetThreadIdMapping();
ProgressControlWrapper.getInstance().setProgressSteps(countNofItems(locationAndInstallation, entry));
} else {
ProgressControlWrapper.getInstance().addProgressSteps(countNofItems(locationAndInstallation, entry));
}
entry.setMarkedForUpdate(true);
// Main.resolveFXMain().refreshTree();
Support.refreshTree();
workQueue.offer(LocationAndArtifactToInstall.builder().artifact(entry).locationsAndInstallationStatus(LocationAndInstallationStatus.builder().location(location).id(installation).build()).build());
}
}
Aggregations