Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
ref & fix handle null values properly
Greedeks26dbd0185861
diff --git a/.Source/GTweak/Assets/UserControl/Card.xaml.cs b/.Source/GTweak/Assets/UserControl/Card.xaml.csindex a3178632..668c2373 100644--- a/.Source/GTweak/Assets/UserControl/Card.xaml.cs+++ b/.Source/GTweak/Assets/UserControl/Card.xaml.cs@@ -45,7 +45,7 @@ namespace GTweak.Assets.UserControl{if (d is Card card && card.CardIcon != null){- if (e.NewValue is Style style)+ if (e.NewValue is Style style && style != null){card.CardIcon.Style = style;}diff --git a/.Source/GTweak/Assets/UserControl/FlowPanel.cs b/.Source/GTweak/Assets/UserControl/FlowPanel.csindex 33ac867d..0981e63b 100644--- a/.Source/GTweak/Assets/UserControl/FlowPanel.cs+++ b/.Source/GTweak/Assets/UserControl/FlowPanel.cs@@ -97,16 +97,16 @@ namespace GTweak.Assets.UserControlprotected override Size MeasureOverride(Size availableSize){List<UIElement> visible = new List<UIElement>(InternalChildren.Count);- for (int i = 0; i < InternalChildren.Count; i++)+ for (int i = 0; i < InternalChildren?.Count; i++){- UIElement c = InternalChildren[i];- if (c != null && c.Visibility != Visibility.Collapsed)+ UIElement child = InternalChildren[i];+ if (child != null && child.Visibility != Visibility.Collapsed){- visible.Add(c);+ visible.Add(child);}}- if (visible.Count == 0)+ if (visible?.Count == 0){return new Size(0, 0);}@@ -139,12 +139,12 @@ namespace GTweak.Assets.UserControlprotected override Size ArrangeOverride(Size finalSize){List<UIElement> visible = new List<UIElement>(InternalChildren.Count);- for (int i = 0; i < InternalChildren.Count; i++)+ for (int i = 0; i < InternalChildren?.Count; i++){- UIElement c = InternalChildren[i];- if (c != null && c.Visibility != Visibility.Collapsed)+ UIElement child = InternalChildren[i];+ if (child != null && child.Visibility != Visibility.Collapsed){- visible.Add(c);+ visible.Add(child);}}@@ -161,7 +161,7 @@ namespace GTweak.Assets.UserControlprivate void ArrangeAligned(List<FlowItemGroup> groups, double availableWidth){- if (groups == null || groups.Count == 0)+ if (groups == null || groups?.Count == 0){return;}@@ -170,7 +170,7 @@ namespace GTweak.Assets.UserControl{double y = 0;- for (int i = 0; i < groups.Count; i++)+ for (int i = 0; i < groups?.Count; i++){FlowItemGroup row = groups[i];if (row.Elements.Count == 0)@@ -189,7 +189,7 @@ namespace GTweak.Assets.UserControldouble x = xStart;- foreach (UIElement child in row.Elements)+ foreach (UIElement child in row?.Elements){double w = GetChildWidth(child);double h = GetChildHeight(child);@@ -221,7 +221,7 @@ namespace GTweak.Assets.UserControl}double contentWidth = 0;- for (int i = 0; i < groups.Count; i++)+ for (int i = 0; i < groups?.Count; i++){contentWidth += groups[i].Width;if (i > 0)@@ -240,7 +240,7 @@ namespace GTweak.Assets.UserControldouble xV = xStartV;- for (int i = 0; i < groups.Count; i++)+ for (int i = 0; i < groups?.Count; i++){FlowItemGroup col = groups[i];if (col.Elements.Count == 0)@@ -250,7 +250,7 @@ namespace GTweak.Assets.UserControl}double shift = 0;- if (Orientation == FlowOrientation.Unset && groups.Count > 1 && i > 0)+ if (Orientation == FlowOrientation.Unset && groups?.Count > 1 && i > 0){shift = extraSpaceV * (i / (double)(groups.Count - 1)) * 0.3;}@@ -258,7 +258,7 @@ namespace GTweak.Assets.UserControldouble columnX = xV + shift;double y = 0;- foreach (UIElement child in col.Elements)+ foreach (UIElement child in col?.Elements){double w = GetChildWidth(child);double h = GetChildHeight(child);@@ -294,7 +294,7 @@ namespace GTweak.Assets.UserControlif (Orientation == FlowOrientation.Horizontal){double total = 0;- for (int i = 0; i < groups.Count; i++)+ for (int i = 0; i < groups?.Count; i++){total += groups[i].Height;if (i > 0)@@ -310,21 +310,21 @@ namespace GTweak.Assets.UserControlprivate double CalculateMaxColumnHeight(List<FlowItemGroup> columns){- if (columns == null || columns.Count == 0)+ if (columns == null || columns?.Count == 0){return 0;}double max = 0;- for (int i = 0; i < columns.Count; i++)+ for (int i = 0; i < columns?.Count; i++){FlowItemGroup col = columns[i];double h = 0;- for (int j = 0; j < col.Elements.Count; j++)+ for (int j = 0; j < col?.Elements.Count; j++){- UIElement child = col.Elements[j];+ UIElement child = col?.Elements[j];h += GetChildHeight(child);if (j > 0){@@ -343,7 +343,7 @@ namespace GTweak.Assets.UserControlprivate List<FlowItemGroup> CreateOptimalColumns(double availableWidth, double availableHeight, List<UIElement> visibleChildren){- if (visibleChildren == null || visibleChildren.Count == 0)+ if (visibleChildren == null || visibleChildren?.Count == 0){return new List<FlowItemGroup>();}@@ -392,9 +392,9 @@ namespace GTweak.Assets.UserControlcontinue;}- double widthIfAdded = current.Width + (current.Width > 0 ? HorizontalSpacing : 0) + childWidth;+ double widthIfAdded = current.Width + (current?.Width > 0 ? HorizontalSpacing : 0) + childWidth;- if (widthIfAdded <= maxWidth || current.Elements.Count == 0)+ if (widthIfAdded <= maxWidth || current?.Elements.Count == 0){current.Elements.Add(child);current.Width = widthIfAdded;@@ -433,9 +433,9 @@ namespace GTweak.Assets.UserControlcontinue;}- double heightIfAdded = current.Height + (current.Height > 0 ? VerticalSpacing : 0) + childHeight;+ double heightIfAdded = current.Height + (current?.Height > 0 ? VerticalSpacing : 0) + childHeight;- if (heightIfAdded <= maxHeight || current.Elements.Count == 0)+ if (heightIfAdded <= maxHeight || current.Elements?.Count == 0){current.Elements.Add(child);current.Height = heightIfAdded;@@ -464,7 +464,7 @@ namespace GTweak.Assets.UserControlif (UseMasonryLayout){- var heights = new double[columnCount];+ double[] heights = new double[columnCount];foreach (UIElement child in visibleChildren){@@ -535,7 +535,7 @@ namespace GTweak.Assets.UserControlcol.Width = Math.Max(col.Width, GetChildWidth(child));totalHeight += GetChildHeight(child);- if (col.Elements.Count > 1)+ if (col.Elements?.Count > 1){totalHeight += VerticalSpacing;}@@ -547,13 +547,13 @@ namespace GTweak.Assets.UserControlprivate double CalculateTotalWidth(List<FlowItemGroup> columns){- if (columns == null || columns.Count == 0)+ if (columns == null || columns?.Count == 0){return 0;}double total = 0;- for (int i = 0; i < columns.Count; i++)+ for (int i = 0; i < columns?.Count; i++){total += columns[i].Width;if (i > 0)diff --git a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.csindex 2f1afc06..f32b4d6a 100644--- a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs+++ b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs@@ -113,8 +113,8 @@ namespace GTweak.Utilities.Configurationtry{using var managementObj = new ManagementObjectSearcher(@"root\microsoft\windows\storage", "select FriendlyName from MSFT_PhysicalDisk", new EnumerationOptions { ReturnImmediately = true });- var results = managementObj.Get();- isMsftAvailable = results != null && results.Count > 0;+ var results = managementObj?.Get();+ isMsftAvailable = results?.Count > 0;}catch { isMsftAvailable = false; }});diff --git a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs b/.Source/GTweak/Utilities/Helpers/CommandExecutor.csindex bebaa188..2fae81ff 100644--- a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs+++ b/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs@@ -1,4 +1,5 @@using System;+using System.Collections.Generic;using System.Diagnostics;using System.Linq;using System.Text;@@ -154,7 +155,7 @@ namespace GTweak.Utilities.Helpersreturn string.Empty;}- var lines = rawCommand.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(line => line.Trim()).Where(line => !string.IsNullOrEmpty(line)).Select(line => Regex.Replace(line, @"\s+", " ")).ToList();+ var lines = string.IsNullOrEmpty(rawCommand) ? new List<string>() : rawCommand.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(line => line.Trim()).Where(line => !string.IsNullOrEmpty(line)).Select(line => Regex.Replace(line, @"\s+", " ")).ToList();if (lines.Count == 0){diff --git a/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.cs b/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.csindex fa5b10a2..a614bf76 100644--- a/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.cs+++ b/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.cs@@ -112,7 +112,7 @@ namespace GTweak.Utilities.Helpers{try{- files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories);+ files = string.IsNullOrEmpty(directoryPath) ? new string[0] : Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories);if (files == null || files.Length == 0){diff --git a/.Source/GTweak/Utilities/Managers/ArchiveManager.cs b/.Source/GTweak/Utilities/Managers/ArchiveManager.csindex 3d6ab0af..848bf320 100644--- a/.Source/GTweak/Utilities/Managers/ArchiveManager.cs+++ b/.Source/GTweak/Utilities/Managers/ArchiveManager.cs@@ -1,4 +1,3 @@-using System;using System.IO;using System.IO.Compression;@@ -8,7 +7,7 @@ namespace GTweak.Utilities.Managers{internal static void Unarchive(string path, byte[] resource){- string folderDir = path.Remove(path.LastIndexOf(@"\", StringComparison.OrdinalIgnoreCase));+ string folderDir = Path.GetDirectoryName(path);if (!Directory.Exists(folderDir)){diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.csindex 80aff0fe..9425dc65 100644--- a/.Source/GTweak/Windows/MainWindow.xaml.cs+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs@@ -9,6 +9,7 @@ using System.Windows.Threading;using GTweak.Utilities.Animation;using GTweak.Utilities.Configuration;using GTweak.Utilities.Controls;+using GTweak.Utilities.Managers;using Wpf.Ui.Controls;namespace GTweak.Windows@@ -24,6 +25,9 @@ namespace GTweak.Windows{InitializeComponent();App.TweaksImported += delegate { BtnUtils.IsChecked = true; };++ ArchiveManager.Unarchive(PathLocator.Executable.NSudo, Properties.Resources.NSudoLC);+ ArchiveManager.Unarchive(PathLocator.Executable.DisablingWD, Properties.Resources.DisablingWD);}private void AnimateSettings()diff --git a/.Source/GTweak/Windows/OverlayWindow.xaml.cs b/.Source/GTweak/Windows/OverlayWindow.xaml.csindex a9c367fc..6aa67ef4 100644--- a/.Source/GTweak/Windows/OverlayWindow.xaml.cs+++ b/.Source/GTweak/Windows/OverlayWindow.xaml.cs@@ -23,7 +23,7 @@ namespace GTweak.Windowsif (e != null){Closing -= Window_Closing;- e.Cancel = true;+ e!.Cancel = true;BeginAnimation(OpacityProperty, FactoryAnimation.CreateTo(0.15, () =>{ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;