Skip to content

Free, open-source Windows optimization tool for performance, privacy, and simplicity.

feat: add restore point creation functionality

itsfatduck93602832a1e4
diff --git a/README.md b/README.md
index 4d73291..a44b20b 100644
--- a/README.md
+++ b/README.md
@@ -96,7 +96,7 @@ Every star and contribution helps keep the project growing.
- 💬 [Discord](https://discord.gg/tDUBDCYw9Q) → Live chat & support
- 🐞 [Issues](https://github.com/itsfatduck/optimizerDuck/issues) → Bug reports
- 💡 [Discussions](https://github.com/itsfatduck/optimizerDuck/discussions) → Feature requests
-- 📚 [Third-Party Notices](./THIRD-PARTY-NOTICES.md) → open source acknowledgments
+- 📚 [Third-Party Notices](./THIRD-PARTY-NOTICES.md) → Open Source acknowledgments
> [!TIP]
> Before asking for help, check the docs and existing issues — your answer may already be there.
diff --git a/SUPPORT.md b/SUPPORT.md
index 6033528..a363eae 100644
--- a/SUPPORT.md
+++ b/SUPPORT.md
@@ -22,8 +22,6 @@ Your support helps with:
## ☕ Quick & Easy Support
-If you prefer traditional payment platforms:
-
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/itsfatduck)
Even small contributions make a big difference.
diff --git a/optimizerDuck.Test/Services/OptimizationServiceTests.cs b/optimizerDuck.Test/Services/OptimizationServiceTests.cs
index a1470d7..87b166a 100644
--- a/optimizerDuck.Test/Services/OptimizationServiceTests.cs
+++ b/optimizerDuck.Test/Services/OptimizationServiceTests.cs
@@ -9,6 +9,7 @@ using optimizerDuck.Core.Models.Revert.Steps;
using optimizerDuck.Core.Models.UI;
using optimizerDuck.Services;
using optimizerDuck.Services.Managers;
+using Wpf.Ui;
namespace optimizerDuck.Test.Services;
@@ -155,7 +156,9 @@ public class OptimizationServiceTests
var loggerFactory = NullLoggerFactory.Instance;
var systemInfoService = new SystemInfoService(NullLogger<SystemInfoService>.Instance);
var streamService = new StreamService(NullLogger<StreamService>.Instance);
- return new OptimizationService(revertManager, loggerFactory, systemInfoService, streamService);
+ var contentDialogService = new ContentDialogService();
+ var logger = NullLogger<OptimizationService>.Instance;
+ return new OptimizationService(revertManager, loggerFactory, systemInfoService, streamService, contentDialogService, logger);
}
private static string GetRevertFilePath(Guid id)
diff --git a/optimizerDuck/Common/Helpers/Shared.cs b/optimizerDuck/Common/Helpers/Shared.cs
index 33ec27c..d7b485b 100644
--- a/optimizerDuck/Common/Helpers/Shared.cs
+++ b/optimizerDuck/Common/Helpers/Shared.cs
@@ -22,10 +22,11 @@ public static class Shared
public const string SupportMeURL = "https://github.com/itsfatduck/optimizerDuck/SUPPORT.md";
public const string AcknowledgementsURL = "https://github.com/itsfatduck/optimizerDuck/blob/master/THIRD-PARTY-NOTICES.md";
+
+ public const string RestorePointName = "optimizerDuck Restore Point";
public const string PowerPlanUrl =
"https://github.com/itsfatduck/optimizerDuck/raw/refs/heads/master/optimizerDuck.Resources/optimizerDuck.pow";
-
public const string PowerPlanGUID = "8ae61178-2c55-43f2-afb2-f83725823657";
public static readonly string ExePath = Environment.ProcessPath!;
@@ -41,4 +42,5 @@ public static class Shared
public static string RevertDirectory =>
Path.Combine(RootDirectory, "Revert");
+
}
\ No newline at end of file
diff --git a/optimizerDuck/Core/Optimizers/BloatwareAndServices.cs b/optimizerDuck/Core/Optimizers/BloatwareAndServices.cs
index 71e625f..4b6b893 100644
--- a/optimizerDuck/Core/Optimizers/BloatwareAndServices.cs
+++ b/optimizerDuck/Core/Optimizers/BloatwareAndServices.cs
@@ -109,7 +109,7 @@ public class BloatwareAndServices : IOptimizationCategory
new("KeyIso", ServiceStartupType.Automatic),
new("KtmRm", ServiceStartupType.Manual),
new("LSM", ServiceStartupType.Automatic),
- new("LanmanServer", ServiceStartupType.Automatic),
+ new("LanmanServer", ServiceStartupType.Manual),
new("LanmanWorkstation", ServiceStartupType.Automatic),
new("LicenseManager", ServiceStartupType.Manual),
new("LxpSvc", ServiceStartupType.Manual),
@@ -127,10 +127,10 @@ public class BloatwareAndServices : IOptimizationCategory
new("NcdAutoSetup", ServiceStartupType.Manual),
new("NetSetupSvc", ServiceStartupType.Manual),
new("NetTcpPortSharing", ServiceStartupType.Disabled),
- new("Netman", ServiceStartupType.Manual),
+ new("Netman", ServiceStartupType.Automatic),
new("NgcCtnrSvc", ServiceStartupType.Manual),
new("NgcSvc", ServiceStartupType.Manual),
- new("NlaSvc", ServiceStartupType.Manual),
+ new("NlaSvc", ServiceStartupType.Automatic),
new("PNRPAutoReg", ServiceStartupType.Manual),
new("PNRPsvc", ServiceStartupType.Manual),
new("PcaSvc", ServiceStartupType.Manual),
@@ -148,7 +148,7 @@ public class BloatwareAndServices : IOptimizationCategory
new("RasMan", ServiceStartupType.Manual),
new("RemoteAccess", ServiceStartupType.Disabled),
new("RemoteRegistry", ServiceStartupType.Disabled),
- new("RetailDemo", ServiceStartupType.Manual),
+ new("RetailDemo", ServiceStartupType.Disabled),
new("RmSvc", ServiceStartupType.Manual),
new("RpcEptMapper", ServiceStartupType.Automatic),
new("RpcLocator", ServiceStartupType.Manual),
@@ -171,14 +171,14 @@ public class BloatwareAndServices : IOptimizationCategory
new("SharedRealitySvc", ServiceStartupType.Manual),
new("ShellHWDetection", ServiceStartupType.Automatic),
new("SmsRouter", ServiceStartupType.Manual),
- new("Spooler", ServiceStartupType.Automatic),
+ new("Spooler", ServiceStartupType.Manual),
new("SstpSvc", ServiceStartupType.Manual),
new("StiSvc", ServiceStartupType.Manual),
new("StorSvc", ServiceStartupType.Manual),
new("SystemEventsBroker", ServiceStartupType.Automatic),
new("TabletInputService", ServiceStartupType.Manual),
new("TapiSrv", ServiceStartupType.Manual),
- new("TermService", ServiceStartupType.Automatic),
+ new("TermService", ServiceStartupType.Manual),
new("Themes", ServiceStartupType.Automatic),
new("TieringEngineService", ServiceStartupType.Manual),
new("TimeBroker", ServiceStartupType.Manual),
@@ -191,8 +191,8 @@ public class BloatwareAndServices : IOptimizationCategory
new("UmRdpService", ServiceStartupType.Manual),
new("UserManager", ServiceStartupType.Automatic),
new("UsoSvc", ServiceStartupType.Manual),
- new("VGAuthService", ServiceStartupType.Automatic),
- new("VMTools", ServiceStartupType.Automatic),
+ new("VGAuthService", ServiceStartupType.Manual),
+ new("VMTools", ServiceStartupType.Manual),
new("VSS", ServiceStartupType.Manual),
new("VacSvc", ServiceStartupType.Manual),
new("VaultSvc", ServiceStartupType.Automatic),
@@ -202,7 +202,7 @@ public class BloatwareAndServices : IOptimizationCategory
new("WMPNetworkSvc", ServiceStartupType.Manual),
new("WManSvc", ServiceStartupType.Manual),
new("WPDBusEnum", ServiceStartupType.Manual),
- new("WSearch", ServiceStartupType.AutomaticDelayedStart),
+ new("WSearch", ServiceStartupType.Manual),
new("WaaSMedicSvc", ServiceStartupType.Manual),
new("WalletService", ServiceStartupType.Manual),
new("WarpJITSvc", ServiceStartupType.Manual),
@@ -240,7 +240,6 @@ public class BloatwareAndServices : IOptimizationCategory
new("embeddedmode", ServiceStartupType.Manual),
new("fdPHost", ServiceStartupType.Manual),
new("fhsvc", ServiceStartupType.Manual),
- new("gpsvc", ServiceStartupType.Automatic),
new("hidserv", ServiceStartupType.Manual),
new("icssvc", ServiceStartupType.Manual),
new("iphlpsvc", ServiceStartupType.Automatic),
diff --git a/optimizerDuck/Resources/Languages/Translations.Designer.cs b/optimizerDuck/Resources/Languages/Translations.Designer.cs
index d1d022f..ae5fff3 100644
--- a/optimizerDuck/Resources/Languages/Translations.Designer.cs
+++ b/optimizerDuck/Resources/Languages/Translations.Designer.cs
@@ -1698,6 +1698,69 @@ namespace optimizerDuck.Resources.Languages {
}
}
+ /// <summary>
+ /// Looks up a localized string similar to Creating a restore point....
+ /// </summary>
+ public static string RestorePoint_Progress_Creating {
+ get {
+ return ResourceManager.GetString("RestorePoint.Progress.Creating", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Enabling System Restore....
+ /// </summary>
+ public static string RestorePoint_Progress_Enabling {
+ get {
+ return ResourceManager.GetString("RestorePoint.Progress.Enabling", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Retrying to create the restore point....
+ /// </summary>
+ public static string RestorePoint_Progress_Retrying {
+ get {
+ return ResourceManager.GetString("RestorePoint.Progress.Retrying", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to An error occurred while creating or enabling System Restore. Please try creating it manually..
+ /// </summary>
+ public static string RestorePoint_Snackbar_Error_Message {
+ get {
+ return ResourceManager.GetString("RestorePoint.Snackbar.Error.Message", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Unable to create or enable System Restore..
+ /// </summary>
+ public static string RestorePoint_Snackbar_Error_Title {
+ get {
+ return ResourceManager.GetString("RestorePoint.Snackbar.Error.Title", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to A restore point has been created with the name: {0}..
+ /// </summary>
+ public static string RestorePoint_Snackbar_Success_Message {
+ get {
+ return ResourceManager.GetString("RestorePoint.Snackbar.Success.Message", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Restore point created successfully.
+ /// </summary>
+ public static string RestorePoint_Snackbar_Success_Title {
+ get {
+ return ResourceManager.GetString("RestorePoint.Snackbar.Success.Title", resourceCulture);
+ }
+ }
+
/// <summary>
/// Looks up a localized string similar to System Restore.
/// </summary>
diff --git a/optimizerDuck/Resources/Languages/Translations.resx b/optimizerDuck/Resources/Languages/Translations.resx
index 1be42d2..d532360 100644
--- a/optimizerDuck/Resources/Languages/Translations.resx
+++ b/optimizerDuck/Resources/Languages/Translations.resx
@@ -745,4 +745,25 @@
<data name="RestorePointDialog.Help" xml:space="preserve">
<value>When you proceed, the application will automatically activate System Restore (if it is disabled) and create a new restore point with a name starting with "optimizerDuck...", helping safeguard the system before any changes.</value>
</data>
+ <data name="RestorePoint.Snackbar.Error.Title" xml:space="preserve">
+ <value>Unable to create or enable System Restore.</value>
+ </data>
+ <data name="RestorePoint.Snackbar.Error.Message" xml:space="preserve">
+ <value>An error occurred while creating or enabling System Restore. Please try creating it manually.</value>
+ </data>
+ <data name="RestorePoint.Progress.Creating" xml:space="preserve">
+ <value>Creating a restore point...</value>
+ </data>
+ <data name="RestorePoint.Progress.Enabling" xml:space="preserve">
+ <value>Enabling System Restore...</value>
+ </data>
+ <data name="RestorePoint.Progress.Retrying" xml:space="preserve">
+ <value>Retrying to create the restore point...</value>
+ </data>
+ <data name="RestorePoint.Snackbar.Success.Title" xml:space="preserve">
+ <value>Restore point created successfully</value>
+ </data>
+ <data name="RestorePoint.Snackbar.Success.Message" xml:space="preserve">
+ <value>A restore point has been created with the name: {0}.</value>
+ </data>
</root>
\ No newline at end of file
diff --git a/optimizerDuck/Resources/Languages/Translations.vi-vn.resx b/optimizerDuck/Resources/Languages/Translations.vi-vn.resx
index 26d63d3..727392d 100644
--- a/optimizerDuck/Resources/Languages/Translations.vi-vn.resx
+++ b/optimizerDuck/Resources/Languages/Translations.vi-vn.resx
@@ -742,4 +742,25 @@
<data name="RestorePointDialog.Help" xml:space="preserve">
<value>Khi bạn tiếp tục, ứng dụng sẽ tự động kích hoạt System Restore (nếu đang tắt) và tạo một điểm khôi phục mới với tên bắt đầu bằng "optimizerDuck...", giúp bảo vệ hệ thống trước mọi thay đổi.</value>
</data>
+ <data name="RestorePoint.Snackbar.Error.Title" xml:space="preserve">
+ <value>Không thể tạo hoặc bật System Restore</value>
+ </data>
+ <data name="RestorePoint.Snackbar.Error.Message" xml:space="preserve">
+ <value>Lỗi khi tạo hoặc bật System Restore, bạn hãy thử tạo thủ công.</value>
+ </data>
+ <data name="RestorePoint.Progress.Creating" xml:space="preserve">
+ <value>Đang tạo điểm khôi phục...</value>
+ </data>
+ <data name="RestorePoint.Progress.Enabling" xml:space="preserve">
+ <value>Đang mở System Restore...</value>
+ </data>
+ <data name="RestorePoint.Progress.Retrying" xml:space="preserve">
+ <value>Đang thử tạo lại điểm khôi phục...</value>
+ </data>
+ <data name="RestorePoint.Snackbar.Success.Title" xml:space="preserve">
+ <value>Tạo thành công điểm khôi phục</value>
+ </data>
+ <data name="RestorePoint.Snackbar.Success.Message" xml:space="preserve">
+ <value>Điểm khôi phục đã được tạo với tên: {0}.</value>
+ </data>
</root>
\ No newline at end of file
diff --git a/optimizerDuck/Services/OptimizationService.cs b/optimizerDuck/Services/OptimizationService.cs
index fe50635..790d274 100644
--- a/optimizerDuck/Services/OptimizationService.cs
+++ b/optimizerDuck/Services/OptimizationService.cs
@@ -1,12 +1,19 @@
using System.IO;
+using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging;
using optimizerDuck.Common.Helpers;
using optimizerDuck.Core.Interfaces;
using optimizerDuck.Core.Models.Optimization;
+using optimizerDuck.Core.Models.Optimization.Services;
using optimizerDuck.Core.Models.Revert;
using optimizerDuck.Core.Models.UI;
using optimizerDuck.Resources.Languages;
using optimizerDuck.Services.Managers;
+using optimizerDuck.Services.OptimizationServices;
+using optimizerDuck.UI.ViewModels.Dialogs;
+using optimizerDuck.UI.Views.Dialogs;
+using Wpf.Ui;
+using Wpf.Ui.Controls;
namespace optimizerDuck.Services;
@@ -14,10 +21,13 @@ public class OptimizationService(
RevertManager revertManager,
ILoggerFactory loggerFactory,
SystemInfoService systemInfoService,
- StreamService streamService)
+ StreamService streamService,
+ IContentDialogService contentDialogService,
+ ILogger<OptimizationService> logger)
{
private static readonly Dictionary<Guid, (bool IsApplied, DateTime? AppliedAt)> _stateCache = new();
private static readonly object _cacheLock = new();
+ private readonly ILogger _logger = logger;
#region Main Methods
@@ -99,7 +109,8 @@ public class OptimizationService(
? string.Format(Translations.Optimization_Apply_Success, optimization.OptimizationKey)
: stepResults.Count == failedSteps.Count // if all steps failed
? string.Format(Translations.Optimization_Apply_Error_Failed, optimization.OptimizationKey)
- : string.Format(Translations.Optimization_Apply_Error_FailedWithSteps, optimization.OptimizationKey,
+ : string.Format(Translations.Optimization_Apply_Error_FailedWithSteps,
+ optimization.OptimizationKey,
failedSteps.Count),
FailedSteps = failedSteps
};
@@ -352,4 +363,94 @@ public class OptimizationService(
}
#endregion Helpers
-}
\ No newline at end of file
+
+ public async Task<bool> CreateRestorePointAsync()
+ {
+ var dialogViewModel = new ProcessingOptimizationViewModel();
+ var dialogContent = new ProcessingOptimizationDialog { DataContext = dialogViewModel };
+
+ var dialog = new ContentDialog
+ {
+ Title = Translations.RestorePoint_Title,
+ Content = dialogContent,
+ IsFooterVisible = false,
+ };
+
+ _ = contentDialogService.ShowAsync(dialog, CancellationToken.None);
+
+ try
+ {
+ async Task<ShellResult> RunPowerShellAsync(string command)
+ {
+ return await Task.Run(() => ShellService.PowerShell(command));
+ }
+
+ dialogViewModel.ProgressReporter.Report(new ProcessingProgress
+ {
+ Message = Translations.RestorePoint_Progress_Creating,
+ IsIndeterminate = true
+ });
+
+ using var tracker = ServiceTracker.Begin(_logger);
+
+ var result = await RunPowerShellAsync(
+ $"Checkpoint-Computer -Description \"{Shared.RestorePointName}\" -RestorePointType MODIFY_SETTINGS");
+
+ if (result.ExitCode == 0)
+ return true;
+
+ if (!Regex.IsMatch(result.Stderr,
+ @"\b(is\s+disabled|system\s+restore\s+is\s+disabled|disabled\s+by\s+group\s+policy|disableconfig|disablesr|protection\s+is\s+off)\b",
+ RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
+ {
+ _logger.LogError("Failed to create restore point (not a 'disabled' case): {Message}", result.Stderr);
+ return false;
+ }
+
+ _logger.LogError("Failed to create restore point due to disabled feature: {Message}", result.Stderr);
+
+ dialogViewModel.ProgressReporter.Report(new ProcessingProgress
+ {
+ Message = Translations.RestorePoint_Progress_Enabling,
+ IsIndeterminate = true
+ });
+
+ // try to enable it
+ _logger.LogInformation("Enabling System Protection on system drive...");
+ var enableResult = await RunPowerShellAsync("Enable-ComputerRestore -Drive \"$env:SystemDrive\"");
+ if (enableResult.ExitCode != 0)
+ {
+ _logger.LogError("Failed to enable System Protection on system drive: {Message}", enableResult.Stderr);
+ return false;
+ }
+
+ dialogViewModel.ProgressReporter.Report(new ProcessingProgress
+ {
+ Message = Translations.RestorePoint_Progress_Retrying,
+ IsIndeterminate = true
+ });
+
+ // retry creating restore point
+ _logger.LogInformation("Retrying to create restore point...");
+ result = await RunPowerShellAsync(
+ $"Checkpoint-Computer -Description \"{Shared.RestorePointName}\" -RestorePointType MODIFY_SETTINGS");
+
+ if (result.ExitCode == 0)
+ return true;
+
+ if (result.Stderr.Contains("is disabled", StringComparison.OrdinalIgnoreCase))
+ {
+ _logger.LogError("Failed to create restore point after enabling feature: {Message}", result.Stderr);
+ return false;
+ }
+
+
+ _logger.LogError("Failed to create restore point: {Message}", result.Stderr);
+ return false;
+ }
+ finally
+ {
+ dialog.Hide();
+ }
+ }
+}
diff --git a/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs b/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs
index f093540..935314e 100644
--- a/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs
+++ b/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs
@@ -3,10 +3,12 @@ using System.Windows.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
+using optimizerDuck.Common.Helpers;
using optimizerDuck.Core.Interfaces;
using optimizerDuck.Core.Models.Optimization;
using optimizerDuck.Core.Models.UI;
using optimizerDuck.Resources.Languages;
+using optimizerDuck.Resources.Languages;
using optimizerDuck.Services;
using optimizerDuck.UI.ViewModels.Dialogs;
using optimizerDuck.UI.Views.Dialogs;
@@ -157,6 +159,26 @@ public partial class OptimizationCategoryViewModel : ViewModel
};
var result = await _contentDialogService.ShowAsync(dialog, CancellationToken.None);
+ if (result != ContentDialogResult.Primary)
+ return;
+
+ var success = await _optimizationService.CreateRestorePointAsync();
+ if (!success)
+ _snackbarService.Show(
+ Translations.RestorePoint_Snackbar_Error_Title,
+ Translations.RestorePoint_Snackbar_Error_Message,
+ ControlAppearance.Danger,
+ new SymbolIcon { Symbol = SymbolRegular.ErrorCircle24, Filled = true },
+ TimeSpan.FromSeconds(5)
+ );
+ else
+ _snackbarService.Show(
+ Translations.RestorePoint_Snackbar_Success_Title,
+ string.Format(Translations.RestorePoint_Snackbar_Success_Message, Shared.RestorePointName),
+ ControlAppearance.Success,
+ new SymbolIcon { Symbol = SymbolRegular.CheckmarkCircle24, Filled = true },
+ TimeSpan.FromSeconds(5)
+ );
}
private static StackPanel BuildDialogTitle(IOptimization optimization)
diff --git a/optimizerDuck/UI/Views/Pages/SettingsPage.xaml b/optimizerDuck/UI/Views/Pages/SettingsPage.xaml
index 3b6144b..3b25607 100644
--- a/optimizerDuck/UI/Views/Pages/SettingsPage.xaml
+++ b/optimizerDuck/UI/Views/Pages/SettingsPage.xaml
@@ -216,7 +216,7 @@
</ui:CardControl.Header>
</ui:CardControl>
- <ui:CardAction Command="{Binding ViewModel.OpenSourceLicensesCommand}" VerticalAlignment="Stretch">
+ <ui:CardAction Command="{Binding ViewModel.AcknowledgementsCommand}" VerticalAlignment="Stretch">
<ui:CardAction.Icon>
<ui:SymbolIcon Symbol="DocumentHeart24" />
</ui:CardAction.Icon>
@@ -224,11 +224,11 @@
<ui:TextBlock
Appearance="Primary"
FontTypography="BodyStrong"
- Text="{ext:Loc Settings.About.OpenSourceLicenses.Title}"
+ Text="{ext:Loc Settings.About.Acknowledgements.Title}"
TextWrapping="Wrap" />
<ui:TextBlock
Appearance="Secondary"
- Text="{ext:Loc Settings.About.OpenSourceLicenses.Description}"
+ Text="{ext:Loc Settings.About.Acknowledgements.Description}"
TextWrapping="Wrap" />
</StackPanel>
</ui:CardAction>