Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
fix prevent timer auto-start on instantiation & ref task checking/INI reading reliability
Greedeksc245b12278df
diff --git a/.Source/GTweak/Utilities/Managers/INIManager.cs b/.Source/GTweak/Utilities/Managers/INIManager.csindex d9e7249b..ec1a673b 100644--- a/.Source/GTweak/Utilities/Managers/INIManager.cs+++ b/.Source/GTweak/Utilities/Managers/INIManager.cs@@ -18,6 +18,7 @@ namespace GTweak.Utilities.Managersprivate static extern int GetPrivateProfileSection(string section, StringBuilder retVal, int size, string filePath);private readonly string _pathToConfig;+ private const int MaxBuffer = 4096;internal static Dictionary<string, string>TempTweaksConf = new Dictionary<string, string>(),@@ -36,8 +37,8 @@ namespace GTweak.Utilities.Managersinternal string Read(string section, string key){- StringBuilder retValue = new StringBuilder(255);- GetPrivateProfileString(section, key, "", retValue, 255, _pathToConfig);+ StringBuilder retValue = new StringBuilder(MaxBuffer);+ GetPrivateProfileString(section, key, "", retValue, MaxBuffer, _pathToConfig);return retValue.ToString();}@@ -45,37 +46,33 @@ namespace GTweak.Utilities.Managersinternal void WriteAll(string section, Dictionary<string, string> selectedDictionary){- if (selectedDictionary?.Count == 0)+ if ((selectedDictionary?.Count) != 0){- return;- }-- foreach (KeyValuePair<string, string> addKeyValue in selectedDictionary)- {- WritePrivateProfileString(section, addKeyValue.Key, addKeyValue.Value, _pathToConfig);+ foreach (KeyValuePair<string, string> addKeyValue in selectedDictionary)+ {+ WritePrivateProfileString(section, addKeyValue.Key, addKeyValue.Value, _pathToConfig);+ }}}internal static void TempWrite<T>(Dictionary<string, string> selectedDictionary, string tweak, T value){- if (selectedDictionary?.ContainsKey(tweak) == true)+ if (selectedDictionary != null){- selectedDictionary.Remove(tweak);+ selectedDictionary[tweak] = value?.ToString();}-- selectedDictionary.Add(tweak, value.ToString());}internal bool IsThereSection(string section){- StringBuilder retValue = new StringBuilder(255);- GetPrivateProfileSection(section, retValue, 255, _pathToConfig);+ StringBuilder retValue = new StringBuilder(MaxBuffer);+ GetPrivateProfileSection(section, retValue, MaxBuffer, _pathToConfig);return !string.IsNullOrEmpty(retValue.ToString());}internal List<string> GetKeysOrValue(string section, bool isGetKey = true){- var result = new List<string>();+ List<string> result = new List<string>();string[] lines = File.ReadAllLines(_pathToConfig);bool inSection = false;diff --git a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.csindex 4a902c7b..14d8a3cc 100644--- a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs+++ b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs@@ -16,24 +16,15 @@ namespace GTweak.Utilities.Managers{if (tasklist != null && tasklist.Length != 0){- bool isEnabledFound = false;-- Parallel.ForEach(tasklist, () => new Microsoft.Win32.TaskScheduler.TaskService(),+ ParallelLoopResult result = Parallel.ForEach(tasklist, () => new Microsoft.Win32.TaskScheduler.TaskService(),(taskName, loopState, taskScheduler) =>{try{- if (isEnabledFound)- {- loopState.Stop();- return taskScheduler;- }-Microsoft.Win32.TaskScheduler.Task scheduledTask = taskScheduler.GetTask(taskName);if (scheduledTask != null && scheduledTask.Enabled){- isEnabledFound = true;loopState.Stop();}}@@ -46,8 +37,7 @@ namespace GTweak.Utilities.Managerstry { taskScheduler.Dispose(); }catch (Exception ex) { ErrorLogging.LogDebug(ex); }});-- return isEnabledFound;+ return !result.IsCompleted;}return false;diff --git a/.Source/GTweak/Utilities/Managers/TimerControlManager.cs b/.Source/GTweak/Utilities/Managers/TimerControlManager.csindex c88299ee..5b3f3bd0 100644--- a/.Source/GTweak/Utilities/Managers/TimerControlManager.cs+++ b/.Source/GTweak/Utilities/Managers/TimerControlManager.cs@@ -21,7 +21,12 @@ namespace GTweak.Utilities.Managers_action = action;_onFinished = onFinished;- _timer = new DispatcherTimer(interval ?? TimeSpan.FromSeconds(1), DispatcherPriority.Normal, TimerTick, Application.Current.Dispatcher);+ _timer = new DispatcherTimer(DispatcherPriority.Normal, Application.Current.Dispatcher)+ {+ Interval = interval ?? TimeSpan.FromSeconds(1)+ };++ _timer.Tick += TimerTick;}private void TimerTick(object sender, EventArgs e)