use of com.github.mob41.organdebug.DebugDump in project osumer by mob41.
the class Main method runUi.
private static void runUi(Config config, String[] args, ArgParser ap) {
if (!SockThread.testPortFree(SockThread.PORT)) {
// osumer to work
try {
Socket socket = new Socket(InetAddress.getLoopbackAddress().getHostName(), SockThread.PORT);
socket.setSoTimeout(5000);
PrintWriter writer = new PrintWriter(socket.getOutputStream());
writer.println("RUN " + buildArgStr(args));
writer.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line = reader.readLine();
if (line == null || !line.equals("OK")) {
reader.close();
socket.close();
System.out.println("Not OK: " + line);
DebugDump dump = new DebugDump(null, null, "Asking BG osumer to run with args: \"" + buildArgStr(args) + "\"", null, false, "Could not start up BG osumer sucessfully. Destination did not response \"OK\": " + line);
DumpManager.getInstance().addDump(dump);
ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
dialog.setModal(true);
dialog.setVisible(true);
return;
}
reader.close();
socket.close();
System.exit(0);
return;
} catch (IOException e) {
e.printStackTrace();
DebugDump dump = new DebugDump(null, null, "Opening connection to BG osumer socket", null, "Could not open socket at 46725 for BG call. Not osumer running at that port?", false, e);
DumpManager.getInstance().addDump(dump);
ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
dialog.setModal(true);
dialog.setVisible(true);
System.exit(-1);
return;
}
} else {
String urlStr = null;
for (int i = 0; i < args.length; i++) {
if (Osums.isVaildBeatMapUrl(args[i])) {
urlStr = args[i];
break;
}
}
boolean runUi = true;
if (args.length > 0 && urlStr == null && !ap.isDaemonFlag()) {
if (config.isSwitchToBrowserIfWithoutUiArg()) {
System.out.println("Configuration specified that switch to browser if an \"-ui\" arugment wasn't specified.");
if (runUi = ap.isUiFlag() && !ap.isNoUiFlag()) {
System.out.println("An \"-ui\" argument was specified. Launching UI.");
} else {
System.out.println("An \"-ui\" argument wasn't specified. Opening the default browser instead.");
runBrowser(config, args);
return;
}
} else {
System.out.println("Non-beatmap URL detected.");
if (!config.isAutoSwitchBrowser()) {
System.out.println("Auto switch to default browser is off. Nothing to do with such URL.");
return;
} else {
System.out.println("Switching to default browser with the URL.");
runBrowser(config, args);
}
}
}
// Initialize JFX toolkit
new JFXPanel();
TrayIcon icon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(UIFrame.class.getResource("/com/github/mob41/osumer/ui/osumerIcon_16px.png")));
UIFrame frame = new UIFrame(config, new QueueManager(config), icon);
if (ap.isDaemonFlag()) {
if (!SystemTray.isSupported()) {
JOptionPane.showMessageDialog(null, "Your operating system does not support System Tray.\nAs a result, you are not able to start osumer from the tray.", "Warning", JOptionPane.WARNING_MESSAGE);
return;
}
frame.setDaemonMode(true);
SystemTray tray = SystemTray.getSystemTray();
icon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
frame.setVisible(!frame.isVisible());
if (!frame.isVisible()) {
icon.displayMessage("osumer2", "osumer2 is now running in background.", TrayIcon.MessageType.INFO);
}
}
});
icon.setToolTip("osumer2");
try {
tray.add(icon);
icon.displayMessage("osumer2", "osumer2 is now running in background.", TrayIcon.MessageType.INFO);
} catch (AWTException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Error when adding tray icon: " + e + "\nAs a result, you are not able to start osumer from the tray.", "Warning", JOptionPane.WARNING_MESSAGE);
return;
}
} else {
frame.setVisible(true);
new Thread() {
public void run() {
JOptionPane.showMessageDialog(frame, "The osumer2 daemon (background process) is not running.\nThis might slow down further osumerExpress downloads.\nNow this process is listening for more queues till it is stopped.\n\nPlease check \"Help\" for more details.", "Warning", JOptionPane.WARNING_MESSAGE);
}
}.start();
}
if (urlStr != null) {
frame.addBtQueue(urlStr, false);
}
}
}
use of com.github.mob41.organdebug.DebugDump in project osumer by mob41.
the class BeforeSoundAction method run.
@Override
public void run(Queue queue) {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
Media m = new Media(new File(config.getToneBeforeDownloadPath()).toURI().toString());
MediaPlayer mp = new MediaPlayer(m);
mp.play();
} catch (Exception e) {
e.printStackTrace();
DumpManager.getInstance().addDump(new DebugDump(null, "---", "Play before download sound", "---", "Error occurred when trying to play sound", false, e));
}
}
});
thread.setDaemon(true);
thread.start();
}
use of com.github.mob41.organdebug.DebugDump in project osumer by mob41.
the class UpdaterRunAction method run.
@Override
public void run(Queue queue) {
try {
System.out.println("Starting: \"" + filePath + "\"");
Runtime.getRuntime().exec("cmd.exe /c \"" + filePath + "\" -install");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.exit(0);
return;
} catch (IOException e1) {
e1.printStackTrace();
DebugDump dump = 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);
DumpManager.getInstance().addDump(dump);
ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
dialog.setModal(true);
dialog.setVisible(true);
}
}
use of com.github.mob41.organdebug.DebugDump in project osumer by mob41.
the class UIFrame method checkUpdate.
public void checkUpdate() {
if (checkingUpdate) {
return;
}
checkingUpdate = true;
Thread thread = new Thread() {
public void run() {
lblUpdateStatus.setForeground(Color.BLACK);
lblUpdateStatus.setText("Checking for updates...");
UpdateInfo verInfo = null;
try {
verInfo = getUpdateInfoByConfig();
} catch (NoBuildsForVersionException e) {
lblUpdateStatus.setForeground(Color.RED);
lblUpdateStatus.setText("No builds available for the new version. See dump.");
checkingUpdate = false;
return;
} catch (NoSuchVersionException e) {
lblUpdateStatus.setForeground(Color.RED);
lblUpdateStatus.setText("No current version in the selected branch. See dump.");
JOptionPane.showMessageDialog(UIFrame.this, "We don't have version " + Osumer.OSUMER_VERSION + " in the current update branch\n\nPlease try another update branch (snapshot, beta, stable).", "Version not available", JOptionPane.INFORMATION_MESSAGE);
checkingUpdate = false;
return;
} catch (NoSuchBuildNumberException e) {
lblUpdateStatus.setForeground(Color.RED);
lblUpdateStatus.setText("This version has a invalid build number. See dump");
JOptionPane.showMessageDialog(UIFrame.this, "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.", "Build not available", JOptionPane.WARNING_MESSAGE);
checkingUpdate = false;
return;
} catch (DebuggableException e) {
e.printStackTrace();
lblUpdateStatus.setForeground(Color.RED);
lblUpdateStatus.setText("Could not connect to update server.");
JOptionPane.showMessageDialog(UIFrame.this, "Could not connect to update server.", "Error", JOptionPane.ERROR_MESSAGE);
checkingUpdate = false;
return;
}
if (verInfo == null) {
lblUpdateStatus.setForeground(Color.RED);
lblUpdateStatus.setText("Could not obtain update info.");
JOptionPane.showMessageDialog(UIFrame.this, "Could not obtain update info.", "Error", JOptionPane.ERROR_MESSAGE);
checkingUpdate = false;
return;
}
if (verInfo.isThisVersion()) {
lblUpdateStatus.setForeground(Color.BLACK);
lblUpdateStatus.setText("You are running the latest version of osumer" + " (" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-" + verInfo.getBuildNum() + ")");
checkingUpdate = false;
return;
}
lblUpdateStatus.setForeground(new Color(0, 153, 0));
lblUpdateStatus.setText((verInfo.isUpgradedVersion() ? "Upgrade" : "Update") + " available! New version: " + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum());
int option;
String desc = verInfo.getDescription();
if (desc == null) {
option = JOptionPane.showOptionDialog(UIFrame.this, "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?", "Update available", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.NO_OPTION);
} else {
option = JOptionPane.showOptionDialog(UIFrame.this, "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?", "Update available", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[] { "Yes", "No", "Description/Changelog" }, JOptionPane.NO_OPTION);
if (option == 2) {
option = JOptionPane.showOptionDialog(UIFrame.this, new TextPanel(desc), "Update description/change-log", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, 0);
}
}
if (option == JOptionPane.YES_OPTION) {
/*
try {
Desktop.getDesktop().browse(new URI(verInfo.getWebLink()));
} catch (IOException | URISyntaxException e) {
DebugDump dump = new DebugDump(
verInfo.getWebLink(),
"Show option dialog of updating osumer or not",
"Set checkingUpdate to false",
"(End of function / thread)",
"Error when opening the web page",
false,
e);
DumpManager.getInstance().addDump(dump);
DebugDump.showDebugDialog(dump);
}
*/
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();
JOptionPane.showMessageDialog(null, "Error:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
return;
}
final String folder = System.getProperty("java.io.tmpdir");
final String fileName = "osumer_updater_" + Calendar.getInstance().getTimeInMillis() + ".exe";
mgr.addQueue(new Queue("osumer Updater", new URLDownloader(folder, fileName, url), null, null, new QueueAction[] { new UpdaterRunAction(folder + fileName) }));
tab.setSelectedIndex(1);
new Thread() {
public void run() {
JOptionPane.showMessageDialog(UIFrame.this, "The web updater will be downloaded and started very soon.", "Notice", JOptionPane.INFORMATION_MESSAGE);
}
}.start();
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Error:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
checkingUpdate = false;
}
}
checkingUpdate = false;
}
};
thread.start();
}
use of com.github.mob41.organdebug.DebugDump in project osumer by mob41.
the class ViewDumpDialog method updateDumpsTable.
private void updateDumpsTable() {
dumpStr.setText(SELECT_DUMP_MSG);
btnExportSelectedDump.setEnabled(false);
DumpManager mgr = DumpManager.getInstance();
if (mgr == null) {
System.out.println("DumpManager not initialized");
return;
}
dumpsModel.setRowCount(0);
dumpsArr = mgr.getDumps();
String[] rowData;
DebugDump dump;
for (int i = 0; i < dumpsArr.length; i++) {
dump = dumpsArr[i];
rowData = new String[5];
rowData[0] = dump.getGeneratedHuman();
rowData[1] = Long.toString(dump.getGenerated());
rowData[2] = dump.getMessage();
rowData[3] = dump.getStacktrace();
rowData[4] = dump.getUid();
dumpsModel.addRow(rowData);
}
dumpsModel.fireTableDataChanged();
}
Aggregations