diff options
author | sr55 <[email protected]> | 2012-03-19 20:18:46 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2012-03-19 20:18:46 +0000 |
commit | 582d0170487c8dcd113cae0e0b38345226f3147e (patch) | |
tree | 5b1f9ea1fae5652418b22bb2e103e886fdf26fba /win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs | |
parent | 4ff24a85e32d10ee8ab5ed524ec03e3f22da92e1 (diff) |
WinGui: (WPF) Started implementing the startup procedure: Update checking, Preset updates, CLI monitoring.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4517 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs b/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs index 11917e771..2e5398cd0 100644 --- a/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/UpdateCheckHelper.cs @@ -14,8 +14,10 @@ namespace HandBrakeWPF.Helpers using Caliburn.Micro;
+ using HandBrake.ApplicationServices;
using HandBrake.ApplicationServices.Model.General;
using HandBrake.ApplicationServices.Services;
+ using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrakeWPF.Services.Interfaces;
@@ -25,12 +27,77 @@ namespace HandBrakeWPF.Helpers public class UpdateCheckHelper
{
/// <summary>
+ /// Perform a startup update check. Abiding by user settings.
+ /// </summary>
+ public static void PerformStartupUpdateCheck()
+ {
+ // Make sure it's running on the calling thread
+ IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.UpdateStatus))
+ {
+ if (DateTime.Now.Subtract(userSettingService.GetUserSetting<DateTime>(UserSettingConstants.LastUpdateCheckDate)).TotalDays
+ > userSettingService.GetUserSetting<int>(UserSettingConstants.DaysBetweenUpdateCheck))
+ {
+ userSettingService.SetUserSetting(UserSettingConstants.LastUpdateCheckDate, DateTime.Now);
+ string url = userSettingService.GetUserSetting<string>(ASUserSettingConstants.HandBrakePlatform).Contains("x86_64")
+ ? userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_x64)
+ : userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_i686);
+ UpdateService.BeginCheckForUpdates(UpdateCheckDone, false,
+ url, userSettingService.GetUserSetting<int>(ASUserSettingConstants.HandBrakeBuild),
+ userSettingService.GetUserSetting<int>(UserSettingConstants.Skipversion));
+ }
+ }
+ }
+
+ /// <summary>
+ /// Check for Updates.
+ /// </summary>
+ public static void CheckForUpdates()
+ {
+ IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+ userSettingService.SetUserSetting(UserSettingConstants.LastUpdateCheckDate, DateTime.Now);
+ string url = userSettingService.GetUserSetting<string>(ASUserSettingConstants.HandBrakePlatform).Contains("x86_64")
+ ? userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_x64)
+ : userSettingService.GetUserSetting<string>(UserSettingConstants.Appcast_i686);
+ UpdateService.BeginCheckForUpdates(UpdateCheckDoneMenu, false,
+ url, userSettingService.GetUserSetting<int>(ASUserSettingConstants.HandBrakeBuild),
+ userSettingService.GetUserSetting<int>(UserSettingConstants.Skipversion));
+ }
+
+ /// <summary>
+ /// Handle the Update Check Finishing.
+ /// </summary>
+ /// <param name="result">
+ /// The result.
+ /// </param>
+ private static void UpdateCheckDone(IAsyncResult result)
+ {
+ // Make sure it's running on the calling thread
+ IErrorService errorService = IoC.Get<IErrorService>();
+ try
+ {
+ // Get the information about the new build, if any, and close the window
+ UpdateCheckInformation info = UpdateService.EndCheckForUpdates(result);
+
+ if (info.NewVersionAvailable)
+ {
+ errorService.ShowMessageBox(
+ "A New Update is Available", "Update available!", MessageBoxButton.OK, MessageBoxImage.Information);
+ }
+ }
+ catch (Exception ex)
+ {
+ errorService.ShowError("Unable to check for updates", "Please try again later, the update service may currently be down.", ex);
+ }
+ }
+
+ /// <summary>
/// Handle the Update Check Finishing.
/// </summary>
/// <param name="result">
/// The result.
/// </param>
- public static void UpdateCheckDoneMenu(IAsyncResult result)
+ private static void UpdateCheckDoneMenu(IAsyncResult result)
{
// Make sure it's running on the calling thread
IErrorService errorService = IoC.Get<IErrorService>();
@@ -49,7 +116,6 @@ namespace HandBrakeWPF.Helpers errorService.ShowMessageBox(
"There is no new version at this time.", "No Updates", MessageBoxButton.OK, MessageBoxImage.Information);
}
- return;
}
catch (Exception ex)
{
|