Search in sources :

Example 11 with Config

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

the class MainController method setConfiguration.

protected void setConfiguration(Configuration config) {
    this.config = config;
    updater = new Updater(config);
    checkingUpdate = false;
    annChecker = new AnnouncementChecker();
    checkingAnnouncements = false;
    ann = null;
    // TODO do freq check
    checkUpdate();
    checkAnnouncements();
}
Also used : Updater(com.github.mob41.osumer.updater.Updater) AnnouncementChecker(com.github.mob41.osumer.updater.AnnouncementChecker)

Example 12 with Config

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

the class UIFrame method addBtQueue.

public boolean addBtQueue(String url, boolean preview, boolean changeTab, QueueAction[] beforeActions, QueueAction[] afterActions) {
    if (config.getCheckUpdateFreq() == Config.CHECK_UPDATE_FREQ_EVERY_ACT) {
        checkUpdate();
    }
    map = null;
    thumb = null;
    pbd = new ProgressDialog();
    new Thread() {

        public void run() {
            pbd.getProgressBar().setIndeterminate(true);
            pbd.getLabel().setText("Status: Getting configuration...");
            String user = config.getUser();
            String pass = config.getPass();
            if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
                pbd.getLabel().setText("Status: Prompting username and password...");
                LoginPanel loginPanel = new LoginPanel();
                int option = JOptionPane.showOptionDialog(UIFrame.this, loginPanel, "Login to osu!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.CANCEL_OPTION);
                if (option == JOptionPane.OK_OPTION) {
                    if (loginPanel.getUsername().isEmpty() || loginPanel.getPassword().isEmpty()) {
                        JOptionPane.showMessageDialog(UIFrame.this, "Username or password cannot be empty.", "Error", JOptionPane.ERROR_MESSAGE);
                        pbd.dispose();
                        return;
                    }
                    user = loginPanel.getUsername();
                    pass = loginPanel.getPassword();
                } else {
                    pbd.dispose();
                    return;
                }
            }
            pbd.getLabel().setText("Status: Logging in...");
            try {
                osu.login(user, pass);
            } catch (DebuggableException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(UIFrame.this, "Error logging in:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                pbd.dispose();
                return;
            }
            String modUrl = url.replace("osu.ppy.sh", "old.ppy.sh");
            pbd.getLabel().setText("Status: Obtaining beatmap information...");
            try {
                map = osu.getBeatmapInfo(modUrl);
            } catch (DebuggableException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(UIFrame.this, "Error getting beatmap info:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                pbd.dispose();
                return;
            }
            pbd.dispose();
            pbd = null;
        }
    }.start();
    pbd.setLocationRelativeTo(UIFrame.this);
    pbd.setModal(true);
    pbd.setVisible(true);
    if (map == null) {
        return false;
    }
    boolean stillDwn = true;
    if (preview) {
        BeatmapPreviewDialog bpd = new BeatmapPreviewDialog(map);
        bpd.setLocationRelativeTo(UIFrame.this);
        bpd.setModal(true);
        bpd.setVisible(true);
        stillDwn = bpd.isSelectedYes();
        thumb = bpd.getDownloadedImage();
    }
    if (thumb == null) {
        pbd = new ProgressDialog();
        new Thread() {

            public void run() {
                pbd.getProgressBar().setIndeterminate(true);
                pbd.getLabel().setText("Status: Downloading thumb image...");
                URL url = null;
                try {
                    url = new URL("http:" + map.getThumbUrl());
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                    pbd.dispose();
                    return;
                }
                URLConnection conn = null;
                try {
                    conn = url.openConnection();
                } catch (IOException e) {
                    e.printStackTrace();
                    pbd.dispose();
                    return;
                }
                conn.setConnectTimeout(5000);
                conn.setReadTimeout(5000);
                try {
                    thumb = ImageIO.read(conn.getInputStream());
                } catch (IOException e) {
                    e.printStackTrace();
                    pbd.dispose();
                    return;
                }
                pbd.dispose();
            }
        }.start();
        pbd.setLocationRelativeTo(UIFrame.this);
        pbd.setModal(true);
        pbd.setVisible(true);
    }
    if (stillDwn) {
        URL downloadUrl = null;
        try {
            downloadUrl = new URL("http://osu.ppy.sh" + map.getDwnUrl());
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
            JOptionPane.showMessageDialog(UIFrame.this, "Error validating download URL:\n" + e1, "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        }
        String tmpdir = System.getProperty("java.io.tmpdir");
        final String mapName = map.getName();
        OsuDownloader dwn = new OsuDownloader(tmpdir, map.getDwnUrl().substring(3, map.getDwnUrl().length()) + " " + map.getName(), osu, downloadUrl);
        QueueAction importAction;
        if (rdbtnUseDefaultSettings.isSelected()) {
            importAction = new BeatmapImportAction(config);
        } else {
            int action = -1;
            String targetFileOrFolder = null;
            if (rdbtnDownloadAndImport.isSelected()) {
                action = 0;
            } else if (rdbtnDownloadToOsu.isSelected()) {
                action = 1;
            } else if (rdbtnDownloadToFile.isSelected()) {
                action = 2;
                targetFileOrFolder = targetFile;
            } else if (rdbtnDownloadToFolder.isSelected()) {
                action = 3;
                targetFileOrFolder = targetFolder;
            }
            importAction = new CustomImportAction(action, targetFileOrFolder);
        }
        if (beforeActions == null) {
            beforeActions = new QueueAction[] { new BeforeSoundAction(config) };
        }
        if (afterActions == null) {
            afterActions = new QueueAction[] { new AfterSoundAction(config), new QueueAction() {

                @Override
                public void run(Queue queue) {
                    icon.displayMessage("Download completed for \"" + mapName + "\"", "This osumer queue has completed downloading.", TrayIcon.MessageType.INFO);
                }
            }, importAction };
        }
        boolean added = mgr.addQueue(new Queue(map.getName(), dwn, thumb, beforeActions, afterActions));
        if (added) {
            icon.displayMessage("Downloading \"" + mapName + "\"", "osumerExpress is downloading the requested beatmap!", TrayIcon.MessageType.INFO);
        } else {
            icon.displayMessage("Could not add \"" + mapName + "\" to queue", "It has already in queue/downloading or completed.", TrayIcon.MessageType.INFO);
        }
        tableModel.fireTableDataChanged();
        if (changeTab) {
            tab.setSelectedIndex(1);
        }
    } else {
        icon.displayMessage("Could not download \"" + url + "\"", "Error occurred when finding beatmap. Start UI to see details.", TrayIcon.MessageType.INFO);
    }
    return stillDwn;
}
Also used : BeforeSoundAction(com.github.mob41.osumer.io.queue.actions.BeforeSoundAction) DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) MalformedURLException(java.net.MalformedURLException) AfterSoundAction(com.github.mob41.osumer.io.queue.actions.AfterSoundAction) QueueAction(com.github.mob41.osumer.io.queue.QueueAction) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) SockThread(com.github.mob41.osumer.sock.SockThread) CustomImportAction(com.github.mob41.osumer.io.queue.actions.CustomImportAction) OsuDownloader(com.github.mob41.osums.io.beatmap.OsuDownloader) BeatmapImportAction(com.github.mob41.osumer.io.queue.actions.BeatmapImportAction) Queue(com.github.mob41.osumer.io.queue.Queue) EventQueue(java.awt.EventQueue)

Example 13 with Config

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

the class BeatmapSearchPanel method doSearch.

private void doSearch() {
    if (searchFld.getText().isEmpty()) {
        int option = JOptionPane.showOptionDialog(BeatmapSearchPanel.this, "Please consider not to empty the search field.\nIt might cause a long time to do searching.\nAre you sure to continue?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
        if (option == JOptionPane.NO_OPTION) {
            return;
        }
    }
    boolean useDb = rdbtnUseOfflineIndexed.isSelected();
    lblResultDesc.setText("Searching string \"" + searchFld.getText() + "\"" + (useDb ? " in offline indexed database..." : " online..."));
    tableModel.setRowCount(0);
    SearchingProgressDialog dialog = new SearchingProgressDialog();
    Thread thread = new Thread() {

        public void run() {
            try {
                sleep(250);
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
            ResultBeatmap[] maps;
            try {
                if (useDb) {
                    maps = osums.searchMaps(searchFld.getText());
                    if (maps == null) {
                        int option = JOptionPane.showOptionDialog(BeatmapSearchPanel.this, "Online beatmap not indexed. Indexing can improve searching speed.\n" + "It can take some minutes to an hour.\n\n" + "Do you want to index now or just do web search?", "Not indexed", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
                        if (option == JOptionPane.YES_OPTION) {
                            dialog.dispose();
                            IndexingProgressDialog idialog = new IndexingProgressDialog();
                            Thread t2 = new Thread() {

                                public void run() {
                                    try {
                                        sleep(1000);
                                    } catch (InterruptedException e) {
                                        e.printStackTrace();
                                    }
                                    try {
                                        mgr.startIndexing(idialog.getHandler());
                                        mgr.write();
                                    } catch (DebuggableException e) {
                                        e.printStackTrace();
                                        idialog.dispose();
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                    idialog.dispose();
                                }
                            };
                            t2.setDaemon(true);
                            t2.start();
                            idialog.setLocationRelativeTo(BeatmapSearchPanel.this);
                            idialog.setModal(true);
                            idialog.setVisible(true);
                            JOptionPane.showMessageDialog(BeatmapSearchPanel.this, "Please make another search again.", "Info", JOptionPane.INFORMATION_MESSAGE);
                            return;
                        } else if (option == JOptionPane.NO_OPTION) {
                            Config config = frame.getConfig();
                            doUiLogin(config);
                            try {
                                maps = osums.getLinksOfBeatmapSearch(dialog.getHandler(), "https://osu.ppy.sh/p/beatmaplist?q=" + searchFld.getText());
                            } catch (DebuggableException e) {
                                e.printStackTrace();
                            }
                        } else {
                            dialog.dispose();
                            return;
                        }
                    }
                } else {
                    Config config = frame.getConfig();
                    if (!osums.isLoggedIn()) {
                        doUiLogin(config);
                    }
                    if (osums.isLoggedIn()) {
                        // TODO: Change to use NEW Parser
                        maps = osums.getLinksOfBeatmapSearch(dialog.getHandler(), "https://old.ppy.sh/p/beatmaplist?q=" + searchFld.getText());
                    } else {
                        dialog.dispose();
                        JOptionPane.showMessageDialog(BeatmapSearchPanel.this, "You must be logged into osu! forum to perform online search.", "Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            } catch (DebuggableException e) {
                e.printStackTrace();
                return;
            }
            if (maps.length == 0) {
                lblResultDesc.setText("No beatmaps match with the search string. Try using another keyword!" + (useDb ? " Or please try a web search with this string." : ""));
            }
            if (maps.length <= 40) {
                lblResultDesc.setText("Only " + maps.length + " beatmaps match with the search string." + (useDb ? " Please try a web search with this string." : ""));
            } else {
                lblResultDesc.setText("Total of " + maps.length + " beatmaps match with the search string.");
            }
            dialog.getLabel().setText("Status: Updating UI...");
            for (int i = 0; i < maps.length; i++) {
                tableModel.addRow(new Object[] { maps[i] });
            }
            dialog.dispose();
        }
    };
    thread.setDaemon(true);
    thread.start();
    dialog.setLocationRelativeTo(BeatmapSearchPanel.this);
    dialog.setModal(true);
    dialog.setVisible(true);
}
Also used : DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) Config(com.github.mob41.osumer.Config) IOException(java.io.IOException) ResultBeatmap(com.github.mob41.osums.io.beatmap.ResultBeatmap)

Example 14 with Config

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

the class MainController method initialize.

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

        @Override
        public void handle(ActionEvent event) {
            boolean showPreview = showPreviewCheckbox.isSelected();
            String idUrl = beatmapUrlText.getText();
            if (idUrl == null || idUrl.isEmpty()) {
                Alert alert = new Alert(AlertType.WARNING, "Please enter a valid osu! beatmap link/ID.", ButtonType.OK);
                alert.showAndWait();
                return;
            }
            addQueue(idUrl, showPreview, true);
        }
    });
    preferencesMenuItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(AppMain.class.getResource("/view/PreferencesLayout.fxml"));
            BorderPane borderPane = null;
            try {
                borderPane = (BorderPane) loader.load();
            } catch (IOException e) {
                e.printStackTrace();
            }
            PreferencesController controller = loader.getController();
            controller.setD(d);
            controller.setConfig(config);
            controller.restore();
            Scene scene = new Scene(borderPane);
            String skin = config.getUiSkin();
            new JMetro(skin.equals("light") ? JMetro.Style.LIGHT : JMetro.Style.DARK).applyTheme(scene);
            Stage stage = new Stage();
            stage.setScene(scene);
            // stage.setTitle("Preferences");
            stage.initStyle(StageStyle.UTILITY);
            stage.initModality(Modality.APPLICATION_MODAL);
            stage.showAndWait();
        }
    });
    updatesMenuItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            checkUpdate();
            checkAnnouncements();
        }
    });
    locateConfigMenuItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
            try {
                Desktop.getDesktop().open(new File(configPath));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    dumpsMenuItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            String dumpPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress\\dumps" : "";
            File folder = new File(dumpPath);
            if (!folder.exists()) {
                Alert alert = new Alert(AlertType.ERROR, "There are no dumps currently.", ButtonType.OK);
                alert.showAndWait();
                return;
            }
            try {
                Desktop.getDesktop().open(folder);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    closeMenuItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            Platform.exit();
        }
    });
    exitMenuItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            try {
                d.shutdown();
                d = null;
            } catch (RemoteException e) {
            // e.printStackTrace();
            // Alert alert = new Alert(AlertType.ERROR, "Could not shutdown daemon. Please do this manually in task manager by terminating Java VM.", ButtonType.OK);
            // alert.showAndWait();
            }
            Platform.exit();
        }
    });
    docsMenuItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            try {
                Desktop.getDesktop().browse(new URI("https://github.com/mob41/osumer/wiki"));
                ;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    issueMenuItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            try {
                Desktop.getDesktop().browse(new URI("https://github.com/mob41/osumer/issues/new"));
                ;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    aboutMenuItem.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            Alert alert = new Alert(AlertType.NONE, "", ButtonType.OK);
            alert.setHeaderText("About");
            alert.setContentText("osumer2 (" + Osumer.getVersionString() + ")\n" + "Copyright (c) mob41. 2016-2020\n\n" + "osumer is an application that provides osu! players a\n" + "more comfortable and faster way to download beatmaps.");
            alert.showAndWait();
        }
    });
}
Also used : BorderPane(javafx.scene.layout.BorderPane) ActionEvent(javafx.event.ActionEvent) IOException(java.io.IOException) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) URI(java.net.URI) NoBuildsForVersionException(com.github.mob41.osumer.exceptions.NoBuildsForVersionException) RemoteException(java.rmi.RemoteException) MalformedURLException(java.net.MalformedURLException) NoSuchVersionException(com.github.mob41.osumer.exceptions.NoSuchVersionException) IOException(java.io.IOException) NoSuchBuildNumberException(com.github.mob41.osumer.exceptions.NoSuchBuildNumberException) WithDumpException(com.github.mob41.osumer.debug.WithDumpException) Stage(javafx.stage.Stage) Alert(javafx.scene.control.Alert) JMetro(jfxtras.styles.jmetro8.JMetro) RemoteException(java.rmi.RemoteException) File(java.io.File)

