Search in sources :

Example 6 with Config

use of com.github.mob41.osumer.Config in project osumer by mob41.

the class Main method main.

public static void main(String[] args) {
    try {
        DumpManager.init(Osumer.getVersionString(), Osumer.getVersionString());
    } catch (IOException e2) {
        e2.printStackTrace();
        System.err.println("DumpManager: Error initializing dump manager");
    }
    String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
    Configuration config = new Configuration(configPath, Configuration.DEFAULT_DATA_FILE_NAME);
    try {
        config.load();
    } catch (IOException e1) {
        System.err.println("Unable to load configuration");
        e1.printStackTrace();
        if (!GraphicsEnvironment.isHeadless()) {
            JOptionPane.showMessageDialog(null, "Could not load configuration: " + e1, "Configuration Error", JOptionPane.ERROR_MESSAGE);
        }
        System.exit(-1);
        return;
    }
    // Initialize JXToolkit
    new JFXPanel();
    // TODO: Port to config
    int port = DEFAULT_PORT;
    try {
        LocateRegistry.createRegistry(port);
        Daemon daemon = new Daemon(config);
        Naming.bind("rmi://localhost:" + port + "/daemon", daemon);
        DumpManager.reportEvent("active", "daemon");
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
        return;
    }
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) Configuration(com.github.mob41.osumer.Configuration) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with Config

use of com.github.mob41.osumer.Config in project osumer by mob41.

the class PreferencesController method initialize.

