From cde827ff4e294044e18a90bd0a5e319e0675568a Mon Sep 17 00:00:00 2001 From: Taiizor <41683699+Taiizor@users.noreply.github.com> Date: Fri, 8 Mar 2024 13:39:34 +0300 Subject: [PATCH] Infrastructure Preparation 262 --- .../WinFormsDemoWallpaper.csproj | 2 +- src/Skylark.Wing/Helper/OperatingSystem.cs | 19 +++++++ src/Skylark.Wing/Helper/SystemInfo.cs | 51 +++++++++++++++---- src/Skylark.Wing/Native/Methods.cs | 30 ++++++++++- src/Skylark.Wing/Skylark.Wing.cs | 2 +- src/Skylark.Wing/Skylark.Wing.csproj | 2 +- 6 files changed, 92 insertions(+), 14 deletions(-) diff --git a/demo/Skylark.WinForms.Demo/WinFormsDemoWallpaper/WinFormsDemoWallpaper/WinFormsDemoWallpaper.csproj b/demo/Skylark.WinForms.Demo/WinFormsDemoWallpaper/WinFormsDemoWallpaper/WinFormsDemoWallpaper.csproj index 27a7be8c..38974631 100644 --- a/demo/Skylark.WinForms.Demo/WinFormsDemoWallpaper/WinFormsDemoWallpaper/WinFormsDemoWallpaper.csproj +++ b/demo/Skylark.WinForms.Demo/WinFormsDemoWallpaper/WinFormsDemoWallpaper/WinFormsDemoWallpaper.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Skylark.Wing/Helper/OperatingSystem.cs b/src/Skylark.Wing/Helper/OperatingSystem.cs index 5c0deb49..5a61b0b7 100644 --- a/src/Skylark.Wing/Helper/OperatingSystem.cs +++ b/src/Skylark.Wing/Helper/OperatingSystem.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.InteropServices; using SEOST = Skylark.Enum.OperatingSystemType; namespace Skylark.Wing.Helper @@ -85,6 +86,24 @@ public static Version GetVersion() return Environment.OSVersion.Version; } + /// + /// + /// + /// + public static string GetProcessorArchitecture() + { + return $"{Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")}"; + } + + /// + /// + /// + /// + public static Architecture GetProcessArchitecture() + { + return RuntimeInformation.ProcessArchitecture; + } + /// /// /// diff --git a/src/Skylark.Wing/Helper/SystemInfo.cs b/src/Skylark.Wing/Helper/SystemInfo.cs index 109ced49..68b4d0a2 100644 --- a/src/Skylark.Wing/Helper/SystemInfo.cs +++ b/src/Skylark.Wing/Helper/SystemInfo.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Linq; using System.Management; -using System.Runtime.InteropServices; using System.Text; using SE = Skylark.Exception; +using SWNM = Skylark.Wing.Native.Methods; namespace Skylark.Wing.Helper { @@ -158,23 +158,56 @@ public static bool CheckWindowsNorKN() return result; } + /// + /// Total installed memory in Megabyte + /// + /// + public static long GetTotalInstalledMemory() + { + SWNM.GetPhysicallyInstalledSystemMemory(out long memKb); + + return memKb / 1024; + } + /// /// /// - /// /// - [DllImport("kernel32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool GetPhysicallyInstalledSystemMemory(out long TotalMemoryInKilobytes); + public static SWNM.SYSTEM_INFO GetSystemInfo() + { + SWNM.SYSTEM_INFO SystemInfo = new(); + + SWNM.GetNativeSystemInfo(ref SystemInfo); + + return SystemInfo; + } /// - /// Total installed memory in Megabyte + /// /// /// - public static long GetTotalInstalledMemory() + public static string GetSystemInfoArchitecture() { - GetPhysicallyInstalledSystemMemory(out long memKb); - return memKb / 1024; + SWNM.SYSTEM_INFO SystemInfo = GetSystemInfo(); + + return SystemInfo.processorArchitecture switch + { + 0 => "x86", + 5 => "ARM", + 6 => "IA64", + 7 => "Alpha", + 9 => "x64", + 10 => "PPC", + 12 => "ARM64", + 13 => "SHX", + 14 => "IA32_ON_WIN64", + 15 => "AMD64_ON_WIN64", + 16 => "WOW64", + 17 => "IA64_ON_WIN64", + 18 => "WOW64_IA64", + 19 => "WOW64_ARM64", + _ => "Unknown", + }; } } } \ No newline at end of file diff --git a/src/Skylark.Wing/Native/Methods.cs b/src/Skylark.Wing/Native/Methods.cs index 2eb821cb..b40517bc 100644 --- a/src/Skylark.Wing/Native/Methods.cs +++ b/src/Skylark.Wing/Native/Methods.cs @@ -93,8 +93,7 @@ public enum DWM_WINDOW_CORNER_PREFERENCE public const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20; [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType, - int cxDesired, int cyDesired, uint fuLoad); + public static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType, int cxDesired, int cyDesired, uint fuLoad); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type); @@ -324,6 +323,22 @@ public enum RestartFlags [DllImport("user32.dll")] public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); + [StructLayout(LayoutKind.Sequential)] + public struct SYSTEM_INFO + { + public ushort processorArchitecture; + ushort reserved; + public uint pageSize; + public IntPtr minimumApplicationAddress; + public IntPtr maximumApplicationAddress; + public IntPtr activeProcessorMask; + public uint numberOfProcessors; + public uint processorType; + public uint allocationGranularity; + public ushort processorLevel; + public ushort processorRevision; + } + [StructLayout(LayoutKind.Sequential)] public struct LASTINPUTINFO { @@ -1344,6 +1359,13 @@ public enum WM : uint #endregion + /// + /// + /// + /// + [DllImport("kernel32.dll")] + public static extern void GetNativeSystemInfo(ref SYSTEM_INFO lpSystemInfo); + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); @@ -1360,6 +1382,10 @@ public enum WM : uint [DllImport("kernel32.dll")] public static extern bool SetProcessWorkingSetSize(IntPtr hProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize); + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool GetPhysicallyInstalledSystemMemory(out long TotalMemoryInKilobytes); + #region Window_Style [DllImport("user32.dll")] public static extern IntPtr GetMenu(IntPtr hWnd); diff --git a/src/Skylark.Wing/Skylark.Wing.cs b/src/Skylark.Wing/Skylark.Wing.cs index 9df75dc5..0ba05474 100644 --- a/src/Skylark.Wing/Skylark.Wing.cs +++ b/src/Skylark.Wing/Skylark.Wing.cs @@ -22,7 +22,7 @@ // Website: www.Vegalya.com // Created: 17.Jun.2023 // Changed: 08.Mar.2024 -// Version: 3.1.3.5 +// Version: 3.1.3.6 // // |---------DO-NOT-REMOVE---------| diff --git a/src/Skylark.Wing/Skylark.Wing.csproj b/src/Skylark.Wing/Skylark.Wing.csproj index f480c713..62dd25b3 100644 --- a/src/Skylark.Wing/Skylark.Wing.csproj +++ b/src/Skylark.Wing/Skylark.Wing.csproj @@ -12,7 +12,7 @@ Resources\Skylark.Wing.ico - 3.1.3.5 + 3.1.3.6 $(Version) true Skylark.Wing