Ejemplo n.º 1
0
        // Window has been rendered to the screen
        private async void Window_ContentRendered(object sender, EventArgs e)
        {
            if (!_settingsManager.Settings.AutoUpdateCheck)
            {
                return;
            }

            string latestVersion;

            try
            {
                _log.Information("Checking for updates...");
                latestVersion = await GithubConnection.GetLatestVersion().ConfigureAwait(true);
            }
            catch (HttpRequestException ex)
            {
                _log.Warning("Failed to check for updates - " + ex.ToString());
                return; // keep in mind when adding anything to this function!
            }

            if (String.IsNullOrEmpty(latestVersion))
            {
                _log.Warning("Failed to check for updates - github returned nothing or error code");
                return; // keep in mind when adding anything to this function!
            }

            var assemblyName    = Assembly.GetEntryAssembly()?.GetName();
            var assemblyVersion = assemblyName.Version.ToString(3);

            if (latestVersion.Equals(assemblyVersion, StringComparison.OrdinalIgnoreCase))
            {
                _settingsManager.TemporaryValues["UpdateAvailable"] = false;
            }
            else
            {
                _settingsManager.TemporaryValues["UpdateAvailable"] = true;

                var updateNotif = FlyoutHelper.CreateFlyout(true, true);
                updateNotif.SetFlyoutLabelText(TryFindResource("UpdateAvailableNotifText") as String);
                updateNotif.SetFlyoutButtonText(TryFindResource("UpdateAvailableNotifButton") as String);

                updateNotif.GetFlyoutButton().Click += (object e1, RoutedEventArgs a) =>
                {
                    Process.Start((TryFindResource("GitHubReleasesLink") as Uri).ToString());
                };

                updateNotif.Placement = ModernWpf.Controls.Primitives.FlyoutPlacementMode.Bottom;
                updateNotif.ShowAt(SettingsButton);
            }

            return;
        }
Ejemplo n.º 2
0
        private void CheckForUpdatesAsync()
        {
            try
            {
                Thread.Sleep(1000);
                var ghc = new GithubConnection();
                var r   = ghc.GetLatestRelease(Settings.UpdateToPrerelease);

                if (r.Item1 > App.APP_VERSION)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() => { UpdateWindow.Show(Owner, this, r.Item1, r.Item2, r.Item3); }));
                }
            }
            catch (Exception e)
            {
                App.Logger.Error("Main", "Updatecheck failed: Can't get latest version from github", e);
            }
        }
        private void ManuallyCheckForUpdates()
        {
            try
            {
                var ghc = new GithubConnection();
                var r   = ghc.GetLatestRelease(Settings.UpdateToPrerelease);

                if (r.Item1 > App.APP_VERSION)
                {
                    UpdateWindow.Show(Owner, this, r.Item1, r.Item2, r.Item3);
                }
                else
                {
                    MessageBox.Show("You are using the latest version");
                }
            }
            catch (Exception e)
            {
                App.Logger.Error("Main", "Can't get latest version from github", e);
                MessageBox.Show("Cannot get latest version from github API");
            }
        }
