Skip to content

Portable Tool for an Ideal Windows Setup

fix handle null values properly

Greedeks7f52539a10b9
diff --git a/.Source/GTweak/App.xaml.cs b/.Source/GTweak/App.xaml.cs
index 065ec7dd..99e11e56 100644
--- a/.Source/GTweak/App.xaml.cs
+++ b/.Source/GTweak/App.xaml.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Threading;
@@ -32,7 +33,7 @@ namespace GTweak
private async void App_Startup(object sender, StartupEventArgs e)
{
- if (e.Args != null && e.Args.Any(arg => arg.Equals("uninstall", StringComparison.OrdinalIgnoreCase)))
+ if (e.Args != null && e.Args.Any(arg => string.Equals(arg, "uninstall", StringComparison.OrdinalIgnoreCase)))
{
SettingsEngine.SelfRemoval();
return;
@@ -52,13 +53,13 @@ namespace GTweak
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
ErrorLogging.LogWritingFile(e.Exception);
- e.Handled = true;
+ e!.Handled = true;
Environment.Exit(0);
}
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
- if (e.ExceptionObject is Exception ex)
+ if (e?.ExceptionObject is Exception ex)
{
ErrorLogging.LogWritingFile(ex);
}
@@ -112,7 +113,7 @@ namespace GTweak
ResourceDictionary dictionary = new ResourceDictionary
{
- Source = GetResourceUri(char.ToUpper(value[0]) + value.Substring(1).ToLower(), true)
+ Source = GetResourceUri(char.ToUpper(value[0], CultureInfo.InvariantCulture) + value.Substring(1).ToLower(CultureInfo.InvariantCulture), true)
};
foreach (ResourceDictionary oldDictionary in Current.Resources.MergedDictionaries.Where(d => d.Source != null && d.Source.OriginalString.StartsWith("Styles/Themes/")).ToList())
diff --git a/.Source/GTweak/Assets/UserControl/Card.xaml.cs b/.Source/GTweak/Assets/UserControl/Card.xaml.cs
index 205244ca..a3178632 100644
--- a/.Source/GTweak/Assets/UserControl/Card.xaml.cs
+++ b/.Source/GTweak/Assets/UserControl/Card.xaml.cs
@@ -45,7 +45,10 @@ namespace GTweak.Assets.UserControl
{
if (d is Card card && card.CardIcon != null)
{
- card.CardIcon.Style = e.NewValue as Style;
+ if (e.NewValue is Style style)
+ {
+ card.CardIcon.Style = style;
+ }
}
}
diff --git a/.Source/GTweak/Assets/UserControl/FlowColumnPanel.cs b/.Source/GTweak/Assets/UserControl/FlowColumnPanel.cs
index b3b6c210..53fb79dd 100644
--- a/.Source/GTweak/Assets/UserControl/FlowColumnPanel.cs
+++ b/.Source/GTweak/Assets/UserControl/FlowColumnPanel.cs
@@ -83,7 +83,7 @@ namespace GTweak.Assets.UserControl
.Where(c => c != null && c.Visibility != Visibility.Collapsed)
.ToList();
- if (visibleChildren.Count == 0)
+ if (visibleChildren?.Count == 0)
{
return new Size(0, 0);
}
@@ -96,7 +96,7 @@ namespace GTweak.Assets.UserControl
private void ArrangeAligned(List<ColumnInfo> columns, double availableWidth)
{
- if (columns == null || columns.Count == 0)
+ if (columns?.Count == 0)
{
return;
}
@@ -112,10 +112,10 @@ namespace GTweak.Assets.UserControl
double x = xStart;
- for (int i = 0; i < columns.Count; i++)
+ for (int i = 0; i < columns?.Count; i++)
{
var column = columns[i];
- if (column?.Elements == null || column.Elements.Count == 0)
+ if (column?.Elements == null || column?.Elements.Count == 0)
{
x += column?.Width ?? 0.0;
x += HorizontalSpacing;
@@ -126,7 +126,7 @@ namespace GTweak.Assets.UserControl
double columnX = x + shift;
double y = 0;
- foreach (var child in column.Elements)
+ foreach (var child in column?.Elements)
{
if (child.Visibility == Visibility.Collapsed)
{
@@ -160,15 +160,20 @@ namespace GTweak.Assets.UserControl
private double CalculateMaxColumnHeight(List<ColumnInfo> columns)
{
- if (columns == null || columns.Count == 0)
+ if (columns?.Count == 0)
{
return 0;
}
return columns.Max(column =>
{
+ if (column?.Elements == null)
+ {
+ return 0;
+ }
+
double h = 0;
- foreach (var child in column.Elements)
+ foreach (var child in column?.Elements)
{
if (child.Visibility == Visibility.Collapsed)
{
@@ -183,7 +188,7 @@ namespace GTweak.Assets.UserControl
private List<ColumnInfo> CreateOptimalColumns(double availableWidth, double availableHeight, List<UIElement> visibleChildren)
{
- if (visibleChildren == null || visibleChildren.Count == 0)
+ if (visibleChildren?.Count == 0)
{
return new List<ColumnInfo>();
}
diff --git a/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs b/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs
index 5584f01d..817ed790 100644
--- a/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs
+++ b/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs
@@ -138,7 +138,7 @@ namespace GTweak.Assets.UserControl
private void ToggleButton_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
- if ((bool)e.NewValue == false)
+ if (e.NewValue is bool newBool && !newBool)
{
Back.Opacity = 0.7;
Dot.Opacity = 0.7;
diff --git a/.Source/GTweak/Core/ViewModel/PakagesViewModel.cs b/.Source/GTweak/Core/ViewModel/PakagesViewModel.cs
index 0baad48a..240f8da9 100644
--- a/.Source/GTweak/Core/ViewModel/PakagesViewModel.cs
+++ b/.Source/GTweak/Core/ViewModel/PakagesViewModel.cs
@@ -60,7 +60,7 @@ namespace GTweak.Core.ViewModel
private void UpdatePackageState(PakagesModel item)
{
- if (UninstallingPakages.PackagesDetails.TryGetValue(item.Name, out var val))
+ if (UninstallingPakages.PackagesDetails?.TryGetValue(item?.Name ?? default, out var val) == true)
{
item.IsUnavailable = !val.IsUnavailable;
diff --git a/.Source/GTweak/Utilities/Animation/NumberAnimation.cs b/.Source/GTweak/Utilities/Animation/NumberAnimation.cs
index 83aa0be2..2a842569 100644
--- a/.Source/GTweak/Utilities/Animation/NumberAnimation.cs
+++ b/.Source/GTweak/Utilities/Animation/NumberAnimation.cs
@@ -13,7 +13,7 @@ namespace GTweak.Utilities.Animation
internal static void SetValue(DependencyObject dObject, int value) => dObject.SetValue(ValueProperty, value);
- internal static int GetValue(DependencyObject dObject) => (int)dObject.GetValue(ValueProperty);
+ internal static int GetValue(DependencyObject dObject) => dObject.GetValue(ValueProperty) as int? ?? 0;
private static void SetAnimatedValue(DependencyObject dObject, int value) => dObject.SetValue(AnimatedValueProperty, value);
@@ -21,7 +21,7 @@ namespace GTweak.Utilities.Animation
{
if (dObject is TextBlock textBlock)
{
- int newValue = (int)e.NewValue;
+ int newValue = e.NewValue as int? ?? 0;
if (!textBlock.IsLoaded)
{
@@ -29,7 +29,7 @@ namespace GTweak.Utilities.Animation
return;
}
- int oldValue = (int)e.OldValue;
+ int oldValue = (e.OldValue as int?) ?? 0;
Int32Animation int32Anim = new Int32Animation
{
diff --git a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs
index 0ef30ddd..ea7e555d 100644
--- a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs
+++ b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs
@@ -150,7 +150,7 @@ namespace GTweak.Utilities.Configuration
Parallel.Invoke(() => netAdapter = GetNetworkAdapters());
NetworkAdapter = netAdapter;
break;
- case DeviceType.All:
+ default:
Parallel.Invoke
(
() => storage = GetStorageDevices(),
diff --git a/.Source/GTweak/Utilities/Controls/ErrorLogging.cs b/.Source/GTweak/Utilities/Controls/ErrorLogging.cs
index f5b646c1..bdfbd9bb 100644
--- a/.Source/GTweak/Utilities/Controls/ErrorLogging.cs
+++ b/.Source/GTweak/Utilities/Controls/ErrorLogging.cs
@@ -77,7 +77,7 @@ namespace GTweak.Utilities.Controls
if (parameters.Length > 0)
{
await writer.WriteLineAsync($"Parameters:");
- foreach (var param in parameters)
+ foreach (ParameterInfo param in parameters)
{
await writer.WriteLineAsync($"{param.Name}: {param.ParameterType}");
}
diff --git a/.Source/GTweak/Utilities/Helpers/RegistryHelp.cs b/.Source/GTweak/Utilities/Helpers/RegistryHelp.cs
index 9efed2a9..3cedb1e7 100644
--- a/.Source/GTweak/Utilities/Helpers/RegistryHelp.cs
+++ b/.Source/GTweak/Utilities/Helpers/RegistryHelp.cs
@@ -121,7 +121,7 @@ namespace GTweak.Utilities.Helpers
return true;
}
- return string.Concat((byte[])Registry.GetValue(subkey, valueName, null) ?? Array.Empty<byte>()) != expectedValue;
+ return string.Concat(Registry.GetValue(subkey, valueName, null) as byte[] ?? Array.Empty<byte>()) != expectedValue;
}
internal static T GetValue<T>(in string subKey, in string valueName, in T defaultValue)
diff --git a/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.cs b/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.cs
index 48bd3c2d..88dff8f4 100644
--- a/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.cs
+++ b/.Source/GTweak/Utilities/Helpers/UnlockHandleHelper.cs
@@ -69,7 +69,7 @@ namespace GTweak.Utilities.Helpers
return;
}
- HashSet<int> pids = GetUnlockProcessIds(directoryPath);
+ HashSet<int> pids = GetUnlockProcessIds(directoryPath) ?? new HashSet<int>();
foreach (int pid in pids)
{
diff --git a/.Source/GTweak/Utilities/Managers/INIManager.cs b/.Source/GTweak/Utilities/Managers/INIManager.cs
index 9b501be6..491b7ba4 100644
--- a/.Source/GTweak/Utilities/Managers/INIManager.cs
+++ b/.Source/GTweak/Utilities/Managers/INIManager.cs
@@ -17,7 +17,6 @@ namespace GTweak.Utilities.Managers
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int GetPrivateProfileSection(string section, StringBuilder retVal, int size, string filePath);
-
private readonly string _pathToConfig;
internal static Dictionary<string, string>
@@ -46,7 +45,7 @@ namespace GTweak.Utilities.Managers
internal void WriteAll(string section, Dictionary<string, string> selectedDictionary)
{
- if (selectedDictionary.Count == 0)
+ if (selectedDictionary?.Count == 0)
{
return;
}
@@ -59,7 +58,7 @@ namespace GTweak.Utilities.Managers
internal static void TempWrite<T>(Dictionary<string, string> selectedDictionary, string tweak, T value)
{
- if (selectedDictionary.ContainsKey(tweak))
+ if (selectedDictionary?.ContainsKey(tweak) == true)
{
selectedDictionary.Remove(tweak);
}
diff --git a/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs b/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs
index c44bdf33..d9ea8cbf 100644
--- a/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs
@@ -393,6 +393,8 @@ namespace GTweak.Utilities.Tweaks
RegistryHelp.DeleteValue(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Personalization", "NoLockScreenCamera");
}
break;
+ default:
+ break;
}
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/DefenderManager/AclPermissionsBackup.cs b/.Source/GTweak/Utilities/Tweaks/DefenderManager/AclPermissionsBackup.cs
index 9c96074c..becd2cac 100644
--- a/.Source/GTweak/Utilities/Tweaks/DefenderManager/AclPermissionsBackup.cs
+++ b/.Source/GTweak/Utilities/Tweaks/DefenderManager/AclPermissionsBackup.cs
@@ -275,20 +275,20 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
switch (kind)
{
case RegistryValueKind.Binary:
- string b64 = token.Type == JTokenType.String ? token.ToObject<string>() : token.ToString(Formatting.None);
+ string b64 = token.Type == JTokenType.String ? token.ToObject<string>() ?? string.Empty : token.ToString(Formatting.None);
return Convert.FromBase64String(b64);
case RegistryValueKind.DWord:
- return token.ToObject<int>();
+ return token.ToObject<int?>() ?? 0;
case RegistryValueKind.QWord:
- return token.ToObject<long>();
+ return token.ToObject<long?>() ?? 0L;
case RegistryValueKind.MultiString:
- return token.ToObject<string[]>();
+ return token.ToObject<string[]>() ?? Array.Empty<string>();
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
- return token.ToObject<string>();
+ return token.ToObject<string>() ?? string.Empty;
case RegistryValueKind.None:
default:
- return token.ToObject<object>();
+ return token.ToObject<object>() ?? new object();
}
}
@@ -297,40 +297,36 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
case RegistryValueKind.Binary:
if (rawValue is string s)
{
- return Convert.FromBase64String(s);
+ return Convert.FromBase64String(s ?? string.Empty);
}
if (rawValue is byte[] bytes)
{
return bytes;
}
-
- break;
+ return Array.Empty<byte>();
case RegistryValueKind.DWord:
- return Convert.ToInt32(rawValue);
+ return rawValue as int? ?? 0;
case RegistryValueKind.QWord:
- return Convert.ToInt64(rawValue);
+ return rawValue as long? ?? 0L;
case RegistryValueKind.MultiString:
- if (rawValue is JArray jarr)
- {
- return jarr.ToObject<string[]>();
- }
-
if (rawValue is string[] sa)
{
return sa;
}
- break;
+ if (rawValue is JArray jarr)
+ {
+ return jarr.ToObject<string[]>() ?? Array.Empty<string>();
+ }
+ return Array.Empty<string>();
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
- return rawValue?.ToString();
+ return rawValue?.ToString() ?? string.Empty;
case RegistryValueKind.None:
default:
- return rawValue;
+ return rawValue ?? new object();
}
-
- return rawValue;
}
private static object ConvertJTokenToObject(object tokenOrObj)
diff --git a/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs b/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs
index ead9d3a6..3cbdcec9 100644
--- a/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs
@@ -574,6 +574,8 @@ namespace GTweak.Utilities.Tweaks
}
}
break;
+ default:
+ break;
}
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs b/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
index f806f7e9..73fcd589 100644
--- a/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
@@ -435,6 +435,8 @@ namespace GTweak.Utilities.Tweaks
RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\WpnService", "Start", isDisabled ? 4 : 2, RegistryValueKind.DWord);
RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\WpnService", "DelayedAutoStart", isDisabled ? 1 : 0, RegistryValueKind.DWord);
break;
+ default:
+ break;
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
index 04bad84d..2fefc94a 100644
--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
@@ -503,6 +503,8 @@ namespace GTweak.Utilities.Tweaks
RegistryHelp.Write(Registry.CurrentUser, @"""SOFTWARE\Microsoft\Dfrg\BootOptimizeFunction", "Enable", isDisabled ? "N" : "Y", RegistryValueKind.String);
RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\services\defragsvc", "Start", 2, RegistryValueKind.DWord);
break;
+ default:
+ break;
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
index 21b04f23..f092f716 100644
--- a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
+++ b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
@@ -23,19 +23,13 @@ namespace GTweak.Utilities.Tweaks
internal void GetInstalledPackages()
{
- try
- {
- InstalledPackagesCache = RegistryHelp.GetSubKeyNames<HashSet<string>>(Registry.CurrentUser, @"Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages") ?? new HashSet<string>();
- }
+ try { InstalledPackagesCache = RegistryHelp.GetSubKeyNames<HashSet<string>>(Registry.CurrentUser, @"Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages") ?? new HashSet<string>(); }
catch (Exception ex)
{
ErrorLogging.LogDebug(ex);
InstalledPackagesCache = new HashSet<string>();
}
- finally
- {
- OnPackagesChanged();
- }
+ finally { OnPackagesChanged(); }
}
internal static Dictionary<string, (string Alias, bool IsUnavailable, List<string> Scripts)> PackagesDetails = new Dictionary<string, (string Alias, bool IsUnavailable, List<string> Scripts)>()
@@ -341,6 +335,8 @@ namespace GTweak.Utilities.Tweaks
}
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
break;
+ default:
+ break;
}
});
}
diff --git a/.Source/GTweak/View/ConfidentialityView.xaml.cs b/.Source/GTweak/View/ConfidentialityView.xaml.cs
index 3db875df..77488831 100644
--- a/.Source/GTweak/View/ConfidentialityView.xaml.cs
+++ b/.Source/GTweak/View/ConfidentialityView.xaml.cs
@@ -18,7 +18,7 @@ namespace GTweak.View
private void Tweak_MouseEnter(object sender, MouseEventArgs e)
{
- string description = ((ToggleButton)sender).Description?.ToString() ?? string.Empty;
+ string description = ((ToggleButton)sender!).Description?.ToString() ?? string.Empty;
if (DescBlock.Text != description)
{
diff --git a/.Source/GTweak/View/DataSystemView.xaml.cs b/.Source/GTweak/View/DataSystemView.xaml.cs
index d695ed47..d9a1df3c 100644
--- a/.Source/GTweak/View/DataSystemView.xaml.cs
+++ b/.Source/GTweak/View/DataSystemView.xaml.cs
@@ -110,7 +110,7 @@ namespace GTweak.View
private void BtnVision_PreviewKeyDown(object sender, KeyEventArgs e)
{
- if (e.Key == Key.Space || e.Key == Key.Enter)
+ if (e?.Key == Key.Space || e?.Key == Key.Enter)
{
e.Handled = true;
}
@@ -118,7 +118,7 @@ namespace GTweak.View
private void HandleCopyingData_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
- if (e.LeftButton == MouseButtonState.Pressed)
+ if (e?.LeftButton == MouseButtonState.Pressed)
{
Clipboard.Clear();
switch (sender.GetType().Name)
@@ -135,7 +135,7 @@ namespace GTweak.View
textBlock.FontStyle, textBlock.FontWeight, textBlock.FontStretch), textBlock.FontSize, textBlock.Foreground, VisualTreeHelper.GetDpi(textBlock).PixelsPerDip);
cumulativeHeight += formattedText.Height;
- if (cumulativeHeight >= e.GetPosition(textBlock).Y)
+ if (cumulativeHeight >= e?.GetPosition(textBlock).Y)
{
SelectedLine = line;
break;
@@ -150,6 +150,8 @@ namespace GTweak.View
Clipboard.SetData(DataFormats.UnicodeText, runtext.Text.Replace('\n', ' '));
break;
}
+ default:
+ break;
}
if (!PopupCopy.IsOpen)
diff --git a/.Source/GTweak/View/InterfaceView.xaml.cs b/.Source/GTweak/View/InterfaceView.xaml.cs
index b11b4bc7..7c3de0eb 100644
--- a/.Source/GTweak/View/InterfaceView.xaml.cs
+++ b/.Source/GTweak/View/InterfaceView.xaml.cs
@@ -26,7 +26,7 @@ namespace GTweak.View
private void Tweak_MouseEnter(object sender, MouseEventArgs e)
{
- string description = ((ToggleButton)sender).Description?.ToString() ?? string.Empty;
+ string description = ((ToggleButton)sender!).Description?.ToString() ?? string.Empty;
if (DescBlock.Text != description)
{
diff --git a/.Source/GTweak/View/ServicesView.xaml.cs b/.Source/GTweak/View/ServicesView.xaml.cs
index 7dd80e4d..2b0d996a 100644
--- a/.Source/GTweak/View/ServicesView.xaml.cs
+++ b/.Source/GTweak/View/ServicesView.xaml.cs
@@ -18,7 +18,7 @@ namespace GTweak.View
private void Tweak_MouseEnter(object sender, MouseEventArgs e)
{
- string description = ((ToggleButton)sender).Description?.ToString() ?? string.Empty;
+ string description = ((ToggleButton)sender!).Description?.ToString() ?? string.Empty;
if (DescBlock.Text != description)
{
diff --git a/.Source/GTweak/View/SystemView.xaml.cs b/.Source/GTweak/View/SystemView.xaml.cs
index c9c2bf82..1557fc25 100644
--- a/.Source/GTweak/View/SystemView.xaml.cs
+++ b/.Source/GTweak/View/SystemView.xaml.cs
@@ -25,10 +25,11 @@ namespace GTweak.View
case StackPanel panel:
description = panel.ToolTip?.ToString() ?? string.Empty;
break;
-
case ToggleButton toggle:
description = toggle.Description?.ToString() ?? string.Empty;
break;
+ default:
+ break;
}
if (DescBlock.Text != description)
diff --git a/.Source/GTweak/Windows/ImportWindow.xaml.cs b/.Source/GTweak/Windows/ImportWindow.xaml.cs
index 35253bc8..09eff0f8 100644
--- a/.Source/GTweak/Windows/ImportWindow.xaml.cs
+++ b/.Source/GTweak/Windows/ImportWindow.xaml.cs
@@ -13,7 +13,7 @@ using Wpf.Ui.Controls;
namespace GTweak.Windows
{
- public partial class ImportWindow : FluentWindow
+ public partial class ImportWindow : FluentWindow, IDisposable
{
private readonly ConfidentialityTweaks _confTweaks = new ConfidentialityTweaks();
private readonly InterfaceTweaks _intfTweaks = new InterfaceTweaks();
@@ -169,5 +169,16 @@ namespace GTweak.Windows
}
}
+ public void Dispose()
+ {
+ _cancellationTokenSource.Cancel();
+ _cancellationTokenSource.Dispose();
+ }
+
+ protected override void OnClosed(EventArgs e)
+ {
+ Dispose();
+ base.OnClosed(e);
+ }
}
}
diff --git a/.Source/GTweak/Windows/LoadingWindow.xaml.cs b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
index 0594002e..0891dcc0 100644
--- a/.Source/GTweak/Windows/LoadingWindow.xaml.cs
+++ b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
@@ -73,7 +73,7 @@ namespace GTweak.Windows
private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
- int index = Array.IndexOf(new[] { 0, 10, 30, 55, 75, 95 }, e.ProgressPercentage);
+ int index = Array.IndexOf(new[] { 0, 10, 30, 55, 75, 95 }, e?.ProgressPercentage ?? 0);
if (index > 0)
{
TypewriterAnimation.Create((string)FindResource($"step{++index}_load"), StatusLoading, TimeSpan.FromMilliseconds(200));
diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.cs
index 3a2911f1..b6e1ab36 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs
@@ -51,11 +51,11 @@ namespace GTweak.Windows
private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
{
- if (e.ChangedButton == MouseButton.Left && e.ClickCount != 2)
+ if (e?.ChangedButton == MouseButton.Left && e.ClickCount != 2)
{
if (WindowState == WindowState.Maximized)
{
- _mouseDownWindowPoint = e.GetPosition(this);
+ _mouseDownWindowPoint = e!.GetPosition(this);
_draggingFromMaximized = true;
}
else
@@ -69,7 +69,7 @@ namespace GTweak.Windows
{
if (_draggingFromMaximized)
{
- if (e.LeftButton != MouseButtonState.Pressed)
+ if (e?.LeftButton != MouseButtonState.Pressed)
{
_draggingFromMaximized = false;
return;
@@ -110,9 +110,9 @@ namespace GTweak.Windows
private async void TitleBar_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
- if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
+ if (e?.ChangedButton == MouseButton.Left && e?.ClickCount == 2)
{
- if (e.OriginalSource is DependencyObject source)
+ if (e?.OriginalSource is DependencyObject source)
{
DependencyObject current = source;
while (current != null)
@@ -127,7 +127,6 @@ namespace GTweak.Windows
}
_ignoreMouseClick = true;
-
HandleWindowState();
if (WindowState == WindowState.Maximized && _lastNormalPosition.HasValue && _lastNormalSize.HasValue)
@@ -144,7 +143,7 @@ namespace GTweak.Windows
await Task.Delay(100).ConfigureAwait(false);
_ignoreMouseClick = false;
- e.Handled = true;
+ e!.Handled = true;
}
}
@@ -168,12 +167,14 @@ namespace GTweak.Windows
SettingsEngine.SelfReboot();
Visibility = Visibility.Collapsed;
break;
+ default:
+ break;
}
}
private void TglButton_PreviewKeyDown(object sender, KeyEventArgs e)
{
- if (e.Key == Key.Space || e.Key == Key.Enter)
+ if (e?.Key == Key.Space || e?.Key == Key.Enter)
{
e.Handled = true;
}
diff --git a/.Source/GTweak/Windows/OverlayWindow.xaml.cs b/.Source/GTweak/Windows/OverlayWindow.xaml.cs
index 684b37e4..f12b9095 100644
--- a/.Source/GTweak/Windows/OverlayWindow.xaml.cs
+++ b/.Source/GTweak/Windows/OverlayWindow.xaml.cs
@@ -21,7 +21,7 @@ namespace GTweak.Windows
private void Window_Closing(object sender, CancelEventArgs e)
{
Closing -= Window_Closing;
- e.Cancel = true;
+ e!.Cancel = true;
BeginAnimation(OpacityProperty, FactoryAnimation.CreateTo(0.15, () =>
{
ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;