/// <summary> /// Throw up an error message for any unhandled exceptions. /// </summary> /// <param name="sender">The sender</param> /// <param name="e">Unhandled Exception EventArgs </param> private static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { try { ExceptionWindow window = new ExceptionWindow(); if (e.ExceptionObject.GetType() == typeof(GeneralApplicationException)) { GeneralApplicationException applicationException = e.ExceptionObject as GeneralApplicationException; if (applicationException != null) { window.Setup( applicationException.Error + Environment.NewLine + applicationException.Solution, e.ExceptionObject + "\n\n ---- \n\n" + applicationException.ActualException); } } else { window.Setup("An Unknown Error has occured.", e.ExceptionObject.ToString()); } window.ShowDialog(); } catch (Exception) { MessageBox.Show( "An Unknown Error has occured. \n\n Exception:" + e.ExceptionObject, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Show the Exception Window /// </summary> /// <param name="shortError"> /// The short error. /// </param> /// <param name="longError"> /// The long error. /// </param> public static void ShowExceptiowWindow(string shortError, string longError) { ExceptionWindow window = new ExceptionWindow(); window.Setup(shortError, longError); window.ShowDialog(); }
/// <summary> /// Get's HandBrakes version data from the CLI. /// </summary> public static void SetCliVersionData() { string line; // 0 = SVN Build / Version // 1 = Build Date // Get the SHA1 Hash of HandBrakeCLI byte[] hash; using (Stream stream = File.OpenRead(Path.Combine(Application.StartupPath, "HandBrakeCLI.exe"))) { hash = SHA1.Create().ComputeHash(stream); } string base64Hash = Convert.ToBase64String(hash); // Compare the hash with the last known hash. If it's the same, return. if (UserSettingService.GetUserSetting<string>(UserSettingConstants.CliExeHash) == base64Hash) { return; } // It's not the same, so start the CLI to get it's version data. Process cliProcess = new Process(); ProcessStartInfo handBrakeCli = new ProcessStartInfo("HandBrakeCLI.exe", " -u -v0") { UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true, CreateNoWindow = true }; cliProcess.StartInfo = handBrakeCli; try { cliProcess.Start(); // Retrieve standard output and report back to parent thread until the process is complete TextReader stdOutput = cliProcess.StandardError; while (!cliProcess.HasExited) { line = stdOutput.ReadLine() ?? string.Empty; Match m = Regex.Match(line, @"HandBrake ([svnM0-9.]*) \(([0-9]*)\)"); Match platform = Regex.Match(line, @"- ([A-Za-z0-9\s ]*) -"); if (m.Success) { string version = m.Groups[1].Success ? m.Groups[1].Value : string.Empty; string build = m.Groups[2].Success ? m.Groups[2].Value : string.Empty; int buildValue; int.TryParse(build, out buildValue); UserSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeBuild, buildValue); UserSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeVersion, version); } if (platform.Success) { UserSettingService.SetUserSetting(ASUserSettingConstants.HandBrakePlatform, platform.Value.Replace("-", string.Empty).Trim()); } if (cliProcess.TotalProcessorTime.Seconds > 10) // Don't wait longer than 10 seconds. { Process cli = Process.GetProcessById(cliProcess.Id); if (!cli.HasExited) { cli.Kill(); } } } UserSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeExeHash, base64Hash); } catch (Exception e) { UserSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeBuild, string.Empty); UserSettingService.SetUserSetting(ASUserSettingConstants.HandBrakePlatform, string.Empty); UserSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeVersion, string.Empty); UserSettingService.SetUserSetting(ASUserSettingConstants.HandBrakeExeHash, string.Empty); ExceptionWindow window = new ExceptionWindow(); window.Setup("Unable to Initialise HandBrake \nThis error is unrecoverable. Maybe try restarting.", e.ToString()); window.ShowDialog(); Application.Exit(); } }
/// <summary> /// Throw up an error message for any unhandled exceptions. /// </summary> /// <param name="sender">The sender</param> /// <param name="e">Unhandled Exception EventArgs </param> private static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { try { ExceptionWindow window = new ExceptionWindow(); window.Setup("An Unknown Error has occured.", e.ExceptionObject.ToString()); window.ShowDialog(); } catch (Exception) { MessageBox.Show( "An Unknown Error has occured. \n\n Exception:" + e.ExceptionObject, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } }