diff options
author | sr55 <[email protected]> | 2011-05-14 14:46:16 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-05-14 14:46:16 +0000 |
commit | 407aa2324adb84d97a61ddefde22178dff5c6063 (patch) | |
tree | 40ab418a4016065d5fc829f2935a690f6d5b3bac /win/CS | |
parent | e710acff9681ba85b7bddf65d001bc0444d4a69d (diff) |
WinGui:
- Removed the Question Alert box when adding an item to the queue where the destination folder does not exist. The folder is automatically created before encode anyway, so no point in asking the user pre-Encode.cs
- Better error handling in the encode service.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3979 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS')
7 files changed, 134 insertions, 65 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Exceptions/GeneralApplicationException.cs b/win/CS/HandBrake.ApplicationServices/Exceptions/GeneralApplicationException.cs new file mode 100644 index 000000000..1ee6608ba --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Exceptions/GeneralApplicationException.cs @@ -0,0 +1,49 @@ +/* GeneralApplicationException.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr/>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace HandBrake.ApplicationServices.Exceptions
+{
+ using System;
+
+ /// <summary>
+ /// The Encode Failure Exception
+ /// </summary>
+ public class GeneralApplicationException : Exception
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="GeneralApplicationException"/> class.
+ /// </summary>
+ /// <param name="error">
+ /// The error.
+ /// </param>
+ /// <param name="solution">
+ /// The solution.
+ /// </param>
+ /// <param name="innerException">
+ /// The inner Exception.
+ /// </param>
+ public GeneralApplicationException(string error, string solution, Exception innerException)
+ {
+ this.Error = error;
+ this.Solution = solution;
+ this.ActualException = innerException;
+ }
+
+ /// <summary>
+ /// Gets or sets FailureReason.
+ /// </summary>
+ public string Error { get; set; }
+
+ /// <summary>
+ /// Gets or sets Solution.
+ /// </summary>
+ public string Solution { get; set; }
+
+ /// <summary>
+ /// Gets or sets InnerException.
+ /// </summary>
+ public Exception ActualException { get; set; }
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index dd44f6d9c..f6a0122d9 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -84,6 +84,7 @@ </ItemGroup>
<ItemGroup>
<Compile Include="Converters\EnumToDescConverter.cs" />
+ <Compile Include="Exceptions\GeneralApplicationException.cs" />
<Compile Include="EventArgs\EncodeCompletedEventArgs.cs" />
<Compile Include="EventArgs\EncodeProgressEventArgs.cs" />
<Compile Include="EventArgs\QueueProgressEventArgs.cs" />
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs index 5787ab8a8..468f4597a 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs @@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Services using System.Windows.Forms;
using HandBrake.ApplicationServices.EventArgs;
+ using HandBrake.ApplicationServices.Exceptions;
using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
@@ -95,6 +96,12 @@ namespace HandBrake.ApplicationServices.Services /// Encode process has progressed
/// </summary>
public event EncodeProgessStatus EncodeStatusChanged;
+
+ /// <summary>
+ /// An event for a failed encode.
+ /// </summary>
+ public event EventHandler EncodeFailed;
+
#endregion
#region Properties
@@ -139,27 +146,22 @@ namespace HandBrake.ApplicationServices.Services {
QueueTask queueTask = encodeQueueTask;
- if (queueTask == null)
- {
- throw new ArgumentNullException("QueueTask was null");
- }
-
- if (IsEncoding)
+ if (this.IsEncoding)
{
throw new Exception("HandBrake is already encodeing.");
}
- IsEncoding = true;
+ this.IsEncoding = true;
if (enableLogging)
{
try
{
- SetupLogging(queueTask);
+ this.SetupLogging(queueTask);
}
catch (Exception)
{
- IsEncoding = false;
+ this.IsEncoding = false;
throw;
}
}
@@ -173,8 +175,15 @@ namespace HandBrake.ApplicationServices.Services string path = Directory.GetParent(queueTask.Destination).ToString();
if (!Directory.Exists(path))
{
- // TODO - Better handle a directoryNotFound exception.
- Directory.CreateDirectory(path);
+ try
+ {
+ Directory.CreateDirectory(path);
+ }
+ catch (Exception)
+ {
+ throw new Exception(
+ "Unable to create directory for the encoded output. Please verify the drive and path is correct.");
+ }
}
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
@@ -194,12 +203,12 @@ namespace HandBrake.ApplicationServices.Services if (enableLogging)
{
- this.HbProcess.ErrorDataReceived += HbProcErrorDataReceived;
+ this.HbProcess.ErrorDataReceived += this.HbProcErrorDataReceived;
this.HbProcess.BeginErrorReadLine();
}
- this.processId = HbProcess.Id;
- this.processHandle = HbProcess.Handle;
+ this.processId = this.HbProcess.Id;
+ this.processHandle = this.HbProcess.Handle;
// Set the process Priority
if (this.processId != -1)
@@ -233,12 +242,16 @@ namespace HandBrake.ApplicationServices.Services // Fire the Encode Started Event
if (this.EncodeStarted != null)
+ {
this.EncodeStarted(this, new EventArgs());
+ }
}
catch (Exception exc)
{
if (this.EncodeCompleted != null)
- this.EncodeCompleted(this, new EncodeCompletedEventArgs(false, exc, "An Error has occured in EncodeService.Run()"));
+ {
+ this.EncodeCompleted(this, new EncodeCompletedEventArgs(false, exc, "An Error occured when trying to encode this source. "));
+ }
}
}
@@ -275,12 +288,19 @@ namespace HandBrake.ApplicationServices.Services if (exc == null)
{
if (this.EncodeCompleted != null)
+ {
this.EncodeCompleted(this, new EncodeCompletedEventArgs(true, null, string.Empty));
+ }
}
else
{
if (this.EncodeCompleted != null)
- this.EncodeCompleted(this, new EncodeCompletedEventArgs(false, exc, "An Error has occured."));
+ {
+ this.EncodeCompleted(
+ this,
+ new EncodeCompletedEventArgs(
+ false, exc, "An Unknown Error has occured when trying to Stop this encode."));
+ }
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs index f2ca04c6d..fe3eb8549 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs @@ -10,6 +10,7 @@ namespace HandBrake.ApplicationServices.Services using System.Windows.Forms;
using HandBrake.ApplicationServices.EventArgs;
+ using HandBrake.ApplicationServices.Exceptions;
using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Services.Interfaces;
@@ -200,15 +201,18 @@ namespace HandBrake.ApplicationServices.Services if (!e.Successful)
{
this.Pause();
- MessageBox.Show(e.Exception + e.ErrorInformation);
+ throw new GeneralApplicationException(e.ErrorInformation, e.Exception.Message, e.Exception);
}
- // Post-Processing
- SendToApplication(this.QueueManager.LastProcessedJob.Destination);
-
// Handling Log Data
this.EncodeService.ProcessLogs(this.QueueManager.LastProcessedJob.Destination);
+ // Post-Processing
+ if (e.Successful)
+ {
+ SendToApplication(this.QueueManager.LastProcessedJob.Destination);
+ }
+
// Move onto the next job.
this.ProcessNextJob();
}
diff --git a/win/CS/HandBrake.ApplicationServices/Settings.StyleCop b/win/CS/HandBrake.ApplicationServices/Settings.StyleCop index c8383e569..5d3a523a0 100644 --- a/win/CS/HandBrake.ApplicationServices/Settings.StyleCop +++ b/win/CS/HandBrake.ApplicationServices/Settings.StyleCop @@ -1,9 +1,14 @@ <StyleCopSettings Version="105">
- <Parsers>
- <Parser ParserId="StyleCop.CSharp.CsParser">
- <ParserSettings>
- <BooleanProperty Name="AnalyzeDesignerFiles">False</BooleanProperty>
- </ParserSettings>
- </Parser>
- </Parsers>
+ <Analyzers>
+ <Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
+ <Rules>
+ <Rule Name="FileHeaderFileNameDocumentationMustMatchTypeName">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">False</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ </Analyzers>
</StyleCopSettings>
\ No newline at end of file diff --git a/win/CS/Program.cs b/win/CS/Program.cs index acdaf0266..132624b28 100644 --- a/win/CS/Program.cs +++ b/win/CS/Program.cs @@ -10,6 +10,7 @@ namespace Handbrake using System.IO;
using System.Windows.Forms;
+ using HandBrake.ApplicationServices.Exceptions;
using HandBrake.ApplicationServices.Services;
using Handbrake.Properties;
@@ -111,10 +112,24 @@ namespace Handbrake private static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
- {
+ {
ExceptionWindow window = new ExceptionWindow();
- window.Setup("An Unknown Error has occured.", e.ExceptionObject.ToString());
- window.ShowDialog();
+
+ if (e.ExceptionObject.GetType() == typeof(GeneralApplicationException))
+ {
+ GeneralApplicationException applicationException = e.ExceptionObject as GeneralApplicationException;
+ if (applicationException != null)
+ {
+ window.Setup(
+ applicationException.Error + Environment.NewLine + applicationException.Solution,
+ e.ExceptionObject + "\n\n ---- \n\n" + applicationException.ActualException);
+ }
+ }
+ else
+ {
+ window.Setup("An Unknown Error has occured.", e.ExceptionObject.ToString());
+ }
+ window.ShowDialog();
}
catch (Exception)
{
@@ -124,7 +139,6 @@ namespace Handbrake MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
-
}
public static int InstanceId;
diff --git a/win/CS/frmMain.cs b/win/CS/frmMain.cs index 5177f6983..2ff793c3a 100644 --- a/win/CS/frmMain.cs +++ b/win/CS/frmMain.cs @@ -598,6 +598,16 @@ namespace Handbrake private void BtnAddPreset_Click(object sender, EventArgs e)
{
+ if (this.selectedTitle == null)
+ {
+ MessageBox.Show(
+ "Please scan a source before trying to import a preset.",
+ "Error",
+ MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ return;
+ }
+
Form preset = new frmAddPreset(this, presetHandler);
if (preset.ShowDialog() == DialogResult.OK)
{
@@ -846,7 +856,6 @@ namespace Handbrake else
{
PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
-
Preset preset = new Preset
{
Name = parsed.PresetName,
@@ -1139,39 +1148,6 @@ namespace Handbrake return false;
}
- // Make sure the destination path exists.
- if (!Directory.Exists(Path.GetDirectoryName(jobDestination)))
- {
- if (showError)
- {
- DialogResult result =
- MessageBox.Show(
- string.Format("Destination Path does not exist.\nPath: {0}\n\n Would you like to create it now?", Path.GetDirectoryName(jobDestination)),
- "Warning",
- MessageBoxButtons.YesNo,
- MessageBoxIcon.Question);
-
- if (result == DialogResult.Yes)
- {
- // Make sure the path exists, attempt to create it if it doesn't
- string path = Directory.GetParent(jobDestination).ToString();
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
-
-
// Make sure we don't have a duplciate on the queue.
if (this.queueProcessor.QueueManager.CheckForDestinationPathDuplicates(jobDestination))
{
|