use of com.github.mob41.osumer.Configuration in project osumer by mob41.
the class AppMain method start.
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
try {
DumpManager.init(Osumer.getVersionString(), Osumer.getVersionString());
} catch (IOException e) {
e.printStackTrace();
System.err.println("DumpManager: Error initializing dump manager");
Alert alert = new Alert(AlertType.ERROR, e.getMessage(), ButtonType.OK);
alert.setHeaderText("Error initializing dump manager");
alert.showAndWait();
Platform.exit();
System.exit(-1);
return;
}
// Arg is handled by osumer-launcher
String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
config = new Configuration(configPath, Configuration.DEFAULT_DATA_FILE_NAME);
try {
config.load();
} catch (IOException e) {
e.printStackTrace();
System.err.println("Unable to load configuration");
DumpManager.addDump(new DebugDump(null, "Initialize Configuration", "Load configuration from file", "Set uiSuffix", "Unable to load configuration", false, e));
Alert alert = new Alert(AlertType.ERROR, e.getMessage(), ButtonType.OK);
alert.setHeaderText("Could not load configuration");
alert.showAndWait();
DumpManager.forceMetricsReport();
Platform.exit();
System.exit(-1);
return;
}
String uiSuffix = RMI_UI_PORT + "/" + RMI_UI_PATH;
String daemonSuffix = RMI_DAEMON_PORT + "/" + RMI_DAEMON_PATH;
ui = null;
try {
// Find any running UI
ui = (IUI) Naming.lookup("rmi://localhost:" + uiSuffix);
} catch (Exception ignore) {
}
if (ui != null) {
try {
ui.wake();
} catch (RemoteException e) {
e.printStackTrace();
String msg = "Unable to wake up the UI:\n" + e.getMessage();
System.err.println(msg);
DumpManager.addDump(new DebugDump(null, "Check if ui is not null", "Call ui to wake", "Stop this UI", msg, false, e));
Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
alert.setHeaderText("osumer RMI Connection Error");
alert.showAndWait();
DumpManager.forceMetricsReport();
Platform.exit();
System.exit(-1);
return;
}
try {
stop();
} catch (Exception e) {
e.printStackTrace();
}
return;
}
d = null;
try {
// Contact the daemon via RMI
d = (IDaemon) Naming.lookup("rmi://localhost:" + daemonSuffix);
} catch (Exception e) {
e.printStackTrace();
String msg = "Could not connect to daemon! Please ensure osumer-daemon is running properly.\n" + "Instead of starting directly with \"osumer-ui.exe\", please use \"osumer.exe\" to launch osumer.";
System.err.println(msg);
DumpManager.addDump(new DebugDump(null, "Set d as null", "Look for running daemon", "Create RMI Registry for UI", msg, false, e));
Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
alert.setHeaderText("osumer RMI Connection Error");
alert.showAndWait();
DumpManager.forceMetricsReport();
Platform.exit();
System.exit(-1);
return;
}
try {
LocateRegistry.createRegistry(RMI_UI_PORT);
ui = new UI(this);
Naming.bind("rmi://localhost:" + uiSuffix, ui);
} catch (Exception e) {
e.printStackTrace();
String msg = "Could not register UI RMI registry on port " + RMI_UI_PORT + ":\n" + e.getMessage();
System.err.println(msg);
DumpManager.addDump(new DebugDump(null, "Look for running daemon", "Create RMI Registry for UI", "Register UI to daemon", msg, false, e));
Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
alert.setHeaderText("osumer RMI Initialization Error");
alert.showAndWait();
DumpManager.forceMetricsReport();
Platform.exit();
System.exit(-1);
return;
}
try {
d.registerUi(ui);
} catch (RemoteException e) {
e.printStackTrace();
String msg = "Could not register UI to daemon\n" + e.getMessage();
System.err.println(msg);
DumpManager.addDump(new DebugDump(null, "Create RMI Registry for UI", "Register UI to daemon", "Set stage title", msg, false, e));
Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
alert.setHeaderText("osumer RMI Initialization Error");
alert.showAndWait();
DumpManager.forceMetricsReport();
Platform.exit();
System.exit(-1);
return;
}
primaryStage.setTitle("osumer2");
primaryStage.getIcons().add(new Image(AppMain.class.getResourceAsStream("/image/osumerIcon_64px.png")));
// TODO Use new parser
osums = new OsumsOldParser();
// osums = config.isUseOldParser() ? new OsumsOldParser() : new OsumsNewParser();
initRootLayout();
DumpManager.reportEvent("active", "ui");
}
use of com.github.mob41.osumer.Configuration in project osumer by mob41.
the class MainController method setConfiguration.
protected void setConfiguration(Configuration config) {
this.config = config;
updater = new Updater(config);
checkingUpdate = false;
annChecker = new AnnouncementChecker();
checkingAnnouncements = false;
ann = null;
// TODO do freq check
checkUpdate();
checkAnnouncements();
}
use of com.github.mob41.osumer.Configuration in project osumer by mob41.
the class UIFrame method addBtQueue.
public boolean addBtQueue(String url, boolean preview, boolean changeTab, QueueAction[] beforeActions, QueueAction[] afterActions) {
if (config.getCheckUpdateFreq() == Config.CHECK_UPDATE_FREQ_EVERY_ACT) {
checkUpdate();
}
map = null;
thumb = null;
pbd = new ProgressDialog();
new Thread() {
public void run() {
pbd.getProgressBar().setIndeterminate(true);
pbd.getLabel().setText("Status: Getting configuration...");
String user = config.getUser();
String pass = config.getPass();
if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
pbd.getLabel().setText("Status: Prompting username and password...");
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);
pbd.dispose();
return;
}
user = loginPanel.getUsername();
pass = loginPanel.getPassword();
} else {
pbd.dispose();
return;
}
}
pbd.getLabel().setText("Status: Logging in...");
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);
pbd.dispose();
return;
}
String modUrl = url.replace("osu.ppy.sh", "old.ppy.sh");
pbd.getLabel().setText("Status: Obtaining beatmap information...");
try {
map = osu.getBeatmapInfo(modUrl);
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error getting beatmap info:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
pbd.dispose();
return;
}
pbd.dispose();
pbd = null;
}
}.start();
pbd.setLocationRelativeTo(UIFrame.this);
pbd.setModal(true);
pbd.setVisible(true);
if (map == null) {
return false;
}
boolean stillDwn = true;
if (preview) {
BeatmapPreviewDialog bpd = new BeatmapPreviewDialog(map);
bpd.setLocationRelativeTo(UIFrame.this);
bpd.setModal(true);
bpd.setVisible(true);
stillDwn = bpd.isSelectedYes();
thumb = bpd.getDownloadedImage();
}
if (thumb == null) {
pbd = new ProgressDialog();
new Thread() {
public void run() {
pbd.getProgressBar().setIndeterminate(true);
pbd.getLabel().setText("Status: Downloading thumb image...");
URL url = null;
try {
url = new URL("http:" + map.getThumbUrl());
} catch (MalformedURLException e) {
e.printStackTrace();
pbd.dispose();
return;
}
URLConnection conn = null;
try {
conn = url.openConnection();
} catch (IOException e) {
e.printStackTrace();
pbd.dispose();
return;
}
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
try {
thumb = ImageIO.read(conn.getInputStream());
} catch (IOException e) {
e.printStackTrace();
pbd.dispose();
return;
}
pbd.dispose();
}
}.start();
pbd.setLocationRelativeTo(UIFrame.this);
pbd.setModal(true);
pbd.setVisible(true);
}
if (stillDwn) {
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);
}
if (beforeActions == null) {
beforeActions = new QueueAction[] { new BeforeSoundAction(config) };
}
if (afterActions == null) {
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();
if (changeTab) {
tab.setSelectedIndex(1);
}
} else {
icon.displayMessage("Could not download \"" + url + "\"", "Error occurred when finding beatmap. Start UI to see details.", TrayIcon.MessageType.INFO);
}
return stillDwn;
}
use of com.github.mob41.osumer.Configuration in project osumer by mob41.
the class MainController method addQueue.
private void addQueue(String beatmapUrlId, boolean showPreview, boolean changeTab) {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(AppMain.class.getResource("/view/ProgressDialogLayout.fxml"));
DialogPane progressPane = null;
try {
progressPane = (DialogPane) loader.load();
} catch (IOException e1) {
e1.printStackTrace();
}
ProgressDialogController progressController = loader.getController();
progressController.getHeaderText().setText("Beatmap Download");
progressController.getStatusText().setText("Status: Initializing");
progressController.getProgressBar().setProgress(-1);
Alert progressDialog = new Alert(AlertType.NONE);
progressDialog.initStyle(StageStyle.UTILITY);
progressDialog.initModality(Modality.APPLICATION_MODAL);
progressDialog.setTitle("Beatmap Download");
progressDialog.setDialogPane(progressPane);
progressDialog.getButtonTypes().add(ButtonType.CANCEL);
progressDialog.show();
String url = null;
boolean isBeatmap = false;
if (beatmapUrlId.matches("^[sb]\\d+") && beatmapUrlId.length() > 1) {
if (beatmapUrlId.startsWith("b")) {
isBeatmap = true;
url = "https://osu.ppy.sh/b/" + beatmapUrlId.substring(1);
} else {
url = "https://osu.ppy.sh/s/" + beatmapUrlId.substring(1);
}
} else {
if (osums.isVaildBeatmapUrl(beatmapUrlId)) {
url = beatmapUrlId;
if (url.contains("b/")) {
isBeatmap = true;
}
} else {
Alert alert = new Alert(AlertType.WARNING, "Please enter a valid osu! beatmap link.", ButtonType.OK);
alert.showAndWait();
progressDialog.close();
return;
}
}
if (showPreview) {
progressController.getStatusText().setText("Status: Getting Configuration...");
String user = config.getUser();
String pass = config.getPass();
if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
FXMLLoader loader0 = new FXMLLoader();
loader0.setLocation(AppMain.class.getResource("/view/LoginDialogLayout.fxml"));
DialogPane loginPane = null;
try {
loginPane = (DialogPane) loader0.load();
} catch (IOException e1) {
e1.printStackTrace();
}
LoginDialogController loginController = loader0.getController();
Alert loginDialog = new Alert(AlertType.NONE);
loginDialog.initStyle(StageStyle.UTILITY);
loginDialog.initModality(Modality.APPLICATION_MODAL);
loginDialog.setTitle("");
loginDialog.setDialogPane(loginPane);
loginDialog.getButtonTypes().add(ButtonType.OK);
loginDialog.getButtonTypes().add(ButtonType.CANCEL);
loginDialog.showAndWait();
String usr = loginController.getUser();
String pwd = loginController.getPwd();
if (usr == null || pwd == null || usr.isEmpty() || pwd.isEmpty()) {
Alert alert = new Alert(AlertType.WARNING, "Username or password must not be empty.", ButtonType.OK);
alert.showAndWait();
progressDialog.close();
return;
}
user = usr;
pass = pwd;
}
final String _url = url;
// OsuBeatmap map = null;
final String _user = user;
final String _pass = pass;
final boolean _isBeatmap = isBeatmap;
Thread thread = new Thread() {
public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
progressController.getStatusText().setText("Status: Logging in...");
}
});
try {
osums.login(_user, _pass);
} catch (WithDumpException e) {
e.printStackTrace();
Platform.runLater(new Runnable() {
@Override
public void run() {
Alert alert = new Alert(AlertType.INFORMATION, "Error logging in:\n" + e.getDump().getStacktrace(), ButtonType.OK);
alert.showAndWait();
progressDialog.close();
}
});
return;
}
OsuSong map = null;
Platform.runLater(new Runnable() {
@Override
public void run() {
progressController.getStatusText().setText("Status: Obtaining song/beatmap information...");
}
});
try {
if (_isBeatmap) {
map = osums.getBeatmapInfo(_url);
} else {
map = osums.getSongInfo(_url);
}
} catch (WithDumpException e) {
e.printStackTrace();
Platform.runLater(new Runnable() {
@Override
public void run() {
Alert alert = new Alert(AlertType.INFORMATION, "Error getting song/beatmap info:\n" + e.getDump().getStacktrace(), ButtonType.OK);
alert.showAndWait();
progressDialog.close();
}
});
return;
}
final OsuSong _map = map;
Platform.runLater(new Runnable() {
@Override
public void run() {
progressDialog.hide();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(AppMain.class.getResource("/view/BeatmapPreviewDialogLayout.fxml"));
DialogPane dialogPane = null;
;
try {
dialogPane = (DialogPane) loader.load();
} catch (IOException e) {
e.printStackTrace();
}
BeatmapPreviewDialogController controller = loader.getController();
controller.preview(_map);
Alert previewDialog = new Alert(AlertType.NONE);
previewDialog.initStyle(StageStyle.UTILITY);
previewDialog.initModality(Modality.APPLICATION_MODAL);
previewDialog.setTitle("Beatmap Preview");
previewDialog.setDialogPane(dialogPane);
List<ButtonType> btnTypes = previewDialog.getButtonTypes();
btnTypes.add(ButtonType.YES);
btnTypes.add(ButtonType.NO);
previewDialog.showAndWait();
ButtonType result = previewDialog.getResult();
if (result != ButtonType.YES) {
progressDialog.close();
return;
}
progressDialog.show();
uiRequestQueue(progressDialog, progressController, _url, changeTab);
}
});
}
};
thread.start();
} else {
uiRequestQueue(progressDialog, progressController, url, changeTab);
}
}
use of com.github.mob41.osumer.Configuration in project osumer by mob41.
the class Main method runBrowser.
public static void runBrowser(Configuration config, String[] args) {
String argstr = buildArgStr(args);
// Run the default browser application
if (!GraphicsEnvironment.isHeadless() && Osumer.isWindows()) {
if (config.getDefaultBrowser() == null || config.getDefaultBrowser().isEmpty()) {
JOptionPane.showInputDialog(null, "No default browser path is specified. Please maunally launch the browser the following arguments:", "osumer2", JOptionPane.INFORMATION_MESSAGE, null, null, argstr);
System.exit(-1);
return;
}
String browserPath = Installer.getBrowserExePath(config.getDefaultBrowser());
if (browserPath == null) {
JOptionPane.showMessageDialog(null, "Cannot read browser executable path in registry.\nCannot start default browser application for:\n" + argstr, "osumer2", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
return;
}
File file = new File(browserPath.replaceAll("\"", ""));
if (!file.exists()) {
JOptionPane.showMessageDialog(null, "The specified browser application does not exist.\nCannot start default browser application for:\n" + argstr, "osumer2", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
return;
}
try {
Runtime.getRuntime().exec(browserPath + " " + argstr);
} catch (IOException e) {
e.printStackTrace();
DumpManager.addDump(new DebugDump(null, "Check if the file exists", "Execute browser with args", "System Exit", "Could not execute browser with arguments", false, e));
DumpManager.forceMetricsReport();
JOptionPane.showMessageDialog(null, "Could not execute browser with arguments. For more details, check dump:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
System.exit(-1);
return;
}
System.exit(0);
return;
}
}
Aggregations