Exemple #1
0
        /// <summary>
        /// Handle the Update Check Finishing.
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        private static void UpdateCheckDoneMenu(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);
                }
                else
                {
                    errorService.ShowMessageBox(
                        "There is no new version at this time.", "No Updates", 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);
            }
        }
Exemple #2
0
        /// <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()
                                ? Constants.Appcast64
                                : Constants.Appcast32;

                        var currentBuild =
                            this.userSettingService.GetUserSetting<int>(UserSettingConstants.HandBrakeBuild);
                        var skipBuild = this.userSettingService.GetUserSetting<int>(
                            UserSettingConstants.Skipversion);

                        // 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;
                        int skip = skipBuild;

                        // If the user wanted to skip this version, don't report the update
                        if (latest == skip)
                        {
                            var info = new UpdateCheckInformation { NewVersionAvailable = false };
                            callback(info);
                            return;
                        }

                        var info2 = new UpdateCheckInformation
                            {
                                NewVersionAvailable = latest > current,
                                DescriptionUrl = reader.DescriptionUrl,
                                DownloadFile = reader.DownloadFile,
                                Build = reader.Build,
                                Version = reader.Version,
                            };

                        callback(info2);
                    }
                    catch (Exception exc)
                    {
                        callback(new UpdateCheckInformation { NewVersionAvailable = false, Error = exc });
                    }
                });
        }
Exemple #3
0
        /// <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
                    });
                }
            });
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UpdateInfo"/> class.
        /// </summary>
        /// <param name="reader">
        /// The appcast reader.
        /// </param>
        /// <param name="currentVersion">
        /// The current Version.
        /// </param>
        /// <param name="currentBuild">
        /// The current Build.
        /// </param>
        public UpdateInfo(UpdateCheckInformation reader, string currentVersion, string currentBuild)
        {
            InitializeComponent();

            appcast             = reader;
            this.currentVersion = currentVersion;
            this.currentBuild   = currentBuild;
            GetRss();
            SetVersions();
        }
Exemple #5
0
        /*
         * TODO: Refactor this to use Caliburn Invocation
         */

        /// <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>
        public static void BeginCheckForUpdates(AsyncCallback callback, bool debug, string url, int currentBuild, int skipBuild)
        {
            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>
 /// Update Check Complete
 /// </summary>
 /// <param name="info">
 /// The info.
 /// </param>
 private void UpdateCheckComplete(UpdateCheckInformation info)
 {
     this.updateInfo = info;
     if (info.NewVersionAvailable)
     {
         this.UpdateMessage   = Resources.OptionsViewModel_NewUpdate;
         this.UpdateAvailable = true;
     }
     else if (Environment.Is64BitOperatingSystem && !System.Environment.Is64BitProcess)
     {
         this.UpdateMessage   = Resources.OptionsViewModel_64bitAvailable;
         this.UpdateAvailable = true;
     }
     else
     {
         this.UpdateMessage   = Resources.OptionsViewModel_NoNewUpdates;
         this.UpdateAvailable = false;
     }
 }
Exemple #7
0
        /// <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
                    });
                }
            });
        }