Пример #1
0
        private string GetUpdateChannel(AppUpdateChannelOptions channel)
        {
            switch (channel)
            {
            case AppUpdateChannelOptions.Stable:
                return("https://api.github.com/repos/tsunamods-codes/7th-Heaven/releases/latest");

            case AppUpdateChannelOptions.Canary:
                return("https://api.github.com/repos/tsunamods-codes/7th-Heaven/releases/tags/canary");

            default:
                return("");
            }
        }
Пример #2
0
        public void CheckForUpdates(AppUpdateChannelOptions channel, bool manualCheck = false)
        {
            try
            {
                _currentAppVersion = FileVersionInfo.GetVersionInfo(
                    Path.Combine(Sys._7HFolder, $"{App.GetAppName()}.exe")
                    );
            }
            catch (FileNotFoundException)
            {
                _currentAppVersion = null;
            }

            DownloadItem download = new DownloadItem()
            {
                Links = new List <string>()
                {
                    LocationUtil.FormatHttpUrl(GetUpdateChannel(channel))
                },
                SaveFilePath = GetUpdateInfoPath(),
                Category     = DownloadCategory.AppUpdate,
                ItemName     = $"{ResourceHelper.Get(StringKey.CheckingForUpdatesUsingChannel)} {channel.ToString()}"
            };

            download.IProc = new Install.InstallProcedureCallback(e =>
            {
                bool success = (e.Error == null && e.Cancelled == false);

                if (success)
                {
                    try
                    {
                        StreamReader file = File.OpenText(download.SaveFilePath);
                        dynamic release   = JValue.Parse(file.ReadToEnd());
                        file.Close();
                        File.Delete(download.SaveFilePath);

                        Version curVersion = new Version(GetCurrentAppVersion());
                        Version newVersion = new Version(GetUpdateVersion(release.name.Value));

                        switch (newVersion.CompareTo(curVersion))
                        {
                        case 1:     // NEWER
                            if (
                                MessageDialogWindow.Show(
                                    string.Format(ResourceHelper.Get(StringKey.AppUpdateIsAvailableMessage), $"{App.GetAppName()} - {App.GetAppVersion()}", newVersion.ToString(), release.body.Value),
                                    ResourceHelper.Get(StringKey.NewVersionAvailable),
                                    System.Windows.MessageBoxButton.YesNo,
                                    System.Windows.MessageBoxImage.Question
                                    ).Result == System.Windows.MessageBoxResult.Yes)
                            {
                                DownloadAndExtract(GetUpdateReleaseUrl(release.assets), newVersion.ToString());
                            }
                            break;

                        case 0:     // SAME
                            if (manualCheck)
                            {
                                MessageDialogWindow.Show("You seem to be up to date!", "No update found", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
                            }
                            break;

                        case -1:     // OLDER
                            if (
                                MessageDialogWindow.Show(
                                    $"Your current version seems newer to the one currently available.\n\nCurrent Version: {curVersion.ToString()}\nNew Version: {newVersion.ToString()}\n\nWould you like to install it anyway?",
                                    "Update found!",
                                    System.Windows.MessageBoxButton.YesNo,
                                    System.Windows.MessageBoxImage.Question
                                    ).Result == System.Windows.MessageBoxResult.Yes)
                            {
                                DownloadAndExtract(GetUpdateReleaseUrl(release.assets), newVersion.ToString());
                            }
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        MessageDialogWindow.Show("Something went wrong while checking for App updates. Please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                        Sys.Message(new WMessage()
                        {
                            Text = $"Could not parse the 7thHeaven release json at {GetUpdateChannel(channel)}", LoggedException = e.Error
                        });
                    }
                }
                else
                {
                    MessageDialogWindow.Show("Something went wrong while checking for App updates. Please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    Sys.Message(new WMessage()
                    {
                        Text = $"Could not fetch for 7thHeaven updates at {GetUpdateChannel(channel)}", LoggedException = e.Error
                    });
                }
            });

            Sys.Downloads.AddToDownloadQueue(download);
        }