Local crash saving

This commit is contained in:
Anuken
2018-11-04 09:57:12 -05:00
parent 9ffc8c6800
commit 5f1addc54d
2 changed files with 52 additions and 6 deletions

View File

@@ -8,9 +8,15 @@ 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{
@@ -49,6 +55,18 @@ public class CrashHandler{
ex(() -> value.addChild("os", new JsonValue(System.getProperty("os.name"))));
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());
Log.info("Saved crash report at {0}", path.toAbsolutePath().toString());
}catch(Throwable t){
Log.err("Failure saving crash report: ");
t.printStackTrace();
}
Log.info("&lcSending crash report.");
//post to crash report URL
Net.http(Vars.crashReportURL, "POST", value.toJson(OutputType.json), r -> System.exit(1), t -> System.exit(1));