Search in sources :

Example 1 with Settings

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

the class SearchViewFilesController method openFile.

private void openFile(boolean launchExplorerEvenIfOneFile, boolean loadStar) {
    ContentEntry selectedItem = table.getSelectionModel().getSelectedItem();
    try {
        File file = null;
        if (fromSearch) {
            file = downloadService.downloadItem(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), searchedItem.getName(), selectedItem.getName(), searchedItem.getCategoryShortName(), FILE_ACTION.TMPDOWNLOAD);
        } else {
            // we're using the id as pathfield
            file = new File(selectedItem.getId());
        }
        String path = file.getAbsolutePath().toLowerCase();
        if (path.endsWith(".d64") || path.endsWith(".d71") || path.endsWith(".d81")) {
            GuiUtils.showDialogWithOwner("viewimage.fxml", "Browsing diskimage for " + selectedItem.getName(), getStage(), new Object[] { file, launchExplorerEvenIfOneFile, loadStar });
        } else if (path.endsWith(".sid")) {
            GuiUtils.showDialog("sidifyPlaySid.fxml", true, "Sidplay", getStage(), file);
        } else {
            if (StringUtils.isNotEmpty(localDb.getLocalDBSetting("vicepath"))) {
                Analytics.sendEvent("search", "viceopen");
                if (fromSearch) {
                    downloadService.downloadItem(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), searchedItem.getName(), selectedItem.getName(), searchedItem.getCategoryShortName(), FILE_ACTION.EXECUTE);
                } else {
                    viceService.execVice(file);
                }
            } else {
                Analytics.sendEvent("search", "novice");
                GenericMessageDialogController.withErrorProps("Specify vicepath", "In order to run files you need to specify Vicepath in settings").showAndWait();
            }
        }
    } catch (Exception e) {
        GenericMessageDialogController.withErrorProps("Specify vicepath", "Unable to view files").showAndWait();
    }
}
Also used : ContentEntry(se.light.assembly64.model.ContentEntry) File(java.io.File)

Example 2 with Settings

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

the class UserService method storeSettings.

public void storeSettings() throws HttpException {
    Response response = null;
    try {
        response = getClient().target(getBackendServer()).path("/leet/user3/settings").request().header("email", getSessionInfo().getEmail()).header("token", getSessionInfo().getToken()).post(Entity.json(settings));
    } finally {
        response.close();
    }
    invalidateUserDb();
    if (response.getStatus() != 200) {
        throw new HttpException(response.getStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) HttpException(se.light.assembly64.model.HttpException)

Example 3 with Settings

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

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

Example 5 with Settings

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

the class SettingsController method init.

public void init() throws Exception {
    localDb = LocalDBService.getInstance();
    userService = UserService.getInstance();
    addTextLimiter(username, 48);
    Settings settings = userService.getSettings();
    if (userService.isPremium()) {
        String[] tkns = Support.readStringResourceFromFile("countries.txt", getClass()).split(System.getProperty("line.separator"));
        initialWorkers = getWorkersIndex();
        workers.getSelectionModel().clearAndSelect(initialWorkers);
        notifyOnNewContent.setSelected(settings.getNotificationOnNewContent());
        Arrays.stream(tkns).forEach(item -> countries.getItems().add(item));
        countries.getSelectionModel().select(settings.getCountry());
        username.setText(settings.getName());
        anonymous.setSelected(settings.getAnonymous());
    } else {
        sidifyAsDefault.setDisable(true);
        latestMaxAge.setDisable(true);
        anonymous.setDisable(true);
        username.setDisable(true);
        countries.setDisable(true);
        workers.getSelectionModel().select(0);
        workers.setDisable(true);
        notifyOnNewContent.setDisable(true);
    }
    sidifyAsDefault.setSelected(localDb.getSidifyAsDefault());
    latestMaxAge.getSelectionModel().select(LocalDBService.getInstance().getMagAgeIndex());
    currMaxAgeIndex = latestMaxAge.getSelectionModel().getSelectedIndex();
    if (localDb.hasLocalDBSetting("vicepath")) {
        vicePath.setText(localDb.getLocalDBSetting("vicepath"));
    }
    if (localDb.getRunScriptInsteadOfVice()) {
        viceStyleFormatOnArgs.setSelected(localDb.getViceStyleFormatOnArgs());
        executeAsCommand.setSelected(true);
        openFileImage.setVisible(false);
    } else {
        viceStyleFormatOnArgs.setDisable(true);
    }
}
Also used : Settings(se.light.assembly64.model.Settings)

Aggregations

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