diff options
author | sr55 <[email protected]> | 2010-09-14 19:54:29 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2010-09-14 19:54:29 +0000 |
commit | 919590e39871a63b726ee47cd705b7754a469b91 (patch) | |
tree | ae712f31d71744705c4fa9acc38959af5a7ef53c /win | |
parent | 4043695d61478681fa2be0f19476321bf94cdcb3 (diff) |
WinGui:
- Log Exceptions out to the Log folder when they occur.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3528 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
5 files changed, 69 insertions, 29 deletions
diff --git a/win/C#/HandBrake.ApplicationServices/Functions/Main.cs b/win/C#/HandBrake.ApplicationServices/Functions/Main.cs index 8cc209e52..a8ebee394 100644 --- a/win/C#/HandBrake.ApplicationServices/Functions/Main.cs +++ b/win/C#/HandBrake.ApplicationServices/Functions/Main.cs @@ -22,21 +22,5 @@ namespace HandBrake.ApplicationServices.Functions {
return Process.GetProcessesByName("HandBrakeCLI");
}
-
- /// <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 exceptionWindow = new ExceptionWindow();
- exceptionWindow.Setup(shortError, longError);
- exceptionWindow.Show();
- }
}
}
\ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs index ee1673a2f..a8cd3cadc 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs @@ -23,9 +23,15 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
public class Encode : IEncode
{
+
#region Private Variables
/// <summary>
+ /// The Error Service
+ /// </summary>
+ protected IErrorService errorService;
+
+ /// <summary>
/// The Log Buffer
/// </summary>
private StringBuilder logBuffer;
@@ -61,6 +67,8 @@ namespace HandBrake.ApplicationServices.Services {
this.EncodeStarted += Encode_EncodeStarted;
GrowlCommunicator.Register();
+
+ this.errorService = new ErrorService();
}
#region Delegates and Event Handlers
@@ -214,7 +222,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- Main.ShowExceptiowWindow("It would appear that HandBrakeCLI has not started correctly." +
+ errorService.ShowError("It would appear that HandBrakeCLI has not started correctly." +
"You should take a look at the Activity log as it may indicate the reason why.\n\nDetailed Error Information: error occured in runCli()",
exc.ToString());
}
@@ -231,7 +239,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- Main.ShowExceptiowWindow("Unable to stop HandBrakeCLI. It may not be running.", exc.ToString());
+ errorService.ShowError("Unable to stop HandBrakeCLI. It may not be running.", exc.ToString());
}
if (this.EncodeEnded != null)
@@ -300,7 +308,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- Main.ShowExceptiowWindow("Unable to make a copy of the log file", exc.ToString());
+ errorService.ShowError("Unable to make a copy of the log file", exc.ToString());
}
}
@@ -336,7 +344,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- Main.ShowExceptiowWindow("Unable to close the log file wrtier", exc.ToString());
+ errorService.ShowError("Unable to close the log file wrtier", exc.ToString());
}
}
@@ -386,7 +394,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- Main.ShowExceptiowWindow("Unable to read log file", exc.ToString());
+ errorService.ShowError("Unable to read log file", exc.ToString());
}
}
}
@@ -420,7 +428,7 @@ namespace HandBrake.ApplicationServices.Services {
if (fileWriter != null)
fileWriter.Close();
- Main.ShowExceptiowWindow("Error", exc.ToString());
+ errorService.ShowError("Error", exc.ToString());
}
}
@@ -447,7 +455,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- Main.ShowExceptiowWindow("Unable to write log data...", exc.ToString());
+ errorService.ShowError("Unable to write log data...", exc.ToString());
}
}
}
@@ -483,7 +491,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- Main.ShowExceptiowWindow("An Unknown Error has occured", exc.ToString());
+ errorService.ShowError("An Unknown Error has occured", exc.ToString());
}
}
diff --git a/win/C#/HandBrake.ApplicationServices/Services/ErrorService.cs b/win/C#/HandBrake.ApplicationServices/Services/ErrorService.cs index 039cae727..a45cd113f 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/ErrorService.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/ErrorService.cs @@ -6,6 +6,9 @@ namespace HandBrake.ApplicationServices.Services
{
using System;
+ using System.IO;
+ using System.Threading;
+
using Interfaces;
using Views;
@@ -25,12 +28,44 @@ namespace HandBrake.ApplicationServices.Services /// </param>
public void ShowError(string shortError, string longError)
{
+ Thread newThread = new Thread(new ParameterizedThreadStart(WriteExceptionToFile));
+ newThread.Start(shortError + Environment.NewLine + longError);
+
ExceptionWindow window = new ExceptionWindow();
window.Setup(shortError, longError);
window.Show();
}
/// <summary>
+ /// Write Exceptions out to log files
+ /// </summary>
+ /// <param name="state">
+ /// The state.
+ /// </param>
+ public void WriteExceptionToFile(object state)
+ {
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ string file = Path.Combine(logDir, string.Format("Exception_{0}.txt", DateTime.Now.Ticks));
+
+ try
+ {
+ if (!File.Exists(file))
+ {
+ using (StreamWriter streamWriter = new StreamWriter(file))
+ {
+ streamWriter.WriteLine(state.ToString());
+ streamWriter.Close();
+ streamWriter.Dispose();
+ }
+ }
+ }
+ catch
+ {
+ return; // Game over. Stop digging.
+ }
+ }
+
+ /// <summary>
/// Show a Notice or Warning Message.
/// </summary>
/// <param name="notice">
diff --git a/win/C#/HandBrake.ApplicationServices/Services/Queue.cs b/win/C#/HandBrake.ApplicationServices/Services/Queue.cs index 7500dfec3..4c4beda08 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Queue.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Queue.cs @@ -288,7 +288,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- Main.ShowExceptiowWindow("Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", exc.ToString());
+ errorService.ShowError("Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", exc.ToString());
}
}
return false;
@@ -365,7 +365,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- Main.ShowExceptiowWindow("Unable to Start Queue", exc.ToString());
+ errorService.ShowError("Unable to Start Queue", exc.ToString());
}
}
}
diff --git a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs b/win/C#/HandBrake.ApplicationServices/Services/Scan.cs index 558dbb8a7..be150989b 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Scan.cs @@ -24,6 +24,11 @@ namespace HandBrake.ApplicationServices.Services /* Private Variables */
/// <summary>
+ /// The Error Service
+ /// </summary>
+ private IErrorService errorService;
+
+ /// <summary>
/// A Lock object
/// </summary>
private static readonly object locker = new object();
@@ -48,6 +53,14 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
private Process hbProc;
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ScanService"/> class.
+ /// </summary>
+ public ScanService()
+ {
+ this.errorService = new ErrorService();
+ }
+
/* Event Handlers */
/// <summary>
@@ -128,7 +141,7 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception ex)
{
- Main.ShowExceptiowWindow("Unable to kill HandBrakeCLI.exe \n" +
+ errorService.ShowError("Unable to kill HandBrakeCLI.exe \n" +
"You may need to manually kill HandBrakeCLI.exe using the Windows Task Manager if it does not close automatically" +
" within the next few minutes. ", ex.ToString());
}
@@ -200,11 +213,11 @@ namespace HandBrake.ApplicationServices.Services IsScanning = false;
if (this.ScanCompleted != null)
- this.ScanCompleted(this, new EventArgs());
+ this.ScanCompleted(this, new EventArgs());
}
catch (Exception exc)
{
- Main.ShowExceptiowWindow("frmMain.cs - scanProcess() Error", exc.ToString());
+ errorService.ShowError("frmMain.cs - scanProcess() Error", exc.ToString());
}
}
|