From: sr55 Date: Wed, 26 Nov 2008 19:32:53 +0000 (+0000) Subject: WinGui: X-Git-Tag: 0.9.4~999 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e8b7af4abd15d0035f69ebd96cc592e171d2ae43;p=handbrake WinGui: - The Queue Recovery, inport/export features now use an XML based file system rather than text file. - Queue now uses class based Queue Items for storing data rather than an arraylist. - Fixes an issue where the source and/or destination would not show up in the list of queue items. - Queue progress meter will now update correctly if a user adds more items to the queue after starting the queue. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1958 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/win/C#/Functions/Encode.cs b/win/C#/Functions/Encode.cs index 0445392d0..471acb586 100644 --- a/win/C#/Functions/Encode.cs +++ b/win/C#/Functions/Encode.cs @@ -133,7 +133,7 @@ namespace Handbrake.Functions /// if this feature is enabled in options. /// /// - public void copyLog(string query) + public void copyLog(string query, string destination) { // The user may wish to do something with the log. if (Properties.Settings.Default.saveLog == "Checked") @@ -143,7 +143,7 @@ namespace Handbrake.Functions if (Properties.Settings.Default.saveLogWithVideo == "Checked") { - string[] destName = parsed.Destination.Split('\\'); + string[] destName = destination.Split('\\'); string destinationFile = ""; for (int i = 0; i < destName.Length - 1; i++) { @@ -156,7 +156,7 @@ namespace Handbrake.Functions } else if (Properties.Settings.Default.saveLogPath != String.Empty) { - string[] destName = parsed.Destination.Split('\\'); + string[] destName = destination.Split('\\'); string dest = destName[destName.Length - 1]; string filename = DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + " " + dest + ".txt"; string useDefinedLogPath = Path.Combine(Properties.Settings.Default.saveLogPath, filename); diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index f8600d3e9..0a202b15d 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -13,11 +13,16 @@ using System.IO; using System.Drawing; using System.Diagnostics; using System.Text.RegularExpressions; +using System.Collections.Generic; +using System.Xml.Serialization; namespace Handbrake.Functions { class Main { + // Private Variables + private static XmlSerializer ser = new XmlSerializer(typeof(List)); + /// /// Calculate the duration of the selected title and chapters /// @@ -361,28 +366,21 @@ namespace Handbrake.Functions { try { - string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat"); - using (StreamReader reader = new StreamReader(tempPath)) + string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml"); + if (File.Exists(tempPath)) { - string queue_item = reader.ReadLine(); - if (queue_item == null) - { - reader.Close(); - reader.Dispose(); - return false; - } - else // There exists an item in the recovery queue file, so try and recovr it. + using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read)) { - reader.Close(); - reader.Dispose(); - return true; + List list = ser.Deserialize(strm) as List; + if (list.Count != 0) + return true; } } + return false; } catch (Exception) { - // Keep quiet about the error. - return false; + return false; // Keep quiet about the error. } } diff --git a/win/C#/Functions/QueryParser.cs b/win/C#/Functions/QueryParser.cs index 3e8b18ebe..b2d2ee661 100644 --- a/win/C#/Functions/QueryParser.cs +++ b/win/C#/Functions/QueryParser.cs @@ -19,20 +19,6 @@ namespace Handbrake.Functions #region Varibles #region Source - - private string q_source; - /// - /// Returns a String - /// Full path of the source. - /// - public string Source - { - get - { - return this.q_source; - } - } - private int q_dvdTitle; /// /// Returns an Integer @@ -74,20 +60,6 @@ namespace Handbrake.Functions #endregion #region Destination - - private string q_destination; - /// - /// Returns a String - /// Full path of the destination. - /// - public string Destination - { - get - { - return this.q_destination; - } - } - private string q_format; /// /// Returns a String @@ -811,16 +783,16 @@ namespace Handbrake.Functions QueryParser thisQuery = new QueryParser(); #region Regular Expressions + // Useful Destination Finder + //Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9?';!^%&*()_\-:\\\s\.]+)(?:\"")"); + //Match source = r1.Match(input.Replace('"', '\"')); + //Source - Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9_\-:\\\s\.]+)(?:\"")"); - Match source = r1.Match(input.Replace('"', '\"')); Match title = Regex.Match(input, @"-t ([0-9]*)"); Match chapters = Regex.Match(input, @"-c ([0-9-]*)"); Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)"); //Destination - Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9_\-:\\\s\.]+)(?:\"")"); - Match destination = r2.Match(input.Replace('"', '\"')); Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)"); //Picture Settings Tab @@ -896,12 +868,9 @@ namespace Handbrake.Functions #region Set Varibles try { - #region Source Tab - - thisQuery.q_source = source.ToString().Replace("-i ", "").Replace("\"", ""); if (title.Success != false) - thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", "")); + thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", "")); if (chapters.Success != false) { @@ -923,11 +892,8 @@ namespace Handbrake.Functions #endregion #region Destination - thisQuery.q_destination = destination.ToString().Replace("-o ", "").Replace("\"", ""); - - string videoEncoderConvertion; - videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", ""); + string videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", ""); switch (videoEncoderConvertion) { case "ffmpeg": diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index df5258c1d..64d5d69ec 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -90,12 +90,6 @@ x86 - - 3.0 - - - 3.0 - @@ -103,13 +97,7 @@ - - - 3.0 - - - 3.0 - + @@ -166,7 +154,7 @@ - + @@ -250,6 +238,7 @@ frmSplashScreen.cs + diff --git a/win/C#/Functions/Queue.cs b/win/C#/Queue/QueueHandler.cs similarity index 61% rename from win/C#/Functions/Queue.cs rename to win/C#/Queue/QueueHandler.cs index 3afca7d3e..6810dec5f 100644 --- a/win/C#/Functions/Queue.cs +++ b/win/C#/Queue/QueueHandler.cs @@ -4,16 +4,18 @@ using System.Text; using System.Collections; using System.IO; using System.Windows.Forms; +using System.Xml.Serialization; -namespace Handbrake.Functions +namespace Handbrake.Queue { public class Queue { - ArrayList queue = new ArrayList(); - ArrayList lastQuery; + private static XmlSerializer ser = new XmlSerializer(typeof(List)); + List queue = new List(); int id = 0; // Unique identifer number for each job + private QueueItem lastItem; - public ArrayList getQueue() + public List getQueue() { return queue; } @@ -22,24 +24,35 @@ namespace Handbrake.Functions /// Get's the next CLI query for encoding /// /// String - public String getNextItemForEncoding() + public string getNextItemForEncoding() { - Object query = queue[0]; - lastQuery = (ArrayList)query; + QueueItem job = queue[0]; + String query = job.Query; + lastItem = job; remove(0); // Remove the item which we are about to pass out. - return lastQuery[1].ToString(); + return query; + } + + /// + /// Get the last query that was returned by getNextItemForEncoding() + /// + /// + public QueueItem getLastQuery() + { + return lastItem; } /// /// Add's a new item to the queue /// /// String - public void add(string query) + public void add(string query, string source, string destination) { - // Creates a new job with a unique identifer and cli query - ArrayList newJob = new ArrayList(); - newJob.Add(id); - newJob.Add(query); + QueueItem newJob = new QueueItem(); + newJob.Id = id; + newJob.Query = query; + newJob.Source = source; + newJob.Destination = destination; id++; // Adds the job to the queue @@ -66,15 +79,6 @@ namespace Handbrake.Functions return queue.Count; } - /// - /// Get's the last query to be selected for encoding by getNextItemForEncoding() - /// - /// String - public string getLastQuery() - { - return lastQuery[1].ToString(); - } - /// /// Move an item with an index x, up in the queue /// @@ -83,7 +87,7 @@ namespace Handbrake.Functions { if (index != 0) { - ArrayList item = (ArrayList)queue[index]; + QueueItem item = (QueueItem)queue[index]; queue.Insert((index - 1), item); queue.RemoveAt((index + 1)); @@ -98,7 +102,7 @@ namespace Handbrake.Functions { if (index != queue.Count - 1) { - ArrayList item = (ArrayList)queue[index]; + QueueItem item = (QueueItem)queue[index]; queue.Insert((index + 2), item); queue.RemoveAt((index)); @@ -106,31 +110,30 @@ namespace Handbrake.Functions } /// - /// Writes the current queue to disk. hb_queue_recovery.dat + /// Writes the current queue to disk. hb_queue_recovery.xml /// This function is called after getNextItemForEncoding() /// public void write2disk(string file) { + string tempPath = ""; + if (file == "hb_queue_recovery.xml") + tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml"); + else + tempPath = file; + try { - string tempPath = ""; - if (file == "hb_queue_recovery.dat") - tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat"); - else - tempPath = file; - using (StreamWriter writer = new StreamWriter(tempPath)) + using (FileStream strm = new FileStream(tempPath, FileMode.Create, FileAccess.Write)) { - foreach (ArrayList item in queue) - { - writer.WriteLine(item[1].ToString()); - } - writer.Close(); - writer.Dispose(); + ser.Serialize(strm, queue); + strm.Close(); + strm.Dispose(); } } catch (Exception) { - // Any Errors will be out of diskspace/permissions problems. Don't report them as they'll annoy the user. + // Any Errors will be out of diskspace/permissions problems. + // Don't report them as they'll annoy the user. } } @@ -141,9 +144,9 @@ namespace Handbrake.Functions public void writeBatchScript(string file) { string queries = ""; - foreach (ArrayList queue_item in queue) + foreach (QueueItem queue_item in queue) { - string q_item = queue_item[1].ToString(); + string q_item = queue_item.Query; string fullQuery = '"' + Application.StartupPath.ToString() + "\\HandBrakeCLI.exe" + '"' + q_item; if (queries == string.Empty) @@ -174,33 +177,29 @@ namespace Handbrake.Functions } /// - /// Recover the queue from hb_queue_recovery.dat + /// Recover the queue from hb_queue_recovery.xml /// public void recoverQueue(string file) { - try + string tempPath = ""; + if (file == "hb_queue_recovery.xml") + tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml"); + else + tempPath = file; + + if (File.Exists(tempPath)) { - string tempPath = ""; - if (file == "hb_queue_recovery.dat") - tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat"); - else - tempPath = file; - using (StreamReader reader = new StreamReader(tempPath)) + using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read)) { - string queue_item = reader.ReadLine(); - - while (queue_item != null) + if (strm.Length != 0) { - this.add(queue_item); - queue_item = reader.ReadLine(); + List list = ser.Deserialize(strm) as List; + + foreach (QueueItem item in list) + queue.Add(item); } } } - catch (Exception exc) - { - MessageBox.Show("HandBrake was unable to recover the queue. \nError Information:" + exc.ToString(), "Queue Recovery Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } } - } } diff --git a/win/C#/Queue/QueueItem.cs b/win/C#/Queue/QueueItem.cs new file mode 100644 index 000000000..1639b168b --- /dev/null +++ b/win/C#/Queue/QueueItem.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Handbrake.Queue +{ + public class QueueItem + { + private int id; + private string query; + private string source; + private string destination; + + /// + /// Get or Set the job id. + /// + public int Id + { + get { return id; } + set { this.id = value; } + } + + /// + /// Get or Set the query string. + /// + public string Query + { + get { return query; } + set { this.query = value; } + } + + /// + /// Get or set the source file of encoding + /// + public string Source + { + get { return source; } + set { this.source = value; } + } + + /// + /// Get or set the destination for the file to be encoded. + /// + public string Destination + { + get { return destination; } + set { this.destination = value; } + } + } +} diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 149664600..59ae27ba2 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -25,7 +25,7 @@ namespace Handbrake // Objects which may be used by one or more other objects Functions.Main hb_common_func = new Functions.Main(); Functions.Encode cliObj = new Functions.Encode(); - Functions.Queue encodeQueue = new Functions.Queue(); + Queue.Queue encodeQueue = new Queue.Queue(); Presets.PresetsHandler presetHandler = new Presets.PresetsHandler(); Parsing.Title selectedTitle; @@ -184,11 +184,11 @@ namespace Handbrake 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); if (result == DialogResult.Yes) - encodeQueue.recoverQueue("hb_queue_recovery.dat"); // Start Recovery + encodeQueue.recoverQueue("hb_queue_recovery.xml"); // Start Recovery else { // Remove the Queue recovery file if the user doesn't want to recovery the last queue. - string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat"); + string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml"); if (File.Exists(queuePath)) File.Delete(queuePath); } @@ -397,8 +397,8 @@ namespace Handbrake if (rtf_query.Text != "") query = rtf_query.Text; - encodeQueue.add(query); - encodeQueue.write2disk("hb_queue_recovery.dat"); // Writes the queue to the recovery file, just incase the GUI crashes. + encodeQueue.add(query, text_source.Text, text_destination.Text); + encodeQueue.write2disk("hb_queue_recovery.xml"); // Writes the queue to the recovery file, just incase the GUI crashes. queueWindow.setQueue(encodeQueue); queueWindow.Show(); @@ -1919,7 +1919,7 @@ namespace Handbrake // After the encode is done, we may want to shutdown, suspend etc. cliObj.addCLIQueryToLog((string)state); - cliObj.copyLog((string)state); // Make a copy of the log in the users desired location if necessary + cliObj.copyLog((string)state, text_destination.Text); // Make a copy of the log in the users desired location if necessary cliObj.afterEncodeAction(); } } diff --git a/win/C#/frmQueue.cs b/win/C#/frmQueue.cs index 88acf24e9..765c940b7 100644 --- a/win/C#/frmQueue.cs +++ b/win/C#/frmQueue.cs @@ -26,7 +26,7 @@ namespace Handbrake Functions.Encode cliObj = new Functions.Encode(); Boolean cancel = false; Process hbProc = null; - Functions.Queue queue; + Queue.Queue queue; frmMain mainWindow = null; public frmQueue(frmMain main) @@ -39,11 +39,20 @@ namespace Handbrake /// Initializes the Queue list with the Arraylist from the Queue class /// /// - public void setQueue(Functions.Queue qw) + public void setQueue(Queue.Queue qw) { queue = qw; redrawQueue(); lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending"; + + // Recalculate the progress bar, but only if the queue has already started. + if (progressBar.Value != 0) + { + progressBar.Value = 0; + progressBar.Step = 100 / queue.count(); + progressBar.PerformStep(); + lbl_progressValue.Text = string.Format("{0} %", progressBar.Value); + } } /// @@ -62,10 +71,10 @@ namespace Handbrake private void redrawQueue() { list_queue.Items.Clear(); - ArrayList theQueue = queue.getQueue(); - foreach (ArrayList queue_item in theQueue) + List theQueue = queue.getQueue(); + foreach (Queue.QueueItem queue_item in theQueue) { - string q_item = queue_item[1].ToString(); + string q_item = queue_item.Query; Functions.QueryParser parsed = Functions.QueryParser.Parse(q_item); // Get the DVD Title @@ -89,8 +98,8 @@ namespace Handbrake ListViewItem item = new ListViewItem(); item.Text = title; // Title item.SubItems.Add(chapters); // Chapters - item.SubItems.Add(parsed.Source); // Source - item.SubItems.Add(parsed.Destination); // Destination + item.SubItems.Add(queue_item.Source); // Source + item.SubItems.Add(queue_item.Destination); // Destination item.SubItems.Add(parsed.VideoEncoder); // Video item.SubItems.Add(parsed.AudioEncoder1); // Audio @@ -139,7 +148,7 @@ namespace Handbrake while (queue.count() != 0) { string query = queue.getNextItemForEncoding(); - queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file + queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file setEncValue(); updateUIElements(); @@ -148,7 +157,7 @@ namespace Handbrake hbProc.WaitForExit(); cliObj.addCLIQueryToLog(query); - cliObj.copyLog(query); + cliObj.copyLog(query, queue.getLastQuery().Destination); hbProc.Close(); hbProc.Dispose(); @@ -255,9 +264,9 @@ namespace Handbrake } // found query is a global varible - Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.getLastQuery()); - lbl_source.Text = parsed.Source; - lbl_dest.Text = parsed.Destination; + Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.getLastQuery().Query); + lbl_source.Text = queue.getLastQuery().Source; + lbl_dest.Text = queue.getLastQuery().Destination; if (parsed.DVDTitle == 0) @@ -295,7 +304,7 @@ namespace Handbrake int selected = list_queue.SelectedIndices[0]; queue.moveUp(selected); - queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file + queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file redrawQueue(); if (selected - 1 > 0) @@ -313,7 +322,7 @@ namespace Handbrake int selected = list_queue.SelectedIndices[0]; queue.moveDown(list_queue.SelectedIndices[0]); - queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file + queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file redrawQueue(); if (selected +1 < list_queue.Items.Count) @@ -329,7 +338,7 @@ namespace Handbrake if (list_queue.SelectedIndices.Count != 0) { queue.remove(list_queue.SelectedIndices[0]); - queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file + queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file redrawQueue(); lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending"; } @@ -373,7 +382,7 @@ namespace Handbrake if (list_queue.SelectedIndices.Count != 0) { queue.remove(list_queue.SelectedIndices[0]); - queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file + queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file redrawQueue(); } } @@ -393,6 +402,5 @@ namespace Handbrake base.OnClosing(e); } - } } \ No newline at end of file