Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
fix handle null values properly
Greedekse378a20bb03c
diff --git a/.Source/GTweak/Assets/UserControls/ColorWheelPicker/ColorPicker.xaml b/.Source/GTweak/Assets/UserControls/ColorWheelPicker/ColorPicker.xamlindex 88c08399..64b42758 100644--- a/.Source/GTweak/Assets/UserControls/ColorWheelPicker/ColorPicker.xaml+++ b/.Source/GTweak/Assets/UserControls/ColorWheelPicker/ColorPicker.xaml@@ -63,7 +63,7 @@<Ellipse x:Name="PART_ColorPreview" Grid.Column="0" Width="20" Height="20" Stroke="{StaticResource Brush_Separator}" StrokeThickness="2" Margin="0,0,8,0" Fill="White"/>- <TextBlock x:Name="PART_ColorTextBlock" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14px" FontFamily="{StaticResource Play}" Foreground="{StaticResource Brush_Highlighted}" Text="255 255 255" MinWidth="80"/>+ <TextBlock x:Name="PART_ColorTextBlock" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14px" FontFamily="{StaticResource Play}" Foreground="{StaticResource Brush_Highlighted}" Text="255 255 255" MinWidth="80" Typography.NumeralAlignment="Tabular" Typography.NumeralStyle="Lining"/></Grid></ToggleButton>diff --git a/.Source/GTweak/Assets/UserControls/FlowPanel.cs b/.Source/GTweak/Assets/UserControls/FlowPanel.csindex d26d3ab1..493e6d49 100644--- a/.Source/GTweak/Assets/UserControls/FlowPanel.cs+++ b/.Source/GTweak/Assets/UserControls/FlowPanel.cs@@ -89,7 +89,7 @@ namespace GTweak.Assets.UserControlsprivate readonly Dictionary<UIElement, Point> _lastPos = new Dictionary<UIElement, Point>();- private static bool Moved(Point a, Point b) => Math.Abs(a.X - b.X) > 0.5 || Math.Abs(a.Y - b.Y) > 0.5;+ private static bool Moved(Point a, Point b) => a != null && b != null && (Math.Abs(a.X - b.X) > 0.5 || Math.Abs(a.Y - b.Y) > 0.5);private double GetChildWidth(UIElement child) => EqualizeItemSize ? ItemWidth : child?.DesiredSize.Width ?? 0;@@ -114,8 +114,8 @@ namespace GTweak.Assets.UserControlsreturn new Size(0, 0);}- double aw = double.IsInfinity(availableSize.Width) ? 1200 : availableSize.Width;- double ah = availableSize.Height;+ double aw = availableSize is { Width: double w } && !double.IsInfinity(w) ? w : 1200;+ double ah = (availableSize is Size s) ? s.Height : double.PositiveInfinity;if (EqualizeItemSize){@@ -175,8 +175,11 @@ namespace GTweak.Assets.UserControlsreturn finalSize;}- List<FlowItemGroup> groups = CreateOptimalColumns(finalSize.Width, finalSize.Height, visible);- ArrangeAligned(groups, finalSize.Width);+ List<FlowItemGroup> groups = CreateOptimalColumns(finalSize.Width, finalSize.Height, visible) ?? new List<FlowItemGroup>();+ if (groups != null)+ {+ ArrangeAligned(groups, finalSize.Width);+ }return finalSize;}@@ -301,7 +304,7 @@ namespace GTweak.Assets.UserControls}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;}@@ -431,7 +434,7 @@ namespace GTweak.Assets.UserControls{try{- if (visibleChildren == null || visibleChildren?.Count == 0)+ if (visibleChildren == null || visibleChildren.Count == 0){return new List<FlowItemGroup>();}@@ -447,6 +450,7 @@ namespace GTweak.Assets.UserControls}double basisWidth;+if (EqualizeItemSize){basisWidth = Math.Max(16.0, ItemWidth);@@ -476,13 +480,15 @@ namespace GTweak.Assets.UserControlsbasisWidth = Math.Max(16.0, avg);}- int maxPossibleColumns = Math.Max(1, (int)(availableWidth / (basisWidth + HorizontalSpacing)));+ int maxPossibleColumns = Math.Max(1, (int)(availableWidth / 100));for (int columnCount = maxPossibleColumns; columnCount >= 1; columnCount--){List<FlowItemGroup> columns = TryDistributeToColumns(columnCount, availableHeight, visibleChildren);- if (columns != null && columns.Count > 0 && CalculateTotalWidth(columns) <= availableWidth)+ if (columns != null &&+ columns.Count > 0 &&+ CalculateTotalWidth(columns) <= availableWidth){return columns;}@@ -490,13 +496,22 @@ namespace GTweak.Assets.UserControlsreturn CreateSingleColumn(visibleChildren);}- catch (Exception ex) { ErrorLogging.LogDebug(ex); return new List<FlowItemGroup>(); }+ catch (Exception ex)+ {+ ErrorLogging.LogDebug(ex);+ return new List<FlowItemGroup>();+ }}private List<FlowItemGroup> CreateWrappedRows(double maxWidth, List<UIElement> visibleChildren){try{+ if (visibleChildren == null || visibleChildren.Count == 0)+ {+ return new List<FlowItemGroup>();+ }+List<FlowItemGroup> rows = new List<FlowItemGroup>();FlowItemGroup current = null;@@ -520,9 +535,9 @@ namespace GTweak.Assets.UserControlscontinue;}- 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;@@ -540,13 +555,22 @@ namespace GTweak.Assets.UserControlsreturn rows;}- catch (Exception ex) { ErrorLogging.LogDebug(ex); return new List<FlowItemGroup>(); }+ catch (Exception ex)+ {+ ErrorLogging.LogDebug(ex);+ return new List<FlowItemGroup>();+ }}private List<FlowItemGroup> CreateWrappedColumns(double maxHeight, List<UIElement> visibleChildren){try{+ if (visibleChildren == null || visibleChildren.Count == 0)+ {+ return new List<FlowItemGroup>();+ }+List<FlowItemGroup> cols = new List<FlowItemGroup>();FlowItemGroup current = null;@@ -570,9 +594,9 @@ namespace GTweak.Assets.UserControlscontinue;}- 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;@@ -590,7 +614,11 @@ namespace GTweak.Assets.UserControlsreturn cols;}- catch (Exception ex) { ErrorLogging.LogDebug(ex); return new List<FlowItemGroup>(); }+ catch (Exception ex)+ {+ ErrorLogging.LogDebug(ex);+ return new List<FlowItemGroup>();+ }}private List<FlowItemGroup> TryDistributeToColumns(int columnCount, double maxHeight, List<UIElement> visibleChildren)@@ -677,6 +705,11 @@ namespace GTweak.Assets.UserControls{try{+ if (visibleChildren == null || visibleChildren.Count == 0)+ {+ return new List<FlowItemGroup>();+ }+FlowItemGroup col = new FlowItemGroup();double totalHeight = 0;@@ -689,18 +722,23 @@ namespace GTweak.Assets.UserControlscol.Elements.Add(child);col.Width = Math.Max(col.Width, GetChildWidth(child));-totalHeight += GetChildHeight(child);- if (col.Elements?.Count > 1)++ if (col.Elements.Count > 1){totalHeight += VerticalSpacing;}}col.Height = totalHeight;+return new List<FlowItemGroup> { col };}- catch (Exception ex) { ErrorLogging.LogDebug(ex); return new List<FlowItemGroup>(); }+ catch (Exception ex)+ {+ ErrorLogging.LogDebug(ex);+ return new List<FlowItemGroup>();+ }}private double CalculateTotalWidth(List<FlowItemGroup> columns)@@ -731,20 +769,23 @@ namespace GTweak.Assets.UserControlsprotected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo){- base.OnRenderSizeChanged(sizeInfo);-- if (Math.Abs(sizeInfo.PreviousSize.Width - sizeInfo.NewSize.Width) > 0.5 ||- Math.Abs(sizeInfo.PreviousSize.Height - sizeInfo.NewSize.Height) > 0.5)+ if (sizeInfo != null){- _lastPos.Clear();- InvalidateMeasure();- InvalidateArrange();+ base.OnRenderSizeChanged(sizeInfo);++ if (Math.Abs(sizeInfo.PreviousSize.Width - sizeInfo.NewSize.Width) > 0.5 || Math.Abs(sizeInfo.PreviousSize.Height - sizeInfo.NewSize.Height) > 0.5)+ {+ _lastPos.Clear();+ InvalidateMeasure();+ InvalidateArrange();+ }}}protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved){- base.OnVisualChildrenChanged(visualAdded, visualRemoved);+ base.OnVisualChildrenChanged(visualAdded!, visualRemoved!);+_lastPos.Clear();InvalidateMeasure();InvalidateArrange();diff --git a/.Source/GTweak/Utilities/Configuration/SystemDataCollector.cs b/.Source/GTweak/Utilities/Configuration/SystemDataCollector.csindex 7550e841..ff246bd5 100644--- a/.Source/GTweak/Utilities/Configuration/SystemDataCollector.cs+++ b/.Source/GTweak/Utilities/Configuration/SystemDataCollector.cs@@ -42,10 +42,14 @@ namespace GTweak.Utilities.Configurationinternal static IPMetadata ParseData(string response){- JObject jObject = JObject.Parse(response);- string ip = (string)(jObject["ip"] ?? jObject["ipAddress"] ?? jObject["query"]);- string country = (string)(jObject["country_code"] ?? jObject["countryCode"]);- return new IPMetadata { Ip = ip, Country = country };+ if (!string.IsNullOrWhiteSpace(response))+ {+ JObject jObject = JObject.Parse(response);+ string ip = jObject["ip"]?.ToString() ?? jObject["ipAddress"]?.ToString() ?? jObject["query"]?.ToString() ?? string.Empty;+ string country = jObject["country_code"]?.ToString() ?? jObject["countryCode"]?.ToString() ?? string.Empty;+ return new IPMetadata { Ip = ip, Country = country };+ }+ return new IPMetadata { Ip = string.Empty, Country = string.Empty };}}@@ -367,7 +371,7 @@ namespace GTweak.Utilities.Configuration{string speedData = new string[] { "ConfiguredClockSpeed", "Speed" }.Select(prop => managementObj[prop]?.ToString()).FirstOrDefault(s => !string.IsNullOrEmpty(s) && s != "0");string data = new string[] { "Manufacturer", "Name", "Caption", "Description", "Tag" }.Select(prop => managementObj[prop] as string).FirstOrDefault(value => !string.IsNullOrWhiteSpace(value) && !string.Equals(value, "Unspecified", StringComparison.OrdinalIgnoreCase)) ?? string.Empty;- string memoryType = (uint)managementObj["SMBIOSMemoryType"] switch+ string memoryType = Convert.ToUInt32(managementObj["SMBIOSMemoryType"] ?? 0u) switch{2 => "DRAM",3 => "EDRAM",@@ -407,7 +411,7 @@ namespace GTweak.Utilities.Configuration};Memory.Type = memoryType;- Memory.Data += $"{string.Concat(data, ", ")}{SizeCalculationHelper((ulong)managementObj["Capacity"])}{(string.IsNullOrEmpty(speedData) ? "" : $", {speedData}MHz")}\n";+ Memory.Data += $"{string.Concat(data, ", ")}{SizeCalculationHelper(Convert.ToUInt64(managementObj["Capacity"] ?? 0UL))}{(string.IsNullOrEmpty(speedData) ? "" : $", {speedData}MHz")}\n";}}}@@ -425,7 +429,7 @@ namespace GTweak.Utilities.Configurationstatic string GetStorageType(object mediaType, string deviceId, ushort busType, string interfaceType){- string storageType = StorageTypeMappings.MediaTypeMap.Where(x => x.Keys != null && mediaType != null && x.Keys.Contains(mediaType) && x.Type != null).Select(x => x.Type).FirstOrDefault() ?? StorageTypeLabels.Unspecified;+ string storageType = StorageTypeMappings.MediaTypeMap.FirstOrDefault(x => x.Keys != null && x.Keys.Any(k => k is string ks && mediaType is string ms ? string.Equals(ks, ms, StringComparison.OrdinalIgnoreCase) : Equals(k, mediaType))).Type ?? StorageTypeLabels.Unspecified;if (isMsftAvailable){@@ -441,7 +445,7 @@ namespace GTweak.Utilities.Configurationif (storageType != StorageTypeLabels.Unspecified){- string lowLevelType = StorageTypeIdentifier.GetStorageKind(deviceId);+ string lowLevelType = StorageTypeIdentifier.GetStorageKind(deviceId ?? string.Empty) ?? string.Empty;if (!string.IsNullOrEmpty(lowLevelType) && lowLevelType != StorageTypeLabels.Unspecified){return lowLevelType;@@ -450,7 +454,7 @@ namespace GTweak.Utilities.Configurationif (storageType == StorageTypeLabels.Unspecified && !string.IsNullOrEmpty(deviceId)){- return StorageTypeIdentifier.GetStorageKind(deviceId);+ return StorageTypeIdentifier.GetStorageKind(deviceId ?? string.Empty) ?? StorageTypeLabels.Unspecified;}return storageType;@@ -468,10 +472,9 @@ namespace GTweak.Utilities.Configurationushort busType = managementObj["BusType"] is IConvertible b ? Convert.ToUInt16(b) : (ushort)0;string storageType = GetStorageType(mediaType, $@"\\.\PhysicalDrive{managementObj["DeviceId"]?.ToString() ?? "0"}", busType, default);- result.AppendLine($"{SizeCalculationHelper((ulong)managementObj["Size"])} [{data}] {storageType}");+ result.AppendLine($"{SizeCalculationHelper(Convert.ToUInt64(managementObj["Size"] ?? 0UL))} [{data}] {storageType}");}}-}else{@@ -485,7 +488,7 @@ namespace GTweak.Utilities.Configurationstring interfaceType = managementObj["InterfaceType"]?.ToString() ?? string.Empty;string storageType = GetStorageType(mediaType, managementObj["DeviceID"] as string ?? string.Empty, default, interfaceType);- result.AppendLine($"{SizeCalculationHelper((ulong)managementObj["Size"])} [{data}] {storageType}");+ result.AppendLine($"{SizeCalculationHelper(Convert.ToUInt64(managementObj["Size"] ?? 0UL))} [{data}] {storageType}");}}}@@ -554,7 +557,7 @@ namespace GTweak.Utilities.Configuration{using (managementObj){- (bool isUsbDevice, string data) = IsUsbAudioDevice(managementObj["DeviceID"].ToString());+ (bool isUsbDevice, string data) = IsUsbAudioDevice(managementObj["DeviceID"]?.ToString() ?? string.Empty);if (isUsbDevice && !string.IsNullOrEmpty(data)){@@ -565,7 +568,7 @@ namespace GTweak.Utilities.Configurationresult.AppendLine(new string[] { "Name", "Caption", "Description" }.Select(prop => managementObj[prop] as string).FirstOrDefault(info => !string.IsNullOrEmpty(info)) ?? string.Empty);}- VendorDetection.Realtek |= managementObj["PNPDeviceID"]?.ToString().IndexOf("VEN_10EC", StringComparison.OrdinalIgnoreCase) >= 0;+ VendorDetection.Realtek |= (managementObj["PNPDeviceID"]?.ToString().IndexOf("VEN_10EC", StringComparison.OrdinalIgnoreCase) ?? -1) >= 0;}}}@@ -599,7 +602,7 @@ namespace GTweak.Utilities.Configuration{using (managementObj){- result.AppendLine(new string[] { "Name", "Description", "ProductName", "Manufacturer" }.Select(prop => managementObj[prop] as string).FirstOrDefault(info => !string.IsNullOrEmpty(info)) ?? string.Empty);+ result.AppendLine(new string[] { "Name", "Description", "ProductName", "Manufacturer" }.Select(prop => managementObj[prop]?.ToString()).FirstOrDefault(info => !string.IsNullOrEmpty(info)) ?? string.Empty); ;}}}