From b1327ac3ff1313936c7a7e52a8e25642ed4f0e1a Mon Sep 17 00:00:00 2001 From: Taiizor <41683699+Taiizor@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:29:17 +0300 Subject: [PATCH] Preparing Backgroundog --- src/Project/Sucrose.Backgroundog/App.cs | 2 +- .../Sucrose.Backgroundog/Extension/Data.cs | 7 +++++ .../Extension/Thumbnail.cs | 22 +++++++++------ .../Sucrose.Backgroundog/Helper/Initialize.cs | 2 +- .../Helper/Specification.cs | 11 ++++++++ .../Sucrose.Backgroundog/Manage/Internal.cs | 11 ++++++++ .../Sucrose.Backgroundog/Struct/Data.cs | 28 +++++++++++++++++++ 7 files changed, 72 insertions(+), 11 deletions(-) diff --git a/src/Project/Sucrose.Backgroundog/App.cs b/src/Project/Sucrose.Backgroundog/App.cs index 7ad064c48..733490881 100644 --- a/src/Project/Sucrose.Backgroundog/App.cs +++ b/src/Project/Sucrose.Backgroundog/App.cs @@ -43,7 +43,7 @@ public static async Task Main() { SBMI.Initialize.Dispose(); - await Task.Delay(1000); + await Task.Delay(SBMI.AppTime); } while (SBMI.Exit); SBMI.Initialize.Stop(); diff --git a/src/Project/Sucrose.Backgroundog/Extension/Data.cs b/src/Project/Sucrose.Backgroundog/Extension/Data.cs index 36f3a3a9f..1cf9104f2 100644 --- a/src/Project/Sucrose.Backgroundog/Extension/Data.cs +++ b/src/Project/Sucrose.Backgroundog/Extension/Data.cs @@ -14,6 +14,7 @@ public static JObject GetCpuInfo() { "Max", SBMI.CpuData.Max }, { "Name", SBMI.CpuData.Name }, { "Core", SBMI.CpuData.Core }, + { "State", SBMI.CpuData.State }, { "Thread", SBMI.CpuData.Thread }, { "Fullname", SBMI.CpuData.Fullname } }; @@ -24,6 +25,7 @@ public static JObject GetBiosInfo() return new JObject { { "Name", SBMI.BiosData.Name }, + { "State", SBMI.BiosData.State }, { "Caption", SBMI.BiosData.Caption }, { "Version", SBMI.BiosData.Version }, { "Description", SBMI.BiosData.Description }, @@ -41,6 +43,7 @@ public static JObject GetDateInfo() { "Day", SBMI.DateData.Day }, { "Hour", SBMI.DateData.Hour }, { "Year", SBMI.DateData.Year }, + { "State", SBMI.DateData.State }, { "Month", SBMI.DateData.Month }, { "Minute", SBMI.DateData.Minute }, { "Second", SBMI.DateData.Second }, @@ -90,6 +93,7 @@ public static JObject GetMemoryInfo() return new JObject { { "Name", SBMI.MemoryData.Name }, + { "State", SBMI.MemoryData.State }, { "MemoryUsed", SBMI.MemoryData.MemoryUsed }, { "MemoryLoad", SBMI.MemoryData.MemoryLoad }, { "MemoryAvailable", SBMI.MemoryData.MemoryAvailable }, @@ -104,6 +108,7 @@ public static JObject GetBatteryInfo() return new JObject { { "Name", SBMI.BatteryData.Name }, + { "State", SBMI.BatteryData.State }, { "Voltage", SBMI.BatteryData.Voltage }, { "ChargeRate", SBMI.BatteryData.ChargeRate }, { "ChargeLevel", SBMI.BatteryData.ChargeLevel }, @@ -126,6 +131,7 @@ public static JObject GetNetworkInfo() return new JObject { { "Name", SBMI.NetworkData.Name }, + { "State", SBMI.NetworkData.State }, { "Upload", SBMI.NetworkData.Upload }, { "Download", SBMI.NetworkData.Download }, { "FormatUploadData", SBMI.NetworkData.FormatUploadData }, @@ -156,6 +162,7 @@ public static JObject GetMotherboardInfo() return new JObject { { "Name", SBMI.MotherboardData.Name }, + { "State", SBMI.MotherboardData.State }, { "Product", SBMI.MotherboardData.Product }, { "Version", SBMI.MotherboardData.Version }, { "Manufacturer", SBMI.MotherboardData.Manufacturer } diff --git a/src/Project/Sucrose.Backgroundog/Extension/Thumbnail.cs b/src/Project/Sucrose.Backgroundog/Extension/Thumbnail.cs index c784396c3..062b578a0 100644 --- a/src/Project/Sucrose.Backgroundog/Extension/Thumbnail.cs +++ b/src/Project/Sucrose.Backgroundog/Extension/Thumbnail.cs @@ -6,16 +6,16 @@ namespace Sucrose.Backgroundog.Extension { internal class Thumbnail { - public static string Create(Stream stream) + public static string Create(Stream Stream) { - using MemoryStream Stream = new(); + using MemoryStream MemoryStream = new(); - Stream.Seek(0, SeekOrigin.Begin); - stream.CopyTo(Stream); + MemoryStream.Seek(0, SeekOrigin.Begin); + Stream.CopyTo(MemoryStream); if (!SBMM.Windows11_OrGreater) { - using Bitmap Image = new(Stream); + using Bitmap Image = new(MemoryStream); if (PixelAlpha(Image, 0, 0)) { @@ -23,7 +23,9 @@ public static string Create(Stream stream) } } - byte[] Array = Stream.ToArray(); + byte[] Array = MemoryStream.ToArray(); + + MemoryStream.Flush(); return Convert.ToBase64String(Array); } @@ -37,17 +39,19 @@ private static string CropImage(Bitmap Image, int X, int Y, int Width, int Heigh { Rectangle Rect = new(X, Y, Width, Height); - using Bitmap CroppedBitmap = new(Rect.Width, Rect.Height, Image.PixelFormat); + using Bitmap CroppedImage = new(Rect.Width, Rect.Height, Image.PixelFormat); - Graphics Graphic = Graphics.FromImage(CroppedBitmap); + Graphics Graphic = Graphics.FromImage(CroppedImage); Graphic.DrawImage(Image, 0, 0, Rect, GraphicsUnit.Pixel); using MemoryStream Stream = new(); - CroppedBitmap.Save(Stream, ImageFormat.Png); + CroppedImage.Save(Stream, ImageFormat.Png); byte[] ByteImage = Stream.ToArray(); + Stream.Flush(); + return Convert.ToBase64String(ByteImage); } } diff --git a/src/Project/Sucrose.Backgroundog/Helper/Initialize.cs b/src/Project/Sucrose.Backgroundog/Helper/Initialize.cs index 50864b75d..7eaa27ca8 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Initialize.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Initialize.cs @@ -13,7 +13,7 @@ public void Start() { SBMI.Computer.Open(); TimerCallback Callback = InitializeTimer_Callback; - SBMI.InitializeTimer = new(Callback, null, 0, 250); + SBMI.InitializeTimer = new(Callback, null, 0, SBMI.InitializeTime); } public void Stop() diff --git a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs index 4549c6791..0ebe37d2f 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs @@ -27,6 +27,7 @@ public static async Task Start() foreach (ManagementObject Object in Searcher.Get().Cast()) { + SBMI.CpuData.State = true; SBMI.CpuData.Core = Convert.ToInt32(Object["NumberOfCores"]); SBMI.CpuData.Fullname = Object["Name"].ToString().TrimStart().TrimEnd(); SBMI.CpuData.Thread = Convert.ToInt32(Object["NumberOfLogicalProcessors"]); @@ -45,6 +46,7 @@ public static async Task Start() foreach (ManagementObject Object in Searcher.Get().Cast()) { + SBMI.BiosData.State = true; SBMI.BiosData.Name = Object["Name"].ToString(); SBMI.BiosData.Caption = Object["Caption"].ToString(); SBMI.BiosData.Version = Object["Version"].ToString(); @@ -53,6 +55,7 @@ public static async Task Start() SBMI.BiosData.Manufacturer = Object["Manufacturer"].ToString(); SBMI.BiosData.SerialNumber = Object["SerialNumber"].ToString(); SBMI.BiosData.CurrentLanguage = Object["CurrentLanguage"].ToString(); + break; } } @@ -64,6 +67,7 @@ public static async Task Start() SBMI.DateData = new() { + State = true, Day = Date.Day, Hour = Date.Hour, Year = Date.Year, @@ -94,6 +98,7 @@ public static async Task Start() { if (SMMM.NetworkAdapter != SBMI.NetworkData.Name) { + SBMI.NetworkData.State = true; SBMI.NetworkData.Name = SMMM.NetworkAdapter; SBMI.UploadCounter = new("Network Interface", "Bytes Sent/sec", Name); @@ -124,9 +129,11 @@ public static async Task Start() foreach (ManagementObject Object in Searcher.Get().Cast()) { + SBMI.MotherboardData.State = true; SBMI.MotherboardData.Product = Object["Product"].ToString(); SBMI.MotherboardData.Version = Object["Version"].ToString(); SBMI.MotherboardData.Manufacturer = Object["Manufacturer"].ToString(); + break; } } @@ -146,6 +153,7 @@ public static async Task Start() { if (Sensor.SensorType == SensorType.Load && Sensor.Name == "CPU Total") { + SBMI.CpuData.State = true; SBMI.CpuData.Min = Sensor.Min; SBMI.CpuData.Max = Sensor.Max; SBMI.CpuData.Now = Sensor.Value; @@ -159,6 +167,7 @@ public static async Task Start() { Hardware.Update(); + SBMI.MemoryData.State = true; SBMI.MemoryData.Name = Hardware.Name; foreach (ISensor Sensor in Hardware.Sensors) @@ -192,6 +201,7 @@ public static async Task Start() { Hardware.Update(); + SBMI.BatteryData.State = true; SBMI.BatteryData.Name = Hardware.Name; foreach (ISensor Sensor in Hardware.Sensors) @@ -249,6 +259,7 @@ public static async Task Start() { Hardware.Update(); + SBMI.MotherboardData.State = true; SBMI.MotherboardData.Name = Hardware.Name; } } diff --git a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs index 9af0d622d..e2d513553 100644 --- a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs +++ b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs @@ -18,12 +18,16 @@ internal static class Internal { public static bool Exit = true; + public static int AppTime = 250; + public static bool Condition = false; public static bool Processing = true; public static SBHI Initialize = new(); + public static int InitializeTime = 250; + public static bool CpuManagement = true; public static bool BiosManagement = true; @@ -53,12 +57,14 @@ internal static class Internal Max = 0f, Core = 0, Thread = 0, + State = false, Name = string.Empty, Fullname = string.Empty }; public static SBSDBSS BiosData = new() { + State = false, Name = string.Empty, Caption = string.Empty, Version = string.Empty, @@ -77,6 +83,7 @@ internal static class Internal Month = 0, Minute = 0, Second = 0, + State = false, Millisecond = 0 }; @@ -116,6 +123,7 @@ internal static class Internal public static SBSDMYS MemoryData = new() { + State = false, MemoryUsed = 0f, MemoryLoad = 0f, Name = string.Empty, @@ -141,6 +149,7 @@ internal static class Internal public static SBSDNS NetworkData = new() { Upload = 0f, + State = false, Download = 0f, UploadData = new(), Name = string.Empty, @@ -152,6 +161,7 @@ internal static class Internal public static SBSDBYS BatteryData = new() { Voltage = 0f, + State = false, ChargeRate = 0f, ChargeLevel = 0f, ChargeCurrent = 0f, @@ -170,6 +180,7 @@ internal static class Internal public static SBSDMDS MotherboardData = new() { + State = false, Name = string.Empty, Product = string.Empty, Version = string.Empty, diff --git a/src/Project/Sucrose.Backgroundog/Struct/Data.cs b/src/Project/Sucrose.Backgroundog/Struct/Data.cs index ab2446b93..148736622 100644 --- a/src/Project/Sucrose.Backgroundog/Struct/Data.cs +++ b/src/Project/Sucrose.Backgroundog/Struct/Data.cs @@ -29,6 +29,10 @@ public struct CpuStruct /// /// /// + public bool State; + /// + /// + /// public int? Thread; /// /// @@ -46,6 +50,10 @@ public struct CpuStruct [StructLayout(LayoutKind.Sequential)] public struct BiosStruct { + /// + /// + /// + public bool State; /// /// /// @@ -113,6 +121,10 @@ public struct DateStruct /// /// /// + public bool State; + /// + /// + /// public int Millisecond; } @@ -250,6 +262,10 @@ public struct AudioStruct [StructLayout(LayoutKind.Sequential)] public struct MemoryStruct { + /// + /// + /// + public bool State; /// /// /// @@ -286,6 +302,10 @@ public struct MemoryStruct [StructLayout(LayoutKind.Sequential)] public struct BatteryStruct { + /// + /// + /// + public bool State; /// /// /// @@ -354,6 +374,10 @@ public struct BatteryStruct [StructLayout(LayoutKind.Sequential)] public struct NetworkStruct { + /// + /// + /// + public bool State; /// /// /// @@ -390,6 +414,10 @@ public struct NetworkStruct [StructLayout(LayoutKind.Sequential)] public struct MotherboardStruct { + /// + /// + /// + public bool State; /// /// ///