Search in sources :

Example 6 with Downloader

use of com.github.mob41.osumer.io.Downloader in project osumer by mob41.

the class QueueCell method updateData.

public void updateData(Queue queue) {
    Downloader dwn = queue.getDownloader();
    lblFilename.setText(dwn.getFileName());
    lblTitle.setText(queue.getName());
    lblThumb.setIcon(null);
    lblThumb.setText("Loading thumb...");
    lblStatus.setForeground(Color.BLACK);
    BufferedImage image = queue.getThumb();
    if (image != null) {
        lblThumb.setText("");
        lblThumb.setIcon(new ImageIcon(image));
    } else {
        lblThumb.setText("No thumb");
    }
    int progress = (int) dwn.getProgress();
    pb.setValue(progress);
    switch(dwn.getStatus()) {
        case Downloader.DOWNLOADING:
            pb.setIndeterminate(false);
            long elapsedTime = System.nanoTime() - queue.getStartTime();
            long allTimeForDownloading = dwn.getDownloaded() != 0 ? (elapsedTime * dwn.getSize() / dwn.getDownloaded()) : -1;
            if (allTimeForDownloading == -1) {
                lblStatus.setText("Status: Starting...");
            } else {
                long eta = allTimeForDownloading - elapsedTime;
                lblElapsed.setText("Elapsed: " + nanoSecToString(elapsedTime));
                lblEta.setText("ETA: " + nanoSecToString(eta));
                lblStatus.setText("Status: Downloading...");
            }
            break;
        case Downloader.COMPLETED:
            lblStatus.setForeground(Color.GREEN);
            lblEta.setText("ETA: ---");
            lblStatus.setText("Status: Completed.");
            break;
        case Downloader.ERROR:
            lblEta.setText("ETA: ---");
            lblStatus.setForeground(Color.RED);
            lblStatus.setText("Status: Error occurred while downloading.");
            break;
        case Downloader.PAUSED:
            lblEta.setText("ETA: ---");
            lblStatus.setForeground(Color.BLUE);
            lblStatus.setText("Status: Paused.");
            break;
        case Downloader.CANCELLED:
            lblEta.setText("ETA: ---");
            lblStatus.setForeground(Color.BLACK);
            lblStatus.setText("Status: Cancelled.");
            break;
        case -1:
            lblEta.setText("ETA: ---");
            lblStatus.setForeground(Color.BLACK);
            lblStatus.setText("Status: Waiting for queuing...");
            break;
        default:
            lblEta.setText("ETA: ---");
            lblStatus.setForeground(Color.RED);
            lblStatus.setText("Status: Unknown status.");
    }
/*
         * if (this.queue != null){
         * this.queue.getDownloader().deleteObservers(); }
         * 
         * this.queue = queue;
         * 
         * Downloader downloader = queue.getDownloader();
         * downloader.addObserver(new Observer() {
         * 
         * @Override public void update(Observable o, Object arg) { switch
         * (downloader.getStatus()){ case Downloader.DOWNLOADING:
         * pb.setIndeterminate(false); int progress = (int)
         * downloader.getProgress(); pb.setValue(progress);
         * 
         * long elapsedTime = System.nanoTime() - queue.getStartTime(); long
         * allTimeForDownloading = downloader.getDownloaded() != 0 ?
         * (elapsedTime * downloader.getSize() / downloader.getDownloaded()) :
         * -1;
         * 
         * if (allTimeForDownloading == -1){ lblStatus.setText(
         * "Status: Starting..."); } else { long eta = allTimeForDownloading -
         * elapsedTime; lblElapsed.setText("Elapsed: " +
         * nanoSecToString(elapsedTime)); lblEta.setText("ETA: " +
         * nanoSecToString(eta)); lblStatus.setText("Status: Downloading..."); }
         * break; case Downloader.COMPLETED:
         * lblStatus.setForeground(Color.GREEN);
         * 
         * lblEta.setText("ETA: ---"); lblStatus.setText("Status: Completed.");
         * break; case Downloader.ERROR: lblEta.setText("ETA: ---");
         * lblStatus.setForeground(Color.RED); lblStatus.setText(
         * "Status: Error occurred while downloading."); break; case
         * Downloader.PAUSED: lblEta.setText("ETA: ---");
         * lblStatus.setForeground(Color.BLUE); lblStatus.setText(
         * "Status: Paused."); break; case Downloader.CANCELLED: lblEta.setText(
         * "ETA: ---"); lblStatus.setForeground(Color.BLACK); lblStatus.setText(
         * "Status: Cancelled."); break; default: lblEta.setText("ETA: ---");
         * lblStatus.setForeground(Color.RED); lblStatus.setText(
         * "Status: Unknown status."); } } }); queue.start();
         */
}
Also used : ImageIcon(javax.swing.ImageIcon) Downloader(com.github.mob41.osums.io.Downloader) BufferedImage(java.awt.image.BufferedImage)

Example 7 with Downloader

use of com.github.mob41.osumer.io.Downloader 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 8 with Downloader

use of com.github.mob41.osumer.io.Downloader 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)6 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 Downloader (com.github.mob41.osumer.io.Downloader)3 Downloader (com.github.mob41.osums.io.Downloader)3 DebuggableException (com.github.mob41.organdebug.exceptions.DebuggableException)1 Configuration (com.github.mob41.osumer.Configuration)1 DebugDump (com.github.mob41.osumer.debug.DebugDump)1 Installer (com.github.mob41.osumer.installer.Installer)1 Installer (com.github.mob41.osumer.io.Installer)1 OsuDownloader (com.github.mob41.osumer.io.OsuDownloader)1 Queue (com.github.mob41.osumer.queue.Queue)1 QueueStatus (com.github.mob41.osumer.queue.QueueStatus)1 IDaemon (com.github.mob41.osumer.rmi.IDaemon)1 ErrorDumpDialog (com.github.mob41.osumer.ui.ErrorDumpDialog)1 AWTException (java.awt.AWTException)1 BufferedImage (java.awt.image.BufferedImage)1 MalformedURLException (java.net.MalformedURLException)1 RemoteException (java.rmi.RemoteException)1 ImageIcon (javax.swing.ImageIcon)1