Represents an update available for the application.
        /// <summary>
        /// Initialises a new instance of the <see cref="UpdateInformationDialog"/> class.
        /// </summary>
        /// <param name="update">The update to show information about.</param>
        public UpdateInformationDialog(ProgramUpdate update)
        {
            this.InitializeComponent();

            this.client = new WebClient();
            this.client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.Client_DownloadProgressChanged);
            this.client.DownloadFileCompleted += new AsyncCompletedEventHandler(this.Client_DownloadFileCompleted);

            this.update = update;

            this.update.ReleaseNotes.ForEach(notes =>
            {
                string section = string.Format(
                    "-- Version {0}, Released {1} --\r\n{2}\r\n\r\n",
                    notes.Version,
                    notes.Date,
                    notes.Summary.Replace("\n", Environment.NewLine));

                this.summaryTextBox.Text += section;
            });

            this.Localise();
        }
Example #2
0
 /// <summary>
 /// Handles the DoWork event of System.ComponentModel.BackgroundWorker.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The event arguments.</param>
 private void UpdateCheckBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     ProgramUpdate update = new ProgramUpdate();
     if (update.Fetch())
     {
         Version executingVersion = Assembly.GetExecutingAssembly().GetName().Version;
         Version updateVersion = new Version(update.Version);
         if (executingVersion < updateVersion)
         {
             update.FetchReleaseNotes(executingVersion);
             e.Result = update;
         }
         else
         {
             e.Result = null;
         }
     }
     else
     {
         e.Result = false;
     }
 }
        /// <summary>
        /// Validates the integrity of an update file.
        /// </summary>
        /// <param name="fileName">The full path of the local file to validate.</param>
        /// <param name="update">The upgrade the file is associated with.</param>
        /// <returns>true if the hashes match, false if not.</returns>
        private bool ValidateUpgradeFile(string fileName, ProgramUpdate update)
        {
            bool retval = false;

            if (File.Exists(fileName))
            {
                SHA1Managed sha1 = new SHA1Managed();
                StringBuilder sb = new StringBuilder(41);
                byte[] data = File.ReadAllBytes(fileName);
                byte[] hash = sha1.ComputeHash(data);

                for (int i = 0; i < hash.Length; i++)
                {
                    sb.Append(hash[i].ToString("X2"));
                }

                retval = sb.ToString().Equals(update.Hash, StringComparison.OrdinalIgnoreCase);
            }

            return retval;
        }