Search in sources :

Example 1 with WorkLocation

use of se.light.assembly64.model.WorkLocation in project assembly64fx by freabemania.

the class LocalDBService method addWorkLocation.

public WorkLocation addWorkLocation(String path) {
    List<WorkLocation> workLocations = getWorkLocations();
    WorkLocation currentMaxLocation = workLocations.stream().max(Comparator.comparing(i -> i.getId())).orElse(WorkLocation.builder().id(-1).path(path).build());
    WorkLocation toBeAdded = WorkLocation.builder().id(currentMaxLocation.getId() + 1).path(path).build();
    workLocations.add(toBeAdded);
    storeWorkLocations(workLocations);
    return toBeAdded;
}
Also used : WorkLocation(se.light.assembly64.model.WorkLocation)

Example 2 with WorkLocation

use of se.light.assembly64.model.WorkLocation in project assembly64fx by freabemania.

the class Main method addLocation.

private static void addLocation(File location) {
    File tmp = null;
    if (location != null) {
        tmp = location;
    } else {
        tmp = new DirectoryChooser().showDialog(primaryStage);
        if (tmp != null) {
            if (userService.isLocationAlreadyAdded(tmp)) {
                GenericMessageDialogController.withErrorProps("Oops", "Dir already exist").showAndWait();
                return;
            } else {
                if (UserService.getInstance().isFreemium() && UserService.getInstance().getLocations().size() > 0) {
                    GenericMessageDialogController.withErrorProps("Oops", "Only one location for free-edition is allowed").showAndWait();
                    return;
                }
            }
        }
    }
    if (tmp != null) {
        WorkLocation createdLocation = userService.addLocation(tmp);
        if (userService.getExistingLocations().size() == 1) {
            userService.setPrimaryInstallationId(createdLocation.getId());
            LOGGER.info("Setting first installation (" + createdLocation.getId() + ") to primary");
        }
        try {
            PathService.getInstance().renameDbFolder(createdLocation);
            InstallationService.getInstance().createDbFolder(tmp);
            refreshTree();
            examineContent();
            artifactsService.assertCorrectTargetFolderNames(tmp);
            LOGGER.info("Selected location " + tmp.getAbsolutePath());
            Analytics.sendEvent("application_click", "select_location");
        } catch (Exception e) {
            LOGGER.error("Unable to set workingdir", e);
            GenericMessageDialogController.withErrorProps("Oops", "Unable to set workingdir").showAndWait();
        }
    }
}
Also used : WorkLocation(se.light.assembly64.model.WorkLocation) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser)

Example 3 with WorkLocation

use of se.light.assembly64.model.WorkLocation 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 4 with WorkLocation

use of se.light.assembly64.model.WorkLocation in project assembly64fx by freabemania.

the class Main method viewPrimary.

