summaryrefslogtreecommitdiffstats
path: root/win/C#/HandBrake.ApplicationServices/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2011-03-13 12:35:48 +0000
committersr55 <[email protected]>2011-03-13 12:35:48 +0000
commit57224a250b66b28bed628f587486197c9900bc1d (patch)
tree1e8a04f83cacafcd70b1eea74a4d76913875d34d /win/C#/HandBrake.ApplicationServices/Services
parentfdc4b3187ae9c825793e9e665c5e0d4bc5ccbc25 (diff)
WinGui:
- Shuffle some more code around. Aiming to remove the framework library completely soon. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3842 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/HandBrake.ApplicationServices/Services')
-rw-r--r--win/C#/HandBrake.ApplicationServices/Services/UpdateService.cs97
1 files changed, 97 insertions, 0 deletions
diff --git a/win/C#/HandBrake.ApplicationServices/Services/UpdateService.cs b/win/C#/HandBrake.ApplicationServices/Services/UpdateService.cs
new file mode 100644
index 000000000..5e65021e5
--- /dev/null
+++ b/win/C#/HandBrake.ApplicationServices/Services/UpdateService.cs
@@ -0,0 +1,97 @@
+namespace HandBrake.ApplicationServices.Services
+{
+ using System;
+ using System.IO;
+ using System.Net;
+ using System.Threading;
+
+ using HandBrake.ApplicationServices.Model.General;
+ using HandBrake.ApplicationServices.Utilities;
+
+ /// <summary>
+ /// The Update Service
+ /// </summary>
+ public class UpdateService
+ {
+ /// <summary>
+ /// Begins checking for an update to HandBrake.
+ /// </summary>
+ /// <param name="callback">
+ /// The method that will be called when the check is finished.
+ /// </param>
+ /// <param name="debug">
+ /// Whether or not to execute this in debug mode.
+ /// </param>
+ /// <param name="url">
+ /// The url.
+ /// </param>
+ /// <param name="currentBuild">
+ /// The current Build.
+ /// </param>
+ /// <param name="skipBuild">
+ /// The skip Build.
+ /// </param>
+ /// <param name="currentVersion">
+ /// The current Version.
+ /// </param>
+ public static void BeginCheckForUpdates(AsyncCallback callback, bool debug, string url, int currentBuild, int skipBuild, string currentVersion)
+ {
+ ThreadPool.QueueUserWorkItem(delegate
+ {
+ try
+ {
+ // 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.GetUpdateInfo(new StreamReader(response.GetResponseStream()).ReadToEnd());
+
+ // Further parse the information
+ string build = reader.Build;
+
+ int latest = int.Parse(build);
+ int current = currentBuild;
+ int skip = skipBuild;
+
+ // If the user wanted to skip this version, don't report the update
+ if (latest == skip)
+ {
+ UpdateCheckInformation info = new UpdateCheckInformation { NewVersionAvailable = false };
+ callback(new UpdateCheckResult(debug, info));
+ return;
+ }
+
+ UpdateCheckInformation info2 = new UpdateCheckInformation
+ {
+ NewVersionAvailable = latest > current,
+ DescriptionUrl = reader.DescriptionUrl,
+ DownloadFile = reader.DownloadFile,
+ Build = reader.Build,
+ Version = reader.Version,
+ };
+ callback(new UpdateCheckResult(debug, info2));
+ }
+ catch (Exception exc)
+ {
+ callback(new UpdateCheckResult(debug, new UpdateCheckInformation { Error = exc }));
+ }
+ });
+ }
+
+ /// <summary>
+ /// End Check for Updates
+ /// </summary>
+ /// <param name="result">
+ /// The result.
+ /// </param>
+ /// <returns>
+ /// Update Check information
+ /// </returns>
+ public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result)
+ {
+ return ((UpdateCheckResult)result).Result;
+ }
+ }
+}