From 7be6051e420dba45add0a213f12f143b898f5d7a Mon Sep 17 00:00:00 2001 From: sr55 Date: Thu, 21 Jan 2010 20:47:15 +0000 Subject: [PATCH] WinGui: - Some code refactoring. git-svn-id: svn://localhost/HandBrake/trunk@3081 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/EncodeQueue/Encode.cs | 29 +++++++++++++++++++++------ win/C#/EncodeQueue/Job.cs | 1 - win/C#/EncodeQueue/Queue.cs | 9 ++------- win/C#/Functions/AppcastReader.cs | 41 ++++++++++++++++++++------------------- win/C#/Functions/Main.cs | 5 ++--- win/C#/frmActivityWindow.cs | 2 +- win/C#/frmPreview.cs | 2 +- win/C#/frmUpdater.cs | 12 ++++++------ 8 files changed, 56 insertions(+), 45 deletions(-) diff --git a/win/C#/EncodeQueue/Encode.cs b/win/C#/EncodeQueue/Encode.cs index 8beca3fe..49a836bb 100644 --- a/win/C#/EncodeQueue/Encode.cs +++ b/win/C#/EncodeQueue/Encode.cs @@ -14,20 +14,38 @@ namespace Handbrake.EncodeQueue { public class Encode { + private int ProcessID { get; set; } + + /// + /// The HB Process + /// public Process HbProcess { get; set; } - public int ProcessID { get; set; } + + /// + /// The Process Handle + /// public IntPtr ProcessHandle { get; set; } - public String CurrentQuery { get; set; } - public Boolean IsEncoding { get; set; } + + /// + /// Returns true of HandBrakeCLI.exe is running + /// + public Boolean IsEncoding { get; set; } + /// + /// Fires when a new CLI Job starts + /// public event EventHandler EncodeStarted; + + /// + /// Fires when a CLI job finishes. + /// public event EventHandler EncodeEnded; /// /// Create a preview sample video /// /// - public void CreatePreviewSampe(string query) + public void CreatePreviewSample(string query) { Run(query); } @@ -63,7 +81,7 @@ namespace Handbrake.EncodeQueue Process[] before = Process.GetProcesses(); // Get a list of running processes before starting. HbProcess = Process.Start(cliStart); ProcessID = Main.GetCliProcess(before); - CurrentQuery = query; + if (HbProcess != null) ProcessHandle = HbProcess.MainWindowHandle; // Set the process Handle @@ -125,7 +143,6 @@ namespace Handbrake.EncodeQueue protected void Finish() { IsEncoding = false; - CurrentQuery = String.Empty; //Growl if (Properties.Settings.Default.growlQueue) diff --git a/win/C#/EncodeQueue/Job.cs b/win/C#/EncodeQueue/Job.cs index 5771ece8..7dfe7e51 100644 --- a/win/C#/EncodeQueue/Job.cs +++ b/win/C#/EncodeQueue/Job.cs @@ -5,7 +5,6 @@ It may be used under the terms of the GNU General Public License. */ using System; -using Handbrake.Parsing; namespace Handbrake.EncodeQueue { diff --git a/win/C#/EncodeQueue/Queue.cs b/win/C#/EncodeQueue/Queue.cs index 0372d90b..87db876d 100644 --- a/win/C#/EncodeQueue/Queue.cs +++ b/win/C#/EncodeQueue/Queue.cs @@ -12,7 +12,6 @@ using System.Threading; using System.Windows.Forms; using System.Xml.Serialization; using Handbrake.Functions; -using Handbrake.Parsing; namespace Handbrake.EncodeQueue { @@ -316,13 +315,9 @@ namespace Handbrake.EncodeQueue } /// - /// Stops the current job. + /// Run through all the jobs on the queue. /// - public void End() - { - Stop(); - } - + /// private void StartQueue(object state) { // Run through each item on the queue diff --git a/win/C#/Functions/AppcastReader.cs b/win/C#/Functions/AppcastReader.cs index 7f1e90b8..ea9cac11 100644 --- a/win/C#/Functions/AppcastReader.cs +++ b/win/C#/Functions/AppcastReader.cs @@ -16,7 +16,7 @@ namespace Handbrake.Functions /// /// Get the build information from the required appcasts. Run before accessing the public vars. /// - public void getInfo(string input) + public void GetInfo(string input) { try { @@ -28,13 +28,14 @@ namespace Handbrake.Functions Match ver = Regex.Match(result, @"sparkle:version=""([0-9]*)\"""); Match verShort = Regex.Match(result, @"sparkle:shortVersionString=""(([svn]*)([0-9.\s]*))\"""); - build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""); - version = verShort.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", ""); - downloadFile = nodeItem["windows"].InnerText; - descriptionUrl = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText); - } catch( Exception) + Build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""); + Version = verShort.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", ""); + DownloadFile = nodeItem["windows"].InnerText; + DescriptionUrl = new Uri(nodeItem["sparkle:releaseNotesLink"].InnerText); + } + catch( Exception) { - // Ignore Error. + return; } } @@ -51,24 +52,24 @@ namespace Handbrake.Functions XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssReader); - for (int i = 0; i < rssDoc.ChildNodes.Count; i++) + foreach (XmlNode t in rssDoc.ChildNodes) { - if (rssDoc.ChildNodes[i].Name == "rss") - nodeRss = rssDoc.ChildNodes[i]; + if (t.Name == "rss") + nodeRss = t; } if (nodeRss != null) - for (int i = 0; i < nodeRss.ChildNodes.Count; i++) + foreach (XmlNode t in nodeRss.ChildNodes) { - if (nodeRss.ChildNodes[i].Name == "channel") - nodeChannel = nodeRss.ChildNodes[i]; + if (t.Name == "channel") + nodeChannel = t; } if (nodeChannel != null) - for (int i = 0; i < nodeChannel.ChildNodes.Count; i++) + foreach (XmlNode t in nodeChannel.ChildNodes) { - if (nodeChannel.ChildNodes[i].Name == "item") - nodeItem = nodeChannel.ChildNodes[i]; + if (t.Name == "item") + nodeItem = t; } return nodeItem; @@ -77,21 +78,21 @@ namespace Handbrake.Functions /// /// Get Information about an update to HandBrake /// - public Uri descriptionUrl { get; set; } + public Uri DescriptionUrl { get; set; } /// /// Get HandBrake's version from the appcast.xml file. /// - public string version { get; set; } + public string Version { get; set; } /// /// Get HandBrake's Build from the appcast.xml file. /// - public string build { get; set; } + public string Build { get; set; } /// /// Get's the URL for update file. /// - public string downloadFile { get; set; } + public string DownloadFile { get; set; } } } \ No newline at end of file diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index f2187676..e9c4442b 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -373,7 +373,6 @@ namespace Handbrake.Functions } } - /// /// Begins checking for an update to HandBrake. /// @@ -394,10 +393,10 @@ namespace Handbrake.Functions AppcastReader reader = new AppcastReader(); // Get the data, convert it to a string, and parse it into the AppcastReader - reader.getInfo(new StreamReader(response.GetResponseStream()).ReadToEnd()); + reader.GetInfo(new StreamReader(response.GetResponseStream()).ReadToEnd()); // Further parse the information - string build = reader.build; + string build = reader.Build; int latest = int.Parse(build); int current = Properties.Settings.Default.hb_build; diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs index a4d5cd21..ca4edcfd 100644 --- a/win/C#/frmActivityWindow.cs +++ b/win/C#/frmActivityWindow.cs @@ -105,7 +105,7 @@ namespace Handbrake sr.Dispose(); } - catch (Exception exc) + catch (Exception) { Reset(); appendText = new StringBuilder(); diff --git a/win/C#/frmPreview.cs b/win/C#/frmPreview.cs index 8cd51a67..6118b43d 100644 --- a/win/C#/frmPreview.cs +++ b/win/C#/frmPreview.cs @@ -110,7 +110,7 @@ namespace Handbrake MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning); else { - Process.CreatePreviewSampe((string)state); + Process.CreatePreviewSample((string)state); if (Process.HbProcess != null) { Process.HbProcess.WaitForExit(); diff --git a/win/C#/frmUpdater.cs b/win/C#/frmUpdater.cs index 816e00fa..12376068 100644 --- a/win/C#/frmUpdater.cs +++ b/win/C#/frmUpdater.cs @@ -12,31 +12,31 @@ namespace Handbrake { public partial class frmUpdater : Form { - readonly AppcastReader _appcast; + readonly AppcastReader Appcast; public frmUpdater(AppcastReader reader) { InitializeComponent(); - _appcast = reader; + Appcast = reader; GetRss(); SetVersions(); } private void GetRss() { - wBrowser.Url = _appcast.descriptionUrl; + wBrowser.Url = Appcast.DescriptionUrl; } private void SetVersions() { string old = "(You have: " + Properties.Settings.Default.hb_version.Trim() + " / " + Properties.Settings.Default.hb_build.ToString().Trim() + ")"; - string newBuild = _appcast.version.Trim() + " (" + _appcast.build + ")"; + string newBuild = Appcast.Version.Trim() + " (" + Appcast.Build + ")"; lbl_update_text.Text = "HandBrake " + newBuild + " is now available. " + old; } private void btn_installUpdate_Click(object sender, EventArgs e) { - frmDownload download = new frmDownload(_appcast.downloadFile); + frmDownload download = new frmDownload(Appcast.DownloadFile); download.ShowDialog(); this.Close(); } @@ -48,7 +48,7 @@ namespace Handbrake private void btn_skip_Click(object sender, EventArgs e) { - Properties.Settings.Default.skipversion = int.Parse(_appcast.build); + Properties.Settings.Default.skipversion = int.Parse(Appcast.Build); Properties.Settings.Default.Save(); this.Close(); -- 2.11.0