Skip to content

Commit

Permalink
Simplify Environment.IsWindows8OrAbove. (dotnet#70818)
Browse files Browse the repository at this point in the history
* Simplify Environment.IsWindows8OrAbove.
Since .NET 5, the regular Windows version detecton code always returns the correct version.

* Remove two unused interop files.
  • Loading branch information
teo-tsirpanis authored Jun 16, 2022
1 parent 6e7001c commit 1b6f76d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 64 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1756,12 +1756,6 @@
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.TzSpecificLocalTimeToSystemTime.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.TzSpecificLocalTimeToSystemTime.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.VerifyVersionExW.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.VerifyVersionExW.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.VerSetConditionMask.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.VerSetConditionMask.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.VirtualAlloc_Ptr.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.VirtualAlloc_Ptr.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Internal.Win32;
Expand Down Expand Up @@ -383,30 +382,8 @@ private static string GetKnownFolderPath(string folderGuid, SpecialFolderOption
private static class WindowsVersion
{
// Cache the value in static readonly that can be optimized out by the JIT
internal static readonly bool IsWindows8OrAbove = GetIsWindows8OrAbove();

private static bool GetIsWindows8OrAbove()
{
ulong conditionMask = Interop.Kernel32.VerSetConditionMask(0, Interop.Kernel32.VER_MAJORVERSION, Interop.Kernel32.VER_GREATER_EQUAL);
conditionMask = Interop.Kernel32.VerSetConditionMask(conditionMask, Interop.Kernel32.VER_MINORVERSION, Interop.Kernel32.VER_GREATER_EQUAL);
conditionMask = Interop.Kernel32.VerSetConditionMask(conditionMask, Interop.Kernel32.VER_SERVICEPACKMAJOR, Interop.Kernel32.VER_GREATER_EQUAL);
conditionMask = Interop.Kernel32.VerSetConditionMask(conditionMask, Interop.Kernel32.VER_SERVICEPACKMINOR, Interop.Kernel32.VER_GREATER_EQUAL);

// Windows 8 version is 6.2
Interop.Kernel32.OSVERSIONINFOEX version = default;
unsafe
{
version.dwOSVersionInfoSize = sizeof(Interop.Kernel32.OSVERSIONINFOEX);
}
version.dwMajorVersion = 6;
version.dwMinorVersion = 2;
version.wServicePackMajor = 0;
version.wServicePackMinor = 0;

return Interop.Kernel32.VerifyVersionInfoW(ref version,
Interop.Kernel32.VER_MAJORVERSION | Interop.Kernel32.VER_MINORVERSION | Interop.Kernel32.VER_SERVICEPACKMAJOR | Interop.Kernel32.VER_SERVICEPACKMINOR,
conditionMask);
}
// Windows 8 version is 6.2
internal static readonly bool IsWindows8OrAbove = OperatingSystem.IsWindowsVersionAtLeast(6, 2);
}
}
}

0 comments on commit 1b6f76d

Please sign in to comment.