Search in sources :

Example 1 with LatestInstalledItemInfo

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;
    }
}
Also used : LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) HashSet(java.util.HashSet)

Example 2 with LatestInstalledItemInfo

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();
            }
        }
    });
}
Also used : EventHandler(javafx.event.EventHandler) StageStyle(javafx.stage.StageStyle) RandomAccessFile(java.io.RandomAccessFile) Scheduler(se.light.assembly64.Scheduler) TYPE(se.light.assembly64.model.GuiLocation.TYPE) LoggerFactory(org.slf4j.LoggerFactory) PathService(se.light.assembly64.service.PathService) VBox(javafx.scene.layout.VBox) StringUtils(org.apache.commons.lang3.StringUtils) FileLock(java.nio.channels.FileLock) Application(javafx.application.Application) ArtifactType(se.light.assembly64.model.ArtifactType) LogConfig(se.light.assembly64.LogConfig) ContextMenu(javafx.scene.control.ContextMenu) Type(se.light.assembly64.Support.Type) WindowEvent(javafx.stage.WindowEvent) WorkLocation(se.light.assembly64.model.WorkLocation) Pane(javafx.scene.layout.Pane) Rectangle2D(javafx.geometry.Rectangle2D) MenuItem(javafx.scene.control.MenuItem) ButtonType(se.light.assembly64.fx.GenericMessageDialogController.ButtonType) Set(java.util.Set) Screen(javafx.stage.Screen) Artifact(se.light.assembly64.model.Artifact) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) UserService(se.light.assembly64.service.UserService) Platform(javafx.application.Platform) Duration(javafx.util.Duration) List(java.util.List) PlatformInfoService(se.light.assembly64.service.PlatformInfoService) Optional(java.util.Optional) InstallationService(se.light.assembly64.service.InstallationService) Autoupgrade(se.light.assembly64.Autoupgrade) ReturningTask(se.light.assembly64.model.ReturningTask) Scene(javafx.scene.Scene) MouseButton(javafx.scene.input.MouseButton) TreeItem(javafx.scene.control.TreeItem) GuiLocation(se.light.assembly64.model.GuiLocation) MouseEvent(javafx.scene.input.MouseEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GlobalRepoService(se.light.assembly64.service.GlobalRepoService) GenericMessageDialogController.heroesOnlyFeatureDialog(se.light.assembly64.fx.GenericMessageDialogController.heroesOnlyFeatureDialog) ArrayList(java.util.ArrayList) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) ViceService(se.light.assembly64.service.ViceService) UpgradeOptions(se.light.assembly64.Support.UpgradeOptions) FadeTransition(javafx.animation.FadeTransition) GuiUtils(se.light.assembly64.util.GuiUtils) Support(se.light.assembly64.Support) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Support.resolveInstallationExpandedKey(se.light.assembly64.Support.resolveInstallationExpandedKey) DirectoryChooser(javafx.stage.DirectoryChooser) Color(javafx.scene.paint.Color) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) MenuBar(javafx.scene.control.MenuBar) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) FileUtils(org.apache.commons.io.FileUtils) ArtifactsService(se.light.assembly64.service.ArtifactsService) File(java.io.File) Menu(javafx.scene.control.Menu) Consumer(java.util.function.Consumer) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) PlatformInfo(se.light.assembly64.model.PlatformInfo) ImageView(javafx.scene.image.ImageView) LocalDBService(se.light.assembly64.service.LocalDBService) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Support.resolveLeafInInstallationExpandedKey(se.light.assembly64.Support.resolveLeafInInstallationExpandedKey) Image(javafx.scene.image.Image) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) Set(java.util.Set) MouseEvent(javafx.scene.input.MouseEvent) Optional(java.util.Optional) TreeItem(javafx.scene.control.TreeItem) WorkLocation(se.light.assembly64.model.WorkLocation) GuiLocation(se.light.assembly64.model.GuiLocation) Artifact(se.light.assembly64.model.Artifact) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(javafx.scene.image.ImageView)

Example 3 with LatestInstalledItemInfo

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));
}
Also used : ArtifactDelta(se.light.assembly64.model.ArtifactDelta) ReturningTask(se.light.assembly64.model.ReturningTask) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Support.isRemoteArtifact(se.light.assembly64.Support.isRemoteArtifact) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) Support.getVersionAsInteger(se.light.assembly64.Support.getVersionAsInteger) ArtifactType(se.light.assembly64.model.ArtifactType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressDBController(se.light.assembly64.fx.ProgressDBController) GuiUtils(se.light.assembly64.util.GuiUtils) Map(java.util.Map) Support(se.light.assembly64.Support) Support.flush(se.light.assembly64.Support.flush) CancelableTask(se.light.assembly64.model.CancelableTask) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) Support.getObjectMapper(se.light.assembly64.Support.getObjectMapper) ContentEntry(se.light.assembly64.model.ContentEntry) GenericMessageDialogController(se.light.assembly64.fx.GenericMessageDialogController) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Artifact(se.light.assembly64.model.Artifact) Collectors(java.util.stream.Collectors) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) File(java.io.File) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) Platform(javafx.application.Platform) ProgressControlWrapper(se.light.assembly64.fx.ProgressControlWrapper) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) SearchResultItem(se.light.assembly64.model.SearchResultItem) NullWindowOwner(se.light.assembly64.fx.NullWindowOwner) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) DOWNLOAD_STATUS(se.light.assembly64.service.FTPService.DOWNLOAD_STATUS) ProgressMessageBox(se.light.assembly64.ProgressMessageBox) FILE_ACTION(se.light.assembly64.Support.FILE_ACTION) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo)

Aggregations

LatestInstalledItemInfo (se.light.assembly64.model.LatestInstalledItemInfo)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Platform (javafx.application.Platform)2 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 FileChannel (java.nio.channels.FileChannel)1 FileLock (java.nio.channels.FileLock)1 LocalDate (java.time.LocalDate)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1