From 54677588017721ab195445d9252c84aa1ee89335 Mon Sep 17 00:00:00 2001 From: Taiizor <41683699+Taiizor@users.noreply.github.com> Date: Mon, 18 Sep 2023 18:16:54 +0300 Subject: [PATCH] Preparing Backgroundog --- .../Sucrose.Backgroundog/Extension/Data.cs | 29 ++++++++++++- .../Helper/Specification.cs | 42 +++++++++++++++++-- .../Sucrose.Backgroundog/Manage/Internal.cs | 19 +++++++-- .../Sucrose.Backgroundog/Struct/Data.cs | 30 +++++++++++-- 4 files changed, 108 insertions(+), 12 deletions(-) diff --git a/src/Project/Sucrose.Backgroundog/Extension/Data.cs b/src/Project/Sucrose.Backgroundog/Extension/Data.cs index c102895e9..bf3f155c9 100644 --- a/src/Project/Sucrose.Backgroundog/Extension/Data.cs +++ b/src/Project/Sucrose.Backgroundog/Extension/Data.cs @@ -12,7 +12,26 @@ public static JObject GetCpuInfo() { "Min", SBMI.CpuData.Min }, { "Now", SBMI.CpuData.Now }, { "Max", SBMI.CpuData.Max }, - { "Name", SBMI.CpuData.Name } + { "Name", SBMI.CpuData.Name }, + { "Core", SBMI.CpuData.Core }, + { "Thread", SBMI.CpuData.Thread }, + { "Fullname", SBMI.CpuData.Fullname } + }; + } + + public static JObject GetDateInfo() + { + DateTime Date = DateTime.Now; + + return new JObject + { + { "Year", Date.Year }, + { "Month", Date.Month }, + { "Day", Date.Day }, + { "Hour", Date.Hour }, + { "Minute", Date.Minute }, + { "Second", Date.Second }, + { "Millisecond", Date.Millisecond } }; } @@ -51,5 +70,13 @@ public static JObject GetBatteryInfo() { "RemainingTimeEstimated", SBMI.BatteryData.RemainingTimeEstimated } }; } + + public static JObject GetMotherboardInfo() + { + return new JObject + { + { "Name", SBMI.MotherboardData.Name } + }; + } } } \ No newline at end of file diff --git a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs index f35e70745..f73274919 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs @@ -1,5 +1,7 @@ using LibreHardwareMonitor.Hardware; using Newtonsoft.Json; +using Sucrose.Backgroundog.Extension; +using System.Management; using SBMI = Sucrose.Backgroundog.Manage.Internal; namespace Sucrose.Backgroundog.Helper @@ -30,10 +32,31 @@ public static async Task Start() Min = Sensor.Min, Max = Sensor.Max, Now = Sensor.Value, - Name = Hardware.Name + Name = Hardware.Name, + Core = SBMI.CpuData.Core, + Thread = SBMI.CpuData.Thread, + Fullname = SBMI.CpuData.Fullname }; } } + + if (SBMI.CpuManagement) + { + SBMI.CpuManagement = false; + + _ = Task.Run(() => + { + ManagementObjectSearcher Searcher = new("SELECT * FROM Win32_Processor"); + + foreach (ManagementObject Object in Searcher.Get().Cast()) + { + SBMI.CpuData.Core = Convert.ToInt32(Object["NumberOfCores"]); + SBMI.CpuData.Fullname = Object["Name"].ToString().TrimStart().TrimEnd(); + SBMI.CpuData.Thread = Convert.ToInt32(Object["NumberOfLogicalProcessors"]); + break; + } + }); + } } else if (Hardware.HardwareType == HardwareType.Memory) { @@ -125,11 +148,22 @@ public static async Task Start() } } } + else if (Hardware.HardwareType == HardwareType.Motherboard) + { + Hardware.Update(); + + SBMI.MotherboardData = new() + { + Name = Hardware.Name + }; + } } - Console.WriteLine(JsonConvert.SerializeObject(SBMI.CpuData, Formatting.Indented)); - Console.WriteLine(JsonConvert.SerializeObject(SBMI.MemoryData, Formatting.Indented)); - Console.WriteLine(JsonConvert.SerializeObject(SBMI.BatteryData, Formatting.Indented)); + Console.WriteLine(JsonConvert.SerializeObject(Data.GetCpuInfo(), Formatting.Indented)); + Console.WriteLine(JsonConvert.SerializeObject(Data.GetDateInfo(), Formatting.Indented)); + Console.WriteLine(JsonConvert.SerializeObject(Data.GetMemoryInfo(), Formatting.Indented)); + Console.WriteLine(JsonConvert.SerializeObject(Data.GetBatteryInfo(), Formatting.Indented)); + Console.WriteLine(JsonConvert.SerializeObject(Data.GetMotherboardInfo(), Formatting.Indented)); //foreach (IHardware Hardware in SBMI.Computer.Hardware) //{ diff --git a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs index f71cab234..b9960055f 100644 --- a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs +++ b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs @@ -1,7 +1,8 @@ using LibreHardwareMonitor.Hardware; using SBSDBS = Sucrose.Backgroundog.Struct.Data.BatteryStruct; using SBSDCS = Sucrose.Backgroundog.Struct.Data.CpuStruct; -using SBSDMS = Sucrose.Backgroundog.Struct.Data.MemoryStruct; +using SBSDMDS = Sucrose.Backgroundog.Struct.Data.MotherboardStruct; +using SBSDMYS = Sucrose.Backgroundog.Struct.Data.MemoryStruct; using Timer = System.Threading.Timer; namespace Sucrose.Backgroundog.Manage @@ -16,6 +17,8 @@ internal static class Internal public static bool Processing = true; + public static bool CpuManagement = true; + public static Timer InitializeTimer = null; public static SBSDCS CpuData = new() @@ -23,10 +26,13 @@ internal static class Internal Min = 0f, Now = 0f, Max = 0f, - Name = string.Empty + Core = 0, + Thread = 0, + Name = string.Empty, + Fullname = string.Empty }; - public static SBSDMS MemoryData = new() + public static SBSDMYS MemoryData = new() { MemoryUsed = 0f, MemoryLoad = 0f, @@ -47,7 +53,7 @@ internal static class Internal IsStorageEnabled = false, IsBatteryEnabled = true, IsControllerEnabled = false, - IsMotherboardEnabled = false, + IsMotherboardEnabled = true, }; public static SBSDBS BatteryData = new() @@ -68,5 +74,10 @@ internal static class Internal ChargeDischargeCurrent = 0f, RemainingTimeEstimated = 0f }; + + public static SBSDMDS MotherboardData = new() + { + Name = string.Empty + }; } } \ No newline at end of file diff --git a/src/Project/Sucrose.Backgroundog/Struct/Data.cs b/src/Project/Sucrose.Backgroundog/Struct/Data.cs index f96cad3f4..675f529e0 100644 --- a/src/Project/Sucrose.Backgroundog/Struct/Data.cs +++ b/src/Project/Sucrose.Backgroundog/Struct/Data.cs @@ -8,6 +8,10 @@ namespace Sucrose.Backgroundog.Struct.Data [StructLayout(LayoutKind.Sequential)] public struct CpuStruct { + /// + /// + /// + public int? Core; /// /// /// @@ -23,7 +27,15 @@ public struct CpuStruct /// /// /// - public string? Name; + public int? Thread; + /// + /// + /// + public string Name; + /// + /// + /// + public string Fullname; } /// @@ -35,7 +47,7 @@ public struct MemoryStruct /// /// /// - public string? Name; + public string Name; /// /// /// @@ -71,7 +83,7 @@ public struct BatteryStruct /// /// /// - public string? Name; + public string Name; /// /// /// @@ -129,4 +141,16 @@ public struct BatteryStruct /// public float? RemainingTimeEstimated; } + + /// + /// + /// + [StructLayout(LayoutKind.Sequential)] + public struct MotherboardStruct + { + /// + /// + /// + public string Name; + } } \ No newline at end of file