Skip to content

Commit

Permalink
OS version check without requiring app.manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Jul 28, 2020
1 parent fd718cf commit 2c27fba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ModernWpf/Helpers/ColorsHelper.cs
@@ -1,10 +1,9 @@
using ModernWpf.Media.ColorPalette;
using System;
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Media;
using ModernWpf.Media.ColorPalette;
using Windows.UI.ViewManagement;

namespace ModernWpf
Expand Down Expand Up @@ -35,7 +34,7 @@ private ColorsHelper()
}
}

public static bool SystemColorsSupported { get; } = Environment.OSVersion.Version.Major >= 10;
public static bool SystemColorsSupported { get; } = OSVersionHelper.IsWindows10;

public static ColorsHelper Current { get; } = new ColorsHelper();

Expand Down
35 changes: 35 additions & 0 deletions ModernWpf/Helpers/OSVersionHelper.cs
@@ -0,0 +1,35 @@
using System;
using System.Runtime.InteropServices;

namespace ModernWpf
{
internal static class OSVersionHelper
{
internal static bool IsWindowsNT { get; } = Environment.OSVersion.Platform == PlatformID.Win32NT;

internal static bool IsWindows10 { get; } = IsWindowsNT && IsWindows10Impl();

private static bool IsWindows10Impl()
{
var osv = new RTL_OSVERSIONINFOEX();
osv.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osv);
int ret = RtlGetVersion(out osv);
return ret == 0 && osv.dwMajorVersion >= 10;
}

[DllImport("ntdll.dll")]
private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation);

[StructLayout(LayoutKind.Sequential)]
private struct RTL_OSVERSIONINFOEX
{
internal uint dwOSVersionInfoSize;
internal uint dwMajorVersion;
internal uint dwMinorVersion;
internal uint dwBuildNumber;
internal uint dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
internal string szCSDVersion;
}
}
}

0 comments on commit 2c27fba

Please sign in to comment.