public static void Run(Action action, Action onCrash = null) { if (Platform.RunningOS == OS.Windows) { string bindir = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location); var fullpath = Path.Combine(bindir, IntPtr.Size == 8 ? "x64" : "x86"); SetDllDirectory(fullpath); } #if !DEBUG var domain = AppDomain.CurrentDomain; domain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { var ex = (Exception)(e.ExceptionObject); CrashWindow.Run("Uh-oh!", "Librelancer has crashed. See the log for more information.", FormatException(ex)); }; try { #endif if (!Platform.CheckDependencies()) { return; } action(); #if !DEBUG } catch (Exception ex) { try { onCrash?.Invoke(); } catch { } CrashWindow.Run("Uh-oh!", "Librelancer has crashed. See the log for more information.", FormatException(ex)); } #endif }
// ReSharper disable once UnusedMember.Local // ReSharper disable once UnusedParameter.Local private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { e.Handled = true; var crash = new CrashWindow(e.Exception); crash.Show(); }
// ReSharper disable once UnusedMember.Local // ReSharper disable once UnusedParameter.Local void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) { e.SetObserved(); var crash = new CrashWindow(e.Exception); crash.Show(); }
/// <summary> /// Searches for a given crash window. /// Throws a HolodeckCrashedException if the crash window was found. /// -- Might throw a HolodeckExceptions.HolodeckCrashedException /// </summary> /// <param name="crashWindow">the crash window info to look for</param> protected static void SearchForCrashWindow (CrashWindow crashWindow) { IntPtr window = FindWindowA (null, crashWindow.title); if (window != IntPtr.Zero) { WindowInfo windowInfo = GetWindowInfo (window); string label = SearchForLabel (windowInfo, crashWindow.labelContains); if (label != string.Empty) { // we've found the specified label -> Holodeck is crashed if (crashWindow.title == UnhandledExceptionWindowTitle) { label = SearchForLabel (windowInfo, "Exception Text"); if (label != string.Empty) { throw new HolodeckExceptions.HolodeckCrashedException (label); } // it seems that even if the "Details" button is unpressed, we still have the editbox containing "Exception Text", therefore we don't need the else branch... } // TODO: provide better exception message throw new HolodeckExceptions.HolodeckCrashedException (label); } } }
public static void Main(string[] args) { if (Platform.RunningOS == OS.Windows) { string bindir = Path.GetDirectoryName(typeof(MainClass).Assembly.Location); var fullpath = Path.Combine(bindir, IntPtr.Size == 8 ? "x64" : "x86"); SetDllDirectory(fullpath); } if (!Platform.CheckDependencies()) { return; } MainWindow mw = null; #if !DEBUG var domain = AppDomain.CurrentDomain; domain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { var ex = (Exception)(e.ExceptionObject); CrashWindow.Run("Uh-oh!", "Librelancer has crashed. See the log for more information.", ex.Message + "\n" + ex.StackTrace); }; try { #endif mw = new MainWindow(); mw.Run(); #if !DEBUG } catch (Exception ex) { try { mw.Crashed(); } catch { } CrashWindow.Run("Uh-oh!", "Librelancer has crashed. See the log for more information.", ex.Message + "\n" + ex.StackTrace); } #endif }
void StartPlay(string classname) { try { _playData = new UiData() { Fonts = Project.UiData.Fonts, Infocards = Project.UiData.Infocards, DataPath = Project.UiData.DataPath, FileSystem = Project.UiData.FileSystem, FlDirectory = Project.UiData.FlDirectory, ResourceManager = Project.UiData.ResourceManager, NavbarIcons = Project.UiData.NavbarIcons, NavmapIcons = Project.UiData.NavmapIcons, Resources = Project.UiData.Resources }; _playData.SetBundle(Compiler.Compile(Project.XmlFolder, Project.XmlLoader)); _playContext = new UiContext(_playData) { RenderContext = RenderContext }; _playContext.CommandBuffer = CommandBuffer; _playContext.GameApi = TestApi; _playContext.LoadCode(); _playContext.OpenScene(classname); playing = true; } catch (Exception e) { var detail = new StringBuilder(); BuildExceptionString(e, detail); CrashWindow.Run("Interface Edit", "Compile Error", detail.ToString()); } }
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 }
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs args) { args.Handled = true; CrashWindow wnd = new CrashWindow(args.Exception); wnd.ShowDialog(); Environment.Exit(0); }
static bool CheckVCRun(string file, string errx64, string errx86) { if (LoadLibrary(file) == IntPtr.Zero) { CrashWindow.Run("Librelancer", "Missing Components", IntPtr.Size == 8 ? errx64 : errx86); return(false); } return(true); }
static bool CheckVCRun(string file, string errx64, string errx86) { if (LoadLibrary(file) == IntPtr.Zero) { CrashWindow.Run("Librelancer", "Missing Components", "LoadLibrary failed for " + file + ": " + Marshal.GetLastWin32Error() + "\n" + (IntPtr.Size == 8 ? errx64 : errx86)); return(false); } return(true); }
void CompileProject() { try { Compiler.Compile(Project.XmlFolder, Project.XmlLoader, Path.Combine(Project.XmlFolder, "out")); } catch (Exception e) { var detail = new StringBuilder(); BuildExceptionString(e, detail); CrashWindow.Run("Interface Edit", "Compile Error", detail.ToString()); } }
private static void AttachUnhandledExceptionHandlers() { Current.DispatcherUnhandledException += (sender, args) => Log.Error("A DispatcherUnhandledException has been encountered...", args.Exception); AppDomain.CurrentDomain.UnhandledException += (sender, args) => Log.Error("An UnhandledException has been encountered...", args.ExceptionObject as Exception); TaskScheduler.UnobservedTaskException += (sender, args) => Log.Error("An UnobservedTaskException has been encountered...", args.Exception); #if !DEBUG Application.Current.DispatcherUnhandledException += NBug.Handler.DispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += NBug.Handler.UnhandledException; TaskScheduler.UnobservedTaskException += NBug.Handler.UnobservedTaskException; NBug.Settings.ProcessingException += (exception, report) => { //Add latest log file contents as custom info in the error report var rootAppender = ((Hierarchy)LogManager.GetRepository()) .Root.Appenders.OfType <FileAppender>() .FirstOrDefault(); if (rootAppender != null) { using (var fs = new FileStream(rootAppender.File, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var sr = new StreamReader(fs, Encoding.Default)) { var logFileText = sr.ReadToEnd(); report.CustomInfo = logFileText; } } } }; NBug.Settings.CustomUIEvent += (sender, args) => { var crashWindow = new CrashWindow { Topmost = true, ShowActivated = true }; crashWindow.ShowDialog(); //The crash report has not been created yet - the UIDialogResult SendReport param determines what happens next args.Result = new UIDialogResult(ExecutionFlow.BreakExecution, SendReport.Send); }; NBug.Settings.InternalLogWritten += (logMessage, category) => Log.DebugFormat("NBUG:{0} - {1}", category, logMessage); #endif }
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { if (!(e.Exception is COMException)) { e.Handled = true; if (!Application.Current.Windows.OfType <CrashWindow>().Any()) { Application.Current.MainWindow.IsEnabled = false; CrashWindow crashWindow = new CrashWindow($"Error thrown of type: {e.Exception.GetType().ToString()}. {e.Exception.Message} {Environment.NewLine} {e.Exception.StackTrace}"); crashWindow.Owner = Application.Current.MainWindow; (Application.Current.MainWindow.DataContext as MainViewModel).Stop(); crashWindow.ShowDialog(); crashWindow.BringIntoView(); } } else { e.Handled = true; } }
public static void Main(string[] args) { if (Platform.RunningOS == OS.Windows) { string bindir = Path.GetDirectoryName(typeof(MainClass).Assembly.Location); var fullpath = Path.Combine(bindir, IntPtr.Size == 8 ? "x64" : "x86"); SetDllDirectory(fullpath); } if (!Platform.CheckDependencies()) { return; } FreelancerGame flgame = null; #if !DEBUG var domain = AppDomain.CurrentDomain; domain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { var ex = (Exception)(e.ExceptionObject); CrashWindow.Run("Uh-oh!", "Librelancer has crashed. See the log for more information.", ex.Message + "\n" + ex.StackTrace); }; try { #endif Func <string> filePath = null; if (args.Length > 0) { filePath = () => args[0]; } var cfg = GameConfig.Create(true, filePath); flgame = new FreelancerGame(cfg); flgame.Run(); #if !DEBUG } catch (Exception ex) { try { flgame.Crashed(); } catch { } CrashWindow.Run("Uh-oh!", "Librelancer has crashed. See the log for more information.", ex.Message + "\n" + ex.StackTrace); } #endif }
public void CrashWindow(Exception ex, [CallerMemberName] string callerMemberName = "") { CrashWindow crashWindow = new CrashWindow { ErrorName = { Text = ex.GetType().ToString() }, Message = { Text = ex.Message }, StackTrace = { Text = ex.StackTrace } }; crashWindow.Show(); Log.Add(new LogEntry(ex.GetType().ToString(), "Crash", ex)); string guid = crashWindow.SendReport(ex); var definition = new { uuid = "", status = "" }; var output = JsonConvert.DeserializeAnonymousType(guid, definition); string url = Api.CrashLogUrl + output.uuid; crashWindow.ErrorReportUrl = url; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(url, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); crashWindow.Qrcode.Source = BitmapToImageSource(qrCodeImage); }
public static bool CheckDependencies() { if (RunningOS != OS.Windows) { return(true); } if (IntPtr.Size == 8) { if (!CheckVCKey("11", @"HKEY_LOCAL_MACHINE\Software\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6}")) { CrashWindow.Run("Librelancer", "Missing Components", V2012_64); return(false); } if (!CheckVCKey("1", @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64", "Installed") && !CheckVCKey("14", @"HKEY_LOCAL_MACHINE\Software\Classes\Installer\Dependencies\{d992c12e-cab2-426f-bde3-fb8c53950b0d}")) { CrashWindow.Run("Librelancer", "Missing Components", V2015_64); return(false); } } else { if (!CheckVCKey("11", @"HKEY_LOCAL_MACHINE\Software\Classes\Installer\Dependencies\{33d1fd90-4274-48a1-9bc1-97e33d9c2d6f}")) { CrashWindow.Run("Librelancer", "Missing Components", V2012_32); return(false); } if (!CheckVCKey("1", @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86", "Installed") && !CheckVCKey("14", @"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Dependencies\{e2803110-78b3-4664-a479-3611a381656a}")) { CrashWindow.Run("Librelancer", "Missing Components", V2015_32); return(false); } } return(true); }
private void btnLogin_Click(object sender, RoutedEventArgs e) { if (txtUsername.Text == "" || pwbPassword.Password == "") { MessageBox.Show("Enter username or password"); return; } var pass = Md5Helper.GetMd5(pwbPassword.Password); var user = Db.Context.Users.Where(t => t.Email == txtUsername.Text && t.Password == pass).FirstOrDefault(); if (user != null) { times = 0; if (user.Active.Value) { var lgs = user.LoginHistories.ToList(); if (lgs.Count > 0 && lgs.Last().LogoutTime == null) { CrashWindow crashWindow = new CrashWindow(); crashWindow.Log = lgs.Last(); this.Hide(); crashWindow.ShowDialog(); if (crashWindow.IsConfirmed == false) { this.Show(); return; } } var now = DateTime.Now; var log = new LoginHistory() { UserId = user.ID, LoginTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0) }; user.LoginHistories.Add(log); Db.Context.SaveChanges(); MenuWindow menuWindow = new MenuWindow(); menuWindow.User = user; this.Hide(); menuWindow.ShowDialog(); this.Show(); txtUsername.Text = pwbPassword.Password = ""; } else { MessageBox.Show("Your account was disabled"); } } else { times++; if (times > 3) { MessageBox.Show("Username or password not correct! You must wait 10s for the next lgoin time.", "Message", MessageBoxButton.OK, MessageBoxImage.Error); btnLogin.IsEnabled = false; timer.Start(); } else { MessageBox.Show("Username or password not correct", "Message", MessageBoxButton.OK, MessageBoxImage.Error); } } }
/// <summary> /// Searches for a given crash window. /// Throws a HolodeckCrashedException if the crash window was found. /// -- Might throw a HolodeckExceptions.HolodeckCrashedException /// </summary> /// <param name="crashWindow">the crash window info to look for</param> protected static void SearchForCrashWindow(CrashWindow crashWindow) { IntPtr window = FindWindowA (null, crashWindow.title); if (window != IntPtr.Zero) { WindowInfo windowInfo = GetWindowInfo (window); string label = SearchForLabel (windowInfo, crashWindow.labelContains); if (label != string.Empty) { // we've found the specified label -> Holodeck is crashed if (crashWindow.title == UnhandledExceptionWindowTitle) { label = SearchForLabel (windowInfo, "Exception Text"); if (label != string.Empty) { throw new HolodeckExceptions.HolodeckCrashedException (label); } // it seems that even if the "Details" button is unpressed, we still have the editbox containing "Exception Text", therefore we don't need the else branch... } // TODO: provide better exception message throw new HolodeckExceptions.HolodeckCrashedException (label); } } }
protected override void Draw(double elapsed) { var delta = elapsed; RenderDelta = delta; RenderContext.ReplaceViewport(0, 0, Width, Height); RenderContext.ClearColor = new Color4(0.2f, 0.2f, 0.2f, 1f); RenderContext.ClearAll(); guiHelper.NewFrame(elapsed); ImGui.PushFont(ImGuiHelper.Noto); ImGui.BeginMainMenuBar(); if (ImGui.BeginMenu("File")) { if (Theme.IconMenuItem(Icons.File, "New", true)) { string folder; string outpath; if ((folder = FileDialog.ChooseFolder()) != null) { if ((outpath = FileDialog.Save(projectFilters)) != null) { var proj = new Project(this); proj.Create(folder, outpath); OpenGui(outpath); } } } if (Theme.IconMenuItem(Icons.Open, "Open", true)) { string f; if ((f = FileDialog.Open(projectFilters)) != null) { OpenGui(f); } } recentFiles.Menu(); if (!playing && selected is SaveableTab saveable) { if (Theme.IconMenuItem(Icons.Save, $"Save '{saveable.Title}'", true)) { saveable.Save(); } } else { Theme.IconMenuItem(Icons.Save, "Save", false); } if (ImGui.MenuItem("Compile", Project != null && !playing)) { CompileProject(); } if (Theme.IconMenuItem(Icons.Quit, "Quit", true)) { Exit(); } ImGui.EndMenu(); } if (ImGui.BeginMenu("Lua")) { if (ImGui.BeginMenu("Base Icons")) { ImGui.MenuItem("Bar", "", ref TestApi.HasBar); ImGui.MenuItem("Trader", "", ref TestApi.HasTrader); ImGui.MenuItem("Equipment", "", ref TestApi.HasEquip); ImGui.MenuItem("Ship Dealer", "", ref TestApi.HasShipDealer); ImGui.EndMenu(); } if (ImGui.BeginMenu("Active Room")) { var rooms = TestApi.GetNavbarButtons(); for (int i = 0; i < rooms.Length; i++) { if (ImGui.MenuItem(rooms[i].IconName + "##" + i, "", TestApi.ActiveHotspotIndex == i)) { TestApi.ActiveHotspotIndex = i; } } ImGui.EndMenu(); } if (ImGui.BeginMenu("Room Actions")) { ImGui.MenuItem("Launch", "", ref TestApi.HasLaunchAction); ImGui.MenuItem("Repair", "", ref TestApi.HasRepairAction); ImGui.MenuItem("Missions", "", ref TestApi.HasMissionVendor); ImGui.MenuItem("News", "", ref TestApi.HasNewsAction); ImGui.MenuItem("Commodity Trader", "", ref TestApi.HasCommodityTraderAction); ImGui.MenuItem("Ship Dealer", "", ref TestApi.HasShipDealerAction); ImGui.EndMenu(); } ImGui.EndMenu(); } if (Project != null && ImGui.BeginMenu("View")) { ImGui.MenuItem("Project", "", ref projectWindow.IsOpen); ImGui.MenuItem("Resources", "", ref resourceEditor.IsOpen); ImGui.EndMenu(); } if (Project != null && !playing && ImGui.BeginMenu("Play")) { foreach (var file in projectWindow.GetClasses()) { if (ImGui.MenuItem(file)) { StartPlay(Path.GetFileNameWithoutExtension(file)); } } ImGui.EndMenu(); } if (Project != null && playing && ImGui.MenuItem("Stop")) { playing = false; _playContext = null; _playData = null; } var menu_height = ImGui.GetWindowSize().Y; ImGui.EndMainMenuBar(); var size = (Vector2)ImGui.GetIO().DisplaySize; size.Y -= menu_height; ImGui.SetNextWindowSize(new Vector2(size.X, size.Y - 25 * ImGuiHelper.Scale), ImGuiCond.Always); ImGui.SetNextWindowPos(new Vector2(0, menu_height), ImGuiCond.Always, Vector2.Zero); if (playing) { try { Player(delta); } catch (Exception e) { var detail = new StringBuilder(); BuildExceptionString(e, detail); CrashWindow.Run("Interface Edit", "Runtime Error", detail.ToString()); playing = false; _playContext = null; _playData = null; } } else { Tabs(); } //Status Bar ImGui.SetNextWindowSize(new Vector2(size.X, 25f * ImGuiHelper.Scale), ImGuiCond.Always); ImGui.SetNextWindowPos(new Vector2(0, size.Y - 6f), ImGuiCond.Always, Vector2.Zero); bool sbopened = true; ImGui.Begin("statusbar", ref sbopened, ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize); ImGui.Text($"InterfaceEdit{(Project != null ? " - Editing: " : "")}{(Project?.ProjectFile ?? "")}"); if (playing) { ImGui.SameLine(); ImGui.Text($"Mouse Wanted: {mouseWanted}"); } ImGui.End(); recentFiles.DrawErrors(); //Finish Render ImGui.PopFont(); guiHelper.Render(RenderContext); }