Skip to content

Commit

Permalink
Preparing Backgroundog
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 20, 2023
1 parent e352362 commit b1327ac
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Project/Sucrose.Backgroundog/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/Project/Sucrose.Backgroundog/Extension/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};
Expand All @@ -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 },
Expand All @@ -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 },
Expand Down Expand Up @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
Expand Down Expand Up @@ -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 }
Expand Down
22 changes: 13 additions & 9 deletions src/Project/Sucrose.Backgroundog/Extension/Thumbnail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ 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))
{
return CropImage(Image, 34, 1, 233, 233);
}
}

byte[] Array = Stream.ToArray();
byte[] Array = MemoryStream.ToArray();

MemoryStream.Flush();

return Convert.ToBase64String(Array);
}
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Project/Sucrose.Backgroundog/Helper/Initialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions src/Project/Sucrose.Backgroundog/Helper/Specification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static async Task Start()

foreach (ManagementObject Object in Searcher.Get().Cast<ManagementObject>())
{
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"]);
Expand All @@ -45,6 +46,7 @@ public static async Task Start()

foreach (ManagementObject Object in Searcher.Get().Cast<ManagementObject>())
{
SBMI.BiosData.State = true;
SBMI.BiosData.Name = Object["Name"].ToString();
SBMI.BiosData.Caption = Object["Caption"].ToString();
SBMI.BiosData.Version = Object["Version"].ToString();
Expand All @@ -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;
}
}
Expand All @@ -64,6 +67,7 @@ public static async Task Start()

SBMI.DateData = new()
{
State = true,
Day = Date.Day,
Hour = Date.Hour,
Year = Date.Year,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -124,9 +129,11 @@ public static async Task Start()

foreach (ManagementObject Object in Searcher.Get().Cast<ManagementObject>())
{
SBMI.MotherboardData.State = true;
SBMI.MotherboardData.Product = Object["Product"].ToString();
SBMI.MotherboardData.Version = Object["Version"].ToString();
SBMI.MotherboardData.Manufacturer = Object["Manufacturer"].ToString();

break;
}
}
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -249,6 +259,7 @@ public static async Task Start()
{
Hardware.Update();

SBMI.MotherboardData.State = true;
SBMI.MotherboardData.Name = Hardware.Name;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/Project/Sucrose.Backgroundog/Manage/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -77,6 +83,7 @@ internal static class Internal
Month = 0,
Minute = 0,
Second = 0,
State = false,
Millisecond = 0
};

Expand Down Expand Up @@ -116,6 +123,7 @@ internal static class Internal

public static SBSDMYS MemoryData = new()
{
State = false,
MemoryUsed = 0f,
MemoryLoad = 0f,
Name = string.Empty,
Expand All @@ -141,6 +149,7 @@ internal static class Internal
public static SBSDNS NetworkData = new()
{
Upload = 0f,
State = false,
Download = 0f,
UploadData = new(),
Name = string.Empty,
Expand All @@ -152,6 +161,7 @@ internal static class Internal
public static SBSDBYS BatteryData = new()
{
Voltage = 0f,
State = false,
ChargeRate = 0f,
ChargeLevel = 0f,
ChargeCurrent = 0f,
Expand All @@ -170,6 +180,7 @@ internal static class Internal

public static SBSDMDS MotherboardData = new()
{
State = false,
Name = string.Empty,
Product = string.Empty,
Version = string.Empty,
Expand Down
28 changes: 28 additions & 0 deletions src/Project/Sucrose.Backgroundog/Struct/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public struct CpuStruct
/// <summary>
///
/// </summary>
public bool State;
/// <summary>
///
/// </summary>
public int? Thread;
/// <summary>
///
Expand All @@ -46,6 +50,10 @@ public struct CpuStruct
[StructLayout(LayoutKind.Sequential)]
public struct BiosStruct
{
/// <summary>
///
/// </summary>
public bool State;
/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -113,6 +121,10 @@ public struct DateStruct
/// <summary>
///
/// </summary>
public bool State;
/// <summary>
///
/// </summary>
public int Millisecond;
}

Expand Down Expand Up @@ -250,6 +262,10 @@ public struct AudioStruct
[StructLayout(LayoutKind.Sequential)]
public struct MemoryStruct
{
/// <summary>
///
/// </summary>
public bool State;
/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -286,6 +302,10 @@ public struct MemoryStruct
[StructLayout(LayoutKind.Sequential)]
public struct BatteryStruct
{
/// <summary>
///
/// </summary>
public bool State;
/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -354,6 +374,10 @@ public struct BatteryStruct
[StructLayout(LayoutKind.Sequential)]
public struct NetworkStruct
{
/// <summary>
///
/// </summary>
public bool State;
/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -390,6 +414,10 @@ public struct NetworkStruct
[StructLayout(LayoutKind.Sequential)]
public struct MotherboardStruct
{
/// <summary>
///
/// </summary>
public bool State;
/// <summary>
///
/// </summary>
Expand Down

0 comments on commit b1327ac

Please sign in to comment.