use of se.light.assembly64.model.LatestInstalledItemInfo in project assembly64fx by freabemania.
the class InstallationService method resolveLatestInstalledByLocation.
public Set<LatestInstalledItemInfo> resolveLatestInstalledByLocation(LocationAndInstallationStatus location) {
String key = location.getLocation().getPath();
if (recentlyInstalled.containsKey(key)) {
return recentlyInstalled.get(key);
} else {
List<LatestInstalledItemInfo> items = Support.readList(LatestInstalledItemInfo.class, resolvedLatestInstallationsFile(location));
int size = items.size();
items.removeIf(item -> ChronoUnit.DAYS.between(item.toLocalDate(), LocalDate.now()) > 3);
int sizeAfterCheck = items.size();
if (size != sizeAfterCheck) {
flush(items, resolvedLatestInstallationsFile(location));
}
Set<LatestInstalledItemInfo> set = new HashSet<>(items);
recentlyInstalled.put(key, set);
return set;
}
}
use of se.light.assembly64.model.LatestInstalledItemInfo in project assembly64fx by freabemania.
the class Main method refreshTree.
public static void refreshTree() {
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
ProgressbarEnhanced progressBar = (ProgressbarEnhanced) GlobalRepoService.getInstance().get("pbar");
if (progressBar != null) {
topContainer.getChildren().remove(progressBar);
}
rootItemBase.getChildren().clear();
for (WorkLocation location : userService.getLocations()) {
List<Artifact> artifactsDb = artifactsService.getArtifactsDb();
Set<LatestInstalledItemInfo> lastestAdditions = null;
if (location.exists()) {
lastestAdditions = InstallationService.getInstance().resolveLatestInstalledByLocation(location.toLocationAndInstallation());
} else {
lastestAdditions = lastestAdditionsNotFound;
}
ImageView icon = new ImageView();
icon.setFitWidth(20);
icon.setFitHeight(20);
if (location.exists()) {
if (userService.isInstallationPrimary(location.getId())) {
icon.setImage(ImageResolveService.getInstance().getImage("image-root-primary.png"));
} else {
icon.setImage(ImageResolveService.getInstance().getImage("image-root.png"));
}
TreeItem<GuiLocation> rootItem = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION_ROOT).name(Support.removeEndingSlash(location.getPath())).build(), icon);
rootItem.setExpanded(localDbService.getBooleanLocalDBSetting(resolveInstallationExpandedKey(location.getId()), false));
rootItemBase.getChildren().add(rootItem);
TreeItem<GuiLocation> leaf = rootItem;
for (Artifact entry : artifactsDb) {
String node = entry.getPrefix();
if (node != null) {
String[] path = node.split("/");
String leafKey = "";
for (String pathItem : path) {
leafKey += pathItem + "/";
ImageView testIcon = new ImageView();
testIcon.setFitWidth(20);
testIcon.setFitHeight(20);
if (checkIfFolderNeedsUpdate(leafKey, location) && userService.isPremium()) {
testIcon.setImage(ImageResolveService.getInstance().getImage("image-folder-updateneeded.png"));
} else {
testIcon.setImage(ImageResolveService.getInstance().getImage("image-folder.png"));
}
Optional<TreeItem<GuiLocation>> categoryItem = leaf.getChildren().stream().filter(item -> item.getValue().getName() != null && item.getValue().getName().equals(pathItem)).findFirst();
if (!categoryItem.isPresent()) {
TreeItem<GuiLocation> depNode = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.LEAF).name(pathItem).leafKey(leafKey).build(), testIcon);
leaf.getChildren().add(depNode);
leaf = depNode;
} else {
leaf = categoryItem.get();
}
leaf.setExpanded(localDbService.getBooleanLocalDBSetting(resolveLeafInInstallationExpandedKey(leaf.getValue()), false));
}
// we're at thre position in the list now with the correct leaf
if (!localDbService.hasLocalDBSetting("exclude_" + location.getId() + "_" + entry.getName())) {
ImageView itemIcon = new ImageView();
itemIcon.setFitWidth(16);
itemIcon.setFitHeight(16);
if (entry.getCurrentInstallingId() != null && entry.getCurrentInstallingId().equals(location.getId())) {
if (entry.isMarkedForUpdate() && !entry.isUpdating()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-waiting.png"));
} else if (entry.isUpdating()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-install2.png"));
}
} else {
if (entry.getHero() && userService.isFreemium()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notavailable.png"));
} else if (entry.getType() == ArtifactType.LOCAL && !artifactsService.isPrivateDirAvailable()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notavailable.png"));
} else if (!artifactsService.isInstalled(location.toLocationAndInstallation(), entry)) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notinstalled2bw.png"));
} else if (artifactsService.needsUpdate(location.toLocationAndInstallation(), entry)) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-needsupdatebw.png"));
} else {
Optional<LatestInstalledItemInfo> findFirst = lastestAdditions.stream().filter(item -> item.getId().equals(entry.getName())).findFirst();
if (findFirst.isPresent() && userService.isPremium()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-updated-new.png"));
} else {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-updated2.png"));
}
}
}
TreeItem<GuiLocation> depNode = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION).artifact(entry).build(), itemIcon);
leaf.getChildren().add(depNode);
}
// reset
leaf = rootItem;
}
}
} else {
icon.setImage(ImageResolveService.getInstance().getImage("image-root-invalid.png"));
TreeItem<GuiLocation> rootItem = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION_ROOT).name(Support.removeEndingSlash(location.getPath())).build(), icon);
rootItemBase.getChildren().add(rootItem);
}
}
if (Scheduler.getInstance() != null && Scheduler.getInstance().isWorking() && ProgressControlWrapper.getInstance().isClosed()) {
int height = 25;
progressBar = new ProgressbarEnhanced();
progressBar.setMinWidth(300);
progressBar.setMinHeight(height);
progressBar.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent event) -> handleMouseClicked2(event));
topContainer.getChildren().add(1, progressBar);
GlobalRepoService.getInstance().put("pbar", progressBar);
tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight() - height);
} else {
tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight());
}
} catch (Exception e) {
LOGGER.error("Unable to refresh view", e);
GenericMessageDialogController.withErrorProps("Ooops", "Unable to refresh view").showAndWait();
}
}
});
}
use of se.light.assembly64.model.LatestInstalledItemInfo in project assembly64fx by freabemania.
the class InstallationService method addToLatestInstalled.
public void addToLatestInstalled(LocationAndInstallationStatus location, Artifact entry) {
Set<LatestInstalledItemInfo> latestItems = resolveLatestInstalledByLocation(location);
Optional<LatestInstalledItemInfo> foundItem = latestItems.stream().filter(item -> item.getId().equals(entry.getName())).findFirst();
LatestInstalledItemInfo updatedItem = LatestInstalledItemInfo.builder().id(entry.getName()).date(getTodayDateAsBasicIsoString()).build();
if (foundItem.isPresent()) {
latestItems.remove(foundItem.get());
}
latestItems.add(updatedItem);
flush(latestItems, resolvedLatestInstallationsFile(location));
}
Aggregations