Search in sources :

Example 1 with DebugDump

use of com.github.mob41.osumer.debug.DebugDump in project osumer by mob41.

the class Main method runUi.

private static void runUi(Config config, String[] args, ArgParser ap) {
    if (!SockThread.testPortFree(SockThread.PORT)) {
        // osumer to work
        try {
            Socket socket = new Socket(InetAddress.getLoopbackAddress().getHostName(), SockThread.PORT);
            socket.setSoTimeout(5000);
            PrintWriter writer = new PrintWriter(socket.getOutputStream());
            writer.println("RUN " + buildArgStr(args));
            writer.flush();
            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String line = reader.readLine();
            if (line == null || !line.equals("OK")) {
                reader.close();
                socket.close();
                System.out.println("Not OK: " + line);
                DebugDump dump = new DebugDump(null, null, "Asking BG osumer to run with args: \"" + buildArgStr(args) + "\"", null, false, "Could not start up BG osumer sucessfully. Destination did not response \"OK\": " + line);
                DumpManager.getInstance().addDump(dump);
                ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
                dialog.setModal(true);
                dialog.setVisible(true);
                return;
            }
            reader.close();
            socket.close();
            System.exit(0);
            return;
        } catch (IOException e) {
            e.printStackTrace();
            DebugDump dump = new DebugDump(null, null, "Opening connection to BG osumer socket", null, "Could not open socket at 46725 for BG call. Not osumer running at that port?", false, e);
            DumpManager.getInstance().addDump(dump);
            ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
            dialog.setModal(true);
            dialog.setVisible(true);
            System.exit(-1);
            return;
        }
    } else {
        String urlStr = null;
        for (int i = 0; i < args.length; i++) {
            if (Osums.isVaildBeatMapUrl(args[i])) {
                urlStr = args[i];
                break;
            }
        }
        boolean runUi = true;
        if (args.length > 0 && urlStr == null && !ap.isDaemonFlag()) {
            if (config.isSwitchToBrowserIfWithoutUiArg()) {
                System.out.println("Configuration specified that switch to browser if an \"-ui\" arugment wasn't specified.");
                if (runUi = ap.isUiFlag() && !ap.isNoUiFlag()) {
                    System.out.println("An \"-ui\" argument was specified. Launching UI.");
                } else {
                    System.out.println("An \"-ui\" argument wasn't specified. Opening the default browser instead.");
                    runBrowser(config, args);
                    return;
                }
            } else {
                System.out.println("Non-beatmap URL detected.");
                if (!config.isAutoSwitchBrowser()) {
                    System.out.println("Auto switch to default browser is off. Nothing to do with such URL.");
                    return;
                } else {
                    System.out.println("Switching to default browser with the URL.");
                    runBrowser(config, args);
                }
            }
        }
        // Initialize JFX toolkit
        new JFXPanel();
        TrayIcon icon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(UIFrame.class.getResource("/com/github/mob41/osumer/ui/osumerIcon_16px.png")));
        UIFrame frame = new UIFrame(config, new QueueManager(config), icon);
        if (ap.isDaemonFlag()) {
            if (!SystemTray.isSupported()) {
                JOptionPane.showMessageDialog(null, "Your operating system does not support System Tray.\nAs a result, you are not able to start osumer from the tray.", "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
            frame.setDaemonMode(true);
            SystemTray tray = SystemTray.getSystemTray();
            icon.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    frame.setVisible(!frame.isVisible());
                    if (!frame.isVisible()) {
                        icon.displayMessage("osumer2", "osumer2 is now running in background.", TrayIcon.MessageType.INFO);
                    }
                }
            });
            icon.setToolTip("osumer2");
            try {
                tray.add(icon);
                icon.displayMessage("osumer2", "osumer2 is now running in background.", TrayIcon.MessageType.INFO);
            } catch (AWTException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(null, "Error when adding tray icon: " + e + "\nAs a result, you are not able to start osumer from the tray.", "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
        } else {
            frame.setVisible(true);
            new Thread() {

                public void run() {
                    JOptionPane.showMessageDialog(frame, "The osumer2 daemon (background process) is not running.\nThis might slow down further osumerExpress downloads.\nNow this process is listening for more queues till it is stopped.\n\nPlease check \"Help\" for more details.", "Warning", JOptionPane.WARNING_MESSAGE);
                }
            }.start();
        }
        if (urlStr != null) {
            frame.addBtQueue(urlStr, false);
        }
    }
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) InputStreamReader(java.io.InputStreamReader) ErrorDumpDialog(com.github.mob41.osumer.ui.ErrorDumpDialog) SystemTray(java.awt.SystemTray) ActionEvent(java.awt.event.ActionEvent) UIFrame(com.github.mob41.osumer.ui.UIFrame) IOException(java.io.IOException) QueueManager(com.github.mob41.osumer.io.queue.QueueManager) SockThread(com.github.mob41.osumer.sock.SockThread) ActionListener(java.awt.event.ActionListener) TrayIcon(java.awt.TrayIcon) BufferedReader(java.io.BufferedReader) DebugDump(com.github.mob41.organdebug.DebugDump) Socket(java.net.Socket) PrintWriter(java.io.PrintWriter) AWTException(java.awt.AWTException)