Example 15 with Config

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

the class Main method runBrowser.

public static void runBrowser(Configuration config, String[] args) {
    String argstr = buildArgStr(args);
    // Run the default browser application
    if (!GraphicsEnvironment.isHeadless() && Osumer.isWindows()) {
        if (config.getDefaultBrowser() == null || config.getDefaultBrowser().isEmpty()) {
            JOptionPane.showInputDialog(null, "No default browser path is specified. Please maunally launch the browser the following arguments:", "osumer2", JOptionPane.INFORMATION_MESSAGE, null, null, argstr);
            System.exit(-1);
            return;
        }
        String browserPath = Installer.getBrowserExePath(config.getDefaultBrowser());
        if (browserPath == null) {
            JOptionPane.showMessageDialog(null, "Cannot read browser executable path in registry.\nCannot start default browser application for:\n" + argstr, "osumer2", JOptionPane.ERROR_MESSAGE);
            System.exit(-1);
            return;
        }
        File file = new File(browserPath.replaceAll("\"", ""));
        if (!file.exists()) {
            JOptionPane.showMessageDialog(null, "The specified browser application does not exist.\nCannot start default browser application for:\n" + argstr, "osumer2", JOptionPane.ERROR_MESSAGE);
            System.exit(-1);
            return;
        }
        try {
            Runtime.getRuntime().exec(browserPath + " " + argstr);
        } catch (IOException e) {
            e.printStackTrace();
            DumpManager.addDump(new DebugDump(null, "Check if the file exists", "Execute browser with args", "System Exit", "Could not execute browser with arguments", false, e));
            DumpManager.forceMetricsReport();
            JOptionPane.showMessageDialog(null, "Could not execute browser with arguments. For more details, check dump:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
            System.exit(-1);
            return;
        }
        System.exit(0);
        return;
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) DebugDump(com.github.mob41.osumer.debug.DebugDump)

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