use of com.github.mob41.osumer.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.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 Main method main.
public static void main(String[] args) {
try {
DumpManager.init(Osumer.getVersionString(), Osumer.getVersionString());
} catch (IOException e2) {
e2.printStackTrace();
System.err.println("DumpManager: Error initializing dump manager");
}
DumpManager.reportEvent("active", "launcher");
ArgParser ap = new ArgParser(args);
if (ap.isVersionFlag()) {
System.out.println(Osumer.OSUMER_VERSION + "-" + Osumer.OSUMER_BRANCH + "-" + Osumer.OSUMER_BUILD_NUM);
return;
}
// 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()) {
DumpManager.reportEvent("event", "launcherHideIcons");
installer.hideIcons();
} else if (ap.isShowIconsFlag()) {
DumpManager.reportEvent("event", "launcherShowIcons");
installer.showIcons();
} else if (ap.isReinstallFlag()) {
DumpManager.reportEvent("event", "launcherReinstall");
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 (WithDumpException e) {
if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
//TODO: Error Dump Dialog Control
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 (WithDumpException e) {
if (!ap.isNoUiFlag() && !GraphicsEnvironment.isHeadless()) {
//TODO: Error Dump Dialog Control
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$");
}
}
}*/
DumpManager.forceMetricsReport();
System.exit(0);
return;
}
//
// Launch osumer system right here if no installation arguments
//
String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
Configuration config = new Configuration(configPath, Configuration.DEFAULT_DATA_FILE_NAME);
try {
config.load();
} catch (IOException e1) {
System.err.println("Unable to load configuration");
e1.printStackTrace();
DumpManager.addDump(new DebugDump(null, "Configuration initialization", "Load configuration", "Set String urlStr to null", "Unable to load configuration", false, e1));
DumpManager.forceMetricsReport();
if (!GraphicsEnvironment.isHeadless()) {
JOptionPane.showMessageDialog(null, "Could not load configuration. For more details, check dump:\n" + e1, "Configuration Error", JOptionPane.ERROR_MESSAGE);
}
System.exit(-1);
return;
}
String urlStr = null;
for (int i = 0; i < args.length; i++) {
if (config.isUseOldParser() ? OsumsOldParser.checkVaildBeatmapUrl(args[i]) : OsumsNewParser.checkVaildBeatmapUrl(args[i])) {
urlStr = args[i];
break;
}
}
if (// Configuration
(config.isSwitchToBrowserIfWithoutUiArg() && !ap.isUiFlag() && ap.isNoUiFlag()) || (urlStr != null && !config.isOEEnabled()) || (args != null && args.length > 0 && urlStr == null)) {
// Browser if disabled OE
runBrowser(config, args);
DumpManager.reportEvent("event", "launcherRunBrowser");
DumpManager.forceMetricsReport();
System.exit(0);
return;
} else {
IDaemon d = null;
try {
// Contact the daemon via RMI
d = (IDaemon) Naming.lookup("rmi://localhost:46726/daemon");
} catch (Exception e) {
}
if (d == null) {
try {
Runtime.getRuntime().exec("\"" + OsumerNative.getProgramFiles() + "\\osumer2\\osumer-daemon.exe\"");
} catch (IOException e) {
e.printStackTrace();
DumpManager.addDump(new DebugDump(null, "Check if \"d\" is null", "Execute osumer-daemon.exe", "Initialize \"c\" as 0", "Could not start daemon. Terminating", false, e));
DumpManager.forceMetricsReport();
JOptionPane.showMessageDialog(null, "Could not start daemon. For more details, check dump. Terminating:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
return;
}
int c = 0;
while (c < 20) {
try {
// Contact the daemon via RMI
d = (IDaemon) Naming.lookup("rmi://localhost:46726/daemon");
} catch (Exception e) {
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
c++;
}
if (d == null) {
DumpManager.addDump(new DebugDump(null, "(While-loop) Look up daemon RMI", "Check if \\\"d\\\" is null", "Check if \"urlStr\" is null", false, "Could not connect to daemon. Terminating"));
DumpManager.forceMetricsReport();
JOptionPane.showMessageDialog(null, "Could not connect to daemon. For more details, check dump. Terminating", "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
return;
}
}
if (urlStr != null) {
try {
d.addQueue(urlStr);
System.exit(0);
return;
} catch (RemoteException e) {
e.printStackTrace();
DumpManager.addDump(new DebugDump(null, "Check if \\\"urlStr\\\" is null", "Request daemon to add queue", "System Exit", "Could not connect or add queue to daemon", false, e));
DumpManager.forceMetricsReport();
JOptionPane.showMessageDialog(null, "Could not connect or add queue to daemon. For more details, check dump:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
return;
}
}
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;
}
runUi(config, args, ap, d);
}
DumpManager.forceMetricsReport();
}
use of com.github.mob41.osumer.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.osumer.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();
}
}
}
Aggregations