diff --git a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs index 68a2e44d0..e53640c39 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs @@ -38,14 +38,14 @@ public static async Task Start() { if (SBMI.Exit) { - _ = Task.Run(() => + if (SBMI.CpuManagement) { - try + SBMI.CpuManagement = false; + + _ = Task.Run(() => { - if (SBMI.CpuManagement) + try { - SBMI.CpuManagement = false; - ManagementObjectSearcher Searcher = new("SELECT * FROM Win32_Processor"); foreach (ManagementObject Object in Searcher.Get().Cast()) @@ -57,21 +57,22 @@ public static async Task Start() break; } } - } - catch (Exception Exception) - { - SSWW.Watch_CatchException(Exception); - } - }); + catch (Exception Exception) + { + SBMI.CpuManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } - _ = Task.Run(() => + if (SBMI.BiosManagement) { - try + SBMI.BiosManagement = false; + + _ = Task.Run(() => { - if (SBMI.BiosManagement) + try { - SBMI.BiosManagement = false; - ManagementObjectSearcher Searcher = new("SELECT * FROM Win32_BIOS"); foreach (ManagementObject Object in Searcher.Get().Cast()) @@ -89,12 +90,13 @@ public static async Task Start() break; } } - } - catch (Exception Exception) - { - SSWW.Watch_CatchException(Exception); - } - }); + catch (Exception Exception) + { + SBMI.BiosManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } _ = Task.Run(() => { @@ -141,34 +143,42 @@ public static async Task Start() } }); - _ = Task.Run(() => + if (SBMI.BatteryManagement) { - try - { - SBMI.BatteryData.ACPowerStatus = $"{SWUP.GetACPowerStatus()}"; - SBMI.BatteryData.SavingMode = SWUP.IsBatterySavingMode; - SBMI.BatteryData.SaverStatus = $"{SWUP.GetBatterySaverStatus()}"; - - SBMI.BatteryData.LifePercent = SystemInformation.PowerStatus.BatteryLifePercent; - SBMI.BatteryData.PowerLineStatus = SystemInformation.PowerStatus.PowerLineStatus; - SBMI.BatteryData.FullLifetime = SystemInformation.PowerStatus.BatteryFullLifetime; - SBMI.BatteryData.ChargeStatus = SystemInformation.PowerStatus.BatteryChargeStatus; - SBMI.BatteryData.LifeRemaining = SystemInformation.PowerStatus.BatteryLifeRemaining; - } - catch (Exception Exception) + SBMI.BatteryManagement = false; + + _ = Task.Run(() => { - SSWW.Watch_CatchException(Exception); - } - }); + try + { + SBMI.BatteryData.ACPowerStatus = $"{SWUP.GetACPowerStatus()}"; + SBMI.BatteryData.SavingMode = SWUP.IsBatterySavingMode; + SBMI.BatteryData.SaverStatus = $"{SWUP.GetBatterySaverStatus()}"; - _ = Task.Run(() => + SBMI.BatteryData.LifePercent = SystemInformation.PowerStatus.BatteryLifePercent; + SBMI.BatteryData.PowerLineStatus = SystemInformation.PowerStatus.PowerLineStatus; + SBMI.BatteryData.FullLifetime = SystemInformation.PowerStatus.BatteryFullLifetime; + SBMI.BatteryData.ChargeStatus = SystemInformation.PowerStatus.BatteryChargeStatus; + SBMI.BatteryData.LifeRemaining = SystemInformation.PowerStatus.BatteryLifeRemaining; + + SBMI.BatteryManagement = true; + } + catch (Exception Exception) + { + SBMI.BatteryManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } + + if (SBMI.PingManagement) { - try + SBMI.PingManagement = false; + + _ = Task.Run(() => { - if (SBMI.PingManagement) + try { - SBMI.PingManagement = false; - if (SSSHN.GetHostEntry()) { List Hosts = SSSHN.GetHost(); @@ -195,93 +205,118 @@ public static async Task Start() SBMI.PingManagement = true; } - } - catch (Exception Exception) - { - SBMI.PingManagement = true; - SSWW.Watch_CatchException(Exception); - } - }); + catch (Exception Exception) + { + SBMI.PingManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } - _ = Task.Run(() => + if (SBMI.GraphicManagement) { - try - { - string[] Interfaces = SSSHG.AllVideoController(); + SBMI.GraphicManagement = false; - SMMI.SystemSettingManager.SetSetting(SMC.GraphicInterfaces, Interfaces); - } - catch (Exception Exception) + _ = Task.Run(() => { - SSWW.Watch_CatchException(Exception); - } - }); + try + { + string[] Interfaces = SSSHG.AllVideoController(); - _ = Task.Run(() => + SMMI.SystemSettingManager.SetSetting(SMC.GraphicInterfaces, Interfaces); + } + catch (Exception Exception) + { + SBMI.GraphicManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } + + if (SBMI.NetworkManagement) { - try + SBMI.NetworkManagement = false; + + _ = Task.Run(() => { - string[] Interfaces = SSSHN.InstanceNetworkInterfaces(); + try + { + SBMI.NetworkInterfaces = SSSHN.InstanceNetworkInterfaces(); - SMMI.SystemSettingManager.SetSetting(SMC.NetworkInterfaces, Interfaces); + SMMI.SystemSettingManager.SetSetting(SMC.NetworkInterfaces, SBMI.NetworkInterfaces); + } + catch (Exception Exception) + { + SBMI.NetworkManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } - if (Interfaces.Contains(SMMM.NetworkAdapter)) + if (SBMI.NetworkInterfaces.Any()) + { + _ = Task.Run(() => + { + try { - foreach (string Name in Interfaces) + if (SBMI.NetworkInterfaces.Contains(SMMM.NetworkAdapter)) { - if (SMMM.NetworkAdapter == Name) + foreach (string Name in SBMI.NetworkInterfaces) { - if (SMMM.NetworkAdapter != SBMI.NetworkData.Name) + if (SMMM.NetworkAdapter == Name) { - SBMI.NetworkData.State = true; - SBMI.NetworkData.Name = SMMM.NetworkAdapter; + if (SMMM.NetworkAdapter != SBMI.NetworkData.Name) + { + SBMI.NetworkData.State = true; + SBMI.NetworkData.Name = SMMM.NetworkAdapter; - SBMI.UploadCounter = new("Network Interface", "Bytes Sent/sec", Name); - SBMI.DownloadCounter = new("Network Interface", "Bytes Received/sec", Name); - } + SBMI.UploadCounter = new("Network Interface", "Bytes Sent/sec", Name); + SBMI.DownloadCounter = new("Network Interface", "Bytes Received/sec", Name); + } - if (SBMI.UploadCounter != null) - { - SBMI.NetworkData.Upload = SBMI.UploadCounter.NextValue(); + if (SBMI.UploadCounter != null) + { + SBMI.NetworkData.Upload = SBMI.UploadCounter.NextValue(); - SBMI.NetworkData.UploadData = SSESSE.AutoConvert(SBMI.NetworkData.Upload, SEST.Byte, SEMST.Palila); + SBMI.NetworkData.UploadData = SSESSE.AutoConvert(SBMI.NetworkData.Upload, SEST.Byte, SEMST.Palila); - SBMI.NetworkData.FormatUploadData = SHN.Numeral(SBMI.NetworkData.UploadData.Value, true, true, 2, '0', SECNT.None) + " " + SBMI.NetworkData.UploadData.Text; - } + SBMI.NetworkData.FormatUploadData = SHN.Numeral(SBMI.NetworkData.UploadData.Value, true, true, 2, '0', SECNT.None) + " " + SBMI.NetworkData.UploadData.Text; + } - if (SBMI.DownloadCounter != null) - { - SBMI.NetworkData.Download = SBMI.DownloadCounter.NextValue(); + if (SBMI.DownloadCounter != null) + { + SBMI.NetworkData.Download = SBMI.DownloadCounter.NextValue(); - SBMI.NetworkData.DownloadData = SSESSE.AutoConvert(SBMI.NetworkData.Download, SEST.Byte, SEMST.Palila); + SBMI.NetworkData.DownloadData = SSESSE.AutoConvert(SBMI.NetworkData.Download, SEST.Byte, SEMST.Palila); - SBMI.NetworkData.FormatDownloadData = SHN.Numeral(SBMI.NetworkData.DownloadData.Value, true, true, 2, '0', SECNT.None) + " " + SBMI.NetworkData.DownloadData.Text; - } + SBMI.NetworkData.FormatDownloadData = SHN.Numeral(SBMI.NetworkData.DownloadData.Value, true, true, 2, '0', SECNT.None) + " " + SBMI.NetworkData.DownloadData.Text; + } - break; + break; + } } } + else + { + SBMI.NetworkData.State = false; + SBMI.NetworkData.Name = SMMM.NetworkAdapter; + } } - else + catch (Exception Exception) { - SBMI.NetworkData.State = false; - SBMI.NetworkData.Name = SMMM.NetworkAdapter; + SSWW.Watch_CatchException(Exception); } - } - catch (Exception Exception) - { - SSWW.Watch_CatchException(Exception); - } - }); + }); + } - _ = Task.Run(() => + if (SBMI.MotherboardManagement) { - try + SBMI.MotherboardManagement = false; + + _ = Task.Run(() => { - if (SBMI.MotherboardManagement) + try { - SBMI.MotherboardManagement = false; - ManagementObjectSearcher Searcher = new("SELECT * FROM Win32_BaseBoard"); foreach (ManagementObject Object in Searcher.Get().Cast()) @@ -294,78 +329,116 @@ public static async Task Start() break; } } - } - catch (Exception Exception) - { - SSWW.Watch_CatchException(Exception); - } - }); + catch (Exception Exception) + { + SBMI.MotherboardManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } - _ = Task.Run(() => + if (SBMI.FullscreenManagement) { - try + SBMI.FullscreenManagement = false; + + _ = Task.Run(() => { - IntPtr Foreground = SWNM.GetForegroundWindow(); + try + { + IntPtr Foreground = SWNM.GetForegroundWindow(); - StringBuilder Class = new(256); - SWNM.GetClassName((int)Foreground, Class, 256); + StringBuilder Class = new(256); + SWNM.GetClassName((int)Foreground, Class, 256); - if (!SBMI.FocusDesktop) - { - foreach (SSMMS Screen in SWUS.Screens) + if (!SBMI.FocusDesktop) { - if (SWHF.IsFullscreen(Foreground, Screen.rcMonitor)) + foreach (SSMMS Screen in SWUS.Screens) { - SBMI.Fullscreen = true; + if (SWHF.IsFullscreen(Foreground, Screen.rcMonitor)) + { + SBMI.FullscreenManagement = true; + + SBMI.Fullscreen = true; - return; + return; + } } } - } - SBMI.Fullscreen = false; - } - catch (Exception Exception) - { - SSWW.Watch_CatchException(Exception); - } - }); + SBMI.Fullscreen = false; + SBMI.FullscreenManagement = true; + } + catch (Exception Exception) + { + SBMI.FullscreenManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } - _ = Task.Run(() => + if (SBMI.VirtualityManagement) { - try - { - SBMI.Virtuality = SBEV.VirtualityActive(); - } - catch (Exception Exception) + SBMI.VirtualityManagement = false; + + _ = Task.Run(async () => { - SSWW.Watch_CatchException(Exception); - } - }); + try + { + SBMI.Virtuality = SBEV.VirtualityActive(); - _ = Task.Run(() => + await Task.Delay(SBMI.InitializeTime * 8); + + SBMI.VirtualityManagement = true; + } + catch (Exception Exception) + { + SBMI.VirtualityManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } + + if (SBMI.FocusManagement) { - try - { - SBMI.FocusDesktop = SWUD.IsDesktopBasic() || SWUD.IsDesktopAdvanced(); - } - catch (Exception Exception) + SBMI.FocusManagement = false; + + _ = Task.Run(() => { - SSWW.Watch_CatchException(Exception); - } - }); + try + { + SBMI.FocusDesktop = SWUD.IsDesktopBasic() || SWUD.IsDesktopAdvanced(); - _ = Task.Run(() => + SBMI.FocusManagement = true; + } + catch (Exception Exception) + { + SBMI.FocusManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } + + if (SBMI.RemoteManagement) { - try - { - SBMI.RemoteDesktop = SBER.DesktopActive(); - } - catch (Exception Exception) + SBMI.RemoteManagement = false; + + _ = Task.Run(async () => { - SSWW.Watch_CatchException(Exception); - } - }); + try + { + SBMI.RemoteDesktop = SBER.DesktopActive(); + + await Task.Delay(SBMI.InitializeTime * 8); + + SBMI.RemoteManagement = true; + } + catch (Exception Exception) + { + SBMI.RemoteManagement = true; + SSWW.Watch_CatchException(Exception); + } + }); + } _ = Task.Run(() => { @@ -381,7 +454,7 @@ public static async Task Start() { try { - Hardware.Update(); + //Hardware.Update(); foreach (ISensor Sensor in Hardware.Sensors) { @@ -409,7 +482,7 @@ public static async Task Start() { try { - Hardware.Update(); + //Hardware.Update(); SBMI.MemoryData.State = true; SBMI.MemoryData.Name = Hardware.Name; @@ -453,7 +526,7 @@ public static async Task Start() { try { - Hardware.Update(); + //Hardware.Update(); if (Hardware.Sensors.Any()) { @@ -528,7 +601,7 @@ public static async Task Start() { try { - Hardware.Update(); + //Hardware.Update(); SBMI.MotherboardData.State = true; SBMI.MotherboardData.Name = Hardware.Name; @@ -545,16 +618,16 @@ public static async Task Start() { try { - Hardware.Update(); + //Hardware.Update(); List Sensors = new() - { - new SBSSSS { - Name = Hardware.Name, - Type = $"{Hardware.HardwareType}" - } - }; + new SBSSSS + { + Name = Hardware.Name, + Type = $"{Hardware.HardwareType}" + } + }; foreach (ISensor Sensor in Hardware.Sensors) { diff --git a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs index 6217e7e0a..cab9eb653 100644 --- a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs +++ b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs @@ -52,8 +52,24 @@ internal static class Internal public static bool AudioManagement = true; + public static bool FocusManagement = true; + + public static bool RemoteManagement = true; + public static Timer InitializeTimer = null; + public static bool GraphicManagement = true; + + public static bool NetworkManagement = true; + + public static bool BatteryManagement = true; + + public static bool EqualizerManagement = true; + + public static bool FullscreenManagement = true; + + public static bool VirtualityManagement = true; + public static bool MotherboardManagement = true; public static readonly object LockObject = new(); @@ -74,6 +90,8 @@ internal static class Internal public static NowPlayingSessionManager SessionManager = null; + public static string[] NetworkInterfaces = Array.Empty(); + public static SBSDCS CpuData = new() { Min = 0f,