use of com.github.mob41.osums.io.Downloader in project osumer by mob41.
the class Main method main.
public static void main(String[] args) {
ArgParser ap = new ArgParser(args);
if (ap.isVersionFlag()) {
System.out.println(Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-" + Osumer.OSUMER_BUILD_NUM);
return;
}
if (!GraphicsEnvironment.isHeadless()) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
}
// These are called by Windows when setting Default Programs
if (ap.isHideIconsFlag() || ap.isShowIconsFlag() || ap.isReinstallFlag() || ap.isInstallFlag() || ap.isUninstallFlag()) {
Installer installer = new Installer();
if (ap.isHideIconsFlag()) {
installer.hideIcons();
} else if (ap.isShowIconsFlag()) {
installer.showIcons();
} else if (ap.isReinstallFlag()) {
installer.reinstall();
} else if (ap.isInstallFlag()) {
if (!ap.isQuietFlag() && !ap.isForceFlag()) {
int option = JOptionPane.showOptionDialog(null, "You are installing osumer " + Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-" + Osumer.OSUMER_BUILD_NUM + ".\n" + "Are you sure?", "Installing osumer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION);
if (option != JOptionPane.YES_OPTION) {
return;
}
}
try {
long startTime = System.currentTimeMillis();
installer.install();
if (!(ap.isQuietFlag() && ap.isForceFlag())) {
System.out.println("Info@U$\nInstallation success within " + (System.currentTimeMillis() - startTime) + " ms\nInfo@D$");
}
} catch (DebuggableException e) {
if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
ErrorDumpDialog dialog = new ErrorDumpDialog(e.getDump());
dialog.setModal(true);
dialog.setVisible(true);
}
if (!(ap.isQuietFlag() && ap.isForceFlag())) {
System.out.println("Error@U$\n" + e.getDump().toString() + "Error@D$");
}
}
} else if (ap.isUninstallFlag()) {
if (!ap.isQuietFlag() && !ap.isForceFlag()) {
int option = JOptionPane.showOptionDialog(null, "You are uninstalling osumer " + Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-" + Osumer.OSUMER_BUILD_NUM + ".\n" + "Are you sure?", "Uninstalling osumer", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION);
if (option != JOptionPane.YES_OPTION) {
return;
}
}
try {
long startTime = System.currentTimeMillis();
installer.uninstall();
if (!(ap.isQuietFlag() && ap.isForceFlag())) {
System.out.println("Info@U$\nUninstallation success within " + (System.currentTimeMillis() - startTime) + " ms\nInfo@D$");
}
} catch (DebuggableException e) {
if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
ErrorDumpDialog dialog = new ErrorDumpDialog(e.getDump());
dialog.setModal(true);
dialog.setVisible(true);
}
if (!(ap.isQuietFlag() && ap.isForceFlag())) {
System.out.println("Error@U$\n" + e.getDump().toString() + "Error@D$");
}
}
}
System.exit(0);
return;
}
String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
Config config = new Config(configPath, Config.DEFAULT_DATA_FILE_NAME);
try {
config.load();
} catch (IOException e1) {
System.err.println("Unable to load configuration");
e1.printStackTrace();
if (!GraphicsEnvironment.isHeadless()) {
JOptionPane.showMessageDialog(null, "Could not load configuration: " + e1, "Configuration Error", JOptionPane.ERROR_MESSAGE);
}
System.exit(-1);
return;
}
if (args != null && args.length > 0) {
if (!config.isOEEnabled()) {
System.out.println("osumerExpress is disabled.");
runBrowser(config, args);
System.exit(0);
return;
}
runUi(config, args, ap);
} else {
if (GraphicsEnvironment.isHeadless()) {
System.out.println("Error: Arguments are required to use this application. Otherwise, a graphics environment is required to show the downloader UI.");
System.exit(0);
return;
}
if (config.isSwitchToBrowserIfWithoutUiArg()) {
runBrowser(config, args);
} else {
runUi(config, args, ap);
}
}
}
use of com.github.mob41.osums.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.osums.io.Downloader in project osumer by mob41.
the class CustomImportAction 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;
}
if (action == 1 || action == 2 || action == 3) {
String loc = null;
if (action == 1) {
loc = System.getenv("LOCALAPPDATA") + "\\osu!\\Songs";
} else {
loc = targetFileOrFolder;
}
if (action == 3) {
File songsFolder = new File(loc);
if (!songsFolder.exists()) {
songsFolder.mkdirs();
}
}
String filePath;
if (action == 2) {
if (!loc.endsWith(".osz")) {
loc = loc + ".osz";
}
filePath = loc;
} else {
filePath = loc + "\\" + dwn.getFileName() + ".osz";
}
File toFile = new File(filePath);
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.osums.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();
*/
}
Aggregations