summaryrefslogtreecommitdiffstats
path: root/win/C#/EncodeQueue
diff options
context:
space:
mode:
authorsr55 <[email protected]>2009-06-15 14:56:23 +0000
committersr55 <[email protected]>2009-06-15 14:56:23 +0000
commit24780596a9e62e823d619792445a784094f904a2 (patch)
tree79909eb55db5bf00acd2466a32d7da343949d8f5 /win/C#/EncodeQueue
parentb023bb532c17e1284230172b660baa32b5750318 (diff)
WinGui:
- Picture Settings: Height of 0 allows for no -l to be passed to the CLI - Picture Settings / pre-sets now set 0 when no Height specified. Prevents the panel from using incorrect values when pre-sets are selected. - Simplified the Encode.cs set-up. Includes changes to QueueHandler git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2534 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/EncodeQueue')
-rw-r--r--win/C#/EncodeQueue/Encode.cs38
-rw-r--r--win/C#/EncodeQueue/EncodeProcess.cs39
-rw-r--r--win/C#/EncodeQueue/Job.cs (renamed from win/C#/EncodeQueue/QueueItem.cs)2
-rw-r--r--win/C#/EncodeQueue/QueueHandler.cs76
4 files changed, 58 insertions, 97 deletions
diff --git a/win/C#/EncodeQueue/Encode.cs b/win/C#/EncodeQueue/Encode.cs
index 80125fc30..6eced17c7 100644
--- a/win/C#/EncodeQueue/Encode.cs
+++ b/win/C#/EncodeQueue/Encode.cs
@@ -14,13 +14,18 @@ namespace Handbrake.EncodeQueue
{
public class Encode
{
+ public Process hbProcess { get; set; }
+ public int processID { get; set; }
+ public IntPtr processHandle { get; set; }
+ public Boolean isEncoding { get; set; }
+ public String currentQuery { get; set; }
+
/// <summary>
/// Execute a HandBrakeCLI process.
/// </summary>
/// <param name="query">The CLI Query</param>
- public EncodeProcess runCli(string query)
+ public void runCli(string query)
{
- EncodeProcess currentEncode = new EncodeProcess();
try
{
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
@@ -39,17 +44,17 @@ namespace Handbrake.EncodeQueue
cliStart.WindowStyle = ProcessWindowStyle.Minimized;
Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.
- currentEncode.hbProcProcess = Process.Start(cliStart);
- currentEncode.processID = Main.getCliProcess(before);
- currentEncode.isEncoding = true;
- currentEncode.currentQuery = query;
- if (currentEncode.hbProcProcess != null)
- currentEncode.processHandle = (int)currentEncode.hbProcProcess.MainWindowHandle; // Set the process Handle
+ hbProcess = Process.Start(cliStart);
+ processID = Main.getCliProcess(before);
+ isEncoding = true;
+ currentQuery = query;
+ if (hbProcess != null)
+ processHandle = hbProcess.MainWindowHandle; // Set the process Handle
// Set the process Priority
Process hbCliProcess = null;
- if (currentEncode.processID != -1)
- hbCliProcess = Process.GetProcessById(currentEncode.processID);
+ if (processID != -1)
+ hbCliProcess = Process.GetProcessById(processID);
if (hbCliProcess != null)
switch (Properties.Settings.Default.processPriority)
@@ -79,26 +84,23 @@ namespace Handbrake.EncodeQueue
MessageBox.Show("It would appear that HandBrakeCLI has not started correctly. You should take a look at the Activity log as it may indicate the reason why.\n\n Detailed Error Information: error occured in runCli()\n\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
- return currentEncode;
}
/// <summary>
/// Kill the CLI process
/// </summary>
- public void closeCLI(EncodeProcess ep)
+ public void closeCLI()
{
- Process cli = Process.GetProcessById(ep.processID);
- if (!cli.HasExited)
- cli.Kill();
+ hbProcess.Kill();
}
/// <summary>
/// Perform an action after an encode. e.g a shutdown, standby, restart etc.
/// </summary>
- public void afterEncodeAction(EncodeProcess ep)
+ public void afterEncodeAction()
{
- ep.isEncoding = false;
- ep.currentQuery = String.Empty;
+ isEncoding = false;
+ currentQuery = String.Empty;
// Do something whent he encode ends.
switch (Properties.Settings.Default.CompletionOption)
{
diff --git a/win/C#/EncodeQueue/EncodeProcess.cs b/win/C#/EncodeQueue/EncodeProcess.cs
deleted file mode 100644
index c65caea0d..000000000
--- a/win/C#/EncodeQueue/EncodeProcess.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-/* QueueItem.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. */
-
-using System;
-using System.Diagnostics;
-
-namespace Handbrake.EncodeQueue
-{
- public class EncodeProcess
- {
- /// <summary>
- /// The CMD.exe process that runs HandBrakeCLI.exe
- /// </summary>
- public Process hbProcProcess { get; set; }
-
- /// <summary>
- /// Returns whether HandBrake is currently encoding or not.
- /// </summary>
- public Boolean isEncoding { get; set; }
-
- /// <summary>
- /// Returns the currently encoding query string
- /// </summary>
- public String currentQuery { get; set; }
-
- /// <summary>
- /// Get or set the process ID of HandBrakeCLI.exe
- /// </summary>
- public int processID { get; set; }
-
- /// <summary>
- /// Get or Set the Process Handle
- /// </summary>
- public int processHandle { get; set; }
- }
-} \ No newline at end of file
diff --git a/win/C#/EncodeQueue/QueueItem.cs b/win/C#/EncodeQueue/Job.cs
index 587bfb73f..291ef400d 100644
--- a/win/C#/EncodeQueue/QueueItem.cs
+++ b/win/C#/EncodeQueue/Job.cs
@@ -6,7 +6,7 @@
namespace Handbrake.EncodeQueue
{
- public class QueueItem
+ public class Job
{
/// <summary>
/// Get or Set the job id.
diff --git a/win/C#/EncodeQueue/QueueHandler.cs b/win/C#/EncodeQueue/QueueHandler.cs
index 68cfe306a..6670e9e89 100644
--- a/win/C#/EncodeQueue/QueueHandler.cs
+++ b/win/C#/EncodeQueue/QueueHandler.cs
@@ -15,13 +15,13 @@ namespace Handbrake.EncodeQueue
{
public class QueueHandler
{
- Encode encodeHandler = new Encode();
- private static XmlSerializer ser = new XmlSerializer(typeof(List<QueueItem>));
- List<QueueItem> queue = new List<QueueItem>();
+ public Encode encodeHandler = new Encode();
+ private static XmlSerializer ser = new XmlSerializer(typeof(List<Job>));
+ List<Job> queue = new List<Job>();
int id; // Unique identifer number for each job
#region Queue Handling
- public List<QueueItem> getQueue()
+ public List<Job> getQueue()
{
return queue;
}
@@ -30,23 +30,22 @@ namespace Handbrake.EncodeQueue
/// Get's the next CLI query for encoding
/// </summary>
/// <returns>String</returns>
- private string getNextItemForEncoding()
+ private Job getNextJobForEncoding()
{
- QueueItem job = queue[0];
- String query = job.Query;
+ Job job = queue[0];
lastQueueItem = job;
remove(0); // Remove the item which we are about to pass out.
updateQueueRecoveryFile("hb_queue_recovery.xml");
- return query;
+ return job;
}
/// <summary>
/// Get the last query that was returned by getNextItemForEncoding()
/// </summary>
/// <returns></returns>
- public QueueItem lastQueueItem { get; set; }
+ public Job lastQueueItem { get; set; }
/// <summary>
/// Add's a new item to the queue
@@ -56,7 +55,7 @@ namespace Handbrake.EncodeQueue
/// <param name="destination"></param>
public void add(string query, string source, string destination)
{
- QueueItem newJob = new QueueItem { Id = id, Query = query, Source = source, Destination = destination };
+ Job newJob = new Job { Id = id, Query = query, Source = source, Destination = destination };
id++;
queue.Add(newJob);
@@ -64,21 +63,6 @@ namespace Handbrake.EncodeQueue
}
/// <summary>
- /// Check to see if a destination path is already on the queue
- /// </summary>
- /// <param name="destination">Destination path</param>
- /// <returns>Boolean True/False. True = Path Exists</returns>
- public Boolean checkDestinationPath(string destination)
- {
- foreach (QueueItem checkItem in queue)
- {
- if (checkItem.Destination.Contains(destination.Replace("\\\\", "\\")))
- return true;
- }
- return false;
- }
-
- /// <summary>
/// Removes an item from the queue.
/// </summary>
/// <param name="index">Index</param>
@@ -106,7 +90,7 @@ namespace Handbrake.EncodeQueue
{
if (index > 0)
{
- QueueItem item = queue[index];
+ Job item = queue[index];
queue.RemoveAt(index);
queue.Insert((index - 1), item);
@@ -122,7 +106,7 @@ namespace Handbrake.EncodeQueue
{
if (index < queue.Count - 1)
{
- QueueItem item = queue[index];
+ Job item = queue[index];
queue.RemoveAt(index);
queue.Insert((index + 1), item);
@@ -161,7 +145,7 @@ namespace Handbrake.EncodeQueue
public void writeBatchScript(string file)
{
string queries = "";
- foreach (QueueItem queue_item in queue)
+ foreach (Job queue_item in queue)
{
string q_item = queue_item.Query;
string fullQuery = '"' + Application.StartupPath + "\\HandBrakeCLI.exe" + '"' + q_item;
@@ -206,10 +190,10 @@ namespace Handbrake.EncodeQueue
{
if (strm.Length != 0)
{
- List<QueueItem> list = ser.Deserialize(strm) as List<QueueItem>;
+ List<Job> list = ser.Deserialize(strm) as List<Job>;
if (list != null)
- foreach (QueueItem item in list)
+ foreach (Job item in list)
queue.Add(item);
if (file != "hb_queue_recovery.xml")
@@ -218,6 +202,21 @@ namespace Handbrake.EncodeQueue
}
}
}
+
+ /// <summary>
+ /// Check to see if a destination path is already on the queue
+ /// </summary>
+ /// <param name="destination">Destination path</param>
+ /// <returns>Boolean True/False. True = Path Exists</returns>
+ public Boolean checkDestinationPath(string destination)
+ {
+ foreach (Job checkItem in queue)
+ {
+ if (checkItem.Destination.Contains(destination.Replace("\\\\", "\\")))
+ return true;
+ }
+ return false;
+ }
#endregion
#region Encoding
@@ -225,7 +224,6 @@ namespace Handbrake.EncodeQueue
public Boolean isEncodeStarted { get; private set; }
public Boolean isPaused { get; private set; }
public Boolean isEncoding { get; private set; }
- public EncodeProcess encodeProcess { get; set; }
public void startEncode()
{
@@ -255,7 +253,7 @@ namespace Handbrake.EncodeQueue
}
public void endEncode()
{
- encodeHandler.closeCLI(encodeProcess);
+ encodeHandler.closeCLI();
}
private void startProcess(object state)
@@ -265,29 +263,29 @@ namespace Handbrake.EncodeQueue
// Run through each item on the queue
while (this.count() != 0)
{
- string query = getNextItemForEncoding();
+ string query = getNextJobForEncoding().Query;
updateQueueRecoveryFile("hb_queue_recovery.xml"); // Update the queue recovery file
- encodeProcess = encodeHandler.runCli(query);
+ encodeHandler.runCli(query);
EncodeStarted(null);
- encodeProcess.hbProcProcess.WaitForExit();
+ encodeHandler.hbProcess.WaitForExit();
encodeHandler.addCLIQueryToLog(query);
encodeHandler.copyLog(lastQueueItem.Destination);
- encodeProcess.hbProcProcess.Close();
- encodeProcess.hbProcProcess.Dispose();
+ encodeHandler.hbProcess.Close();
+ encodeHandler.hbProcess.Dispose();
EncodeFinished(null);
while (isPaused) // Need to find a better way of doing this.
{
- Thread.Sleep(10000);
+ Thread.Sleep(5000);
}
}
EncodeQueueFinished(null);
// After the encode is done, we may want to shutdown, suspend etc.
- encodeHandler.afterEncodeAction(encodeProcess);
+ encodeHandler.afterEncodeAction();
}
catch (Exception exc)
{