|
6 | 6 | using System.Text; |
7 | 7 | using System.Threading; |
8 | 8 | using System.Threading.Tasks; |
| 9 | +using AssettoServer.Shared.Services; |
9 | 10 | using AssettoServer.Utils; |
10 | 11 | using Autofac.Extensions.DependencyInjection; |
11 | 12 | using CommandLine; |
@@ -61,7 +62,9 @@ private class StartOptions |
61 | 62 | public string? EntryListPath { get; init; } |
62 | 63 | } |
63 | 64 |
|
64 | | - public static bool IsContentManager; |
| 65 | + public static bool IsContentManager { get; private set; } |
| 66 | + public static ConfigurationLocations? ConfigurationLocations { get; private set; } |
| 67 | + |
65 | 68 | private static bool _loadPluginsFromWorkdir; |
66 | 69 | private static bool _generatePluginConfigs; |
67 | 70 | private static TaskCompletionSource<StartOptions> _restartTask = new(); |
@@ -100,7 +103,8 @@ internal static async Task Main(string[] args) |
100 | 103 | string logPrefix = string.IsNullOrEmpty(options.Preset) ? "log" : options.Preset; |
101 | 104 | Logging.CreateLogger(logPrefix, IsContentManager, options.Preset, options.UseVerboseLogging); |
102 | 105 |
|
103 | | - AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; |
| 106 | + AppDomain.CurrentDomain.UnhandledException += UnhandledException; |
| 107 | + CriticalBackgroundService.UnhandledException += UnhandledException; |
104 | 108 | Log.Information("AssettoServer {Version}", ThisAssembly.AssemblyInformationalVersion); |
105 | 109 | if (IsContentManager) |
106 | 110 | { |
@@ -150,11 +154,11 @@ private static async Task RunServerAsync( |
150 | 154 | bool useVerboseLogging, |
151 | 155 | CancellationToken token = default) |
152 | 156 | { |
153 | | - var configLocations = ConfigurationLocations.FromOptions(preset, serverCfgPath, entryListPath); |
| 157 | + ConfigurationLocations = ConfigurationLocations.FromOptions(preset, serverCfgPath, entryListPath); |
154 | 158 |
|
155 | 159 | try |
156 | 160 | { |
157 | | - var config = new ACServerConfiguration(preset, configLocations, _loadPluginsFromWorkdir, _generatePluginConfigs); |
| 161 | + var config = new ACServerConfiguration(preset, ConfigurationLocations, _loadPluginsFromWorkdir, _generatePluginConfigs); |
158 | 162 |
|
159 | 163 | string logPrefix = string.IsNullOrEmpty(preset) ? "log" : preset; |
160 | 164 | Logging.CreateLogger(logPrefix, IsContentManager, preset, useVerboseLogging, config.Extra.RedactIpAddresses, config.Extra.LokiSettings); |
@@ -191,26 +195,13 @@ private static async Task RunServerAsync( |
191 | 195 | } |
192 | 196 | catch (Exception ex) |
193 | 197 | { |
194 | | - Log.Fatal(ex, "Error starting server"); |
195 | | - string? crashReportPath = null; |
196 | | - try |
197 | | - { |
198 | | - crashReportPath = CrashReportHelper.GenerateCrashReport(configLocations, ex); |
199 | | - } |
200 | | - catch (Exception ex2) |
201 | | - { |
202 | | - Log.Error(ex2, "Error writing crash report"); |
203 | | - } |
204 | | - await Log.CloseAndFlushAsync(); |
205 | | - ExceptionHelper.PrintExceptionHelp(ex, IsContentManager, crashReportPath); |
| 198 | + CrashReportHelper.HandleFatalException(ex); |
206 | 199 | } |
207 | 200 | } |
208 | 201 |
|
209 | | - private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs args) |
| 202 | + private static void UnhandledException(object sender, UnhandledExceptionEventArgs args) |
210 | 203 | { |
211 | | - Log.Fatal((Exception)args.ExceptionObject, "Unhandled exception occurred"); |
212 | | - Log.CloseAndFlush(); |
213 | | - Environment.Exit(1); |
| 204 | + CrashReportHelper.HandleFatalException((Exception)args.ExceptionObject); |
214 | 205 | } |
215 | 206 |
|
216 | 207 | private static void SetupFluentValidation() |
|
0 commit comments