Ejemplo n.º 1
0
        private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
        {
            if (args.Error == null)
            {
                if (args.IsUpdateAvailable)
                {
                    var messageBox = new MessageBoxModel
                    {
                        Text = $"There is new version {args.CurrentVersion} available.{Environment.NewLine}" +
                               $"You are using version {args.InstalledVersion}.{Environment.NewLine}" +
                               $"{ChangelogText}{Environment.NewLine}" +
                               "Do you want to update the application now?",
                        Caption = @"Update Available",
                        Buttons = MessageBoxButtons.YesNo()
                    };

                    MessageBox.Show(messageBox);

                    if (!manual)
                    {
                        SplashWindow.splash.Hide();
                    }

                    if (messageBox.Result.Equals(MessageBoxResult.Yes))
                    {
                        try
                        {
                            if (AutoUpdater.DownloadUpdate(args))
                            {
                                if (!manual)
                                {
                                    SplashWindow.Stop();
                                }
                                Application.Current.Shutdown();
                                Environment.Exit(0);
                            }
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(
                                exception.Message,
                                exception.GetType().ToString(),
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                        }
                    }

                    if (!manual)
                    {
                        SplashWindow.splash.Show();
                    }
                }
                else if (manual)
                {
                    OnUpdateCheckCompleteEvent(new EventArgs());
                }
            }
            else
            {
                if (args.Error is WebException)
                {
                    MessageBox.Show(
                        @"There is a problem reaching update server. Please check your internet connection and try again later.",
                        @"Update Check Failed",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show(
                        args.Error.Message,
                        args.Error.GetType().ToString(),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
            AutoUpdater.ParseUpdateInfoEvent -= AutoUpdaterOnParseUpdateInfoEvent;
            AutoUpdater.CheckForUpdateEvent  -= AutoUpdaterOnCheckForUpdateEvent;
        }