From ee47b8670f55622a0ac590ef5b065cdea1f1e7bc Mon Sep 17 00:00:00 2001 From: ttp Date: Sat, 8 Aug 2015 18:54:50 +0900 Subject: [PATCH] Windows 8.1/10 version support --- na-get-lib/NaGet.InteropServices/WindowsVersion.cs | 65 ++++++++++++++++++++++ na-get-lib/NaGet.Packages/Platform.cs | 13 ++++- na-get-lib/na-get-lib.csproj | 4 +- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 na-get-lib/NaGet.InteropServices/WindowsVersion.cs diff --git a/na-get-lib/NaGet.InteropServices/WindowsVersion.cs b/na-get-lib/NaGet.InteropServices/WindowsVersion.cs new file mode 100644 index 0000000..aa336c8 --- /dev/null +++ b/na-get-lib/NaGet.InteropServices/WindowsVersion.cs @@ -0,0 +1,65 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +namespace NaGet.InteropServices +{ + /// + /// Windows Os Version + /// + public sealed class WindowsVersion + { + [DllImport("ntdll.dll", SetLastError=true)] + private static extern int RtlGetVersion([In, Out] ref OSVERSIONINFOEX lpVersionInformation); + + [StructLayout(LayoutKind.Sequential)] + private struct OSVERSIONINFOEX + { + public uint dwOSVersionInfoSize; + public uint dwMajorVersion; + public uint dwMinorVersion; + public uint dwBuildNumber; + public uint dwPlatformId; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)] + public string szCSDVersion; + public ushort wServicePackMajor; + public ushort wServicePackMinor; + public ushort wSuiteMask; + public char wProductType; + public char wReserved; + } + + public struct VersionInfo { + public uint MajorVersion; + public uint MinorVersion; + public uint BuildNumber; + public ushort ServicePackMajor; + public ushort ServicePackMinor; + } + + public static VersionInfo? GetVersionInfo() { + VersionInfo? retval = null; + + try { + OSVERSIONINFOEX versionInformation = new OSVERSIONINFOEX(); + versionInformation.dwOSVersionInfoSize = (uint)Marshal.SizeOf(versionInformation); + + int result = RtlGetVersion(ref versionInformation); + if (result == 0) { + VersionInfo info = new VersionInfo(); + info.MajorVersion = versionInformation.dwMajorVersion; + info.MinorVersion = versionInformation.dwMinorVersion; + info.BuildNumber = versionInformation.dwBuildNumber; + info.ServicePackMajor = versionInformation.wServicePackMajor; + info.ServicePackMinor = versionInformation.wServicePackMinor; + + retval = info; + } + } catch (Exception) { + // Drop any exception + } + + return retval; + } + } +} diff --git a/na-get-lib/NaGet.Packages/Platform.cs b/na-get-lib/NaGet.Packages/Platform.cs index e058bc7..4fec91b 100644 --- a/na-get-lib/NaGet.Packages/Platform.cs +++ b/na-get-lib/NaGet.Packages/Platform.cs @@ -20,6 +20,8 @@ namespace NaGet.Packages VISTA = 160, WIN7 = 161, WIN8 = 162, + WIN8_1 = 163, + WIN10 = 164, } public class Platform @@ -172,13 +174,22 @@ namespace NaGet.Packages return PlatformOSType.WIN2003; } } else if (osVer.Major == 6) { - switch (osVer.Minor) { + int osVerMinor = osVer.Minor; + NaGet.InteropServices.WindowsVersion.VersionInfo? verInfo = NaGet.InteropServices.WindowsVersion.GetVersionInfo(); + if (verInfo.HasValue) { + osVerMinor = (int) verInfo.Value.MinorVersion; + } + switch (osVerMinor) { case 0: return PlatformOSType.VISTA; case 1: return PlatformOSType.WIN7; case 2: return PlatformOSType.WIN8; + case 3: + return PlatformOSType.WIN8_1; + case 4: + return PlatformOSType.WIN10; } } break; diff --git a/na-get-lib/na-get-lib.csproj b/na-get-lib/na-get-lib.csproj index 02993a8..a11dd1c 100644 --- a/na-get-lib/na-get-lib.csproj +++ b/na-get-lib/na-get-lib.csproj @@ -1,4 +1,5 @@ - + + {058E953D-3986-4F74-8516-5A50D267D36A} Debug @@ -63,6 +64,7 @@ + -- 2.11.0