2 using System.Collections.Generic;
\r
4 using System.Collections;
\r
6 using System.Windows.Forms;
\r
8 namespace Handbrake.Functions
\r
12 ArrayList queue = new ArrayList();
\r
13 ArrayList lastQuery;
\r
14 int id = 0; // Unique identifer number for each job
\r
16 public ArrayList getQueue()
\r
22 /// Get's the next CLI query for encoding
\r
24 /// <returns>String</returns>
\r
25 public String getNextItemForEncoding()
\r
27 Object query = queue[0];
\r
28 lastQuery = (ArrayList)query;
\r
29 remove(0); // Remove the item which we are about to pass out.
\r
30 return lastQuery[1].ToString();
\r
34 /// Add's a new item to the queue
\r
36 /// <param name="query">String</param>
\r
37 public void add(string query)
\r
39 // Creates a new job with a unique identifer and cli query
\r
40 ArrayList newJob = new ArrayList();
\r
45 // Adds the job to the queue
\r
50 /// Removes an item from the queue.
\r
52 /// <param name="index">Index</param>
\r
53 /// <returns>Bolean true if successful</returns>
\r
54 public Boolean remove(int index)
\r
56 queue.RemoveAt(index);
\r
61 /// Returns how many items are in the queue
\r
63 /// <returns>Int</returns>
\r
70 /// Get's the last query to be selected for encoding by getNextItemForEncoding()
\r
72 /// <returns>String</returns>
\r
73 public string getLastQuery()
\r
75 return lastQuery[1].ToString();
\r
79 /// Move an item with an index x, up in the queue
\r
81 /// <param name="index">Int</param>
\r
82 public void moveUp(int index)
\r
86 string item = queue[index].ToString();
\r
88 queue.Insert((index - 1), item);
\r
89 queue.RemoveAt((index + 1));
\r
94 /// Move an item with an index x, down in the queue
\r
96 /// <param name="index">Int</param>
\r
97 public void moveDown(int index)
\r
99 if (index != queue.Count - 1)
\r
101 string item = queue[index].ToString();
\r
103 queue.Insert((index + 2), item);
\r
104 queue.RemoveAt((index));
\r
109 /// Writes the current queue to disk. hb_queue_recovery.dat
\r
110 /// This function is called after getNextItemForEncoding()
\r
112 public void write2disk(string file)
\r
116 string tempPath = "";
\r
117 if (file == "hb_queue_recovery.dat")
\r
118 tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");
\r
121 using (StreamWriter writer = new StreamWriter(tempPath))
\r
123 foreach (ArrayList item in queue)
\r
125 writer.WriteLine(item[1].ToString());
\r
133 // Any Errors will be out of diskspace/permissions problems. Don't report them as they'll annoy the user.
\r
138 /// Writes the current queue to disk to the location specified in file
\r
140 /// <param name="file"></param>
\r
141 public void writeBatchScript(string file)
\r
143 string queries = "";
\r
144 foreach (ArrayList queue_item in queue)
\r
146 string q_item = queue_item[1].ToString();
\r
147 string fullQuery = '"' + Application.StartupPath.ToString() + "\\HandBrakeCLI.exe" + '"' + q_item;
\r
149 if (queries == string.Empty)
\r
150 queries = queries + fullQuery;
\r
152 queries = queries + " && " + fullQuery;
\r
154 string strCmdLine = queries;
\r
160 // Create a StreamWriter and open the file, Write the batch file query to the file and
\r
161 // Close the stream
\r
162 StreamWriter line = new StreamWriter(file);
\r
163 line.WriteLine(strCmdLine);
\r
166 MessageBox.Show("Your batch script has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
170 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
177 /// Recover the queue from hb_queue_recovery.dat
\r
179 public void recoverQueue(string file)
\r
183 string tempPath = "";
\r
184 if (file == "hb_queue_recovery.dat")
\r
185 tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");
\r
188 using (StreamReader reader = new StreamReader(tempPath))
\r
190 string queue_item = reader.ReadLine();
\r
192 while (queue_item != null)
\r
194 this.add(queue_item);
\r
195 queue_item = reader.ReadLine();
\r
199 catch (Exception exc)
\r
201 MessageBox.Show("HandBrake was unable to recover the queue. \nError Information:" + exc.ToString(), "Queue Recovery Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r