@Override
public void initialize(URL location, ResourceBundle resources) {
    saveBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            save();
            Stage stage = (Stage) saveBtn.getScene().getWindow();
            stage.close();
        }
    });
    applyBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            save();
        }
    });
    cancelBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            Stage stage = (Stage) cancelBtn.getScene().getWindow();
            stage.close();
        }
    });
    startOsuWithOverlayBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            try {
                d.startOsuWithOverlay();
                if (autoCloseOsumerAfterOverlayCheckbox.isSelected()) {
                    Platform.exit();
                    System.exit(0);
                }
            } catch (RemoteException e) {
                e.printStackTrace();
                Alert alert = new Alert(AlertType.ERROR, "Could not call daemon to start osu!:\n" + e.getMessage(), ButtonType.OK);
                alert.showAndWait();
            }
        }
    });
    toneBeforeDwnSelectBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            Stage stage = (Stage) toneBeforeDwnSelectBtn.getScene().getWindow();
            FileChooser fileChooser = new FileChooser();
            File sf = fileChooser.showOpenDialog(stage);
            if (sf != null) {
                if (sf.exists() && sf.isFile()) {
                    toneBeforeDwnText.setText(sf.getAbsolutePath());
                } else {
                    Alert alert = new Alert(AlertType.ERROR, "You must select a file that exists.", ButtonType.OK);
                    alert.showAndWait();
                }
            }
        }
    });
    toneAfterDwnSelectBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            Stage stage = (Stage) toneAfterDwnSelectBtn.getScene().getWindow();
            FileChooser fileChooser = new FileChooser();
            File sf = fileChooser.showOpenDialog(stage);
            if (sf != null) {
                if (sf.exists() && sf.isFile()) {
                    toneAfterDwnText.setText(sf.getAbsolutePath());
                } else {
                    Alert alert = new Alert(AlertType.ERROR, "You must select a file that exists.", ButtonType.OK);
                    alert.showAndWait();
                }
            }
        }
    });
    dwnFolderSelectBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            Stage stage = (Stage) dwnFolderSelectBtn.getScene().getWindow();
            DirectoryChooser chooser = new DirectoryChooser();
            File file = new File(importFolderText.getText());
            if (file.exists() && file.isDirectory()) {
                chooser.setInitialDirectory(file);
            }
            File sf = chooser.showDialog(stage);
            if (sf != null) {
                if (sf.exists() && sf.isDirectory()) {
                    importFolderText.setText(sf.getAbsolutePath());
                } else {
                    Alert alert = new Alert(AlertType.ERROR, "You must select a folder that exists.", ButtonType.OK);
                    alert.showAndWait();
                }
            }
        }
    });
    addCredentialsBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            FXMLLoader loader0 = new FXMLLoader();
            loader0.setLocation(AppMain.class.getResource("/view/LoginDialogLayout.fxml"));
            DialogPane loginPane = null;
            try {
                loginPane = (DialogPane) loader0.load();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            LoginDialogController loginController = loader0.getController();
            Alert loginDialog = new Alert(AlertType.NONE);
            loginDialog.initStyle(StageStyle.UTILITY);
            loginDialog.initModality(Modality.APPLICATION_MODAL);
            loginDialog.setTitle("");
            loginDialog.setDialogPane(loginPane);
            loginDialog.getButtonTypes().add(ButtonType.OK);
            loginDialog.getButtonTypes().add(ButtonType.CANCEL);
            FXMLLoader loader1 = new FXMLLoader();
            loader1.setLocation(AppMain.class.getResource("/view/ProgressDialogLayout.fxml"));
            DialogPane progressPane = null;
            try {
                progressPane = (DialogPane) loader1.load();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            ProgressDialogController progressController = loader1.getController();
            progressController.getHeaderText().setText("Login");
            progressController.getStatusText().setText("Status: Logging in...");
            progressController.getProgressBar().setProgress(-1);
            Alert progressDialog = new Alert(AlertType.NONE);
            progressDialog.initStyle(StageStyle.UTILITY);
            progressDialog.initModality(Modality.APPLICATION_MODAL);
            progressDialog.setTitle("");
            progressDialog.setDialogPane(progressPane);
            progressDialog.getButtonTypes().add(ButtonType.CANCEL);
            loginDialog.showAndWait();
            if (loginDialog.getResult() == ButtonType.OK) {
                final String usr = loginController.getUser();
                final String pwd = loginController.getPwd();
                if (usr == null || pwd == null || usr.isEmpty() || pwd.isEmpty()) {
                    Alert alert = new Alert(AlertType.WARNING, "Username or password must not be empty.", ButtonType.OK);
                    alert.showAndWait();
                    return;
                }
                Thread thread = new Thread() {

                    public void run() {
                        // TODO Allow the use of new parser
                        Osums osums = new OsumsOldParser();
                        // Osums osums = config.isUseOldParser() ? new OsumsOldParser() : new OsumsNewParser();
                        boolean err = false;
                        try {
                            osums.login(usr, pwd);
                        } catch (WithDumpException e1) {
                            err = true;
                        }
                        Platform.runLater(new Runnable() {

                            @Override
                            public void run() {
                                progressDialog.close();
                            }
                        });
                        if (err) {
                            Platform.runLater(new Runnable() {

                                @Override
                                public void run() {
                                    Alert alert = new Alert(AlertType.WARNING, "", ButtonType.YES);
                                    alert.setTitle("Attempting to login");
                                    alert.setHeaderText("Login Failed");
                                    alert.setContentText("Cannot login into this osu! account.\nDo you still want to save it?");
                                    alert.getButtonTypes().add(ButtonType.NO);
                                    alert.showAndWait();
                                    if (alert.getResult() == ButtonType.YES) {
                                        updateLoginUi(config, loginController);
                                    }
                                }
                            });
                        } else {
                            Platform.runLater(new Runnable() {

                                @Override
                                public void run() {
                                    updateLoginUi(config, loginController);
                                }
                            });
                        }
                    }
                };
                progressDialog.show();
                thread.start();
            }
        }
    });
    removeCredentialsBtn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            Alert alert = new Alert(AlertType.WARNING, "Are you sure to remove your credentials?", ButtonType.YES);
            alert.getButtonTypes().add(ButtonType.NO);
            alert.setHeaderText("Removing Credentials");
            alert.showAndWait();
            if (alert.getResult() == ButtonType.YES) {
                config.setUser("");
                config.setPass("");
                credentialsStatus.setText(CRED_STATUS_NOT_EXIST);
            }
        }
    });
    NumberFormat format = NumberFormat.getIntegerInstance();
    UnaryOperator<TextFormatter.Change> filter = c -> {
        if (c.isContentChange()) {
            ParsePosition parsePosition = new ParsePosition(0);
            // NumberFormat evaluates the beginning of the text
            format.parse(c.getControlNewText(), parsePosition);
            if (parsePosition.getIndex() == 0 || parsePosition.getIndex() < c.getControlNewText().length()) {
                // reject parsing the complete text failed
                return null;
            }
        }
        return c;
    };
    TextFormatter<Integer> numFormatter0 = new TextFormatter<Integer>(new IntegerStringConverter(), 0, filter);
    TextFormatter<Integer> numFormatter1 = new TextFormatter<Integer>(new IntegerStringConverter(), 0, filter);
    SpinnerValueFactory<Integer> valueFactory0 = new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 16, 0);
    SpinnerValueFactory<Integer> valueFactory1 = new SpinnerValueFactory.IntegerSpinnerValueFactory(50, 30000, 0);
    simRunningQueues.setValueFactory(valueFactory0);
    nextQueueCheckDelay.setValueFactory(valueFactory1);
    simRunningQueues.getEditor().setTextFormatter(numFormatter0);
    nextQueueCheckDelay.getEditor().setTextFormatter(numFormatter1);
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) StageStyle(javafx.stage.StageStyle) Initializable(javafx.fxml.Initializable) IntegerStringConverter(javafx.util.converter.IntegerStringConverter) Osums(com.github.mob41.osums.Osums) URL(java.net.URL) ButtonType(javafx.scene.control.ButtonType) ParsePosition(java.text.ParsePosition) UnaryOperator(java.util.function.UnaryOperator) OsumsNewParser(com.github.mob41.osums.OsumsNewParser) TextFormatter(javafx.scene.control.TextFormatter) NumberFormat(java.text.NumberFormat) Base64(org.apache.commons.codec.binary.Base64) OsumsOldParser(com.github.mob41.osums.OsumsOldParser) ResourceBundle(java.util.ResourceBundle) AlertType(javafx.scene.control.Alert.AlertType) ComboBox(javafx.scene.control.ComboBox) Installer(com.github.mob41.osumer.installer.Installer) FXMLLoader(javafx.fxml.FXMLLoader) Configuration(com.github.mob41.osumer.Configuration) DirectoryChooser(javafx.stage.DirectoryChooser) Alert(javafx.scene.control.Alert) TextField(javafx.scene.control.TextField) Modality(javafx.stage.Modality) Label(javafx.scene.control.Label) IDaemon(com.github.mob41.osumer.rmi.IDaemon) CheckBox(javafx.scene.control.CheckBox) IOException(java.io.IOException) Spinner(javafx.scene.control.Spinner) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) RemoteException(java.rmi.RemoteException) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) FileChooser(javafx.stage.FileChooser) List(java.util.List) ActionEvent(javafx.event.ActionEvent) DialogPane(javafx.scene.control.DialogPane) WithDumpException(com.github.mob41.osumer.debug.WithDumpException) Stage(javafx.stage.Stage) RadioButton(javafx.scene.control.RadioButton) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) TextFormatter(javafx.scene.control.TextFormatter) ActionEvent(javafx.event.ActionEvent) IntegerStringConverter(javafx.util.converter.IntegerStringConverter) FXMLLoader(javafx.fxml.FXMLLoader) FileChooser(javafx.stage.FileChooser) Osums(com.github.mob41.osums.Osums) Stage(javafx.stage.Stage) ParsePosition(java.text.ParsePosition) WithDumpException(com.github.mob41.osumer.debug.WithDumpException) IOException(java.io.IOException) DialogPane(javafx.scene.control.DialogPane) OsumsOldParser(com.github.mob41.osums.OsumsOldParser) Alert(javafx.scene.control.Alert) RemoteException(java.rmi.RemoteException) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser) NumberFormat(java.text.NumberFormat)

