use of com.github.mob41.osumer.debug.WithDumpException in project osumer by mob41.
the class Installer method getAvailableBrowsers.
public static String[] getAvailableBrowsers() throws WithDumpException {
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 WithDumpException(null, "(Try&catch try)", "Throw debuggable exception", "(End of function)", "Error reading registry", false, e);
}
}
use of com.github.mob41.osumer.debug.WithDumpException 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.debug.WithDumpException in project osumer by mob41.
the class Updater method getPerVersionPerBranchLatestVersion.
public UpdateInfo getPerVersionPerBranchLatestVersion() throws WithDumpException {
final String thisVersion = Osumer.OSUMER_VERSION;
final String buildBranch = Osumer.OSUMER_BRANCH;
final int buildNum = Osumer.OSUMER_BUILD_NUM;
final int updateSource = config.getUpdateSource();
JSONObject json = getVersions();
if (json.isNull("sources")) {
throw new WithDumpException(VERSION_LIST, "Create JSONObject", "JSONObject validating \"sources\" parameter", "Convert source integer to string", "Structure invalid, missing \"sources\" parameter", false);
}
// sources -> snapshot (updateSource) -> 1.0.0 (version) -> (array:
// index0) 1 (build-number)
JSONObject sourcesJson = json.getJSONObject("sources");
JSONArray buildsArr;
String sourceKey = null;
switch(updateSource) {
case UPDATE_SOURCE_SNAPSHOT:
sourceKey = SOURCE_SNAPSHOT;
break;
case UPDATE_SOURCE_BETA:
sourceKey = SOURCE_BETA;
break;
case UPDATE_SOURCE_STABLE:
sourceKey = SOURCE_STABLE;
break;
default:
throw new InvalidSourceIntegerException(json.toString(5), "JSONObject validating \"sources\" parameter", "Convert source integer to string", "Validate sources' JSONObject and set variable", updateSource);
}
if (sourcesJson.isNull(sourceKey)) {
throw new NoSuchSourceException(json.toString(5), "Convert source integer to string", "Validate sources' JSONObject and set variable", "Validate versions' JSONObject and set variable", sourceKey);
}
JSONObject versionsJson = sourcesJson.getJSONObject(sourceKey);
if (versionsJson.isNull(thisVersion)) {
throw new NoSuchVersionException(json.toString(5), "Validate sources' JSONObject and set variable", "Validate versions' JSONObject and set variable", "Validate builds JSONArray and set variable", sourceKey, thisVersion);
}
buildsArr = versionsJson.getJSONArray(thisVersion);
if (buildsArr.length() < buildNum) {
throw new NoSuchBuildNumberException(json.toString(5), "Validate versions' JSONObject and set variable", "Validate builds JSONArray and set variable", "Get latest build number from JSONArray", buildNum);
}
int latest = buildsArr.length();
JSONObject verJson = buildsArr.getJSONObject(latest - 1);
if ((verJson.isNull("ended") || !verJson.getBoolean("ended")) && (!buildBranch.equals(sourceKey) || latest != buildNum)) {
String webLink = verJson.isNull("web_link") ? null : verJson.getString("web_link");
String exeLink = verJson.isNull("exe_link") ? null : verJson.getString("exe_link");
String jarLink = verJson.isNull("jar_link") ? null : verJson.getString("jar_link");
String desc = verJson.isNull("desc") ? null : verJson.getString("desc");
return new UpdateInfo(desc, thisVersion, updateSource, latest, webLink, exeLink, jarLink, false, false);
}
// As the version is ended, we are finding a new version here
Iterator<String> it = versionsJson.keys();
String key;
String upgradeNode = null;
while (it.hasNext()) {
key = it.next();
switch(compareVersion(thisVersion, key)) {
case -2:
break;
case -1:
if ((upgradeNode != null && compareVersion(upgradeNode, key) == -1) || upgradeNode == null) {
upgradeNode = key;
}
break;
case 0:
break;
case 1:
break;
}
}
JSONArray upgradeNodeArr = null;
int upgradedBuildNum = -1;
if (upgradeNode != null) {
upgradeNodeArr = versionsJson.getJSONArray(upgradeNode);
upgradedBuildNum = upgradeNodeArr.length();
}
if (upgradedBuildNum == 0) {
throw new NoBuildsForVersionException(json.toString(5), "Get Upgrade Node", "Validate build info JSON", "Return VersionInfo");
}
if (upgradeNode != null && upgradedBuildNum != -1) {
JSONObject upgradedVerJson = upgradeNodeArr.getJSONObject(upgradedBuildNum - 1);
String webLink = upgradedVerJson.isNull("web_link") ? null : upgradedVerJson.getString("web_link");
String exeLink = upgradedVerJson.isNull("exe_link") ? null : upgradedVerJson.getString("exe_link");
String jarLink = upgradedVerJson.isNull("jar_link") ? null : upgradedVerJson.getString("jar_link");
String desc = upgradedVerJson.isNull("desc") ? null : upgradedVerJson.getString("desc");
return new UpdateInfo(desc, upgradeNode, updateSource, upgradedBuildNum, webLink, exeLink, jarLink, false, true);
} else {
String webLink = verJson.isNull("web_link") ? null : verJson.getString("web_link");
String exeLink = verJson.isNull("exe_link") ? null : verJson.getString("exe_link");
String jarLink = verJson.isNull("jar_link") ? null : verJson.getString("jar_link");
String desc = verJson.isNull("desc") ? null : verJson.getString("desc");
return new UpdateInfo(desc, thisVersion, updateSource, buildNum, webLink, exeLink, jarLink, true, false);
}
}
use of com.github.mob41.osumer.debug.WithDumpException in project osumer by mob41.
the class Updater method getUpdaterLink.
public static String getUpdaterLink() throws WithDumpException {
URL url = null;
try {
url = new URL(VERSION_LIST + "?update=" + Calendar.getInstance().getTimeInMillis());
} catch (MalformedURLException e) {
throw new WithDumpException(VERSION_LIST, "URL url = null;", "new URL(VERSION_LIST);", "URLConnection conn = url.openConnection();", "", false, e);
}
String data = "";
try {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Connection", "close");
conn.setUseCaches(false);
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
InputStream in = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
data += line;
}
} catch (IOException e) {
throw new WithDumpException(VERSION_LIST, "URL url = new URL(VERSION_LIST);", "(lots of code) -- Connecting and fetch data", "Data validating (isEmpty / null)", "", false, e);
}
if (data == null || data.isEmpty()) {
throw new WithDumpException(VERSION_LIST, "(lots of code) -- Connecting and fetch data", "Data validating (isEmpty / null)", "Create JSONObject", "No data fetched. \"data\" is null/isEmpty", false);
}
JSONObject json = null;
try {
json = new JSONObject(data);
} catch (JSONException e) {
throw new WithDumpException(VERSION_LIST, "Data validating (isEmpty / null)", "Create JSONObject", "JSON stuff", "Structure invalid", false, e);
}
return json.isNull("updater_exe_link") ? null : json.getString("updater_exe_link");
}
use of com.github.mob41.osumer.debug.WithDumpException in project osumer by mob41.
the class Daemon method addQueue.
@Override
public MethodResult<Integer> addQueue(String url, int downloadAction, String targetFileOrFolder) throws RemoteException {
DumpManager.reportEvent("event", "queueAdd");
String user = config.getUser();
String pass = config.getPass();
if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
return new MethodResult<Integer>(ErrorCode.RESULT_NO_CREDENTIALS);
}
try {
osums.login(user, pass);
} catch (WithDumpException e) {
e.printStackTrace();
return new MethodResult<Integer>(ErrorCode.RESULT_LOGIN_FAILED, e.getDump());
}
OsuSong map;
try {
if (url.contains("b/")) {
map = osums.getBeatmapInfo(url);
} else {
map = osums.getSongInfo(url);
}
} catch (WithDumpException e) {
e.printStackTrace();
return new MethodResult<Integer>(ErrorCode.RESULT_GET_BEATMAP_INFO_FAILED, e.getDump());
}
String thumbUrl = "http:" + map.getThumbUrl();
String dwnUrlStr = map.getDwnUrl();
if (dwnUrlStr.length() <= 3) {
return new MethodResult<Integer>(ErrorCode.RESULT_DOWNLOAD_URL_TOO_SHORT);
}
URL downloadUrl = null;
try {
downloadUrl = new URL("https://osu.ppy.sh" + dwnUrlStr);
} catch (MalformedURLException e) {
e.printStackTrace();
return new MethodResult<Integer>(ErrorCode.RESULT_VALIDATE_DOWNLOAD_URL_FAILED);
}
String tmpdir = System.getProperty("java.io.tmpdir");
final String mapName = map.getName();
String fileName = dwnUrlStr.substring(3, map.getDwnUrl().length()) + " " + mapName;
fileName = fileName.replaceAll("[\\/:*?\"<>|]", " ");
OsuDownloader dwn = new OsuDownloader(tmpdir, fileName, osums, downloadUrl);
QueueAction importAction;
if (downloadAction == -1) {
importAction = new BeatmapImportAction(config);
} else {
importAction = new CustomImportAction(downloadAction, targetFileOrFolder);
}
QueueAction[] beforeActions = new QueueAction[] { new BeforeSoundAction(config) };
QueueAction[] afterActions = new QueueAction[] { new AfterSoundAction(config), new QueueAction() {
@Override
public void run(Queue queue) {
trayIcon.displayMessage("Download completed for \"" + mapName + "\"", "This osumer queue has completed downloading.", TrayIcon.MessageType.INFO);
}
}, importAction };
boolean added = queueManager.addQueue(new Queue(map.getName(), dwn, thumbUrl, beforeActions, afterActions));
if (added) {
trayIcon.displayMessage("Downloading \"" + mapName + "\"", "osumerExpress is downloading the requested beatmap!", TrayIcon.MessageType.INFO);
dwn.addObserver(new Observer() {
@Override
public void update(Observable o, Object arg) {
requestAllUiUpdateQueues();
}
});
DumpManager.reportEvent("event", "queueAdded");
if (!url.endsWith("/")) {
String beatmapNum = url.replaceAll("\\D+", "");
;
DumpManager.reportEvent("beatmap", "queueFrequency", beatmapNum);
}
} else {
trayIcon.displayMessage("Could not add \"" + mapName + "\" to queue", "It has already in queue/downloading or completed.", TrayIcon.MessageType.INFO);
}
requestAllUiUpdateQueues();
return new MethodResult<Integer>(ErrorCode.RESULT_OK);
}
Aggregations