public void viewPrimary() {
    primaryStage = new Stage();
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        public void handle(WindowEvent we) {
            System.exit(1);
        }
    });
    if (!userService.isPremium()) {
        userService.deleteExcludesFromLocalDbQuiet();
    }
    // Setting the saved windowsize
    if (localDbService.hasLocalDBSetting("screenHeight")) {
        primaryStage.setHeight(Double.valueOf(localDbService.getLocalDBSetting("screenHeight")));
    }
    if (localDbService.hasLocalDBSetting("screenWidth")) {
        primaryStage.setWidth(Double.valueOf(localDbService.getLocalDBSetting("screenWidth")));
    }
    GuiUtils.attachIconToStage(primaryStage);
    LOGGER.info("Assembly64 v." + version + " is starting up...");
    try {
        if (userService.isPremium()) {
            primaryStage.setTitle("Assembly64 - Hero edition");
        } else {
            primaryStage.setTitle("Assembly64 - Free edition");
        }
        // menuBar = new MenuBar();
        Menu menuFile = new Menu("Assembly64");
        Menu menuLogs = new Menu("Logs");
        Menu menuMisc = new Menu("Misc");
        // A64
        MenuItem openFile = new MenuItem("Open D64/D71/D81/TAP/G64/T64/BIN/CRT/SID");
        menuFile.getItems().add(openFile);
        MenuItem settingsItem = new MenuItem("Preferences");
        menuFile.getItems().add(settingsItem);
        MenuItem exitItem = new MenuItem("Exit");
        menuFile.getItems().add(exitItem);
        // logsmenu
        MenuItem viewLogItem = new MenuItem("Systemlog");
        menuLogs.getItems().add(viewLogItem);
        MenuItem changelog = new MenuItem("Changelog");
        menuLogs.getItems().add(changelog);
        MenuItem instructions = new MenuItem("Instructions");
        menuMisc.getItems().add(instructions);
        // misc
        MenuItem backers = new MenuItem("Backers");
        menuMisc.getItems().add(backers);
        MenuItem donations = new MenuItem("Donations");
        menuMisc.getItems().add(donations);
        MenuItem feedbackItem = new MenuItem("Feedback & Feature requests");
        menuMisc.getItems().add(feedbackItem);
        MenuItem aboutItem = new MenuItem("About");
        menuMisc.getItems().add(aboutItem);
        menuBar = new MenuBar();
        menuBar.getMenus().addAll(menuFile, menuLogs, menuMisc);
        feedbackItem.setOnAction((item) -> {
            GuiUtils.showDialogBare("feedback.fxml", "Submit feedback");
        });
        exitItem.setOnAction((item) -> {
            System.exit(1);
        });
        openFile.setOnAction((item) -> {
            Analytics.sendEvent("application_click", "open_file");
            FileChooser fileChooser = new FileChooser();
            fileChooser.setTitle("Open Resource File");
            fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("All", "*.*"), new FileChooser.ExtensionFilter("PRG", "*.d64"), new FileChooser.ExtensionFilter("D64", "*.d64"), new FileChooser.ExtensionFilter("D71", "*.d71"), new FileChooser.ExtensionFilter("T64", "*.t64"), new FileChooser.ExtensionFilter("TAP", "*.d71"), new FileChooser.ExtensionFilter("G64", "*.g64"), new FileChooser.ExtensionFilter("G64", "*.tap"), new FileChooser.ExtensionFilter("D71", "*.d71"), new FileChooser.ExtensionFilter("D81", "*.d81"), new FileChooser.ExtensionFilter("BIN", "*.bin"), new FileChooser.ExtensionFilter("CRT", "*.crt"));
            launchViceOrImageView(fileChooser.showOpenDialog(primaryStage));
        });
        settingsItem.setOnAction((item) -> {
            try {
                GuiUtils.showDialogBare("mainSettings.fxml", "Settings", new Object[] {});
            } catch (Exception e) {
                LOGGER.error("Unable to view settings", e);
                GenericMessageDialogController.withErrorProps("Oops", "Unable to view settings").showAndWait();
            }
        });
        viewLogItem.setOnAction((item) -> {
            try {
                Analytics.sendEvent("application_click", "view_logs");
                GuiUtils.showDialogBare("viewFileFromDisk.fxml", "View log", new File(LogConfig.getLogFileAsString()), "Systemlog");
            } catch (Exception e) {
                LOGGER.error("Unable to view logs", e);
                GenericMessageDialogController.withErrorProps("Oops", "Unable to view logs").showAndWait();
            }
        });
        donations.setOnAction((i) -> {
            String linebreak = System.getProperty("line.separator");
            String donStr = userService.getDonations().stream().map(item -> item.dateFormatted() + linebreak + item.getName()).collect(Collectors.joining(linebreak + linebreak));
            GuiUtils.showDialogBare("viewFileFromDisk.fxml", "Donations by heroes", donStr, "Donationshistory");
        });
        backers.setOnAction((item) -> {
            try {
                String[] bck = userService.getBackers();
                int start = ThreadLocalRandom.current().nextInt(0, bck.length - 1);
                StringBuffer names = new StringBuffer();
                for (int i = 0; i < bck.length - 1; i++) {
                    int pos = (start + i) % (bck.length - 1);
                    names.append(bck[pos] + "\n");
                }
                Analytics.sendEvent("application_click", "view_backers");
                GuiUtils.showDialogBare("viewFileFromDisk.fxml", "Backing heroes of Assembly64", names.toString(), "List of backers");
            } catch (Exception e) {
                GenericMessageDialogController.withErrorProps("Oops", "Unable to view backers").showAndWait();
                LOGGER.error("Unable to view logs", e);
            }
        });
        instructions.setOnAction((item) -> {
            try {
                Analytics.sendEvent("application_click", "view_instructions");
                GuiUtils.showDialogBare("viewFileFromDisk.fxml", "This is the way", getClass().getResourceAsStream("instructions.txt"), "Instructions");
            } catch (Exception e) {
                GenericMessageDialogController.withErrorProps("Oops", "Unable to view instructions").showAndWait();
                LOGGER.error("Unable to view instructions", e);
            }
        });
        changelog.setOnAction((item) -> {
            Analytics.sendEvent("application_click", "view_changelog");
            try {
                GuiUtils.showDialogBare("viewFileFromDisk.fxml", "Haxxing haxxing haxxing", getClass().getResourceAsStream("changelog.txt"), "Changelog");
            } catch (Exception e) {
                GenericMessageDialogController.withErrorProps("Oops", "Unable to view changelog").showAndWait();
                LOGGER.error("Unable to view logs", e);
            }
        });
        aboutItem.setOnAction((item) -> {
            try {
                Analytics.sendEvent("application_click", "view_about");
                showAboutDia();
            } catch (Exception e) {
                LOGGER.error("Unable to view about", e);
                GenericMessageDialogController.withErrorProps("Oops", "Unable to view about").showAndWait();
            }
        });
        topContainer.getChildren().addAll(menuBar);
        topContainer.setStyle("-fx-background: #222222;");
        Scene scene = new Scene(topContainer, 300, maxHeight);
        scene.getStylesheets().add(getClass().getResource("css-psidplayer.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.setResizable(true);
        GlobalRepoService.getInstance().put("primarystage", primaryStage);
        if (!localDbService.getBooleanLocalDBSetting(Support.SIDIFYASDEFAULT) || userService.isFreemium()) {
            primaryStage.show();
        } else {
            ReturningTask<Void> task = () -> {
                Platform.runLater(() -> {
                    primaryStage.hide();
                    executeIfPremium((Runnable) -> {
                        GuiUtils.showDialog("sidifyMain.fxml", false, "Sidify Heroium", NullWindowOwner.of(), new Object[] { Boolean.TRUE });
                    }, "open_sidify_default");
                });
                return null;
            };
            ExecutorUtil.executeAsyncWithRetry(task);
        }
        scene.heightProperty().addListener(new ChangeListener<Number>() {

            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
                tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight());
                setMagnifierAndSidify();
            }
        });
        scene.widthProperty().addListener(new ChangeListener<Number>() {

            @Override
            public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
                tree.setMinWidth(treeAndComponents.getWidth());
                setMagnifierAndSidify();
            }
        });
        // bootstrapping
        GlobalRepoService.getInstance().put("rootscene", scene);
        for (WorkLocation location : userService.getExistingLocations()) {
            artifactsService.assertCorrectTargetFolderNames(location.asFile());
        }
        setupTree();
        sidifyView.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
            Analytics.sendEvent("application_click", "open_sidify");
            executeIfPremium((Runnable) -> {
                // Platform.runLater(() -> primaryStage.hide());
                GuiUtils.showDialog("sidifyMain.fxml", false, "Sidify Heroium", NullWindowOwner.of(), new Object[] { Boolean.FALSE });
            }, "open_sidify");
        });
        downloadLatestDbView.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
            executeIfPremium((Runnable) -> {
                if (userService.getPrimaryInstallation().exists()) {
                    InstallationService.getInstance().downloadLatestFromDatabase();
                } else {
                    GenericMessageDialogController.withErrorProps("Ooops..", "No valid downloadlocation is present").showAndWait();
                }
            }, "download_latest");
        });
        userService.locationsAssert();
        if (!localDbService.hasLocalDBSetting(Support.LAST_VERSION)) {
            localDbService.addLocalDBSetting(Support.LAST_VERSION, "0.00");
        }
        if (localDbService.getBooleanLocalDBSetting(Support.SHOWDIA_ON_STARTUP) || !version.equals(localDbService.getLocalDBSetting(Support.LAST_VERSION))) {
            ReturningTask<Void> task = () -> {
                Thread.sleep(300);
                Platform.runLater(() -> showAboutDia());
                return null;
            };
            ExecutorUtil.executeAsyncWithRetry(task);
        }
        ReturningTask<Void> deleteTmpTask = () -> {
            LocalStorageUtil.deleteOldFiles(PathService.getInstance().getTmpFolderAsString(), Support.ONE_WEEK_IN_MILLIS);
            LocalStorageUtil.deleteOldFiles(PathService.getInstance().getDownloadTmpFolderAsString(), Support.ONE_MONTH_IN_MILLIS);
            return null;
        };
        ExecutorUtil.executeAsyncWithRetry(deleteTmpTask);
        // migrate db to .db
        for (WorkLocation location : userService.getLocations()) {
            PathService.getInstance().renameDbFolder(location);
        }
        if (userService.getExistingLocations().size() == 0 && localDbService.hasLocalDBSetting(WORKDIR)) {
            addLocation(new File(localDbService.getLocalDBSetting(WORKDIR)));
            localDbService.deleteLocalDBSetting(WORKDIR);
        }
        if (userService.isPremium() && !localDbService.getBooleanLocalDBSetting(Support.SIDIFYASDEFAULT)) {
            ExecutorUtil.executeAsync(() -> {
                Platform.runLater(() -> {
                    examineContent();
                });
            });
        }
        refreshTree();
    } catch (Exception e) {
        LOGGER.error("Unable to delete cached items", e);
        GenericMessageDialogController.withErrorProps("OOoops", "Unable to startup properly").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) WorkLocation(se.light.assembly64.model.WorkLocation) MenuBar(javafx.scene.control.MenuBar) MenuItem(javafx.scene.control.MenuItem) Scene(javafx.scene.Scene) WindowEvent(javafx.stage.WindowEvent) FileChooser(javafx.stage.FileChooser) Stage(javafx.stage.Stage) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 5 with WorkLocation

