public static void RunUpdateChecker()
        {
            Debugger.WriteLine(LogLevel.Info, "Checking for updates...");
            UpdateInfo = new UpdateInfo();
            Dictionary<string, object> versionInfo;
            try
            {
                versionInfo = GetLatestReleasedVersion();
                if (versionInfo == null)
                    throw new Exception("No version data downloaded!");
            }
            catch (WebException e)
            {
                Debugger.WriteLine(LogLevel.Error, $"Failed to get latest version info! Reason: {e}");
                Debugger.WriteLine(
                LogLevel.Error,
                $"Response: {new StreamReader(e.Response.GetResponseStream()).ReadToEnd()}");
                UpdatesChecked = true;
                return;
            }
            catch (Exception e)
            {
                Debugger.WriteLine(LogLevel.Error, $"Failed to get latest version info! Reason: {e}");
                UpdatesChecked = true;
                return;
            }

            Debugger.WriteLine(LogLevel.Info, "Got latest version info!");
            Debugger.WriteLine(LogLevel.Info, $"Current version: {MaidFiddler.VERSION_TAG}");
            Debugger.WriteLine(LogLevel.Info, $"Latest version: {versionInfo["tag_name"]}");

            Match current = versionPattern.Match(MaidFiddler.VERSION_TAG);
            Match latest = versionPattern.Match((string) versionInfo["tag_name"]);
            if (!latest.Success)
            {
                Debugger.WriteLine(
                LogLevel.Error,
                "Could not process version tag. Tag is probably older than Beta 0.11 Skipping version check.");
                UpdatesChecked = true;
                return;
            }

            bool isNewAvailable;
            try
            {
                string currentVersionPrefix = current.Groups["prefix"].Value;
                int currentMajor = int.Parse(current.Groups["major"].Value);
                int currentMinor = int.Parse(current.Groups["minor"].Value);
                int currentPatch = current.Groups["patch"].Success ? int.Parse(current.Groups["patch"].Value) : 0;

                string latestVersionPrefix = latest.Groups["prefix"].Value;
                int latestMajor = int.Parse(latest.Groups["major"].Value);
                int latestMinor = int.Parse(latest.Groups["minor"].Value);
                int latestPatch = latest.Groups["patch"].Success ? int.Parse(latest.Groups["patch"].Value) : 0;

                bool samePrefix = latestVersionPrefix == currentVersionPrefix;
                bool sameMajor = latestMajor == currentMajor;
                bool sameMinor = latestMinor == currentMinor;

                isNewAvailable = latestVersionPrefix == "v" && currentVersionPrefix == "Beta-"
                                 || samePrefix && latestMajor > currentMajor
                                 || samePrefix && sameMajor && latestMinor > currentMinor
                                 || samePrefix && sameMajor && sameMinor && latestPatch > currentPatch;
            }
            catch (Exception e)
            {
                Debugger.WriteLine(LogLevel.Error, $"Failed to parse tool versions! Reason: {e}");
                UpdatesChecked = true;
                return;
            }

            if (!isNewAvailable)
            {
                UpdatesChecked = true;
                return;
            }
            UpdateInfo newUpdateInfo = new UpdateInfo
            {
                IsAvailable = true,
                Version = (string) versionInfo["name"],
                Changelog = ((string) versionInfo["body"]).Replace("*", string.Empty)
            };
            UpdateInfo = newUpdateInfo;
            UpdatesChecked = true;
        }
示例#2
0
        public static void RunUpdateChecker()
        {
            Debugger.WriteLine(LogLevel.Info, "Checking for updates...");
            UpdateInfo = new UpdateInfo();
            Dictionary <string, object> versionInfo;

            try
            {
                versionInfo = GetLatestReleasedVersion();
                if (versionInfo == null)
                {
                    throw new Exception("No version data downloaded!");
                }
            }
            catch (WebException e)
            {
                Debugger.WriteLine(LogLevel.Error, $"Failed to get latest version info! Reason: {e}");
                Debugger.WriteLine(
                    LogLevel.Error,
                    $"Response: {new StreamReader(e.Response.GetResponseStream()).ReadToEnd()}");
                UpdatesChecked = true;
                return;
            }
            catch (Exception e)
            {
                Debugger.WriteLine(LogLevel.Error, $"Failed to get latest version info! Reason: {e}");
                UpdatesChecked = true;
                return;
            }

            Debugger.WriteLine(LogLevel.Info, "Got latest version info!");
            Debugger.WriteLine(LogLevel.Info, $"Current version: {MaidFiddler.VERSION_TAG}");
            Debugger.WriteLine(LogLevel.Info, $"Latest version: {versionInfo["tag_name"]}");

            Match current = versionPattern.Match(MaidFiddler.VERSION_TAG);
            Match latest  = versionPattern.Match((string)versionInfo["tag_name"]);

            if (!latest.Success)
            {
                Debugger.WriteLine(
                    LogLevel.Error,
                    "Could not process version tag. Tag is probably older than Beta 0.11 Skipping version check.");
                UpdatesChecked = true;
                return;
            }

            bool isNewAvailable;

            try
            {
                string currentVersionPrefix = current.Groups["prefix"].Value;
                int    currentMajor         = int.Parse(current.Groups["major"].Value);
                int    currentMinor         = int.Parse(current.Groups["minor"].Value);
                int    currentPatch         = current.Groups["patch"].Success ? int.Parse(current.Groups["patch"].Value) : 0;

                string latestVersionPrefix = latest.Groups["prefix"].Value;
                int    latestMajor         = int.Parse(latest.Groups["major"].Value);
                int    latestMinor         = int.Parse(latest.Groups["minor"].Value);
                int    latestPatch         = latest.Groups["patch"].Success ? int.Parse(latest.Groups["patch"].Value) : 0;

                bool samePrefix = latestVersionPrefix == currentVersionPrefix;
                bool sameMajor  = latestMajor == currentMajor;
                bool sameMinor  = latestMinor == currentMinor;

                isNewAvailable = latestVersionPrefix == "v" && currentVersionPrefix == "Beta-" ||
                                 samePrefix && latestMajor > currentMajor ||
                                 samePrefix && sameMajor && latestMinor > currentMinor ||
                                 samePrefix && sameMajor && sameMinor && latestPatch > currentPatch;
            }
            catch (Exception e)
            {
                Debugger.WriteLine(LogLevel.Error, $"Failed to parse tool versions! Reason: {e}");
                UpdatesChecked = true;
                return;
            }

            if (!isNewAvailable)
            {
                UpdatesChecked = true;
                return;
            }
            UpdateInfo newUpdateInfo = new UpdateInfo
            {
                IsAvailable = true,
                Version     = (string)versionInfo["name"],
                Changelog   = ((string)versionInfo["body"]).Replace("*", string.Empty)
            };

            UpdateInfo     = newUpdateInfo;
            UpdatesChecked = true;
        }