public static void Run(Action action, Action onCrash = null) { string errorMessage = $"Librelancer has crashed. See the log for more information."; Environment.SetEnvironmentVariable("ALSOFT_LOGLEVEL", "2"); if (Platform.RunningOS == OS.Windows) { string bindir = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location); var fullpath = Path.Combine(bindir, IntPtr.Size == 8 ? "x64" : "x86"); SetDllDirectory(fullpath); //Setup Spew var spewFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Librelancer"); if (!Directory.Exists(spewFolder)) { Directory.CreateDirectory(spewFolder); } string spewFilename = Assembly.GetCallingAssembly().GetName().Name + ".log.txt"; var spewPath = Path.Combine(spewFolder, spewFilename); string openAlFilename = Assembly.GetCallingAssembly().GetName().Name + ".openallog.txt"; var openalPath = Path.Combine(spewFolder, openAlFilename); if (!Debugger.IsAttached) { Environment.SetEnvironmentVariable("ALSOFT_LOGFILE", openalPath); } if (FLLog.CreateSpewFile(spewPath)) { errorMessage += "\n" + spewPath; } else { errorMessage += "\n(Log file could not be created)."; } } #if !DEBUG var domain = AppDomain.CurrentDomain; domain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { var ex = (Exception)(e.ExceptionObject); CrashWindow.Run("Uh-oh!", errorMessage, FormatException(ex).ToString()); }; try { #endif if (!Platform.CheckDependencies()) { return; } action(); #if !DEBUG } catch (Exception ex) { try { onCrash?.Invoke(); } catch { } CrashWindow.Run("Uh-oh!", errorMessage, FormatException(ex).ToString()); } #endif }