2 using System.Collections.Generic;
\r
4 using System.Collections;
\r
6 using System.Windows.Forms;
\r
7 using System.Xml.Serialization;
\r
9 namespace Handbrake.Queue
\r
13 private static XmlSerializer ser = new XmlSerializer(typeof(List<QueueItem>));
\r
14 List<QueueItem> queue = new List<QueueItem>();
\r
15 int id = 0; // Unique identifer number for each job
\r
16 private QueueItem lastItem;
\r
18 public List<QueueItem> getQueue()
\r
24 /// Get's the next CLI query for encoding
\r
26 /// <returns>String</returns>
\r
27 public string getNextItemForEncoding()
\r
29 QueueItem job = queue[0];
\r
30 String query = job.Query;
\r
32 remove(0); // Remove the item which we are about to pass out.
\r
37 /// Get the last query that was returned by getNextItemForEncoding()
\r
39 /// <returns></returns>
\r
40 public QueueItem getLastQuery()
\r
46 /// Add's a new item to the queue
\r
48 /// <param name="query">String</param>
\r
49 public void add(string query, string source, string destination)
\r
51 QueueItem newJob = new QueueItem();
\r
53 newJob.Query = query;
\r
54 newJob.Source = source;
\r
55 newJob.Destination = destination;
\r
58 // Adds the job to the queue
\r
63 /// Removes an item from the queue.
\r
65 /// <param name="index">Index</param>
\r
66 /// <returns>Bolean true if successful</returns>
\r
67 public Boolean remove(int index)
\r
69 queue.RemoveAt(index);
\r
74 /// Returns how many items are in the queue
\r
76 /// <returns>Int</returns>
\r
83 /// Move an item with an index x, up in the queue
\r
85 /// <param name="index">Int</param>
\r
86 public void moveUp(int index)
\r
90 QueueItem item = (QueueItem)queue[index];
\r
92 queue.Insert((index - 1), item);
\r
93 queue.RemoveAt((index + 1));
\r
98 /// Move an item with an index x, down in the queue
\r
100 /// <param name="index">Int</param>
\r
101 public void moveDown(int index)
\r
103 if (index != queue.Count - 1)
\r
105 QueueItem item = (QueueItem)queue[index];
\r
107 queue.Insert((index + 2), item);
\r
108 queue.RemoveAt((index));
\r
113 /// Writes the current queue to disk. hb_queue_recovery.xml
\r
114 /// This function is called after getNextItemForEncoding()
\r
116 public void write2disk(string file)
\r
118 string tempPath = "";
\r
119 if (file == "hb_queue_recovery.xml")
\r
120 tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
\r
126 using (FileStream strm = new FileStream(tempPath, FileMode.Create, FileAccess.Write))
\r
128 ser.Serialize(strm, queue);
\r
135 // Any Errors will be out of diskspace/permissions problems.
\r
136 // Don't report them as they'll annoy the user.
\r
141 /// Writes the current queue to disk to the location specified in file
\r
143 /// <param name="file"></param>
\r
144 public void writeBatchScript(string file)
\r
146 string queries = "";
\r
147 foreach (QueueItem queue_item in queue)
\r
149 string q_item = queue_item.Query;
\r
150 string fullQuery = '"' + Application.StartupPath.ToString() + "\\HandBrakeCLI.exe" + '"' + q_item;
\r
152 if (queries == string.Empty)
\r
153 queries = queries + fullQuery;
\r
155 queries = queries + " && " + fullQuery;
\r
157 string strCmdLine = queries;
\r
163 // Create a StreamWriter and open the file, Write the batch file query to the file and
\r
164 // Close the stream
\r
165 StreamWriter line = new StreamWriter(file);
\r
166 line.WriteLine(strCmdLine);
\r
169 MessageBox.Show("Your batch script has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
173 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
180 /// Recover the queue from hb_queue_recovery.xml
\r
182 public void recoverQueue(string file)
\r
184 string tempPath = "";
\r
185 if (file == "hb_queue_recovery.xml")
\r
186 tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
\r
190 if (File.Exists(tempPath))
\r
192 using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))
\r
194 if (strm.Length != 0)
\r
196 List<QueueItem> list = ser.Deserialize(strm) as List<QueueItem>;
\r
198 foreach (QueueItem item in list)
\r