Clean up Windows version detection, now flagging Win11 21H2

This commit is contained in:
YoshiRulz 2024-10-28 11:18:03 +10:00
parent f32277ebd6
commit a8b8fb39ab
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 13 additions and 6 deletions

View File

@ -762,9 +762,9 @@ namespace BizHawk.Client.EmuHawk
var (winVersion, win10PlusVersion) = OSTailoredCode.HostWindowsVersion.Value; var (winVersion, win10PlusVersion) = OSTailoredCode.HostWindowsVersion.Value;
var message = winVersion switch var message = winVersion switch
{ {
// OSTailoredCode.WindowsVersion._11 when win10PlusVersion! < new Version(10, 0, 22621) => $"Quick reminder: Your copy of Windows 11 (build {win10PlusVersion.Build}) is no longer supported by Microsoft.\nEmuHawk will probably continue working, but please update to at least 21H2 for increased security.", OSTailoredCode.WindowsVersion._11 when win10PlusVersion! < new Version(10, 0, 22621) => $"Quick reminder: Your copy of Windows 11 (build {win10PlusVersion.Build}) is no longer supported by Microsoft.\nEmuHawk will probably continue working, but please update to 24H2 for increased security.",
OSTailoredCode.WindowsVersion._11 => null, OSTailoredCode.WindowsVersion._11 => null,
OSTailoredCode.WindowsVersion._10 when win10PlusVersion! < new Version(10, 0, 19045) => $"Quick reminder: Your copy of Windows 10 (build {win10PlusVersion.Build}) is no longer supported by Microsoft.\nEmuHawk will probably continue working, but please update to at least 22H2 for increased security.", OSTailoredCode.WindowsVersion._10 when win10PlusVersion! < new Version(10, 0, 19045) => $"Quick reminder: Your copy of Windows 10 (build {win10PlusVersion.Build}) is no longer supported by Microsoft.\nEmuHawk will probably continue working, but please update to 22H2 for increased security.",
OSTailoredCode.WindowsVersion._10 => null, OSTailoredCode.WindowsVersion._10 => null,
_ => $"Quick reminder: Windows {winVersion.ToString().RemovePrefix('_').Replace('_', '.')} is no longer supported by Microsoft.\nEmuHawk will probably continue working, but please get a new operating system for increased security (either Windows 10+ or a GNU+Linux distro)." _ => $"Quick reminder: Windows {winVersion.ToString().RemovePrefix('_').Replace('_', '.')} is no longer supported by Microsoft.\nEmuHawk will probably continue working, but please get a new operating system for increased security (either Windows 10+ or a GNU+Linux distro)."
}; };

View File

@ -63,11 +63,18 @@ namespace BizHawk.Common
if ((GetRegValue("ProductName") ?? "Windows 10").Contains("Windows 10")) if ((GetRegValue("ProductName") ?? "Windows 10").Contains("Windows 10"))
{ {
// Win11 has ProductName == "Windows 10 Pro" MICROSOFT WHY https://stackoverflow.com/a/69922526 https://stackoverflow.com/a/70456554 // Win11 has ProductName == "Windows 10 Pro" MICROSOFT WHY https://stackoverflow.com/a/69922526 https://stackoverflow.com/a/70456554
// Version win10PlusVer = new(FileVersionInfo.GetVersionInfo(@"C:\Windows\System32\kernel32.dll").FileVersion.SubstringBefore(' ')); // bonus why: this doesn't work because the file's metadata wasn't updated #if false // bonus why: this doesn't work because the file's metadata wasn't updated
Version win10PlusVer = new(10, 0, int.TryParse(GetRegValue("CurrentBuild") ?? "19044", out var i) ? i : 19044); // still, leaving the Version wrapper here for when they inevitably do something stupid like decide to call Win11 11.0.x (or 10.1.x because they're incapable of doing anything sensible) Version win10PlusVer = new(FileVersionInfo.GetVersionInfo(@"C:\Windows\System32\kernel32.dll").FileVersion.SubstringBefore(' '));
return (win10PlusVer < new Version(10, 0, 22000) ? WindowsVersion._10 : WindowsVersion._11, win10PlusVer); #else
const int FALLBACK_BUILD_NUMBER = 19045; // last Win10 release
var buildNumber = int.TryParse(GetRegValue("CurrentBuild") ?? string.Empty, out var i) ? i : FALLBACK_BUILD_NUMBER;
Version win10PlusVer = new(10, 0, buildNumber); // leaving this wrapped in a `Version` struct for when they inevitably do something stupid like decide to call Win12 `12.0.x` (or, since that makes too much sense, `10.2.x`)
#endif
const int WIN11_BUILD_NUMBER_THRESHOLD = 21000; // first Win11 release was 22000
winVer = win10PlusVer < new Version(10, 0, WIN11_BUILD_NUMBER_THRESHOLD) ? WindowsVersion._10 : WindowsVersion._11;
return (winVer, win10PlusVer);
} }
// ...else we're on 8.1. Can't be bothered writing code for KB installed check, not that I have a Win8.1 machine to test on anyway, so it gets a free pass (though I suspect `CurrentBuild` would work here too). --yoshi // ...else we're on 8.1
winVer = WindowsVersion._8_1; winVer = WindowsVersion._8_1;
} }
else if (rawWinVer == new Version(6, 2)) winVer = WindowsVersion._8; else if (rawWinVer == new Version(6, 2)) winVer = WindowsVersion._8;