Search in sources :

Example 1 with Queue

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

the class UIFrame method addQuietBtQueue.

public boolean addQuietBtQueue(String url) {
    if (config.getCheckUpdateFreq() == Config.CHECK_UPDATE_FREQ_EVERY_ACT) {
        checkUpdate();
    }
    String user = config.getUser();
    String pass = config.getPass();
    if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
        LoginPanel loginPanel = new LoginPanel();
        int option = JOptionPane.showOptionDialog(UIFrame.this, loginPanel, "Login to osu!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.CANCEL_OPTION);
        if (option == JOptionPane.OK_OPTION) {
            if (loginPanel.getUsername().isEmpty() || loginPanel.getPassword().isEmpty()) {
                JOptionPane.showMessageDialog(UIFrame.this, "Username or password cannot be empty.", "Error", JOptionPane.ERROR_MESSAGE);
                return false;
            }
            user = loginPanel.getUsername();
            pass = loginPanel.getPassword();
        } else {
            return false;
        }
    }
    try {
        osu.login(user, pass);
    } catch (DebuggableException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(UIFrame.this, "Error logging in:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    try {
        map = osu.getBeatmapInfo(url);
    } catch (DebuggableException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(UIFrame.this, "Error getting beatmap info:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    String modUrl = map.getThumbUrl();
    URL thumbUrl = null;
    try {
        thumbUrl = new URL("http:" + modUrl);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return false;
    }
    URLConnection conn = null;
    try {
        conn = thumbUrl.openConnection();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    conn.setConnectTimeout(5000);
    conn.setReadTimeout(5000);
    try {
        thumb = ImageIO.read(conn.getInputStream());
    } catch (IOException e) {
        e.printStackTrace();
        thumb = null;
    }
    URL downloadUrl = null;
    try {
        downloadUrl = new URL("http://osu.ppy.sh" + map.getDwnUrl());
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
        JOptionPane.showMessageDialog(UIFrame.this, "Error validating download URL:\n" + e1, "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    String tmpdir = System.getProperty("java.io.tmpdir");
    final String mapName = map.getName();
    OsuDownloader dwn = new OsuDownloader(tmpdir, map.getDwnUrl().substring(3, map.getDwnUrl().length()) + " " + map.getName(), osu, downloadUrl);
    QueueAction importAction;
    if (rdbtnUseDefaultSettings.isSelected()) {
        importAction = new BeatmapImportAction(config);
    } else {
        int action = -1;
        String targetFileOrFolder = null;
        if (rdbtnDownloadAndImport.isSelected()) {
            action = 0;
        } else if (rdbtnDownloadToOsu.isSelected()) {
            action = 1;
        } else if (rdbtnDownloadToFile.isSelected()) {
            action = 2;
            targetFileOrFolder = targetFile;
        } else if (rdbtnDownloadToFolder.isSelected()) {
            action = 3;
            targetFileOrFolder = targetFolder;
        }
        importAction = new CustomImportAction(action, targetFileOrFolder);
    }
    QueueAction[] beforeActions = new QueueAction[] { new BeforeSoundAction(config) };
    QueueAction[] afterActions = new QueueAction[] { new AfterSoundAction(config), new QueueAction() {

        @Override
        public void run(Queue queue) {
            icon.displayMessage("Download completed for \"" + mapName + "\"", "This osumer queue has completed downloading.", TrayIcon.MessageType.INFO);
        }
    }, importAction };
    boolean added = mgr.addQueue(new Queue(map.getName(), dwn, thumb, beforeActions, afterActions));
    if (added) {
        icon.displayMessage("Downloading \"" + mapName + "\"", "osumerExpress is downloading the requested beatmap!", TrayIcon.MessageType.INFO);
    } else {
        icon.displayMessage("Could not add \"" + mapName + "\" to queue", "It has already in queue/downloading or completed.", TrayIcon.MessageType.INFO);
    }
    tableModel.fireTableDataChanged();
    return true;
}
Also used : BeforeSoundAction(com.github.mob41.osumer.io.queue.actions.BeforeSoundAction) DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) MalformedURLException(java.net.MalformedURLException) AfterSoundAction(com.github.mob41.osumer.io.queue.actions.AfterSoundAction) QueueAction(com.github.mob41.osumer.io.queue.QueueAction) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) CustomImportAction(com.github.mob41.osumer.io.queue.actions.CustomImportAction) OsuDownloader(com.github.mob41.osums.io.beatmap.OsuDownloader) BeatmapImportAction(com.github.mob41.osumer.io.queue.actions.BeatmapImportAction) Queue(com.github.mob41.osumer.io.queue.Queue) EventQueue(java.awt.EventQueue)

Example 2 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.osums.io.Downloader) IOException(java.io.IOException) File(java.io.File)

Example 3 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.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 4 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.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 5 with Queue

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

the class EditQueueDialog method refresh.

private void refresh() {
    btnCancelAndRemove.setEnabled(false);
    List<Queue> queues = mgr.getList();
    tableModel.setRowCount(0);
    for (int i = 0; i < queues.size(); i++) {
        Queue queue = queues.get(i);
        tableModel.addRow(new String[] { queue.getName(), queue.getDownloader().getFileName(), ((int) queue.getDownloader().getProgress()) + "%" });
    }
    tableModel.fireTableDataChanged();
}
Also used : Queue(com.github.mob41.osumer.io.queue.Queue)

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