/// <summary> /// Check for Updates /// </summary> /// <param name="callback"> /// The callback. /// </param> public void CheckForUpdates(Action <UpdateCheckInformation> callback) { ThreadPool.QueueUserWorkItem( delegate { try { string url = VersionHelper.Is64Bit() || Environment.Is64BitOperatingSystem ? Constants.Appcast64 : Constants.Appcast32; if (VersionHelper.IsNightly()) { url = VersionHelper.Is64Bit() || Environment.Is64BitOperatingSystem ? Constants.AppcastUnstable64 : Constants.AppcastUnstable32; } var currentBuild = HandBrakeUtils.Build; // Initialize variables WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); var 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; var info2 = new UpdateCheckInformation { NewVersionAvailable = latest > current, DescriptionUrl = reader.DescriptionUrl, DownloadFile = reader.DownloadFile, Build = reader.Build, Version = reader.Version, ExpectedSHA1Hash = reader.Hash }; callback(info2); } catch (Exception exc) { callback(new UpdateCheckInformation { NewVersionAvailable = false, Error = exc }); } }); }
/// <summary> /// Check for Updates /// </summary> /// <param name="callback"> /// The callback. /// </param> public void CheckForUpdates(Action <UpdateCheckInformation> callback) { ThreadPool.QueueUserWorkItem( delegate { try { // Figure out which appcast we want to read. string url = VersionHelper.Is64Bit() || Environment.Is64BitOperatingSystem ? Constants.Appcast64 : Constants.Appcast32; if (VersionHelper.IsNightly()) { url = VersionHelper.Is64Bit() || Environment.Is64BitOperatingSystem ? Constants.AppcastUnstable64 : Constants.AppcastUnstable32; } var currentBuild = HandBrakeUtils.Build; // Fetch the Appcast from our server. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AllowAutoRedirect = false; // We will never do this. request.UserAgent = string.Format("HandBrake Win Upd {0}", VersionHelper.GetVersionShort()); WebResponse response = request.GetResponse(); // Parse the data with the AppcastReader var reader = new AppcastReader(); reader.GetUpdateInfo(new StreamReader(response.GetResponseStream()).ReadToEnd()); // Further parse the information string build = reader.Build; int latest = int.Parse(build); int current = currentBuild; // Security Check // Verify the download URL is for handbrake.fr and served over https. // This prevents a compromised appcast download tricking the GUI into downloading a file, or accessing another website or local network resource. Uri uriResult; bool result = Uri.TryCreate(reader.DownloadFile, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttps; if (!result || (uriResult.Host != "handbrake.fr" && uriResult.Host != "download.handbrake.fr")) { callback(new UpdateCheckInformation { NewVersionAvailable = false, Error = new Exception("The HandBrake update service is currently unavailable.") }); return; } // Validate the URL from the appcast is ours. var info2 = new UpdateCheckInformation { NewVersionAvailable = latest > current, DescriptionUrl = reader.DescriptionUrl, DownloadFile = reader.DownloadFile, Build = reader.Build, Version = reader.Version, Signature = reader.Hash }; callback(info2); } catch (Exception exc) { callback(new UpdateCheckInformation { NewVersionAvailable = false, Error = exc }); } }); }
/// <summary> /// Check for Updates /// </summary> /// <param name="callback"> /// The callback. /// </param> public void CheckForUpdates(Action<UpdateCheckInformation> callback) { ThreadPool.QueueUserWorkItem( delegate { try { string url = VersionHelper.Is64Bit() || Environment.Is64BitOperatingSystem ? Constants.Appcast64 : Constants.Appcast32; if (VersionHelper.IsNightly()) { url = VersionHelper.Is64Bit() || Environment.Is64BitOperatingSystem ? Constants.AppcastUnstable64 : Constants.AppcastUnstable32; } var currentBuild = HandBrakeUtils.Build; // Initialize variables WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); var 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; var info2 = new UpdateCheckInformation { NewVersionAvailable = latest > current, DescriptionUrl = reader.DescriptionUrl, DownloadFile = reader.DownloadFile, Build = reader.Build, Version = reader.Version, Signature = reader.Hash }; callback(info2); } catch (Exception exc) { callback(new UpdateCheckInformation { NewVersionAvailable = false, Error = exc }); } }); }
/// <summary> /// Check for Updates /// </summary> /// <param name="callback"> /// The callback. /// </param> public void CheckForUpdates(Action<UpdateCheckInformation> callback) { ThreadPool.QueueUserWorkItem( delegate { try { // Figure out which appcast we want to read. string url = VersionHelper.Is64Bit() || Environment.Is64BitOperatingSystem ? Constants.Appcast64 : Constants.Appcast32; if (VersionHelper.IsNightly()) { url = VersionHelper.Is64Bit() || Environment.Is64BitOperatingSystem ? Constants.AppcastUnstable64 : Constants.AppcastUnstable32; } var currentBuild = HandBrakeUtils.Build; // Fetch the Appcast from our server. HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); request.AllowAutoRedirect = false; // We will never do this. WebResponse response = request.GetResponse(); // Parse the data with the AppcastReader var reader = new AppcastReader(); reader.GetUpdateInfo(new StreamReader(response.GetResponseStream()).ReadToEnd()); // Further parse the information string build = reader.Build; int latest = int.Parse(build); int current = currentBuild; // Security Check // Verify the download URL is for handbrake.fr and served over https. // This prevents a compromised appcast download tricking the GUI into downloading a file, or accessing another website or local network resource. Uri uriResult; bool result = Uri.TryCreate(reader.DownloadFile, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttps; if (!result || (uriResult.Host != "handbrake.fr" && uriResult.Host != "download.handbrake.fr")) { callback(new UpdateCheckInformation { NewVersionAvailable = false, Error = new Exception("The HandBrake update service is currently unavailable.") }); return; } // Validate the URL from the appcast is ours. var info2 = new UpdateCheckInformation { NewVersionAvailable = latest > current, DescriptionUrl = reader.DescriptionUrl, DownloadFile = reader.DownloadFile, Build = reader.Build, Version = reader.Version, Signature = reader.Hash }; callback(info2); } catch (Exception exc) { callback(new UpdateCheckInformation { NewVersionAvailable = false, Error = exc }); } }); }