From 6f2bc9f9153543f33cc31c5c413431912c958e48 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:34:22 +0100 Subject: [PATCH 01/15] Use explicit modifiers, sort modifiers --- zal_program/Zal/Backend.cs | 4 ++-- .../HelperFunctions/ComputerDataGetter.cs | 2 +- .../Backend/HelperFunctions/FilesGetter.cs | 5 +++-- .../Backend/HelperFunctions/FpsDataGetter.cs | 4 ++-- .../Zal/Backend/HelperFunctions/Logger.cs | 4 ++-- .../HelperFunctions/ProcessesGetter.cs | 2 +- .../SpecificFunctions/BatteryDataGetter.cs | 2 +- .../SpecificFunctions/CpuInfoGetter.cs | 2 +- .../CrystalDiskInfoGetter.cs | 8 ++++---- .../SpecificFunctions/DiskInfoGetter.cs | 20 ++++++++----------- .../SpecificFunctions/GpuUtilizationGetter.cs | 2 +- .../SpecificFunctions/IpGetter.cs | 3 ++- .../IsAdminstratorChecker.cs | 2 +- .../SpecificFunctions/MonitorDataGetter.cs | 2 +- .../SpecificFunctions/NetworkSpeedGetter.cs | 2 +- .../SpecificFunctions/ProcessPathGetter.cs | 2 +- .../SpecificFunctions/RamPieceDataGetter.cs | 2 +- .../Functions/MajorFunctions/DataManager.cs | 5 +++-- .../Functions/MajorFunctions/LocalDatabase.cs | 6 +++--- zal_program/Zal/MainForm.cs | 6 +++--- zal_program/Zal/Pages/ConfigurationsForm.cs | 4 ++-- zal_program/Zal/Program.cs | 3 ++- 22 files changed, 46 insertions(+), 46 deletions(-) diff --git a/zal_program/Zal/Backend.cs b/zal_program/Zal/Backend.cs index 868dd1f..7516ad9 100644 --- a/zal_program/Zal/Backend.cs +++ b/zal_program/Zal/Backend.cs @@ -9,9 +9,9 @@ namespace Zal { public class BackendManager { - readonly computerDataGetter computerDataGetter = null; + private readonly computerDataGetter computerDataGetter = null; public event EventHandler fpsDataReceived; - readonly FpsDataGetter fpsDataGetter = new FpsDataGetter(); + private readonly FpsDataGetter fpsDataGetter = new FpsDataGetter(); public BackendManager() { diff --git a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs index ae2b823..1c18c12 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs @@ -227,7 +227,7 @@ public async Task getcomputerDataAsync() } } -class UpdateVisitor : IVisitor +internal class UpdateVisitor : IVisitor { public void VisitComputer(IComputer computer) { diff --git a/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs index adae1c9..4409250 100644 --- a/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs @@ -8,8 +8,9 @@ namespace ZalConsole.HelperFunctions public class FilesGetter { ///used to send file to mobile, this can be used to stop sending the file. - readonly CancellationTokenSource cts; - readonly int chunkSize = 153600; + private readonly CancellationTokenSource cts; + + private readonly int chunkSize = 153600; // SocketIOClient.SocketIO client; //var client; // public FilesGetter(SocketIOClient.SocketIO client) { diff --git a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs index 8e20248..764db04 100644 --- a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs @@ -16,8 +16,8 @@ public class FpsDataGetter public event EventHandler sendFpsData; private readonly List fpsDatas = []; private readonly int processId; - readonly Stopwatch stopwatch = new Stopwatch(); - bool shouldLog = false; + private readonly Stopwatch stopwatch = new Stopwatch(); + private bool shouldLog = false; public FpsDataGetter() { diff --git a/zal_program/Zal/Backend/HelperFunctions/Logger.cs b/zal_program/Zal/Backend/HelperFunctions/Logger.cs index 5e89077..4314a12 100644 --- a/zal_program/Zal/Backend/HelperFunctions/Logger.cs +++ b/zal_program/Zal/Backend/HelperFunctions/Logger.cs @@ -5,7 +5,7 @@ namespace Zal { public static class Logger { - static readonly object _locker = new object(); + private static readonly object _locker = new object(); public static void LogError(string message, Exception ex, object dataToPrint = null) { @@ -47,7 +47,7 @@ public static void ResetLog() } } - static void WriteToLog(string logMessage, string logFilePath) + private static void WriteToLog(string logMessage, string logFilePath) { lock (_locker) { diff --git a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs index 0d956e8..ae60548 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs @@ -8,7 +8,7 @@ namespace Zal.HelperFunctions { public class ProcessesGetter { - readonly SocketIOClient.SocketIO client = new SocketIOClient.SocketIO($"http://localhost:6511/"); + private readonly SocketIOClient.SocketIO client = new SocketIOClient.SocketIO($"http://localhost:6511/"); private readonly Dictionary> taskCompletionSources = new Dictionary>(); public Dictionary data = new Dictionary(); diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs index 7560500..0785623 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs @@ -3,7 +3,7 @@ namespace Zal.HelperFunctions.SpecificFunctions { - class batteryDataGetter + internal class batteryDataGetter { public static batteryData getbatteryData() { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs index 1b6e08c..bb34e91 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs @@ -4,7 +4,7 @@ namespace Zal.HelperFunctions.SpecificcomputerDataFunctions { - class cpuInfoGetter + internal class cpuInfoGetter { public static cpuInfo getcpuInfo() { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs index 7bff398..125c5a8 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs @@ -9,9 +9,9 @@ namespace Zal.HelperFunctions.SpecificFunctions { - class CrystaldiskInfoGetter + internal class CrystaldiskInfoGetter { - static public List? getcrystalDiskData() + public static List? getcrystalDiskData() { if (IsAdminstratorChecker.IsAdministrator() == false) { @@ -57,7 +57,7 @@ class CrystaldiskInfoGetter return null; } - static private List parseCrystaldiskInfoOutput(string filePath) + private static List parseCrystaldiskInfoOutput(string filePath) { List hardwareList = new List(); crystalDiskData currentHardware = null; @@ -244,7 +244,7 @@ static private List parseCrystaldiskInfoOutput(string filePath) return hardwareList; } - static List ParseDriveLettersFromString(string input) + private static List ParseDriveLettersFromString(string input) { List driveLetters = new List(); diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs index 3563c53..4153bbe 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs @@ -7,13 +7,12 @@ namespace Zal.HelperFunctions.SpecificFunctions { - class diskInfoGetter + internal class diskInfoGetter { - static public diskInfo GetdiskInfo(int diskNumber,crystalDiskData? crystalDiskData) + public static diskInfo GetdiskInfo(int diskNumber,crystalDiskData? crystalDiskData) { foreach (ManagementObject disk in GlobalClass.Instance.getWin32DiskDrives()) { - //iterate until we get the disk number we want int diskIndex = Convert.ToInt32(disk["Index"]); if (diskIndex != diskNumber) continue; @@ -24,7 +23,6 @@ static public diskInfo GetdiskInfo(int diskNumber,crystalDiskData? crystalDiskDa foreach (ManagementObject partition in GlobalClass.Instance.getWin32DiskPartitions(diskNumber)) { - partitionInfo partitionInfo = new partitionInfo(); if (crystalDiskData != null) { @@ -36,8 +34,6 @@ static public diskInfo GetdiskInfo(int diskNumber,crystalDiskData? crystalDiskDa partitionInfo.freeSpace = driveInfo.TotalFreeSpace; partitionInfo.label = driveInfo.VolumeLabel; } - - } else { @@ -54,8 +50,9 @@ static public diskInfo GetdiskInfo(int diskNumber,crystalDiskData? crystalDiskDa return null; } + //this is a fallback function in case crystalDiskData is not available - static private string GetDriveLetter(ManagementObject partition) + private static string GetDriveLetter(ManagementObject partition) { using (ManagementObjectSearcher searcher = new ManagementObjectSearcher($"ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{partition["DeviceID"]}'}} WHERE AssocClass=Win32_LogicalDiskToPartition")) { @@ -67,6 +64,7 @@ static private string GetDriveLetter(ManagementObject partition) } return ""; } + private static DriveInfo? GetDriveByLetter(string driveName) { foreach (DriveInfo drive in DriveInfo.GetDrives()) @@ -78,14 +76,14 @@ static private string GetDriveLetter(ManagementObject partition) if (driveLetter == driveName) { return drive; - + } } return null; } - static private ulong GetFreeSpaceForDisk(int diskNumber) - { + private static ulong GetFreeSpaceForDisk(int diskNumber) + { var managementObjectDisks = GlobalClass.Instance.getWin32DiskPartitionsForFreeDiskSpace(); foreach (ManagementObject disk in managementObjectDisks) { @@ -112,7 +110,5 @@ static private ulong GetFreeSpaceForDisk(int diskNumber) return 0; } - } - } diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs index 6404f21..4411f16 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs @@ -10,7 +10,7 @@ namespace ZalConsole.HelperFunctions.SpecificFunctions { - class GpuUtilizationGetter + internal class GpuUtilizationGetter { //this function is based on this https://github.com/GameTechDev/PresentMon/issues/189 //and some modifications to make the data to be parsed easier from c# side. diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IpGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IpGetter.cs index 1e585eb..1e90c9f 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IpGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IpGetter.cs @@ -2,7 +2,8 @@ using System.Net.Sockets; namespace Zal.Backend.HelperFunctions.SpecificFunctions; -class IpGetter + +internal class IpGetter { public static string getIp() { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IsAdminstratorChecker.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IsAdminstratorChecker.cs index 1b88889..747d083 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IsAdminstratorChecker.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IsAdminstratorChecker.cs @@ -2,7 +2,7 @@ namespace Zal.HelperFunctions.SpecificFunctions { - class IsAdminstratorChecker + internal class IsAdminstratorChecker { public static bool IsAdministrator() { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs index cd82d0d..650520e 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs @@ -4,7 +4,7 @@ namespace Zal.HelperFunctions.SpecificFunctions { - class monitorDataGetter + internal class monitorDataGetter { public static List? getmonitorData() { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs index 16b086c..798afa0 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs @@ -9,7 +9,7 @@ namespace ZalConsole.HelperFunctions.SpecificFunctions { - class NetworkSpeedGetter + internal class NetworkSpeedGetter { public networkSpeed primaryNetworkSpeed; private readonly Timer networkInterfaceTimer; diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/ProcessPathGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/ProcessPathGetter.cs index 9f4d51a..eb2b9e1 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/ProcessPathGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/ProcessPathGetter.cs @@ -3,7 +3,7 @@ namespace Zal.HelperFunctions.SpecificFunctions { - class ProcesspathGetter + internal class ProcesspathGetter { ///saves process path public static void save(string name, string processPath) diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs index 7cad38f..91534d6 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs @@ -4,7 +4,7 @@ namespace Zal.HelperFunctions.SpecificFunctions { - class ramPieceDataGetter + internal class ramPieceDataGetter { public static List GetRamPiecesData() { diff --git a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs index a00f114..c86cdd7 100644 --- a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs +++ b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs @@ -90,7 +90,8 @@ private async Task sendDataToMobile() var compressedData = CompressGzip(Newtonsoft.Json.JsonConvert.SerializeObject(data)); FrontendGlobalClass.Instance.localSocket?.sendMessage("pc_data", compressedData); } - static string CompressGzip(string text) + + private static string CompressGzip(string text) { byte[] enCodedJson = Encoding.UTF8.GetBytes(text); @@ -109,7 +110,7 @@ static string CompressGzip(string text) } } -class ChartsDataManager +internal class ChartsDataManager { private readonly Dictionary> data = new Dictionary>(); diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs index de39414..31a88e4 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs @@ -8,7 +8,7 @@ namespace Zal { public class LocalDatabase { - readonly Dictionary data = new Dictionary(); + private readonly Dictionary data = new Dictionary(); private static LocalDatabase instance; private readonly SemaphoreSlim _writeSemaphore = new SemaphoreSlim(1); @@ -17,7 +17,7 @@ private LocalDatabase(Dictionary initData) data = initData; } - public async static Task Initialize() + public static async Task Initialize() { var text = await GlobalClass.Instance.readTextFromDocumentFolder("database.json"); if (text != null && text != "") @@ -79,7 +79,7 @@ public async Task writeKey(string key, object text) } } - static private void WriteAsync(string text) + private static void WriteAsync(string text) { GlobalClass.Instance.saveTextToDocumentFolder("database.json", text); diff --git a/zal_program/Zal/MainForm.cs b/zal_program/Zal/MainForm.cs index f0232d2..40c0999 100644 --- a/zal_program/Zal/MainForm.cs +++ b/zal_program/Zal/MainForm.cs @@ -20,10 +20,10 @@ public partial class MainForm : Form private const int WM_SYSCOMMAND = 0x0112; private const int SC_MINIMIZE = 0xf020; private Task pipeTask; - List gpuDatas = new List(); - NotifyIcon ni; + private List gpuDatas = new List(); + private NotifyIcon ni; private const string PipeName = "ZalAppPipe"; - bool launchedByStartup; + private bool launchedByStartup; public MainForm(bool launchedByStartup) { diff --git a/zal_program/Zal/Pages/ConfigurationsForm.cs b/zal_program/Zal/Pages/ConfigurationsForm.cs index ada6cf7..467171f 100644 --- a/zal_program/Zal/Pages/ConfigurationsForm.cs +++ b/zal_program/Zal/Pages/ConfigurationsForm.cs @@ -6,8 +6,8 @@ namespace Zal.Pages { public partial class ConfigurationsForm : Form { - Func setupRunOnStartup; - System.Collections.Generic.List gpuData; + private Func setupRunOnStartup; + private System.Collections.Generic.List gpuData; public ConfigurationsForm(Func setupRunOnStartup, System.Collections.Generic.List gpuData) { this.gpuData = gpuData; diff --git a/zal_program/Zal/Program.cs b/zal_program/Zal/Program.cs index cb6d63e..582b100 100644 --- a/zal_program/Zal/Program.cs +++ b/zal_program/Zal/Program.cs @@ -11,11 +11,12 @@ internal static class Program { private static Mutex mutex; private const string PipeName = "ZalAppPipe"; + /// /// The main entry point for the application. /// [STAThread] - static void Main(string[] args) + private static void Main(string[] args) { bool createdNew; mutex = new Mutex(true, "ZalAppMutex", out createdNew); // Unique mutex name From 895bfdd8f605cf5f95a27209b788e7492b64c244 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:36:43 +0100 Subject: [PATCH 02/15] Performance: use TryGetValue --- zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs index 31a88e4..00de324 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs @@ -56,9 +56,9 @@ public static LocalDatabase Instance public object readKey(string key) { - if (data.ContainsKey(key)) + if (data.TryGetValue(key, out var key1)) { - return data[key]; + return key1; } return null; @@ -82,7 +82,6 @@ public async Task writeKey(string key, object text) private static void WriteAsync(string text) { GlobalClass.Instance.saveTextToDocumentFolder("database.json", text); - } } } From 4baeb00f70b501da97df195b921c4c573a60bce0 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:37:30 +0100 Subject: [PATCH 03/15] Use IsNullOrEmpty() --- zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs index 00de324..7b0e85a 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs @@ -20,7 +20,7 @@ private LocalDatabase(Dictionary initData) public static async Task Initialize() { var text = await GlobalClass.Instance.readTextFromDocumentFolder("database.json"); - if (text != null && text != "") + if (!string.IsNullOrEmpty(text)) { try { @@ -30,7 +30,6 @@ public static async Task Initialize() instance = new LocalDatabase(parsedData); return; } - } catch (Exception ex) { From 0863b6f967e4c56bc41cd4784a8bf69db21627b8 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:38:34 +0100 Subject: [PATCH 04/15] Use var, remove unused usings --- .../Backend/Constants/Models/StorageData.cs | 2 +- .../HelperFunctions/ComputerDataGetter.cs | 14 +++---- .../Backend/HelperFunctions/FilesGetter.cs | 18 ++++----- .../Backend/HelperFunctions/FpsDataGetter.cs | 15 ++++---- .../Backend/HelperFunctions/GlobalClass.cs | 24 ++++++------ .../Zal/Backend/HelperFunctions/Logger.cs | 6 +-- .../HelperFunctions/ProcessesGetter.cs | 8 ++-- .../Backend/HelperFunctions/ScreenCapturer.cs | 2 +- .../SpecificFunctions/BatteryDataGetter.cs | 4 +- .../SpecificFunctions/CpuInfoGetter.cs | 2 +- .../CrystalDiskInfoGetter.cs | 38 +++++++++---------- .../SpecificFunctions/DiskInfoGetter.cs | 24 ++++++------ .../SpecificFunctions/FocusedWindowGetter.cs | 4 +- .../SpecificFunctions/GpuUtilizationGetter.cs | 23 ++++++----- .../SpecificFunctions/IpGetter.cs | 4 +- .../SpecificFunctions/MonitorDataGetter.cs | 4 +- .../SpecificFunctions/NetworkSpeedGetter.cs | 14 +++---- .../SpecificFunctions/ProcessPathGetter.cs | 2 +- .../SpecificFunctions/RamPieceDataGetter.cs | 2 +- .../Functions/MajorFunctions/DataManager.cs | 10 ++--- .../Functions/MajorFunctions/LocalSocket.cs | 6 +-- zal_program/Zal/Functions/Utils.cs | 6 +-- zal_program/Zal/MainForm.cs | 26 ++++++------- zal_program/Zal/Pages/ConfigurationsForm.cs | 2 +- zal_program/Zal/Program.cs | 6 +-- 25 files changed, 130 insertions(+), 136 deletions(-) diff --git a/zal_program/Zal/Backend/Constants/Models/StorageData.cs b/zal_program/Zal/Backend/Constants/Models/StorageData.cs index 9020f35..14d1cf1 100644 --- a/zal_program/Zal/Backend/Constants/Models/StorageData.cs +++ b/zal_program/Zal/Backend/Constants/Models/StorageData.cs @@ -25,7 +25,7 @@ public storageData(IHardware hardware, List? crystalDiskDatas) crystalDiskData? crystalDiskData = null; if (crystalDiskDatas != null) { - foreach (crystalDiskData _crystalDiskData in crystalDiskDatas) + foreach (var _crystalDiskData in crystalDiskDatas) { if (_crystalDiskData.info["model"] == hardware.Name) { diff --git a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs index 1c18c12..273d558 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs @@ -84,16 +84,16 @@ public computerDataGetter() } public string getEntireComputerData() { - computerData computerData = new computerData(); + var computerData = new computerData(); computer.Accept(new UpdateVisitor()); - Dictionary result = new Dictionary(); + var result = new Dictionary(); foreach (IHardware hardware in computer.Hardware) { - Dictionary data = new Dictionary(); + var data = new Dictionary(); data["type"] = hardware.HardwareType.ToString(); foreach (var sensor in hardware.Sensors) { - Dictionary sensorData = new Dictionary(); + var sensorData = new Dictionary(); sensorData["type"] = sensor.SensorType.ToString(); sensorData["value"] = sensor.Value.ToString(); data[sensor.Name] = sensorData; @@ -106,7 +106,7 @@ public string getEntireComputerData() } public async Task getcomputerDataAsync() { - computerData computerData = new computerData(); + var computerData = new computerData(); computer.Accept(new UpdateVisitor()); GlobalClass.Instance.processesGetter.update(); computerData.isAdminstrator = IsAdminstratorChecker.IsAdministrator(); @@ -182,7 +182,7 @@ public async Task getcomputerDataAsync() } try { - List? monitorsData = monitorDataGetter.getmonitorData(); + var monitorsData = monitorDataGetter.getmonitorData(); computerData.monitorsData = monitorsData; } catch (Exception ex) @@ -191,7 +191,7 @@ public async Task getcomputerDataAsync() } try { - batteryData? batteryData = batteryDataGetter.getbatteryData(); + var batteryData = batteryDataGetter.getbatteryData(); computerData.batteryData = batteryData; } catch (Exception ex) diff --git a/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs index 4409250..85969be 100644 --- a/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs @@ -178,7 +178,7 @@ public class FilesGetter private List getDirectoryFiles(string path) { var result = new List(); - DirectoryInfo info = new DirectoryInfo(path); + var info = new DirectoryInfo(path); if (info.Exists) { @@ -189,7 +189,7 @@ private List getDirectoryFiles(string path) { continue; } - FileData filed = new FileData(); + var filed = new FileData(); filed.name = file.Name; filed.extension = file.Extension; filed.directory = file.DirectoryName; @@ -206,7 +206,7 @@ private List getDirectoryFiles(string path) private List getDirectoryFolders(string path) { var result = new List(); - DirectoryInfo info = new DirectoryInfo(path); + var info = new DirectoryInfo(path); if (info.Exists) { @@ -217,7 +217,7 @@ private List getDirectoryFolders(string path) { continue; } - FileData folder = new FileData(); + var folder = new FileData(); folder.directory = path; folder.name = directory.Name; folder.fileType = "folder"; @@ -231,17 +231,17 @@ private List getDirectoryFolders(string path) } public static long ConvertToUnixTimestamp(DateTime date) { - DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); - TimeSpan diff = date.ToUniversalTime() - origin; + var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + var diff = date.ToUniversalTime() - origin; return ((long)diff.TotalMilliseconds); } private List getDrives() { - DriveInfo[] drives = DriveInfo.GetDrives(); - List result = new List(); + var drives = DriveInfo.GetDrives(); + var result = new List(); foreach (var drive in drives) { - FileData data = new FileData(); + var data = new FileData(); data.label = drive.VolumeLabel; data.name = drive.Name; data.fileType = "folder"; diff --git a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs index 764db04..27883c2 100644 --- a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Linq; using System.Threading.Tasks; using ZalConsole.HelperFunctions; @@ -36,9 +35,9 @@ public double calculatePercentile(IEnumerable seq, double percentile) { var elements = seq.ToArray(); Array.Sort(elements); - double realIndex = percentile * (elements.Length - 1); - int index = (int)realIndex; - double frac = realIndex - index; + var realIndex = percentile * (elements.Length - 1); + var index = (int)realIndex; + var frac = realIndex - index; if (index + 1 < elements.Length) return elements[index] * (1 - frac) + elements[index + 1] * frac; else @@ -67,7 +66,7 @@ public async void startPresentmon(int processId, bool logFps) //startFpsTimer(); //kill any presentmon process that might be running var filePath = GlobalClass.Instance.getFilepathFromResources("presentmon.exe"); - ProcessStartInfo startInfo = new ProcessStartInfo + var startInfo = new ProcessStartInfo { FileName = filePath, RedirectStandardOutput = true, @@ -98,7 +97,7 @@ private static string getTimestamp() //chosenProcessName is the process that was used during the creation of this void, if the currentProcessName changes, this void will stop itself. private async Task parseIncomingPresentmonData() { - StreamReader reader = presentmonProcess.StandardOutput; + var reader = presentmonProcess.StandardOutput; while (!reader.EndOfStream) { @@ -111,7 +110,7 @@ private async Task parseIncomingPresentmonData() } //Thread.Sleep(30); - string line = reader.ReadLine(); + var line = reader.ReadLine(); if (shouldLog) Logger.Log($"fpsData:{line}"); var msBetweenPresents = ""; try @@ -125,7 +124,7 @@ private async Task parseIncomingPresentmonData() } uint? processId = null; - string? processName = line.Split(',')[0]; + var processName = line.Split(',')[0]; try { processId = uint.Parse(line.Split(',')[1]); diff --git a/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs b/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs index a8a26f9..8fa48c8 100644 --- a/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs +++ b/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs @@ -31,7 +31,7 @@ public bool saveTextToDocumentFolder(string filename, string data) var filePath = Path.Combine(directory, filename); try { - using (StreamWriter writer = new StreamWriter(filePath)) + using (var writer = new StreamWriter(filePath)) { writer.Write(data); } @@ -61,7 +61,7 @@ public bool saveTextToDocumentFolder(string filename, string data) File.Create(filePath).Close(); // Close the file stream immediately after creating it } - using (StreamReader reader = new StreamReader(filePath)) + using (var reader = new StreamReader(filePath)) { var data = await reader.ReadToEndAsync(); return data; @@ -141,7 +141,7 @@ public string getFileIcon(string fileName) { var filePath = extractZipFromResourcesAndGetFilepathWithinTheExtract("get_process_icon.zip", "get_process_icon.exe"); - Process process = new Process(); + var process = new Process(); process.StartInfo.FileName = filePath; process.StartInfo.Arguments = $"\"{fileName}\""; process.StartInfo.UseShellExecute = false; @@ -150,7 +150,7 @@ public string getFileIcon(string fileName) process.StartInfo.CreateNoWindow = true; process.Start(); //* Read the output (or the error) - string output = process.StandardOutput.ReadToEnd(); + var output = process.StandardOutput.ReadToEnd(); process.WaitForExit(); output = output.Replace("\r\n", ""); return output; @@ -160,7 +160,7 @@ public ManagementObjectCollection getWin32DiskDrives() { if (win32DiskDrives == null) { - ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); + var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); win32DiskDrives = searcher.Get(); Task.Run(async () => { @@ -178,13 +178,13 @@ public List getProcessInfos() { if (processInfos == null) { - string jsonFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Processes.json"); + var jsonFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Processes.json"); // Check if the file exists if (File.Exists(jsonFilePath)) { // Read the contents of the JSON file - string jsonContent = File.ReadAllText(jsonFilePath); + var jsonContent = File.ReadAllText(jsonFilePath); processInfos = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonContent); } } @@ -196,7 +196,7 @@ public List getWin32DiskPartitions(int diskNumber) { if (win32DiskPartitions == null) { - ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskPartition"); + var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskPartition"); win32DiskPartitions = searcher.Get(); Task.Run(async () => { @@ -206,11 +206,11 @@ public List getWin32DiskPartitions(int diskNumber) } // Filter the partitions based on the specified disk number - List filteredPartitions = new List(); + var filteredPartitions = new List(); foreach (ManagementObject partition in win32DiskPartitions) { // Adjust the property name based on the actual property for the disk number - int currentDiskNumber = Convert.ToInt32(partition["DiskIndex"]); + var currentDiskNumber = Convert.ToInt32(partition["DiskIndex"]); if (currentDiskNumber == diskNumber) { @@ -225,8 +225,8 @@ public ManagementObjectCollection getWin32DiskPartitionsForFreeDiskSpace() { if (win32DiskPartitionsForFreeDiskSpace == null) { - ManagementScope scope = new ManagementScope(@"\\.\root\cimv2"); - ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); + var scope = new ManagementScope(@"\\.\root\cimv2"); + var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); scope.Connect(); searcher.Scope = scope; win32DiskPartitionsForFreeDiskSpace = searcher.Get(); diff --git a/zal_program/Zal/Backend/HelperFunctions/Logger.cs b/zal_program/Zal/Backend/HelperFunctions/Logger.cs index 4314a12..434fda6 100644 --- a/zal_program/Zal/Backend/HelperFunctions/Logger.cs +++ b/zal_program/Zal/Backend/HelperFunctions/Logger.cs @@ -9,8 +9,8 @@ public static class Logger public static void LogError(string message, Exception ex, object dataToPrint = null) { - string stringifiedData = Newtonsoft.Json.JsonConvert.SerializeObject(dataToPrint); - string text = dataToPrint == null ? "" : stringifiedData; + var stringifiedData = Newtonsoft.Json.JsonConvert.SerializeObject(dataToPrint); + var text = dataToPrint == null ? "" : stringifiedData; Log($"{message},,error:{ex.Message},,stack:{ex.StackTrace},,{text}"); } @@ -51,7 +51,7 @@ private static void WriteToLog(string logMessage, string logFilePath) { lock (_locker) { - string formattedDate = DateTime.Now.ToString("HH:mm:ss"); + var formattedDate = DateTime.Now.ToString("HH:mm:ss"); File.AppendAllText(logFilePath, string.Format("DT: {1}{0}Msg: {2}{0}--------------------{0}", Environment.NewLine, formattedDate, logMessage)); diff --git a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs index ae60548..c7364af 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs @@ -60,13 +60,13 @@ public void resetSentIcons() public async Task update() { - Dictionary result = new Dictionary(); + var result = new Dictionary(); var allProcesses = Process.GetProcesses(); foreach (var process in allProcesses) { - string processName = process.ProcessName; - long ramUsageBytes = process.WorkingSet64; - Dictionary processData = new Dictionary(); + var processName = process.ProcessName; + var ramUsageBytes = process.WorkingSet64; + var processData = new Dictionary(); if (result.ContainsKey(processName)) { processData = (Dictionary)result[processName]; diff --git a/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs b/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs index c1d2d55..b6f6d75 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs @@ -82,7 +82,7 @@ public void Start(int frameRate = 30) var mapDest = bitmap.LockBits(boundsRect, ImageLockMode.WriteOnly, bitmap.PixelFormat); var sourcePtr = mapSource.DataPointer; var destPtr = mapDest.Scan0; - for (int y = 0; y < height; y++) + for (var y = 0; y < height; y++) { // Copy a single line Utilities.CopyMemory(destPtr, sourcePtr, width * 4); diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs index 0785623..1552010 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs @@ -7,9 +7,9 @@ internal class batteryDataGetter { public static batteryData getbatteryData() { - PowerStatus p = SystemInformation.PowerStatus; + var p = SystemInformation.PowerStatus; - int life = (int)(p.BatteryLifePercent * 100); + var life = (int)(p.BatteryLifePercent * 100); var data = new batteryData(); data.hasBattery = p.BatteryChargeStatus != BatteryChargeStatus.NoSystemBattery; diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs index bb34e91..dbc02e2 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs @@ -14,7 +14,7 @@ public static cpuInfo getcpuInfo() .Get() .Cast() .First(); - cpuInfo cpuInfo = new cpuInfo(); + var cpuInfo = new cpuInfo(); cpuInfo.socket = (string)cpu["SocketDesignation"]; cpuInfo.name = (string)cpu["Name"]; cpuInfo.speed = (uint)cpu["MaxClockSpeed"]; diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs index 125c5a8..2999325 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs @@ -22,7 +22,7 @@ internal class CrystaldiskInfoGetter var filePath = GlobalClass.Instance.extractZipFromResourcesAndGetFilepathWithinTheExtract("DiskInfo.zip", "diskInfo.exe"); - ProcessStartInfo startInfo = new ProcessStartInfo + var startInfo = new ProcessStartInfo { FileName = filePath, RedirectStandardOutput = true, @@ -44,7 +44,7 @@ internal class CrystaldiskInfoGetter try { process.WaitForExit(); - string resultPath = Path.Combine(Path.GetDirectoryName(filePath), "diskInfo.txt"); + var resultPath = Path.Combine(Path.GetDirectoryName(filePath), "diskInfo.txt"); var diskInfos = parseCrystaldiskInfoOutput(resultPath); process.Close(); return diskInfos; @@ -59,10 +59,10 @@ internal class CrystaldiskInfoGetter private static List parseCrystaldiskInfoOutput(string filePath) { - List hardwareList = new List(); + var hardwareList = new List(); crystalDiskData currentHardware = null; - foreach (string line in File.ReadLines(filePath)) + foreach (var line in File.ReadLines(filePath)) { if (line.StartsWith(" (0")) { @@ -84,7 +84,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) if (line.Contains("Buffer Size :") && line.Contains("Unknown") == false) { - string hoursString = Regex.Match(line.Split(':')[1].Trim(), @"\d+").Value; + var hoursString = Regex.Match(line.Split(':')[1].Trim(), @"\d+").Value; if (!string.IsNullOrEmpty(hoursString)) { currentHardware.info.Add("bufferSize", int.Parse(hoursString)); @@ -93,7 +93,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) if (line.Contains("Transfer Mode :")) { - string text = line.Split(':')[1]; + var text = line.Split(':')[1]; currentHardware.info.Add("transferMode", text.Split('|')); } @@ -110,7 +110,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) if (line.Contains("Power On Hours :")) { - string hoursString = Regex.Match(line.Split(':')[1].Trim(), @"\d+").Value; + var hoursString = Regex.Match(line.Split(':')[1].Trim(), @"\d+").Value; if (!string.IsNullOrEmpty(hoursString)) { currentHardware.info.Add("powerOnHours", int.Parse(hoursString)); @@ -119,7 +119,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) if (line.Contains("Drive Letter :")) { - List driveLetters = ParseDriveLettersFromString(line); + var driveLetters = ParseDriveLettersFromString(line); if (driveLetters.Count != 0) { currentHardware.info.Add("driveLetters", driveLetters); @@ -128,7 +128,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) if (line.Contains("Power On Count :")) { - string hoursString = Regex.Match(line.Split(':')[1].Trim(), @"\d+").Value; + var hoursString = Regex.Match(line.Split(':')[1].Trim(), @"\d+").Value; if (!string.IsNullOrEmpty(hoursString)) { currentHardware.info.Add("powerOnCount", int.Parse(hoursString)); @@ -137,14 +137,14 @@ private static List parseCrystaldiskInfoOutput(string filePath) if (line.Contains("Health Status :")) { - string hoursString = Regex.Match(line.Split(':')[1].Trim(), @"\d+").Value; + var hoursString = Regex.Match(line.Split(':')[1].Trim(), @"\d+").Value; if (!string.IsNullOrEmpty(hoursString)) { currentHardware.info.Add("healthPercentage", int.Parse(hoursString)); } - Regex regex = new Regex("[a-zA-Z]+"); - Match match = regex.Match(line.Split(':')[1].Trim()); + var regex = new Regex("[a-zA-Z]+"); + var match = regex.Match(line.Split(':')[1].Trim()); if (match.Success) { currentHardware.info.Add("healthText", match.Value); @@ -174,7 +174,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) } else if (currentHardware.smartAttributes != null && currentHardware.isNvme == false) { - string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + var parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var attributeName = string.Join(" ", parts, 5, parts.Length - 5); if (attributeName.Contains("Temperature")) { @@ -191,7 +191,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) Console.WriteLine(c.Message); } - smartAttribute smartAttribute = new smartAttribute + var smartAttribute = new smartAttribute { id = parts[0], currentValue = int.Parse(parts[1].Replace("_", "")), @@ -204,7 +204,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) } else if (currentHardware.smartAttributes != null && currentHardware.isNvme == true) { - string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + var parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var attributeName = string.Join(" ", parts, 2, parts.Length - 2); if (attributeName.Contains("Temperature")) { @@ -221,7 +221,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) Console.WriteLine(c.Message); } - smartAttribute smartAttribute = new smartAttribute + var smartAttribute = new smartAttribute { id = parts[0], rawValue = rawValue, @@ -246,11 +246,11 @@ private static List parseCrystaldiskInfoOutput(string filePath) private static List ParseDriveLettersFromString(string input) { - List driveLetters = new List(); + var driveLetters = new List(); // Use a regular expression to match drive letters - Regex regex = new Regex(@"[A-Za-z]:"); - MatchCollection matches = regex.Matches(input); + var regex = new Regex(@"[A-Za-z]:"); + var matches = regex.Matches(input); foreach (Match match in matches) { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs index 4153bbe..9f6515b 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs @@ -14,16 +14,16 @@ public static diskInfo GetdiskInfo(int diskNumber,crystalDiskData? crystalDiskDa foreach (ManagementObject disk in GlobalClass.Instance.getWin32DiskDrives()) { //iterate until we get the disk number we want - int diskIndex = Convert.ToInt32(disk["Index"]); + var diskIndex = Convert.ToInt32(disk["Index"]); if (diskIndex != diskNumber) continue; - diskInfo diskInfo = new diskInfo(); + var diskInfo = new diskInfo(); diskInfo.diskNumber = Convert.ToInt32(disk["Index"]); diskInfo.totalSize = Convert.ToInt64(disk["Size"]); - foreach (ManagementObject partition in GlobalClass.Instance.getWin32DiskPartitions(diskNumber)) + foreach (var partition in GlobalClass.Instance.getWin32DiskPartitions(diskNumber)) { - partitionInfo partitionInfo = new partitionInfo(); + var partitionInfo = new partitionInfo(); if (crystalDiskData != null) { @@ -54,7 +54,7 @@ public static diskInfo GetdiskInfo(int diskNumber,crystalDiskData? crystalDiskDa //this is a fallback function in case crystalDiskData is not available private static string GetDriveLetter(ManagementObject partition) { - using (ManagementObjectSearcher searcher = new ManagementObjectSearcher($"ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{partition["DeviceID"]}'}} WHERE AssocClass=Win32_LogicalDiskToPartition")) + using (var searcher = new ManagementObjectSearcher($"ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{partition["DeviceID"]}'}} WHERE AssocClass=Win32_LogicalDiskToPartition")) { foreach (ManagementObject logicalDisk in searcher.Get()) { @@ -67,12 +67,12 @@ private static string GetDriveLetter(ManagementObject partition) private static DriveInfo? GetDriveByLetter(string driveName) { - foreach (DriveInfo drive in DriveInfo.GetDrives()) + foreach (var drive in DriveInfo.GetDrives()) { - string pattern = "[^a-zA-Z]"; - string replacement = ""; - Regex regex = new Regex(pattern); - string driveLetter = regex.Replace(drive.Name, replacement); + var pattern = "[^a-zA-Z]"; + var replacement = ""; + var regex = new Regex(pattern); + var driveLetter = regex.Replace(drive.Name, replacement); if (driveLetter == driveName) { return drive; @@ -90,13 +90,13 @@ private static ulong GetFreeSpaceForDisk(int diskNumber) var index = Convert.ToInt32(disk["Index"]); if (index == diskNumber) { - ManagementObjectSearcher partitionSearcher = new ManagementObjectSearcher($"ASSOCIATORS OF {{Win32_DiskDrive.DeviceID='{disk["DeviceID"]}'}} WHERE AssocClass=Win32_DiskDriveToDiskPartition"); + var partitionSearcher = new ManagementObjectSearcher($"ASSOCIATORS OF {{Win32_DiskDrive.DeviceID='{disk["DeviceID"]}'}} WHERE AssocClass=Win32_DiskDriveToDiskPartition"); ulong totalFreeSpace = 0; foreach (ManagementObject partition in partitionSearcher.Get()) { - ManagementObjectSearcher logicalDiskSearcher = new ManagementObjectSearcher($"ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{partition["DeviceID"]}'}} WHERE AssocClass=Win32_LogicalDiskToPartition"); + var logicalDiskSearcher = new ManagementObjectSearcher($"ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{partition["DeviceID"]}'}} WHERE AssocClass=Win32_LogicalDiskToPartition"); foreach (ManagementObject logicalDisk in logicalDiskSearcher.Get()) { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/FocusedWindowGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/FocusedWindowGetter.cs index 23e4555..e349b95 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/FocusedWindowGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/FocusedWindowGetter.cs @@ -16,7 +16,7 @@ public class FocusedWindowGetter public IList? getFocusedWindowProcessId() { - IntPtr hwnd = GetForegroundWindow(); + var hwnd = GetForegroundWindow(); // The foreground window can be NULL in certain circumstances, // such as when a window is losing activation. @@ -42,7 +42,7 @@ public static IList GetChildProcesses(this Process process) Process.GetProcessById(Convert.ToInt32(mo["ProcessID"]))) .ToList(); processes.Add(process); - Process[] processesByName = Process.GetProcessesByName(process.ProcessName); + var processesByName = Process.GetProcessesByName(process.ProcessName); foreach (var processByName in processesByName) { processes.Add(processByName); diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs index 4411f16..158f687 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Management.Automation; @@ -16,14 +15,14 @@ internal class GpuUtilizationGetter //and some modifications to make the data to be parsed easier from c# side. public static Dictionary> getProcessesGpuUsage(bool skipBlackListedProcesses = true) { - Dictionary> result = new Dictionary>(); + var result = new Dictionary>(); var rawData = getRawDataFromPowershell(); var processInfos = GlobalClass.Instance.getProcessInfos(); foreach (var process in rawData) { - Dictionary data = new Dictionary(); + var data = new Dictionary(); var splittedData = process.Split(','); - int pid = int.Parse(splittedData[0].Split('_')[1]); + var pid = int.Parse(splittedData[0].Split('_')[1]); double usage = 1; try @@ -90,18 +89,18 @@ public static Dictionary> getProcessesGpuUsa private static List getRawDataFromPowershell() { - List result = new List(); - using (PowerShell PowerShellInstance = PowerShell.Create()) + var result = new List(); + using (var PowerShellInstance = PowerShell.Create()) { // Add the PowerShell script - string script = "$counter = Get-Counter '\\GPU Engine(*engtype_3D)\\Utilization Percentage';" + - "foreach ($sample in $counter.CounterSamples) {" + - "$sample.InstanceName + ',' + $sample.CookedValue" + - "}"; + var script = "$counter = Get-Counter '\\GPU Engine(*engtype_3D)\\Utilization Percentage';" + + "foreach ($sample in $counter.CounterSamples) {" + + "$sample.InstanceName + ',' + $sample.CookedValue" + + "}"; PowerShellInstance.AddScript(script); // Invoke execution on the PowerShell object - Collection PSOutput = PowerShellInstance.Invoke(); + var PSOutput = PowerShellInstance.Invoke(); // Check for errors if (PowerShellInstance.Streams.Error.Count > 0) @@ -112,7 +111,7 @@ private static List getRawDataFromPowershell() else { // Output the results - foreach (PSObject outputItem in PSOutput) + foreach (var outputItem in PSOutput) { result.Add(outputItem.ToString()); } diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IpGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IpGetter.cs index 1e90c9f..402a87f 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IpGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/IpGetter.cs @@ -7,10 +7,10 @@ internal class IpGetter { public static string getIp() { - using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0)) + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0)) { socket.Connect("8.8.8.8", 65530); - IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint; + var endPoint = socket.LocalEndPoint as IPEndPoint; var ip = endPoint.Address.ToString(); Logger.Log($"ip found: {ip.ToString()}"); return ip.ToString(); diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs index 650520e..337d02d 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs @@ -9,8 +9,8 @@ internal class monitorDataGetter public static List? getmonitorData() { var result = new List(); - Screen[] screens = Screen.AllScreens; - foreach (Screen screen in screens) + var screens = Screen.AllScreens; + foreach (var screen in screens) { var data = new monitorData(); data.name = screen.DeviceName; diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs index 798afa0..4188665 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs @@ -18,7 +18,7 @@ internal class NetworkSpeedGetter public NetworkSpeedGetter() { - networkSpeed s = new networkSpeed(0, 0); + var s = new networkSpeed(0, 0); primaryNetworkSpeed = s; //run code that gets networkInterfaces every 5 seconds @@ -34,7 +34,7 @@ public NetworkSpeedGetter() { while (true) { - string? primaryNetwork = (string?)LocalDatabase.Instance.readKey("primaryNetwork"); + var primaryNetwork = (string?)LocalDatabase.Instance.readKey("primaryNetwork"); getPrimaryNetworkSpeedAsync(primaryNetwork); } }); @@ -93,7 +93,7 @@ private async Task getPrimaryNetworkSpeedAsync(string? primaryNetwork) // ~1 second var brSec = readsBr.Sum() / readsBs.Count(); var bsSec = readsBs.Sum() / readsBs.Count(); - networkSpeed s = new networkSpeed((int)brSec, (int)bsSec); + var s = new networkSpeed((int)brSec, (int)bsSec); primaryNetworkSpeed = s; } } @@ -105,14 +105,14 @@ private async Task> getNetworkInterfacesAsync() if (!NetworkInterface.GetIsNetworkAvailable()) return new List(); - NetworkInterface[] interfaces + var interfaces = NetworkInterface.GetAllNetworkInterfaces(); - List data = new List(); + var data = new List(); - foreach (NetworkInterface ni in interfaces) + foreach (var ni in interfaces) { var stats = ni.GetIPv4Statistics(); - networkInterfaceData info = new networkInterfaceData(); + var info = new networkInterfaceData(); info.name = ni.Name; info.description = ni.Description; info.status = ni.OperationalStatus.ToString(); diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/ProcessPathGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/ProcessPathGetter.cs index eb2b9e1..f5ab394 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/ProcessPathGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/ProcessPathGetter.cs @@ -10,7 +10,7 @@ public static void save(string name, string processPath) { var directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Zal", "programs_path"); var folderPath = Directory.CreateDirectory(directory).FullName; - using (StreamWriter w = File.CreateText(Path.Combine(folderPath, name))) + using (var w = File.CreateText(Path.Combine(folderPath, name))) { w.Write(processPath); } diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs index 91534d6..9a43b62 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs @@ -9,7 +9,7 @@ internal class ramPieceDataGetter public static List GetRamPiecesData() { var data = new List(); - ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory"); + var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory"); foreach (ManagementObject obj in searcher.Get()) { var ramData = new ramPieceData(); diff --git a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs index c86cdd7..e391e9c 100644 --- a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs +++ b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs @@ -93,17 +93,17 @@ private async Task sendDataToMobile() private static string CompressGzip(string text) { - byte[] enCodedJson = Encoding.UTF8.GetBytes(text); + var enCodedJson = Encoding.UTF8.GetBytes(text); - using (MemoryStream memoryStream = new MemoryStream()) + using (var memoryStream = new MemoryStream()) { - using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress)) + using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress)) { gzipStream.Write(enCodedJson, 0, enCodedJson.Length); } - byte[] gZipJson = memoryStream.ToArray(); - string base64Json = Convert.ToBase64String(gZipJson); + var gZipJson = memoryStream.ToArray(); + var base64Json = Convert.ToBase64String(gZipJson); return base64Json; } } diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs index ee1adee..0a709c1 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs @@ -56,7 +56,7 @@ private async Task setupSocketio() } pcName = string.Concat(pcName.Where(char.IsLetterOrDigit)); var filePath = GlobalClass.Instance.getFilepathFromResources("server.exe"); - ProcessStartInfo startInfo = new ProcessStartInfo + var startInfo = new ProcessStartInfo { FileName = filePath, RedirectStandardOutput = true, @@ -128,7 +128,7 @@ private async Task setupSocketio() socketio.On("start_fps", response => { - int data = int.Parse(response.GetValue()); + var data = int.Parse(response.GetValue()); FrontendGlobalClass.Instance.backend?.startFps(data, FrontendGlobalClass.Instance.shouldLogFpsData); FrontendGlobalClass.Instance.backend.fpsDataReceived += (sender, e) => { @@ -144,7 +144,7 @@ private async Task setupSocketio() socketio.On("restart_admin", response => { - string selfPath = Process.GetCurrentProcess().MainModule.FileName; + var selfPath = Process.GetCurrentProcess().MainModule.FileName; var proc = new Process { StartInfo = diff --git a/zal_program/Zal/Functions/Utils.cs b/zal_program/Zal/Functions/Utils.cs index 5601cc2..18f7409 100644 --- a/zal_program/Zal/Functions/Utils.cs +++ b/zal_program/Zal/Functions/Utils.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Zal.Functions { diff --git a/zal_program/Zal/MainForm.cs b/zal_program/Zal/MainForm.cs index 40c0999..4545d5b 100644 --- a/zal_program/Zal/MainForm.cs +++ b/zal_program/Zal/MainForm.cs @@ -40,14 +40,14 @@ private Task StartPipeServer() { while (true) { - using (NamedPipeServerStream pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.In)) + using (var pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.In)) { try { pipeServer.WaitForConnection(); // Wait for a client to connect - using (StreamReader reader = new StreamReader(pipeServer)) + using (var reader = new StreamReader(pipeServer)) { - string command = reader.ReadLine(); + var command = reader.ReadLine(); if (command == "SHOW") { Invoke(new Action(() => @@ -123,34 +123,34 @@ await FrontendGlobalClass.Initialize(socketConnectionStateChanged: (sender, stat private void connectionSettingsToolStripMenuItem_Click(object sender, EventArgs e) { - ConnectionSettingsForm form2 = new ConnectionSettingsForm(); + var form2 = new ConnectionSettingsForm(); form2.Show(); } private void configurationsToolStripMenuItem_Click(object sender, EventArgs e) { - ConfigurationsForm form2 = new ConfigurationsForm(setupRunOnStartup, gpuDatas); + var form2 = new ConfigurationsForm(setupRunOnStartup, gpuDatas); form2.Show(); } private async Task checkForUpdates() { - string latestVersion = new WebClient().DownloadString("https://zalapp.com/program-version"); + var latestVersion = new WebClient().DownloadString("https://zalapp.com/program-version"); var currentVersion = System.Windows.Forms.Application.ProductVersion; if (latestVersion != currentVersion) { var dialog = System.Windows.Forms.MessageBox.Show($"New update is available! do you want to update?\ncurrent version: {currentVersion}\nlatest version:{latestVersion}", "Zal", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { - using (WebClient webClient = new WebClient()) + using (var webClient = new WebClient()) { try { - string fileName = Path.Combine(Path.GetTempPath(), "zal.msi"); + var fileName = Path.Combine(Path.GetTempPath(), "zal.msi"); webClient.DownloadFile("https://zalapp.com/zal.msi", fileName); Console.WriteLine("File downloaded successfully."); - Process p = new Process(); - ProcessStartInfo pi = new ProcessStartInfo(); + var p = new Process(); + var pi = new ProcessStartInfo(); pi.UseShellExecute = true; pi.FileName = fileName; p.StartInfo = pi; @@ -168,9 +168,9 @@ private async Task setupRunOnStartup() { var runOnStartup = (string?)LocalDatabase.Instance.readKey("runOnStartup") == "1"; //replace false with saved settings - RegistryKey rk = Registry.CurrentUser.OpenSubKey + var rk = Registry.CurrentUser.OpenSubKey ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); - string executablePath = $"\"{Process.GetCurrentProcess().MainModule.FileName}\" --startup"; + var executablePath = $"\"{Process.GetCurrentProcess().MainModule.FileName}\" --startup"; if (runOnStartup) rk.SetValue("Zal", executablePath); else @@ -210,7 +210,7 @@ private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWor private void timer1_Tick(object sender, EventArgs e) { - Process[] pname = Process.GetProcessesByName("server"); + var pname = Process.GetProcessesByName("server"); serverConnectionText.Text = pname.Length != 0 ? "Server running" : "Server not running"; serverConnectionText.ForeColor = (pname.Length == 0) ? Color.FromKnownColor(KnownColor.IndianRed) : Color.FromKnownColor(KnownColor.ForestGreen); diff --git a/zal_program/Zal/Pages/ConfigurationsForm.cs b/zal_program/Zal/Pages/ConfigurationsForm.cs index 467171f..e043c3f 100644 --- a/zal_program/Zal/Pages/ConfigurationsForm.cs +++ b/zal_program/Zal/Pages/ConfigurationsForm.cs @@ -46,7 +46,7 @@ private void ConfigurationsForm_Load(object sender, EventArgs e) else { //check if the primary gpu exists inside this data, this is a useful check in case of the user changed their gpu - bool doesPrimaryGpuExist = false; + var doesPrimaryGpuExist = false; foreach (var gpu in gpuData) { if (gpu.name == primaryGpu.ToString()) diff --git a/zal_program/Zal/Program.cs b/zal_program/Zal/Program.cs index 582b100..4582109 100644 --- a/zal_program/Zal/Program.cs +++ b/zal_program/Zal/Program.cs @@ -27,7 +27,7 @@ private static void Main(string[] args) SendShowSignal(); return; // Exit the new instance } - bool launchedByStartup = args.Contains("--startup"); + var launchedByStartup = args.Contains("--startup"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(launchedByStartup)); @@ -36,10 +36,10 @@ private static void SendShowSignal() { try { - using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", PipeName, PipeDirection.Out)) + using (var pipeClient = new NamedPipeClientStream(".", PipeName, PipeDirection.Out)) { pipeClient.Connect(1000); // Attempt to connect to the server - using (StreamWriter writer = new StreamWriter(pipeClient)) + using (var writer = new StreamWriter(pipeClient)) { writer.WriteLine("SHOW"); } From d075ce042dec490b1c3150801aedacf751045b92 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:42:30 +0100 Subject: [PATCH 05/15] Use object initializers --- .../HelperFunctions/ComputerDataGetter.cs | 14 ++--- .../Backend/HelperFunctions/FilesGetter.cs | 54 ++++++++++--------- .../SpecificFunctions/BatteryDataGetter.cs | 11 ++-- .../SpecificFunctions/CpuInfoGetter.cs | 19 +++---- .../CrystalDiskInfoGetter.cs | 6 ++- .../SpecificFunctions/DiskInfoGetter.cs | 7 +-- .../SpecificFunctions/MonitorDataGetter.cs | 13 ++--- .../SpecificFunctions/NetworkSpeedGetter.cs | 17 +++--- .../SpecificFunctions/RamPieceDataGetter.cs | 11 ++-- zal_program/Zal/MainForm.cs | 8 +-- 10 files changed, 87 insertions(+), 73 deletions(-) diff --git a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs index 273d558..6917516 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs @@ -12,7 +12,6 @@ namespace Zal.HelperFunctions { public class computerDataGetter { - private readonly cpuInfo? cpuInfo; private readonly List? crystalDiskDatas; private readonly List? ramPiecesData; @@ -89,13 +88,16 @@ public string getEntireComputerData() var result = new Dictionary(); foreach (IHardware hardware in computer.Hardware) { - var data = new Dictionary(); - data["type"] = hardware.HardwareType.ToString(); + var data = new Dictionary + { + ["type"] = hardware.HardwareType.ToString() + }; foreach (var sensor in hardware.Sensors) { - var sensorData = new Dictionary(); - sensorData["type"] = sensor.SensorType.ToString(); - sensorData["value"] = sensor.Value.ToString(); + var sensorData = new Dictionary { + ["type"] = sensor.SensorType.ToString(), + ["value"] = sensor.Value.ToString(), + }; data[sensor.Name] = sensorData; } diff --git a/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs index 85969be..71fc30f 100644 --- a/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/FilesGetter.cs @@ -36,7 +36,7 @@ public class FilesGetter // catch(UnauthorizedAccessException) { // await client.EmitAsync("information_text", "Access to path is denied."); // return; - // } + // } // var files = getDirectoryFiles(path); // Dictionary data = new Dictionary(); // var allFiles = folders.Concat(files).ToList(); @@ -70,7 +70,7 @@ public class FilesGetter // byteOffset += bytesRead; // // Simulate some delay to avoid overwhelming the network // await Task.Delay(150); - // + // // } // // } @@ -92,7 +92,7 @@ public class FilesGetter // string base64Chunk = Convert.ToBase64String(buffer, 0, bytesRead); // sendData("file", new { ByteOffset = chunk, ChunkData = base64Chunk }); // await Task.Delay(150); - // + // // } // } // await Task.Delay(150); @@ -156,7 +156,7 @@ public class FilesGetter // { // await client.EmitAsync("information_text", $"error performing action: {ex.Message}"); // } - // + // // }); // } //void ProcessChunk(byte[] chunk, int bytesRead) @@ -181,7 +181,6 @@ private List getDirectoryFiles(string path) var info = new DirectoryInfo(path); if (info.Exists) { - var files = info.GetFiles(); foreach (var file in files) { @@ -189,27 +188,28 @@ private List getDirectoryFiles(string path) { continue; } - var filed = new FileData(); - filed.name = file.Name; - filed.extension = file.Extension; - filed.directory = file.DirectoryName; - filed.fileType = "file"; - filed.size = file.Length; - filed.dateModified = ConvertToUnixTimestamp(file.LastWriteTime); - filed.dateCreated = ConvertToUnixTimestamp(file.CreationTime); + var filed = new FileData { + name = file.Name, + extension = file.Extension, + directory = file.DirectoryName, + fileType = "file", + size = file.Length, + dateModified = ConvertToUnixTimestamp(file.LastWriteTime), + dateCreated = ConvertToUnixTimestamp(file.CreationTime), + }; result.Add(filed); } } return result; } + private List getDirectoryFolders(string path) { var result = new List(); var info = new DirectoryInfo(path); if (info.Exists) { - var directories = info.GetDirectories(); foreach (var directory in directories) { @@ -217,35 +217,39 @@ private List getDirectoryFolders(string path) { continue; } - var folder = new FileData(); - folder.directory = path; - folder.name = directory.Name; - folder.fileType = "folder"; - folder.dateCreated = ConvertToUnixTimestamp(directory.CreationTime); - folder.dateModified = ConvertToUnixTimestamp(directory.LastWriteTime); + var folder = new FileData { + directory = path, + name = directory.Name, + fileType = "folder", + dateCreated = ConvertToUnixTimestamp(directory.CreationTime), + dateModified = ConvertToUnixTimestamp(directory.LastWriteTime), + }; result.Add(folder); } } return result; } + public static long ConvertToUnixTimestamp(DateTime date) { var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); var diff = date.ToUniversalTime() - origin; return ((long)diff.TotalMilliseconds); } + private List getDrives() { var drives = DriveInfo.GetDrives(); var result = new List(); foreach (var drive in drives) { - var data = new FileData(); - data.label = drive.VolumeLabel; - data.name = drive.Name; - data.fileType = "folder"; - data.size = drive.TotalSize - drive.AvailableFreeSpace; + var data = new FileData { + label = drive.VolumeLabel, + name = drive.Name, + fileType = "folder", + size = drive.TotalSize - drive.AvailableFreeSpace, + }; result.Add(data); } diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs index 1552010..a44f927 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/BatteryDataGetter.cs @@ -11,11 +11,12 @@ public static batteryData getbatteryData() var life = (int)(p.BatteryLifePercent * 100); - var data = new batteryData(); - data.hasBattery = p.BatteryChargeStatus != BatteryChargeStatus.NoSystemBattery; - data.life = (uint)life; - data.isCharging = p.PowerLineStatus == PowerLineStatus.Online; - data.lifeRemaining = (uint)p.BatteryLifeRemaining; + var data = new batteryData { + hasBattery = p.BatteryChargeStatus != BatteryChargeStatus.NoSystemBattery, + life = (uint)life, + isCharging = p.PowerLineStatus == PowerLineStatus.Online, + lifeRemaining = (uint)p.BatteryLifeRemaining, + }; return data; } diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs index dbc02e2..dac2291 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CpuInfoGetter.cs @@ -14,15 +14,16 @@ public static cpuInfo getcpuInfo() .Get() .Cast() .First(); - var cpuInfo = new cpuInfo(); - cpuInfo.socket = (string)cpu["SocketDesignation"]; - cpuInfo.name = (string)cpu["Name"]; - cpuInfo.speed = (uint)cpu["MaxClockSpeed"]; - cpuInfo.busSpeed = (uint)cpu["ExtClock"]; - cpuInfo.l2Cache = (uint)cpu["L2CacheSize"] * (ulong)1024; - cpuInfo.l3Cache = (uint)cpu["L3CacheSize"] * (ulong)1024; - cpuInfo.cores = (uint)cpu["NumberOfCores"]; - cpuInfo.threads = (uint)cpu["NumberOfLogicalProcessors"]; + var cpuInfo = new cpuInfo { + socket = (string)cpu["SocketDesignation"], + name = (string)cpu["Name"], + speed = (uint)cpu["MaxClockSpeed"], + busSpeed = (uint)cpu["ExtClock"], + l2Cache = (uint)cpu["L2CacheSize"] * (ulong)1024, + l3Cache = (uint)cpu["L3CacheSize"] * (ulong)1024, + cores = (uint)cpu["NumberOfCores"], + threads = (uint)cpu["NumberOfLogicalProcessors"], + }; cpuInfo.name = cpuInfo.name diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs index 2999325..b0d0fc5 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs @@ -72,8 +72,10 @@ private static List parseCrystaldiskInfoOutput(string filePath) hardwareList.Add(currentHardware); } - currentHardware = new crystalDiskData(); - currentHardware.info = new Dictionary(); + currentHardware = new crystalDiskData + { + info = new Dictionary() + }; } else if (currentHardware != null) { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs index 9f6515b..8906712 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs @@ -17,9 +17,10 @@ public static diskInfo GetdiskInfo(int diskNumber,crystalDiskData? crystalDiskDa var diskIndex = Convert.ToInt32(disk["Index"]); if (diskIndex != diskNumber) continue; - var diskInfo = new diskInfo(); - diskInfo.diskNumber = Convert.ToInt32(disk["Index"]); - diskInfo.totalSize = Convert.ToInt64(disk["Size"]); + var diskInfo = new diskInfo { + diskNumber = Convert.ToInt32(disk["Index"]), + totalSize = Convert.ToInt64(disk["Size"]), + }; foreach (var partition in GlobalClass.Instance.getWin32DiskPartitions(diskNumber)) { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs index 337d02d..b4a5c91 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/MonitorDataGetter.cs @@ -12,12 +12,13 @@ internal class monitorDataGetter var screens = Screen.AllScreens; foreach (var screen in screens) { - var data = new monitorData(); - data.name = screen.DeviceName; - data.height = (uint)screen.Bounds.Height; - data.width = (uint)screen.Bounds.Width; - data.isPrimary = screen.Primary; - data.bitsPerPixel = (uint)screen.BitsPerPixel; + var data = new monitorData { + name = screen.DeviceName, + height = (uint)screen.Bounds.Height, + width = (uint)screen.Bounds.Width, + isPrimary = screen.Primary, + bitsPerPixel = (uint)screen.BitsPerPixel, + }; result.Add(data); } return result; diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs index 4188665..a6e9850 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs @@ -112,14 +112,15 @@ var interfaces foreach (var ni in interfaces) { var stats = ni.GetIPv4Statistics(); - var info = new networkInterfaceData(); - info.name = ni.Name; - info.description = ni.Description; - info.status = ni.OperationalStatus.ToString(); - info.id = ni.Id; - info.bytesReceived = stats.BytesReceived; - info.bytesSent = stats.BytesSent; - info.isPrimary = primaryNetwork == ni.Name; + var info = new networkInterfaceData { + name = ni.Name, + description = ni.Description, + status = ni.OperationalStatus.ToString(), + id = ni.Id, + bytesReceived = stats.BytesReceived, + bytesSent = stats.BytesSent, + isPrimary = primaryNetwork == ni.Name, + }; data.Add(info); } diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs index 9a43b62..aac956b 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/RamPieceDataGetter.cs @@ -12,11 +12,12 @@ public static List GetRamPiecesData() var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory"); foreach (ManagementObject obj in searcher.Get()) { - var ramData = new ramPieceData(); - ramData.capacity = (ulong)obj["Capacity"]; - ramData.manufacturer = (string)obj["Manufacturer"]; - ramData.partNumber = (string)obj["PartNumber"]; - ramData.speed = (uint)obj["Speed"]; + var ramData = new ramPieceData { + capacity = (ulong)obj["Capacity"], + manufacturer = (string)obj["Manufacturer"], + partNumber = (string)obj["PartNumber"], + speed = (uint)obj["Speed"], + }; data.Add(ramData); } return data; diff --git a/zal_program/Zal/MainForm.cs b/zal_program/Zal/MainForm.cs index 4545d5b..0cac20d 100644 --- a/zal_program/Zal/MainForm.cs +++ b/zal_program/Zal/MainForm.cs @@ -31,7 +31,6 @@ public MainForm(bool launchedByStartup) InitializeComponent(); Logger.ResetLog(); pipeTask = StartPipeServer(); - } private Task StartPipeServer() @@ -150,9 +149,10 @@ private async Task checkForUpdates() Console.WriteLine("File downloaded successfully."); var p = new Process(); - var pi = new ProcessStartInfo(); - pi.UseShellExecute = true; - pi.FileName = fileName; + var pi = new ProcessStartInfo { + UseShellExecute = true, + FileName = fileName, + }; p.StartInfo = pi; p.Start(); } From 4fe9f781086648be44c118d0a23f3fc1f1500f62 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:43:24 +0100 Subject: [PATCH 06/15] Use var part 2 --- zal_program/Zal/Backend/Constants/Models/CpuData.cs | 2 +- zal_program/Zal/Backend/Constants/Models/GpuData.cs | 2 +- .../Zal/Backend/Constants/Models/MotherboardData.cs | 2 +- zal_program/Zal/Backend/Constants/Models/RamData.cs | 2 +- .../Zal/Backend/Constants/Models/StorageData.cs | 2 +- .../Backend/HelperFunctions/ComputerDataGetter.cs | 6 +++--- .../Zal/Backend/HelperFunctions/ScreenCapturer.cs | 4 ++-- .../Zal/Functions/MajorFunctions/LocalSocket.cs | 12 ++++++------ 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/zal_program/Zal/Backend/Constants/Models/CpuData.cs b/zal_program/Zal/Backend/Constants/Models/CpuData.cs index 6af226d..845c666 100644 --- a/zal_program/Zal/Backend/Constants/Models/CpuData.cs +++ b/zal_program/Zal/Backend/Constants/Models/CpuData.cs @@ -21,7 +21,7 @@ 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) { diff --git a/zal_program/Zal/Backend/Constants/Models/GpuData.cs b/zal_program/Zal/Backend/Constants/Models/GpuData.cs index cab508f..cf778f8 100644 --- a/zal_program/Zal/Backend/Constants/Models/GpuData.cs +++ b/zal_program/Zal/Backend/Constants/Models/GpuData.cs @@ -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") { diff --git a/zal_program/Zal/Backend/Constants/Models/MotherboardData.cs b/zal_program/Zal/Backend/Constants/Models/MotherboardData.cs index e28ef77..497af8d 100644 --- a/zal_program/Zal/Backend/Constants/Models/MotherboardData.cs +++ b/zal_program/Zal/Backend/Constants/Models/MotherboardData.cs @@ -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) { diff --git a/zal_program/Zal/Backend/Constants/Models/RamData.cs b/zal_program/Zal/Backend/Constants/Models/RamData.cs index 50c1b6f..4ecf6f2 100644 --- a/zal_program/Zal/Backend/Constants/Models/RamData.cs +++ b/zal_program/Zal/Backend/Constants/Models/RamData.cs @@ -13,7 +13,7 @@ public class ramData public ramData(IHardware hardware, List? 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") { diff --git a/zal_program/Zal/Backend/Constants/Models/StorageData.cs b/zal_program/Zal/Backend/Constants/Models/StorageData.cs index 14d1cf1..8755f84 100644 --- a/zal_program/Zal/Backend/Constants/Models/StorageData.cs +++ b/zal_program/Zal/Backend/Constants/Models/StorageData.cs @@ -50,7 +50,7 @@ public storageData(IHardware hardware, List? crystalDiskDatas) } } - foreach (ISensor sensor in hardware.Sensors) + foreach (var sensor in hardware.Sensors) { if (sensor.SensorType == SensorType.Temperature) { diff --git a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs index 6917516..69b8bcb 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs @@ -86,7 +86,7 @@ public string getEntireComputerData() var computerData = new computerData(); computer.Accept(new UpdateVisitor()); var result = new Dictionary(); - foreach (IHardware hardware in computer.Hardware) + foreach (var hardware in computer.Hardware) { var data = new Dictionary { @@ -117,7 +117,7 @@ public async Task 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 }; @@ -252,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) diff --git a/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs b/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs index b6f6d75..f0fb326 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs @@ -34,8 +34,8 @@ public void Start(int frameRate = 30) var output1 = output.QueryInterface(); // Width/Height of desktop to capture - int width = output.Description.DesktopBounds.Right; - int height = output.Description.DesktopBounds.Bottom; + var width = output.Description.DesktopBounds.Right; + var height = output.Description.DesktopBounds.Bottom; // Create Staging texture CPU-accessible diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs index 0a709c1..03e2d61 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs @@ -95,7 +95,7 @@ private async Task setupSocketio() socketio.On("room_clients", response => { - int parsedData = response.GetValue(); + var parsedData = response.GetValue(); Logger.Log($"local socketio room_clients {parsedData}"); // if the data is 1, that means w'ere the only one connected to this server. if it's more than 1, it means a mobile is connected to the server. isMobileConnected = parsedData > 1; @@ -106,7 +106,7 @@ private async Task setupSocketio() { - int parsedData = response.GetValue(); + var parsedData = response.GetValue(); Logger.Log($"local socketio room_clients {parsedData}"); // if the data is 1, that means w'ere the only one connected to this server. if it's more than 1, it means a mobile is connected to the server. isMobileConnected = parsedData > 1; @@ -167,13 +167,13 @@ private async Task setupSocketio() socketio.On("change_primary_network", async response => { - string parsedData = response.GetValue(); + var parsedData = response.GetValue(); await LocalDatabase.Instance.writeKey("primaryNetwork", parsedData); }); socketio.On("launch_app", response => { - string parsedData = response.GetValue(); + var parsedData = response.GetValue(); var processpath = ProcesspathGetter.load(parsedData); if (processpath != null) { @@ -188,7 +188,7 @@ private async Task setupSocketio() socketio.On("get_process_icon", async response => { - string parsedData = response.GetValue(); + var parsedData = response.GetValue(); var processpath = ProcesspathGetter.load(parsedData); if (processpath != null) { @@ -199,7 +199,7 @@ private async Task setupSocketio() socketio.On("kill_process", response => { - string parsedData = response.GetValue(); + var parsedData = response.GetValue(); var pids = JsonConvert.DeserializeObject>(parsedData); foreach (var pid in pids) { From 8fd42601b8a7f71b481ece2d14e9487424c38121 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:44:34 +0100 Subject: [PATCH 07/15] Remove redundant initializers and redundant else blocks --- zal_program/Zal/Backend.cs | 2 +- .../Zal/Backend/HelperFunctions/FpsDataGetter.cs | 13 +++++-------- .../Zal/Backend/HelperFunctions/ProcessesGetter.cs | 6 ++---- .../SpecificFunctions/DiskInfoGetter.cs | 3 --- .../Zal/Functions/MajorFunctions/DataManager.cs | 10 ++++------ .../Zal/Functions/MajorFunctions/LocalSocket.cs | 4 ++-- 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/zal_program/Zal/Backend.cs b/zal_program/Zal/Backend.cs index 7516ad9..d4afd1d 100644 --- a/zal_program/Zal/Backend.cs +++ b/zal_program/Zal/Backend.cs @@ -9,7 +9,7 @@ namespace Zal { public class BackendManager { - private readonly computerDataGetter computerDataGetter = null; + private readonly computerDataGetter computerDataGetter; public event EventHandler fpsDataReceived; private readonly FpsDataGetter fpsDataGetter = new FpsDataGetter(); diff --git a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs index 27883c2..e199d28 100644 --- a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs @@ -11,12 +11,12 @@ public class FpsDataGetter { private Process? presentmonProcess; private readonly Task fpsTask; - private bool isDisposed = false; + private bool isDisposed; public event EventHandler sendFpsData; private readonly List fpsDatas = []; private readonly int processId; private readonly Stopwatch stopwatch = new Stopwatch(); - private bool shouldLog = false; + private bool shouldLog; public FpsDataGetter() { @@ -40,8 +40,7 @@ public double calculatePercentile(IEnumerable seq, double percentile) var frac = realIndex - index; if (index + 1 < elements.Length) return elements[index] * (1 - frac) + elements[index + 1] * frac; - else - return elements[index]; + return elements[index]; } public void disposeIt() @@ -164,10 +163,8 @@ private async Task parseIncomingPresentmonData() continue; } - else - { - Logger.Log("msBetweenPresents not digits"); - } + + Logger.Log("msBetweenPresents not digits"); } else { diff --git a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs index c7364af..a19fee6 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs @@ -52,10 +52,8 @@ public void resetSentIcons() // Timeout occurred return null; } - else - { - return await tcs.Task; - } + + return await tcs.Task; } public async Task update() diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs index 8906712..33584fa 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/DiskInfoGetter.cs @@ -36,10 +36,7 @@ public static diskInfo GetdiskInfo(int diskNumber,crystalDiskData? crystalDiskDa partitionInfo.label = driveInfo.VolumeLabel; } } - else - { - } partitionInfo.size = Convert.ToInt64(partition["Size"]); diskInfo.partitions.Add(partitionInfo); } diff --git a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs index e391e9c..b55f4b8 100644 --- a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs +++ b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs @@ -18,7 +18,7 @@ namespace Zal.Functions.MajorFunctions public class DataManager { //if this is true, the loop will run every 1 second. if false, the loop will run every 5 seconds. - private bool isMobileConnected = false; + private bool isMobileConnected; private readonly EventHandler computerDataReceived; private readonly ChartsDataManager chartsDataManager = new ChartsDataManager(); public DataManager(EventHandler computerDataReceived) @@ -166,11 +166,9 @@ public async Task>> updateAsync(computerData com { return computerData.gpuData.First(); } - else - { - Logger.Log("available gpu is 0, will return no gpu"); - return null; - } + + Logger.Log("available gpu is 0, will return no gpu"); + return null; } private static List addElementToList(List? oldList, object element) diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs index 03e2d61..fe1dcf4 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs @@ -16,8 +16,8 @@ public class LocalSocket { public event EventHandler connectionStateChanged; public SocketIOClient.SocketIO socketio; - public bool isConnected = false; - public bool isMobileConnected = false; + public bool isConnected; + public bool isMobileConnected; private Process? serverProcess; public LocalSocket( EventHandler stateChanged From 3a8319ea35e1dfebaae2dcc5d5677488e9dbc9d7 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:48:46 +0100 Subject: [PATCH 08/15] Remove redundant conde --- zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs | 5 ++--- zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs | 2 +- zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs | 4 ---- .../SpecificFunctions/CrystalDiskInfoGetter.cs | 4 ++-- zal_program/Zal/Functions/MajorFunctions/DataManager.cs | 4 ---- zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs | 6 +++--- 6 files changed, 8 insertions(+), 17 deletions(-) diff --git a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs index e199d28..9c48e77 100644 --- a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs @@ -76,15 +76,14 @@ public async void startPresentmon(int processId, bool logFps) presentmonProcess = new Process { StartInfo = startInfo }; try { - presentmonProcess.Start(); } catch (Exception ex) { - Logger.LogError($"error running presentmon", ex); + Logger.LogError("error running presentmon", ex); } - Task.Run(async () => { await parseIncomingPresentmonData(); }); + Task.Run(parseIncomingPresentmonData); } private static string getTimestamp() diff --git a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs index a19fee6..baf6524 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs @@ -8,7 +8,7 @@ namespace Zal.HelperFunctions { public class ProcessesGetter { - private readonly SocketIOClient.SocketIO client = new SocketIOClient.SocketIO($"http://localhost:6511/"); + private readonly SocketIOClient.SocketIO client = new SocketIOClient.SocketIO("http://localhost:6511/"); private readonly Dictionary> taskCompletionSources = new Dictionary>(); public Dictionary data = new Dictionary(); diff --git a/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs b/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs index f0fb326..0e0bf3c 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ScreenCapturer.cs @@ -17,10 +17,6 @@ public class ScreenCapturer private bool _run, _init; public int Size { get; private set; } - public ScreenCapturer() - { - } - public void Start(int frameRate = 30) { _run = true; diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs index b0d0fc5..95c6cb0 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs @@ -38,7 +38,7 @@ internal class CrystaldiskInfoGetter } catch (Exception ex) { - Logger.LogError($"error running crystaldiskInfo process", ex); + Logger.LogError("error running crystaldiskInfo process", ex); } try @@ -51,7 +51,7 @@ internal class CrystaldiskInfoGetter } catch (Exception ex) { - Logger.LogError($"error parsing crystaldiskInfo data", ex); + Logger.LogError("error parsing crystaldiskInfo data", ex); } return null; diff --git a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs index b55f4b8..b2fe97f 100644 --- a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs +++ b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs @@ -114,10 +114,6 @@ internal class ChartsDataManager { private readonly Dictionary> data = new Dictionary>(); - public ChartsDataManager() - { - } - public async Task>> updateAsync(computerData computerData) { var primaryGpu = await getPrimaryGpu(computerData); diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs index fe1dcf4..8648d9e 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs @@ -77,7 +77,7 @@ private async Task setupSocketio() } catch (Exception ex) { - Logger.LogError($"error running server process", ex); + Logger.LogError("error running server process", ex); } @@ -209,11 +209,11 @@ private async Task setupSocketio() } catch (Exception ex) { - sendMessage($"information_text", $"failed to kill a process,{ex.Message}"); + sendMessage("information_text", $"failed to kill a process,{ex.Message}"); } } - sendMessage("information_text", $"Process killed!"); + sendMessage("information_text", "Process killed!"); }); socketio.OnConnected += (sender, args) => From f92c570ea4f00642a724843c32e46766bbc4ec70 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:49:29 +0100 Subject: [PATCH 09/15] Performance: Use count property --- .../HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs index a6e9850..d221dac 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs @@ -91,8 +91,8 @@ private async Task getPrimaryNetworkSpeedAsync(string? primaryNetwork) if (i % 10 == 0) { // ~1 second - var brSec = readsBr.Sum() / readsBs.Count(); - var bsSec = readsBs.Sum() / readsBs.Count(); + var brSec = readsBr.Sum() / readsBs.Count; + var bsSec = readsBs.Sum() / readsBs.Count; var s = new networkSpeed((int)brSec, (int)bsSec); primaryNetworkSpeed = s; } From e164ebfdbaeb8f789e493d818f2c50d81b7597fa Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:55:06 +0100 Subject: [PATCH 10/15] Use [] and target typed new. Simplify IF statements --- zal_program/Zal/Backend.cs | 2 +- .../Zal/Backend/Constants/Models/ComputerData.cs | 4 ++-- .../Zal/Backend/Constants/Models/CpuData.cs | 8 ++++---- .../Zal/Backend/Constants/Models/StorageData.cs | 8 ++++---- .../HelperFunctions/ComputerDataGetter.cs | 8 ++++---- .../Zal/Backend/HelperFunctions/FpsDataGetter.cs | 2 +- .../Zal/Backend/HelperFunctions/GlobalClass.cs | 2 +- .../Zal/Backend/HelperFunctions/Logger.cs | 2 +- .../Backend/HelperFunctions/ProcessesGetter.cs | 10 +++++----- .../SpecificFunctions/CrystalDiskInfoGetter.cs | 16 ++++++++-------- .../SpecificFunctions/GpuUtilizationGetter.cs | 2 +- .../SpecificFunctions/NetworkSpeedGetter.cs | 2 +- .../Zal/Functions/MajorFunctions/DataManager.cs | 4 ++-- .../Functions/MajorFunctions/LocalDatabase.cs | 4 ++-- zal_program/Zal/MainForm.cs | 2 +- zal_program/Zal/Pages/ConfigurationsForm.cs | 2 +- 16 files changed, 39 insertions(+), 39 deletions(-) diff --git a/zal_program/Zal/Backend.cs b/zal_program/Zal/Backend.cs index d4afd1d..b7a15dd 100644 --- a/zal_program/Zal/Backend.cs +++ b/zal_program/Zal/Backend.cs @@ -11,7 +11,7 @@ public class BackendManager { private readonly computerDataGetter computerDataGetter; public event EventHandler fpsDataReceived; - private readonly FpsDataGetter fpsDataGetter = new FpsDataGetter(); + private readonly FpsDataGetter fpsDataGetter = new(); public BackendManager() { diff --git a/zal_program/Zal/Backend/Constants/Models/ComputerData.cs b/zal_program/Zal/Backend/Constants/Models/ComputerData.cs index 512e15d..517b29d 100644 --- a/zal_program/Zal/Backend/Constants/Models/ComputerData.cs +++ b/zal_program/Zal/Backend/Constants/Models/ComputerData.cs @@ -20,8 +20,8 @@ public class computerData public computerData() { - gpuData = new List(); - storagesData = new List(); + gpuData = []; + storagesData = []; } } } diff --git a/zal_program/Zal/Backend/Constants/Models/CpuData.cs b/zal_program/Zal/Backend/Constants/Models/CpuData.cs index 845c666..fd352c2 100644 --- a/zal_program/Zal/Backend/Constants/Models/CpuData.cs +++ b/zal_program/Zal/Backend/Constants/Models/CpuData.cs @@ -11,10 +11,10 @@ public class cpuData public uint temperature; public uint load; public ulong power; - public Dictionary powers = new Dictionary(); - public Dictionary loads = new Dictionary(); - public Dictionary voltages = new Dictionary(); - public Dictionary clocks = new Dictionary(); + public Dictionary powers = new(); + public Dictionary loads = new(); + public Dictionary voltages = new(); + public Dictionary clocks = new(); public cpuData(IHardware hardware, cpuInfo? cpuInfo) { diff --git a/zal_program/Zal/Backend/Constants/Models/StorageData.cs b/zal_program/Zal/Backend/Constants/Models/StorageData.cs index 8755f84..42f8498 100644 --- a/zal_program/Zal/Backend/Constants/Models/StorageData.cs +++ b/zal_program/Zal/Backend/Constants/Models/StorageData.cs @@ -16,9 +16,9 @@ public class storageData public ulong? writeRate { get; set; } //whether it's hdd, ssd, or external storage public string type { get; set; } - public List partitions { get; } = new List(); - public Dictionary info = new Dictionary(); - public List smartAttributes = new List(); + public List partitions { get; } = []; + public Dictionary info = new(); + public List smartAttributes = []; public storageData(IHardware hardware, List? crystalDiskDatas) { type = "External"; @@ -129,5 +129,5 @@ public class diskInfo public int diskNumber { get; set; } public long totalSize { get; set; } public ulong freeSpace { get; set; } - public List partitions { get; } = new List(); + public List partitions { get; } = []; } diff --git a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs index 69b8bcb..878b244 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs @@ -16,14 +16,14 @@ public class computerDataGetter private readonly List? crystalDiskDatas; private readonly List? 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 processesGpuUsage = new Dictionary(); - private readonly Computer computer = new Computer + private readonly Dictionary processesGpuUsage = new(); + private readonly Computer computer = new() { IsCpuEnabled = true, IsGpuEnabled = true, diff --git a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs index 9c48e77..d651c6a 100644 --- a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs @@ -15,7 +15,7 @@ public class FpsDataGetter public event EventHandler sendFpsData; private readonly List fpsDatas = []; private readonly int processId; - private readonly Stopwatch stopwatch = new Stopwatch(); + private readonly Stopwatch stopwatch = new(); private bool shouldLog; public FpsDataGetter() diff --git a/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs b/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs index 8fa48c8..b4dac1b 100644 --- a/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs +++ b/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs @@ -15,7 +15,7 @@ public class GlobalClass private ManagementObjectCollection? win32DiskDrives; private ManagementObjectCollection? win32DiskPartitions; private ManagementObjectCollection? win32DiskPartitionsForFreeDiskSpace; - public ProcessesGetter processesGetter = new ProcessesGetter(); + public ProcessesGetter processesGetter = new(); private static GlobalClass instance; private List? processInfos; diff --git a/zal_program/Zal/Backend/HelperFunctions/Logger.cs b/zal_program/Zal/Backend/HelperFunctions/Logger.cs index 434fda6..7bf2972 100644 --- a/zal_program/Zal/Backend/HelperFunctions/Logger.cs +++ b/zal_program/Zal/Backend/HelperFunctions/Logger.cs @@ -5,7 +5,7 @@ namespace Zal { public static class Logger { - private static readonly object _locker = new object(); + private static readonly object _locker = new(); public static void LogError(string message, Exception ex, object dataToPrint = null) { diff --git a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs index baf6524..6835ba2 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs @@ -8,15 +8,15 @@ namespace Zal.HelperFunctions { public class ProcessesGetter { - private readonly SocketIOClient.SocketIO client = new SocketIOClient.SocketIO("http://localhost:6511/"); - private readonly Dictionary> taskCompletionSources = new Dictionary>(); - public Dictionary data = new Dictionary(); + private readonly SocketIOClient.SocketIO client = new("http://localhost:6511/"); + private readonly Dictionary> taskCompletionSources = new(); + public Dictionary data = new(); //this list contains the names of processes that we've already loaded and sent to the phone. //this is to save network bandwidth as icons are quite large (i think about 5-10kb each), //so we cache the icons in the mobile app, and when the app disconnects, we reset this list //so that we send icons to the app once again when app reconnects. - private readonly List loadedIcons = new List(); + private readonly List loadedIcons = []; public ProcessesGetter() { @@ -69,7 +69,7 @@ public async Task update() { processData = (Dictionary)result[processName]; processData["memoryUsage"] = (long)processData["memoryUsage"] + ramUsageBytes / (1024 * 1024); - processData["pids"] = ((List)processData["pids"]).Concat(new[] { (int)process.Id }).ToList(); + processData["pids"] = ((List)processData["pids"]).Concat([(int)process.Id]).ToList(); result[processName] = processData; } else diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs index 95c6cb0..6151e77 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs @@ -13,7 +13,7 @@ internal class CrystaldiskInfoGetter { public static List? getcrystalDiskData() { - if (IsAdminstratorChecker.IsAdministrator() == false) + if (!IsAdminstratorChecker.IsAdministrator()) { //dont run if it's not running as adminstrator, because crystaldiskInfo don't work without it Logger.Log("didn't run crystaldiskInfo, program isn't running as adminstrator"); @@ -84,7 +84,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) currentHardware.info.Add("model", line.Split(':')[1].Trim()); } - if (line.Contains("Buffer Size :") && line.Contains("Unknown") == false) + if (line.Contains("Buffer Size :") && !line.Contains("Unknown")) { var hoursString = Regex.Match(line.Split(':')[1].Trim(), @"\d+").Value; if (!string.IsNullOrEmpty(hoursString)) @@ -161,12 +161,12 @@ private static List parseCrystaldiskInfoOutput(string filePath) /////////////////// else if ((line.Contains("ID Cur Wor Thr RawValues(6) Attribute Name"))) { - currentHardware.smartAttributes = new List(); + currentHardware.smartAttributes = []; continue; // Skip header line } else if (line.Contains("ID RawValues(6) Attribute Name")) { - currentHardware.smartAttributes = new List(); + currentHardware.smartAttributes = []; currentHardware.isNvme = true; continue; // Skip header line } @@ -174,9 +174,9 @@ private static List parseCrystaldiskInfoOutput(string filePath) { continue; } - else if (currentHardware.smartAttributes != null && currentHardware.isNvme == false) + else if (currentHardware.smartAttributes != null && !currentHardware.isNvme) { - var parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + var parts = line.Split([' '], StringSplitOptions.RemoveEmptyEntries); var attributeName = string.Join(" ", parts, 5, parts.Length - 5); if (attributeName.Contains("Temperature")) { @@ -204,9 +204,9 @@ private static List parseCrystaldiskInfoOutput(string filePath) }; currentHardware.smartAttributes.Add(smartAttribute); } - else if (currentHardware.smartAttributes != null && currentHardware.isNvme == true) + else if (currentHardware.smartAttributes != null && currentHardware.isNvme) { - var parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + var parts = line.Split([' '], StringSplitOptions.RemoveEmptyEntries); var attributeName = string.Join(" ", parts, 2, parts.Length - 2); if (attributeName.Contains("Temperature")) { diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs index 158f687..d1aa6a7 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/GpuUtilizationGetter.cs @@ -64,7 +64,7 @@ public static Dictionary> getProcessesGpuUsa { if (skipBlackListedProcesses) { - if (foundProcessInfo.isBlacklisted == true) continue; + if (foundProcessInfo.isBlacklisted) continue; } if (foundProcessInfo.displayName != null) diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs index d221dac..f3aee16 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs @@ -103,7 +103,7 @@ private async Task> getNetworkInterfacesAsync() { var primaryNetwork = (string?)LocalDatabase.Instance.readKey("primaryNetwork"); if (!NetworkInterface.GetIsNetworkAvailable()) - return new List(); + return []; var interfaces = NetworkInterface.GetAllNetworkInterfaces(); diff --git a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs index b2fe97f..296d9b3 100644 --- a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs +++ b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs @@ -20,7 +20,7 @@ public class DataManager //if this is true, the loop will run every 1 second. if false, the loop will run every 5 seconds. private bool isMobileConnected; private readonly EventHandler computerDataReceived; - private readonly ChartsDataManager chartsDataManager = new ChartsDataManager(); + private readonly ChartsDataManager chartsDataManager = new(); public DataManager(EventHandler computerDataReceived) { this.computerDataReceived = computerDataReceived; @@ -112,7 +112,7 @@ private static string CompressGzip(string text) internal class ChartsDataManager { - private readonly Dictionary> data = new Dictionary>(); + private readonly Dictionary> data = new(); public async Task>> updateAsync(computerData computerData) { diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs index 7b0e85a..83273eb 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs @@ -8,9 +8,9 @@ namespace Zal { public class LocalDatabase { - private readonly Dictionary data = new Dictionary(); + private readonly Dictionary data = new(); private static LocalDatabase instance; - private readonly SemaphoreSlim _writeSemaphore = new SemaphoreSlim(1); + private readonly SemaphoreSlim _writeSemaphore = new(1); private LocalDatabase(Dictionary initData) { diff --git a/zal_program/Zal/MainForm.cs b/zal_program/Zal/MainForm.cs index 0cac20d..f7a3e86 100644 --- a/zal_program/Zal/MainForm.cs +++ b/zal_program/Zal/MainForm.cs @@ -20,7 +20,7 @@ public partial class MainForm : Form private const int WM_SYSCOMMAND = 0x0112; private const int SC_MINIMIZE = 0xf020; private Task pipeTask; - private List gpuDatas = new List(); + private List gpuDatas = []; private NotifyIcon ni; private const string PipeName = "ZalAppPipe"; private bool launchedByStartup; diff --git a/zal_program/Zal/Pages/ConfigurationsForm.cs b/zal_program/Zal/Pages/ConfigurationsForm.cs index e043c3f..936e711 100644 --- a/zal_program/Zal/Pages/ConfigurationsForm.cs +++ b/zal_program/Zal/Pages/ConfigurationsForm.cs @@ -57,7 +57,7 @@ private void ConfigurationsForm_Load(object sender, EventArgs e) } } - if (doesPrimaryGpuExist == false) + if (!doesPrimaryGpuExist) { Logger.Log($"primary gpu not found, setting this gpu as default:{gpuData[0].name}"); //reset primary gpu From fb1e904760af3b4b2ed1666002cb0ce06375fcd3 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:56:03 +0100 Subject: [PATCH 11/15] Use [] part 2 --- zal_program/Zal/Backend/Constants/Models/CpuData.cs | 8 ++++---- zal_program/Zal/Backend/Constants/Models/StorageData.cs | 2 +- .../Zal/Backend/HelperFunctions/ComputerDataGetter.cs | 2 +- .../Zal/Backend/HelperFunctions/ProcessesGetter.cs | 4 ++-- .../SpecificFunctions/CrystalDiskInfoGetter.cs | 2 +- zal_program/Zal/Functions/MajorFunctions/DataManager.cs | 2 +- zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/zal_program/Zal/Backend/Constants/Models/CpuData.cs b/zal_program/Zal/Backend/Constants/Models/CpuData.cs index fd352c2..ba459b9 100644 --- a/zal_program/Zal/Backend/Constants/Models/CpuData.cs +++ b/zal_program/Zal/Backend/Constants/Models/CpuData.cs @@ -11,10 +11,10 @@ public class cpuData public uint temperature; public uint load; public ulong power; - public Dictionary powers = new(); - public Dictionary loads = new(); - public Dictionary voltages = new(); - public Dictionary clocks = new(); + public Dictionary powers = []; + public Dictionary loads = []; + public Dictionary voltages = []; + public Dictionary clocks = []; public cpuData(IHardware hardware, cpuInfo? cpuInfo) { diff --git a/zal_program/Zal/Backend/Constants/Models/StorageData.cs b/zal_program/Zal/Backend/Constants/Models/StorageData.cs index 42f8498..2eda977 100644 --- a/zal_program/Zal/Backend/Constants/Models/StorageData.cs +++ b/zal_program/Zal/Backend/Constants/Models/StorageData.cs @@ -17,7 +17,7 @@ public class storageData //whether it's hdd, ssd, or external storage public string type { get; set; } public List partitions { get; } = []; - public Dictionary info = new(); + public Dictionary info = []; public List smartAttributes = []; public storageData(IHardware hardware, List? crystalDiskDatas) { diff --git a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs index 878b244..e63726d 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs @@ -22,7 +22,7 @@ public class computerDataGetter //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 processesGpuUsage = new(); + private readonly Dictionary processesGpuUsage = []; private readonly Computer computer = new() { IsCpuEnabled = true, diff --git a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs index 6835ba2..e68cd5a 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs @@ -9,8 +9,8 @@ namespace Zal.HelperFunctions public class ProcessesGetter { private readonly SocketIOClient.SocketIO client = new("http://localhost:6511/"); - private readonly Dictionary> taskCompletionSources = new(); - public Dictionary data = new(); + private readonly Dictionary> taskCompletionSources = []; + public Dictionary data = []; //this list contains the names of processes that we've already loaded and sent to the phone. //this is to save network bandwidth as icons are quite large (i think about 5-10kb each), diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs index 6151e77..acf0047 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/CrystalDiskInfoGetter.cs @@ -74,7 +74,7 @@ private static List parseCrystaldiskInfoOutput(string filePath) currentHardware = new crystalDiskData { - info = new Dictionary() + info = [] }; } else if (currentHardware != null) diff --git a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs index 296d9b3..908b901 100644 --- a/zal_program/Zal/Functions/MajorFunctions/DataManager.cs +++ b/zal_program/Zal/Functions/MajorFunctions/DataManager.cs @@ -112,7 +112,7 @@ private static string CompressGzip(string text) internal class ChartsDataManager { - private readonly Dictionary> data = new(); + private readonly Dictionary> data = []; public async Task>> updateAsync(computerData computerData) { diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs index 83273eb..e2c1e08 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalDatabase.cs @@ -8,7 +8,7 @@ namespace Zal { public class LocalDatabase { - private readonly Dictionary data = new(); + private readonly Dictionary data = []; private static LocalDatabase instance; private readonly SemaphoreSlim _writeSemaphore = new(1); @@ -37,7 +37,7 @@ public static async Task Initialize() } } - instance = new LocalDatabase(new Dictionary()); + instance = new LocalDatabase([]); } public static LocalDatabase Instance From bdecca0e2e66cbdee91ce63351e4c31a5d6f29c1 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:57:28 +0100 Subject: [PATCH 12/15] Simplify if checks --- zal_program/Zal/Backend/Constants/Models/CpuData.cs | 10 ++-------- zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs | 5 +---- .../SpecificFunctions/NetworkSpeedGetter.cs | 5 +---- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/zal_program/Zal/Backend/Constants/Models/CpuData.cs b/zal_program/Zal/Backend/Constants/Models/CpuData.cs index ba459b9..875a8a1 100644 --- a/zal_program/Zal/Backend/Constants/Models/CpuData.cs +++ b/zal_program/Zal/Backend/Constants/Models/CpuData.cs @@ -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) { diff --git a/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs b/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs index b4dac1b..548f5c3 100644 --- a/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs +++ b/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs @@ -102,10 +102,7 @@ public static GlobalClass Instance { get { - if (instance == null) - { - instance = new GlobalClass(); - } + instance ??= new GlobalClass(); return instance; } diff --git a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs index f3aee16..4df0641 100644 --- a/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/SpecificFunctions/NetworkSpeedGetter.cs @@ -44,10 +44,7 @@ private async Task getPrimaryNetworkSpeedAsync(string? primaryNetwork) { //var nics = networkInterfaces(); - if (networkInterfaces == null) - { - networkInterfaces = NetworkInterface.GetAllNetworkInterfaces().ToList(); - } + networkInterfaces ??= NetworkInterface.GetAllNetworkInterfaces().ToList(); // Select desired NIC var a = primaryNetwork; From 45fedf2822604eb9496862252a118f579e77e45d Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:58:57 +0100 Subject: [PATCH 13/15] Fix warnings about not used exception --- .../Zal/Backend/Constants/Models/StorageData.cs | 10 +++------- .../Zal/Backend/HelperFunctions/ComputerDataGetter.cs | 2 +- zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs | 4 ++-- zal_program/Zal/Backend/HelperFunctions/Logger.cs | 2 +- .../Zal/Backend/HelperFunctions/ProcessesGetter.cs | 2 +- .../Zal/Functions/MajorFunctions/LocalSocket.cs | 2 +- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/zal_program/Zal/Backend/Constants/Models/StorageData.cs b/zal_program/Zal/Backend/Constants/Models/StorageData.cs index 2eda977..696bd94 100644 --- a/zal_program/Zal/Backend/Constants/Models/StorageData.cs +++ b/zal_program/Zal/Backend/Constants/Models/StorageData.cs @@ -58,9 +58,8 @@ public storageData(IHardware hardware, List? crystalDiskDatas) { temperature = (ulong)sensor.Value; } - catch (Exception ex) + catch (Exception) { - } } else if (sensor.SensorType == SensorType.Throughput && sensor.Name == "Read Rate") @@ -72,11 +71,9 @@ public storageData(IHardware hardware, List? crystalDiskDatas) { readRate = ulong.Parse(sensor.Value.ToString().Split('.')[0]); } - } - catch (Exception ex) + catch (Exception) { - } } @@ -86,9 +83,8 @@ public storageData(IHardware hardware, List? crystalDiskDatas) { writeRate = (ulong)sensor.Value; } - catch (Exception ex) + catch (Exception) { - } } } diff --git a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs index e63726d..44df91e 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ComputerDataGetter.cs @@ -44,7 +44,7 @@ public computerDataGetter() computer.Open(); break; } - catch (Exception ex) + catch (Exception) { attempts++; } diff --git a/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs b/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs index 548f5c3..e1293c1 100644 --- a/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs +++ b/zal_program/Zal/Backend/HelperFunctions/GlobalClass.cs @@ -72,7 +72,7 @@ public bool saveTextToDocumentFolder(string filename, string data) // File not found return null; } - catch (IOException c) + catch (IOException) { // Error reading file, try to delete the file try @@ -121,7 +121,7 @@ public string extractZipFromResourcesAndGetFilepathWithinTheExtract(string zipFi { System.IO.Compression.ZipFile.ExtractToDirectory(zipFilepath, zipFileNameWithoutDotZip); } - catch (IOException c) + catch (IOException) { } diff --git a/zal_program/Zal/Backend/HelperFunctions/Logger.cs b/zal_program/Zal/Backend/HelperFunctions/Logger.cs index 7bf2972..0875d13 100644 --- a/zal_program/Zal/Backend/HelperFunctions/Logger.cs +++ b/zal_program/Zal/Backend/HelperFunctions/Logger.cs @@ -22,7 +22,7 @@ public static void Log(string logMessage) //Use this for daily log files : "Log" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt"; WriteToLog(logMessage, logFilePath); } - catch (Exception e) + catch (Exception) { //the irony, right? well I can't do much here } diff --git a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs index e68cd5a..0b8581f 100644 --- a/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/ProcessesGetter.cs @@ -96,7 +96,7 @@ public async Task update() } } } - catch (Exception c) + catch (Exception) { // loadedIcons.Add(processName); } diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs index 8648d9e..e0e32df 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs @@ -243,7 +243,7 @@ private async void connectToServer() { socketio.ConnectAsync(); } - catch (Exception ex) + catch (Exception) { connectToServer(); } From 2ff302f4516053b180867a81164c7d6ac48cf544 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 12:59:51 +0100 Subject: [PATCH 14/15] Simplify object initialization --- zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs | 8 +++++--- zal_program/Zal/MainForm.cs | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs index e0e32df..623500f 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs @@ -64,8 +64,11 @@ private async Task setupSocketio() CreateNoWindow = true, Arguments = $"{port} \"{pcName}\"", }; - serverProcess = new Process { StartInfo = startInfo }; - serverProcess.EnableRaisingEvents = true; // Enables the Exited event to be raised + serverProcess = new Process + { + StartInfo = startInfo, + EnableRaisingEvents = true // Enables the Exited event to be raised + }; serverProcess.Exited += (sender, args) => { System.Diagnostics.Debug.WriteLine(args); @@ -80,7 +83,6 @@ private async Task setupSocketio() Logger.LogError("error running server process", ex); } - var ip = Zal.Backend.HelperFunctions.SpecificFunctions.IpGetter.getIp(); socketio = new SocketIOClient.SocketIO($"http://{ip}:{port}", new SocketIOOptions diff --git a/zal_program/Zal/MainForm.cs b/zal_program/Zal/MainForm.cs index f7a3e86..df03127 100644 --- a/zal_program/Zal/MainForm.cs +++ b/zal_program/Zal/MainForm.cs @@ -69,9 +69,11 @@ private Task StartPipeServer() } private void setupTrayMenu() { - ni = new NotifyIcon(); - ni.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Process.GetCurrentProcess().MainModule.FileName); - ni.Visible = true; + ni = new NotifyIcon + { + Icon = System.Drawing.Icon.ExtractAssociatedIcon(Process.GetCurrentProcess().MainModule.FileName), + Visible = true + }; var trayMenu = new ContextMenuStrip(); trayMenu.Click += delegate (object sender, EventArgs args) From 6deb76a8e82c05582c89a5b2f576f962aadbc200 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sat, 9 Nov 2024 13:00:21 +0100 Subject: [PATCH 15/15] Remove redundant qualifiers --- .../Functions/MajorFunctions/LocalSocket.cs | 5 ++-- zal_program/Zal/MainForm.cs | 28 +++++++++---------- zal_program/Zal/Pages/ConfigurationsForm.cs | 2 +- .../Zal/Pages/ConnectionSettingsForm.cs | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs index 623500f..0af3d00 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs @@ -54,6 +54,7 @@ private async Task setupSocketio() pcName = "Default Computer"; } } + pcName = string.Concat(pcName.Where(char.IsLetterOrDigit)); var filePath = GlobalClass.Instance.getFilepathFromResources("server.exe"); var startInfo = new ProcessStartInfo @@ -71,7 +72,7 @@ private async Task setupSocketio() }; serverProcess.Exited += (sender, args) => { - System.Diagnostics.Debug.WriteLine(args); + Debug.WriteLine(args); }; try { @@ -83,7 +84,7 @@ private async Task setupSocketio() Logger.LogError("error running server process", ex); } - var ip = Zal.Backend.HelperFunctions.SpecificFunctions.IpGetter.getIp(); + var ip = Backend.HelperFunctions.SpecificFunctions.IpGetter.getIp(); socketio = new SocketIOClient.SocketIO($"http://{ip}:{port}", new SocketIOOptions { diff --git a/zal_program/Zal/MainForm.cs b/zal_program/Zal/MainForm.cs index df03127..a17ff55 100644 --- a/zal_program/Zal/MainForm.cs +++ b/zal_program/Zal/MainForm.cs @@ -51,9 +51,9 @@ private Task StartPipeServer() { Invoke(new Action(() => { - this.Show(); - this.WindowState = FormWindowState.Normal; - this.Activate(); + Show(); + WindowState = FormWindowState.Normal; + Activate(); })); } } @@ -71,7 +71,7 @@ private void setupTrayMenu() { ni = new NotifyIcon { - Icon = System.Drawing.Icon.ExtractAssociatedIcon(Process.GetCurrentProcess().MainModule.FileName), + Icon = Icon.ExtractAssociatedIcon(Process.GetCurrentProcess().MainModule.FileName), Visible = true }; var trayMenu = new ContextMenuStrip(); @@ -83,7 +83,7 @@ private void setupTrayMenu() }; // Add items to the context menu trayMenu.Items.Add("Open", null, (sender, e) => Show()); - trayMenu.Items.Add("Exit", null, (sender, e) => System.Windows.Forms.Application.Exit()); + trayMenu.Items.Add("Exit", null, (sender, e) => Application.Exit()); ni.ContextMenuStrip = trayMenu; ni.DoubleClick += delegate (object sender, EventArgs args) @@ -95,7 +95,7 @@ private void setupTrayMenu() if ((string?)LocalDatabase.Instance.readKey("startMinimized") == "1") { if (launchedByStartup) - { this.Hide(); } + { Hide(); } } } private async void MainForm_Load(object sender, EventArgs e) @@ -104,14 +104,14 @@ private async void MainForm_Load(object sender, EventArgs e) await FrontendGlobalClass.Initialize(socketConnectionStateChanged: (sender, state) => { - this.Invoke(new Action(() => + Invoke(new Action(() => { mobileConnectionText.Text = state == Functions.Models.SocketConnectionState.Connected ? "Mobile connected" : "Mobile not connected"; mobileConnectionText.ForeColor = !(state == Functions.Models.SocketConnectionState.Connected) ? Color.FromKnownColor(KnownColor.IndianRed) : Color.FromKnownColor(KnownColor.ForestGreen); })); }, computerDataReceived: (sender, data) => { - this.Invoke(new Action(() => + Invoke(new Action(() => { gpuDatas = data.gpuData; @@ -136,10 +136,10 @@ private void configurationsToolStripMenuItem_Click(object sender, EventArgs e) private async Task checkForUpdates() { var latestVersion = new WebClient().DownloadString("https://zalapp.com/program-version"); - var currentVersion = System.Windows.Forms.Application.ProductVersion; + var currentVersion = Application.ProductVersion; if (latestVersion != currentVersion) { - var dialog = System.Windows.Forms.MessageBox.Show($"New update is available! do you want to update?\ncurrent version: {currentVersion}\nlatest version:{latestVersion}", "Zal", MessageBoxButtons.YesNo); + var dialog = MessageBox.Show($"New update is available! do you want to update?\ncurrent version: {currentVersion}\nlatest version:{latestVersion}", "Zal", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { using (var webClient = new WebClient()) @@ -160,7 +160,7 @@ private async Task checkForUpdates() } catch (Exception ex) { - System.Windows.Forms.MessageBox.Show("An error occurred updating Zal: " + ex.Message); + MessageBox.Show("An error occurred updating Zal: " + ex.Message); } } } @@ -188,13 +188,13 @@ private void viewLogToolStripMenuItem_Click(object sender, EventArgs e) private async void copyProcessedBackendDataToolStripMenuItem_ClickAsync(object sender, EventArgs e) { var data = await FrontendGlobalClass.Instance.dataManager.getBackendData(); - System.Windows.Forms.Clipboard.SetText(Newtonsoft.Json.JsonConvert.SerializeObject(data)); + Clipboard.SetText(Newtonsoft.Json.JsonConvert.SerializeObject(data)); } private void copyRawBackendDataToolStripMenuItem_Click(object sender, EventArgs e) { var data = FrontendGlobalClass.Instance.backend.getEntireComputerData(); - System.Windows.Forms.Clipboard.SetText(Newtonsoft.Json.JsonConvert.SerializeObject(data)); + Clipboard.SetText(Newtonsoft.Json.JsonConvert.SerializeObject(data)); } @@ -230,7 +230,7 @@ protected override void WndProc(ref Message m) if (m.WParam.ToInt32() == SC_MINIMIZE) { - this.Hide(); + Hide(); m.Result = IntPtr.Zero; return; } diff --git a/zal_program/Zal/Pages/ConfigurationsForm.cs b/zal_program/Zal/Pages/ConfigurationsForm.cs index 936e711..cbe69aa 100644 --- a/zal_program/Zal/Pages/ConfigurationsForm.cs +++ b/zal_program/Zal/Pages/ConfigurationsForm.cs @@ -76,7 +76,7 @@ private async void button1_Click(object sender, EventArgs e) await LocalDatabase.Instance.writeKey("runOnStartup", runOnStartupCheckbox.Checked ? "1" : "0"); await LocalDatabase.Instance.writeKey("startMinimized", startMinimizedCheckbox.Checked ? "1" : "0"); FrontendGlobalClass.Instance.localSocket.restartSocketio(); - this.Hide(); + Hide(); } private async void gpusList_SelectedIndexChanged(object sender, EventArgs e) diff --git a/zal_program/Zal/Pages/ConnectionSettingsForm.cs b/zal_program/Zal/Pages/ConnectionSettingsForm.cs index 7663fab..4d82fc3 100644 --- a/zal_program/Zal/Pages/ConnectionSettingsForm.cs +++ b/zal_program/Zal/Pages/ConnectionSettingsForm.cs @@ -36,7 +36,7 @@ private void button1_Click(object sender, EventArgs e) LocalDatabase.Instance.writeKey("port", portTextBox.Text.Length == 0 ? null : portTextBox.Text); LocalDatabase.Instance.writeKey("pcName", pcNameTextBox.Text.Length == 0 ? null : pcNameTextBox.Text); FrontendGlobalClass.Instance.localSocket.restartSocketio(); - this.Hide(); + Hide(); } private void pcNameTextBox_KeyPress(object sender, KeyPressEventArgs e)