Search in sources :

Example 6 with DebugDump

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

Example 7 with DebugDump

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

the class MainController method requestQueue.

private boolean requestQueue(String url) {
    int downloadAction = -1;
    String targetFileOrFolder = null;
    if (rdBtnUseDefault.isSelected()) {
        downloadAction = -1;
    } else if (rdBtnDwnImport.isSelected()) {
        downloadAction = 0;
    } else if (rdBtnDwnOsuSong.isSelected()) {
        downloadAction = 1;
    } else if (rdBtnDwnFile.isSelected()) {
        downloadAction = 2;
        targetFileOrFolder = "";
    } else if (rdBtnDwnFolder.isSelected()) {
        downloadAction = 3;
        targetFileOrFolder = "";
    }
    MethodResult<Integer> result = null;
    try {
        result = d.addQueue(url, downloadAction, targetFileOrFolder);
    } catch (RemoteException e) {
        e.printStackTrace();
        DumpManager.addDump(new DebugDump(null, "Process download action", "Request daemon to add queue", "(Method End)", "Unable to request daemon to add queue", false, e));
        Alert alert = new Alert(AlertType.ERROR, e.getMessage(), ButtonType.OK);
        alert.setHeaderText("Unable to request daemon to add queue");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        return false;
    }
    if (result == null) {
        Alert alert = new Alert(AlertType.ERROR, "No result was returned from daemon.", ButtonType.OK);
        alert.setHeaderText("Unable to request daemon to add queue");
        alert.showAndWait();
        return false;
    } else if (result.getResult() != ErrorCode.RESULT_OK) {
        String header = null;
        String msg = null;
        AlertType type = null;
        switch(result.getResult()) {
            case ErrorCode.RESULT_NO_CREDENTIALS:
                header = "No credentials available";
                msg = "Please enter your credentials in the Preferences in order to download beatmaps.";
                type = AlertType.WARNING;
                break;
            case ErrorCode.RESULT_LOGIN_FAILED:
                header = "Login Failed";
                msg = "Please validate your credentials entered in the Preferences.";
                type = AlertType.ERROR;
                break;
            case ErrorCode.RESULT_GET_BEATMAP_INFO_FAILED:
                header = "Could not obtain beatmap info";
                msg = "Is your beatmap link/ID correct?";
                type = AlertType.ERROR;
                break;
            case ErrorCode.RESULT_VALIDATE_DOWNLOAD_URL_FAILED:
                header = "Invalid download link received";
                msg = "Is your beatmap link/ID correct?";
                type = AlertType.ERROR;
                break;
            default:
                header = "Unable to request daemon to add queue";
                msg = "Unknown result code.";
                type = AlertType.ERROR;
        }
        Alert alert = new Alert(type, msg, ButtonType.OK);
        alert.setHeaderText(header);
        alert.showAndWait();
        return false;
    } else {
        return true;
    }
}
Also used : AlertType(javafx.scene.control.Alert.AlertType) Alert(javafx.scene.control.Alert) RemoteException(java.rmi.RemoteException) DebugDump(com.github.mob41.osumer.debug.DebugDump)

Example 8 with DebugDump

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

the class OsuDownloader method run.

@Override
public void run() {
    RandomAccessFile file = null;
    InputStream in = null;
    try {
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Range", "bytes=" + downloaded + "-");
        osu.setCookies(conn);
        conn.connect();
        int code = conn.getResponseCode() / 100;
        if (code < 2 && code > 3) {
            error();
        }
        int len = conn.getContentLength();
        if (len < 1) {
            error();
        }
        if (size == -1) {
            size = len;
            reportState();
        }
        file = new RandomAccessFile(folder + "\\" + fileName + ".osz", "rw");
        file.seek(downloaded);
        in = conn.getInputStream();
        while (status == DOWNLOADING) {
            byte[] buffer = size - downloaded > MAX_BUFFER_SIZE ? new byte[MAX_BUFFER_SIZE] : new byte[size - downloaded];
            int read = in.read(buffer);
            if (read == -1) {
                break;
            }
            file.write(buffer, 0, read);
            downloaded += read;
            reportState();
        }
        if (status == DOWNLOADING) {
            status = COMPLETED;
            reportState();
        }
    } catch (IOException e) {
        e.printStackTrace();
        DumpManager.addDump(dump = new DebugDump(null, "(Try&catch try)", "Error reporting and debug dump", "(Try&catch finally)", "Error when downloading", false, e));
        error();
    } finally {
        if (file != null) {
            try {
                file.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) RandomAccessFile(java.io.RandomAccessFile) InputStream(java.io.InputStream) IOException(java.io.IOException) DebugDump(com.github.mob41.osumer.debug.DebugDump)

Example 9 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 10 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

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