/// <summary>
 /// Sets all control texts from source file
 /// </summary>
 private void SetControlText()
 {
     this.Title = ResourceEnabler.GetResourceText("RemindLaterFormTitle");
     this.lblUpdateQuestion.Text    = ResourceEnabler.GetResourceText("RemindLaterFormUpdateQuestion");
     this.lblWarning.Text           = ResourceEnabler.GetResourceText("UpdateRecommendationWarning");
     this.lblOkButton.Text          = ResourceEnabler.GetResourceText("OkButtonText");
     this.rdoYesRemindLater.Content = ResourceEnabler.GetResourceText("UpdateLaterRadioButtonContent");
     this.rdoNoDownload.Content     = ResourceEnabler.GetResourceText("DownloadNowRadioButtonContent");
 }
        /// <summary>
        /// Initializes a new instances of <see cref="RemindLaterForm"/> class
        /// </summary>
        public RemindLaterForm()
        {
            this.SetLanguageDictionary();
            InitializeComponent();

            this.SetControlText();

            var remindLaterList = ResourceEnabler.GetResourceText("RemindLaterList");
            var list            = remindLaterList.Split(new char[] { ',' }).ToList();

            cbxRemindLater.ItemsSource = list;

            cbxRemindLater.SelectedIndex = 0;
        }
Example #3
0
        /// <inheritdoc />
        public async Task Update(string appcastUrl, EazyUpdaterOptions updaterOptions, Assembly assembly = null)
        {
            this.SetSecurityProtocol();
            this.AppcastUrl     = appcastUrl;
            this.UpdaterOptions = updaterOptions;

            if (!this.IsUpdaterRunning && this._remindLaterTimer == null)
            {
                this.IsUpdaterRunning = true;

                this.IsWinFormsApplication = System.Windows.Application.Current == null;

                ResourceEnabler.SetLanguageDictionary();
            }

            if (!string.IsNullOrEmpty(this.AppcastUrl))
            {
                this.UpdaterInformation = await this.GetUpdateDetilsFromAppCast();
            }
            else if (string.IsNullOrEmpty(this.AppcastUrl) && CheckForUpdateInformation != null)
            {
                #region |Invoke custom implementation|
                var updateArg = new UpdateEventArgs {
                    Options = this.UpdaterOptions
                };
                CheckForUpdateInformation?.Invoke(this, updateArg);
                this.UpdaterInformation = updateArg.UpdateInfo;
                this.UpdaterOptions     = updateArg.Options ?? new EazyUpdaterOptions();
                assembly = updateArg.AssemblyInfo;
                #endregion
            }
            else
            {
                throw new NotImplementedException("There is no implementation or source to get latest update information");
            }

            this.GetAssemblyInformation(assembly ?? Assembly.GetEntryAssembly());
            var updateTask = this.RunApplicationUpdate();
            updateTask.Wait();
            this.IsUpdaterRunning = false;
        }
        /// <summary>
        /// Backgorund worker progress changed event
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">Download progress event arg</param>
        private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            if (_startedAt == default(DateTime))
            {
                _startedAt = DateTime.Now;
            }
            else
            {
                var  timeSpan     = DateTime.Now - _startedAt;
                long totalSeconds = (long)timeSpan.TotalSeconds;
                if (totalSeconds > 0)
                {
                    var bytesPerSecond = e.BytesReceived / totalSeconds;
                    lblDownloadSpeedMessage.Text =
                        string.Format(ResourceEnabler.GetResourceText("DownloadSpeedMessage"), BytesToString(bytesPerSecond));
                }
            }

            lblSize.Text = $@"{BytesToString(e.BytesReceived)} / {BytesToString(e.TotalBytesToReceive)}";
            pgbFileDownloadProgress.Value = e.ProgressPercentage;
        }
