Search in sources :

Example 16 with DebugDump

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

the class Main method runUi.

private static void runUi(Configuration config, String[] args, ArgParser ap, IDaemon d) {
    IUI ui = null;
    try {
        // Contact the ui via RMI
        ui = (IUI) Naming.lookup("rmi://localhost:46727/ui");
    } catch (Exception e) {
    }
    if (ui == null) {
        try {
            Runtime.getRuntime().exec("\"" + OsumerNative.getProgramFiles() + "\\osumer2\\osumer-ui.exe\"");
        } catch (IOException e) {
            e.printStackTrace();
            DumpManager.addDump(new DebugDump(null, "Check if \"ui\" is null", "Execute osumer-ui.exe", "Initialize \"c\" as 0", "Could not start UI. Terminating", false, e));
            DumpManager.forceMetricsReport();
            JOptionPane.showMessageDialog(null, "Could not start UI. 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 ui via RMI
                ui = (IUI) Naming.lookup("rmi://localhost:46727/ui");
            } catch (Exception e) {
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                break;
            }
            c++;
        }
    }
    if (ui == null) {
        DumpManager.addDump(new DebugDump(null, "(While-loop) Look up UI RMI", "Check if \\\"ui\\\" is null", "Try to wake up UI", false, "Could not connect to UI. Terminating"));
        DumpManager.forceMetricsReport();
        JOptionPane.showMessageDialog(null, "Could not connect to UI. For more details, check dump. Terminating", "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
        System.exit(-1);
        return;
    }
    try {
        ui.wake();
    } catch (RemoteException e) {
        e.printStackTrace();
        DumpManager.addDump(new DebugDump(null, "Check if \\\\\\\"ui\\\\\\\" is null", "Try to wake up UI", "End of runUi()", "Could not connect or wake UI", false, e));
        DumpManager.forceMetricsReport();
        JOptionPane.showMessageDialog(null, "Could not connect or wake UI. For more details, check dump:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
        System.exit(-1);
        return;
    }
}
Also used : IOException(java.io.IOException) IUI(com.github.mob41.osumer.rmi.IUI) RemoteException(java.rmi.RemoteException) DebugDump(com.github.mob41.osumer.debug.DebugDump) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Example 17 with DebugDump

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

the class URLDownloader method run.

@Override
public void run() {
    RandomAccessFile file = null;
    InputStream in = null;
    try {
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Range", "bytes=" + downloaded + "-");
        conn.connect();
        if (conn.getResponseCode() / 100 != 2) {
            error();
        }
        int len = conn.getContentLength();
        if (len < 1) {
            error();
        }
        if (size == -1) {
            size = len;
            reportState();
        }
        file = new RandomAccessFile(folder + "\\" + fileName, "rw");
        file.seek(downloaded);
        in = conn.getInputStream();
        while (status == DOWNLOADING) {
            if (size == downloaded) {
                break;
            }
            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) {
            if (file != null) {
                try {
                    file.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            status = COMPLETED;
            reportState();
        }
    } catch (IOException e) {
        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 18 with DebugDump

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

the class AfterSoundAction 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.getToneAfterDownloadPath()).toURI().toString());
                MediaPlayer mp = new MediaPlayer(m);
                mp.play();
            } catch (Exception e) {
                e.printStackTrace();
                DumpManager.addDump(new DebugDump(null, "---", "Play after 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.osumer.debug.DebugDump) MediaPlayer(javafx.scene.media.MediaPlayer)

Example 19 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.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.osumer.debug.DebugDump) MediaPlayer(javafx.scene.media.MediaPlayer)

Example 20 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.addDump(dump);
    // TODO
    /*
            ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
            dialog.setModal(true);
            dialog.setVisible(true);
            */
    }
}
Also used : IOException(java.io.IOException) 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