コード例 #1
0
ファイル: UpdateManager.cs プロジェクト: Darkfoe703/evemon
        /// <summary>
        /// Scans the update feed.
        /// </summary>
        /// <param name="result">The result.</param>
        private static void ScanUpdateFeed(SerializablePatch result)
        {
            Version             currentVersion = Version.Parse(EveMonClient.FileVersionInfo.FileVersion);
            SerializableRelease newestRelease  = result.Releases?.FirstOrDefault(
                release => Version.Parse(release.Version).Major == currentVersion.Major);

            Version newestVersion = (newestRelease != null) ? Version.Parse(newestRelease.
                                                                            Version) : currentVersion;
            Version mostRecentDeniedVersion = !string.IsNullOrEmpty(Settings.Updates.
                                                                    MostRecentDeniedUpgrade) ? new Version(Settings.Updates.
                                                                                                           MostRecentDeniedUpgrade) : new Version();

            // Is the program out of date and user has not previously denied this version?
            if (currentVersion < newestVersion & mostRecentDeniedVersion < newestVersion)
            {
                // Quit if newest release is null
                // (Shouldn't happen but it's nice to be prepared)
                if (newestRelease == null)
                {
                    return;
                }
                // Reset the most recent denied version
                Settings.Updates.MostRecentDeniedUpgrade = string.Empty;

                Uri    forumUrl       = new Uri(newestRelease.TopicAddress);
                Uri    installerUrl   = new Uri(newestRelease.PatchAddress);
                string updateMessage  = newestRelease.Message;
                string installArgs    = newestRelease.InstallerArgs;
                string md5Sum         = newestRelease.MD5Sum;
                string additionalArgs = newestRelease.AdditionalArgs;
                bool   canAutoInstall = !string.IsNullOrEmpty(installerUrl.AbsoluteUri) &&
                                        !string.IsNullOrEmpty(installArgs);

                if (!string.IsNullOrEmpty(additionalArgs) && additionalArgs.Contains(
                        "%EVEMON_EXECUTABLE_PATH%"))
                {
                    string appPath = Path.GetDirectoryName(Application.ExecutablePath);
                    installArgs = $"{installArgs} {additionalArgs}";
                    installArgs = installArgs.Replace("%EVEMON_EXECUTABLE_PATH%", appPath);
                }

                // Requests a notification to subscribers and quit
                EveMonClient.OnUpdateAvailable(forumUrl, installerUrl, updateMessage,
                                               currentVersion, newestVersion, md5Sum, canAutoInstall, installArgs);
                return;
            }

            // New data files released?
            if (result.FilesHaveChanged)
            {
                // Requests a notification to subscribers
                EveMonClient.OnDataUpdateAvailable(result.ChangedDatafiles);
                return;
            }

            // Notify about a new major version
            Version newestMajorVersion = result.Releases?.Max(release => Version.Parse(
                                                                  release.Version)) ?? new Version();
            SerializableRelease newestMajorRelease = result.Releases?.FirstOrDefault(release =>
                                                                                     Version.Parse(release.Version) == newestMajorVersion);

            if (newestMajorRelease == null)
            {
                return;
            }
            newestVersion = Version.Parse(newestMajorRelease.Version);
            Version mostRecentDeniedMajorUpgrade = !string.IsNullOrEmpty(Settings.Updates.
                                                                         MostRecentDeniedMajorUpgrade)
                ? new Version(Settings.Updates.MostRecentDeniedMajorUpgrade)
                : new Version();

            // Is there is a new major version and the user has not previously denied it?
            if (currentVersion >= newestVersion | mostRecentDeniedMajorUpgrade >= newestVersion)
            {
                return;
            }
            // Reset the most recent denied version
            Settings.Updates.MostRecentDeniedMajorUpgrade = string.Empty;
            EveMonClient.OnUpdateAvailable(null, null, null, currentVersion, newestVersion,
                                           null, false, null);
        }