Example #5
0
        /// <summary>
        /// Sets all control texts from source file
        /// </summary>
        private void SetControlText()
        {
            this.Title = string.Format(ResourceEnabler.GetResourceText("UpdateFormTitle"), this._eazyUpdate.UpdaterOptions.ApplicationTitle,
                                       this._eazyUpdate.UpdaterInformation.CurrentVersion);

            lblNewVersionTitle.Text = string.Format(ResourceEnabler.GetResourceText("UpdateFormNewVersionTitle"), this._eazyUpdate.UpdaterOptions.ApplicationTitle);

            lblDownloadQuestion.Text = string.Format(ResourceEnabler.GetResourceText("UpdateFormDownloadQuestion"), this._eazyUpdate.UpdaterOptions.ApplicationTitle,
                                                     this._eazyUpdate.UpdaterInformation.CurrentVersion, this._eazyUpdate.UpdaterInformation.InstalledVersion);

            lblReleaseNote.Text = ResourceEnabler.GetResourceText("UpdateFormReleaseNoteText");

            lblSkip.Text = ResourceEnabler.GetResourceText("SkipVersionButtonText");

            lblRemindLater.Text = ResourceEnabler.GetResourceText("RemindLaterButtonText");

            lblUpdate.Text = ResourceEnabler.GetResourceText("UpdateButtonText");

            btnRemindLater.Visibility = (this._eazyUpdate.UpdaterInformation.UpdateMode == EazyUpdateMode.Forced ||
                                         this._eazyUpdate.UpdaterInformation.UpdateMode == EazyUpdateMode.ForcedDownload) ? Visibility.Hidden : Visibility.Visible;

            btnSkip.Visibility = this._eazyUpdate.UpdaterInformation.UpdateMode == EazyUpdateMode.NoSkip ? Visibility.Hidden : Visibility.Visible;
        }
        /// <summary>
        /// Compare check sum of the downloaded update file with the algorithm and check sum given
        /// </summary>
        /// <param name="fileName">The downloaded file name</param>
        /// <param name="checksum">The check sum value</param>
        /// <returns>Returns true if it matches otherwise false</returns>
        private bool CompareChecksum(string fileName, string checksum)
        {
            using (var hashAlgorithm = HashAlgorithm.Create(this._eazyUpdate.UpdaterInformation.HashingAlgorithm))
            {
                using (var stream = File.OpenRead(fileName))
                {
                    if (hashAlgorithm != null)
                    {
                        var hash         = hashAlgorithm.ComputeHash(stream);
                        var fileChecksum = BitConverter.ToString(hash).Replace("-", string.Empty).ToLowerInvariant();

                        if (fileChecksum == checksum.ToLower())
                        {
                            return(true);
                        }

                        ActionInvokeEnabler.InvokeIfNecessary(() =>
                                                              MessageBox.Show(ResourceEnabler.GetResourceText("FileIntegrityCheckFailedMessage"),
                                                                              ResourceEnabler.GetResourceText("FileIntegrityCheckFailedCaption"),
                                                                              MessageBoxButton.OK, MessageBoxImage.Error));
                    }
                    else
                    {
                        if (this._eazyUpdate.UpdaterOptions.ReportErrors)
                        {
                            ActionInvokeEnabler.InvokeIfNecessary(() =>
                                                                  MessageBox.Show(ResourceEnabler.GetResourceText("UnsupportedHashAlgorithmMessage"),
                                                                                  ResourceEnabler.GetResourceText("UnsupportedHashAlgorithmCaption"),
                                                                                  MessageBoxButton.OK, MessageBoxImage.Error));
                        }
                    }

                    return(false);
                }
            }
        }
