From 877c11d5f9772c66d81695425320fbbe6e9f108c Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 6 Dec 2020 07:35:12 +1000 Subject: [PATCH] Merge UpdateChecker.ParseVersion into VersionInfo.VersionStrToInt --- .../config/ConfigService.cs | 2 +- src/BizHawk.Client.EmuHawk/UpdateChecker.cs | 25 +++---------------- src/BizHawk.Common/VersionInfo.cs | 6 ++--- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/BizHawk.Client.Common/config/ConfigService.cs b/src/BizHawk.Client.Common/config/ConfigService.cs index 66adf2319a..310790ac32 100644 --- a/src/BizHawk.Client.Common/config/ConfigService.cs +++ b/src/BizHawk.Client.Common/config/ConfigService.cs @@ -68,7 +68,7 @@ namespace BizHawk.Client.Common else { var cfgVersion = VersionInfo.VersionStrToInt(cfgVersionStr); - if (cfgVersion < 0x02050000) + if (cfgVersion < 0x02050000U) { fmt = MSGFMT_PRE_2_5; } diff --git a/src/BizHawk.Client.EmuHawk/UpdateChecker.cs b/src/BizHawk.Client.EmuHawk/UpdateChecker.cs index 25e356ae1e..9983ba42a9 100644 --- a/src/BizHawk.Client.EmuHawk/UpdateChecker.cs +++ b/src/BizHawk.Client.EmuHawk/UpdateChecker.cs @@ -55,8 +55,8 @@ namespace BizHawk.Client.EmuHawk public static bool IsNewVersionAvailable => AutoCheckEnabled && LatestVersion != IgnoreVersion - && ParseVersion(VersionInfo.MainVersion) != 0 // Avoid notifying if current version string is invalid - && ParseVersion(LatestVersion) > ParseVersion(VersionInfo.MainVersion); + && VersionInfo.VersionStrToInt(VersionInfo.MainVersion) != 0U // Avoid notifying if current version string is invalid + && VersionInfo.VersionStrToInt(LatestVersion) > VersionInfo.VersionStrToInt(VersionInfo.MainVersion); public static void IgnoreNewVersion() { @@ -100,26 +100,7 @@ namespace BizHawk.Client.EmuHawk private static string ValidateVersionNumberString(string versionNumber) { - return versionNumber != null && ParseVersion(versionNumber) != 0 ? versionNumber : ""; - } - - // Major version goes in the first 16 bits, and so on, up to 4 parts - private static ulong ParseVersion(string str) - { - string[] split = str.Split('.'); - if (split.Length > 4) return 0; - ulong version = 0; - for (int i = 0; i < split.Length; i++) - { - if (!ushort.TryParse(split[i], out var versionPart)) - { - return 0; - } - - version |= (ulong)versionPart << (48 - (i * 16)); - } - - return version; + return versionNumber != null && VersionInfo.VersionStrToInt(versionNumber) != 0U ? versionNumber : ""; } private static void OnCheckComplete() diff --git a/src/BizHawk.Common/VersionInfo.cs b/src/BizHawk.Common/VersionInfo.cs index 9e7adb6589..ddbdcac7dd 100644 --- a/src/BizHawk.Common/VersionInfo.cs +++ b/src/BizHawk.Common/VersionInfo.cs @@ -42,15 +42,15 @@ namespace BizHawk.Common => DeveloperBuild ? $"GIT {GIT_BRANCH}#{GIT_SHORTHASH}" : $"Version {MainVersion}"; /// "2.5.1" => 0x02050100 - public static int VersionStrToInt(string s) + public static uint VersionStrToInt(string s) { var a = s.Split('.'); - var v = 0; + var v = 0U; var i = 0; while (i < 4) { v <<= 8; - v += (i < a.Length && byte.TryParse(a[i], out var b)) ? b : 0; + v += (i < a.Length && byte.TryParse(a[i], out var b)) ? b : 0U; i++; } return v;