mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System.Diagnostics;
|
|
using System.Text.Json;
|
|
|
|
namespace Penumbra.CrashHandler;
|
|
|
|
public class CrashHandler
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
if (args.Length < 4 || !int.TryParse(args[1], out var pid))
|
|
return;
|
|
|
|
try
|
|
{
|
|
using var reader = new GameEventLogReader(pid);
|
|
var parent = Process.GetProcessById(pid);
|
|
using var handle = parent.SafeHandle;
|
|
parent.WaitForExit();
|
|
int exitCode;
|
|
try
|
|
{
|
|
exitCode = parent.ExitCode;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
exitCode = -1;
|
|
}
|
|
|
|
var obj = reader.Dump("Crash", pid, exitCode, args[2], args[3]);
|
|
using var fs = File.Open(args[0], FileMode.Create);
|
|
using var w = new Utf8JsonWriter(fs, new JsonWriterOptions { Indented = true });
|
|
obj.WriteTo(w, new JsonSerializerOptions() { WriteIndented = true });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
File.WriteAllText(args[0], $"{DateTime.UtcNow} {pid} {ex}");
|
|
}
|
|
}
|
|
}
|