- 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
{\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
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
/// <summary>\r
/// The Error Service\r
/// </summary>\r
- private IErrorService errorService;\r
+ private readonly IErrorService errorService;\r
\r
/// <summary>\r
/// A Lock object\r
{\r
try\r
{\r
- if (hbProc != null)\r
+ if (hbProc != null && !hbProc.HasExited)\r
hbProc.Kill();\r
}\r
catch (Exception ex)\r
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
}\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
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
/// </summary>\r
public class ErrorService : IErrorService\r
{\r
+ private int exceptionCount;\r
+\r
/// <summary>\r
/// Show an Error Window\r
/// </summary>\r
/// </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
// 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
{\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
using (StreamWriter streamWriter = new StreamWriter(file))\r
{\r
streamWriter.WriteLine(state.ToString());\r
- streamWriter.Close();\r
- streamWriter.Dispose();\r
}\r
}\r
}\r