From 68663d782dc80922a7ce346bd3d606eb9266e252 Mon Sep 17 00:00:00 2001
From: Taiizor <41683699+Taiizor@users.noreply.github.com>
Date: Mon, 18 Sep 2023 19:26:01 +0300
Subject: [PATCH] Preparing Backgroundog
---
src/Library/Sucrose.Manager/Manage/Manager.cs | 2 +
src/Library/Sucrose.Memory/Constant.cs | 2 +
.../Sucrose.Backgroundog/Extension/Data.cs | 30 +++++++++++++
.../Helper/Specification.cs | 44 ++++++++++++++++---
.../Sucrose.Backgroundog/Manage/Internal.cs | 27 +++++++++---
.../Sucrose.Backgroundog/Struct/Data.cs | 37 ++++++++++++++++
.../Sucrose.Shared.Space/Helper/Network.cs | 10 ++++-
7 files changed, 141 insertions(+), 11 deletions(-)
diff --git a/src/Library/Sucrose.Manager/Manage/Manager.cs b/src/Library/Sucrose.Manager/Manage/Manager.cs
index 4cdfddc7e..20c3b7668 100644
--- a/src/Library/Sucrose.Manager/Manage/Manager.cs
+++ b/src/Library/Sucrose.Manager/Manage/Manager.cs
@@ -38,6 +38,8 @@ public static class Manager
public static int TitleLength => SHS.Clamp(SMMI.PortalSettingManager.GetSettingStable(SMC.TitleLength, 25), 10, 100);
+ public static string NetworkAdapter => SMMI.BackgroundogSettingManager.GetSetting(SMC.NetworkAdapter, string.Empty);
+
public static bool PerformanceCounter => SMMI.BackgroundogSettingManager.GetSetting(SMC.PerformanceCounter, true);
public static string LibrarySelected => SMMI.LibrarySettingManager.GetSetting(SMC.LibrarySelected, string.Empty);
diff --git a/src/Library/Sucrose.Memory/Constant.cs b/src/Library/Sucrose.Memory/Constant.cs
index 3763fcf40..5ac511ade 100644
--- a/src/Library/Sucrose.Memory/Constant.cs
+++ b/src/Library/Sucrose.Memory/Constant.cs
@@ -88,6 +88,8 @@ public static class Constant
public const string DiscordRefresh = "DiscordRefresh";
+ public const string NetworkAdapter = "NetworkAdapter";
+
public const string StorePagination = "StorePagination";
public const string LibraryLocation = "LibraryLocation";
diff --git a/src/Project/Sucrose.Backgroundog/Extension/Data.cs b/src/Project/Sucrose.Backgroundog/Extension/Data.cs
index bf3f155c9..67a5eebb7 100644
--- a/src/Project/Sucrose.Backgroundog/Extension/Data.cs
+++ b/src/Project/Sucrose.Backgroundog/Extension/Data.cs
@@ -71,6 +71,36 @@ public static JObject GetBatteryInfo()
};
}
+ public static JObject GetNetworkInfo()
+ {
+ return new JObject
+ {
+ { "Name", SBMI.NetworkData.Name },
+ { "Upload", SBMI.NetworkData.Upload },
+ { "Download", SBMI.NetworkData.Download },
+ { "FormatUploadData", SBMI.NetworkData.FormatUploadData },
+ { "FormatDownloadData", SBMI.NetworkData.FormatDownloadData },
+ {
+ "UploadData", new JObject
+ {
+ { "Text", SBMI.NetworkData.UploadData.Text },
+ { "Value", SBMI.NetworkData.UploadData.Value },
+ { "Type", SBMI.NetworkData.UploadData.Type.ToString() },
+ { "Short", SBMI.NetworkData.UploadData.Short.ToString() },
+ }
+ },
+ {
+ "DownloadData", new JObject
+ {
+ { "Text", SBMI.NetworkData.DownloadData.Text },
+ { "Value", SBMI.NetworkData.DownloadData.Value },
+ { "Type", SBMI.NetworkData.DownloadData.Type.ToString() },
+ { "Short", SBMI.NetworkData.DownloadData.Short.ToString() },
+ }
+ },
+ };
+ }
+
public static JObject GetMotherboardInfo()
{
return new JObject
diff --git a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs
index f73274919..f8c603e26 100644
--- a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs
+++ b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs
@@ -1,8 +1,13 @@
using LibreHardwareMonitor.Hardware;
using Newtonsoft.Json;
+using Skylark.Enum;
+using Skylark.Helper;
+using Skylark.Standard.Extension.Storage;
using Sucrose.Backgroundog.Extension;
using System.Management;
using SBMI = Sucrose.Backgroundog.Manage.Internal;
+using SMMM = Sucrose.Manager.Manage.Manager;
+using SSSHN = Sucrose.Shared.Space.Helper.Network;
namespace Sucrose.Backgroundog.Helper
{
@@ -159,11 +164,40 @@ public static async Task Start()
}
}
- 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));
+ _ = Task.Run(() =>
+ {
+ foreach (string Name in SSSHN.InstanceNetworkInterfaces())
+ {
+ if (SMMM.NetworkAdapter == Name)
+ {
+ if (SMMM.NetworkAdapter != SBMI.NetworkData.Name)
+ {
+ SBMI.NetworkData.Name = SMMM.NetworkAdapter;
+
+ SBMI.UploadCounter = new("Network Interface", "Bytes Sent/sec", Name);
+ SBMI.DownloadCounter = new("Network Interface", "Bytes Received/sec", Name);
+ }
+
+ SBMI.NetworkData.Upload = SBMI.UploadCounter.NextValue();
+ SBMI.NetworkData.Download = SBMI.DownloadCounter.NextValue();
+
+ SBMI.NetworkData.UploadData = StorageExtension.AutoConvert(SBMI.NetworkData.Upload, StorageType.Byte, ModeStorageType.Palila);
+ SBMI.NetworkData.DownloadData = StorageExtension.AutoConvert(SBMI.NetworkData.Download, StorageType.Byte, ModeStorageType.Palila);
+
+ SBMI.NetworkData.FormatUploadData = Numeric.Numeral(SBMI.NetworkData.UploadData.Value, true, true, 2, '0', ClearNumericType.None) + " " + SBMI.NetworkData.UploadData.Text;
+ SBMI.NetworkData.FormatDownloadData = Numeric.Numeral(SBMI.NetworkData.DownloadData.Value, true, true, 2, '0', ClearNumericType.None) + " " + SBMI.NetworkData.DownloadData.Text;
+
+ break;
+ }
+ }
+ });
+
+ //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.GetNetworkInfo(), 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 b9960055f..20907df3c 100644
--- a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs
+++ b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs
@@ -1,8 +1,10 @@
using LibreHardwareMonitor.Hardware;
+using System.Diagnostics;
using SBSDBS = Sucrose.Backgroundog.Struct.Data.BatteryStruct;
using SBSDCS = Sucrose.Backgroundog.Struct.Data.CpuStruct;
using SBSDMDS = Sucrose.Backgroundog.Struct.Data.MotherboardStruct;
using SBSDMYS = Sucrose.Backgroundog.Struct.Data.MemoryStruct;
+using SBSDNS = Sucrose.Backgroundog.Struct.Data.NetworkStruct;
using Timer = System.Threading.Timer;
namespace Sucrose.Backgroundog.Manage
@@ -21,6 +23,10 @@ internal static class Internal
public static Timer InitializeTimer = null;
+ public static PerformanceCounter UploadCounter = null;
+
+ public static PerformanceCounter DownloadCounter = null;
+
public static SBSDCS CpuData = new()
{
Min = 0f,
@@ -45,15 +51,15 @@ internal static class Internal
public static Computer Computer = new()
{
- IsCpuEnabled = true,
- IsGpuEnabled = false,
+ IsCpuEnabled = false,
+ IsGpuEnabled = true,
IsPsuEnabled = false,
- IsMemoryEnabled = true,
+ IsMemoryEnabled = false,
IsNetworkEnabled = false,
IsStorageEnabled = false,
- IsBatteryEnabled = true,
+ IsBatteryEnabled = false,
IsControllerEnabled = false,
- IsMotherboardEnabled = true,
+ IsMotherboardEnabled = false,
};
public static SBSDBS BatteryData = new()
@@ -75,6 +81,17 @@ internal static class Internal
RemainingTimeEstimated = 0f
};
+ public static SBSDNS NetworkData = new()
+ {
+ Upload = 0f,
+ Download = 0f,
+ UploadData = new(),
+ Name = string.Empty,
+ DownloadData = new(),
+ FormatUploadData = string.Empty,
+ FormatDownloadData = string.Empty
+ };
+
public static SBSDMDS MotherboardData = new()
{
Name = string.Empty
diff --git a/src/Project/Sucrose.Backgroundog/Struct/Data.cs b/src/Project/Sucrose.Backgroundog/Struct/Data.cs
index 675f529e0..64876a06d 100644
--- a/src/Project/Sucrose.Backgroundog/Struct/Data.cs
+++ b/src/Project/Sucrose.Backgroundog/Struct/Data.cs
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
+using SSSSS = Skylark.Struct.Storage.StorageStruct;
namespace Sucrose.Backgroundog.Struct.Data
{
@@ -142,6 +143,42 @@ public struct BatteryStruct
public float? RemainingTimeEstimated;
}
+ ///
+ ///
+ ///
+ [StructLayout(LayoutKind.Sequential)]
+ public struct NetworkStruct
+ {
+ ///
+ ///
+ ///
+ public string Name;
+ ///
+ ///
+ ///
+ public float Upload;
+ ///
+ ///
+ ///
+ public float Download;
+ ///
+ ///
+ ///
+ public SSSSS UploadData;
+ ///
+ ///
+ ///
+ public SSSSS DownloadData;
+ ///
+ ///
+ ///
+ public string FormatUploadData;
+ ///
+ ///
+ ///
+ public string FormatDownloadData;
+ }
+
///
///
///
diff --git a/src/Shared/Sucrose.Shared.Space/Helper/Network.cs b/src/Shared/Sucrose.Shared.Space/Helper/Network.cs
index c223a1142..7b514cf83 100644
--- a/src/Shared/Sucrose.Shared.Space/Helper/Network.cs
+++ b/src/Shared/Sucrose.Shared.Space/Helper/Network.cs
@@ -1,4 +1,5 @@
-using System.Net;
+using System.Diagnostics;
+using System.Net;
using System.Net.NetworkInformation;
using SMR = Sucrose.Memory.Readonly;
@@ -25,6 +26,13 @@ public static bool IsInternetAvailable()
return NetworkInterface.GetIsNetworkAvailable();
}
+ public static string[] InstanceNetworkInterfaces()
+ {
+ PerformanceCounterCategory Category = new("Network Interface");
+
+ return Category.GetInstanceNames();
+ }
+
public static NetworkInterface[] AllNetworkInterfaces()
{
return NetworkInterface.GetAllNetworkInterfaces();