use of com.github.mob41.osumer.debug.DebugDump in project osumer by mob41.
the class AfterSoundAction 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.getToneAfterDownloadPath()).toURI().toString());
MediaPlayer mp = new MediaPlayer(m);
mp.play();
} catch (Exception e) {
e.printStackTrace();
DumpManager.getInstance().addDump(new DebugDump(null, "---", "Play after download sound", "---", "Error occurred when trying to play sound", false, e));
}
}
});
thread.setDaemon(true);
thread.start();
}
use of com.github.mob41.osumer.debug.DebugDump in project osumer by mob41.
the class SockThread method run.
@Override
public void run() {
if (!running) {
running = true;
try {
sock = new ServerSocket(PORT, 0, InetAddress.getLoopbackAddress());
} catch (IOException e1) {
e1.printStackTrace();
DebugDump dump = new DebugDump(null, null, "Opening osumer socket", null, "Could not open socket at 46725 for BG call. Another osumer application running?", false, e1);
DumpManager.getInstance().addDump(dump);
ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
dialog.setModal(true);
dialog.setVisible(true);
System.exit(-1);
return;
}
try {
while (running) {
Socket cs = sock.accept();
new ConnThread(this, cs).start();
}
sock.close();
} catch (IOException e) {
DebugDump dump = new DebugDump(null, null, "ServerSocket breaks at exception", null, "Unexpected ServerSocket break", false, e);
DumpManager.getInstance().addDump(dump);
ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
dialog.setModal(true);
dialog.setVisible(true);
System.exit(-1);
return;
}
running = false;
}
}
use of com.github.mob41.osumer.debug.DebugDump in project osumer by mob41.
the class URLDownloader method run.
@Override
public void run() {
RandomAccessFile file = null;
InputStream in = null;
try {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Range", "bytes=" + downloaded + "-");
conn.connect();
if (conn.getResponseCode() / 100 != 2) {
error();
}
int len = conn.getContentLength();
if (len < 1) {
error();
}
if (size == -1) {
size = len;
reportState();
}
file = new RandomAccessFile(folder + "\\" + fileName, "rw");
file.seek(downloaded);
in = conn.getInputStream();
while (status == DOWNLOADING) {
if (size == downloaded) {
break;
}
byte[] buffer = size - downloaded > MAX_BUFFER_SIZE ? new byte[MAX_BUFFER_SIZE] : new byte[size - downloaded];
int read = in.read(buffer);
if (read == -1) {
break;
}
file.write(buffer, 0, read);
downloaded += read;
reportState();
}
if (status == DOWNLOADING) {
if (file != null) {
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
status = COMPLETED;
reportState();
}
} catch (IOException e) {
DumpManager.getInstance().addDump(new DebugDump(null, "(Try&catch try)", "Error reporting and debug dump", "(Try&catch finally)", "Error when downloading", false, e));
error();
} finally {
if (file != null) {
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of com.github.mob41.osumer.debug.DebugDump 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.DebugDump 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