summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2015-01-31 15:19:14 +0000
committersr55 <[email protected]>2015-01-31 15:19:14 +0000
commit6d57e42b6b2cc38cf256f2970b23b94121e49479 (patch)
tree6841b6c50f50b6ac34bfa9dba954f959f030b480 /win/CS/HandBrake.ApplicationServices/Services
parenta4416e99f06e31e1da8767d071e882f32c5a4e67 (diff)
WinGui: Remove a bunch of CLI handling code.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6840 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Services')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs37
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs332
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs11
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs21
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs9
5 files changed, 25 insertions, 385 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs
index 8737ba64f..9c5c9f7bd 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeBase.cs
@@ -10,7 +10,6 @@
namespace HandBrake.ApplicationServices.Services.Encode
{
using System;
- using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@@ -21,7 +20,6 @@ namespace HandBrake.ApplicationServices.Services.Encode
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Services.Encode.EventArgs;
using HandBrake.ApplicationServices.Services.Encode.Interfaces;
- using HandBrake.ApplicationServices.Services.Encode.Model;
using HandBrake.ApplicationServices.Utilities;
/// <summary>
@@ -59,19 +57,19 @@ namespace HandBrake.ApplicationServices.Services.Encode
public EncodeBase()
{
this.logBuffer = new StringBuilder();
- this.header = GeneralUtilities.CreateCliLogHeader();
+ this.header = GeneralUtilities.CreateLogHeader();
this.LogIndex = 0;
}
#region Events
/// <summary>
- /// Fires when a new CLI QueueTask starts
+ /// Fires when a new QueueTask starts
/// </summary>
public event EventHandler EncodeStarted;
/// <summary>
- /// Fires when a CLI QueueTask finishes.
+ /// Fires when a QueueTask finishes.
/// </summary>
public event EncodeCompletedStatus EncodeCompleted;
@@ -83,6 +81,7 @@ namespace HandBrake.ApplicationServices.Services.Encode
#endregion
#region Properties
+
/// <summary>
/// Gets or sets a value indicating whether IsEncoding.
/// </summary>
@@ -236,7 +235,7 @@ namespace HandBrake.ApplicationServices.Services.Encode
}
/// <summary>
- /// Pase the CLI status output (from standard output)
+ /// Pase the status output (from standard output)
/// </summary>
/// <param name="encodeStatus">
/// The encode Status.
@@ -252,7 +251,7 @@ namespace HandBrake.ApplicationServices.Services.Encode
try
{
Match m = Regex.Match(
- encodeStatus,
+ encodeStatus,
@"^Encoding: task ([0-9]*) of ([0-9]*), ([0-9]*\.[0-9]*) %( \(([0-9]*\.[0-9]*) fps, avg ([0-9]*\.[0-9]*) fps, ETA ([0-9]{2})h([0-9]{2})m([0-9]{2})s\))?");
if (m.Success)
@@ -278,16 +277,16 @@ namespace HandBrake.ApplicationServices.Services.Encode
EncodeProgressEventArgs eventArgs = new EncodeProgressEventArgs
{
- AverageFrameRate = avgFps,
- CurrentFrameRate = currentFps,
+ AverageFrameRate = avgFps,
+ CurrentFrameRate = currentFps,
EstimatedTimeLeft =
Converters.EncodeToTimespan(
- remaining),
- PercentComplete = percent,
- Task = currentTask,
- TaskCount = totalTasks,
+ remaining),
+ PercentComplete = percent,
+ Task = currentTask,
+ TaskCount = totalTasks,
ElapsedTime =
- DateTime.Now - startTime,
+ DateTime.Now - startTime,
};
return eventArgs;
@@ -319,14 +318,8 @@ namespace HandBrake.ApplicationServices.Services.Encode
try
{
- string query = QueryGeneratorUtility.GenerateQuery(new EncodeTask(encodeQueueTask.Task), encodeQueueTask.Configuration);
this.logBuffer = new StringBuilder();
- if (!isLibhb)
- {
- this.logBuffer.AppendLine(String.Format("CLI Query: {0}", query));
- }
-
this.logBuffer.AppendLine();
// Clear the current Encode Logs)
@@ -344,10 +337,6 @@ namespace HandBrake.ApplicationServices.Services.Encode
{
this.fileWriter = new StreamWriter(logFile) { AutoFlush = true };
this.fileWriter.WriteLine(this.header);
- if (!isLibhb)
- {
- this.fileWriter.WriteLine("CLI Query: {0}", query);
- }
this.fileWriter.WriteLine();
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs
deleted file mode 100644
index 1aaa0d301..000000000
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode/EncodeService.cs
+++ /dev/null
@@ -1,332 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="EncodeService.cs" company="HandBrake Project (http://handbrake.fr)">
-// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
-// </copyright>
-// <summary>
-// Class which handles the CLI
-// </summary>
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace HandBrake.ApplicationServices.Services.Encode
-{
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Windows.Forms;
-
- using HandBrake.ApplicationServices.Exceptions;
- using HandBrake.ApplicationServices.Model;
- using HandBrake.ApplicationServices.Services.Encode.EventArgs;
- using HandBrake.ApplicationServices.Services.Encode.Interfaces;
- using HandBrake.ApplicationServices.Services.Encode.Model;
- using HandBrake.ApplicationServices.Utilities;
-
- /// <summary>
- /// Class which handles the CLI
- /// </summary>
- public class EncodeService : EncodeBase, IEncode
- {
- #region Private Variables
-
- /// <summary>
- /// Gets the Process ID
- /// </summary>
- private int processId;
-
- /// <summary>
- /// The Start time of the current Encode;
- /// </summary>
- private DateTime startTime;
-
- /// <summary>
- /// The Current Task
- /// </summary>
- private QueueTask currentTask;
-
- /// <summary>
- /// The init shutdown.
- /// </summary>
- private bool initShutdown;
-
- #endregion
-
- #region Properties
-
- /// <summary>
- /// Gets or sets The HB Process
- /// </summary>
- protected Process HbProcess { get; set; }
-
- /// <summary>
- /// Gets a value indicating whether can pause.
- /// </summary>
- public bool CanPause
- {
- get
- {
- return false;
- }
- }
-
- /// <summary>
- /// Gets a value indicating whether is pasued.
- /// </summary>
- public bool IsPasued { get; private set; }
-
- #endregion
-
- #region Public Methods
-
- /// <summary>
- /// Execute a HandBrakeCLI process.
- /// This should only be called from the UI thread.
- /// </summary>
- /// <param name="encodeQueueTask">
- /// The encodeQueueTask.
- /// </param>
- public void Start(QueueTask encodeQueueTask)
- {
- try
- {
- if (this.IsEncoding)
- {
- throw new GeneralApplicationException("HandBrake is already encodeing.", "Please try again in a minute", null);
- }
-
- this.IsEncoding = true;
- this.currentTask = encodeQueueTask;
-
- try
- {
- this.SetupLogging(this.currentTask, false);
- }
- catch (Exception)
- {
- this.IsEncoding = false;
- throw;
- }
-
- // Make sure the path exists, attempt to create it if it doesn't
- this.VerifyEncodeDestinationPath(this.currentTask);
-
- string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
-
- // TODO tidy this code up, it's kinda messy.
- string query = this.currentTask.Task.IsPreviewEncode
- ? QueryGeneratorUtility.GeneratePreviewQuery(
- new EncodeTask(this.currentTask.Task),
- encodeQueueTask.Configuration,
- this.currentTask.Task.PreviewEncodeDuration.HasValue ? this.currentTask.Task.PreviewEncodeDuration.Value : 0,
- this.currentTask.Task.PreviewEncodeStartAt.HasValue ? this.currentTask.Task.PreviewEncodeStartAt.Value : 0)
- : QueryGeneratorUtility.GenerateQuery(new EncodeTask(this.currentTask.Task), encodeQueueTask.Configuration);
-
- ProcessStartInfo cliStart = new ProcessStartInfo(handbrakeCLIPath, query)
- {
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- UseShellExecute = false,
- CreateNoWindow = true
- };
-
- this.HbProcess = new Process { StartInfo = cliStart };
-
- this.HbProcess.Start();
-
- this.startTime = DateTime.Now;
-
- this.HbProcess.ErrorDataReceived += this.HbProcErrorDataReceived;
- this.HbProcess.BeginErrorReadLine();
-
- this.HbProcess.OutputDataReceived += this.HbProcess_OutputDataReceived;
- this.HbProcess.BeginOutputReadLine();
-
- this.processId = this.HbProcess.Id;
-
- // Set the process Priority
- if (this.processId != -1)
- {
- this.HbProcess.EnableRaisingEvents = true;
- this.HbProcess.Exited += this.HbProcessExited;
- }
-
- // Set the Process Priority
- switch (encodeQueueTask.Configuration.ProcessPriority)
- {
- case "Realtime":
- this.HbProcess.PriorityClass = ProcessPriorityClass.RealTime;
- break;
- case "High":
- this.HbProcess.PriorityClass = ProcessPriorityClass.High;
- break;
- case "Above Normal":
- this.HbProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
- break;
- case "Normal":
- this.HbProcess.PriorityClass = ProcessPriorityClass.Normal;
- break;
- case "Low":
- this.HbProcess.PriorityClass = ProcessPriorityClass.Idle;
- break;
- default:
- this.HbProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
- break;
- }
-
- // Fire the Encode Started Event
- this.InvokeEncodeStarted(System.EventArgs.Empty);
- }
- catch (Exception exc)
- {
- encodeQueueTask.Status = QueueItemStatus.Error;
- this.IsEncoding = false;
- this.InvokeEncodeCompleted(
- new EncodeCompletedEventArgs(
- false, exc, "An Error occured when trying to encode this source. ", this.currentTask.Task.Destination));
- throw;
- }
- }
-
- /// <summary>
- /// The pause.
- /// </summary>
- /// <exception cref="NotImplementedException">
- /// This feature is not available for CLI based encoding.
- /// </exception>
- public void Pause()
- {
- throw new NotImplementedException("This feature is not available for CLI based encoding.");
- }
-
- /// <summary>
- /// The resume.
- /// </summary>
- /// <exception cref="NotImplementedException">
- /// This feature is not available for CLI based encoding.
- /// </exception>
- public void Resume()
- {
- throw new NotImplementedException("This feature is not available for CLI based encoding.");
- }
-
- /// <summary>
- /// Kill the CLI process
- /// </summary>
- public override void Stop()
- {
- try
- {
- if (this.HbProcess != null && !this.HbProcess.HasExited)
- {
- this.HbProcess.Kill();
- }
- }
- catch (Exception)
- {
- // No need to report anything to the user. If it fails, it's probably already stopped.
- }
- }
-
- /// <summary>
- /// Shutdown the service.
- /// </summary>
- public void Shutdown()
- {
- // Nothing to do.
- }
-
- #endregion
-
- #region Private Helper Methods
-
- /// <summary>
- /// The HandBrakeCLI process has exited.
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The EventArgs.
- /// </param>
- private void HbProcessExited(object sender, System.EventArgs e)
- {
- this.HbProcess.WaitForExit();
-
- try
- {
- this.HbProcess.CancelErrorRead();
- this.HbProcess.CancelOutputRead();
- this.ShutdownFileWriter();
- }
- catch (Exception)
- {
- // This exception doesn't warrent user interaction, but it should be logged (TODO)
- }
-
- this.currentTask.Status = QueueItemStatus.Completed;
- this.IsEncoding = false;
- this.InvokeEncodeCompleted(new EncodeCompletedEventArgs(true, null, string.Empty, this.currentTask.Task.Destination));
- }
-
- /// <summary>
- /// Recieve the Standard Error information and process it
- /// </summary>
- /// <param name="sender">
- /// The Sender Object
- /// </param>
- /// <param name="e">
- /// DataReceived EventArgs
- /// </param>
- /// <remarks>
- /// Worker Thread.
- /// </remarks>
- private void HbProcErrorDataReceived(object sender, DataReceivedEventArgs e)
- {
- if (!String.IsNullOrEmpty(e.Data))
- {
- if (this.initShutdown && this.LogBuffer.Length < 25000000)
- {
- this.initShutdown = false; // Reset this flag.
- }
-
- if (this.LogBuffer.Length > 25000000 && !this.initShutdown) // Approx 23.8MB and make sure it's only printed once
- {
- this.ProcessLogMessage("ERROR: Initiating automatic shutdown of encode process. The size of the log file indicates that there is an error! ");
- this.initShutdown = true;
- this.Stop();
- }
-
- this.ProcessLogMessage(e.Data);
- }
- }
-
- /// <summary>
- /// The hb process output data received.
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- private void HbProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
- {
- if (!String.IsNullOrEmpty(e.Data) && this.IsEncoding)
- {
- EncodeProgressEventArgs eventArgs = this.ReadEncodeStatus(e.Data, this.startTime);
- if (eventArgs != null)
- {
- if (!this.IsEncoding)
- {
- // We can get events out of order since the CLI progress is monitored on a background thread.
- // So make sure we don't send a status update after an encode complete event.
- return;
- }
-
- this.InvokeEncodeStatusChanged(eventArgs);
- }
- }
- }
-
- #endregion
- }
-} \ No newline at end of file
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs
index 90c42149b..aa53ed180 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Interfaces/IEncode.cs
@@ -42,12 +42,12 @@ namespace HandBrake.ApplicationServices.Services.Encode.Interfaces
public interface IEncode
{
/// <summary>
- /// Fires when a new CLI Job starts
+ /// Fires when a new Job starts
/// </summary>
event EventHandler EncodeStarted;
/// <summary>
- /// Fires when a CLI job finishes.
+ /// Fires when a job finishes.
/// </summary>
event EncodeCompletedStatus EncodeCompleted;
@@ -100,7 +100,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Interfaces
void Resume();
/// <summary>
- /// Kill the CLI process
+ /// Kill the process
/// </summary>
void Stop();
@@ -114,10 +114,5 @@ namespace HandBrake.ApplicationServices.Services.Encode.Interfaces
/// The configuration.
/// </param>
void ProcessLogs(string destination, HBConfiguration configuration);
-
- /// <summary>
- /// Shutdown the service.
- /// </summary>
- void Shutdown();
}
} \ No newline at end of file
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs
index 208f8d307..82bb4b1a7 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/LibEncode.cs
@@ -174,31 +174,26 @@ namespace HandBrake.ApplicationServices.Services.Encode
}
/// <summary>
- /// Kill the CLI process
+ /// Kill the process
/// </summary>
public override void Stop()
{
try
{
this.IsEncoding = false;
- this.instance.StopEncode();
- ServiceLogMessage("Encode Stopped");
+ if (instance != null)
+ {
+ this.instance.StopEncode();
+ ServiceLogMessage("Encode Stopped");
+ }
}
- catch (Exception)
+ catch (Exception exc)
{
- // Do Nothing.
+ Debug.WriteLine(exc);
}
}
/// <summary>
- /// Shutdown the service.
- /// </summary>
- public void Shutdown()
- {
- // Nothing to do for this implementation.
- }
-
- /// <summary>
/// The scan completed.
/// </summary>
/// <param name="job">
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs b/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs
index 721959a90..bc9304f8e 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Scan/LibScan.cs
@@ -39,13 +39,6 @@ namespace HandBrake.ApplicationServices.Services.Scan
/// </summary>
public class LibScan : IScan
{
- /*
- * TODO
- * 1. Expose the Previews code.
- * 2. Cleanup old instances.
- *
- */
-
#region Private Variables
/// <summary>
@@ -101,7 +94,7 @@ namespace HandBrake.ApplicationServices.Services.Scan
public LibScan()
{
this.logging = new StringBuilder();
- this.header = GeneralUtilities.CreateCliLogHeader();
+ this.header = GeneralUtilities.CreateLogHeader();
}
#region Events