Search in sources :

Example 1 with DebugDump

use of com.github.mob41.organdebug.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.organdebug.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.organdebug.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.organdebug.DebugDump in project osumer by mob41.

the class UIFrame method checkUpdate.

public void checkUpdate() {
    if (checkingUpdate) {
        return;
    }
    checkingUpdate = true;
    Thread thread = new Thread() {

        public void run() {
            lblUpdateStatus.setForeground(Color.BLACK);
            lblUpdateStatus.setText("Checking for updates...");
            UpdateInfo verInfo = null;
            try {
                verInfo = getUpdateInfoByConfig();
            } catch (NoBuildsForVersionException e) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("No builds available for the new version. See dump.");
                checkingUpdate = false;
                return;
            } catch (NoSuchVersionException e) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("No current version in the selected branch. See dump.");
                JOptionPane.showMessageDialog(UIFrame.this, "We don't have version " + Osumer.OSUMER_VERSION + " in the current update branch\n\nPlease try another update branch (snapshot, beta, stable).", "Version not available", JOptionPane.INFORMATION_MESSAGE);
                checkingUpdate = false;
                return;
            } catch (NoSuchBuildNumberException e) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("This version has a invalid build number. See dump");
                JOptionPane.showMessageDialog(UIFrame.this, "We don't have build number greater or equal to " + Osumer.OSUMER_BUILD_NUM + " in version " + Osumer.OSUMER_VERSION + ".\n" + "If you are using a modified/development osumer,\n" + " you can just ignore this message.\n" + "If not, this might be the versions.json in GitHub goes wrong,\n" + " post a new issue about this.", "Build not available", JOptionPane.WARNING_MESSAGE);
                checkingUpdate = false;
                return;
            } catch (DebuggableException e) {
                e.printStackTrace();
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("Could not connect to update server.");
                JOptionPane.showMessageDialog(UIFrame.this, "Could not connect to update server.", "Error", JOptionPane.ERROR_MESSAGE);
                checkingUpdate = false;
                return;
            }
            if (verInfo == null) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("Could not obtain update info.");
                JOptionPane.showMessageDialog(UIFrame.this, "Could not obtain update info.", "Error", JOptionPane.ERROR_MESSAGE);
                checkingUpdate = false;
                return;
            }
            if (verInfo.isThisVersion()) {
                lblUpdateStatus.setForeground(Color.BLACK);
                lblUpdateStatus.setText("You are running the latest version of osumer" + " (" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-" + verInfo.getBuildNum() + ")");
                checkingUpdate = false;
                return;
            }
            lblUpdateStatus.setForeground(new Color(0, 153, 0));
            lblUpdateStatus.setText((verInfo.isUpgradedVersion() ? "Upgrade" : "Update") + " available! New version: " + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum());
            int option;
            String desc = verInfo.getDescription();
            if (desc == null) {
                option = JOptionPane.showOptionDialog(UIFrame.this, "New " + (verInfo.isUpgradedVersion() ? "upgrade" : "update") + " available! New version:\n" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum() + "\n\n" + "Do you want to update it now?", "Update available", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.NO_OPTION);
            } else {
                option = JOptionPane.showOptionDialog(UIFrame.this, "New " + (verInfo.isUpgradedVersion() ? "upgrade" : "update") + " available! New version:\n" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum() + "\n\n" + "Do you want to update it now?", "Update available", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[] { "Yes", "No", "Description/Changelog" }, JOptionPane.NO_OPTION);
                if (option == 2) {
                    option = JOptionPane.showOptionDialog(UIFrame.this, new TextPanel(desc), "Update description/change-log", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, 0);
                }
            }
            if (option == JOptionPane.YES_OPTION) {
                /*
                    try {
                        Desktop.getDesktop().browse(new URI(verInfo.getWebLink()));
                    } catch (IOException | URISyntaxException e) {
                        DebugDump dump = new DebugDump(
                                verInfo.getWebLink(),
                                "Show option dialog of updating osumer or not",
                                "Set checkingUpdate to false",
                                "(End of function / thread)",
                                "Error when opening the web page",
                                false,
                                e);
                        DumpManager.getInstance().addDump(dump);
                        DebugDump.showDebugDialog(dump);
                    }
                    */
                try {
                    String updaterLink = Updater.getUpdaterLink();
                    if (updaterLink == null) {
                        System.out.println("No latest updater .exe defined! Falling back to legacy updater!");
                        updaterLink = Updater.LEGACY_UPDATER_JAR;
                    }
                    URL url;
                    try {
                        url = new URL(updaterLink);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                        JOptionPane.showMessageDialog(null, "Error:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                    final String folder = System.getProperty("java.io.tmpdir");
                    final String fileName = "osumer_updater_" + Calendar.getInstance().getTimeInMillis() + ".exe";
                    mgr.addQueue(new Queue("osumer Updater", new URLDownloader(folder, fileName, url), null, null, new QueueAction[] { new UpdaterRunAction(folder + fileName) }));
                    tab.setSelectedIndex(1);
                    new Thread() {

                        public void run() {
                            JOptionPane.showMessageDialog(UIFrame.this, "The web updater will be downloaded and started very soon.", "Notice", JOptionPane.INFORMATION_MESSAGE);
                        }
                    }.start();
                } catch (DebuggableException e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(null, "Error:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
                    checkingUpdate = false;
                }
            }
            checkingUpdate = false;
        }
    };
    thread.start();
}
Also used : NoSuchVersionException(com.github.mob41.osumer.exceptions.NoSuchVersionException) DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) MalformedURLException(java.net.MalformedURLException) UpdaterRunAction(com.github.mob41.osumer.io.queue.actions.UpdaterRunAction) Color(java.awt.Color) QueueAction(com.github.mob41.osumer.io.queue.QueueAction) NoBuildsForVersionException(com.github.mob41.osumer.exceptions.NoBuildsForVersionException) URLDownloader(com.github.mob41.osumer.io.legacy.URLDownloader) URL(java.net.URL) SockThread(com.github.mob41.osumer.sock.SockThread) NoSuchBuildNumberException(com.github.mob41.osumer.exceptions.NoSuchBuildNumberException) Queue(com.github.mob41.osumer.io.queue.Queue) EventQueue(java.awt.EventQueue) UpdateInfo(com.github.mob41.osumer.updater.UpdateInfo)