Example 8 with Config

use of com.github.mob41.osumer.Config in project osumer by mob41.

the class Main method main.

public static void main(String[] args) {
    try {
        DumpManager.init(Osumer.getVersionString(), Osumer.getVersionString());
    } catch (IOException e2) {
        e2.printStackTrace();
        System.err.println("DumpManager: Error initializing dump manager");
    }
    DumpManager.reportEvent("active", "launcher");
    ArgParser ap = new ArgParser(args);
    if (ap.isVersionFlag()) {
        System.out.println(Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-" + Osumer.OSUMER_BUILD_NUM);
        return;
    }
    // These are called by Windows when setting Default Programs
    if (ap.isHideIconsFlag() || ap.isShowIconsFlag() || ap.isReinstallFlag() || ap.isInstallFlag() || ap.isUninstallFlag()) {
        Installer installer = new Installer();
        if (ap.isHideIconsFlag()) {
            DumpManager.reportEvent("event", "launcherHideIcons");
            installer.hideIcons();
        } else if (ap.isShowIconsFlag()) {
            DumpManager.reportEvent("event", "launcherShowIcons");
            installer.showIcons();
        } else if (ap.isReinstallFlag()) {
            DumpManager.reportEvent("event", "launcherReinstall");
            installer.reinstall();
        }
        /* else if (ap.isInstallFlag()) {
                if (!ap.isQuietFlag() && !ap.isForceFlag()) {
                    int option = JOptionPane.showOptionDialog(null,
                            "You are installing osumer " + Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-"
                                    + Osumer.OSUMER_BUILD_NUM + ".\n" + "Are you sure?",
                            "Installing osumer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null,
                            JOptionPane.NO_OPTION);

                    if (option != JOptionPane.YES_OPTION) {
                        return;
                    }
                }

                try {
                    long startTime = System.currentTimeMillis();
                    installer.install();

                    if (!(ap.isQuietFlag() && ap.isForceFlag())) {
                        System.out.println("Info@U$\nInstallation success within "
                                + (System.currentTimeMillis() - startTime) + " ms\nInfo@D$");
                    }
                } catch (WithDumpException e) {
                    if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
                        //TODO: Error Dump Dialog Control
                        ErrorDumpDialog dialog = new ErrorDumpDialog(e.getDump());
                        dialog.setModal(true);
                        dialog.setVisible(true);
                    }

                    if (!(ap.isQuietFlag() && ap.isForceFlag())) {
                        System.out.println("Error@U$\n" + e.getDump().toString() + "Error@D$");
                    }
                }
            } else if (ap.isUninstallFlag()) {
                if (!ap.isQuietFlag() && !ap.isForceFlag()) {
                    int option = JOptionPane.showOptionDialog(null,
                            "You are uninstalling osumer " + Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-"
                                    + Osumer.OSUMER_BUILD_NUM + ".\n" + "Are you sure?",
                            "Uninstalling osumer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null,
                            JOptionPane.NO_OPTION);

                    if (option != JOptionPane.YES_OPTION) {
                        return;
                    }
                }

                try {
                    long startTime = System.currentTimeMillis();
                    installer.uninstall();

                    if (!(ap.isQuietFlag() && ap.isForceFlag())) {
                        System.out.println("Info@U$\nUninstallation success within "
                                + (System.currentTimeMillis() - startTime) + " ms\nInfo@D$");
                    }
                } catch (WithDumpException e) {
                    if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
                        //TODO: Error Dump Dialog Control
                        ErrorDumpDialog dialog = new ErrorDumpDialog(e.getDump());
                        dialog.setModal(true);
                        dialog.setVisible(true);
                    }

                    if (!(ap.isQuietFlag() && ap.isForceFlag())) {
                        System.out.println("Error@U$\n" + e.getDump().toString() + "Error@D$");
                    }
                }
            }*/
        DumpManager.forceMetricsReport();
        System.exit(0);
        return;
    }
    // 
    // Launch osumer system right here if no installation arguments
    // 
    String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
    Configuration config = new Configuration(configPath, Configuration.DEFAULT_DATA_FILE_NAME);
    try {
        config.load();
    } catch (IOException e1) {
        System.err.println("Unable to load configuration");
        e1.printStackTrace();
        DumpManager.addDump(new DebugDump(null, "Configuration initialization", "Load configuration", "Set String urlStr to null", "Unable to load configuration", false, e1));
        DumpManager.forceMetricsReport();
        if (!GraphicsEnvironment.isHeadless()) {
            JOptionPane.showMessageDialog(null, "Could not load configuration. For more details, check dump:\n" + e1, "Configuration Error", JOptionPane.ERROR_MESSAGE);
        }
        System.exit(-1);
        return;
    }
    String urlStr = null;
    for (int i = 0; i < args.length; i++) {
        if (config.isUseOldParser() ? OsumsOldParser.checkVaildBeatmapUrl(args[i]) : OsumsNewParser.checkVaildBeatmapUrl(args[i])) {
            urlStr = args[i];
            break;
        }
    }
    if (// Configuration
    (config.isSwitchToBrowserIfWithoutUiArg() && !ap.isUiFlag() && ap.isNoUiFlag()) || (urlStr != null && !config.isOEEnabled()) || (args != null && args.length > 0 && urlStr == null)) {
        // Browser if disabled OE
        runBrowser(config, args);
        DumpManager.reportEvent("event", "launcherRunBrowser");
        DumpManager.forceMetricsReport();
        System.exit(0);
        return;
    } else {
        IDaemon d = null;
        try {
            // Contact the daemon via RMI
            d = (IDaemon) Naming.lookup("rmi://localhost:46726/daemon");
        } catch (Exception e) {
        }
        if (d == null) {
            try {
                Runtime.getRuntime().exec("\"" + OsumerNative.getProgramFiles() + "\\osumer2\\osumer-daemon.exe\"");
            } catch (IOException e) {
                e.printStackTrace();
                DumpManager.addDump(new DebugDump(null, "Check if \"d\" is null", "Execute osumer-daemon.exe", "Initialize \"c\" as 0", "Could not start daemon. Terminating", false, e));
                DumpManager.forceMetricsReport();
                JOptionPane.showMessageDialog(null, "Could not start daemon. For more details, check dump. Terminating:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
                System.exit(-1);
                return;
            }
            int c = 0;
            while (c < 20) {
                try {
                    // Contact the daemon via RMI
                    d = (IDaemon) Naming.lookup("rmi://localhost:46726/daemon");
                } catch (Exception e) {
                }
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    break;
                }
                c++;
            }
            if (d == null) {
                DumpManager.addDump(new DebugDump(null, "(While-loop) Look up daemon RMI", "Check if \\\"d\\\" is null", "Check if \"urlStr\" is null", false, "Could not connect to daemon. Terminating"));
                DumpManager.forceMetricsReport();
                JOptionPane.showMessageDialog(null, "Could not connect to daemon. For more details, check dump. Terminating", "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
                System.exit(-1);
                return;
            }
        }
        if (urlStr != null) {
            try {
                d.addQueue(urlStr);
                System.exit(0);
                return;
            } catch (RemoteException e) {
                e.printStackTrace();
                DumpManager.addDump(new DebugDump(null, "Check if \\\"urlStr\\\" is null", "Request daemon to add queue", "System Exit", "Could not connect or add queue to daemon", false, e));
                DumpManager.forceMetricsReport();
                JOptionPane.showMessageDialog(null, "Could not connect or add queue to daemon. For more details, check dump:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
                System.exit(-1);
                return;
            }
        }
        if (GraphicsEnvironment.isHeadless()) {
            System.out.println("Error: Arguments are required to use this application. Otherwise, a graphics environment is required to show the downloader UI.");
            System.exit(0);
            return;
        }
        runUi(config, args, ap, d);
    }
    DumpManager.forceMetricsReport();
}
Also used : Configuration(com.github.mob41.osumer.Configuration) Installer(com.github.mob41.osumer.installer.Installer) IOException(java.io.IOException) IDaemon(com.github.mob41.osumer.rmi.IDaemon) RemoteException(java.rmi.RemoteException) DebugDump(com.github.mob41.osumer.debug.DebugDump) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Example 9 with Config

use of com.github.mob41.osumer.Config in project osumer by mob41.

the class AppMain method initRootLayout.

/**
 * Initializes the root layout.
 */
private void initRootLayout() {
    try {
        // Load root layout from fxml file.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(AppMain.class.getResource("/view/RootLayout.fxml"));
        rootLayout = (BorderPane) loader.load();
        controller = loader.getController();
        controller.setDaemon(d);
        controller.setConfiguration(config);
        controller.setOsums(osums);
        controller.fetchQueues();
        // rootLayout.setStyle("-fx-background-color: #111;");
        // Show the scene containing the root layout.
        Scene scene = new Scene(rootLayout);
        primaryStage.setScene(scene);
        primaryStage.show();
        String skin = config.getUiSkin();
        new JMetro(skin.equals("light") ? JMetro.Style.LIGHT : JMetro.Style.DARK).applyTheme(scene);
        scene.getStylesheets().add(getClass().getResource("/css/application.css").toExternalForm());
    } catch (IOException e) {
        e.printStackTrace();
        DumpManager.addDump(new DebugDump(null, "(Method Start)", "Initialize root layout for UI", "(Method End)", "Could not initialize root layout", false, e));
        Alert alert = new Alert(AlertType.ERROR, "Could not initialize root layout, check dumps for details:\n" + e, ButtonType.OK);
        alert.setHeaderText("osumer UI Layout Error");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        Platform.exit();
        System.exit(-1);
        return;
    }
}
Also used : Alert(javafx.scene.control.Alert) IOException(java.io.IOException) Scene(javafx.scene.Scene) JMetro(jfxtras.styles.jmetro8.JMetro) FXMLLoader(javafx.fxml.FXMLLoader) DebugDump(com.github.mob41.osumer.debug.DebugDump)

Example 10 with Config

use of com.github.mob41.osumer.Config in project osumer by mob41.

the class AppMain method start.

@Override
public void start(Stage primaryStage) {
    this.primaryStage = primaryStage;
    try {
        DumpManager.init(Osumer.getVersionString(), Osumer.getVersionString());
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("DumpManager: Error initializing dump manager");
        Alert alert = new Alert(AlertType.ERROR, e.getMessage(), ButtonType.OK);
        alert.setHeaderText("Error initializing dump manager");
        alert.showAndWait();
        Platform.exit();
        System.exit(-1);
        return;
    }
    // Arg is handled by osumer-launcher
    String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
    config = new Configuration(configPath, Configuration.DEFAULT_DATA_FILE_NAME);
    try {
        config.load();
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Unable to load configuration");
        DumpManager.addDump(new DebugDump(null, "Initialize Configuration", "Load configuration from file", "Set uiSuffix", "Unable to load configuration", false, e));
        Alert alert = new Alert(AlertType.ERROR, e.getMessage(), ButtonType.OK);
        alert.setHeaderText("Could not load configuration");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        Platform.exit();
        System.exit(-1);
        return;
    }
    String uiSuffix = RMI_UI_PORT + "/" + RMI_UI_PATH;
    String daemonSuffix = RMI_DAEMON_PORT + "/" + RMI_DAEMON_PATH;
    ui = null;
    try {
        // Find any running UI
        ui = (IUI) Naming.lookup("rmi://localhost:" + uiSuffix);
    } catch (Exception ignore) {
    }
    if (ui != null) {
        try {
            ui.wake();
        } catch (RemoteException e) {
            e.printStackTrace();
            String msg = "Unable to wake up the UI:\n" + e.getMessage();
            System.err.println(msg);
            DumpManager.addDump(new DebugDump(null, "Check if ui is not null", "Call ui to wake", "Stop this UI", msg, false, e));
            Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
            alert.setHeaderText("osumer RMI Connection Error");
            alert.showAndWait();
            DumpManager.forceMetricsReport();
            Platform.exit();
            System.exit(-1);
            return;
        }
        try {
            stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return;
    }
    d = null;
    try {
        // Contact the daemon via RMI
        d = (IDaemon) Naming.lookup("rmi://localhost:" + daemonSuffix);
    } catch (Exception e) {
        e.printStackTrace();
        String msg = "Could not connect to daemon! Please ensure osumer-daemon is running properly.\n" + "Instead of starting directly with \"osumer-ui.exe\", please use \"osumer.exe\" to launch osumer.";
        System.err.println(msg);
        DumpManager.addDump(new DebugDump(null, "Set d as null", "Look for running daemon", "Create RMI Registry for UI", msg, false, e));
        Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
        alert.setHeaderText("osumer RMI Connection Error");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        Platform.exit();
        System.exit(-1);
        return;
    }
    try {
        LocateRegistry.createRegistry(RMI_UI_PORT);
        ui = new UI(this);
        Naming.bind("rmi://localhost:" + uiSuffix, ui);
    } catch (Exception e) {
        e.printStackTrace();
        String msg = "Could not register UI RMI registry on port " + RMI_UI_PORT + ":\n" + e.getMessage();
        System.err.println(msg);
        DumpManager.addDump(new DebugDump(null, "Look for running daemon", "Create RMI Registry for UI", "Register UI to daemon", msg, false, e));
        Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
        alert.setHeaderText("osumer RMI Initialization Error");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        Platform.exit();
        System.exit(-1);
        return;
    }
    try {
        d.registerUi(ui);
    } catch (RemoteException e) {
        e.printStackTrace();
        String msg = "Could not register UI to daemon\n" + e.getMessage();
        System.err.println(msg);
        DumpManager.addDump(new DebugDump(null, "Create RMI Registry for UI", "Register UI to daemon", "Set stage title", msg, false, e));
        Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
        alert.setHeaderText("osumer RMI Initialization Error");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        Platform.exit();
        System.exit(-1);
        return;
    }
    primaryStage.setTitle("osumer2");
    primaryStage.getIcons().add(new Image(AppMain.class.getResourceAsStream("/image/osumerIcon_64px.png")));
    // TODO Use new parser
    osums = new OsumsOldParser();
    // osums = config.isUseOldParser() ? new OsumsOldParser() : new OsumsNewParser();
    initRootLayout();
    DumpManager.reportEvent("active", "ui");
}
Also used : Configuration(com.github.mob41.osumer.Configuration) IUI(com.github.mob41.osumer.rmi.IUI) OsumsOldParser(com.github.mob41.osums.OsumsOldParser) Alert(javafx.scene.control.Alert) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) Image(javafx.scene.image.Image) DebugDump(com.github.mob41.osumer.debug.DebugDump) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Aggregations

IOException (java.io.IOException)14 DebugDump (com.github.mob41.osumer.debug.DebugDump)5 MalformedURLException (java.net.MalformedURLException)5 RemoteException (java.rmi.RemoteException)5 DebuggableException (com.github.mob41.organdebug.exceptions.DebuggableException)4 Configuration (com.github.mob41.osumer.Configuration)4 File (java.io.File)4 URL (java.net.URL)4 Alert (javafx.scene.control.Alert)4 WithDumpException (com.github.mob41.osumer.debug.WithDumpException)3 FXMLLoader (javafx.fxml.FXMLLoader)3 Config (com.github.mob41.osumer.Config)2 Installer (com.github.mob41.osumer.installer.Installer)2 Queue (com.github.mob41.osumer.io.queue.Queue)2 QueueAction (com.github.mob41.osumer.io.queue.QueueAction)2 AfterSoundAction (com.github.mob41.osumer.io.queue.actions.AfterSoundAction)2 BeatmapImportAction (com.github.mob41.osumer.io.queue.actions.BeatmapImportAction)2 BeforeSoundAction (com.github.mob41.osumer.io.queue.actions.BeforeSoundAction)2 CustomImportAction (com.github.mob41.osumer.io.queue.actions.CustomImportAction)2 IDaemon (com.github.mob41.osumer.rmi.IDaemon)2