From: sr55 Date: Sat, 4 Jul 2009 14:24:59 +0000 (+0000) Subject: WinGui: X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=d646c74eab71ce803181537759b19c9b2726fc0a;p=handbrake-jp%2Fhandbrake-jp-git.git WinGui: - Update checker code cleaned up and multi-threaded. (Thanks to darkassassin ) Made some minor changes to this code to fit it in. http://forum.handbrake.fr/viewtopic.php?f=4&t=11353 - Queue window no longer takes focus on each new addition to the queue. ( Quite annoying otherwise ) git-svn-id: svn://localhost/HandBrake/trunk@2661 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/win/C#/Controls/x264Panel.Designer.cs b/win/C#/Controls/x264Panel.Designer.cs index 379b3dcb..2c7d6cf4 100644 --- a/win/C#/Controls/x264Panel.Designer.cs +++ b/win/C#/Controls/x264Panel.Designer.cs @@ -698,6 +698,7 @@ namespace Handbrake.Controls // x264Panel // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.BackColor = System.Drawing.Color.Transparent; this.Controls.Add(this.slider_psytrellis); this.Controls.Add(this.lbl_psytrellis); this.Controls.Add(this.lbl_psyrd); diff --git a/win/C#/Controls/x264Panel.resx b/win/C#/Controls/x264Panel.resx index 8dca4f1d..dbd32d12 100644 --- a/win/C#/Controls/x264Panel.resx +++ b/win/C#/Controls/x264Panel.resx @@ -120,9 +120,6 @@ 17, 17 - - 17, 17 - Psychovisual Rate Distortion Optimization sure is a mouthful, isn't it? Basically, it means x264 tries to retain detail, for better quality to the human eye, as opposed to trying to maximize quality the way a computer understands it, through signal-to-noise ratios that have trouble telling apart fine detail and noise. diff --git a/win/C#/Functions/AppcastReader.cs b/win/C#/Functions/AppcastReader.cs index 94425859..861bd0ba 100644 --- a/win/C#/Functions/AppcastReader.cs +++ b/win/C#/Functions/AppcastReader.cs @@ -7,6 +7,7 @@ using System; using System.Xml; using System.Text.RegularExpressions; +using System.IO; namespace Handbrake.Functions { @@ -15,15 +16,15 @@ namespace Handbrake.Functions /// /// Get the build information from the required appcasts. Run before accessing the public vars. /// - public void getInfo() + public void getInfo(string input) { // Get the correct Appcast and set input. - XmlNode nodeItem = Properties.Settings.Default.hb_build.ToString().EndsWith("1") ? readRss(new XmlTextReader(Properties.Settings.Default.appcast_unstable)) : readRss(new XmlTextReader(Properties.Settings.Default.appcast)); - string input = nodeItem.InnerXml; + XmlNode nodeItem = readRss(new XmlTextReader(new StringReader(input))); + string result = nodeItem.InnerXml; // Regular Expressions - Match ver = Regex.Match(input, @"sparkle:version=""([0-9]*)\"""); - Match verShort = Regex.Match(input, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\"""); + Match ver = Regex.Match(result, @"sparkle:version=""([0-9]*)\"""); + Match verShort = Regex.Match(result, @"sparkle:shortVersionString=""([0-9].[0-9].[0-9]*)\"""); build = ver.ToString().Replace("sparkle:version=", "").Replace("\"", ""); version = verShort.ToString().Replace("sparkle:shortVersionString=", "").Replace("\"", ""); diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index 04d4d16b..1b223bab 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Xml.Serialization; using System.Threading; using Handbrake.EncodeQueue; +using System.Net; namespace Handbrake.Functions { @@ -189,40 +190,6 @@ namespace Handbrake.Functions } /// - /// Checks for updates and returns true if an update is available. - /// - /// Turns on debug mode. Don't use on program startup - /// Boolean True = Update available - public static Boolean updateCheck(Boolean debug) - { - try - { - AppcastReader rssRead = new AppcastReader(); - rssRead.getInfo(); // Initializes the class. - string build = rssRead.build; - - int latest = int.Parse(build); - int current = Properties.Settings.Default.hb_build; - int skip = Properties.Settings.Default.skipversion; - - if (latest == skip) - return false; - - Properties.Settings.Default.lastUpdateCheckDate = DateTime.Now; - Properties.Settings.Default.Save(); - - Boolean update = (latest > current); - return update; - } - catch (Exception exc) - { - if (debug) - MessageBox.Show("Unable to check for updates, Please try again later. \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - } - - /// /// Get's HandBrakes version data from the CLI. /// /// Arraylist of Version Data. 0 = hb_version 1 = hb_build @@ -370,5 +337,92 @@ namespace Handbrake.Functions } } + /// + /// Begins checking for an update to HandBrake. + /// + /// The method that will be called when the check is finished. + /// Whether or not to execute this in debug mode. + public static void BeginCheckForUpdates(AsyncCallback callback, bool debug) + { + ThreadPool.QueueUserWorkItem(new WaitCallback(delegate + { + try + { + // Is this a stable or unstable build? + string url = Properties.Settings.Default.hb_build.ToString().EndsWith("1") ? Properties.Settings.Default.appcast_unstable : Properties.Settings.Default.appcast; + + // Initialize variables + WebRequest request = WebRequest.Create(url); + WebResponse response = request.GetResponse(); + 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()); + + // Further parse the information + string build = reader.build; + + int latest = int.Parse(build); + int current = Properties.Settings.Default.hb_build; + int skip = Properties.Settings.Default.skipversion; + + // If the user wanted to skip this version, don't report the update + if (latest == skip) + { + UpdateCheckInformation info = new UpdateCheckInformation() { NewVersionAvailable = false, BuildInformation = null }; + callback(new UpdateCheckResult(debug, info)); + return; + } + + // Set when the last update was + Properties.Settings.Default.lastUpdateCheckDate = DateTime.Now; + Properties.Settings.Default.Save(); + + UpdateCheckInformation info2 = new UpdateCheckInformation() { NewVersionAvailable = latest > current, BuildInformation = reader }; + callback(new UpdateCheckResult(debug, info2)); + } + catch (Exception exc) + { + callback(new UpdateCheckResult(debug, new UpdateCheckInformation() { Error = exc })); + } + })); + } + + /// + /// + /// + /// + /// + public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result) + { + UpdateCheckResult checkResult = (UpdateCheckResult)result; + return checkResult.Result; + } + + /// + /// Used in EndUpdateCheck() for update checking and the IAsyncResult design pattern. + /// + private class UpdateCheckResult : IAsyncResult + { + public UpdateCheckResult(object asyncState, UpdateCheckInformation info) + { + AsyncState = asyncState; + Result = info; + } + + /// + /// Gets whether the check was executed in debug mode. + /// + public object AsyncState { get; private set; } + + /// + /// Gets the result of the update check. + /// + public UpdateCheckInformation Result { get; private set; } + + public WaitHandle AsyncWaitHandle { get { throw new NotImplementedException(); } } + public bool CompletedSynchronously { get { throw new NotImplementedException(); } } + public bool IsCompleted { get { throw new NotImplementedException(); } } + } } } diff --git a/win/C#/Functions/UpdateCheckInformation.cs b/win/C#/Functions/UpdateCheckInformation.cs new file mode 100644 index 00000000..25381786 --- /dev/null +++ b/win/C#/Functions/UpdateCheckInformation.cs @@ -0,0 +1,23 @@ +using System; + +namespace Handbrake.Functions +{ + /// + /// Provides information about an update check. + /// + public struct UpdateCheckInformation + { + public bool NewVersionAvailable { get; set; } + public bool ErrorOccured { get { return Error != null; } } + + /// + /// Gets information about the new build, if any. This will be null if there is no new verison. + /// + public AppcastReader BuildInformation { get; set; } + + /// + /// Gets the error that occurred, if any. This will be null if no error occured. + /// + public Exception Error { get; set; } + } +} diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index 824d9708..76666f2b 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -193,6 +193,7 @@ + diff --git a/win/C#/frmMain.Designer.cs b/win/C#/frmMain.Designer.cs index 83751198..d7b522eb 100644 --- a/win/C#/frmMain.Designer.cs +++ b/win/C#/frmMain.Designer.cs @@ -158,6 +158,7 @@ namespace Handbrake this.lbl_source = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.groupBox_output = new System.Windows.Forms.Label(); + this.lbl_updateCheck = new System.Windows.Forms.ToolStripStatusLabel(); this.PictureSettings = new Handbrake.Controls.PictureSettings(); this.Filters = new Handbrake.Controls.Filters(); this.AudioSettings = new Handbrake.Controls.AudioPanel(); @@ -793,6 +794,7 @@ namespace Handbrake // Label47 // this.Label47.AutoSize = true; + this.Label47.BackColor = System.Drawing.Color.Transparent; this.Label47.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label47.ForeColor = System.Drawing.Color.Black; this.Label47.Location = new System.Drawing.Point(13, 39); @@ -859,17 +861,19 @@ namespace Handbrake // radio_cq // this.radio_cq.AutoSize = true; + this.radio_cq.BackColor = System.Drawing.Color.Transparent; this.radio_cq.Location = new System.Drawing.Point(336, 97); this.radio_cq.Name = "radio_cq"; this.radio_cq.Size = new System.Drawing.Size(125, 17); this.radio_cq.TabIndex = 18; this.radio_cq.Text = "Constant Quality:"; - this.radio_cq.UseVisualStyleBackColor = true; + this.radio_cq.UseVisualStyleBackColor = false; this.radio_cq.CheckedChanged += new System.EventHandler(this.radio_cq_CheckedChanged); // // radio_avgBitrate // this.radio_avgBitrate.AutoSize = true; + this.radio_avgBitrate.BackColor = System.Drawing.Color.Transparent; this.radio_avgBitrate.Checked = true; this.radio_avgBitrate.Location = new System.Drawing.Point(336, 64); this.radio_avgBitrate.Name = "radio_avgBitrate"; @@ -877,18 +881,19 @@ namespace Handbrake this.radio_avgBitrate.TabIndex = 17; this.radio_avgBitrate.TabStop = true; this.radio_avgBitrate.Text = "Avg Bitrate (kbps):"; - this.radio_avgBitrate.UseVisualStyleBackColor = true; + this.radio_avgBitrate.UseVisualStyleBackColor = false; this.radio_avgBitrate.CheckedChanged += new System.EventHandler(this.radio_avgBitrate_CheckedChanged); // // radio_targetFilesize // this.radio_targetFilesize.AutoSize = true; + this.radio_targetFilesize.BackColor = System.Drawing.Color.Transparent; this.radio_targetFilesize.Location = new System.Drawing.Point(336, 37); this.radio_targetFilesize.Name = "radio_targetFilesize"; this.radio_targetFilesize.Size = new System.Drawing.Size(126, 17); this.radio_targetFilesize.TabIndex = 16; this.radio_targetFilesize.Text = "Target Size (MB):"; - this.radio_targetFilesize.UseVisualStyleBackColor = true; + this.radio_targetFilesize.UseVisualStyleBackColor = false; this.radio_targetFilesize.CheckedChanged += new System.EventHandler(this.radio_targetFilesize_CheckedChanged); // // label25 @@ -1370,10 +1375,12 @@ namespace Handbrake // StatusStrip // this.StatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.lbl_encode}); + this.lbl_encode, + this.lbl_updateCheck}); this.StatusStrip.Location = new System.Drawing.Point(0, 599); this.StatusStrip.Name = "StatusStrip"; this.StatusStrip.Size = new System.Drawing.Size(1000, 22); + this.StatusStrip.SizingGrip = false; this.StatusStrip.TabIndex = 7; this.StatusStrip.Text = "statusStrip1"; // @@ -1434,6 +1441,16 @@ namespace Handbrake this.groupBox_output.TabIndex = 47; this.groupBox_output.Text = "Output Settings: (Preset: None)"; // + // lbl_updateCheck + // + this.lbl_updateCheck.BackColor = System.Drawing.Color.Transparent; + this.lbl_updateCheck.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.lbl_updateCheck.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbl_updateCheck.Name = "lbl_updateCheck"; + this.lbl_updateCheck.Size = new System.Drawing.Size(139, 17); + this.lbl_updateCheck.Text = "Checking for Updates ..."; + this.lbl_updateCheck.Visible = false; + // // PictureSettings // this.PictureSettings.BackColor = System.Drawing.Color.Transparent; @@ -1468,6 +1485,7 @@ namespace Handbrake // // x264Panel // + this.x264Panel.BackColor = System.Drawing.Color.Transparent; this.x264Panel.Location = new System.Drawing.Point(0, 0); this.x264Panel.Name = "x264Panel"; this.x264Panel.Size = new System.Drawing.Size(720, 306); @@ -1509,7 +1527,9 @@ namespace Handbrake this.Controls.Add(this.frmMainMenu); this.Controls.Add(this.StatusStrip); this.DoubleBuffered = true; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MaximizeBox = false; this.Name = "frmMain"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "HandBrake"; @@ -1668,6 +1688,7 @@ namespace Handbrake internal Label lbl_source; private Label label4; internal Label groupBox_output; + private ToolStripStatusLabel lbl_updateCheck; } diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index cf919abc..5da52c61 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -36,7 +36,6 @@ namespace Handbrake // Delegates ********************************************************** private delegate void UpdateWindowHandler(); - private delegate void UpdateStatusChanger(); // Applicaiton Startup ************************************************ @@ -72,8 +71,7 @@ namespace Handbrake lblStatus.Text = "Checking for updates ..."; Application.DoEvents(); - Thread updateCheckThread = new Thread(startupUpdateCheck); - updateCheckThread.Start(); + Main.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false); } } @@ -131,29 +129,34 @@ namespace Handbrake queueRecovery(); } - // Startup Functions - private void startupUpdateCheck() + private void UpdateCheckDone(IAsyncResult result) { + if (InvokeRequired) + { + Invoke(new MethodInvoker(() => UpdateCheckDone(result))); + return; + } + + UpdateCheckInformation info; + try { - if (InvokeRequired) - { - BeginInvoke(new UpdateStatusChanger(startupUpdateCheck)); - return; - } + info = Main.EndCheckForUpdates(result); - Boolean update = Main.updateCheck(false); - if (update) + if (info.NewVersionAvailable) { - frmUpdater updateWindow = new frmUpdater(); - updateWindow.Show(); + frmUpdater updateWindow = new frmUpdater(info.BuildInformation); + updateWindow.ShowDialog(); } } - catch (Exception exc) + catch (Exception ex) { - MessageBox.Show(splash, "Unable to perform update check. If this problem persists, you can turn of update checking in the program options. \nError Information: \n\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + if ((bool)result.AsyncState) + MessageBox.Show("Unable to check for updates, Please try again later. \n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + // Startup Functions private void queueRecovery() { if (Main.check_queue_recovery()) @@ -393,19 +396,46 @@ namespace Handbrake } private void mnu_UpdateCheck_Click(object sender, EventArgs e) { - Boolean update = Main.updateCheck(true); - if (update) + Main.BeginCheckForUpdates(new AsyncCallback(updateCheckDoneMenu), false); + } + private void updateCheckDoneMenu(IAsyncResult result) + { + // Make sure it's running on the calling thread + if (InvokeRequired) { - frmUpdater updateWindow = new frmUpdater(); - updateWindow.Show(); + Invoke(new MethodInvoker(() => updateCheckDoneMenu(result))); + return; + } + + UpdateCheckInformation info; + + try + { + // Get the information about the new build, if any, and close the window + info = Main.EndCheckForUpdates(result); + lbl_updateCheck.Visible = true; + if (info.NewVersionAvailable && info.BuildInformation != null) + { + frmUpdater updateWindow = new frmUpdater(info.BuildInformation); + updateWindow.ShowDialog(); + } + else + MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information); + lbl_updateCheck.Visible = false; + return; + } + catch (Exception ex) + { + if ((bool)result.AsyncState) + MessageBox.Show("Unable to check for updates, Please try again later. \n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } - else - MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void mnu_about_Click(object sender, EventArgs e) { - Form About = new frmAbout(); - About.ShowDialog(); + using (frmAbout About = new frmAbout()) + { + About.ShowDialog(); + } } #endregion diff --git a/win/C#/frmMain.resx b/win/C#/frmMain.resx index 400badba..ffd42bef 100644 --- a/win/C#/frmMain.resx +++ b/win/C#/frmMain.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 977, 15 + 17, 54 False @@ -157,10 +157,10 @@ Note: Do not change any of the chapter numbers! 106, 15 - 123, 52 + 392, 54 - 1224, 15 + 265, 54 767, 15 @@ -566,10 +566,10 @@ Note: Do not change any of the chapter numbers! - 1113, 15 + 155, 54 - 308, 52 + 595, 54 98 diff --git a/win/C#/frmQueue.cs b/win/C#/frmQueue.cs index 13c0e1f3..c7b280ef 100644 --- a/win/C#/frmQueue.cs +++ b/win/C#/frmQueue.cs @@ -22,21 +22,21 @@ namespace Handbrake InitializeComponent(); this.queue = q; - queue.OnEncodeStart += new EventHandler(queue_OnEncodeStart); - queue.OnQueueFinished += new EventHandler(queue_OnQueueFinished); - queue.OnPaused += new EventHandler(queue_OnPaused); + queue.OnEncodeStart += new EventHandler(queueOnEncodeStart); + queue.OnQueueFinished += new EventHandler(queueOnQueueFinished); + queue.OnPaused += new EventHandler(queueOnPaused); } - void queue_OnPaused(object sender, EventArgs e) + void queueOnPaused(object sender, EventArgs e) { setUIEncodeFinished(); updateUIElements(); } - void queue_OnQueueFinished(object sender, EventArgs e) + void queueOnQueueFinished(object sender, EventArgs e) { setUIEncodeFinished(); resetQueue(); // Reset the Queue Window } - void queue_OnEncodeStart(object sender, EventArgs e) + void queueOnEncodeStart(object sender, EventArgs e) { setUIEncodeStarted(); // make sure the UI is set correctly setCurrentEncodeInformation(); @@ -56,7 +56,7 @@ namespace Handbrake /// public new void Show() { - Show(true); + Show(true); } /// @@ -67,7 +67,8 @@ namespace Handbrake { if (doSetQueue) setQueue(); base.Show(); - Activate(); + + //Activate(); } // Start and Stop Controls diff --git a/win/C#/frmUpdater.cs b/win/C#/frmUpdater.cs index 97a5c9a6..789a620f 100644 --- a/win/C#/frmUpdater.cs +++ b/win/C#/frmUpdater.cs @@ -12,12 +12,12 @@ namespace Handbrake { public partial class frmUpdater : Form { - AppcastReader appcast = new AppcastReader(); - public frmUpdater() + AppcastReader appcast; + public frmUpdater(AppcastReader reader) { InitializeComponent(); - appcast.getInfo(); // Initializes the appcast + appcast = reader; getRss(); setVersions(); } @@ -37,7 +37,7 @@ namespace Handbrake private void btn_installUpdate_Click(object sender, EventArgs e) { frmDownload download = new frmDownload(appcast.downloadFile); - download.Show(); + download.ShowDialog(); this.Close(); }