OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Tue, 14 Sep 2010 19:54:29 +0000 (19:54 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Tue, 14 Sep 2010 19:54:29 +0000 (19:54 +0000)
- Log Exceptions out to the Log folder when they occur.

git-svn-id: svn://localhost/HandBrake/trunk@3528 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/C#/HandBrake.ApplicationServices/Functions/Main.cs
win/C#/HandBrake.ApplicationServices/Services/Encode.cs
win/C#/HandBrake.ApplicationServices/Services/ErrorService.cs
win/C#/HandBrake.ApplicationServices/Services/Queue.cs
win/C#/HandBrake.ApplicationServices/Services/Scan.cs

index 8cc209e..a8ebee3 100644 (file)
@@ -22,21 +22,5 @@ namespace HandBrake.ApplicationServices.Functions
         {\r
             return Process.GetProcessesByName("HandBrakeCLI");\r
         }\r
-\r
-        /// <summary>\r
-        /// Show the Exception Window\r
-        /// </summary>\r
-        /// <param name="shortError">\r
-        /// The short error.\r
-        /// </param>\r
-        /// <param name="longError">\r
-        /// The long error.\r
-        /// </param>\r
-        public static void ShowExceptiowWindow(string shortError, string longError)\r
-        {\r
-            ExceptionWindow exceptionWindow = new ExceptionWindow();\r
-            exceptionWindow.Setup(shortError, longError);\r
-            exceptionWindow.Show();\r
-        }\r
     }\r
 }
\ No newline at end of file
index ee1673a..a8cd3ca 100644 (file)
@@ -23,9 +23,15 @@ namespace HandBrake.ApplicationServices.Services
     /// </summary>\r
     public class Encode : IEncode\r
     {\r
+\r
         #region Private Variables\r
 \r
         /// <summary>\r
+        /// The Error Service\r
+        /// </summary>\r
+        protected IErrorService errorService;\r
+\r
+        /// <summary>\r
         /// The Log Buffer\r
         /// </summary>\r
         private StringBuilder logBuffer;\r
@@ -61,6 +67,8 @@ namespace HandBrake.ApplicationServices.Services
         {\r
             this.EncodeStarted += Encode_EncodeStarted;\r
             GrowlCommunicator.Register();\r
+\r
+            this.errorService = new ErrorService();\r
         }\r
 \r
         #region Delegates and Event Handlers\r
@@ -214,7 +222,7 @@ namespace HandBrake.ApplicationServices.Services
             }\r
             catch (Exception exc)\r
             {\r
-                Main.ShowExceptiowWindow("It would appear that HandBrakeCLI has not started correctly." +\r
+                errorService.ShowError("It would appear that HandBrakeCLI has not started correctly." +\r
                 "You should take a look at the Activity log as it may indicate the reason why.\n\nDetailed Error Information: error occured in runCli()",\r
                 exc.ToString());\r
             }\r
@@ -231,7 +239,7 @@ namespace HandBrake.ApplicationServices.Services
             }\r
             catch (Exception exc)\r
             {\r
-                Main.ShowExceptiowWindow("Unable to stop HandBrakeCLI. It may not be running.", exc.ToString());\r
+                errorService.ShowError("Unable to stop HandBrakeCLI. It may not be running.", exc.ToString());\r
             }\r
 \r
             if (this.EncodeEnded != null)\r
@@ -300,7 +308,7 @@ namespace HandBrake.ApplicationServices.Services
             }\r
             catch (Exception exc)\r
             {\r
-                Main.ShowExceptiowWindow("Unable to make a copy of the log file", exc.ToString());\r
+                errorService.ShowError("Unable to make a copy of the log file", exc.ToString());\r
             }\r
         }\r
 \r
@@ -336,7 +344,7 @@ namespace HandBrake.ApplicationServices.Services
             }\r
             catch (Exception exc)\r
             {\r
-                Main.ShowExceptiowWindow("Unable to close the log file wrtier", exc.ToString());\r
+                errorService.ShowError("Unable to close the log file wrtier", exc.ToString());\r
             }\r
         }\r
 \r
@@ -386,7 +394,7 @@ namespace HandBrake.ApplicationServices.Services
                 }\r
                 catch (Exception exc)\r
                 {\r
-                    Main.ShowExceptiowWindow("Unable to read log file", exc.ToString());\r
+                    errorService.ShowError("Unable to read log file", exc.ToString());\r
                 }\r
             }\r
         }\r
@@ -420,7 +428,7 @@ namespace HandBrake.ApplicationServices.Services
             {\r
                 if (fileWriter != null)\r
                     fileWriter.Close();\r
-                Main.ShowExceptiowWindow("Error", exc.ToString());\r
+                errorService.ShowError("Error", exc.ToString());\r
             }\r
         }\r
 \r
@@ -447,7 +455,7 @@ namespace HandBrake.ApplicationServices.Services
                 }\r
                 catch (Exception exc)\r
                 {\r
-                    Main.ShowExceptiowWindow("Unable to write log data...", exc.ToString());\r
+                    errorService.ShowError("Unable to write log data...", exc.ToString());\r
                 }\r
             }\r
         }\r
