OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 26 Sep 2010 16:10:16 +0000 (16:10 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 26 Sep 2010 16:10:16 +0000 (16:10 +0000)
- The scan log will no longer be written to disk if the log is over 100MB. An error message will be thrown.
- The encode will be terminated if the log file grows beyond 100MB and an error message will be thrown.
- Fixed an issue with the exception window not appearing when called from a worker thead.
- Put a limit on the number of exception windows that can appear during a session of HandBrake. (set to 30)

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

win/C#/HandBrake.ApplicationServices/Services/Encode.cs
win/C#/HandBrake.ApplicationServices/Services/Scan.cs
win/C#/HandBrake.Framework/Services/ErrorService.cs

index 95cc576..a0340c6 100644 (file)
@@ -242,7 +242,7 @@ namespace HandBrake.ApplicationServices.Services
         {\r
             try\r
             {\r
-                if (this.HbProcess != null) this.HbProcess.Kill();\r
+                if (this.HbProcess != null && !this.HbProcess.HasExited) this.HbProcess.Kill();\r
             }\r
             catch (Exception exc)\r
             {\r
@@ -464,6 +464,14 @@ namespace HandBrake.ApplicationServices.Services
                     if (fileWriter != null && fileWriter.BaseStream.CanWrite)\r
                     {\r
                         fileWriter.WriteLine(e.Data);\r
+\r
+                        // If the logging grows past 100MB, kill the encode and stop.\r
+                        if (fileWriter.BaseStream.Length > 100000000)\r
+                        {\r
+                            this.Stop();\r
+                            errorService.ShowError("The encode has been stopped. The log file has grown to over 100MB which indicates a serious problem has occured with the encode.",\r
+                                "Please check the encode log for an indication of what the problem is.");\r
+                        }\r
                     }            \r
                 }\r
                 catch (Exception exc)\r
index 45bd37a..c18fad3 100644 (file)
@@ -28,7 +28,7 @@ namespace HandBrake.ApplicationServices.Services
         /// <summary>\r
         /// The Error Service\r
         /// </summary>\r
-        private IErrorService errorService;\r
+        private readonly IErrorService errorService;\r
 \r
         /// <summary>\r
         /// A Lock object\r
@@ -138,7 +138,7 @@ namespace HandBrake.ApplicationServices.Services
         {\r
             try\r
             {\r
-                if (hbProc != null)\r
+                if (hbProc != null && !hbProc.HasExited)\r
                     hbProc.Kill();\r
             }\r
             catch (Exception ex)\r
@@ -205,12 +205,21 @@ namespace HandBrake.ApplicationServices.Services
                 this.SouceData = DVD.Parse(this.readData);\r
 \r
                 // Write the Buffer out to file.\r
-                StreamWriter scanLog = new StreamWriter(dvdInfoPath);\r
-                scanLog.WriteLine(Logging.CreateCliLogHeader(null));\r
-                scanLog.Write(this.readData.Buffer);\r
-                scanLog.Flush();\r
-                scanLog.Close();\r
-                logBuffer.AppendLine(this.readData.Buffer.ToString());\r
+                using (StreamWriter scanLog = new StreamWriter(dvdInfoPath))\r
+                {\r
+                    // Only write the log file to disk if it's less than 100MB.\r
+                    if (this.readData.Buffer.Length < 100000000)\r
+                    {\r
+                        scanLog.WriteLine(Logging.CreateCliLogHeader(null));\r
+                        scanLog.Write(this.readData.Buffer);\r
+                        logBuffer.AppendLine(this.readData.Buffer.ToString());\r
+                    }\r
+                    else\r
+                    {\r
+                        throw new Exception(\r
+                            "The Log file has not been written to disk as it has grown above the 100MB limit. This indicates there was a problem during the scan process.");\r
+                    }\r
+                }\r
 \r
                 IsScanning = false;\r
 \r
@@ -219,7 +228,12 @@ namespace HandBrake.ApplicationServices.Services
             }\r
             catch (Exception exc)\r
             {\r
-                errorService.ShowError("frmMain.cs - scanProcess() Error", exc.ToString());\r
+                this.Stop();\r
+\r
+                errorService.ShowError("An error has occured during the scan process.", exc.ToString());\r
+\r
+                if (this.ScanCompleted != null)\r
+                    this.ScanCompleted(this, new EventArgs());   \r
             }\r
         }\r
 \r
index 5444ea7..4137264 100644 (file)
@@ -8,6 +8,7 @@ namespace HandBrake.Framework.Services
     using System;\r
     using System.IO;\r
     using System.Threading;\r
+    using System.Windows.Forms;\r
 \r
     using HandBrake.Framework.Services.Interfaces;\r
     using HandBrake.Framework.Views;\r
@@ -17,6 +18,8 @@ namespace HandBrake.Framework.Services
     /// </summary>\r
     public class ErrorService : IErrorService\r
     {\r
+        private int exceptionCount;\r
+\r
         /// <summary>\r
         /// Show an Error Window\r
         /// </summary>\r
@@ -28,6 +31,8 @@ namespace HandBrake.Framework.Services
         /// </param>\r
         public void ShowError(string shortError, string longError)\r
         {\r
+            exceptionCount++;\r
+\r
             try\r
             {\r
                 Thread newThread = new Thread(new ParameterizedThreadStart(WriteExceptionToFile));\r
@@ -38,9 +43,19 @@ namespace HandBrake.Framework.Services
                 // Do Nothing\r
             }\r
 \r
+            if (exceptionCount > 30)\r
+            {\r
+                // If we are getting a large number of exceptions, just die out. We don't want to fill the users drive with a ton \r
+                // of exception files.\r
+                return;\r
+            }\r
+\r
             ExceptionWindow window = new ExceptionWindow();\r
             window.Setup(shortError, longError);\r
-            window.Show();\r
+\r
+            // This seems far from ideal so maybe have a think about a better way of doing this.\r
+            // This method can be called from UI and worker threads, so the ExcWindow needs to be called on the UI thread or on it's on UI thread.\r
+            Application.Run(window); \r
         }\r
 \r
         /// <summary>\r
@@ -67,6 +82,13 @@ namespace HandBrake.Framework.Services
         {\r
             try\r
             {\r
+                if (exceptionCount > 30)\r
+                {\r
+                    // If we are getting a large number of exceptions, just die out. We don't want to fill the users drive with a ton \r
+                    // of exception files.\r
+                    return;\r
+                }\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
@@ -75,8 +97,6 @@ namespace HandBrake.Framework.Services
                     using (StreamWriter streamWriter = new StreamWriter(file))\r
                     {\r
                         streamWriter.WriteLine(state.ToString());\r
-                        streamWriter.Close();\r
-                        streamWriter.Dispose();\r
                     }\r
                 }\r
             }\r