Merge pull request #449 from ghost1372/WindowsVersion
Get Windows Version without System.Management
This commit is contained in:
10 files changed
+27
-36
No files matched your search
@@ -9,7 +9,6 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Management" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AvalonEdit" Version="6.0.1" />
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
<PackageReference Include="AvalonEdit" Version="6.0.1" />
|
||||
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="System.Management" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\Shared\HandyControlDemo_Shared\Data\MessageToken.cs">
|
||||
|
||||
@@ -73,7 +73,6 @@ namespace HandyControlDemo
|
||||
UpdateSkin(GlobalData.Config.Skin);
|
||||
}
|
||||
|
||||
ConfigHelper.Instance.SystemVersionInfo = CommonHelper.GetSystemVersionInfo();
|
||||
ConfigHelper.Instance.SetWindowDefaultStyle();
|
||||
ConfigHelper.Instance.SetNavigationWindowDefaultStyle();
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\StringRepeatConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\LangExtension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\AssemblyHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\CommonHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\Win32Helper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Basic\Avatar.xaml.cs">
|
||||
<DependentUpon>Avatar.xaml</DependentUpon>
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControlDemo.Tools
|
||||
{
|
||||
public class CommonHelper
|
||||
{
|
||||
public static SystemVersionInfo GetSystemVersionInfo()
|
||||
{
|
||||
var managementClass = new ManagementClass("Win32_OperatingSystem");
|
||||
var instances = managementClass.GetInstances();
|
||||
foreach (var instance in instances)
|
||||
{
|
||||
if (instance["Version"] is string version)
|
||||
{
|
||||
var nums = version.Split('.').Select(int.Parse).ToList();
|
||||
var info = new SystemVersionInfo(nums[0], nums[1], nums[2]);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,18 @@ namespace HandyControl.Controls
|
||||
base.OnApplyTemplate();
|
||||
EnableBlur(this);
|
||||
}
|
||||
|
||||
private static SystemVersionInfo GetSystemVersionInfo()
|
||||
{
|
||||
var osv = new InteropValues.RTL_OSVERSIONINFOEX();
|
||||
osv.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osv);
|
||||
InteropMethods.Gdip.RtlGetVersion(out osv);
|
||||
return new SystemVersionInfo((int)osv.dwMajorVersion, (int)osv.dwMinorVersion, (int)osv.dwBuildNumber);
|
||||
}
|
||||
|
||||
internal static void EnableBlur(Window window)
|
||||
{
|
||||
var versionInfo = ConfigHelper.Instance.SystemVersionInfo;
|
||||
var versionInfo = GetSystemVersionInfo();
|
||||
|
||||
if (versionInfo < SystemVersionInfo.Windows10 ||
|
||||
versionInfo >= SystemVersionInfo.Windows10_1903)
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
{
|
||||
public class HandyControlConfig
|
||||
{
|
||||
public SystemVersionInfo SystemVersionInfo { get; set; }
|
||||
|
||||
public string Lang { get; set; }
|
||||
|
||||
public int TimelineFrameRate { get; set; } = 60;
|
||||
|
||||
@@ -37,8 +37,6 @@ namespace HandyControl.Tools
|
||||
}
|
||||
}
|
||||
|
||||
public SystemVersionInfo SystemVersionInfo { get; set; }
|
||||
|
||||
public void SetLang(string lang)
|
||||
{
|
||||
LangProvider.Culture = new CultureInfo(lang);
|
||||
@@ -48,7 +46,6 @@ namespace HandyControl.Tools
|
||||
|
||||
public void SetConfig(HandyControlConfig config)
|
||||
{
|
||||
SystemVersionInfo = config.SystemVersionInfo;
|
||||
SetLang(config.Lang);
|
||||
SetTimelineFrameRate(config.TimelineFrameRate);
|
||||
}
|
||||
|
||||
@@ -703,6 +703,10 @@ namespace HandyControl.Tools.Interop
|
||||
[DllImport(InteropValues.ExternDll.GdiPlus, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
internal static extern int GdipSaveImageToStream(HandleRef image, InteropValues.IStream stream, ref Guid classId, HandleRef encoderParams);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.NTdll)]
|
||||
internal static extern int RtlGetVersion(out InteropValues.RTL_OSVERSIONINFOEX lpVersionInformation);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,8 @@ namespace HandyControl.Tools.Interop
|
||||
GdiPlus = "gdiplus.dll",
|
||||
Kernel32 = "kernel32.dll",
|
||||
Shell32 = "shell32.dll",
|
||||
MsImg = "msimg32.dll";
|
||||
MsImg = "msimg32.dll",
|
||||
NTdll = "ntdll.dll";
|
||||
}
|
||||
|
||||
internal delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);
|
||||
@@ -956,5 +957,17 @@ namespace HandyControl.Tools.Interop
|
||||
public RECT rc;
|
||||
public int lParam;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user