OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 15 Sep 2010 18:12:11 +0000 (18:12 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 15 Sep 2010 18:12:11 +0000 (18:12 +0000)
- Some changes to the way logging / exceptions are handled. This may fix an intermittent issue that causes a large number of exception windows to appear.

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

win/C#/HandBrake.ApplicationServices/Services/Encode.cs

index a8cd3ca..d922b66 100644 (file)
@@ -23,7 +23,6 @@ namespace HandBrake.ApplicationServices.Services
     /// </summary>\r
     public class Encode : IEncode\r
     {\r
-\r
         #region Private Variables\r
 \r
         /// <summary>\r
@@ -123,7 +122,14 @@ namespace HandBrake.ApplicationServices.Services
             {\r
                 if (this.IsEncoding == false)\r
                 {\r
-                    ReadFile(); // Read the last log file back in if it exists\r
+                    try\r
+                    {\r
+                        ReadFile(); // Read the last log file back in if it exists\r
+                    }\r
+                    catch (Exception exc)\r
+                    {\r
+                        return exc.ToString();\r
+                    }\r
                 }\r
 \r
                 return string.IsNullOrEmpty(this.logBuffer.ToString()) ? "No log data available..." : this.logBuffer.ToString();\r
@@ -365,10 +371,6 @@ namespace HandBrake.ApplicationServices.Services
 \r
                 try\r
                 {\r
-                    // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.\r
-                    if (File.Exists(logFile2))\r
-                        File.Delete(logFile2);\r
-\r
                     // Copy the log file.\r
                     if (File.Exists(logFile))\r
                         File.Copy(logFile, logFile2, true);\r
@@ -377,24 +379,25 @@ namespace HandBrake.ApplicationServices.Services
 \r
                     // Start the Reader\r
                     // Only use text which continues on from the last read line\r
-                    StreamReader sr = new StreamReader(logFile2);\r
-                    string line;\r
-                    int i = 1;\r
-                    while ((line = sr.ReadLine()) != null)\r
+                    using (StreamReader sr = new StreamReader(logFile2))\r
                     {\r
-                        if (i > logFilePosition)\r
+                        string line;\r
+                        int i = 1;\r
+                        while ((line = sr.ReadLine()) != null)\r
                         {\r
-                            logBuffer.AppendLine(line);\r
-                            logFilePosition++;\r
+                            if (i > logFilePosition)\r
+                            {\r
+                                logBuffer.AppendLine(line);\r
+                                logFilePosition++;\r
+                            }\r
+                            i++;\r
                         }\r
-                        i++;\r
+                        sr.Close();\r
                     }\r
-                    sr.Close();\r
-                    sr.Dispose();\r
                 }\r
                 catch (Exception exc)\r
                 {\r
-                    errorService.ShowError("Unable to read log file", exc.ToString());\r
+                    throw new Exception("Unable to read log file" + Environment.NewLine + exc);\r
                 }\r
             }\r
         }\r
@@ -428,6 +431,7 @@ namespace HandBrake.ApplicationServices.Services
             {\r
                 if (fileWriter != null)\r
                     fileWriter.Close();\r
+\r
                 errorService.ShowError("Error", exc.ToString());\r
             }\r
         }\r
@@ -455,7 +459,7 @@ namespace HandBrake.ApplicationServices.Services
                 }\r
                 catch (Exception exc)\r
                 {\r
-                    errorService.ShowError("Unable to write log data...", exc.ToString());\r
+                   // errorService.ShowError("Unable to write log data...", exc.ToString());\r
                 }\r
             }\r
         }\r
@@ -491,7 +495,7 @@ namespace HandBrake.ApplicationServices.Services
             }\r
             catch (Exception exc)\r
             {\r
-                errorService.ShowError("An Unknown Error has occured", exc.ToString());\r
+                EncodeOnEncodeProgress(null, 0, 0, 0, 0, 0, "Unknown, status not available..");\r
             }\r
         }\r
 \r