/// <param name="encodeQueue">\r
/// The encode Queue.\r
/// </param>\r
- public static void RecoverQueue(IQueue encodeQueue)\r
+ public static void RecoverQueue(IQueueProcessor encodeQueue)\r
{\r
+ string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");\r
+\r
DialogResult result = DialogResult.None;\r
List<string> queueFiles = CheckQueueRecovery();\r
if (queueFiles.Count == 1)\r
{\r
foreach (string file in queueFiles)\r
{\r
- encodeQueue.LoadQueueFromFile(file); // Start Recovery\r
+ encodeQueue.QueueManager.RestoreQueue(appDataPath + file); // Start Recovery\r
}\r
}\r
else\r
{\r
if (IsMultiInstance) return; // Don't tamper with the files if we are multi instance\r
\r
- string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");\r
foreach (string file in queueFiles)\r
{\r
- if (File.Exists(Path.Combine(tempPath, file)))\r
- File.Delete(Path.Combine(tempPath, file));\r
+ if (File.Exists(Path.Combine(appDataPath, file)))\r
+ File.Delete(Path.Combine(appDataPath, file));\r
}\r
}\r
}\r
</Compile>\r
<Compile Include="Services\Encode.cs" />\r
<Compile Include="Services\Interfaces\IEncode.cs" />\r
- <Compile Include="Services\Interfaces\IQueue.cs" />\r
<Compile Include="Services\Interfaces\IQueueManager.cs" />\r
<Compile Include="Services\Interfaces\IQueueProcessor.cs" />\r
<Compile Include="Services\Interfaces\IScan.cs" />\r
{\r
try\r
{\r
- QueueTask QueueTask = encodeQueueTask as QueueTask;\r
+ QueueTask queueTask = encodeQueueTask;\r
\r
- if (QueueTask == null)\r
+ if (queueTask == null)\r
{\r
throw new ArgumentNullException("QueueTask was null");\r
}\r
\r
if (enableLogging)\r
{\r
- if (!SetupLogging(QueueTask))\r
+ try\r
{\r
- if (this.EncodeCompleted != null)\r
- this.EncodeCompleted(\r
- this,\r
- new EncodeCompletedEventArgs(false, null, "Unable to Start Encode Logging process."));\r
-\r
- return;\r
+ SetupLogging(queueTask);\r
+ }\r
+ catch (Exception)\r
+ {\r
+ IsEncoding = false;\r
+ throw;\r
}\r
}\r
\r
}\r
\r
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
- ProcessStartInfo cliStart = new ProcessStartInfo(handbrakeCLIPath, QueueTask.Query)\r
+ ProcessStartInfo cliStart = new ProcessStartInfo(handbrakeCLIPath, queueTask.Query)\r
{\r
RedirectStandardOutput = true,\r
RedirectStandardError = enableLogging ? true : false,\r
private void HbProcessExited(object sender, EventArgs e)\r
{\r
IsEncoding = false;\r
- if (this.EncodeCompleted != null)\r
- this.EncodeCompleted(this, new EncodeCompletedEventArgs(true, null, string.Empty));\r
-\r
+ \r
if (windowsSeven.IsWindowsSeven)\r
{\r
windowsSeven.SetTaskBarProgressToNoProgress();\r
{\r
// This exception doesn't warrent user interaction, but it should be logged (TODO)\r
}\r
+\r
+ if (this.EncodeCompleted != null)\r
+ this.EncodeCompleted(this, new EncodeCompletedEventArgs(true, null, string.Empty));\r
}\r
\r
/// <summary>\r
/// <param name="encodeQueueTask">\r
/// The encode QueueTask.\r
/// </param>\r
- /// <returns>\r
- /// The setup logging.\r
- /// </returns>\r
- private bool SetupLogging(QueueTask encodeQueueTask)\r
+ private void SetupLogging(QueueTask encodeQueueTask)\r
{\r
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
string logFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", Init.InstanceId));\r
\r
fileWriter.WriteLine(Logging.CreateCliLogHeader(encodeQueueTask));\r
logBuffer.AppendLine(Logging.CreateCliLogHeader(encodeQueueTask));\r
-\r
- return true;\r
}\r
- catch (Exception exc)\r
+ catch (Exception)\r
{\r
if (fileWriter != null)\r
{\r
fileWriter.Close();\r
fileWriter.Dispose();\r
}\r
-\r
- return false;\r
+ throw;\r
}\r
}\r
\r
+++ /dev/null
-/* IQueue.cs $\r
- This file is part of the HandBrake source code.\r
- Homepage: <http://handbrake.fr/>.\r
- It may be used under the terms of the GNU General Public License. */\r
-\r
-namespace HandBrake.ApplicationServices.Services.Interfaces\r
-{\r
- using System;\r
- using System.Collections.ObjectModel;\r
-\r
- using HandBrake.ApplicationServices.Model;\r
-\r
- /// <summary>\r
- /// The IQueue Interface\r
- /// </summary>\r
- public interface IQueue : IEncode\r
- {\r
- /// <summary>\r
- /// Fires when the Queue has started\r
- /// </summary>\r
- event EventHandler QueueStarted;\r
-\r
- /// <summary>\r
- /// Fires when a job is Added, Removed or Re-Ordered.\r
- /// Should be used for triggering an update of the Queue Window.\r
- /// </summary>\r
- event EventHandler QueueListChanged;\r
-\r
- /// <summary>\r
- /// Fires when a pause to the encode queue has been requested.\r
- /// </summary>\r
- event EventHandler QueuePauseRequested;\r
-\r
- /// <summary>\r
- /// Fires when the entire encode queue has completed.\r
- /// </summary>\r
- event EventHandler QueueCompleted;\r
-\r
- /// <summary>\r
- /// Gets or sets the last encode that was processed.\r
- /// </summary>\r
- /// <returns></returns> \r
- QueueTask LastEncode { get; set; }\r
-\r
- /// <summary>\r
- /// Gets a value indicating whether Request Pause\r
- /// </summary>\r
- bool Paused { get; }\r
-\r
- /// <summary>\r
- /// Gets the current state of the encode queue.\r
- /// </summary>\r
- ReadOnlyCollection<QueueTask> CurrentQueue { get; }\r
-\r
- /// <summary>\r
- /// Gets the number of items in the queue.\r
- /// </summary>\r
- int Count { get; }\r
-\r
- /// <summary>\r
- /// Adds an item to the queue.\r
- /// </summary>\r
- /// <param name="query">\r
- /// The query that will be passed to the HandBrake CLI.\r
- /// </param>\r
- /// <param name="title">\r
- /// The title.\r
- /// </param>\r
- /// <param name="source">\r
- /// The location of the source video.\r
- /// </param>\r
- /// <param name="destination">\r
- /// The location where the encoded video will be.\r
- /// </param>\r
- /// <param name="customJob">\r
- /// Custom job\r
- /// </param>\r
- void Add(string query, int title, string source, string destination, bool customJob);\r
-\r
- /// <summary>\r
- /// Removes an item from the queue.\r
- /// </summary>\r
- /// <param name="index">The zero-based location of the job in the queue.</param>\r
- void Remove(int index);\r
-\r
- /// <summary>\r
- /// Retrieve a job from the queue\r
- /// </summary>\r
- /// <param name="index">the job id</param>\r
- /// <returns>A job for the given index or blank job object</returns>\r
- QueueTask GetJob(int index);\r
-\r
- /// <summary>\r
- /// Moves an item up one position in the queue.\r
- /// </summary>\r
- /// <param name="index">The zero-based location of the job in the queue.</param>\r
- void MoveUp(int index);\r
-\r
- /// <summary>\r
- /// Moves an item down one position in the queue.\r
- /// </summary>\r
- /// <param name="index">The zero-based location of the job in the queue.</param>\r
- void MoveDown(int index);\r
-\r
- /// <summary>\r
- /// Writes the current state of the queue to a file.\r
- /// </summary>\r
- /// <param name="file">The location of the file to write the queue to.</param>\r
- void WriteQueueStateToFile(string file);\r
-\r
- /// <summary>\r
- /// Writes the current state of the queue in the form of a batch (.bat) file.\r
- /// </summary>\r
- /// <param name="file">\r
- /// The location of the file to write the batch file to.\r
- /// </param>\r
- /// <returns>\r
- /// The write batch script to file.\r
- /// </returns>\r
- bool WriteBatchScriptToFile(string file);\r
-\r
- /// <summary>\r
- /// Reads a serialized XML file that represents a queue of encoding jobs.\r
- /// </summary>\r
- /// <param name="file">The location of the file to read the queue from.</param>\r
- void LoadQueueFromFile(string file);\r
-\r
- /// <summary>\r
- /// Checks the current queue for an existing instance of the specified destination.\r
- /// </summary>\r
- /// <param name="destination">The destination of the encode.</param>\r
- /// <returns>Whether or not the supplied destination is already in the queue.</returns>\r
- bool CheckForDestinationDuplicate(string destination);\r
-\r
- /// <summary>\r
- /// Starts encoding the first job in the queue and continues encoding until all jobs\r
- /// have been encoded.\r
- /// </summary>\r
- void Start();\r
-\r
- /// <summary>\r
- /// Requests a pause of the encode queue.\r
- /// </summary>\r
- void Pause();\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/* Queue.cs $\r
- This file is part of the HandBrake source code.\r
- Homepage: <http://handbrake.fr/>.\r
- It may be used under the terms of the GNU General Public License. */\r
-\r
-namespace HandBrake.ApplicationServices.Services\r
-{\r
- using System;\r
- using System.Collections.Generic;\r
- using System.Collections.ObjectModel;\r
- using System.Diagnostics;\r
- using System.IO;\r
- using System.Linq;\r
- using System.Threading;\r
- using System.Windows.Forms;\r
- using System.Xml.Serialization;\r
-\r
- using HandBrake.ApplicationServices.Functions;\r
- using HandBrake.ApplicationServices.Model;\r
- using HandBrake.ApplicationServices.Services.Interfaces;\r
-\r
- /// <summary>\r
- /// The HandBrake Queue\r
- /// </summary>\r
- public class Queue : Encode, IQueue\r
- {\r
- /// <summary>\r
- /// The Queue Job List\r
- /// </summary>\r
- private readonly List<QueueTask> queue = new List<QueueTask>();\r
-\r
- /// <summary>\r
- /// An XML Serializer\r
- /// </summary>\r
- private static XmlSerializer serializer;\r
-\r
- /// <summary>\r
- /// The Next Job ID\r
- /// </summary>\r
- private int nextJobId;\r
-\r
- #region Events\r
- /// <summary>\r
- /// Fires when the Queue has started\r
- /// </summary>\r
- public event EventHandler QueueStarted;\r
-\r
- /// <summary>\r
- /// Fires when a job is Added, Removed or Re-Ordered.\r
- /// Should be used for triggering an update of the Queue Window.\r
- /// </summary>\r
- public event EventHandler QueueListChanged;\r
-\r
- /// <summary>\r
- /// Fires when a pause to the encode queue has been requested.\r
- /// </summary>\r
- public event EventHandler QueuePauseRequested;\r
-\r
- /// <summary>\r
- /// Fires when the entire encode queue has completed.\r
- /// </summary>\r
- public event EventHandler QueueCompleted;\r
- #endregion\r
-\r
- #region Properties\r
- /// <summary>\r
- /// Gets or sets the last encode that was processed.\r
- /// </summary>\r
- /// <returns></returns> \r
- public QueueTask LastEncode { get; set; }\r
-\r
- /// <summary>\r
- /// Gets a value indicating whether Request Pause\r
- /// </summary>\r
- public bool Paused { get; private set; }\r
-\r
- /// <summary>\r
- /// Gets the current state of the encode queue.\r
- /// </summary>\r
- public ReadOnlyCollection<QueueTask> CurrentQueue\r
- {\r
- get { return this.queue.AsReadOnly(); }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the number of items in the queue.\r
- /// </summary>\r
- public int Count\r
- {\r
- get { return this.queue.Count; }\r
- }\r
- #endregion\r
-\r
- #region Queue\r
-\r
- /// <summary>\r
- /// Gets and removes the next job in the queue.\r
- /// </summary>\r
- /// <returns>The job that was removed from the queue.</returns>\r
- private QueueTask GetNextJob()\r
- {\r
- QueueTask job = this.queue[0];\r
- this.LastEncode = job;\r
- this.Remove(0); // Remove the item which we are about to pass out.\r
-\r
- this.SaveQueue();\r
-\r
- return job;\r
- }\r
-\r
- /// <summary>\r
- /// Adds an item to the queue.\r
- /// </summary>\r
- /// <param name="query">\r
- /// The query that will be passed to the HandBrake CLI.\r
- /// </param>\r
- /// <param name="title">\r
- /// The title.\r
- /// </param>\r
- /// <param name="source">\r
- /// The location of the source video.\r
- /// </param>\r
- /// <param name="destination">\r
- /// The location where the encoded video will be.\r
- /// </param>\r
- /// <param name="customJob">\r
- /// Custom job\r
- /// </param>\r
- public void Add(string query, int title, string source, string destination, bool customJob)\r
- {\r
- QueueTask newJob = new QueueTask\r
- {\r
- Id = this.nextJobId++,\r
- Title = title,\r
- Query = query,\r
- Source = source,\r
- Destination = destination,\r
- CustomQuery = customJob\r
- };\r
-\r
- this.queue.Add(newJob);\r
- this.SaveQueue();\r
-\r
- if (this.QueueListChanged != null)\r
- this.QueueListChanged(this, new EventArgs());\r
- }\r
-\r
- /// <summary>\r
- /// Removes an item from the queue.\r
- /// </summary>\r
- /// <param name="index">The zero-based location of the job in the queue.</param>\r
- public void Remove(int index)\r
- {\r
- this.queue.RemoveAt(index);\r
- this.SaveQueue();\r
-\r
- if (this.QueueListChanged != null)\r
- this.QueueListChanged(this, new EventArgs());\r
- }\r
-\r
- /// <summary>\r
- /// Retrieve a job from the queue\r
- /// </summary>\r
- /// <param name="index">the job id</param>\r
- /// <returns>A job for the given index or blank job object</returns>\r
- public QueueTask GetJob(int index)\r
- {\r
- if (this.queue.Count >= (index + 1))\r
- return this.queue[index];\r
-\r
- return new QueueTask();\r
- }\r
-\r
- /// <summary>\r
- /// Moves an item up one position in the queue.\r
- /// </summary>\r
- /// <param name="index">The zero-based location of the job in the queue.</param>\r
- public void MoveUp(int index)\r
- {\r
- if (index > 0)\r
- {\r
- QueueTask item = queue[index];\r
-\r
- queue.RemoveAt(index);\r
- queue.Insert((index - 1), item);\r
- }\r
-\r
- this.SaveQueue(); // Update the queue recovery file\r
-\r
- if (this.QueueListChanged != null)\r
- this.QueueListChanged(this, new EventArgs());\r
- }\r
-\r
- /// <summary>\r
- /// Moves an item down one position in the queue.\r
- /// </summary>\r
- /// <param name="index">The zero-based location of the job in the queue.</param>\r
- public void MoveDown(int index)\r
- {\r
- if (index < this.queue.Count - 1)\r
- {\r
- QueueTask item = this.queue[index];\r
-\r
- this.queue.RemoveAt(index);\r
- this.queue.Insert((index + 1), item);\r
- }\r
-\r
- this.SaveQueue(); // Update the queue recovery file\r
-\r
- if (this.QueueListChanged != null)\r
- this.QueueListChanged(this, new EventArgs());\r
- }\r
- \r
- /// <summary>\r
- /// Save any updates to the main queue file.\r
- /// </summary>\r
- public void SaveQueue()\r
- {\r
- string file = Init.InstanceId == 0\r
- ? "hb_queue_recovery.xml"\r
- : string.Format("hb_queue_recovery{0}.xml", Init.InstanceId);\r
- this.WriteQueueStateToFile(file);\r
- }\r
-\r
- /// <summary>\r
- /// Writes the current state of the queue to a file.\r
- /// </summary>\r
- /// <param name="file">The location of the file to write the queue to.</param>\r
- public void WriteQueueStateToFile(string file)\r
- {\r
- string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");\r
- string tempPath = file.Contains("hb_queue_recovery") ? appDataPath + file : file;\r
-\r
- try\r
- {\r
- using (FileStream strm = new FileStream(tempPath, FileMode.Create, FileAccess.Write))\r
- {\r
- if (serializer == null)\r
- serializer = new XmlSerializer(typeof(List<QueueTask>));\r
- serializer.Serialize(strm, queue);\r
- strm.Close();\r
- strm.Dispose();\r
- }\r
- }\r
- catch (Exception)\r
- {\r
- return;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Writes the current state of the queue in the form of a batch (.bat) file.\r
- /// </summary>\r
- /// <param name="file">\r
- /// The location of the file to write the batch file to.\r
- /// </param>\r
- /// <returns>\r
- /// The write batch script to file.\r
- /// </returns>\r
- public bool WriteBatchScriptToFile(string file)\r
- {\r
- string queries = string.Empty;\r
- foreach (QueueTask queueItem in this.queue)\r
- {\r
- string qItem = queueItem.Query;\r
- string fullQuery = '"' + Application.StartupPath + "\\HandBrakeCLI.exe" + '"' + qItem;\r
-\r
- if (queries == string.Empty)\r
- queries = queries + fullQuery;\r
- else\r
- queries = queries + " && " + fullQuery;\r
- }\r
- string strCmdLine = queries;\r
-\r
- if (file != string.Empty)\r
- {\r
- try\r
- {\r
- // Create a StreamWriter and open the file, Write the batch file query to the file and \r
- // Close the stream\r
- using (StreamWriter line = new StreamWriter(file))\r
- {\r
- line.WriteLine(strCmdLine);\r
- }\r
-\r
- return true;\r
- }\r
- catch (Exception exc)\r
- {\r
- throw new Exception("Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", exc);\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- /// <summary>\r
- /// Reads a serialized XML file that represents a queue of encoding jobs.\r
- /// </summary>\r
- /// <param name="file">The location of the file to read the queue from.</param>\r
- public void LoadQueueFromFile(string file)\r
- {\r
- string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");\r
- string tempPath = file.Contains("hb_queue_recovery") ? appDataPath + file : file;\r
-\r
- if (File.Exists(tempPath))\r
- {\r
- using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))\r
- {\r
- if (strm.Length != 0)\r
- {\r
- if (serializer == null)\r
- serializer = new XmlSerializer(typeof(List<QueueTask>));\r
-\r
- List<QueueTask> list = serializer.Deserialize(strm) as List<QueueTask>;\r
-\r
- if (list != null)\r
- foreach (QueueTask item in list)\r
- this.queue.Add(item);\r
-\r
- if (!file.Contains("hb_queue_recovery"))\r
- this.SaveQueue();\r
-\r
- if (this.QueueListChanged != null)\r
- this.QueueListChanged(this, new EventArgs());\r
- }\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Checks the current queue for an existing instance of the specified destination.\r
- /// </summary>\r
- /// <param name="destination">The destination of the encode.</param>\r
- /// <returns>Whether or not the supplied destination is already in the queue.</returns>\r
- public bool CheckForDestinationDuplicate(string destination)\r
- {\r
- return this.queue.Any(checkItem => checkItem.Destination.Contains(destination.Replace("\\\\", "\\")));\r
- }\r
-\r
- #endregion\r
-\r
- #region Encoding\r
-\r
- /// <summary>\r
- /// Starts encoding the first job in the queue and continues encoding until all jobs\r
- /// have been encoded.\r
- /// </summary>\r
- public void Start()\r
- {\r
- if (this.Count != 0)\r
- {\r
- if (this.Paused)\r
- this.Paused = false;\r
- else\r
- {\r
- this.Paused = false;\r
- try\r
- {\r
- Thread theQueue = new Thread(this.StartQueue) { IsBackground = true };\r
- theQueue.Start();\r
-\r
- if (this.QueueStarted != null)\r
- this.QueueStarted(this, new EventArgs());\r
- }\r
- catch (Exception exc)\r
- {\r
- throw new Exception("Unable to Start Queue", exc);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Requests a pause of the encode queue.\r
- /// </summary>\r
- public void Pause()\r
- {\r
- this.Paused = true;\r
-\r
- if (this.QueuePauseRequested != null)\r
- this.QueuePauseRequested(this, new EventArgs());\r
- }\r
-\r
- /// <summary>\r
- /// Run through all the jobs on the queue.\r
- /// </summary>\r
- /// <param name="state">Object State</param>\r
- private void StartQueue(object state)\r
- {\r
- // Run through each item on the queue\r
- while (this.Count != 0)\r
- {\r
- QueueTask encJob = this.GetNextJob();\r
- this.SaveQueue(); // Update the queue recovery file\r
-\r
- Start(encJob, true);\r
-\r
- if (HbProcess == null)\r
- {\r
- return;\r
- }\r
- HbProcess.WaitForExit();\r
-\r
- this.CopyLog(this.LastEncode.Destination);\r
-\r
- HbProcess.Close();\r
- HbProcess.Dispose();\r
-\r
- // Growl\r
- if (Init.GrowlEncode)\r
- GrowlCommunicator.Notify("Encode Completed",\r
- "Put down that cocktail...\nyour Handbrake encode is done.");\r
-\r
- while (this.Paused) // Need to find a better way of doing this.\r
- {\r
- Thread.Sleep(2000);\r
- }\r
- }\r
- this.LastEncode = new QueueTask();\r
-\r
- if (this.QueueCompleted != null)\r
- this.QueueCompleted(this, new EventArgs());\r
-\r
- // After the encode is done, we may want to shutdown, suspend etc.\r
- Finish();\r
- }\r
-\r
- /// <summary>\r
- /// Perform an action after an encode. e.g a shutdown, standby, restart etc.\r
- /// </summary>\r
- private void Finish()\r
- {\r
- // Growl\r
- if (Init.GrowlQueue)\r
- GrowlCommunicator.Notify("Queue Completed", "Put down that cocktail...\nyour Handbrake queue is done.");\r
-\r
- // Do something whent he encode ends.\r
- switch (Init.CompletionOption)\r
- {\r
- case "Shutdown":\r
- Process.Start("Shutdown", "-s -t 60");\r
- break;\r
- case "Log Off":\r
- Win32.ExitWindowsEx(0, 0);\r
- break;\r
- case "Suspend":\r
- Application.SetSuspendState(PowerState.Suspend, true, true);\r
- break;\r
- case "Hibernate":\r
- Application.SetSuspendState(PowerState.Hibernate, true, true);\r
- break;\r
- case "Lock System":\r
- Win32.LockWorkStation();\r
- break;\r
- case "Quit HandBrake":\r
- Application.Exit();\r
- break;\r
- default:\r
- break;\r
- }\r
- }\r
-\r
- #endregion\r
- }\r
-}
\ No newline at end of file
/*\r
* TODO\r
* - Rewrite the batch script generator. \r
+ * - QueueTask, switch everything to use the Task property, which is a model of all settings.\r
*/\r
\r
#region Private Variables\r
{\r
lock (QueueLock)\r
{\r
- // Tag the job with an ID\r
- job.Id = lastJobId++;\r
- queue.Add(job);\r
+ queue.Remove(job);\r
InvokeQueueChanged(EventArgs.Empty);\r
}\r
}\r
this.LastProcessedJob = job;\r
this.Remove(job); // Remove the item which we are about to pass out.\r
\r
- return job; \r
+ return job;\r
}\r
\r
return null;\r
string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");\r
string tempPath = !string.IsNullOrEmpty(exportPath) ? exportPath : appDataPath + string.Format(this.queueFile, string.Empty);\r
\r
- if (File.Exists(tempPath))\r
+ using (FileStream strm = new FileStream(tempPath, FileMode.Create, FileAccess.Write))\r
{\r
- using (FileStream strm = new FileStream(tempPath, FileMode.Create, FileAccess.Write))\r
- {\r
- XmlSerializer serializer = new XmlSerializer(typeof(List<QueueTask>));\r
- serializer.Serialize(strm, queue);\r
- strm.Close();\r
- strm.Dispose();\r
- }\r
+ XmlSerializer serializer = new XmlSerializer(typeof(List<QueueTask>));\r
+ serializer.Serialize(strm, queue);\r
+ strm.Close();\r
+ strm.Dispose();\r
}\r
}\r
\r
/// <returns>Whether or not the supplied destination is already in the queue.</returns>\r
public bool CheckForDestinationPathDuplicates(string destination)\r
{\r
- return this.queue.Any(checkItem => checkItem.Task.Destination.Contains(destination.Replace("\\\\", "\\")));\r
+ return this.queue.Any(checkItem => checkItem.Destination.Contains(destination.Replace("\\\\", "\\")));\r
}\r
\r
/// <summary>\r
case "Shutdown":\r
Process.Start("Shutdown", "-s -t 60");\r
break;\r
- case "Log Off":\r
+ case "Log off":\r
Win32.ExitWindowsEx(0, 0);\r
break;\r
case "Suspend":\r
/// <summary>\r
/// The Encode Object\r
/// </summary>\r
- private readonly IQueue encode;\r
+ private readonly IEncode encode;\r
\r
/// <summary>\r
/// The Scan Object\r
/// <param name="scan">\r
/// The scan.\r
/// </param>\r
- public frmActivityWindow(IQueue encode, IScan scan)\r
+ public frmActivityWindow(IEncode encode, IScan scan)\r
{\r
InitializeComponent();\r
\r
public partial class frmMain : Form\r
{\r
// Objects which may be used by one or more other objects *************\r
- private IQueue encodeQueue = new Queue();\r
+ private IQueueProcessor queueProcessor = new QueueProcessor(Program.InstanceId);\r
private PresetsHandler presetHandler = new PresetsHandler();\r
\r
// Windows ************************************************************\r
treeView_presets.ExpandAll();\r
lbl_encode.Text = string.Empty;\r
drop_mode.SelectedIndex = 0;\r
- queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue\r
+ queueWindow = new frmQueue(this.queueProcessor, this); // Prepare the Queue\r
if (!Settings.Default.QueryEditorTab)\r
tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.\r
if (Settings.Default.tooltipEnable)\r
\r
// Event Handlers and Queue Recovery\r
events();\r
- Main.RecoverQueue(encodeQueue);\r
+ Main.RecoverQueue(this.queueProcessor);\r
\r
// If have a file passed in via command arguemtents, check it's a file and try scanning it.\r
if (args.Length >= 1 && (File.Exists(args[0]) || Directory.Exists(args[0])))\r
RegisterPresetEventHandler();\r
\r
// Handle Window Resize\r
- if (Properties.Settings.Default.MainWindowMinimize)\r
- this.Resize += new EventHandler(frmMain_Resize);\r
+ if (Settings.Default.MainWindowMinimize)\r
+ this.Resize += this.frmMain_Resize;\r
\r
// Handle Encode Start / Finish / Pause\r
- encodeQueue.EncodeStarted += new EventHandler(encodeStarted);\r
- encodeQueue.EncodeCompleted += encodeEnded;\r
+ this.queueProcessor.EncodeService.EncodeStarted += this.encodeStarted;\r
+ this.queueProcessor.EncodeService.EncodeCompleted += encodeEnded;\r
\r
// Scan Started and Completed Events\r
SourceScan.ScanStatusChanged += this.SourceScanScanStatusChanged;\r
SourceScan.ScanCompleted += this.SourceScanScanCompleted;\r
\r
// Handle a file being draged onto the GUI.\r
- this.DragEnter += new DragEventHandler(frmMain_DragEnter);\r
- this.DragDrop += new DragEventHandler(frmMain_DragDrop);\r
+ this.DragEnter += frmMain_DragEnter;\r
+ this.DragDrop += this.frmMain_DragDrop;\r
}\r
\r
// Change the preset label to custom when a user changes a setting. Don't want to give the impression that users can change settings and still be using a preset\r
private void RegisterPresetEventHandler()\r
{\r
// Output Settings\r
- drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel);\r
- check_largeFile.CheckedChanged += new EventHandler(changePresetLabel);\r
- check_iPodAtom.CheckedChanged += new EventHandler(changePresetLabel);\r
- check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);\r
+ drop_format.SelectedIndexChanged += this.changePresetLabel;\r
+ check_largeFile.CheckedChanged += this.changePresetLabel;\r
+ check_iPodAtom.CheckedChanged += this.changePresetLabel;\r
+ check_optimiseMP4.CheckedChanged += this.changePresetLabel;\r
\r
// Picture Settings\r
- PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);\r
+ PictureSettings.PictureSettingsChanged += this.changePresetLabel;\r
\r
// Filter Settings\r
- Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);\r
+ Filters.FilterSettingsChanged += this.changePresetLabel;\r
\r
// Video Tab\r
- drp_videoEncoder.SelectedIndexChanged += new EventHandler(changePresetLabel);\r
- check_2PassEncode.CheckedChanged += new EventHandler(changePresetLabel);\r
- check_turbo.CheckedChanged += new EventHandler(changePresetLabel);\r
- text_filesize.TextChanged += new EventHandler(changePresetLabel);\r
- text_bitrate.TextChanged += new EventHandler(changePresetLabel);\r
- slider_videoQuality.ValueChanged += new EventHandler(changePresetLabel);\r
+ drp_videoEncoder.SelectedIndexChanged += this.changePresetLabel;\r
+ check_2PassEncode.CheckedChanged += this.changePresetLabel;\r
+ check_turbo.CheckedChanged += this.changePresetLabel;\r
+ text_filesize.TextChanged += this.changePresetLabel;\r
+ text_bitrate.TextChanged += this.changePresetLabel;\r
+ slider_videoQuality.ValueChanged += this.changePresetLabel;\r
\r
// Audio Panel\r
- AudioSettings.AudioListChanged += new EventHandler(changePresetLabel);\r
+ AudioSettings.AudioListChanged += this.changePresetLabel;\r
\r
// Advanced Tab\r
- x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);\r
+ x264Panel.rtf_x264Query.TextChanged += this.changePresetLabel;\r
}\r
\r
private void UnRegisterPresetEventHandler()\r
{\r
// Output Settings \r
- drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel);\r
- check_largeFile.CheckedChanged -= new EventHandler(changePresetLabel);\r
- check_iPodAtom.CheckedChanged -= new EventHandler(changePresetLabel);\r
- check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);\r
+ drop_format.SelectedIndexChanged -= this.changePresetLabel;\r
+ check_largeFile.CheckedChanged -= this.changePresetLabel;\r
+ check_iPodAtom.CheckedChanged -= this.changePresetLabel;\r
+ check_optimiseMP4.CheckedChanged -= this.changePresetLabel;\r
\r
// Picture Settings\r
- PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);\r
+ PictureSettings.PictureSettingsChanged -= this.changePresetLabel;\r
\r
// Filter Settings\r
- Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);\r
+ Filters.FilterSettingsChanged -= this.changePresetLabel;\r
\r
// Video Tab\r
- drp_videoEncoder.SelectedIndexChanged -= new EventHandler(changePresetLabel);\r
- check_2PassEncode.CheckedChanged -= new EventHandler(changePresetLabel);\r
- check_turbo.CheckedChanged -= new EventHandler(changePresetLabel);\r
- text_filesize.TextChanged -= new EventHandler(changePresetLabel);\r
- text_bitrate.TextChanged -= new EventHandler(changePresetLabel);\r
- slider_videoQuality.ValueChanged -= new EventHandler(changePresetLabel);\r
+ drp_videoEncoder.SelectedIndexChanged -= this.changePresetLabel;\r
+ check_2PassEncode.CheckedChanged -= this.changePresetLabel;\r
+ check_turbo.CheckedChanged -= this.changePresetLabel;\r
+ text_filesize.TextChanged -= this.changePresetLabel;\r
+ text_bitrate.TextChanged -= this.changePresetLabel;\r
+ slider_videoQuality.ValueChanged -= this.changePresetLabel;\r
\r
// Audio Panel\r
- AudioSettings.AudioListChanged -= new EventHandler(changePresetLabel);\r
+ AudioSettings.AudioListChanged -= this.changePresetLabel;\r
\r
// Advanced Tab\r
- x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);\r
+ x264Panel.rtf_x264Query.TextChanged -= this.changePresetLabel;\r
}\r
\r
private void changePresetLabel(object sender, EventArgs e)\r
private void encodeStarted(object sender, EventArgs e)\r
{\r
SetEncodeStarted();\r
- encodeQueue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;\r
+ this.queueProcessor.EncodeService.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;\r
}\r
\r
private void encodeEnded(object sender, EventArgs e)\r
{\r
- encodeQueue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;\r
+ this.queueProcessor.EncodeService.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;\r
SetEncodeFinished();\r
}\r
#endregion\r
if (result == DialogResult.Yes)\r
{\r
// Pause The Queue\r
- encodeQueue.Pause();\r
+ this.queueProcessor.Pause();\r
\r
if (Settings.Default.showCliForInGuiEncodeStatus)\r
- encodeQueue.SafelyStop();\r
+ this.queueProcessor.EncodeService.SafelyStop();\r
else\r
- encodeQueue.Stop();\r
+ this.queueProcessor.EncodeService.Stop();\r
}\r
}\r
else\r
string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;\r
string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;\r
\r
- if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))\r
+ if (this.queueProcessor.QueueManager.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))\r
{\r
string generatedQuery = QueryGenerator.GenerateFullQuery(this);\r
string specifiedQuery = rtf_query.Text != string.Empty\r
\r
if (overwrite == DialogResult.Yes)\r
{\r
- if (encodeQueue.Count == 0)\r
- encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));\r
+ QueueTask task = new QueueTask(query)\r
+ {\r
+ Title = this.GetTitle(),\r
+ Source = jobSourcePath,\r
+ Destination = jobDestination,\r
+ CustomQuery = (this.rtf_query.Text != string.Empty)\r
+ };\r
+\r
+ if (this.queueProcessor.QueueManager.Count == 0)\r
+ this.queueProcessor.QueueManager.Add(task);\r
\r
queueWindow.SetQueue();\r
- if (encodeQueue.Count > 1)\r
+ if (this.queueProcessor.QueueManager.Count > 1)\r
queueWindow.Show(false);\r
\r
SetEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
- encodeQueue.Start(); // Start The Queue Encoding Process\r
+ this.queueProcessor.Start(); // Start The Queue Encoding Process\r
}\r
\r
this.Focus();\r
}\r
\r
// Make sure we don't have a duplciate on the queue.\r
- if (encodeQueue.CheckForDestinationDuplicate(jobDestination))\r
+ if (this.queueProcessor.QueueManager.CheckForDestinationPathDuplicates(jobDestination))\r
{\r
if (showError)\r
{\r
}\r
\r
// Add the job.\r
- encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));\r
+ QueueTask task = new QueueTask(query)\r
+ {\r
+ Title = this.GetTitle(),\r
+ Source = jobSourcePath,\r
+ Destination = jobDestination,\r
+ CustomQuery = (this.rtf_query.Text != string.Empty)\r
+ };\r
+ this.queueProcessor.QueueManager.Add(task);\r
\r
- lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
+ lbl_encode.Text = this.queueProcessor.QueueManager.Count + " encode(s) pending in the queue";\r
\r
return true;\r
}\r
private void btn_ActivityWindow_Click(object sender, EventArgs e)\r
{\r
if (this.activityWindow == null || !this.activityWindow.IsHandleCreated)\r
- this.activityWindow = new frmActivityWindow(encodeQueue, SourceScan);\r
+ this.activityWindow = new frmActivityWindow(this.queueProcessor.EncodeService, SourceScan);\r
\r
this.activityWindow.Show();\r
this.activityWindow.Activate();\r
lbl_encode.Visible = true;\r
ProgressBarStatus.Value = 0;\r
ProgressBarStatus.Visible = true;\r
- lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";\r
+ lbl_encode.Text = "Encoding with " + this.queueProcessor.QueueManager.Count + " encode(s) pending";\r
btn_start.Text = "Stop";\r
btn_start.ToolTipText = "Stop the encoding process.";\r
btn_start.Image = Properties.Resources.stop;\r
e.CurrentFrameRate,\r
e.AverageFrameRate,\r
e.EstimatedTimeLeft,\r
- encodeQueue.Count);\r
+ this.queueProcessor.QueueManager.Count);\r
\r
ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete);\r
}\r
try\r
{\r
// If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.\r
- if (encodeQueue.IsEncoding)\r
+ if (this.queueProcessor.EncodeService.IsEncoding)\r
{\r
DialogResult result =\r
MessageBox.Show(\r
return;\r
}\r
\r
- encodeQueue.Stop();\r
+ this.queueProcessor.Pause();\r
+ this.queueProcessor.EncodeService.Stop();\r
}\r
\r
if (SourceScan.IsScanning)\r
/// <summary>\r
/// The encode queue\r
/// </summary>\r
- private readonly IQueue encodeQueue = new Queue();\r
+ private readonly IEncode encodeQueue = new Encode();\r
\r
/// <summary>\r
/// What is currently playing\r
using System.Collections.ObjectModel;\r
using System.ComponentModel;\r
using System.IO;\r
+ using System.Linq;\r
using System.Windows.Forms;\r
using Functions;\r
\r
/// <summary>\r
/// An instance of the Queue service\r
/// </summary>\r
- private readonly IQueue queue;\r
+ private readonly IQueueProcessor queue;\r
\r
/// <summary>\r
/// A reference to the main application window\r
/// <param name="mw">\r
/// The main window.\r
/// </param>\r
- public frmQueue(IQueue q, frmMain mw)\r
+ public frmQueue(IQueueProcessor q, frmMain mw)\r
{\r
InitializeComponent();\r
\r
this.mainWindow = mw;\r
\r
this.queue = q;\r
- queue.EncodeStarted += new EventHandler(QueueOnEncodeStart);\r
- queue.QueueCompleted += new EventHandler(QueueOnQueueFinished);\r
- queue.QueuePauseRequested += new EventHandler(QueueOnPaused);\r
- queue.QueueListChanged += new EventHandler(queue_QueueListChanged);\r
+ queue.EncodeService.EncodeStarted += this.QueueOnEncodeStart;\r
+ queue.QueueCompleted += this.QueueOnQueueFinished;\r
+ queue.QueuePaused += this.QueueOnPaused;\r
+ queue.QueueManager.QueueChanged += new EventHandler(queue_QueueListChanged);\r
\r
- queue.EncodeStarted += new EventHandler(queue_EncodeStarted);\r
- queue.EncodeCompleted += queue_EncodeEnded;\r
+ queue.EncodeService.EncodeStarted += this.queue_EncodeStarted;\r
+ queue.EncodeService.EncodeCompleted += this.queue_EncodeEnded;\r
\r
drp_completeOption.Text = Properties.Settings.Default.CompletionOption;\r
}\r
/// </param>\r
private void queue_EncodeEnded(object sender, EventArgs e)\r
{\r
- queue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;\r
+ queue.EncodeService.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;\r
ResetEncodeText();\r
}\r
\r
private void queue_EncodeStarted(object sender, EventArgs e)\r
{\r
this.SetCurrentEncodeInformation();\r
- queue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged; \r
+ queue.EncodeService.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged; \r
}\r
\r
/// <summary>\r
/// <param name="e">the EventArgs</param>\r
private void BtnEncodeClick(object sender, EventArgs e)\r
{\r
- if (queue.Paused)\r
+ if (!queue.IsProcessing)\r
{\r
SetUiEncodeStarted();\r
}\r
}\r
\r
list_queue.Items.Clear();\r
- ReadOnlyCollection<QueueTask> theQueue = queue.CurrentQueue;\r
+ ReadOnlyCollection<QueueTask> theQueue = queue.QueueManager.Queue;\r
foreach (QueueTask queueItem in theQueue)\r
{\r
string qItem = queueItem.Query;\r
- QueryParser parsed = Functions.QueryParser.Parse(qItem);\r
+ QueryParser parsed = QueryParser.Parse(qItem);\r
\r
// Get the DVD Title\r
string title = parsed.Title == 0 ? "Auto" : parsed.Title.ToString();\r
chapters = chapters + " - " + parsed.ChapterFinish;\r
}\r
\r
- ListViewItem item = new ListViewItem();\r
- item.Text = title; // Title\r
+ ListViewItem item = new ListViewItem { Tag = queueItem, Text = title };\r
item.SubItems.Add(chapters); // Chapters\r
item.SubItems.Add(queueItem.Source); // Source\r
item.SubItems.Add(queueItem.Destination); // Destination\r
BeginInvoke(new UpdateHandler(SetCurrentEncodeInformation));\r
}\r
\r
- QueryParser parsed = QueryParser.Parse(queue.LastEncode.Query);\r
+ QueryParser parsed = QueryParser.Parse(queue.QueueManager.LastProcessedJob.Query);\r
\r
// Get title and chapters\r
string title = parsed.Title == 0 ? "Auto" : parsed.Title.ToString();\r
\r
// found query is a global varible \r
lbl_encodeStatus.Text = "Encoding ...";\r
- lbl_source.Text = queue.LastEncode.Source + "(Title: " + title + " Chapters: " + chapterlbl + ")";\r
- lbl_dest.Text = queue.LastEncode.Destination;\r
+ lbl_source.Text = queue.QueueManager.LastProcessedJob.Source + "(Title: " + title + " Chapters: " + chapterlbl + ")";\r
+ lbl_dest.Text = queue.QueueManager.LastProcessedJob.Destination;\r
lbl_encodeOptions.Text = "Video: " + parsed.VideoEncoder + " Audio: " + audio + Environment.NewLine +\r
"x264 Options: " + parsed.H264Query;\r
}\r
{\r
lock (list_queue)\r
{\r
- int index = list_queue.SelectedIndices[0];\r
- mainWindow.RecievingJob(queue.GetJob(index));\r
- queue.Remove(index);\r
+ QueueTask index = list_queue.SelectedItems[0].Tag as QueueTask;\r
+ mainWindow.RecievingJob(index);\r
+ queue.QueueManager.Remove(index);\r
RedrawQueue();\r
}\r
}\r
\r
// Move up each selected item\r
foreach (int selectedIndex in selectedIndices)\r
- queue.MoveUp(selectedIndex);\r
+ queue.QueueManager.MoveUp(selectedIndex);\r
\r
// Keep the selected item(s) selected, now moved up one index\r
foreach (int selectedIndex in selectedIndices)\r
\r
// Move down each selected item\r
foreach (int selectedIndex in selectedIndices)\r
- queue.MoveDown(selectedIndex);\r
+ queue.QueueManager.MoveDown(selectedIndex);\r
\r
// Keep the selected item(s) selected, now moved down one index\r
foreach (int selectedIndex in selectedIndices)\r
// If there are selected items\r
if (list_queue.SelectedIndices.Count > 0)\r
{\r
- // Save the selected indices to select them after the move\r
- List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);\r
- foreach (int selectedIndex in list_queue.SelectedIndices)\r
- selectedIndices.Add(selectedIndex);\r
-\r
- int firstSelectedIndex = selectedIndices[0];\r
-\r
- // Reverse the list to delete the items from last to first (preserves indices)\r
- selectedIndices.Reverse();\r
-\r
// Remove each selected item\r
- foreach (int selectedIndex in selectedIndices)\r
- queue.Remove(selectedIndex);\r
+ foreach (ListViewItem selectedIndex in this.list_queue.SelectedItems)\r
+ queue.QueueManager.Remove((QueueTask)selectedIndex.Tag);\r
\r
- // Select the item where the first deleted item was previously\r
- if (firstSelectedIndex < list_queue.Items.Count)\r
- list_queue.Items[firstSelectedIndex].Selected = true;\r
+ // Select the first item after deletion.\r
+ if (list_queue.Items.Count > 0)\r
+ list_queue.Items[0].Selected = true;\r
}\r
\r
list_queue.Select(); // Activate the control to show the selected items\r
SaveFile.Filter = "Batch|.bat";\r
SaveFile.ShowDialog();\r
if (SaveFile.FileName != String.Empty)\r
- queue.WriteBatchScriptToFile(SaveFile.FileName);\r
+ queue.QueueManager.WriteBatchScriptToFile(SaveFile.FileName);\r
}\r
\r
/// <summary>\r
SaveFile.Filter = "HandBrake Queue|*.queue";\r
SaveFile.ShowDialog();\r
if (SaveFile.FileName != String.Empty)\r
- queue.WriteQueueStateToFile(SaveFile.FileName);\r
+ queue.QueueManager.BackupQueue(SaveFile.FileName);\r
}\r
\r
/// <summary>\r
OpenFile.FileName = string.Empty;\r
OpenFile.ShowDialog();\r
if (OpenFile.FileName != String.Empty)\r
- queue.LoadQueueFromFile(OpenFile.FileName);\r
+ queue.QueueManager.RestoreQueue(OpenFile.FileName);\r
}\r
\r
/// <summary>\r
/// </param>\r
private void MnuReaddClick(object sender, EventArgs e)\r
{\r
- if (queue.LastEncode != null && !queue.LastEncode.IsEmpty)\r
+ if (queue.QueueManager.LastProcessedJob != null && !queue.QueueManager.LastProcessedJob.IsEmpty)\r
{\r
- queue.Add(\r
- queue.LastEncode.Query, \r
- queue.LastEncode.Title, \r
- queue.LastEncode.Source,\r
- queue.LastEncode.Destination,\r
- queue.LastEncode.CustomQuery);\r
+ queue.QueueManager.Add(queue.QueueManager.LastProcessedJob);\r
}\r
}\r
\r