From 1b8b4dd1300a23270afbc7813609256523d4cbb1 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 1 Aug 2012 15:04:31 +0200 Subject: [PATCH] logger: Create crash report in ~/SparkleShare on crashes. --- SparkleLib/SparkleLogger.cs | 41 ++++++++++++++++++++++++++++++++ SparkleShare/Mac/SparkleSetup.cs | 2 +- SparkleShare/Program.cs | 14 +++++++---- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/SparkleLib/SparkleLogger.cs b/SparkleLib/SparkleLogger.cs index f6e5a370..78c3fdae 100755 --- a/SparkleLib/SparkleLogger.cs +++ b/SparkleLib/SparkleLogger.cs @@ -36,5 +36,46 @@ namespace SparkleLib { lock (debug_lock) File.AppendAllText (SparkleConfig.DefaultConfig.LogFilePath, line + Environment.NewLine); } + + + public static void WriteCrashReport (Exception e) + { + string home_path = Environment.GetFolderPath (Environment.SpecialFolder.Personal); + + if (SparkleBackend.Platform == PlatformID.Win32NT) + home_path = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile); + + string crash_report_file_path = new string [] { home_path, "SparkleShare", "crash_report.txt" }.Combine (); + + string n = Environment.NewLine; + string crash_report = "Oops! SparkleShare has crashed... :(" + n + n + + "If you want to help fix this crash, please report it at " + n + + "https://github.com/hbons/SparkleShare/issues and include the lines below." + n + n + + "Remove any sensitive information like file names, IP addresses, domain names, etc. if needed." + n + n + + "------" + n + n + + "SparkleShare version: " + SparkleLib.SparkleBackend.Version + n + + "Operating system: " + SparkleLib.SparkleBackend.Platform + " " + Environment.OSVersion + n; + + crash_report += n + e.Message + n + e.StackTrace + n; + + if (e.InnerException != null) + crash_report += n + e.InnerException.Message + n + e.InnerException.StackTrace + n; + + if (SparkleConfig.DefaultConfig != null && File.Exists (SparkleConfig.DefaultConfig.LogFilePath)) { + string debug_log = File.ReadAllText (SparkleConfig.DefaultConfig.LogFilePath); + string [] debug_lines = debug_log.Split (Environment.NewLine.ToCharArray ()); + int line_count = 50; + + if (debug_lines.Length > line_count) { + crash_report += string.Join (Environment.NewLine, debug_lines, + (debug_lines.Length - line_count), line_count) + n; + + } else { + crash_report += debug_log + n; + } + } + + File.WriteAllText (crash_report_file_path, crash_report); + } } } diff --git a/SparkleShare/Mac/SparkleSetup.cs b/SparkleShare/Mac/SparkleSetup.cs index 62c80cda..a449740c 100755 --- a/SparkleShare/Mac/SparkleSetup.cs +++ b/SparkleShare/Mac/SparkleSetup.cs @@ -491,7 +491,7 @@ namespace SparkleShare { Buttons.Add (FinishButton); Buttons.Add (CancelButton); } - + if (type == PageType.Error) { Header = "Oops! Something went wrong…"; Description = "Please check the following:"; diff --git a/SparkleShare/Program.cs b/SparkleShare/Program.cs index 4b6d39a2..6e69bd43 100644 --- a/SparkleShare/Program.cs +++ b/SparkleShare/Program.cs @@ -63,11 +63,17 @@ namespace SparkleShare { Environment.Exit (-1); } - Controller = new SparkleController (); - Controller.Initialize (); + try { + Controller = new SparkleController (); + Controller.Initialize (); - UI = new SparkleUI (); - UI.Run (); + UI = new SparkleUI (); + UI.Run (); + + } catch (Exception e) { + SparkleLogger.WriteCrashReport (e); + Environment.Exit (-1); + } #if !__MonoCS__ // Suppress assertion messages in debug mode