diff options
author | sr55 <[email protected]> | 2010-09-26 16:10:16 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2010-09-26 16:10:16 +0000 |
commit | 944fe868810ac0438ae97b1ade8c7cff2de05192 (patch) | |
tree | 886d04c858ea026d938b83c8b6fe0ba1e5af262d /win | |
parent | 1bca5338bb277f7351c67c890fc8fbc6b4fdbc71 (diff) |
WinGui:
- 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://svn.handbrake.fr/HandBrake/trunk@3554 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
-rw-r--r-- | win/C#/HandBrake.ApplicationServices/Services/Encode.cs | 10 | ||||
-rw-r--r-- | win/C#/HandBrake.ApplicationServices/Services/Scan.cs | 32 | ||||
-rw-r--r-- | win/C#/HandBrake.Framework/Services/ErrorService.cs | 26 |
3 files changed, 55 insertions, 13 deletions
diff --git a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs index 95cc57676..a0340c656 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs @@ -242,7 +242,7 @@ namespace HandBrake.ApplicationServices.Services {
try
{
- if (this.HbProcess != null) this.HbProcess.Kill();
+ if (this.HbProcess != null && !this.HbProcess.HasExited) this.HbProcess.Kill();
}
catch (Exception exc)
{
@@ -464,6 +464,14 @@ namespace HandBrake.ApplicationServices.Services if (fileWriter != null && fileWriter.BaseStream.CanWrite)
{
fileWriter.WriteLine(e.Data);
+
+ // If the logging grows past 100MB, kill the encode and stop.
+ if (fileWriter.BaseStream.Length > 100000000)
+ {
+ this.Stop();
+ 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.",
+ "Please check the encode log for an indication of what the problem is.");
+ }
}
}
catch (Exception exc)
diff --git a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs b/win/C#/HandBrake.ApplicationServices/Services/Scan.cs index 45bd37a90..c18fad3d8 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Scan.cs @@ -28,7 +28,7 @@ namespace HandBrake.ApplicationServices.Services /// <summary>
/// The Error Service
/// </summary>
- private IErrorService errorService;
+ private readonly IErrorService errorService;
/// <summary>
/// A Lock object
@@ -138,7 +138,7 @@ namespace HandBrake.ApplicationServices.Services {
try
{
- if (hbProc != null)
+ if (hbProc != null && !hbProc.HasExited)
hbProc.Kill();
}
catch (Exception ex)
@@ -205,12 +205,21 @@ namespace HandBrake.ApplicationServices.Services this.SouceData = DVD.Parse(this.readData);
// Write the Buffer out to file.
- StreamWriter scanLog = new StreamWriter(dvdInfoPath);
- scanLog.WriteLine(Logging.CreateCliLogHeader(null));
- scanLog.Write(this.readData.Buffer);
- scanLog.Flush();
- scanLog.Close();
- logBuffer.AppendLine(this.readData.Buffer.ToString());
+ using (StreamWriter scanLog = new StreamWriter(dvdInfoPath))
+ {
+ // Only write the log file to disk if it's less than 100MB.
+ if (this.readData.Buffer.Length < 100000000)
+ {
+ scanLog.WriteLine(Logging.CreateCliLogHeader(null));
+ scanLog.Write(this.readData.Buffer);
+ logBuffer.AppendLine(this.readData.Buffer.ToString());
+ }
+ else
+ {
+ throw new Exception(
+ "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.");
+ }
+ }
IsScanning = false;
@@ -219,7 +228,12 @@ namespace HandBrake.ApplicationServices.Services }
catch (Exception exc)
{
- errorService.ShowError("frmMain.cs - scanProcess() Error", exc.ToString());
+ this.Stop();
+
+ errorService.ShowError("An error has occured during the scan process.", exc.ToString());
+
+ if (this.ScanCompleted != null)
+ this.ScanCompleted(this, new EventArgs());
}
}
diff --git a/win/C#/HandBrake.Framework/Services/ErrorService.cs b/win/C#/HandBrake.Framework/Services/ErrorService.cs index 5444ea7bc..41372648d 100644 --- a/win/C#/HandBrake.Framework/Services/ErrorService.cs +++ b/win/C#/HandBrake.Framework/Services/ErrorService.cs @@ -8,6 +8,7 @@ namespace HandBrake.Framework.Services using System;
using System.IO;
using System.Threading;
+ using System.Windows.Forms;
using HandBrake.Framework.Services.Interfaces;
using HandBrake.Framework.Views;
@@ -17,6 +18,8 @@ namespace HandBrake.Framework.Services /// </summary>
public class ErrorService : IErrorService
{
+ private int exceptionCount;
+
/// <summary>
/// Show an Error Window
/// </summary>
@@ -28,6 +31,8 @@ namespace HandBrake.Framework.Services /// </param>
public void ShowError(string shortError, string longError)
{
+ exceptionCount++;
+
try
{
Thread newThread = new Thread(new ParameterizedThreadStart(WriteExceptionToFile));
@@ -38,9 +43,19 @@ namespace HandBrake.Framework.Services // Do Nothing
}
+ if (exceptionCount > 30)
+ {
+ // If we are getting a large number of exceptions, just die out. We don't want to fill the users drive with a ton
+ // of exception files.
+ return;
+ }
+
ExceptionWindow window = new ExceptionWindow();
window.Setup(shortError, longError);
- window.Show();
+
+ // This seems far from ideal so maybe have a think about a better way of doing this.
+ // 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.
+ Application.Run(window);
}
/// <summary>
@@ -67,6 +82,13 @@ namespace HandBrake.Framework.Services {
try
{
+ if (exceptionCount > 30)
+ {
+ // If we are getting a large number of exceptions, just die out. We don't want to fill the users drive with a ton
+ // of exception files.
+ return;
+ }
+
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
string file = Path.Combine(logDir, string.Format("Exception_{0}.txt", DateTime.Now.Ticks));
@@ -75,8 +97,6 @@ namespace HandBrake.Framework.Services using (StreamWriter streamWriter = new StreamWriter(file))
{
streamWriter.WriteLine(state.ToString());
- streamWriter.Close();
- streamWriter.Dispose();
}
}
}
|