Skip to content

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

fix: remove -allusers

fatDuck6ceda56e0c50
diff --git a/optimizerDuck/Resources/Languages/Translations.Designer.cs b/optimizerDuck/Resources/Languages/Translations.Designer.cs
index c1a53f4..b1a8149 100644
--- a/optimizerDuck/Resources/Languages/Translations.Designer.cs
+++ b/optimizerDuck/Resources/Languages/Translations.Designer.cs
@@ -1897,6 +1897,15 @@ namespace optimizerDuck.Resources.Languages {
}
}
+ /// <summary>
+ /// Looks up a localized string similar to A restore point has already been created within the past 24 hours.
+ /// </summary>
+ public static string RestorePoint_Snackbar_Warning_LimitReached {
+ get {
+ return ResourceManager.GetString("RestorePoint.Snackbar.Warning.LimitReached", 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 b0948be..1a595a4 100644
--- a/optimizerDuck/Resources/Languages/Translations.resx
+++ b/optimizerDuck/Resources/Languages/Translations.resx
@@ -766,6 +766,9 @@ This ensures you can always go back if anything goes wrong.]]></value>
<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.Snackbar.Warning.LimitReached" xml:space="preserve">
+ <value>A restore point has already been created within the past 24 hours.</value>
+ </data>
<data name="RestorePoint.Progress.Creating" xml:space="preserve">
<value>Creating a restore point...</value>
</data>
diff --git a/optimizerDuck/Resources/Languages/Translations.ru-RU.resx b/optimizerDuck/Resources/Languages/Translations.ru-RU.resx
index 69b9b04..1de9c5e 100644
--- a/optimizerDuck/Resources/Languages/Translations.ru-RU.resx
+++ b/optimizerDuck/Resources/Languages/Translations.ru-RU.resx
@@ -819,6 +819,9 @@
<data name="RestorePointDialog.Help" xml:space="preserve">
<value><![CDATA[Приложение автоматически включит восстановление и создаст точку "optimizerDuck...".
Это гарантирует возможность отката, если что-то пойдет не так.]]></value>
+ </data>
+ <data name="RestorePoint.Snackbar.Warning.LimitReached" xml:space="preserve">
+ <value>Точка восстановления уже была создана за последние 24 часа.</value>
</data>
<data name="RestorePoint.Progress.Creating" xml:space="preserve">
<value>Создание точки восстановления...</value>
diff --git a/optimizerDuck/Resources/Languages/Translations.vi-vn.resx b/optimizerDuck/Resources/Languages/Translations.vi-vn.resx
index db7b0f4..58890bf 100644
--- a/optimizerDuck/Resources/Languages/Translations.vi-vn.resx
+++ b/optimizerDuck/Resources/Languages/Translations.vi-vn.resx
@@ -751,6 +751,9 @@ Hãy yên tâm rằng hệ thống của bạn luôn có đường lui nếu có
<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.Snackbar.Warning.LimitReached" xml:space="preserve">
+ <value>Một điểm khôi phục đã được tạo trong vòng 24 giờ qua.</value>
+ </data>
<data name="RestorePoint.Progress.Creating" xml:space="preserve">
<value>Đang tạo điểm khôi phục...</value>
</data>
diff --git a/optimizerDuck/Resources/Languages/Translations.zh-Hans-CN.resx b/optimizerDuck/Resources/Languages/Translations.zh-Hans-CN.resx
index a9cddd9..8caffa0 100644
--- a/optimizerDuck/Resources/Languages/Translations.zh-Hans-CN.resx
+++ b/optimizerDuck/Resources/Languages/Translations.zh-Hans-CN.resx
@@ -819,6 +819,9 @@
<data name="RestorePointDialog.Help" xml:space="preserve">
<value><![CDATA[程序将自动开启系统还原并创建一个名为 "optimizerDuck..." 的还原点。
如果出现任何问题,您可以随时恢复系统。]]></value>
+ </data>
+ <data name="RestorePoint.Snackbar.Warning.LimitReached" xml:space="preserve">
+ <value>过去 24 小时内已创建还原点。</value>
</data>
<data name="RestorePoint.Progress.Creating" xml:space="preserve">
<value>正在创建还原点...</value>
diff --git a/optimizerDuck/Services/BloatwareService.cs b/optimizerDuck/Services/BloatwareService.cs
index 7c5d240..d740eb9 100644
--- a/optimizerDuck/Services/BloatwareService.cs
+++ b/optimizerDuck/Services/BloatwareService.cs
@@ -82,7 +82,7 @@ public class BloatwareService(ILogger<BloatwareService> logger, IOptionsMonitor<
Write-Output "Searching installed package..."
- $installed = Get-AppxPackage -AllUsers | Where-Object { $_.PackageFullName -eq $pkgFull }
+ $installed = Get-AppxPackage | Where-Object { $_.PackageFullName -eq $pkgFull }
if (-not $installed) {
Write-Output "Installed package not found"
@@ -90,11 +90,11 @@ public class BloatwareService(ILogger<BloatwareService> logger, IOptionsMonitor<
else {
foreach ($p in $installed) {
try {
- Remove-AppxPackage -AllUsers -Package $p.PackageFullName -ErrorAction Stop
+ Remove-AppxPackage -Package $p.PackageFullName -ErrorAction Stop
Write-Output "Removed installed package: $($p.PackageFullName)"
}
catch {
- Write-Output "Failed removing installed package: $($p.PackageFullName)"
+ Write-Output "Failed removing installed package: $($p.PackageFullName). Error: $($_.Exception.Message)"
}
}
}
@@ -119,7 +119,7 @@ public class BloatwareService(ILogger<BloatwareService> logger, IOptionsMonitor<
Write-Output "Removed provisioned package: $($p.PackageName)"
}
catch {
- Write-Output "Failed removing provisioned package: $($p.PackageName)"
+ Write-Output "Failed removing provisioned package: $($p.PackageName). Error: $($_.Exception.Message)"
}
}
}
diff --git a/optimizerDuck/Services/OptimizationService.cs b/optimizerDuck/Services/OptimizationService.cs
index 4b079c8..3b5b6f2 100644
--- a/optimizerDuck/Services/OptimizationService.cs
+++ b/optimizerDuck/Services/OptimizationService.cs
@@ -29,7 +29,7 @@ public class OptimizationService(
private static readonly object _cacheLock = new();
private readonly ILogger _logger = logger;
- public async Task<bool> CreateRestorePointAsync()
+ public async Task<RestorePointResult> CreateRestorePointAsync()
{
var dialogViewModel = new ProcessingViewModel();
var dialogContent = new ProcessingDialog { DataContext = dialogViewModel };
@@ -61,15 +61,25 @@ public class OptimizationService(
var result = await RunPowerShellAsync(
$"Checkpoint-Computer -Description \"{Shared.RestorePointName}\" -RestorePointType MODIFY_SETTINGS");
+ // it gives stderr but exitcode is 0
+ if (result.Stderr.Contains("already been created within the past 1440 minutes",
+ StringComparison.OrdinalIgnoreCase))
+ {
+ _logger.LogWarning("Restore point creation skipped: frequency limit reached.");
+ return RestorePointResult.FrequencyLimitReached;
+ }
+
if (result.ExitCode == 0)
- return true;
+ return RestorePointResult.Success;
+
+
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;
+ return RestorePointResult.Failed;
}
_logger.LogError("Failed to create restore point due to disabled feature: {Message}", result.Stderr);
@@ -86,7 +96,7 @@ public class OptimizationService(
if (enableResult.ExitCode != 0)
{
_logger.LogError("Failed to enable System Protection on system drive: {Message}", enableResult.Stderr);
- return false;
+ return RestorePointResult.Failed;
}
dialogViewModel.ProgressReporter.Report(new ProcessingProgress
@@ -100,18 +110,27 @@ public class OptimizationService(
result = await RunPowerShellAsync(
$"Checkpoint-Computer -Description \"{Shared.RestorePointName}\" -RestorePointType MODIFY_SETTINGS");
+ if (result.Stderr.Contains("already been created within the past 1440 minutes",
+ StringComparison.OrdinalIgnoreCase))
+ {
+ _logger.LogWarning("Restore point creation skipped: frequency limit reached.");
+ return RestorePointResult.FrequencyLimitReached;
+ }
+
if (result.ExitCode == 0)
- return true;
+ return RestorePointResult.Success;
if (result.Stderr.Contains("is disabled", StringComparison.OrdinalIgnoreCase))
{
_logger.LogError("Failed to create restore point after enabling feature: {Message}", result.Stderr);
- return false;
+ return RestorePointResult.Failed;
}
+
+
_logger.LogError("Failed to create restore point: {Message}", result.Stderr);
- return false;
+ return RestorePointResult.Failed;
}
finally
{
@@ -449,4 +468,11 @@ public class OptimizationService(
}
#endregion Helpers
+}
+
+public enum RestorePointResult
+{
+ Success,
+ Failed,
+ FrequencyLimitReached
}
\ No newline at end of file
diff --git a/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs b/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs
index 4c43afe..1b46553 100644
--- a/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs
+++ b/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs
@@ -165,23 +165,39 @@ public partial class OptimizationCategoryViewModel : ViewModel
if (result == ContentDialogResult.Secondary) // User skipped
return true;
- 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)
- );
+ var resultState = await _optimizationService.CreateRestorePointAsync();
+
+ switch (resultState)
+ {
+ case RestorePointResult.Success:
+ _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)
+ );
+ break;
+ case RestorePointResult.FrequencyLimitReached:
+ _snackbarService.Show(
+ Translations.RestorePoint_Title,
+ Translations.RestorePoint_Snackbar_Warning_LimitReached,
+ ControlAppearance.Caution,
+ new SymbolIcon { Symbol = SymbolRegular.Warning24, Filled = true },
+ TimeSpan.FromSeconds(5)
+ );
+ break;
+ case RestorePointResult.Failed:
+ default:
+ _snackbarService.Show(
+ Translations.RestorePoint_Snackbar_Error_Title,
+ Translations.RestorePoint_Snackbar_Error_Message,
+ ControlAppearance.Danger,
+ new SymbolIcon { Symbol = SymbolRegular.ErrorCircle24, Filled = true },
+ TimeSpan.FromSeconds(5)
+ );
+ break;
+ }
return true;
}
diff --git a/optimizerDuck/UI/Views/Dialogs/RestorePointDialog.xaml b/optimizerDuck/UI/Views/Dialogs/RestorePointDialog.xaml
index e9522fc..86f9870 100644
--- a/optimizerDuck/UI/Views/Dialogs/RestorePointDialog.xaml
+++ b/optimizerDuck/UI/Views/Dialogs/RestorePointDialog.xaml
@@ -11,7 +11,7 @@
mc:Ignorable="d">
<Grid>
<StackPanel>
- <ui:SymbolIcon FontSize="48" Symbol="DatabaseLightning20" />
+ <ui:SymbolIcon FontSize="48" Symbol="DatabaseLightning20" />
<ui:TextBlock
HorizontalAlignment="Center"
FontTypography="Body"
@@ -19,15 +19,12 @@
TextAlignment="Center"
TextWrapping="Wrap" />
-
<ui:InfoBar
Margin="0,15,0,0"
IsClosable="False"
IsOpen="True"
Message="{ext:Loc RestorePointDialog.Help}"
Severity="Success" />
-
-
</StackPanel>
</Grid>
</UserControl>
\ No newline at end of file