Example 5 with DebugDump

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

the class ViewDumpDialog method updateDumpsTable.

private void updateDumpsTable() {
    dumpStr.setText(SELECT_DUMP_MSG);
    btnExportSelectedDump.setEnabled(false);
    DumpManager mgr = DumpManager.getInstance();
    if (mgr == null) {
        System.out.println("DumpManager not initialized");
        return;
    }
    dumpsModel.setRowCount(0);
    dumpsArr = mgr.getDumps();
    String[] rowData;
    DebugDump dump;
    for (int i = 0; i < dumpsArr.length; i++) {
        dump = dumpsArr[i];
        rowData = new String[5];
        rowData[0] = dump.getGeneratedHuman();
        rowData[1] = Long.toString(dump.getGenerated());
        rowData[2] = dump.getMessage();
        rowData[3] = dump.getStacktrace();
        rowData[4] = dump.getUid();
        dumpsModel.addRow(rowData);
    }
    dumpsModel.fireTableDataChanged();
}
Also used : DumpManager(com.github.mob41.organdebug.DumpManager) DebugDump(com.github.mob41.organdebug.DebugDump)

Aggregations

DebugDump (com.github.mob41.organdebug.DebugDump)7 IOException (java.io.IOException)4 ErrorDumpDialog (com.github.mob41.osumer.exceptions.ErrorDumpDialog)2 SockThread (com.github.mob41.osumer.sock.SockThread)2 File (java.io.File)2 Socket (java.net.Socket)2 Media (javafx.scene.media.Media)2 MediaPlayer (javafx.scene.media.MediaPlayer)2 DumpManager (com.github.mob41.organdebug.DumpManager)1 DebuggableException (com.github.mob41.organdebug.exceptions.DebuggableException)1 NoBuildsForVersionException (com.github.mob41.osumer.exceptions.NoBuildsForVersionException)1 NoSuchBuildNumberException (com.github.mob41.osumer.exceptions.NoSuchBuildNumberException)1 NoSuchVersionException (com.github.mob41.osumer.exceptions.NoSuchVersionException)1 URLDownloader (com.github.mob41.osumer.io.legacy.URLDownloader)1 Queue (com.github.mob41.osumer.io.queue.Queue)1 QueueAction (com.github.mob41.osumer.io.queue.QueueAction)1 QueueManager (com.github.mob41.osumer.io.queue.QueueManager)1 UpdaterRunAction (com.github.mob41.osumer.io.queue.actions.UpdaterRunAction)1 ErrorDumpDialog (com.github.mob41.osumer.ui.ErrorDumpDialog)1 UIFrame (com.github.mob41.osumer.ui.UIFrame)1