Skip to content

Commit

Permalink
Merge pull request #15 from Saibamen/csharp_code_fixes
Browse files Browse the repository at this point in the history
Csharp code fixes
  • Loading branch information
hedihadi authored Nov 9, 2024
2 parents 37261e9 + 6deb76a commit a6bcbf0
Show file tree
Hide file tree
Showing 34 changed files with 367 additions and 391 deletions.
4 changes: 2 additions & 2 deletions zal_program/Zal/Backend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace Zal
{
public class BackendManager
{
readonly computerDataGetter computerDataGetter = null;
private readonly computerDataGetter computerDataGetter;
public event EventHandler<string> fpsDataReceived;
readonly FpsDataGetter fpsDataGetter = new FpsDataGetter();
private readonly FpsDataGetter fpsDataGetter = new();

public BackendManager()
{
Expand Down
4 changes: 2 additions & 2 deletions zal_program/Zal/Backend/Constants/Models/ComputerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class computerData

public computerData()
{
gpuData = new List<gpuData>();
storagesData = new List<storageData>();
gpuData = [];
storagesData = [];
}
}
}
20 changes: 7 additions & 13 deletions zal_program/Zal/Backend/Constants/Models/CpuData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ public class cpuData
public uint temperature;
public uint load;
public ulong power;
public Dictionary<string, dynamic> powers = new Dictionary<string, dynamic>();
public Dictionary<string, dynamic> loads = new Dictionary<string, dynamic>();
public Dictionary<string, dynamic> voltages = new Dictionary<string, dynamic>();
public Dictionary<string, dynamic> clocks = new Dictionary<string, dynamic>();
public Dictionary<string, dynamic> powers = [];
public Dictionary<string, dynamic> loads = [];
public Dictionary<string, dynamic> voltages = [];
public Dictionary<string, dynamic> clocks = [];

public cpuData(IHardware hardware, cpuInfo? cpuInfo)
{
this.cpuInfo = cpuInfo;
name = hardware.Name;

foreach (ISensor sensor in hardware.Sensors)
foreach (var sensor in hardware.Sensors)
{
if (sensor.SensorType == SensorType.Power)
{
Expand Down Expand Up @@ -60,15 +60,9 @@ public cpuData(IHardware hardware, cpuInfo? cpuInfo)
else
{
var foundSensor = hardware.Sensors.FirstOrDefault(s => s.SensorType == SensorType.Temperature && s.Name.Contains("(Tctl/Tdie)"));
if (foundSensor == null)
{
foundSensor = hardware.Sensors.FirstOrDefault(s => s.SensorType == SensorType.Temperature && s.Name.Contains("Average"));
}
foundSensor ??= hardware.Sensors.FirstOrDefault(s => s.SensorType == SensorType.Temperature && s.Name.Contains("Average"));

if (foundSensor == null)
{
foundSensor = hardware.Sensors.FirstOrDefault(s => s.SensorType == SensorType.Temperature && s.Name.Contains("Core #1"));
}
foundSensor ??= hardware.Sensors.FirstOrDefault(s => s.SensorType == SensorType.Temperature && s.Name.Contains("Core #1"));

if (foundSensor != null)
{
Expand Down
2 changes: 1 addition & 1 deletion zal_program/Zal/Backend/Constants/Models/GpuData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public gpuData(IHardware? hardware)
return;
}

foreach (ISensor sensor in hardware.Sensors)
foreach (var sensor in hardware.Sensors)
{
if (sensor.SensorType == SensorType.Clock && sensor.Name == "GPU Core")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class motherboardData
public motherboardData(IHardware hardware)
{
name = hardware.Name;
foreach (ISensor sensor in hardware.Sensors)
foreach (var sensor in hardware.Sensors)
{
if (sensor.SensorType == SensorType.Temperature)
{
Expand Down
2 changes: 1 addition & 1 deletion zal_program/Zal/Backend/Constants/Models/RamData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ramData
public ramData(IHardware hardware, List<ramPieceData>? ramPiecesData)
{
this.ramPiecesData = ramPiecesData;
foreach (ISensor sensor in hardware.Sensors)
foreach (var sensor in hardware.Sensors)
{
if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Used")
{
Expand Down
22 changes: 9 additions & 13 deletions zal_program/Zal/Backend/Constants/Models/StorageData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class storageData
public ulong? writeRate { get; set; }
//whether it's hdd, ssd, or external storage
public string type { get; set; }
public List<partitionInfo> partitions { get; } = new List<partitionInfo>();
public Dictionary<string, dynamic> info = new Dictionary<string, dynamic>();
public List<smartAttribute> smartAttributes = new List<smartAttribute>();
public List<partitionInfo> partitions { get; } = [];
public Dictionary<string, dynamic> info = [];
public List<smartAttribute> smartAttributes = [];
public storageData(IHardware hardware, List<crystalDiskData>? crystalDiskDatas)
{
type = "External";
crystalDiskData? crystalDiskData = null;
if (crystalDiskDatas != null)
{
foreach (crystalDiskData _crystalDiskData in crystalDiskDatas)
foreach (var _crystalDiskData in crystalDiskDatas)
{
if (_crystalDiskData.info["model"] == hardware.Name)
{
Expand All @@ -50,17 +50,16 @@ public storageData(IHardware hardware, List<crystalDiskData>? crystalDiskDatas)
}
}

foreach (ISensor sensor in hardware.Sensors)
foreach (var sensor in hardware.Sensors)
{
if (sensor.SensorType == SensorType.Temperature)
{
try
{
temperature = (ulong)sensor.Value;
}
catch (Exception ex)
catch (Exception)
{

}
}
else if (sensor.SensorType == SensorType.Throughput && sensor.Name == "Read Rate")
Expand All @@ -72,11 +71,9 @@ public storageData(IHardware hardware, List<crystalDiskData>? crystalDiskDatas)
{
readRate = ulong.Parse(sensor.Value.ToString().Split('.')[0]);
}

}
catch (Exception ex)
catch (Exception)
{

}

}
Expand All @@ -86,9 +83,8 @@ public storageData(IHardware hardware, List<crystalDiskData>? crystalDiskDatas)
{
writeRate = (ulong)sensor.Value;
}
catch (Exception ex)
catch (Exception)
{

}
}
}
Expand Down Expand Up @@ -129,5 +125,5 @@ public class diskInfo
public int diskNumber { get; set; }
public long totalSize { get; set; }
public ulong freeSpace { get; set; }
public List<partitionInfo> partitions { get; } = new List<partitionInfo>();
public List<partitionInfo> partitions { get; } = [];
}
42 changes: 22 additions & 20 deletions zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ namespace Zal.HelperFunctions
{
public class computerDataGetter
{

private readonly cpuInfo? cpuInfo;
private readonly List<crystalDiskData>? crystalDiskDatas;
private readonly List<ramPieceData>? ramPiecesData;
//this variable holds the network speed that the user has chosen as primary.
private readonly networkSpeed primarynetworkSpeed = new networkSpeed(download: 0, upload: 0);
private readonly networkSpeed primarynetworkSpeed = new(download: 0, upload: 0);

private readonly NetworkSpeedGetter networkSpeedGetter = new NetworkSpeedGetter();
private readonly NetworkSpeedGetter networkSpeedGetter = new();
//disabled fps feature because it's buggy
//public fpsDataGetter fpsDataGetter;
//this variable holds the processes and how much % gpu they use. we use this data to determine which process is a game. and get the fps data from it.
private readonly Dictionary<int, double> processesGpuUsage = new Dictionary<int, double>();
private readonly Computer computer = new Computer
private readonly Dictionary<int, double> processesGpuUsage = [];
private readonly Computer computer = new()
{
IsCpuEnabled = true,
IsGpuEnabled = true,
Expand All @@ -45,7 +44,7 @@ public computerDataGetter()
computer.Open();
break;
}
catch (Exception ex)
catch (Exception)
{
attempts++;
}
Expand Down Expand Up @@ -84,18 +83,21 @@ public computerDataGetter()
}
public string getEntireComputerData()
{
computerData computerData = new computerData();
var computerData = new computerData();
computer.Accept(new UpdateVisitor());
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (IHardware hardware in computer.Hardware)
var result = new Dictionary<string, object>();
foreach (var hardware in computer.Hardware)
{
Dictionary<string, object> data = new Dictionary<string, object>();
data["type"] = hardware.HardwareType.ToString();
var data = new Dictionary<string, object>
{
["type"] = hardware.HardwareType.ToString()
};
foreach (var sensor in hardware.Sensors)
{
Dictionary<string, object> sensorData = new Dictionary<string, object>();
sensorData["type"] = sensor.SensorType.ToString();
sensorData["value"] = sensor.Value.ToString();
var sensorData = new Dictionary<string, object> {
["type"] = sensor.SensorType.ToString(),
["value"] = sensor.Value.ToString(),
};
data[sensor.Name] = sensorData;
}

Expand All @@ -106,7 +108,7 @@ public string getEntireComputerData()
}
public async Task<computerData> getcomputerDataAsync()
{
computerData computerData = new computerData();
var computerData = new computerData();
computer.Accept(new UpdateVisitor());
GlobalClass.Instance.processesGetter.update();
computerData.isAdminstrator = IsAdminstratorChecker.IsAdministrator();
Expand All @@ -115,7 +117,7 @@ public async Task<computerData> getcomputerDataAsync()
{
Logger.Log("warning getting computer data, computerHardware count is 0");
}
foreach (IHardware hardware in computer.Hardware)
foreach (var hardware in computer.Hardware)
{
//Console.WriteLine($"name:{hardware.Name},type:{hardware.HardwareType}");
var gpuTypes = new HardwareType[] { HardwareType.GpuNvidia, HardwareType.GpuIntel, HardwareType.GpuAmd };
Expand Down Expand Up @@ -182,7 +184,7 @@ public async Task<computerData> getcomputerDataAsync()
}
try
{
List<monitorData>? monitorsData = monitorDataGetter.getmonitorData();
var monitorsData = monitorDataGetter.getmonitorData();
computerData.monitorsData = monitorsData;
}
catch (Exception ex)
Expand All @@ -191,7 +193,7 @@ public async Task<computerData> getcomputerDataAsync()
}
try
{
batteryData? batteryData = batteryDataGetter.getbatteryData();
var batteryData = batteryDataGetter.getbatteryData();
computerData.batteryData = batteryData;
}
catch (Exception ex)
Expand Down Expand Up @@ -227,7 +229,7 @@ public async Task<computerData> getcomputerDataAsync()
}
}

class UpdateVisitor : IVisitor
internal class UpdateVisitor : IVisitor
{
public void VisitComputer(IComputer computer)
{
Expand All @@ -250,7 +252,7 @@ public void VisitHardware(IHardware hardware)
}
}

foreach (IHardware subHardware in hardware.SubHardware) subHardware.Accept(this);
foreach (var subHardware in hardware.SubHardware) subHardware.Accept(this);
}

public void VisitSensor(ISensor sensor)
Expand Down
Loading

0 comments on commit a6bcbf0

Please sign in to comment.