diff options
author | sr55 <[email protected]> | 2011-05-29 17:29:57 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-05-29 17:29:57 +0000 |
commit | e6f26f89f2d084a2adb40e4c41e46de5c7e5d2c5 (patch) | |
tree | 4a35b75dc8874a06d2f27806b5119364df58d3e1 /win/CS/HandBrake.ApplicationServices/Services | |
parent | 6521211f3657d5f4dc424ec871d2e0458bb6b287 (diff) |
WinGui: Some additional work on the libhb encode service to move it closer to a working service.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4010 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Services')
3 files changed, 118 insertions, 18 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs index ecaafeeb2..ca9558175 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs @@ -336,6 +336,33 @@ namespace HandBrake.ApplicationServices.Services.Base }
}
+ /// <summary>
+ /// Verify the Encode Destination path exists and if not, create it.
+ /// </summary>
+ /// <param name="task">
+ /// The task.
+ /// </param>
+ /// <exception cref="Exception">
+ /// If the creation fails, an exception is thrown.
+ /// </exception>
+ protected void VerifyEncodeDestinationPath(QueueTask task)
+ {
+ // Make sure the path exists, attempt to create it if it doesn't
+ string path = Directory.GetParent(task.Destination).ToString();
+ if (!Directory.Exists(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.");
+ }
+ }
+ }
+
#endregion
}
}
\ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs index 12f1e2760..26708434f 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs @@ -103,19 +103,7 @@ namespace HandBrake.ApplicationServices.Services }
// Make sure the path exists, attempt to create it if it doesn't
- string path = Directory.GetParent(queueTask.Destination).ToString();
- if (!Directory.Exists(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.");
- }
- }
+ this.VerifyEncodeDestinationPath(queueTask);
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
ProcessStartInfo cliStart = new ProcessStartInfo(handbrakeCLIPath, queueTask.Query)
diff --git a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs index 0cacea2ac..d8a951d51 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/LibEncode.cs @@ -6,7 +6,9 @@ namespace HandBrake.ApplicationServices.Services
{
using System;
+ using System.Diagnostics;
using System.Text;
+ using System.Threading;
using HandBrake.ApplicationServices.Functions;
using HandBrake.ApplicationServices.Model;
@@ -39,6 +41,11 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
private HandBrakeInstance instance;
+ /// <summary>
+ /// A flag to indicate if logging is enabled or not.
+ /// </summary>
+ private bool loggingEnabled;
+
#endregion
/// <summary>
@@ -68,8 +75,80 @@ namespace HandBrake.ApplicationServices.Services /// </param>
public void Start(QueueTask job, bool enableLogging)
{
- throw new NotImplementedException("This will be implemented later.");
+ throw new NotImplementedException("This Method has not been completed yet");
+
this.startTime = DateTime.Now;
+ this.loggingEnabled = enableLogging;
+
+ try
+ {
+ // Sanity Checking and Setup
+ if (this.IsEncoding)
+ {
+ throw new Exception("HandBrake is already encodeing.");
+ }
+
+ this.IsEncoding = true;
+
+ // Get an EncodeJob object for the Interop Library
+ EncodeJob encodeJob = InteropModelCreator.GetEncodeJob(job);
+
+ // Enable logging if required.
+ if (enableLogging)
+ {
+ try
+ {
+ this.SetupLogging(job);
+ }
+ catch (Exception)
+ {
+ this.IsEncoding = false;
+ throw;
+ }
+ }
+
+ // Prvent the system from sleeping if the user asks
+ if (Properties.Settings.Default.PreventSleep)
+ {
+ Win32.PreventSleep();
+ }
+
+ // Verify the Destination Path Exists, and if not, create it.
+ this.VerifyEncodeDestinationPath(job);
+
+ // Start the Encode
+ this.instance.StartEncode(encodeJob);
+
+ // Set the Process Priority
+ switch (Properties.Settings.Default.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;
+ }
+
+ // Fire the Encode Started Event
+ this.Invoke_encodeStarted(EventArgs.Empty);
+ }
+ catch (Exception exc)
+ {
+ this.Invoke_encodeCompleted(new EncodeCompletedEventArgs(false, exc, "An Error has occured in EncodeService.Run()"));
+ }
}
/// <summary>
@@ -119,9 +198,12 @@ namespace HandBrake.ApplicationServices.Services /// </param>
private void HandBrakeInstanceErrorLogged(object sender, MessageLoggedEventArgs e)
{
- lock (logLock)
+ if (this.loggingEnabled)
{
- this.LogBuffer.AppendLine(e.Message);
+ lock (logLock)
+ {
+ this.LogBuffer.AppendLine(e.Message);
+ }
}
}
@@ -136,9 +218,12 @@ namespace HandBrake.ApplicationServices.Services /// </param>
private void HandBrakeInstanceMessageLogged(object sender, MessageLoggedEventArgs e)
{
- lock (logLock)
+ if (this.loggingEnabled)
{
- this.LogBuffer.AppendLine(e.Message);
+ lock (logLock)
+ {
+ this.LogBuffer.AppendLine(e.Message);
+ }
}
}
|