summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs10
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs55
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs32
-rw-r--r--win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs29
4 files changed, 74 insertions, 52 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs
index 9c5c9f7bd..9b817069b 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs
@@ -228,9 +228,9 @@ namespace HandBrake.ApplicationServices.Services.Encode
tempLogFile, Path.Combine(configuration.SaveLogCopyDirectory, encodeLogFile));
}
}
- catch (Exception)
+ catch (Exception exc)
{
- // This exception doesn't warrent user interaction, but it should be logged (TODO)
+ Debug.WriteLine(exc); // This exception doesn't warrent user interaction, but it should be logged
}
}
@@ -375,7 +375,7 @@ namespace HandBrake.ApplicationServices.Services.Encode
/// </param>
protected void ProcessLogMessage(string message)
{
- if (!String.IsNullOrEmpty(message))
+ if (!string.IsNullOrEmpty(message))
{
try
{
@@ -394,9 +394,9 @@ namespace HandBrake.ApplicationServices.Services.Encode
}
}
}
- catch (Exception)
+ catch (Exception exc)
{
- // Do Nothing.
+ Debug.WriteLine(exc); // This exception doesn't warrent user interaction, but it should be logged
}
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs
index 82bb4b1a7..483b88e7e 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs
@@ -225,43 +225,44 @@ namespace HandBrake.ApplicationServices.Services.Encode
FramerateNumerator = title.FramerateNumerator,
};
- // TODO fix this tempory hack to pass in the required title information into the factory.
try
{
ServiceLogMessage("Starting Encode ...");
instance.StartEncode(encodeJob, scannedTitle);
+
+ // Fire the Encode Started Event
+ this.InvokeEncodeStarted(System.EventArgs.Empty);
+
+ // Set the Process Priority
+ switch (job.Configuration.ProcessPriority)
+ {
+ case "Realtime":
+ Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
+ break;
+ case "High":
+ Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
+ break;
+ case "Above Normal":
+ Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;
+ break;
+ case "Normal":
+ Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal;
+ break;
+ case "Low":
+ Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle;
+ break;
+ default:
+ Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;
+ break;
+ }
}
catch (Exception exc)
{
+ this.IsEncoding = false;
+
ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc);
this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", job.Task.Source));
}
-
- // Fire the Encode Started Event
- this.InvokeEncodeStarted(System.EventArgs.Empty);
-
- // Set the Process Priority
- switch (job.Configuration.ProcessPriority)
- {
- case "Realtime":
- Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
- break;
- case "High":
- Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
- break;
- case "Above Normal":
- Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal;
- break;
- case "Normal":
- Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal;
- break;
- case "Low":
- Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle;
- break;
- default:
- Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;
- break;
- }
}
#region HandBrakeInstance Event Handlers.
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs b/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs
index bc9304f8e..d17de41b1 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs
@@ -11,6 +11,7 @@ namespace HandBrake.ApplicationServices.Services.Scan
{
using System;
using System.Collections.Generic;
+ using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows.Media.Imaging;
@@ -194,9 +195,9 @@ namespace HandBrake.ApplicationServices.Services.Scan
File.Delete(this.dvdInfoPath);
}
}
- catch (Exception)
+ catch (Exception exc)
{
- // Do nothing.
+ Debug.WriteLine(exc);
}
if (!Directory.Exists(Path.GetDirectoryName(this.dvdInfoPath)))
@@ -223,11 +224,12 @@ namespace HandBrake.ApplicationServices.Services.Scan
/// </summary>
public void Stop()
{
- ServiceLogMessage("Stopping Scan.");
- this.instance.StopScan();
-
try
{
+ ServiceLogMessage("Stopping Scan.");
+ this.IsScanning = false;
+ this.instance.StopScan();
+
if (this.scanLog != null)
{
this.scanLog.Close();
@@ -307,17 +309,16 @@ namespace HandBrake.ApplicationServices.Services.Scan
this.currentSourceScanPath = source;
this.IsScanning = true;
- if (this.ScanStared != null)
- this.ScanStared(this, System.EventArgs.Empty);
- TimeSpan minDuration =
- TimeSpan.FromSeconds(
- configuraiton.MinScanDuration);
+ TimeSpan minDuration = TimeSpan.FromSeconds(configuraiton.MinScanDuration);
HandBrakeUtils.SetDvdNav(!configuraiton.IsDvdNavDisabled);
this.ServiceLogMessage("Starting Scan ...");
this.instance.StartScan(sourcePath.ToString(), previewCount, minDuration, title != 0 ? title : 0);
+
+ if (this.ScanStared != null)
+ this.ScanStared(this, System.EventArgs.Empty);
}
catch (Exception exc)
{
@@ -343,7 +344,7 @@ namespace HandBrake.ApplicationServices.Services.Scan
/// </param>
private void InstanceScanCompleted(object sender, System.EventArgs e)
{
- this.ServiceLogMessage("Starting Completed ...");
+ this.ServiceLogMessage("Scan Finished ...");
// Write the log file out before we start processing incase we crash.
try
@@ -353,9 +354,9 @@ namespace HandBrake.ApplicationServices.Services.Scan
this.scanLog.Flush();
}
}
- catch (Exception)
+ catch (Exception exc)
{
- // Do Nothing.
+ Debug.WriteLine(exc);
}
HandBrakeUtils.MessageLogged -= this.HandBrakeInstanceMessageLogged;
@@ -369,7 +370,10 @@ namespace HandBrake.ApplicationServices.Services.Scan
}
// Process into internal structures.
- this.SouceData = new Source { Titles = ConvertTitles(this.instance.Titles, this.instance.FeatureTitle), ScanPath = path };
+ if (this.instance != null && this.instance.Titles != null)
+ {
+ this.SouceData = new Source { Titles = ConvertTitles(this.instance.Titles, this.instance.FeatureTitle), ScanPath = path };
+ }
this.IsScanning = false;
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs
index 6920295cb..906781835 100644
--- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs
+++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs
@@ -207,7 +207,14 @@ namespace HandBrake.Interop
// Lambda notation used to make sure we can view any JIT exceptions the method throws
this.scanPollTimer.Elapsed += (o, e) =>
{
- this.PollScanProgress();
+ try
+ {
+ this.PollScanProgress();
+ }
+ catch (Exception exc)
+ {
+ Debug.WriteLine(exc);
+ }
};
this.scanPollTimer.Start();
}
@@ -215,6 +222,7 @@ namespace HandBrake.Interop
/// <summary>
/// Stops an ongoing scan.
/// </summary>
+ [HandleProcessCorruptedStateExceptions]
public void StopScan()
{
HBFunctions.hb_scan_stop(this.hbHandle);
@@ -357,7 +365,14 @@ namespace HandBrake.Interop
this.encodePollTimer.Elapsed += (o, e) =>
{
- this.PollEncodeProgress();
+ try
+ {
+ this.PollEncodeProgress();
+ }
+ catch (Exception exc)
+ {
+ Debug.WriteLine(exc);
+ }
};
this.encodePollTimer.Start();
}
@@ -442,13 +457,14 @@ namespace HandBrake.Interop
/// <summary>
/// Checks the status of the ongoing scan.
/// </summary>
+ [HandleProcessCorruptedStateExceptions]
private void PollScanProgress()
{
IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);
string statusJson = Marshal.PtrToStringAnsi(json);
JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);
- if (state.State == NativeConstants.HB_STATE_SCANNING)
+ if (state != null && state.State == NativeConstants.HB_STATE_SCANNING)
{
if (this.ScanProgress != null)
{
@@ -462,7 +478,7 @@ namespace HandBrake.Interop
});
}
}
- else if (state.State == NativeConstants.HB_STATE_SCANDONE)
+ else if (state != null && state.State == NativeConstants.HB_STATE_SCANDONE)
{
this.titles = new List<Title>();
@@ -495,13 +511,14 @@ namespace HandBrake.Interop
/// <summary>
/// Checks the status of the ongoing encode.
/// </summary>
+ [HandleProcessCorruptedStateExceptions]
private void PollEncodeProgress()
{
IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);
string statusJson = Marshal.PtrToStringAnsi(json);
JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);
- if (state.State == NativeConstants.HB_STATE_WORKING)
+ if (state != null && state.State == NativeConstants.HB_STATE_WORKING)
{
if (this.EncodeProgress != null)
{
@@ -517,7 +534,7 @@ namespace HandBrake.Interop
this.EncodeProgress(this, progressEventArgs);
}
}
- else if (state.State == NativeConstants.HB_STATE_WORKDONE)
+ else if (state != null && state.State == NativeConstants.HB_STATE_WORKDONE)
{
this.encodePollTimer.Stop();