use of com.github.mob41.osumer.debug.WithDumpException in project osumer by mob41.
the class OsumsOldParser method searchOnlineMaps.
@Override
public SearchResult searchOnlineMaps(String keywords, SearchFilter[] filters, int page) throws WithDumpException {
if (keywords == null) {
keywords = "";
}
String url = SEARCH_URL + keywords;
String rank = null;
if (filters != null) {
for (SearchFilter filter : filters) {
if (filter instanceof RankFilter) {
rank = ((RankFilter) filter).getRank();
}
url = filter.handleUrl(url);
}
}
if (rank == null) {
rank = RANK_ANY;
}
if (rank.equals(RANK_RANKED)) {
url += "&r=" + RANK_RANKED_INT;
} else if (rank.equals(RANK_PENDING)) {
url += "&r=" + RANK_PENDING_INT;
} else if (rank.equals(RANK_QUALIFIED)) {
url += "&r=" + RANK_QUALIFIED_INT;
} else if (rank.equals(RANK_LOVED)) {
url += "&r=" + RANK_LOVED_INT;
} else if (rank.equals(RANK_ANY)) {
url += "&r=" + RANK_ALL_INT;
} else {
System.out.println("Unknown beatmap rank: " + rank);
}
try {
String data = getHttpCookiedContent(url + "&page=" + page);
Document doc = Jsoup.parse(data);
Element pagination = doc.getElementsByClass("pagination").first();
String paginationText = pagination.html();
int totalPages = 1;
int brIndex = paginationText.indexOf("<br>");
if (brIndex == -1) {
throw new WithDumpException(paginationText, "Get br index in pagination", "Validate brIndex != -1", "Extract pagination text before br", "Could not find at least one br element!", false);
}
String pageText = paginationText.substring(0, brIndex);
// 11
int displayingIndex = pageText.indexOf("Displaying ");
// 4
int toIndex = pageText.indexOf(" to ");
// 4
int ofIndex = pageText.indexOf(" of ");
// 9
int resultIndex = pageText.indexOf(" results.");
if (displayingIndex == -1 || toIndex == -1 || ofIndex == -1 || resultIndex == -1) {
throw new WithDumpException(paginationText, "Get all text indexes", "Validate all text indexes != -1", "Extract result pages data", "The pagination is invalid or unregonized.", false);
}
// int nowPage = -1;
int currPageMaps = -1;
int totalResultMaps = -1;
try {
// nowPage = Integer.parseInt(pageText.substring(displayingIndex + 11, toIndex));
String currPageMapsStr = pageText.substring(toIndex + 4, ofIndex);
if (!currPageMapsStr.equals("many")) {
currPageMaps = Integer.parseInt(currPageMapsStr);
}
String totalResultMapsStr = pageText.substring(ofIndex + 4, resultIndex);
if (!totalResultMapsStr.equals("many")) {
totalResultMaps = Integer.parseInt(totalResultMapsStr);
}
} catch (NumberFormatException e) {
throw new WithDumpException(pageText, "Validate all text indexes != -1", "Extract result pages data", "Get page data", "Pagination number-text data cannot be decoded as number.", false, e);
}
if (totalResultMaps != -1 && currPageMaps != -1 && currPageMaps != totalResultMaps) {
currPageMaps -= 40 * (page - 1);
// System.out.println("Using method 1 to identify Total Pages");
// System.out.println("TRM/CPM: " + totalResultMaps + " / " + currPageMaps);
float calc = ((float) totalResultMaps / currPageMaps);
totalPages = (int) calc;
if (calc != totalPages) {
// System.out.println("Calc != totalPages: " + calc + " != " + totalPages);
totalPages++;
}
// System.out.println("Now total pages: " + totalPages);
} else {
// System.out.println("Using method 2 to identify Total Pages");
Elements pageLinkEls = pagination.children();
int size = pageLinkEls.size();
if (size < 2) {
totalPages = 1;
/*
throw new WithDumpException(pageText, "Get page links size",
"Validate children size >= 2", "Get last page link element",
"Invalid page! The page has less than 2 page links!", false);
*/
} else {
Element lastPageLinkEl = pageLinkEls.get(size - 2);
if (lastPageLinkEl != null) {
int lastPageNum = -1;
try {
lastPageNum = Integer.parseInt(lastPageLinkEl.html());
} catch (NumberFormatException e) {
throw new WithDumpException(pageText, "Get last page link element", "Parse last page number String to number", "Set as total page", "Pagination last page number-text data cannot be decoded as number.", false, e);
}
if (lastPageNum > totalPages) {
// System.out.println("Last page num is bigger than total pages: " + lastPageNum + " > " + totalPages);
totalPages = lastPageNum;
} else {
// System.out.println("Last page num is sammler than total pages: " + lastPageNum + " < " + totalPages);
}
}
}
}
SongResult[] results = parseSearch(rank, doc);
return new SearchResult(results, page, totalPages);
} catch (Exception e) {
throw new WithDumpException(url, "(Try&catch try) getting search result links", "Throw debuggable exception on catch", "(End of function)", "Error occurred when getting search result links", false, e);
}
}
use of com.github.mob41.osumer.debug.WithDumpException in project osumer by mob41.
the class OsumsOldParser method getSongInfo.
@Override
public OsuSong getSongInfo(String link) throws WithDumpException {
try {
link = link.replaceFirst("osu.ppy.sh", "old.ppy.sh");
String data = getHttpCookiedContent(link);
Document doc = Jsoup.parse(data);
return parseSong(link, doc);
} catch (Exception e) {
throw new WithDumpException(link, "(Try&catch try) getting beatmap info", "Throw debuggable exception on catch", "(End of function)", "Error occurred when getting beatmap info", false, e);
}
}
use of com.github.mob41.osumer.debug.WithDumpException 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.debug.WithDumpException in project osumer by mob41.
the class MainController method checkUpdate.
public void checkUpdate() {
if (checkingUpdate) {
return;
}
checkingUpdate = true;
Thread thread = new Thread() {
public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
updateText.setText("Checking for updates...");
}
});
UpdateInfo verInfo = null;
try {
verInfo = getUpdateInfoByConfig();
} catch (NoBuildsForVersionException e) {
Platform.runLater(new Runnable() {
@Override
public void run() {
updateText.setText("No builds available for the new version. See dump.");
}
});
checkingUpdate = false;
return;
} catch (NoSuchVersionException e) {
Platform.runLater(new Runnable() {
@Override
public void run() {
updateText.setText("No current version in the selected branch. See dump.");
Alert alert = new Alert(AlertType.INFORMATION, "We don't have version " + Osumer.OSUMER_VERSION + " in the current update branch\n\n" + "Please try another update branch (snapshot, beta, stable).", ButtonType.OK);
alert.setHeaderText("osumer - Version not available");
alert.showAndWait();
}
});
checkingUpdate = false;
return;
} catch (NoSuchBuildNumberException e) {
Platform.runLater(new Runnable() {
@Override
public void run() {
updateText.setText("This version has a invalid build number. See dump");
Alert alert = new Alert(AlertType.WARNING, "We don't have build number greater or equal to " + Osumer.OSUMER_BUILD_NUM + " in version " + Osumer.OSUMER_VERSION + ".\n" + "If you are using a modified/development osumer,\n" + " you can just ignore this message.\n" + "If not, this might be the versions.json in GitHub goes wrong,\n" + " post a new issue about this.", ButtonType.OK);
alert.setHeaderText("osumer - Build not available");
alert.showAndWait();
}
});
checkingUpdate = false;
return;
} catch (WithDumpException e) {
e.printStackTrace();
Platform.runLater(new Runnable() {
@Override
public void run() {
updateText.setText("Could not connect to update server.");
Alert alert = new Alert(AlertType.ERROR, "Could not connect to update server.", ButtonType.OK);
alert.setHeaderText("osumer - Error Checking Update");
alert.showAndWait();
}
});
checkingUpdate = false;
return;
}
final UpdateInfo _verInfo = verInfo;
Platform.runLater(new Runnable() {
@Override
public void run() {
if (_verInfo == null) {
updateText.setText("Could not obtain update info.");
Alert alert = new Alert(AlertType.ERROR, "Could not obtain update info.", ButtonType.OK);
alert.setHeaderText("osumer - Error Checking Update");
alert.showAndWait();
checkingUpdate = false;
return;
}
if (_verInfo.isThisVersion()) {
updateText.setText("Running the latest: " + " " + _verInfo.getVersion() + "-" + Updater.getBranchStr(_verInfo.getBranch()) + "-b" + _verInfo.getBuildNum());
checkingUpdate = false;
return;
}
updateText.setText((_verInfo.isUpgradedVersion() ? "Upgrade" : "Update") + " now to " + _verInfo.getVersion() + "-" + Updater.getBranchStr(_verInfo.getBranch()) + "-b" + _verInfo.getBuildNum());
Alert alert = new Alert(AlertType.INFORMATION, "", ButtonType.YES);
alert.getButtonTypes().add(ButtonType.NO);
alert.setHeaderText("Update available");
String desc = _verInfo.getDescription();
alert.setContentText("New " + (_verInfo.isUpgradedVersion() ? "upgrade" : "update") + " available! New version:\n" + _verInfo.getVersion() + "-" + Updater.getBranchStr(_verInfo.getBranch()) + "-b" + _verInfo.getBuildNum() + "\n\n" + "Do you want to update it now?");
ButtonType detailsBtn = new ButtonType("Details");
if (desc != null) {
alert.getButtonTypes().add(detailsBtn);
}
Alert detailsAlert = new Alert(AlertType.NONE, "", ButtonType.OK);
detailsAlert.setHeaderText("Change-log");
detailsAlert.setContentText(desc);
ButtonType result;
do {
alert.showAndWait();
result = alert.getResult();
if (result == detailsBtn) {
detailsAlert.showAndWait();
}
} while (result == detailsBtn);
if (result == ButtonType.YES) {
try {
String updaterLink = Updater.getUpdaterLink();
if (updaterLink == null) {
System.out.println("No latest updater .exe defined! Falling back to legacy updater!");
updaterLink = Updater.LEGACY_UPDATER_JAR;
}
URL url;
try {
url = new URL(updaterLink);
} catch (MalformedURLException e) {
e.printStackTrace();
Alert alert0 = new Alert(AlertType.ERROR, "Error:\n" + e, ButtonType.OK);
alert0.showAndWait();
return;
}
final String folder = System.getProperty("java.io.tmpdir");
final String fileName = "osumer_updater_" + Calendar.getInstance().getTimeInMillis() + ".exe";
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("Update");
progressController.getStatusText().setText("Status: Initializing...");
progressController.getProgressBar().setProgress(-1);
boolean noClose = false;
Alert progressDialog = new Alert(AlertType.NONE);
progressDialog.initStyle(StageStyle.UTILITY);
progressDialog.initModality(Modality.APPLICATION_MODAL);
progressDialog.setTitle("");
progressDialog.setDialogPane(progressPane);
progressDialog.getButtonTypes().add(ButtonType.CANCEL);
Thread thread = new Thread() {
public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
progressController.getStatusText().setText("Status: Downloading updater...");
}
});
URLDownloader dwn = new URLDownloader(folder, fileName, url);
dwn.download();
while (dwn.getStatus() == OsuDownloader.DOWNLOADING) {
if (this.isInterrupted()) {
return;
}
int progress = (int) dwn.getProgress();
Platform.runLater(new Runnable() {
@Override
public void run() {
progressController.getProgressBar().setProgress(progress / 100.0);
}
});
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Platform.runLater(new Runnable() {
@Override
public void run() {
progressController.getProgressBar().setProgress(-1);
}
});
if (dwn.getStatus() == OsuDownloader.ERROR) {
Platform.runLater(new Runnable() {
@Override
public void run() {
progressController.getStatusText().setText("Status: Error when downloading updater. Please restart osumer.");
}
});
System.out.println("Download failed.");
} else if (dwn.getStatus() == OsuDownloader.COMPLETED) {
String loc = folder + "\\" + fileName;
Platform.runLater(new Runnable() {
@Override
public void run() {
progressController.getStatusText().setText("Status: Download completed. Starting...");
}
});
System.out.println("Download completed...");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
Runtime.getRuntime().exec("cmd.exe /c " + loc + " -install");
} catch (IOException e1) {
e1.printStackTrace();
DumpManager.addDump(new DebugDump(null, "(If[openFile] scope) (UI) Set status to lblStatus", "(Try scope) Open file loc using Desktop.getDesktop.open()", "(Try scope) Sleep 2000 ms (2 sec)", "Unable to open file", false, e1));
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Platform.exit();
System.exit(0);
return;
}
}
};
thread.start();
progressDialog.showAndWait();
} catch (WithDumpException e) {
e.printStackTrace();
checkingUpdate = false;
Alert alert0 = new Alert(AlertType.ERROR, "Error:\n" + e, ButtonType.OK);
alert0.showAndWait();
return;
}
}
checkingUpdate = false;
}
});
}
};
thread.start();
}
use of com.github.mob41.osumer.debug.WithDumpException in project osumer by mob41.
the class MainController method checkAnnouncements.
public void checkAnnouncements() {
if (checkingAnnouncements) {
return;
}
checkingAnnouncements = true;
Thread thread = new Thread() {
public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
announcementLabel.setText("Loading announcements...");
}
});
if (updateAnnUiTimeline != null) {
updateAnnUiTimeline.stop();
}
currAnnIndex = -1;
ann = null;
try {
ann = annChecker.getAnnouncements();
} catch (WithDumpException e) {
Platform.runLater(new Runnable() {
@Override
public void run() {
announcementLabel.setText("Error checking announcements. See dump for more details.");
}
});
checkingAnnouncements = false;
return;
}
nextAnnouncement();
updateAnnUiTimeline = new Timeline(new KeyFrame(Duration.seconds(15), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if (ann == null) {
updateAnnUiTimeline.stop();
return;
}
nextAnnouncement();
}
}));
updateAnnUiTimeline.setCycleCount(Timeline.INDEFINITE);
updateAnnUiTimeline.play();
checkingAnnouncements = false;
}
};
thread.start();
}
Aggregations