Skip to content

Portable Tool for an Ideal Windows Setup

fix potential null pointer exceptions in SystemRestoreService (#118) & DescriptionBlock designer crash & upd. NuGet packages

Greedeks612a19783805
diff --git a/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml b/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml
index 23d7cbdd..c6dbba3c 100644
--- a/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml
+++ b/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml
@@ -3,11 +3,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:b="clr-namespace:GTweak.Utilities.Behaviors"
xmlns:local="clr-namespace:GTweak.Assets.UserControls"
mc:Ignorable="d" IsTabStop="False" Focusable="False" KeyboardNavigation.TabNavigation="None" SnapsToDevicePixels="True" UseLayoutRounding="True"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="10">
- <ScrollViewer x:Name="Scroller" Margin="6" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Disabled" ClipToBounds="True">
+ <ScrollViewer x:Name="Scroller" b:ScrollFadeBehavior.EnableFade="True" Margin="6" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Disabled" ClipToBounds="True">
<TextBlock x:Name="FunctionDescription" Style="{StaticResource Description}" Text="{Binding DefaultText, RelativeSource={RelativeSource AncestorType=local:DescriptionBlock}}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" MaxWidth="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=UserControl}}"/>
</ScrollViewer>
diff --git a/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml.cs b/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml.cs
index fdd17ccb..5e055b9a 100644
--- a/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml.cs
+++ b/.Source/GTweak/Assets/UserControls/DescriptionBlock.xaml.cs
@@ -1,4 +1,5 @@
using System;
+using System.ComponentModel;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
@@ -81,7 +82,7 @@ namespace GTweak.Assets.UserControls
private void UpdateFlowDirection()
{
- if (FunctionDescription != null)
+ if (FunctionDescription != null && !DesignerProperties.GetIsInDesignMode(new DependencyObject()))
{
try
{
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csproj
index dbe4f5f1..39924e5a 100644
--- a/.Source/GTweak/GTweak.csproj
+++ b/.Source/GTweak/GTweak.csproj
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="..\..\packages\Costura.Fody.6.1.0\build\Costura.Fody.props" Condition="Exists('..\..\packages\Costura.Fody.6.1.0\build\Costura.Fody.props')" />
+ <Import Project="..\..\packages\Costura.Fody.6.2.0\build\Costura.Fody.props" Condition="Exists('..\..\packages\Costura.Fody.6.2.0\build\Costura.Fody.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -66,8 +66,8 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Costura, Version=6.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
- <HintPath>..\..\packages\Costura.Fody.6.1.0\lib\netstandard2.0\Costura.dll</HintPath>
+ <Reference Include="Costura, Version=6.2.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
+ <HintPath>..\..\packages\Costura.Fody.6.2.0\lib\netstandard2.0\Costura.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.12.1.0, Culture=neutral, PublicKeyToken=2806574b39b74d4b, processorArchitecture=MSIL">
<HintPath>..\..\packages\TaskScheduler.2.12.2\lib\net48\Microsoft.Win32.TaskScheduler.dll</HintPath>
@@ -113,11 +113,11 @@
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
- <Reference Include="Wpf.Ui, Version=4.2.0.0, Culture=neutral, PublicKeyToken=11f9f5cc97b3ffd6, processorArchitecture=MSIL">
- <HintPath>..\..\packages\WPF-UI.4.2.1\lib\net472\Wpf.Ui.dll</HintPath>
+ <Reference Include="Wpf.Ui, Version=4.3.0.0, Culture=neutral, PublicKeyToken=11f9f5cc97b3ffd6, processorArchitecture=MSIL">
+ <HintPath>..\..\packages\WPF-UI.4.3.0\lib\net472\Wpf.Ui.dll</HintPath>
</Reference>
- <Reference Include="Wpf.Ui.Abstractions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=11f9f5cc97b3ffd6, processorArchitecture=MSIL">
- <HintPath>..\..\packages\WPF-UI.Abstractions.4.2.1\lib\net472\Wpf.Ui.Abstractions.dll</HintPath>
+ <Reference Include="Wpf.Ui.Abstractions, Version=4.3.0.0, Culture=neutral, PublicKeyToken=11f9f5cc97b3ffd6, processorArchitecture=MSIL">
+ <HintPath>..\..\packages\WPF-UI.Abstractions.4.3.0\lib\net472\Wpf.Ui.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@@ -545,8 +545,8 @@
<PropertyGroup>
<ErrorText>Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}.</ErrorText>
</PropertyGroup>
- <Error Condition="!Exists('..\..\packages\Costura.Fody.6.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Costura.Fody.6.1.0\build\Costura.Fody.props'))" />
- <Error Condition="!Exists('..\..\packages\Costura.Fody.6.1.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Costura.Fody.6.1.0\build\Costura.Fody.targets'))" />
+ <Error Condition="!Exists('..\..\packages\Costura.Fody.6.2.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Costura.Fody.6.2.0\build\Costura.Fody.props'))" />
+ <Error Condition="!Exists('..\..\packages\Costura.Fody.6.2.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Costura.Fody.6.2.0\build\Costura.Fody.targets'))" />
</Target>
- <Import Project="..\..\packages\Costura.Fody.6.1.0\build\Costura.Fody.targets" Condition="Exists('..\..\packages\Costura.Fody.6.1.0\build\Costura.Fody.targets')" />
+ <Import Project="..\..\packages\Costura.Fody.6.2.0\build\Costura.Fody.targets" Condition="Exists('..\..\packages\Costura.Fody.6.2.0\build\Costura.Fody.targets')" />
</Project>
\ No newline at end of file
diff --git a/.Source/GTweak/Styles/Inputs/ComboBox.xaml b/.Source/GTweak/Styles/Inputs/ComboBox.xaml
index 812bdda8..920271f2 100644
--- a/.Source/GTweak/Styles/Inputs/ComboBox.xaml
+++ b/.Source/GTweak/Styles/Inputs/ComboBox.xaml
@@ -169,7 +169,7 @@
</ToggleButton>
</Grid>
</Border>
- <Popup x:Name="Popup" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" VerticalOffset="2" AllowsTransparency="True" Focusable="False">
+ <Popup x:Name="Popup" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" VerticalOffset="2" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade">
<Border x:Name="PopupBorder"
Width="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}"
Background="{StaticResource Brush_Background_ComboBox}"
diff --git a/.Source/GTweak/Utilities/Maintenance/SystemRestoreService.cs b/.Source/GTweak/Utilities/Maintenance/SystemRestoreService.cs
index 5a4e8277..3be5a07e 100644
--- a/.Source/GTweak/Utilities/Maintenance/SystemRestoreService.cs
+++ b/.Source/GTweak/Utilities/Maintenance/SystemRestoreService.cs
@@ -28,9 +28,9 @@ namespace GTweak.Utilities.Maintenance
{
RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore", "SystemRestorePointCreationFrequency", 0, RegistryValueKind.DWord);
- if (!IsPointCreationAllowed)
+ if (!IsPointCreationAllowed && !EnableRestorePoint("error_point_noty"))
{
- EnableRestorePoint();
+ return;
}
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"\\localhost\root\default", "SELECT Description, SequenceNumber FROM SystemRestore", new EnumerationOptions { ReturnImmediately = true }))
@@ -39,7 +39,8 @@ namespace GTweak.Utilities.Maintenance
{
using (managementObj)
{
- if (managementObj["Description"]?.ToString().IndexOf("GTweak", StringComparison.OrdinalIgnoreCase) >= 0)
+ string description = managementObj["Description"] as string;
+ if (!string.IsNullOrEmpty(description) && description.IndexOf("GTweak", StringComparison.OrdinalIgnoreCase) >= 0)
{
SRRemoveRestorePoint(Convert.ToInt32(managementObj["SequenceNumber"]));
}
@@ -48,12 +49,18 @@ namespace GTweak.Utilities.Maintenance
}
_inParams = _restorePoint.GetMethodParameters("CreateRestorePoint");
+ if (_inParams == null)
+ {
+ NotificationManager.Show("warn", "error_point_noty").Perform();
+ return;
+ }
+
_inParams["Description"] = (string)Application.Current.Resources["textpoint_more"];
_inParams["EventType"] = 100;
_inParams["RestorePointType"] = 12;
_outParams = _restorePoint.InvokeMethod("CreateRestorePoint", _inParams, null);
- if ((uint)_outParams["ReturnValue"] == 0)
+ if (_outParams != null && _outParams["ReturnValue"] is uint retCode && retCode == 0)
{
NotificationManager.Show("info", "success_point_noty").WithDelay(300).Perform();
}
@@ -71,9 +78,9 @@ namespace GTweak.Utilities.Maintenance
{
try
{
- if (!IsPointCreationAllowed)
+ if (!IsPointCreationAllowed && !EnableRestorePoint("error_recovery_noty"))
{
- EnableRestorePoint();
+ return;
}
CommandExecutor.RunCommand("/c rstrui.exe");
@@ -103,18 +110,42 @@ namespace GTweak.Utilities.Maintenance
DisableSR(PathLocator.Folders.SystemDrive + @"\\");
}
- internal void EnableRestorePoint()
+ internal bool EnableRestorePoint(string errorKey = "error_recovery_noty")
{
- RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows NT\SystemRestore");
+ try
+ {
+ RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows NT\SystemRestore");
- SetTaskState(true, restoreTask);
+ SetTaskState(true, restoreTask);
- CommandExecutor.RunCommand("/c sc config wbengine start= demand && sc config swprv start= demand && sc config vds start= demand && sc config VSS start= demand");
+ CommandExecutor.RunCommand("/c sc config wbengine start= demand && sc config swprv start= demand && sc config vds start= demand && sc config VSS start= demand");
+
+ ManagementBaseObject inParams = _restorePoint.GetMethodParameters("Enable");
+
+ if (inParams == null)
+ {
+ NotificationManager.Show("warn", errorKey).Perform();
+ return false;
+ }
- _inParams = _restorePoint.GetMethodParameters("Enable");
- _inParams["WaitTillEnabled"] = true;
- _inParams["Drive"] = Path.GetPathRoot(Environment.SystemDirectory);
- _restorePoint.InvokeMethod("Enable", _inParams, null);
+ inParams["WaitTillEnabled"] = true;
+ inParams["Drive"] = Path.GetPathRoot(Environment.SystemDirectory);
+
+ ManagementBaseObject outParams = _restorePoint.InvokeMethod("Enable", inParams, null);
+
+ if (outParams == null || !(outParams["ReturnValue"] is uint retCode) || retCode != 0)
+ {
+ NotificationManager.Show("warn", errorKey).Perform();
+ return false;
+ }
+
+ return true;
+ }
+ catch (Exception)
+ {
+ NotificationManager.Show("warn", errorKey).Perform();
+ return false;
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/.Source/GTweak/View/UtilsView.xaml.cs b/.Source/GTweak/View/UtilsView.xaml.cs
index bc6867ae..7d1526a3 100644
--- a/.Source/GTweak/View/UtilsView.xaml.cs
+++ b/.Source/GTweak/View/UtilsView.xaml.cs
@@ -51,7 +51,16 @@ namespace GTweak.View
overlayWindow.Show();
NotificationManager.Show("info", "createpoint_noty").Perform();
BackgroundQueue backgroundQueue = new BackgroundQueue();
- await backgroundQueue.QueueTask(delegate { _systemRestore.CreateRestorePoint(); });
+
+ if (_systemRestore == null)
+ {
+ overlayWindow.Close();
+ NotificationManager.Show("warn", "error_point_noty").WithDelay(300).Perform();
+ return;
+ }
+
+ try { await backgroundQueue.QueueTask(delegate { _systemRestore.CreateRestorePoint(); }); }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
overlayWindow.Close();
}
diff --git a/.Source/GTweak/packages.config b/.Source/GTweak/packages.config
index c970816e..2a056b1d 100644
--- a/.Source/GTweak/packages.config
+++ b/.Source/GTweak/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="Costura.Fody" version="6.1.0" targetFramework="net48" developmentDependency="true" />
+ <package id="Costura.Fody" version="6.2.0" targetFramework="net48" developmentDependency="true" />
<package id="Fody" version="6.9.3" targetFramework="net48" developmentDependency="true" />
<package id="Newtonsoft.Json" version="13.0.4" targetFramework="net48" />
<package id="Ookii.Dialogs.Wpf" version="5.0.1" targetFramework="net48" />
@@ -9,6 +9,6 @@
<package id="System.Numerics.Vectors" version="4.6.1" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.1.2" targetFramework="net48" />
<package id="TaskScheduler" version="2.12.2" targetFramework="net48" />
- <package id="WPF-UI" version="4.2.1" targetFramework="net48" />
- <package id="WPF-UI.Abstractions" version="4.2.1" targetFramework="net48" />
+ <package id="WPF-UI" version="4.3.0" targetFramework="net48" />
+ <package id="WPF-UI.Abstractions" version="4.3.0" targetFramework="net48" />
</packages>
\ No newline at end of file