Search in sources :

Example 16 with Queue

use of com.github.mob41.osumer.queue.Queue in project osumer by mob41.

the class BeatmapImportAction method run.

@Override
public void run(Queue queue) {
    Downloader dwn = queue.getDownloader();
    String path = dwn.getDownloadFolder() + dwn.getFileName();
    File file = new File(path + ".osz");
    if (!file.exists()) {
        System.out.println("File not exists: " + path + ".osz");
        return;
    }
    int action = config.getDefaultOpenBeatmapAction();
    if (action == 1 || action == 2) {
        String loc = null;
        if (action == 1) {
            loc = System.getenv("LOCALAPPDATA") + "\\osu!\\Songs";
        } else {
            loc = config.getDefaultBeatmapSaveLocation();
        }
        File songsFolder = new File(loc);
        if (!songsFolder.exists()) {
            songsFolder.mkdirs();
        }
        File toFile = new File(loc + "\\" + dwn.getFileName() + ".osz");
        if (toFile.exists()) {
            toFile.delete();
        }
        FileOutputStream toFileOut;
        try {
            toFileOut = new FileOutputStream(toFile);
            Files.copy(file.toPath(), toFileOut);
            toFileOut.close();
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, "osumer Song Copy failed:\n\nFrom: " + path + "\nTo: " + loc + "\n\nMake sure you have access to that folder.\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }
    } else {
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Downloader(com.github.mob41.osumer.io.Downloader) IOException(java.io.IOException) File(java.io.File)

Example 17 with Queue

use of com.github.mob41.osumer.queue.Queue 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 18 with Queue

use of com.github.mob41.osumer.queue.Queue 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 19 with Queue

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

Example 20 with Queue

use of com.github.mob41.osumer.queue.Queue in project osumer by mob41.

the class Daemon method getQueues.

@Override
public QueueStatus[] getQueues() throws RemoteException {
    List<Queue> queues = queueManager.getList();
    QueueStatus[] status = new QueueStatus[queues.size()];
    Downloader dwn;
    Queue q;
    QueueStatus s;
    for (int i = 0; i < status.length; i++) {
        q = queues.get(i);
        dwn = q.getDownloader();
        long elapsedTime = System.nanoTime() - q.getStartTime();
        long allTimeForDownloading = dwn.getDownloaded() != 0 ? (elapsedTime * dwn.getSize() / dwn.getDownloaded()) : -1;
        long eta = allTimeForDownloading - elapsedTime;
        s = new QueueStatus(q.getName(), dwn.getFileName(), q.getThumbUrl(), (int) dwn.getProgress(), eta, elapsedTime, dwn.getStatus());
        status[i] = s;
    }
    return status;
}
Also used : Downloader(com.github.mob41.osumer.io.Downloader) OsuDownloader(com.github.mob41.osumer.io.OsuDownloader) Queue(com.github.mob41.osumer.queue.Queue) QueueStatus(com.github.mob41.osumer.queue.QueueStatus)

Aggregations

IOException (java.io.IOException)9 File (java.io.File)8 DebugDump (com.github.mob41.osumer.debug.DebugDump)5 Queue (com.github.mob41.osumer.io.queue.Queue)4 FileOutputStream (java.io.FileOutputStream)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 Media (javafx.scene.media.Media)4 DebugDump (com.github.mob41.organdebug.DebugDump)3 DebuggableException (com.github.mob41.organdebug.exceptions.DebuggableException)3 Downloader (com.github.mob41.osumer.io.Downloader)3 QueueAction (com.github.mob41.osumer.io.queue.QueueAction)3 Queue (com.github.mob41.osumer.queue.Queue)3 Downloader (com.github.mob41.osums.io.Downloader)3 EventQueue (java.awt.EventQueue)3 MediaPlayer (javafx.scene.media.MediaPlayer)3 OsuDownloader (com.github.mob41.osumer.io.OsuDownloader)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