Local crash saving
This commit is contained in:
@@ -8,21 +8,33 @@ import io.anuke.mindustry.game.Version;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.OS;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class CrashHandler{
|
||||
|
||||
public static void handle(Throwable e){
|
||||
try{
|
||||
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
|
||||
}catch(Throwable ignored){}
|
||||
|
||||
boolean badGPU = false;
|
||||
|
||||
if(e.getMessage() != null && (e.getMessage().contains("Couldn't create window") || e.getMessage().contains("OpenGL 2.0 or higher"))){
|
||||
try{
|
||||
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
|
||||
javax.swing.JOptionPane.showMessageDialog(null, "Your graphics card does not support OpenGL 2.0!\n" +
|
||||
"Try to update your graphics drivers.\n\n" +
|
||||
"(If that doesn't work, your computer just doesn't support Mindustry.)",
|
||||
"oh no", javax.swing.JOptionPane.INFORMATION_MESSAGE);
|
||||
badGPU = true;
|
||||
}catch(Throwable ignored){}
|
||||
javax.swing.JOptionPane.showMessageDialog(null, "Your graphics card does not support OpenGL 2.0!\n" +
|
||||
"Try to update your graphics drivers.\n\n" +
|
||||
"(If that doesn't work, your computer just doesn't support Mindustry.)",
|
||||
"oh no", javax.swing.JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
e.printStackTrace();
|
||||
@@ -59,6 +71,22 @@ public class CrashHandler{
|
||||
ex(() -> value.addChild("multithreading", new JsonValue(Settings.getBool("multithread"))));
|
||||
ex(() -> value.addChild("trace", new JsonValue(parseException(e))));
|
||||
|
||||
try{
|
||||
Path path = Paths.get(OS.getAppDataDirectoryString(Vars.appName), "crashes",
|
||||
"crash-report-" + DateTimeFormatter.ofPattern("MM-dd-yyyy-HH:mm:ss").format(LocalDateTime.now()) + ".txt");
|
||||
Files.createDirectories(Paths.get(OS.getAppDataDirectoryString(Vars.appName), "crashes"));
|
||||
|
||||
Files.write(path, parseException(e).getBytes());
|
||||
|
||||
if(!badGPU){
|
||||
javax.swing.JOptionPane.showMessageDialog(null, "A crash has occured. It has been saved in:\n" + path.toAbsolutePath().toString(),
|
||||
"oh no", javax.swing.JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}catch(Throwable t){
|
||||
Log.err("Failed to save local crash report.");
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
Log.info("Sending crash report.");
|
||||
//post to crash report URL
|
||||
Net.http(Vars.crashReportURL, "POST", value.toJson(OutputType.json), r -> {
|
||||
@@ -77,7 +105,7 @@ public class CrashHandler{
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
return sw.toString();
|
||||
return sw.toString().replace(e.getMessage(), e.getMessage().replace(System.getProperty("user.name"), "[USERNAME]"));
|
||||
}
|
||||
|
||||
private static void ex(Runnable r){
|
||||
|
||||
Reference in New Issue
Block a user