use of com.github.mob41.organdebug.exceptions.DebuggableException 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.organdebug.exceptions.DebuggableException in project osumer by mob41.
the class BeatmapSearchPanel method doSearch.
private void doSearch() {
if (searchFld.getText().isEmpty()) {
int option = JOptionPane.showOptionDialog(BeatmapSearchPanel.this, "Please consider not to empty the search field.\nIt might cause a long time to do searching.\nAre you sure to continue?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
if (option == JOptionPane.NO_OPTION) {
return;
}
}
boolean useDb = rdbtnUseOfflineIndexed.isSelected();
lblResultDesc.setText("Searching string \"" + searchFld.getText() + "\"" + (useDb ? " in offline indexed database..." : " online..."));
tableModel.setRowCount(0);
SearchingProgressDialog dialog = new SearchingProgressDialog();
Thread thread = new Thread() {
public void run() {
try {
sleep(250);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
ResultBeatmap[] maps;
try {
if (useDb) {
maps = osums.searchMaps(searchFld.getText());
if (maps == null) {
int option = JOptionPane.showOptionDialog(BeatmapSearchPanel.this, "Online beatmap not indexed. Indexing can improve searching speed.\n" + "It can take some minutes to an hour.\n\n" + "Do you want to index now or just do web search?", "Not indexed", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null);
if (option == JOptionPane.YES_OPTION) {
dialog.dispose();
IndexingProgressDialog idialog = new IndexingProgressDialog();
Thread t2 = new Thread() {
public void run() {
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
mgr.startIndexing(idialog.getHandler());
mgr.write();
} catch (DebuggableException e) {
e.printStackTrace();
idialog.dispose();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
idialog.dispose();
}
};
t2.setDaemon(true);
t2.start();
idialog.setLocationRelativeTo(BeatmapSearchPanel.this);
idialog.setModal(true);
idialog.setVisible(true);
JOptionPane.showMessageDialog(BeatmapSearchPanel.this, "Please make another search again.", "Info", JOptionPane.INFORMATION_MESSAGE);
return;
} else if (option == JOptionPane.NO_OPTION) {
Config config = frame.getConfig();
doUiLogin(config);
try {
maps = osums.getLinksOfBeatmapSearch(dialog.getHandler(), "https://osu.ppy.sh/p/beatmaplist?q=" + searchFld.getText());
} catch (DebuggableException e) {
e.printStackTrace();
}
} else {
dialog.dispose();
return;
}
}
} else {
Config config = frame.getConfig();
if (!osums.isLoggedIn()) {
doUiLogin(config);
}
if (osums.isLoggedIn()) {
// TODO: Change to use NEW Parser
maps = osums.getLinksOfBeatmapSearch(dialog.getHandler(), "https://old.ppy.sh/p/beatmaplist?q=" + searchFld.getText());
} else {
dialog.dispose();
JOptionPane.showMessageDialog(BeatmapSearchPanel.this, "You must be logged into osu! forum to perform online search.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
} catch (DebuggableException e) {
e.printStackTrace();
return;
}
if (maps.length == 0) {
lblResultDesc.setText("No beatmaps match with the search string. Try using another keyword!" + (useDb ? " Or please try a web search with this string." : ""));
}
if (maps.length <= 40) {
lblResultDesc.setText("Only " + maps.length + " beatmaps match with the search string." + (useDb ? " Please try a web search with this string." : ""));
} else {
lblResultDesc.setText("Total of " + maps.length + " beatmaps match with the search string.");
}
dialog.getLabel().setText("Status: Updating UI...");
for (int i = 0; i < maps.length; i++) {
tableModel.addRow(new Object[] { maps[i] });
}
dialog.dispose();
}
};
thread.setDaemon(true);
thread.start();
dialog.setLocationRelativeTo(BeatmapSearchPanel.this);
dialog.setModal(true);
dialog.setVisible(true);
}
use of com.github.mob41.organdebug.exceptions.DebuggableException in project osumer by mob41.
the class Installer method getAvailableBrowsers.
public static String[] getAvailableBrowsers() throws DebuggableException {
try {
String[] keys = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, WIN_REG_CLIENTS_PATH);
List<String> filteredList = new ArrayList<String>(50);
for (int i = 0; i < keys.length; i++) {
if (!keys[i].equals(WIN_REG_INTERNET_CLIENT_KEY)) {
filteredList.add(keys[i]);
}
}
String[] out = new String[filteredList.size()];
for (int i = 0; i < out.length; i++) {
out[i] = filteredList.get(i);
}
return out;
} catch (Win32Exception e) {
throw new DebuggableException(null, "(Try&catch try)", "Throw debuggable exception", "(End of function)", "Error reading registry", false, e);
}
}
Aggregations