use of se.light.assembly64.model.WorkLocation in project assembly64fx by freabemania.

the class SettingsController method storeSettings.

@FXML
protected void storeSettings(MouseEvent event) {
    try {
        Settings settings = userService.getSettings();
        if (settings.getNotificationOnNewContent() != notifyOnNewContent.isSelected() || !settings.getCountry().equals(countries.getSelectionModel().getSelectedItem()) || !settings.getName().equals(username.getText()) || !settings.getAnonymous().equals(anonymous.isSelected())) {
            settings.setNotificationOnNewContent(notifyOnNewContent.isSelected());
            settings.setCountry(countries.getSelectionModel().getSelectedItem());
            settings.setName(username.getText());
            settings.setAnonymous(anonymous.isSelected());
            userService.storeSettings();
            Analytics.sendEvent("application_click", "store_settings");
            LOGGER.info("Settings were stored");
        }
        localDb.setSidifyAsDefault(sidifyAsDefault.isSelected());
        if (userService.isPremium()) {
            int tmp = workers.getSelectionModel().getSelectedIndex();
            if (tmp != initialWorkers) {
                localDb.addLocalDBSetting("instances", String.valueOf(workers.getSelectionModel().getSelectedIndex()));
                Scheduler.reinitIfNotWorking();
            }
            localDb.addLocalDBSetting("vicepath", vicePath.getText());
            localDb.setRunScriptInsteadOfVice(executeAsCommand.isSelected());
            if (executeAsCommand.isSelected()) {
                localDb.setViceStyleFormatOnArgs(viceStyleFormatOnArgs.isSelected());
            } else {
                localDb.setViceStyleFormatOnArgs(false);
            }
        }
        localDb.addLocalDBSetting("maxage", String.valueOf(latestMaxAge.getSelectionModel().getSelectedItem()));
        if (latestMaxAge.getSelectionModel().getSelectedIndex() > currMaxAgeIndex) {
            for (WorkLocation location : userService.getExistingLocations()) {
                FileUtils.deleteQuietly(new File(location.asFile().getAbsolutePath() + "/.db/latest"));
            }
        }
        getStage().close();
    } catch (Exception e) {
        if (e instanceof HttpException) {
            GenericMessageDialogController.withErrorProps("Oops", "Unable to store. Invalid length of name").showAndWait();
        }
        LOGGER.error("Unable to store settings", e);
    }
}
Also used : WorkLocation(se.light.assembly64.model.WorkLocation) HttpException(se.light.assembly64.model.HttpException) File(java.io.File) Settings(se.light.assembly64.model.Settings) HttpException(se.light.assembly64.model.HttpException) FXML(javafx.fxml.FXML)

Aggregations

File (java.io.File)5 WorkLocation (se.light.assembly64.model.WorkLocation)5 RandomAccessFile (java.io.RandomAccessFile)3 FileChannel (java.nio.channels.FileChannel)2 FileLock (java.nio.channels.FileLock)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 FadeTransition (javafx.animation.FadeTransition)2 Application (javafx.application.Application)2 Platform (javafx.application.Platform)2 ChangeListener (javafx.beans.value.ChangeListener)2 ObservableValue (javafx.beans.value.ObservableValue)2 ActionEvent (javafx.event.ActionEvent)2