Skip to content

Portable Tool for an Ideal Windows Setup

upd. async counting for services & processes ref. optimized data sync logic and removed code duplication deb v5.4.6

Greedeks02be3cb2e77b
diff --git a/.Source/GTweak/Core/ViewModel/DataSystemViewModel.cs b/.Source/GTweak/Core/ViewModel/DataSystemViewModel.cs
index 611b34ba..5678e070 100644
--- a/.Source/GTweak/Core/ViewModel/DataSystemViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/DataSystemViewModel.cs
@@ -1,3 +1,5 @@
+using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
@@ -20,6 +22,8 @@ namespace GTweak.Core.ViewModel
private readonly DataSystemModel _model = new DataSystemModel();
private ObservableCollection<DataSystemModel> _collection;
+ private readonly List<Action> _modelUpdateActions = new List<Action>();
+ private readonly DataSystemModel _ipAddressModel;
public ObservableCollection<DataSystemModel> DisplayData
{
@@ -75,70 +79,70 @@ namespace GTweak.Core.ViewModel
{
DisplayData = new ObservableCollection<DataSystemModel>
{
- UpsertModelCollection("OSName", HardwareData.OS.Name, FallbackKeys.Unknown),
- UpsertModelCollection("OSVersion", HardwareData.OS.Version, FallbackKeys.Unknown),
- UpsertModelCollection("Processes", HardwareData.RunningProcessesCount),
- UpsertModelCollection("Services", HardwareData.RunningServicesCount),
- UpsertModelCollection("Bios", HardwareData.Bios.Data, FallbackKeys.NoDevice),
- UpsertModelCollection("Mode", HardwareData.Bios.Mode, FallbackKeys.Unknown),
- UpsertModelCollection("Motherboard", HardwareData.Motherboard, FallbackKeys.NoDevice),
- UpsertModelCollection("Processor", HardwareData.Processor.Data, FallbackKeys.NoDevice),
- UpsertModelCollection("Cores", HardwareData.Processor.Cores, FallbackKeys.Unknown),
- UpsertModelCollection("Threads", HardwareData.Processor.Threads, FallbackKeys.Unknown),
- UpsertModelCollection("Graphics", HardwareData.Graphics, FallbackKeys.NoDriver),
- UpsertModelCollection("RefreshRate", HardwareData.MonitorRefreshRate, FallbackKeys.Unknown),
- UpsertModelCollection("Memory", HardwareData.Memory.Data, FallbackKeys.NoDevice),
- UpsertModelCollection("Type", HardwareData.Memory.Type, FallbackKeys.Unknown),
- UpsertModelCollection("Storage", HardwareData.Storage, FallbackKeys.NoDevice),
- UpsertModelCollection("Audio", HardwareData.AudioDevice, FallbackKeys.NoDriver),
- UpsertModelCollection("Network", HardwareData.NetworkAdapter, FallbackKeys.NoDriver),
- UpsertModelCollection("IpAddress", HardwareData.UserIPAddress, FallbackKeys.ConnectionLost)
+ CreateModelCollection("OSName", () => HardwareData.OS.Name, FallbackKeys.Unknown),
+ CreateModelCollection("OSVersion", () => HardwareData.OS.Version, FallbackKeys.Unknown),
+ CreateModelCollection("Processes", () => HardwareData.RunningProcessesCount, isUpdatable: true),
+ CreateModelCollection("Services", () => HardwareData.RunningServicesCount, isUpdatable: true),
+ CreateModelCollection("Bios", () => HardwareData.Bios.Data, FallbackKeys.NoDevice),
+ CreateModelCollection("Mode", () => HardwareData.Bios.Mode, FallbackKeys.Unknown),
+ CreateModelCollection("Motherboard", () => HardwareData.Motherboard, FallbackKeys.NoDevice),
+ CreateModelCollection("Processor", () => HardwareData.Processor.Data, FallbackKeys.NoDevice),
+ CreateModelCollection("Cores", () => HardwareData.Processor.Cores, FallbackKeys.Unknown),
+ CreateModelCollection("Threads", () => HardwareData.Processor.Threads, FallbackKeys.Unknown),
+ CreateModelCollection("Graphics", () => HardwareData.Graphics, FallbackKeys.NoDevice),
+ CreateModelCollection("RefreshRate", () => HardwareData.MonitorRefreshRate, FallbackKeys.Unknown, true),
+ CreateModelCollection("Memory", () => HardwareData.Memory.Data, FallbackKeys.NoDevice),
+ CreateModelCollection("Type", () => HardwareData.Memory.Type, FallbackKeys.Unknown),
+ CreateModelCollection("Storage", () => HardwareData.Storage, FallbackKeys.NoDevice, true),
+ CreateModelCollection("Audio", () => HardwareData.AudioDevice, FallbackKeys.NoDriver, true),
+ CreateModelCollection("Network", () => HardwareData.NetworkAdapter, FallbackKeys.NoDriver, true),
+ (_ipAddressModel = CreateModelCollection("IpAddress", () => HardwareData.UserIPAddress, FallbackKeys.ConnectionLost, true))
};
-
RefreshStates();
}
internal void Update()
{
- UpsertModelCollection("RefreshRate", HardwareData.MonitorRefreshRate, FallbackKeys.Unknown);
- UpsertModelCollection("Storage", HardwareData.Storage, FallbackKeys.NoDevice);
- UpsertModelCollection("Audio", HardwareData.AudioDevice, FallbackKeys.NoDriver);
- UpsertModelCollection("Network", HardwareData.NetworkAdapter, FallbackKeys.NoDriver);
- UpsertModelCollection("IpAddress", HardwareData.UserIPAddress, FallbackKeys.ConnectionLost);
+ foreach (Action updateItemAction in _modelUpdateActions)
+ {
+ updateItemAction();
+ }
RefreshStates();
}
private void RefreshStates()
{
- DataSystemModel ipModel = this["IpAddress"];
- if (ipModel != null)
+ if (NetworkProvider.isIPAddressFormatValid || _ipAddressModel.Data.Any(char.IsDigit))
{
- if (NetworkProvider.isIPAddressFormatValid || ipModel.Data.Any(char.IsDigit))
- {
- SetBlurValue = SettingsEngine.IsHiddenIpAddress ? 20 : 0;
- SetVisibility = Visibility.Visible;
- }
- else
- {
- SetBlurValue = 0;
- SetVisibility = Visibility.Hidden;
- }
+ SetBlurValue = SettingsEngine.IsHiddenIpAddress ? 20 : 0;
+ SetVisibility = Visibility.Visible;
+ }
+ else
+ {
+ SetBlurValue = 0;
+ SetVisibility = Visibility.Hidden;
}
}
- private DataSystemModel UpsertModelCollection(string name, string data, string fallbackKey = null)
+ private DataSystemModel CreateModelCollection(string name, Func<string> dataProvider, string fallbackKey = null, bool isUpdatable = false)
{
- string targetData = (fallbackKey == null) ? (data ?? string.Empty) : (!string.IsNullOrEmpty(data) ? data : (Application.Current.Resources[fallbackKey] as string ?? string.Empty));
- DataSystemModel model = this[name];
+ DataSystemModel model = new DataSystemModel { Name = name };
+
+ void UpdateModelData()
+ {
+ string data = dataProvider();
+ model.Data = fallbackKey == null ? (data ?? string.Empty) : (!string.IsNullOrEmpty(data) ? data : (Application.Current.Resources[fallbackKey] as string ?? string.Empty));
+ }
+
+ UpdateModelData();
- if (model != null)
+ if (isUpdatable)
{
- model.Data = targetData;
- return model;
+ _modelUpdateActions.Add(UpdateModelData);
}
- return new DataSystemModel { Name = name, Data = targetData };
+ return model;
}
}
}
diff --git a/.Source/GTweak/Properties/AssemblyInfo.cs b/.Source/GTweak/Properties/AssemblyInfo.cs
index 95b99972..fc69aade 100644
--- a/.Source/GTweak/Properties/AssemblyInfo.cs
+++ b/.Source/GTweak/Properties/AssemblyInfo.cs
@@ -7,9 +7,9 @@ using System.Windows;
[assembly: AssemblyProduct("GTweak")]
[assembly: AssemblyCopyright("� 2024-2026 Greedeks")]
[assembly: AssemblyTrademark("Greedeks")]
-[assembly: AssemblyInformationalVersion("Build: 5.4.5")]
-[assembly: AssemblyVersion("5.4.55.15")]
-[assembly: AssemblyFileVersion("5.4.55.15")]
+[assembly: AssemblyInformationalVersion("Build: 5.4.6")]
+[assembly: AssemblyVersion("5.4.40.710")]
+[assembly: AssemblyFileVersion("5.4.40.710")]
[assembly: ComVisible(false)]
diff --git a/.Source/GTweak/Properties/AssemblyInfo.tt b/.Source/GTweak/Properties/AssemblyInfo.tt
index e0cb41b2..84f92623 100644
--- a/.Source/GTweak/Properties/AssemblyInfo.tt
+++ b/.Source/GTweak/Properties/AssemblyInfo.tt
@@ -22,7 +22,7 @@ using System.Windows;
[assembly: AssemblyMetadata("RepositoryType", "git")]
<#+
- private const string majorVersion = "Build: 5.4.5";
+ private const string majorVersion = "Build: 5.4.6";
private string GenerateVersion()
{
diff --git a/.Source/GTweak/Utilities/Configuration/MonitoringProvider.cs b/.Source/GTweak/Utilities/Configuration/MonitoringProvider.cs
index 41ab2c09..ba02644c 100644
--- a/.Source/GTweak/Utilities/Configuration/MonitoringProvider.cs
+++ b/.Source/GTweak/Utilities/Configuration/MonitoringProvider.cs
@@ -91,9 +91,9 @@ namespace GTweak.Utilities.Configuration
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool GetSystemTimes(out SystemTime lpIdleTime, out SystemTime lpKernelTime, out SystemTime lpUserTime);
- internal async Task<string> GetProcessCount()
+ internal Task GetProcessCount()
{
- return await Task.Run(() =>
+ return Task.Run(() =>
{
const uint initialCapacity = 1024;
uint capacity = initialCapacity;
@@ -122,18 +122,19 @@ namespace GTweak.Utilities.Configuration
if (bytesNeeded < capacity * sizeof(uint))
{
- return (bytesNeeded / sizeof(uint)).ToString();
+ RunningProcessesCount = ((int)(bytesNeeded / sizeof(uint))).ToString();
+ return;
}
capacity = bytesNeeded / sizeof(uint) + 1;
buffer = new uint[capacity];
}
- return Process.GetProcesses().Length.ToString();
- }).ConfigureAwait(false);
+ RunningProcessesCount = Process.GetProcesses().Length.ToString();
+ });
}
- internal async Task<string> GetServicesCount()
+ internal async Task GetServicesCount()
{
int running = 0;
@@ -150,7 +151,7 @@ namespace GTweak.Utilities.Configuration
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
}).ToArray()).ConfigureAwait(false);
- return running.ToString();
+ RunningServicesCount = running.ToString();
}
internal async Task GetPhysicalAvailableMemory()
diff --git a/.Source/GTweak/View/DataSystemView.xaml.cs b/.Source/GTweak/View/DataSystemView.xaml.cs
index 18243b0c..8c9ed2e4 100644
--- a/.Source/GTweak/View/DataSystemView.xaml.cs
+++ b/.Source/GTweak/View/DataSystemView.xaml.cs
@@ -67,12 +67,10 @@ namespace GTweak.View
{
await backgroundQueue.QueueTask(async () =>
{
- await _hardwareProvider.GetTotalProcessorUsage();
- await _hardwareProvider.GetPhysicalAvailableMemory();
+ await Task.WhenAll(_hardwareProvider.GetTotalProcessorUsage(), _hardwareProvider.GetPhysicalAvailableMemory(),
+ _hardwareProvider.GetProcessCount(), _hardwareProvider.GetServicesCount());
});
- HardwareData.RunningProcessesCount = await Task.Run(() => _hardwareProvider.GetProcessCount());
- HardwareData.RunningServicesCount = await Task.Run(() => _hardwareProvider.GetServicesCount());
_ = Dispatcher.BeginInvoke(new Action(() =>
{
diff --git a/.Source/GTweak/Windows/LoadingWindow.xaml.cs b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
index 46933164..dc6dd943 100644
--- a/.Source/GTweak/Windows/LoadingWindow.xaml.cs
+++ b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
@@ -54,14 +54,14 @@ namespace GTweak.Windows
ExecuteWithLogging(TrustedInstaller.StartTrustedInstallerService, nameof(TrustedInstaller.StartTrustedInstallerService));
ExecuteWithLogging(WinLicenseHandler.LicenseStatus, nameof(WinLicenseHandler.LicenseStatus));
- ExecuteWithLogging(_hardwareProvider.GetHardwareData, nameof(_hardwareProvider.GetHardwareData));
ExecuteWithLogging(_uninstallingPakages.GetInstalledPackages, nameof(_uninstallingPakages.GetInstalledPackages));
ExecuteWithLogging(UninstallingPakages.CheckingForLocalAccount, nameof(UninstallingPakages.CheckingForLocalAccount));
ExecuteWithLogging(SystemTweaks.ViewNetshState, nameof(SystemTweaks.ViewNetshState));
ExecuteWithLogging(SystemTweaks.ViewBluetoothStatus, nameof(SystemTweaks.ViewBluetoothStatus));
ExecuteWithLogging(SystemTweaks.ViewConfigTick, nameof(SystemTweaks.ViewConfigTick));
- ExecuteWithLogging(() => HardwareData.RunningProcessesCount = _hardwareProvider.GetProcessCount().GetAwaiter().GetResult(), nameof(_hardwareProvider.GetProcessCount));
- ExecuteWithLogging(() => HardwareData.RunningServicesCount = _hardwareProvider.GetServicesCount().GetAwaiter().GetResult(), nameof(_hardwareProvider.GetServicesCount));
+ ExecuteWithLogging(_hardwareProvider.GetHardwareData, nameof(_hardwareProvider.GetHardwareData));
+ ExecuteWithLogging(() => _hardwareProvider.GetProcessCount().GetAwaiter().GetResult(), nameof(_hardwareProvider.GetProcessCount));
+ ExecuteWithLogging(() => _hardwareProvider.GetServicesCount().GetAwaiter().GetResult(), nameof(_hardwareProvider.GetServicesCount));
ExecuteWithLogging(() => _hardwareProvider.ValidateVersionUpdates().GetAwaiter().GetResult(), nameof(_hardwareProvider.ValidateVersionUpdates));
ExecuteWithLogging(() => _hardwareProvider.GetTotalProcessorUsage().GetAwaiter().GetResult(), nameof(_hardwareProvider.GetTotalProcessorUsage));
ExecuteWithLogging(() => _hardwareProvider.GetPhysicalAvailableMemory().GetAwaiter().GetResult(), nameof(_hardwareProvider.GetPhysicalAvailableMemory));