diff options
author | sr55 <[email protected]> | 2009-07-04 14:24:59 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2009-07-04 14:24:59 +0000 |
commit | bdf19259ac2d6ac94abf0fad38ce6c98e3e58460 (patch) | |
tree | 3b92fa3d9ef24eeb3e71a45574b1c7f96d720558 /win/C#/frmMain.cs | |
parent | f3ea70992ab591a46754f68f5b7b02ca9d0529cc (diff) |
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://svn.handbrake.fr/HandBrake/trunk@2661 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/frmMain.cs')
-rw-r--r-- | win/C#/frmMain.cs | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index cf919abc4..5da52c61d 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
|