@@ -483,7 +491,7 @@ namespace HandBrake.ApplicationServices.Services
             }\r
             catch (Exception exc)\r
             {\r
-                Main.ShowExceptiowWindow("An Unknown Error has occured", exc.ToString());\r
+                errorService.ShowError("An Unknown Error has occured", exc.ToString());\r
             }\r
         }\r
 \r
index 039cae7..a45cd11 100644 (file)
@@ -6,6 +6,9 @@
 namespace HandBrake.ApplicationServices.Services\r
 {\r
     using System;\r
+    using System.IO;\r
+    using System.Threading;\r
+\r
     using Interfaces;\r
     using Views;\r
 \r
@@ -25,12 +28,44 @@ namespace HandBrake.ApplicationServices.Services
         /// </param>\r
         public void ShowError(string shortError, string longError)\r
         {\r
+            Thread newThread = new Thread(new ParameterizedThreadStart(WriteExceptionToFile));\r
+            newThread.Start(shortError + Environment.NewLine + longError);\r
+\r
             ExceptionWindow window = new ExceptionWindow();\r
             window.Setup(shortError, longError);\r
             window.Show();\r
         }\r
 \r
         /// <summary>\r
+        /// Write Exceptions out to log files\r
+        /// </summary>\r
+        /// <param name="state">\r
+        /// The state.\r
+        /// </param>\r
+        public void WriteExceptionToFile(object state)\r
+        {\r
+            string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+            string file = Path.Combine(logDir, string.Format("Exception_{0}.txt", DateTime.Now.Ticks));\r
+\r
+            try\r
+            {\r
+                if (!File.Exists(file))\r
+                {\r
+                    using (StreamWriter streamWriter = new StreamWriter(file))\r
+                    {\r
+                        streamWriter.WriteLine(state.ToString());\r
+                        streamWriter.Close();\r
+                        streamWriter.Dispose();\r
+                    }\r
+                }\r
+            }\r
+            catch\r
+            {\r
+                return; // Game over. Stop digging.\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
         /// Show a Notice or Warning Message.\r
         /// </summary>\r
         /// <param name="notice">\r
index 7500dfe..4c4beda 100644 (file)
@@ -288,7 +288,7 @@ namespace HandBrake.ApplicationServices.Services
                 }\r
                 catch (Exception exc)\r
                 {\r
-                    Main.ShowExceptiowWindow("Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", exc.ToString());\r
+                    errorService.ShowError("Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", exc.ToString());\r
                 }\r
             }\r
             return false;\r
@@ -365,7 +365,7 @@ namespace HandBrake.ApplicationServices.Services
                     }\r
                     catch (Exception exc)\r
                     {\r
-                        Main.ShowExceptiowWindow("Unable to Start Queue", exc.ToString());\r
+                        errorService.ShowError("Unable to Start Queue", exc.ToString());\r
                     }\r
                 }\r
             }\r
index 558dbb8..be15098 100644 (file)
@@ -24,6 +24,11 @@ namespace HandBrake.ApplicationServices.Services
         /* Private Variables */\r
 \r
         /// <summary>\r
+        /// The Error Service\r
+        /// </summary>\r
+        private IErrorService errorService;\r
+\r
+        /// <summary>\r
         /// A Lock object\r
         /// </summary>\r
         private static readonly object locker = new object();\r
@@ -48,6 +53,14 @@ namespace HandBrake.ApplicationServices.Services
         /// </summary>\r
         private Process hbProc;\r
 \r
+        /// <summary>\r
+        /// Initializes a new instance of the <see cref="ScanService"/> class.\r
+        /// </summary>\r
+        public ScanService()\r
+        {\r
+            this.errorService = new ErrorService();\r
+        }\r
+\r
         /* Event Handlers */\r
 \r
         /// <summary>\r
@@ -128,7 +141,7 @@ namespace HandBrake.ApplicationServices.Services
             }\r
             catch (Exception ex)\r
             {\r
-                Main.ShowExceptiowWindow("Unable to kill HandBrakeCLI.exe \n" +\r
+                errorService.ShowError("Unable to kill HandBrakeCLI.exe \n" +\r
                 "You may need to manually kill HandBrakeCLI.exe using the Windows Task Manager if it does not close automatically" + \r
                 " within the next few minutes. ", ex.ToString());\r
             }\r
@@ -200,11 +213,11 @@ namespace HandBrake.ApplicationServices.Services
                 IsScanning = false;\r
 \r
                 if (this.ScanCompleted != null)\r
-                    this.ScanCompleted(this, new EventArgs());\r
+                    this.ScanCompleted(this, new EventArgs()); \r
             }\r
             catch (Exception exc)\r
             {\r
-                Main.ShowExceptiowWindow("frmMain.cs - scanProcess() Error", exc.ToString());\r
+                errorService.ShowError("frmMain.cs - scanProcess() Error", exc.ToString());\r
             }\r
         }\r
 \r