+ /// <summary>\r
+ /// Begins checking for an update to HandBrake.\r
+ /// </summary>\r
+ /// <param name="callback">The method that will be called when the check is finished.</param>\r
+ /// <param name="debug">Whether or not to execute this in debug mode.</param>\r
+ public static void BeginCheckForUpdates(AsyncCallback callback, bool debug)\r
+ {\r
+ ThreadPool.QueueUserWorkItem(new WaitCallback(delegate\r
+ {\r
+ try\r
+ {\r
+ // Is this a stable or unstable build?\r
+ string url = Properties.Settings.Default.hb_build.ToString().EndsWith("1") ? Properties.Settings.Default.appcast_unstable : Properties.Settings.Default.appcast;\r
+\r
+ // Initialize variables\r
+ WebRequest request = WebRequest.Create(url);\r
+ WebResponse response = request.GetResponse();\r
+ AppcastReader reader = new AppcastReader();\r
+\r
+ // Get the data, convert it to a string, and parse it into the AppcastReader\r
+ reader.getInfo(new StreamReader(response.GetResponseStream()).ReadToEnd());\r
+\r
+ // Further parse the information\r
+ string build = reader.build;\r
+\r
+ int latest = int.Parse(build);\r
+ int current = Properties.Settings.Default.hb_build;\r
+ int skip = Properties.Settings.Default.skipversion;\r
+\r
+ // If the user wanted to skip this version, don't report the update\r
+ if (latest == skip)\r
+ {\r
+ UpdateCheckInformation info = new UpdateCheckInformation() { NewVersionAvailable = false, BuildInformation = null };\r
+ callback(new UpdateCheckResult(debug, info));\r
+ return;\r
+ }\r
+\r
+ // Set when the last update was\r
+ Properties.Settings.Default.lastUpdateCheckDate = DateTime.Now;\r
+ Properties.Settings.Default.Save();\r
+\r
+ UpdateCheckInformation info2 = new UpdateCheckInformation() { NewVersionAvailable = latest > current, BuildInformation = reader };\r
+ callback(new UpdateCheckResult(debug, info2));\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ callback(new UpdateCheckResult(debug, new UpdateCheckInformation() { Error = exc }));\r
+ }\r
+ }));\r
+ }\r
+\r
+ /// <summary>\r
+ /// \r
+ /// </summary>\r
+ /// <param name="result"></param>\r
+ /// <returns></returns>\r
+ public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result)\r
+ {\r
+ UpdateCheckResult checkResult = (UpdateCheckResult)result;\r
+ return checkResult.Result;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Used in EndUpdateCheck() for update checking and the IAsyncResult design pattern.\r
+ /// </summary>\r
+ private class UpdateCheckResult : IAsyncResult\r
+ {\r
+ public UpdateCheckResult(object asyncState, UpdateCheckInformation info)\r
+ {\r
+ AsyncState = asyncState;\r
+ Result = info;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Gets whether the check was executed in debug mode.\r
+ /// </summary>\r
+ public object AsyncState { get; private set; }\r
+\r
+ /// <summary>\r
+ /// Gets the result of the update check.\r
+ /// </summary>\r
+ public UpdateCheckInformation Result { get; private set; }\r
+\r
+ public WaitHandle AsyncWaitHandle { get { throw new NotImplementedException(); } }\r
+ public bool CompletedSynchronously { get { throw new NotImplementedException(); } }\r
+ public bool IsCompleted { get { throw new NotImplementedException(); } }\r
+ }\r