use of se.light.assembly64.model.LocationAndInstallationStatus 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.LocationAndInstallationStatus 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.LocationAndInstallationStatus 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