Skip to content

Commit

Permalink
add option to show crash report in explorer in ExceptionHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
compujuckel committed Jan 11, 2024
1 parent 7049583 commit 457a329
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
8 changes: 5 additions & 3 deletions AssettoServer/CrashReportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private class Attachment
public required string Content { get; init; }
}

public static void GenerateCrashReport(ConfigurationLocations locations, Exception exception)
public static string GenerateCrashReport(ConfigurationLocations locations, Exception exception)
{
Template template;
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AssettoServer.Assets.crash_report.md.tpl")!)
Expand Down Expand Up @@ -63,8 +63,10 @@ public static void GenerateCrashReport(ConfigurationLocations locations, Excepti
}
}
});

File.WriteAllText(Path.Join("crash", filename), result);

var path = Path.Join("crash", filename);
File.WriteAllText(path, result);
return Path.GetFullPath(path);
}

[GeneratedRegex(@"((?:password|key|token|url)\s*[=:][ \t]*)(.*)$", RegexOptions.Multiline | RegexOptions.IgnoreCase)]
Expand Down
17 changes: 16 additions & 1 deletion AssettoServer/ExceptionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Please make sure that you downloaded AssettoServer from the official website.
or another Discord server.
""";

public static void PrintExceptionHelp(Exception ex, bool isContentManager)
public static void PrintExceptionHelp(Exception ex, bool isContentManager, string? crashReportPath)
{
string? helpLink = null;

Expand Down Expand Up @@ -72,6 +72,10 @@ public static void PrintExceptionHelp(Exception ex, bool isContentManager)
{
Console.WriteLine("Press I to get more info on this error");
}
if (crashReportPath != null)
{
Console.WriteLine("Press C to show the crash report");
}
Console.WriteLine("Press W to go to the AssettoServer website");
Console.WriteLine("Press D to join the official Discord server");
Console.WriteLine("Press any other key to exit");
Expand All @@ -91,6 +95,17 @@ public static void PrintExceptionHelp(Exception ex, bool isContentManager)
{
OpenURL("https://assettoserver.org/");
}
else if (crashReportPath != null && key.Key == ConsoleKey.C)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Process.Start("explorer.exe", $"/select, \"{crashReportPath}\"");
}
else
{
OpenURL(crashReportPath);
}
}
}

Console.ForegroundColor = old;
Expand Down
5 changes: 3 additions & 2 deletions AssettoServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,17 @@ private static async Task RunServerAsync(
catch (Exception ex)
{
Log.Fatal(ex, "Error starting server");
string? crashReportPath = null;
try
{
CrashReportHelper.GenerateCrashReport(configLocations, ex);
crashReportPath = CrashReportHelper.GenerateCrashReport(configLocations, ex);
}
catch (Exception ex2)
{
Log.Error(ex2, "Error writing crash report");
}
await Log.CloseAndFlushAsync();
ExceptionHelper.PrintExceptionHelp(ex, IsContentManager);
ExceptionHelper.PrintExceptionHelp(ex, IsContentManager, crashReportPath);
}
}

Expand Down

0 comments on commit 457a329

Please sign in to comment.