OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / EncodeQueue / Queue.cs
index da9b786..d31caf9 100644 (file)
@@ -1,25 +1,38 @@
 /*  Queue.cs $\r
-       \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
-using System;\r
-using System.Collections.Generic;\r
-using System.Collections.ObjectModel;\r
-using System.IO;\r
-using System.Threading;\r
-using System.Windows.Forms;\r
-using System.Xml.Serialization;\r
-using Handbrake.Functions;\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.EncodeQueue\r
 {\r
+    using System;\r
+    using System.Collections.Generic;\r
+    using System.Collections.ObjectModel;\r
+    using System.IO;\r
+    using System.Threading;\r
+    using System.Windows.Forms;\r
+    using System.Xml.Serialization;\r
+    using Functions;\r
+\r
+    /// <summary>\r
+    /// The HandBrake Queue\r
+    /// </summary>\r
     public class Queue : Encode\r
     {\r
+        /// <summary>\r
+        /// An XML Serializer\r
+        /// </summary>\r
         private static XmlSerializer serializer;\r
+\r
+        /// <summary>\r
+        /// The Queue Job List\r
+        /// </summary>\r
         private readonly List<Job> queue = new List<Job>();\r
-        private int NextJobId;\r
+\r
+        /// <summary>\r
+        /// The Next Job ID\r
+        /// </summary>\r
+        private int nextJobId;\r
 \r
         /// <summary>\r
         /// Fires when a pause to the encode queue has been requested.\r
@@ -32,17 +45,18 @@ namespace Handbrake.EncodeQueue
         public event EventHandler QueueCompleted;\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 Job GetNextJob()\r
         {\r
-            Job job = queue[0];\r
-            LastEncode = job;\r
-            Remove(0); // Remove the item which we are about to pass out.\r
+            Job job = this.queue[0];\r
+            this.LastEncode = job;\r
+            this.Remove(0); // Remove the item which we are about to pass out.\r
 \r
-            WriteQueueStateToFile("hb_queue_recovery.xml");\r
+            this.WriteQueueStateToFile("hb_queue_recovery.xml");\r
 \r
             return job;\r
         }\r
@@ -52,7 +66,7 @@ namespace Handbrake.EncodeQueue
         /// </summary>\r
         public ReadOnlyCollection<Job> CurrentQueue\r
         {\r
-            get { return queue.AsReadOnly(); }\r
+            get { return this.queue.AsReadOnly(); }\r
         }\r
 \r
         /// <summary>\r
@@ -60,23 +74,37 @@ namespace Handbrake.EncodeQueue
         /// </summary>\r
         public int Count\r
         {\r
-            get { return queue.Count; }\r
+            get { return this.queue.Count; }\r
         }\r
 \r
         /// <summary>\r
         /// Adds an item to the queue.\r
         /// </summary>\r
-        /// <param name="query">The query that will be passed to the HandBrake CLI.</param>\r
-        /// <param name="source">The location of the source video.</param>\r
-        /// <param name="destination">The location where the encoded video will be.</param>\r
-        /// <param name="customJob">Custom job</param>\r
-        /// <param name="scanInfo">The Scan</param>\r
+        /// <param name="query">\r
+        /// The query that will be passed to the HandBrake CLI.\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, string source, string destination, bool customJob)\r
         {\r
-            Job newJob = new Job { Id = NextJobId++, Query = query, Source = source, Destination = destination, CustomQuery = customJob };\r
-\r
-            queue.Add(newJob);\r
-            WriteQueueStateToFile("hb_queue_recovery.xml");\r
+            Job newJob = new Job\r
+                             {\r
+                                 Id = this.nextJobId++, \r
+                                 Query = query, \r
+                                 Source = source, \r
+                                 Destination = destination, \r
+                                 CustomQuery = customJob\r
+                             };\r
+\r
+            this.queue.Add(newJob);\r
+            this.WriteQueueStateToFile("hb_queue_recovery.xml");\r
         }\r
 \r
         /// <summary>\r
@@ -85,19 +113,19 @@ namespace Handbrake.EncodeQueue
         /// <param name="index">The zero-based location of the job in the queue.</param>\r
         public void Remove(int index)\r
         {\r
-            queue.RemoveAt(index);\r
-            WriteQueueStateToFile("hb_queue_recovery.xml");\r
+            this.queue.RemoveAt(index);\r
+            this.WriteQueueStateToFile("hb_queue_recovery.xml");\r
         }\r
 \r
         /// <summary>\r
         /// Retrieve a job from the queue\r
         /// </summary>\r
-        /// <param name="index"></param>\r
-        /// <returns></returns>\r
+        /// <param name="index">the job id</param>\r
+        /// <returns>A job for the given index or blank job object</returns>\r
         public Job GetJob(int index)\r
         {\r
-            if (queue.Count >= (index +1))\r
-                return queue[index];\r
+            if (this.queue.Count >= (index + 1))\r
+                return this.queue[index];\r
 \r
             return new Job();\r
         }\r
@@ -125,15 +153,15 @@ namespace Handbrake.EncodeQueue
         /// <param name="index">The zero-based location of the job in the queue.</param>\r
         public void MoveDown(int index)\r
         {\r
-            if (index < queue.Count - 1)\r
+            if (index < this.queue.Count - 1)\r
             {\r
-                Job item = queue[index];\r
+                Job item = this.queue[index];\r
 \r
-                queue.RemoveAt(index);\r
-                queue.Insert((index + 1), item);\r
+                this.queue.RemoveAt(index);\r
+                this.queue.Insert((index + 1), item);\r
             }\r
 \r
-            WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file\r
+            this.WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file\r
         }\r
 \r
         /// <summary>\r
@@ -142,7 +170,8 @@ namespace Handbrake.EncodeQueue
         /// <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\hb_queue_recovery.xml");\r
+            string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), \r
+                                              @"HandBrake\hb_queue_recovery.xml");\r
             string tempPath = file == "hb_queue_recovery.xml" ? appDataPath : file;\r
 \r
             try\r
@@ -150,7 +179,7 @@ namespace Handbrake.EncodeQueue
                 using (FileStream strm = new FileStream(tempPath, FileMode.Create, FileAccess.Write))\r
                 {\r
                     if (serializer == null)\r
-                        serializer = new XmlSerializer(typeof(List<Job>));\r
+                        serializer = new XmlSerializer(typeof (List<Job>));\r
                     serializer.Serialize(strm, queue);\r
                     strm.Close();\r
                     strm.Dispose();\r
@@ -168,11 +197,11 @@ namespace Handbrake.EncodeQueue
         /// <param name="file">The location of the file to write the batch file to.</param>\r
         public void WriteBatchScriptToFile(string file)\r
         {\r
-            string queries = "";\r
-            foreach (Job queue_item in queue)\r
+            string queries = string.Empty;\r
+            foreach (Job queueItem in this.queue)\r
             {\r
-                string q_item = queue_item.Query;\r
-                string fullQuery = '"' + Application.StartupPath + "\\HandBrakeCLI.exe" + '"' + q_item;\r
+                string qItem = queueItem.Query;\r
+                string fullQuery = '"' + Application.StartupPath + "\\HandBrakeCLI.exe" + '"' + qItem;\r
 \r
                 if (queries == string.Empty)\r
                     queries = queries + fullQuery;\r
@@ -181,7 +210,7 @@ namespace Handbrake.EncodeQueue
             }\r
             string strCmdLine = queries;\r
 \r
-            if (file != "")\r
+            if (file != string.Empty)\r
             {\r
                 try\r
                 {\r
@@ -192,13 +221,15 @@ namespace Handbrake.EncodeQueue
                         line.WriteLine(strCmdLine);\r
                     }\r
 \r
-                    MessageBox.Show("Your batch script has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
+                    MessageBox.Show("Your batch script has been sucessfully saved.", "Status", MessageBoxButtons.OK, \r
+                                    MessageBoxIcon.Asterisk);\r
                 }\r
                 catch (Exception)\r
                 {\r
-                    MessageBox.Show("Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
+                    MessageBox.Show(\r
+                        "Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", \r
+                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
                 }\r
-\r
             }\r
         }\r
 \r
@@ -208,7 +239,8 @@ namespace Handbrake.EncodeQueue
         /// <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\hb_queue_recovery.xml");\r
+            string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), \r
+                                              @"HandBrake\hb_queue_recovery.xml");\r
             string tempPath = file == "hb_queue_recovery.xml" ? appDataPath : file;\r
 \r
             if (File.Exists(tempPath))\r
@@ -218,16 +250,16 @@ namespace Handbrake.EncodeQueue
                     if (strm.Length != 0)\r
                     {\r
                         if (serializer == null)\r
-                            serializer = new XmlSerializer(typeof(List<Job>));\r
+                            serializer = new XmlSerializer(typeof (List<Job>));\r
 \r
                         List<Job> list = serializer.Deserialize(strm) as List<Job>;\r
 \r
                         if (list != null)\r
                             foreach (Job item in list)\r
-                                queue.Add(item);\r
+                                this.queue.Add(item);\r
 \r
                         if (file != "hb_queue_recovery.xml")\r
-                            WriteQueueStateToFile("hb_queue_recovery.xml");\r
+                            this.WriteQueueStateToFile("hb_queue_recovery.xml");\r
                     }\r
                 }\r
             }\r
@@ -240,7 +272,7 @@ namespace Handbrake.EncodeQueue
         /// <returns>Whether or not the supplied destination is already in the queue.</returns>\r
         public bool CheckForDestinationDuplicate(string destination)\r
         {\r
-            foreach (Job checkItem in queue)\r
+            foreach (Job checkItem in this.queue)\r
             {\r
                 if (checkItem.Destination.Contains(destination.Replace("\\\\", "\\")))\r
                     return true;\r
@@ -254,15 +286,15 @@ namespace Handbrake.EncodeQueue
         #region Encoding\r
 \r
         /// <summary>\r
-        /// Gets the last encode that was processed.\r
+        /// Gets or sets the last encode that was processed.\r
         /// </summary>\r
         /// <returns></returns> \r
         public Job LastEncode { get; set; }\r
 \r
         /// <summary>\r
-        /// Request Pause\r
+        /// Gets a value indicating whether Request Pause\r
         /// </summary>\r
-        public Boolean PauseRequested { get; private set; }\r
+        public bool PauseRequested { get; private set; }\r
 \r
         /// <summary>\r
         /// Starts encoding the first job in the queue and continues encoding until all jobs\r
@@ -272,14 +304,14 @@ namespace Handbrake.EncodeQueue
         {\r
             if (this.Count != 0)\r
             {\r
-                if (PauseRequested)\r
-                    PauseRequested = false;\r
+                if (this.PauseRequested)\r
+                    this.PauseRequested = false;\r
                 else\r
                 {\r
-                    PauseRequested = false;\r
+                    this.PauseRequested = false;\r
                     try\r
                     {\r
-                        Thread theQueue = new Thread(StartQueue) { IsBackground = true };\r
+                        Thread theQueue = new Thread(this.StartQueue) {IsBackground = true};\r
                         theQueue.Start();\r
                     }\r
                     catch (Exception exc)\r
@@ -295,50 +327,51 @@ namespace Handbrake.EncodeQueue
         /// </summary>\r
         public void Pause()\r
         {\r
-            PauseRequested = true;\r
+            this.PauseRequested = true;\r
 \r
-            if (QueuePauseRequested != null)\r
-                QueuePauseRequested(this, new EventArgs());\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"></param>\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
-                Job encJob = GetNextJob();\r
+                Job encJob = this.GetNextJob();\r
                 string query = encJob.Query;\r
-                WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file\r
+                this.WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file\r
 \r
                 Run(query);\r
 \r
                 HbProcess.WaitForExit();\r
 \r
                 AddCLIQueryToLog(encJob);\r
-                CopyLog(LastEncode.Destination);\r
+                this.CopyLog(this.LastEncode.Destination);\r
 \r
                 HbProcess.Close();\r
                 HbProcess.Dispose();\r
 \r
                 IsEncoding = false;\r
 \r
-                //Growl\r
+                // Growl\r
                 if (Properties.Settings.Default.growlEncode)\r
-                    GrowlCommunicator.Notify("Encode Completed", "Put down that cocktail...\nyour Handbrake encode is done.");\r
+                    GrowlCommunicator.Notify("Encode Completed", \r
+                                             "Put down that cocktail...\nyour Handbrake encode is done.");\r
 \r
-                while (PauseRequested) // Need to find a better way of doing this.\r
+                while (this.PauseRequested) // Need to find a better way of doing this.\r
                 {\r
                     Thread.Sleep(2000);\r
                 }\r
             }\r
-            LastEncode = new Job();\r
+            this.LastEncode = new Job();\r
 \r
-            if (QueueCompleted != null)\r
-                QueueCompleted(this, new EventArgs());\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