Ejemplo n.º 4
0
        private async void UpdateCheckButton_Click(object sender, RoutedEventArgs e)
        {
            if (!(this.DataContext is SettingsManager context))
            {
                return;
            }

            string latestVersion;

            try
            {
                latestVersion = await GithubConnection.GetLatestVersion().ConfigureAwait(true);
            }
            catch (HttpRequestException ex)
            {
                // Http request failed, show error and stop
                // Create Dialog with error message
                var msgDialog = new GenericMessageDialog()
                {
                    Title = TryFindResource("UpdateExceptionTitleText") as String,
                    Owner = this
                };
                msgDialog.SetMessage(TryFindResource("UpdateHTTPExceptionBodyText") as String);

                // Show dialog
                await msgDialog.ShowAsync(ContentDialogPlacement.Popup).ConfigureAwait(true);

                return;
            }

            if (String.IsNullOrEmpty(latestVersion))
            {
                // Either github returned nothing or got an http error code
                // Http request failed, show error and stop
                // Create Dialog with error message
                var msgDialog = new GenericMessageDialog()
                {
                    Title = TryFindResource("UpdateExceptionTitleText") as String,
                    Owner = this
                };
                msgDialog.SetMessage(TryFindResource("UpdateGitHubErrorBodyText") as String);

                // Show dialog
                await msgDialog.ShowAsync(ContentDialogPlacement.Popup).ConfigureAwait(true);

                return;
            }

            var assemblyName    = Assembly.GetEntryAssembly()?.GetName();
            var assemblyVersion = assemblyName.Version.ToString(3);

            if (latestVersion.Equals(assemblyVersion, StringComparison.OrdinalIgnoreCase))
            {
                context.TemporaryValues["UpdateAvailable"] = false;
                UpdateAvailableButton.Visibility           = Visibility.Collapsed;

                var msgDialog = new GenericMessageDialog()
                {
                    Title = TryFindResource("UpdateMostRecentTitleText") as String,
                    Owner = this
                };
                msgDialog.SetMessage(TryFindResource("UpdateMostRecentBodyText") as String);
                await msgDialog.ShowAsync(ContentDialogPlacement.Popup).ConfigureAwait(true);
            }
            else
            {
                context.TemporaryValues["UpdateAvailable"] = true;
                UpdateAvailableButton.Visibility           = Visibility.Visible;

                var msgDialog = new GenericMessageDialog()
                {
                    Title = TryFindResource("UpdateNewerTitleText") as String,
                    Owner = this,
                    IsSecondaryButtonEnabled = true,
                    SecondaryButtonText      = TryFindResource("CancelButtonText") as String
                };
                msgDialog.SetMessage(TryFindResource("UpdateNewerBodyText") as String + $"\n{assemblyVersion} -> {latestVersion}");
                var response = await msgDialog.ShowAsync(ContentDialogPlacement.Popup).ConfigureAwait(true);

                if (response == ContentDialogResult.Primary)
                {
                    Process.Start((TryFindResource("GitHubReleasesLink") as Uri).ToString());
                }
            }

            return;
        }
Ejemplo n.º 5
0
        private async void UpdateCheckButton_Click(object sender, RoutedEventArgs e)
        {
            string latestVersion;

            try
            {
                latestVersion = await GithubConnection.GetLatestVersion().ConfigureAwait(true);
            }
            catch (HttpRequestException ex)
            {
                // Http request failed, show error and stop
                // Create Dialog with error message
                var msgDialog = new GenericMessageDialog()
                {
                    Title = TryFindResource("UpdateExceptionTitleText") as String,
                    Owner = this
                };
                msgDialog.SetMessage(TryFindResource("UpdateHTTPExceptionBodyText") as String);

                // Show dialog
                await msgDialog.ShowAsync(ContentDialogPlacement.Popup).ConfigureAwait(true);

                return;
            }

            if (String.IsNullOrEmpty(latestVersion))
            {
                // Either github returned nothing or got an http error code
                // Http request failed, show error and stop
                // Create Dialog with error message
                var msgDialog = new GenericMessageDialog()
                {
                    Title = TryFindResource("UpdateExceptionTitleText") as String,
                    Owner = this
                };
                msgDialog.SetMessage(TryFindResource("UpdateGitHubErrorBodyText") as String);

                // Show dialog
                await msgDialog.ShowAsync(ContentDialogPlacement.Popup).ConfigureAwait(true);

                return;
            }

            var assemblyName    = Assembly.GetEntryAssembly()?.GetName();
            var assemblyVersion = assemblyName.Version.ToString(3);

            if (latestVersion.Equals(assemblyVersion, StringComparison.OrdinalIgnoreCase))
            {
                var msgDialog = new GenericMessageDialog()
                {
                    Title = TryFindResource("UpdateMostRecentTitleText") as String,
                    Owner = this
                };
                msgDialog.SetMessage(TryFindResource("UpdateMostRecentBodyText") as String);
                await msgDialog.ShowAsync(ContentDialogPlacement.Popup).ConfigureAwait(true);
            }
            else
            {
                var msgDialog = new GenericMessageDialog()
                {
                    Title = TryFindResource("UpdateNewerTitleText") as String,
                    Owner = this
                };
                msgDialog.SetMessage(TryFindResource("UpdateNewerBodyText") as String + $"\n{assemblyVersion} -> {latestVersion}");
                var response = await msgDialog.ShowAsync(ContentDialogPlacement.Popup).ConfigureAwait(true);

                if (response == ContentDialogResult.Primary)
                {
                    Process.Start($"https://github.com/fraxiinus/ReplayBook/releases");
                }
            }

            return;
        }
Ejemplo n.º 6
0
 public void SetUp()
 {
     Client           = new Mock <IGitHubClient>();
     GithubConnection = new GithubConnection(Client.Object);
 }