OSDN Git Service

Windows 8.1/10 version support
authorttp <ttp@users.sourceforge.jp>
Sat, 8 Aug 2015 09:54:50 +0000 (18:54 +0900)
committerttp <ttp@users.sourceforge.jp>
Sat, 8 Aug 2015 09:54:50 +0000 (18:54 +0900)
na-get-lib/NaGet.InteropServices/WindowsVersion.cs [new file with mode: 0644]
na-get-lib/NaGet.Packages/Platform.cs
na-get-lib/na-get-lib.csproj

diff --git a/na-get-lib/NaGet.InteropServices/WindowsVersion.cs b/na-get-lib/NaGet.InteropServices/WindowsVersion.cs
new file mode 100644 (file)
index 0000000..aa336c8
--- /dev/null
@@ -0,0 +1,65 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.ComTypes;
+
+namespace NaGet.InteropServices
+{
+       /// <summary>
+       /// Windows Os Version
+       /// </summary>
+       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;
+               }
+       }
+}
index e058bc7..4fec91b 100644 (file)
@@ -20,6 +20,8 @@ namespace NaGet.Packages
                VISTA = 160,\r
                WIN7 = 161,\r
                WIN8 = 162,\r
+               WIN8_1 = 163,\r
+               WIN10 = 164,\r
        }\r
        \r
        public class Platform\r
@@ -172,13 +174,22 @@ namespace NaGet.Packages
                                                                return PlatformOSType.WIN2003;\r
                                                }\r
                                        } else if (osVer.Major == 6) {\r
-                                               switch (osVer.Minor) {\r
+                                               int osVerMinor = osVer.Minor;\r
+                                               NaGet.InteropServices.WindowsVersion.VersionInfo? verInfo = NaGet.InteropServices.WindowsVersion.GetVersionInfo();\r
+                                               if (verInfo.HasValue) {\r
+                                                       osVerMinor = (int) verInfo.Value.MinorVersion;\r
+                                               }\r
+                                               switch (osVerMinor) {\r
                                                        case 0:\r
                                                                return PlatformOSType.VISTA;\r
                                                        case 1:\r
                                                                return PlatformOSType.WIN7;\r
                                                        case 2:\r
                                                                return PlatformOSType.WIN8;\r
+                                                       case 3:\r
+                                                               return PlatformOSType.WIN8_1;\r
+                                                       case 4:\r
+                                                               return PlatformOSType.WIN10;\r
                                                }\r
                                        }\r
                                        break;\r
index 02993a8..a11dd1c 100644 (file)
@@ -1,4 +1,5 @@
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
   <PropertyGroup>\r
     <ProjectGuid>{058E953D-3986-4F74-8516-5A50D267D36A}</ProjectGuid>\r
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
@@ -63,6 +64,7 @@
     <Compile Include="NaGet.InteropServices\PEFileInfoUtils.cs" />\r
     <Compile Include="NaGet.InteropServices\ShellLink.cs" />\r
     <Compile Include="NaGet.InteropServices\DownloadScannerService.cs" />\r
+    <Compile Include="NaGet.InteropServices\WindowsVersion.cs" />\r
     <Compile Include="NaGet.Packages.Install\DependeciesResolver.cs" />\r
     <Compile Include="NaGet.Packages.Install\InstallationLog.cs" />\r
     <Compile Include="NaGet.Packages.Install\UpgradeFinder.cs" />\r