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();
*/
}
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();
}
}
}
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;
}
Aggregations