logger: Create crash report in ~/SparkleShare on crashes.

This commit is contained in:
Hylke Bons 2012-08-01 15:04:31 +02:00
parent 4b9e1f5c34
commit 66e7a67d14
3 changed files with 52 additions and 5 deletions

View file

@ -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);
}
}
}

View file

@ -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:";

View file

@ -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