Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
ref optimize control states via lazy caching and remove LINQ & anim page
Greedeks21847a93ba72
diff --git a/.Source/GTweak/Core/Base/ViewModelPageBase.cs b/.Source/GTweak/Core/Base/ViewModelPageBase.csindex dcd0e8b2..db6d25e9 100644--- a/.Source/GTweak/Core/Base/ViewModelPageBase.cs+++ b/.Source/GTweak/Core/Base/ViewModelPageBase.cs@@ -1,6 +1,5 @@using System.Collections.Generic;using System.Collections.ObjectModel;-using System.Linq;namespace GTweak.Core.Base{@@ -19,19 +18,59 @@ namespace GTweak.Core.Basewhere TModel : IBasePageItem, new()where TTweaksClass : new(){- public ObservableCollection<TModel> Toggles { get; private set; }+ private ObservableCollection<TModel> _toggles;- public TModel this[string name] => Toggles.FirstOrDefault(d => d.Name == name);protected abstract IReadOnlyDictionary<string, object> GetControlStates();protected abstract void Analyze(TTweaksClass tweaks);- protected ViewModelPageBase()+ public TModel this[string name]+ {+ get+ {+ foreach (TModel toggle in Toggles)+ {+ if (toggle.Name == name)+ {+ return toggle;+ }+ }+ return default;+ }+ }++ public ObservableCollection<TModel> Toggles+ {+ get+ {+ if (_toggles == null)+ {+ InitializeData();+ }+ return _toggles;+ }+ set+ {+ _toggles = value;+ OnPropertyChanged(nameof(Toggles));+ }+ }++ protected ViewModelPageBase() { }++ private void InitializeData(){TTweaksClass tweaks = new TTweaksClass();Analyze(tweaks);- Toggles = new ObservableCollection<TModel>(GetControlStates().Select(kvp => CreateModelFromState(kvp.Key, kvp.Value)));- OnPropertyChanged(nameof(Toggles));+ IReadOnlyDictionary<string, object> states = GetControlStates();+ List<TModel> modelsList = new List<TModel>(states.Count);++ foreach (var kvp in states)+ {+ modelsList.Add(CreateModelFromState(kvp.Key, kvp.Value));+ }++ _toggles = new ObservableCollection<TModel>(modelsList);}private TModel CreateModelFromState(string name, object parameter)diff --git a/.Source/GTweak/Styles/Page.xaml b/.Source/GTweak/Styles/Page.xamlindex 9d06c1b5..6b945c7a 100644--- a/.Source/GTweak/Styles/Page.xaml+++ b/.Source/GTweak/Styles/Page.xaml@@ -1,4 +1,4 @@-<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"+<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Style x:Key="LaunchPage" TargetType="{x:Type UserControl}">@@ -15,9 +15,9 @@<EventTrigger RoutedEvent="Loaded"><BeginStoryboard><Storyboard Timeline.DesiredFrameRate="120">- <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0.45" From="0" To="1" >+ <DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0.2" From="0" To="1" ><DoubleAnimation.EasingFunction>- <QuadraticEase/>+ <CircleEase EasingMode="EaseOut"/></DoubleAnimation.EasingFunction></DoubleAnimation></Storyboard>diff --git a/.Source/GTweak/Utilities/Managers/ControlWriterManager.cs b/.Source/GTweak/Utilities/Managers/ControlWriterManager.csindex af4e36a1..1faeceee 100644--- a/.Source/GTweak/Utilities/Managers/ControlWriterManager.cs+++ b/.Source/GTweak/Utilities/Managers/ControlWriterManager.cs@@ -1,4 +1,5 @@-using System.Collections.Generic;+using System.Collections.Concurrent;+using System.Collections.Generic;namespace GTweak.Utilities.Managers{@@ -6,42 +7,55 @@ namespace GTweak.Utilities.Managers{private readonly Dictionary<string, object> _controlStates;+ internal ButtonCollection Button { get; }+ internal SliderCollection Slider { get; }+internal ControlWriterManager(Dictionary<string, object> controlStates){- _controlStates = controlStates;+ _controlStates = controlStates ?? new Dictionary<string, object>();+ Button = new ButtonCollection(_controlStates);+ Slider = new SliderCollection(_controlStates);}- internal ButtonCollection Button => new ButtonCollection(_controlStates);-- internal SliderCollection Slider => new SliderCollection(_controlStates);-internal class ButtonCollection{private readonly Dictionary<string, object> _controlStates;+ private static readonly ConcurrentDictionary<int, string> KeyCache = new ConcurrentDictionary<int, string>();- internal ButtonCollection(Dictionary<string, object> controlStates)- {- _controlStates = controlStates;- }+ internal ButtonCollection(Dictionary<string, object> controlStates) => _controlStates = controlStates;internal bool this[int index]{- set => _controlStates[$"TglButton{index}"] = value;+ set+ {+ string key = KeyCache.GetOrAdd(index, i => $"TglButton{i}");++ if (_controlStates != null)+ {+ _controlStates[key] = value;+ }+ }}}internal class SliderCollection{private readonly Dictionary<string, object> _controlStates;+ private static readonly ConcurrentDictionary<int, string> KeyCache = new ConcurrentDictionary<int, string>();- internal SliderCollection(Dictionary<string, object> controlStates)- {- _controlStates = controlStates;- }+ internal SliderCollection(Dictionary<string, object> controlStates) => _controlStates = controlStates;internal object this[int index]{- set => _controlStates[$"Slider{index}"] = value;+ set+ {+ string key = KeyCache.GetOrAdd(index, i => $"Slider{i}");++ if (_controlStates != null)+ {+ _controlStates[key] = value;+ }+ }}}}diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.csindex b5e8ff61..52284d6b 100644--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs@@ -112,7 +112,7 @@ namespace GTweak.Utilities.Tweaks_сontrolWriter.Button[9] =RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power", "HiberbootEnabled", "0") ||- RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power", "HibernateEnabled", "0") ||+ RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power", "HibernateEnabled", "0") ||RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FlyoutMenuSettings", "ShowHibernateOption", "0");_сontrolWriter.Button[10] =