Example 2 with DebugDump

use of com.github.mob41.osumer.debug.DebugDump in project osumer by mob41.

the class BeforeSoundAction method run.

@Override
public void run(Queue queue) {
    Thread thread = new Thread(new Runnable() {

        public void run() {
            try {
                Media m = new Media(new File(config.getToneBeforeDownloadPath()).toURI().toString());
                MediaPlayer mp = new MediaPlayer(m);
                mp.play();
            } catch (Exception e) {
                e.printStackTrace();
                DumpManager.getInstance().addDump(new DebugDump(null, "---", "Play before download sound", "---", "Error occurred when trying to play sound", false, e));
            }
        }
    });
    thread.setDaemon(true);
    thread.start();
}
Also used : Media(javafx.scene.media.Media) File(java.io.File) DebugDump(com.github.mob41.organdebug.DebugDump) MediaPlayer(javafx.scene.media.MediaPlayer)

Example 3 with DebugDump

use of com.github.mob41.osumer.debug.DebugDump in project osumer by mob41.

the class UpdaterRunAction method run.

@Override
public void run(Queue queue) {
    try {
        System.out.println("Starting: \"" + filePath + "\"");
        Runtime.getRuntime().exec("cmd.exe /c \"" + filePath + "\" -install");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.exit(0);
        return;
    } catch (IOException e1) {
        e1.printStackTrace();
        DebugDump dump = new DebugDump(null, "(If[openFile] scope) (UI) Set status to lblStatus", "(Try scope) Open file loc using Desktop.getDesktop.open()", "(Try scope) Sleep 2000 ms (2 sec)", "Unable to open file", false, e1);
        DumpManager.getInstance().addDump(dump);
        ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
        dialog.setModal(true);
        dialog.setVisible(true);
    }
}
Also used : ErrorDumpDialog(com.github.mob41.osumer.exceptions.ErrorDumpDialog) IOException(java.io.IOException) DebugDump(com.github.mob41.organdebug.DebugDump)

Example 4 with DebugDump

use of com.github.mob41.osumer.debug.DebugDump 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 5 with DebugDump

use of com.github.mob41.osumer.debug.DebugDump 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)

Aggregations

IOException (java.io.IOException)13 DebugDump (com.github.mob41.osumer.debug.DebugDump)12 DebugDump (com.github.mob41.organdebug.DebugDump)7 File (java.io.File)5 RemoteException (java.rmi.RemoteException)4 Alert (javafx.scene.control.Alert)4 Media (javafx.scene.media.Media)4 MediaPlayer (javafx.scene.media.MediaPlayer)4 InputStream (java.io.InputStream)3 RandomAccessFile (java.io.RandomAccessFile)3 HttpURLConnection (java.net.HttpURLConnection)3 Configuration (com.github.mob41.osumer.Configuration)2 ErrorDumpDialog (com.github.mob41.osumer.exceptions.ErrorDumpDialog)2 NoBuildsForVersionException (com.github.mob41.osumer.exceptions.NoBuildsForVersionException)2 NoSuchBuildNumberException (com.github.mob41.osumer.exceptions.NoSuchBuildNumberException)2 NoSuchVersionException (com.github.mob41.osumer.exceptions.NoSuchVersionException)2 IUI (com.github.mob41.osumer.rmi.IUI)2 SockThread (com.github.mob41.osumer.sock.SockThread)2 UpdateInfo (com.github.mob41.osumer.updater.UpdateInfo)2 MalformedURLException (java.net.MalformedURLException)2