/// if this feature is enabled in options.\r
/// </summary>\r
/// <param name="query"></param>\r
- public void copyLog(string query)\r
+ public void copyLog(string query, string destination)\r
{\r
// The user may wish to do something with the log.\r
if (Properties.Settings.Default.saveLog == "Checked")\r
\r
if (Properties.Settings.Default.saveLogWithVideo == "Checked")\r
{\r
- string[] destName = parsed.Destination.Split('\\');\r
+ string[] destName = destination.Split('\\');\r
string destinationFile = "";\r
for (int i = 0; i < destName.Length - 1; i++)\r
{\r
}\r
else if (Properties.Settings.Default.saveLogPath != String.Empty)\r
{\r
- string[] destName = parsed.Destination.Split('\\');\r
+ string[] destName = destination.Split('\\');\r
string dest = destName[destName.Length - 1];\r
string filename = DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + " " + dest + ".txt";\r
string useDefinedLogPath = Path.Combine(Properties.Settings.Default.saveLogPath, filename);\r
using System.Drawing;\r
using System.Diagnostics;\r
using System.Text.RegularExpressions;\r
+using System.Collections.Generic;\r
+using System.Xml.Serialization;\r
\r
namespace Handbrake.Functions\r
{\r
class Main\r
{\r
+ // Private Variables\r
+ private static XmlSerializer ser = new XmlSerializer(typeof(List<Queue.QueueItem>));\r
+\r
/// <summary>\r
/// Calculate the duration of the selected title and chapters\r
/// </summary>\r
{\r
try\r
{\r
- string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");\r
- using (StreamReader reader = new StreamReader(tempPath))\r
+ string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");\r
+ if (File.Exists(tempPath))\r
{\r
- string queue_item = reader.ReadLine();\r
- if (queue_item == null)\r
- {\r
- reader.Close();\r
- reader.Dispose();\r
- return false;\r
- }\r
- else // There exists an item in the recovery queue file, so try and recovr it.\r
+ using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))\r
{\r
- reader.Close();\r
- reader.Dispose();\r
- return true;\r
+ List<Queue.QueueItem> list = ser.Deserialize(strm) as List<Queue.QueueItem>;\r
+ if (list.Count != 0)\r
+ return true;\r
}\r
}\r
+ return false;\r
}\r
catch (Exception)\r
{\r
- // Keep quiet about the error.\r
- return false;\r
+ return false; // Keep quiet about the error.\r
}\r
}\r
\r
#region Varibles\r
\r
#region Source\r
-\r
- private string q_source;\r
- /// <summary>\r
- /// Returns a String \r
- /// Full path of the source.\r
- /// </summary>\r
- public string Source\r
- {\r
- get\r
- {\r
- return this.q_source;\r
- }\r
- }\r
-\r
private int q_dvdTitle;\r
/// <summary>\r
/// Returns an Integer\r
#endregion\r
\r
#region Destination\r
-\r
- private string q_destination;\r
- /// <summary>\r
- /// Returns a String \r
- /// Full path of the destination.\r
- /// </summary>\r
- public string Destination\r
- {\r
- get\r
- {\r
- return this.q_destination;\r
- }\r
- }\r
-\r
private string q_format;\r
/// <summary>\r
/// Returns a String \r
QueryParser thisQuery = new QueryParser();\r
\r
#region Regular Expressions\r
+ // Useful Destination Finder\r
+ //Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9?';!^%&*()_\-:\\\s\.]+)(?:\"")");\r
+ //Match source = r1.Match(input.Replace('"', '\"'));\r
+\r
//Source\r
- Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9_\-:\\\s\.]+)(?:\"")");\r
- Match source = r1.Match(input.Replace('"', '\"'));\r
Match title = Regex.Match(input, @"-t ([0-9]*)");\r
Match chapters = Regex.Match(input, @"-c ([0-9-]*)");\r
Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)");\r
\r
//Destination\r
- Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9_\-:\\\s\.]+)(?:\"")");\r
- Match destination = r2.Match(input.Replace('"', '\"'));\r
Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");\r
\r
//Picture Settings Tab\r
#region Set Varibles\r
try\r
{\r
- \r
#region Source Tab\r
-\r
- thisQuery.q_source = source.ToString().Replace("-i ", "").Replace("\"", "");\r
if (title.Success != false)\r
- thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));\r
+ thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));\r
\r
if (chapters.Success != false)\r
{\r
#endregion\r
\r
#region Destination\r
- thisQuery.q_destination = destination.ToString().Replace("-o ", "").Replace("\"", "");\r
-\r
- string videoEncoderConvertion;\r
\r
- videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");\r
+ string videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");\r
switch (videoEncoderConvertion)\r
{\r
case "ffmpeg":\r
<PlatformTarget>x86</PlatformTarget>\r
</PropertyGroup>\r
<ItemGroup>\r
- <Reference Include="PresentationCore">\r
- <RequiredTargetFramework>3.0</RequiredTargetFramework>\r
- </Reference>\r
- <Reference Include="PresentationFramework">\r
- <RequiredTargetFramework>3.0</RequiredTargetFramework>\r
- </Reference>\r
<Reference Include="System" />\r
<Reference Include="System.Data" />\r
<Reference Include="System.Deployment" />\r
<Reference Include="System.Drawing" />\r
<Reference Include="System.Messaging" />\r
<Reference Include="System.Windows.Forms" />\r
- <Reference Include="System.Xml" />\r
- <Reference Include="UIAutomationProvider">\r
- <RequiredTargetFramework>3.0</RequiredTargetFramework>\r
- </Reference>\r
- <Reference Include="WindowsBase">\r
- <RequiredTargetFramework>3.0</RequiredTargetFramework>\r
- </Reference>\r
+ <Reference Include="System.XML" />\r
</ItemGroup>\r
<ItemGroup>\r
<Compile Include="frmActivityWindow.cs">\r
<Compile Include="Functions\Main.cs" />\r
<Compile Include="Presets\preset.cs" />\r
<Compile Include="Presets\PresetsHandler.cs" />\r
- <Compile Include="Functions\Queue.cs" />\r
+ <Compile Include="Queue\QueueHandler.cs" />\r
<Compile Include="Functions\AppcastReader.cs" />\r
<Compile Include="Functions\Encode.cs" />\r
<Compile Include="Functions\QueryParser.cs" />\r
<Compile Include="frmSplashScreen.Designer.cs">\r
<DependentUpon>frmSplashScreen.cs</DependentUpon>\r
</Compile>\r
+ <Compile Include="Queue\QueueItem.cs" />\r
</ItemGroup>\r
<ItemGroup>\r
<Content Include="handbrakepineapple.ico" />\r
using System.Collections;\r
using System.IO;\r
using System.Windows.Forms;\r
+using System.Xml.Serialization;\r
\r
-namespace Handbrake.Functions\r
+namespace Handbrake.Queue\r
{\r
public class Queue\r
{\r
- ArrayList queue = new ArrayList();\r
- ArrayList lastQuery;\r
+ private static XmlSerializer ser = new XmlSerializer(typeof(List<QueueItem>));\r
+ List<QueueItem> queue = new List<QueueItem>();\r
int id = 0; // Unique identifer number for each job\r
+ private QueueItem lastItem;\r
\r
- public ArrayList getQueue()\r
+ public List<QueueItem> getQueue()\r
{\r
return queue;\r
}\r
/// Get's the next CLI query for encoding\r
/// </summary>\r
/// <returns>String</returns>\r
- public String getNextItemForEncoding()\r
+ public string getNextItemForEncoding()\r
{\r
- Object query = queue[0];\r
- lastQuery = (ArrayList)query;\r
+ QueueItem job = queue[0];\r
+ String query = job.Query;\r
+ lastItem = job;\r
remove(0); // Remove the item which we are about to pass out.\r
- return lastQuery[1].ToString();\r
+ return query;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get the last query that was returned by getNextItemForEncoding()\r
+ /// </summary>\r
+ /// <returns></returns>\r
+ public QueueItem getLastQuery()\r
+ {\r
+ return lastItem;\r
}\r
\r
/// <summary>\r
/// Add's a new item to the queue\r
/// </summary>\r
/// <param name="query">String</param>\r
- public void add(string query)\r
+ public void add(string query, string source, string destination)\r
{\r
- // Creates a new job with a unique identifer and cli query\r
- ArrayList newJob = new ArrayList();\r
- newJob.Add(id);\r
- newJob.Add(query);\r
+ QueueItem newJob = new QueueItem();\r
+ newJob.Id = id;\r
+ newJob.Query = query;\r
+ newJob.Source = source;\r
+ newJob.Destination = destination;\r
id++;\r
\r
// Adds the job to the queue\r
return queue.Count;\r
}\r
\r
- /// <summary>\r
- /// Get's the last query to be selected for encoding by getNextItemForEncoding()\r
- /// </summary>\r
- /// <returns>String</returns>\r
- public string getLastQuery()\r
- {\r
- return lastQuery[1].ToString();\r
- }\r
-\r
/// <summary>\r
/// Move an item with an index x, up in the queue\r
/// </summary>\r
{\r
if (index != 0)\r
{\r
- ArrayList item = (ArrayList)queue[index];\r
+ QueueItem item = (QueueItem)queue[index];\r
\r
queue.Insert((index - 1), item);\r
queue.RemoveAt((index + 1));\r
{\r
if (index != queue.Count - 1)\r
{\r
- ArrayList item = (ArrayList)queue[index];\r
+ QueueItem item = (QueueItem)queue[index];\r
\r
queue.Insert((index + 2), item);\r
queue.RemoveAt((index));\r
}\r
\r
/// <summary>\r
- /// Writes the current queue to disk. hb_queue_recovery.dat\r
+ /// Writes the current queue to disk. hb_queue_recovery.xml\r
/// This function is called after getNextItemForEncoding()\r
/// </summary>\r
public void write2disk(string file)\r
{\r
+ string tempPath = "";\r
+ if (file == "hb_queue_recovery.xml")\r
+ tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");\r
+ else\r
+ tempPath = file;\r
+\r
try\r
{\r
- string tempPath = "";\r
- if (file == "hb_queue_recovery.dat")\r
- tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");\r
- else\r
- tempPath = file;\r
- using (StreamWriter writer = new StreamWriter(tempPath))\r
+ using (FileStream strm = new FileStream(tempPath, FileMode.Create, FileAccess.Write))\r
{\r
- foreach (ArrayList item in queue)\r
- {\r
- writer.WriteLine(item[1].ToString());\r
- }\r
- writer.Close();\r
- writer.Dispose();\r
+ ser.Serialize(strm, queue);\r
+ strm.Close();\r
+ strm.Dispose();\r
}\r
}\r
catch (Exception)\r
{\r
- // Any Errors will be out of diskspace/permissions problems. Don't report them as they'll annoy the user.\r
+ // Any Errors will be out of diskspace/permissions problems. \r
+ // Don't report them as they'll annoy the user.\r
}\r
}\r
\r
public void writeBatchScript(string file)\r
{\r
string queries = "";\r
- foreach (ArrayList queue_item in queue)\r
+ foreach (QueueItem queue_item in queue)\r
{\r
- string q_item = queue_item[1].ToString();\r
+ string q_item = queue_item.Query;\r
string fullQuery = '"' + Application.StartupPath.ToString() + "\\HandBrakeCLI.exe" + '"' + q_item;\r
\r
if (queries == string.Empty)\r
}\r
\r
/// <summary>\r
- /// Recover the queue from hb_queue_recovery.dat\r
+ /// Recover the queue from hb_queue_recovery.xml\r
/// </summary>\r
public void recoverQueue(string file)\r
{\r
- try\r
+ string tempPath = "";\r
+ if (file == "hb_queue_recovery.xml")\r
+ tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");\r
+ else\r
+ tempPath = file;\r
+\r
+ if (File.Exists(tempPath))\r
{\r
- string tempPath = "";\r
- if (file == "hb_queue_recovery.dat")\r
- tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");\r
- else\r
- tempPath = file;\r
- using (StreamReader reader = new StreamReader(tempPath))\r
+ using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))\r
{\r
- string queue_item = reader.ReadLine();\r
-\r
- while (queue_item != null)\r
+ if (strm.Length != 0)\r
{\r
- this.add(queue_item);\r
- queue_item = reader.ReadLine();\r
+ List<QueueItem> list = ser.Deserialize(strm) as List<QueueItem>;\r
+\r
+ foreach (QueueItem item in list)\r
+ queue.Add(item);\r
}\r
}\r
}\r
- catch (Exception exc)\r
- {\r
- MessageBox.Show("HandBrake was unable to recover the queue. \nError Information:" + exc.ToString(), "Queue Recovery Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
- }\r
}\r
-\r
}\r
}\r
--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Text;\r
+\r
+namespace Handbrake.Queue\r
+{\r
+ public class QueueItem\r
+ {\r
+ private int id;\r
+ private string query;\r
+ private string source;\r
+ private string destination;\r
+\r
+ /// <summary>\r
+ /// Get or Set the job id.\r
+ /// </summary>\r
+ public int Id\r
+ {\r
+ get { return id; }\r
+ set { this.id = value; }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get or Set the query string.\r
+ /// </summary>\r
+ public string Query\r
+ {\r
+ get { return query; }\r
+ set { this.query = value; }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get or set the source file of encoding\r
+ /// </summary>\r
+ public string Source\r
+ {\r
+ get { return source; }\r
+ set { this.source = value; }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Get or set the destination for the file to be encoded.\r
+ /// </summary>\r
+ public string Destination\r
+ {\r
+ get { return destination; }\r
+ set { this.destination = value; }\r
+ }\r
+ }\r
+}\r
// Objects which may be used by one or more other objects\r
Functions.Main hb_common_func = new Functions.Main();\r
Functions.Encode cliObj = new Functions.Encode();\r
- Functions.Queue encodeQueue = new Functions.Queue();\r
+ Queue.Queue encodeQueue = new Queue.Queue();\r
Presets.PresetsHandler presetHandler = new Presets.PresetsHandler();\r
Parsing.Title selectedTitle;\r
\r
DialogResult result = MessageBox.Show("HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?", "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
\r
if (result == DialogResult.Yes)\r
- encodeQueue.recoverQueue("hb_queue_recovery.dat"); // Start Recovery\r
+ encodeQueue.recoverQueue("hb_queue_recovery.xml"); // Start Recovery\r
else\r
{\r
// Remove the Queue recovery file if the user doesn't want to recovery the last queue.\r
- string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");\r
+ string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");\r
if (File.Exists(queuePath))\r
File.Delete(queuePath);\r
}\r
if (rtf_query.Text != "")\r
query = rtf_query.Text;\r
\r
- encodeQueue.add(query);\r
- encodeQueue.write2disk("hb_queue_recovery.dat"); // Writes the queue to the recovery file, just incase the GUI crashes.\r
+ encodeQueue.add(query, text_source.Text, text_destination.Text);\r
+ encodeQueue.write2disk("hb_queue_recovery.xml"); // Writes the queue to the recovery file, just incase the GUI crashes.\r
\r
queueWindow.setQueue(encodeQueue);\r
queueWindow.Show();\r
\r
// After the encode is done, we may want to shutdown, suspend etc.\r
cliObj.addCLIQueryToLog((string)state);\r
- cliObj.copyLog((string)state); // Make a copy of the log in the users desired location if necessary\r
+ cliObj.copyLog((string)state, text_destination.Text); // Make a copy of the log in the users desired location if necessary\r
cliObj.afterEncodeAction();\r
}\r
}\r
Functions.Encode cliObj = new Functions.Encode();\r
Boolean cancel = false;\r
Process hbProc = null;\r
- Functions.Queue queue;\r
+ Queue.Queue queue;\r
frmMain mainWindow = null;\r
\r
public frmQueue(frmMain main)\r
/// Initializes the Queue list with the Arraylist from the Queue class\r
/// </summary>\r
/// <param name="qw"></param>\r
- public void setQueue(Functions.Queue qw)\r
+ public void setQueue(Queue.Queue qw)\r
{\r
queue = qw;\r
redrawQueue();\r
lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";\r
+\r
+ // Recalculate the progress bar, but only if the queue has already started. \r
+ if (progressBar.Value != 0)\r
+ {\r
+ progressBar.Value = 0;\r
+ progressBar.Step = 100 / queue.count();\r
+ progressBar.PerformStep();\r
+ lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);\r
+ }\r
}\r
\r
/// <summary>\r
private void redrawQueue()\r
{\r
list_queue.Items.Clear();\r
- ArrayList theQueue = queue.getQueue();\r
- foreach (ArrayList queue_item in theQueue)\r
+ List<Queue.QueueItem> theQueue = queue.getQueue();\r
+ foreach (Queue.QueueItem queue_item in theQueue)\r
{\r
- string q_item = queue_item[1].ToString();\r
+ string q_item = queue_item.Query;\r
Functions.QueryParser parsed = Functions.QueryParser.Parse(q_item);\r
\r
// Get the DVD Title\r
ListViewItem item = new ListViewItem();\r
item.Text = title; // Title\r
item.SubItems.Add(chapters); // Chapters\r
- item.SubItems.Add(parsed.Source); // Source\r
- item.SubItems.Add(parsed.Destination); // Destination\r
+ item.SubItems.Add(queue_item.Source); // Source\r
+ item.SubItems.Add(queue_item.Destination); // Destination\r
item.SubItems.Add(parsed.VideoEncoder); // Video\r
item.SubItems.Add(parsed.AudioEncoder1); // Audio\r
\r
while (queue.count() != 0)\r
{\r
string query = queue.getNextItemForEncoding();\r
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file\r
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file\r
\r
setEncValue();\r
updateUIElements();\r
\r
hbProc.WaitForExit();\r
cliObj.addCLIQueryToLog(query);\r
- cliObj.copyLog(query);\r
+ cliObj.copyLog(query, queue.getLastQuery().Destination);\r
\r
hbProc.Close();\r
hbProc.Dispose();\r
}\r
\r
// found query is a global varible\r
- Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.getLastQuery());\r
- lbl_source.Text = parsed.Source;\r
- lbl_dest.Text = parsed.Destination;\r
+ Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.getLastQuery().Query);\r
+ lbl_source.Text = queue.getLastQuery().Source;\r
+ lbl_dest.Text = queue.getLastQuery().Destination;\r
\r
\r
if (parsed.DVDTitle == 0)\r
int selected = list_queue.SelectedIndices[0];\r
\r
queue.moveUp(selected);\r
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file\r
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file\r
redrawQueue();\r
\r
if (selected - 1 > 0) \r
int selected = list_queue.SelectedIndices[0];\r
\r
queue.moveDown(list_queue.SelectedIndices[0]);\r
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file\r
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file\r
redrawQueue();\r
\r
if (selected +1 < list_queue.Items.Count) \r
if (list_queue.SelectedIndices.Count != 0)\r
{\r
queue.remove(list_queue.SelectedIndices[0]);\r
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file\r
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file\r
redrawQueue();\r
lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";\r
}\r
if (list_queue.SelectedIndices.Count != 0)\r
{\r
queue.remove(list_queue.SelectedIndices[0]);\r
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file\r
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file\r
redrawQueue();\r
}\r
}\r
base.OnClosing(e);\r
}\r
\r
-\r
}\r
}
\ No newline at end of file