Example #7
0
        /// <summary>
        /// Run application update with current update information
        /// </summary>
        /// <returns>Empty Task object that can be awaited</returns>
        private Task RunApplicationUpdate()
        {
            if (this.UpdaterInformation.CurrentVersion == null ||
                string.IsNullOrEmpty(this.UpdaterInformation.DownloadURL))
            {
                this.IsUpdaterRunning = false;
                throw new InvalidDataException();
            }

            if (!this.UpdaterInformation.IsMandatoryUpdate)
            {
                var registryValues = this.EazyUpdateReadWriter.GetRegistryValues(this.RegistryLocation,
                                                                                 new Collection <string> {
                    RegistryKeys.Skip, RegistryKeys.Version, RegistryKeys.RemindLater
                });

                if (registryValues?.Any() == true)
                {
                    if (registryValues[RegistryKeys.Skip] != null && registryValues[RegistryKeys.Version] != null)
                    {
                        string skipValue   = registryValues[RegistryKeys.Skip].ToString();
                        var    skipVersion = new Version(registryValues[RegistryKeys.Version].ToString());
                        if (skipValue.Equals("1") && this.UpdaterInformation.CurrentVersion <= skipVersion)
                        {
                            return(null);
                        }

                        if (this.UpdaterInformation.CurrentVersion > skipVersion)
                        {
                            var newRegistryValue = new Dictionary <string, object>
                            {
                                { RegistryKeys.Version, this.UpdaterInformation.CurrentVersion.ToString() },
                                { RegistryKeys.Skip, 0 }
                            };

                            this.EazyUpdateReadWriter.UpdateRegistry(this.RegistryLocation, newRegistryValue);
                        }
                    }

                    var remindLaterTime = registryValues?[RegistryKeys.RemindLater];

                    if (remindLaterTime != null)
                    {
                        DateTime remindLater = Convert.ToDateTime(remindLaterTime.ToString(),
                                                                  CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat);

                        int compareResult = DateTime.Compare(DateTime.Now, remindLater);

                        if (compareResult < 0)
                        {
                            this.SetTimer(remindLater);
                            return(null);
                        }
                    }
                }
            }

            if (this.CustomNotification != null)
            {
                this.CustomNotification?.Invoke(this, new NotificationEventArgs(this.UpdaterInformation));
            }
            else
            {
                if (this.UpdaterInformation != null)
                {
                    if (this.UpdaterInformation.IsUpdateAvailable)
                    {
                        if (!this.IsWinFormsApplication)
                        {
                            System.Windows.Forms.Application.EnableVisualStyles();
                        }

                        if (this.UpdaterInformation.IsMandatoryUpdate &&
                            this.UpdaterInformation.UpdateMode == EazyUpdateMode.ForcedDownload)
                        {
                            this.DownloadUpdate();
                            this.Exit();
                        }
                        else
                        {
                            if (Thread.CurrentThread.GetApartmentState().Equals(ApartmentState.STA))
                            {
                                this.ShowUpdateForm();
                            }
                            else
                            {
                                Thread thread = new Thread(this.ShowUpdateForm);
                                thread.CurrentCulture = thread.CurrentUICulture = CultureInfo.CurrentCulture;
                                thread.SetApartmentState(ApartmentState.STA);
                                thread.Start();
                                thread.Join();
                            }
                        }

                        return(null);
                    }
                    else
                    {
                        if (this.UpdaterOptions.ReportErrors)
                        {
                            ActionInvokeEnabler.InvokeIfNecessary(() =>
                                                                  System.Windows.MessageBox.Show(ResourceEnabler.GetResourceText("UpdateUnavailableMessage"),
                                                                                                 ResourceEnabler.GetResourceText("UpdateUnavailableCaption"),
                                                                                                 MessageBoxButton.OK, MessageBoxImage.Information));
                        }
                    }
                }
                else
                {
                    if (this.UpdaterOptions.ReportErrors)
                    {
                        ActionInvokeEnabler.InvokeIfNecessary(() =>
                                                              System.Windows.MessageBox.Show(ResourceEnabler.GetResourceText("UpdateCheckFailedMessage"),
                                                                                             ResourceEnabler.GetResourceText("UpdateCheckFailedCaption"),
                                                                                             MessageBoxButton.OK, MessageBoxImage.Information));
                    }
                }
            }

            this.IsUpdaterRunning = false;
            return(null);
        }