Skip to content

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

xml: add xml docs to public services

fatDuck7ac525c90079
diff --git a/optimizerDuck.Test/optimizerDuck.Test.csproj b/optimizerDuck.Test/optimizerDuck.Test.csproj
index a4eb05a..dc8376a 100644
--- a/optimizerDuck.Test/optimizerDuck.Test.csproj
+++ b/optimizerDuck.Test/optimizerDuck.Test.csproj
@@ -12,7 +12,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.8" />
+ <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="xunit.v3" Version="3.2.2" />
diff --git a/optimizerDuck/Services/Customize/CustomizeRegistry.cs b/optimizerDuck/Services/Customize/CustomizeRegistry.cs
index 8f441eb..6d68de9 100644
--- a/optimizerDuck/Services/Customize/CustomizeRegistry.cs
+++ b/optimizerDuck/Services/Customize/CustomizeRegistry.cs
@@ -10,8 +10,10 @@ namespace optimizerDuck.Services;
public class CustomizeRegistry
{
+ /// <summary>Gets the registered customize categories. Each category contains its child customize settings. Populated after calling <see cref="RegisterCategories"/>.</summary>
public ICustomizeCategory[] Categories { get; private set; } = [];
+ /// <summary>Discovers all customize setting categories and their child settings via reflection, then populates <see cref="Categories"/>.</summary>
public void RegisterCategories()
{
var categories = ReflectionHelper
@@ -55,6 +57,8 @@ public class CustomizeRegistry
Categories = categories;
}
+ /// <summary>Builds the navigation items for the UI from the registered categories. Calls <see cref="RegisterCategories"/> if not yet registered.</summary>
+ /// <returns>A sequence of <see cref="NavigationViewItem"/> instances mapped to customize pages.</returns>
public IEnumerable<NavigationViewItem> GetNavigationItems()
{
if (Categories.Length == 0)
diff --git a/optimizerDuck/Services/Optimization/OptimizationRegistry.cs b/optimizerDuck/Services/Optimization/OptimizationRegistry.cs
index 3e0d712..4c5a53b 100644
--- a/optimizerDuck/Services/Optimization/OptimizationRegistry.cs
+++ b/optimizerDuck/Services/Optimization/OptimizationRegistry.cs
@@ -12,8 +12,10 @@ public class OptimizationRegistry(ILoggerFactory loggerFactory)
private readonly ILogger _logger = loggerFactory.CreateLogger<OptimizationRegistry>();
private Task? _preloadTask;
+ /// <summary>Gets or sets the discovered optimization categories after preloading. Each category contains its child optimizations.</summary>
public IOptimizationCategory[] OptimizationCategories { get; set; } = [];
+ /// <summary>Gets a value that indicates whether the optimizations have been fully discovered and their applied states loaded.</summary>
public bool IsPreloaded { get; private set; }
/// <summary>
@@ -32,6 +34,7 @@ public class OptimizationRegistry(ILoggerFactory loggerFactory)
return _preloadTask ??= PreloadOptimizationsAsync();
}
+ /// <summary>Discovers all optimization categories and their optimizations via reflection, then loads the applied state from revert data on disk.</summary>
public async Task PreloadOptimizationsAsync()
{
// Run reflection work on background thread to avoid blocking startup
@@ -90,6 +93,9 @@ public class OptimizationRegistry(ILoggerFactory loggerFactory)
IsPreloaded = true;
}
+ /// <summary>Gets a category by its runtime type. Categories must have been preloaded first.</summary>
+ /// <param name="type">The runtime type of the category to retrieve.</param>
+ /// <returns>The matching <see cref="IOptimizationCategory"/> instance.</returns>
public IOptimizationCategory GetCategory(Type type)
{
return OptimizationCategories.First(c => c.GetType() == type);
diff --git a/optimizerDuck/Services/Optimization/OptimizationService.cs b/optimizerDuck/Services/Optimization/OptimizationService.cs
index 592230e..6314475 100644
--- a/optimizerDuck/Services/Optimization/OptimizationService.cs
+++ b/optimizerDuck/Services/Optimization/OptimizationService.cs
@@ -28,6 +28,7 @@ public class OptimizationService(
{
private readonly ILogger _logger = logger;
+ /// <summary>Gets or sets a value that indicates whether a system restore point was created before applying optimizations.</summary>
public bool WasRequestedRestorePoint { get; set; } = false;
private static readonly Regex _restorePointDisabledRegex = new(
@@ -35,6 +36,8 @@ public class OptimizationService(
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled
);
+ /// <summary>Creates a system restore point via PowerShell, showing a processing dialog. Enables System Protection if it is disabled.</summary>
+ /// <returns>A <see cref="RestorePointResult"/> indicating success, failure, or frequency-limit reached.</returns>
public async Task<RestorePointResult> CreateRestorePointAsync()
{
var dialogViewModel = new ProcessingViewModel();
@@ -134,6 +137,11 @@ public class OptimizationService(
) == true;
}
+ /// <summary>Applies the specified optimization, captures revert steps into an execution scope, and persists revert data on any successful steps.</summary>
+ /// <param name="optimization">The optimization to apply.</param>
+ /// <param name="progress">An <see cref="IProgress{T}"/> to report application progress.</param>
+ /// <param name="cancellationToken">A token to cancel the operation.</param>
+ /// <returns>An <see cref="OptimizationResult"/> describing the outcome, including partial-success or failure details.</returns>
public async Task<OptimizationResult> ApplyAsync(
IOptimization optimization,
IProgress<ProcessingProgress> progress,
@@ -217,6 +225,11 @@ public class OptimizationService(
}
}
+ /// <summary>Reverts the specified optimization using stored revert data from a previous apply operation.</summary>
+ /// <param name="optimization">The optimization to revert.</param>
+ /// <param name="progress">An optional <see cref="IProgress{T}"/> to report revert progress.</param>
+ /// <param name="cancellationToken">A token to cancel the operation.</param>
+ /// <returns>A <see cref="RevertResult"/> describing the outcome.</returns>
public async Task<RevertResult> RevertAsync(
IOptimization optimization,
IProgress<ProcessingProgress>? progress = null,
@@ -243,6 +256,8 @@ public class OptimizationService(
return result;
}
+ /// <summary>Updates the applied state of the specified optimizations by scanning revert data files on disk. An optimization is considered applied when its revert JSON file exists.</summary>
+ /// <param name="optimizations">The optimizations whose state to update.</param>
public static async Task UpdateOptimizationStateAsync(params IOptimization[] optimizations)
{
if (optimizations.Length == 0)
@@ -279,11 +294,22 @@ public class OptimizationService(
}
}
+ /// <summary>Updates the applied state of the specified optimizations by scanning revert data files on disk.</summary>
+ /// <param name="optimizations">The optimizations whose state to update.</param>
public static Task UpdateOptimizationStateAsync(IEnumerable<IOptimization> optimizations)
{
return UpdateOptimizationStateAsync(optimizations.ToArray());
}
+ /// <summary>Retries the specified failed operation steps, optionally in reverse order. Automatically persists recovered revert steps if a <see cref="RevertManager"/> is provided.</summary>
+ /// <param name="failedSteps">The steps that failed and should be retried.</param>
+ /// <param name="reverseOrder">If <see langword="true"/>, retries steps in descending index order (useful for revert operations).</param>
+ /// <param name="logger">The logger for retry diagnostics.</param>
+ /// <param name="revertManager">Optional revert manager to persist recovered revert steps.</param>
+ /// <param name="optimizationId">The optimization ID for revert step persistence.</param>
+ /// <param name="optimizationKey">The optimization key for revert step persistence.</param>
+ /// <param name="progress">An optional progress reporter.</param>
+ /// <returns>The list of steps that remain failed after retry.</returns>
public static async Task<List<OperationStepResult>> RetryFailedStepsAsync(
IReadOnlyList<OperationStepResult> failedSteps,
bool reverseOrder,
@@ -307,6 +333,15 @@ public class OptimizationService(
).FailedSteps;
}
+ /// <summary>Retries failed operation steps and returns both recovered and remaining failed steps for detailed inspection. Automatically persists recovered revert steps if a <see cref="RevertManager"/> is provided.</summary>
+ /// <param name="failedSteps">The steps that failed and should be retried.</param>
+ /// <param name="reverseOrder">If <see langword="true"/>, retries steps in descending index order.</param>
+ /// <param name="logger">The logger for retry diagnostics.</param>
+ /// <param name="revertManager">Optional revert manager to persist recovered revert steps.</param>
+ /// <param name="optimizationId">The optimization ID for revert step persistence.</param>
+ /// <param name="optimizationKey">The optimization key for revert step persistence.</param>
+ /// <param name="progress">An optional progress reporter.</param>
+ /// <returns>A <see cref="RetryFailedStepsResult"/> containing both recovered and remaining failed steps.</returns>
public static async Task<RetryFailedStepsResult> RetryFailedStepsWithResultsAsync(
IReadOnlyList<OperationStepResult> failedSteps,
bool reverseOrder,
@@ -449,6 +484,8 @@ public class OptimizationService(
}
}
+ /// <summary>Deletes all files in the downloads directory. Silently skips files that cannot be deleted.</summary>
+ /// <param name="logger">The logger for deletion errors.</param>
public static void ClearDownloads(ILogger logger)
{
if (!Directory.Exists(Shared.DownloadsDirectory))
@@ -465,13 +502,22 @@ public class OptimizationService(
}
}
+/// <summary>Represents the result of a system restore point creation attempt.</summary>
public enum RestorePointResult
{
+ /// <summary>The restore point was created successfully.</summary>
Success,
+
+ /// <summary>The restore point creation failed.</summary>
Failed,
+
+ /// <summary>The creation was skipped because a restore point was already created within the frequency limit (24 hours).</summary>
FrequencyLimitReached,
}
+/// <summary>Represents the result of retrying failed operation steps, separating recovered steps from those that remain failed.</summary>
+/// <param name="FailedSteps">The steps that remain failed after retry.</param>
+/// <param name="RecoveredSteps">The steps that succeeded on retry.</param>
public sealed record RetryFailedStepsResult(
List<OperationStepResult> FailedSteps,
List<OperationStepResult> RecoveredSteps
diff --git a/optimizerDuck/Services/Optimization/Providers/ServiceProcessService.cs b/optimizerDuck/Services/Optimization/Providers/ServiceProcessService.cs
index 1278a14..15973b3 100644
--- a/optimizerDuck/Services/Optimization/Providers/ServiceProcessService.cs
+++ b/optimizerDuck/Services/Optimization/Providers/ServiceProcessService.cs
@@ -26,6 +26,9 @@ public static class ServiceProcessService
internal static string? LastError => _lastError.Value;
internal static string? LastErrorDetail => _lastErrorDetail.Value;
+ /// <summary>Retrieves the current startup type of a Windows service by running <c>sc.exe qc</c>.</summary>
+ /// <param name="serviceName">The internal service name.</param>
+ /// <returns>The <see cref="ServiceStartupType"/> if parsed successfully, otherwise <see langword="null"/>.</returns>
public static async Task<ServiceStartupType?> GetStartupTypeAsync(string serviceName)
{
try
@@ -76,6 +79,9 @@ public static class ServiceProcessService
}
}
+ /// <summary>Changes the startup type of a single Windows service via <c>sc.exe config</c>. Records a revert step if the original type differs.</summary>
+ /// <param name="item">The service item with the target startup type.</param>
+ /// <returns><see langword="true"/> if the change succeeded, otherwise <see langword="false"/>.</returns>
public static async Task<bool> ChangeServiceStartupTypeAsync(ServiceItem item)
{
_lastError.Value = _lastErrorDetail.Value = null;
diff --git a/optimizerDuck/Services/System/RegistryWatcher.cs b/optimizerDuck/Services/System/RegistryWatcher.cs
index 011b52a..17be293 100644
--- a/optimizerDuck/Services/System/RegistryWatcher.cs
+++ b/optimizerDuck/Services/System/RegistryWatcher.cs
@@ -4,10 +4,18 @@ using Microsoft.Extensions.Logging;
namespace optimizerDuck.Services;
+/// <summary>Monitors Windows registry keys for changes using RegNotifyChangeKeyValue.</summary>
public interface IRegistryWatcher : IDisposable
{
+ /// <summary>Raised when a watched registry key or its values change. The event argument is the registry path that changed.</summary>
event EventHandler<string>? RegistryKeyChanged;
+
+ /// <summary>Starts watching the specified registry path for changes. Multiple paths can be watched simultaneously.</summary>
+ /// <param name="registryPath">The full registry path (e.g., "HKCU\Software\Microsoft\Windows\CurrentVersion\Run").</param>
void Watch(string registryPath);
+
+ /// <summary>Stops watching the specified registry path.</summary>
+ /// <param name="registryPath">The registry path to stop watching.</param>
void Unwatch(string registryPath);
}
diff --git a/optimizerDuck/Services/System/StreamService.cs b/optimizerDuck/Services/System/StreamService.cs
index fb68551..3aab318 100644
--- a/optimizerDuck/Services/System/StreamService.cs
+++ b/optimizerDuck/Services/System/StreamService.cs
@@ -9,6 +9,15 @@ public class StreamService(ILogger<StreamService> logger) : IDisposable
{
private HttpClient? _client;
+ /// <summary>Downloads a file from the specified URL and saves it to the local downloads directory.</summary>
+ /// <param name="url">The URL to download from.</param>
+ /// <param name="fileName">The target file name (not path) to save as.</param>
+ /// <returns>A tuple where <c>Success</c> indicates whether the download completed, and <c>FilePath</c> is the full local path on success.</returns>
+ /// <example>
+ /// <code language="csharp">
+ /// var (success, path) = await streamService.TryDownloadAsync("https://example.com/file.zip", "file.zip");
+ /// </code>
+ /// </example>
public async Task<(bool Success, string? FilePath)> TryDownloadAsync(
string url,
string fileName
@@ -68,6 +77,7 @@ public class StreamService(ILogger<StreamService> logger) : IDisposable
}
}
+ /// <summary>Releases the underlying <see cref="HttpClient"/> resources.</summary>
public void Dispose()
{
_client?.Dispose();
diff --git a/optimizerDuck/Services/System/SystemInfoService.cs b/optimizerDuck/Services/System/SystemInfoService.cs
index 74f6c9b..0f693f0 100644
--- a/optimizerDuck/Services/System/SystemInfoService.cs
+++ b/optimizerDuck/Services/System/SystemInfoService.cs
@@ -934,6 +934,9 @@ public static class DiskHelper
IntPtr lpOverlapped
);
+ /// <summary>Detects the storage media type for the given drive letter using a combination of seek-penalty detection and WMI queries.</summary>
+ /// <param name="driveLetter">The drive letter (e.g., "C:" or "C:\").</param>
+ /// <returns>A string describing the media type (e.g., "SSD", "HDD"), or "Unknown" if detection fails.</returns>
public static string DetectMediaType(string driveLetter)
{
// Try multiple detection methods
@@ -1074,6 +1077,9 @@ public static class DiskHelper
return "Unknown";
}
+ /// <summary>Determines whether the specified drive letter is the system drive (where Windows is installed).</summary>
+ /// <param name="driveLetter">The drive letter to check.</param>
+ /// <returns><see langword="true"/> if the drive is the system drive, otherwise <see langword="false"/>.</returns>
public static bool IsSystemDrive(string driveLetter)
{
var systemDrive = Path.GetPathRoot(Environment.SystemDirectory)?.TrimEnd('\\') ?? "C:";
diff --git a/optimizerDuck/Services/System/UpdaterService.cs b/optimizerDuck/Services/System/UpdaterService.cs
index e4b3683..74e4413 100644
--- a/optimizerDuck/Services/System/UpdaterService.cs
+++ b/optimizerDuck/Services/System/UpdaterService.cs
@@ -11,11 +11,14 @@ public class UpdaterService : IDisposable
private const string Owner = "itsfatduck";
private const string Repo = "optimizerDuck";
+ /// <summary>The URL to the latest release page on GitHub.</summary>
public const string LatestReleaseUrl = $"https://github.com/{Owner}/{Repo}/releases/latest";
private readonly HttpClient _httpClient;
private readonly ILogger _logger;
+ /// <summary>Initializes a new instance of the <see cref="UpdaterService"/> class.</summary>
+ /// <param name="logger">The logger for update diagnostics.</param>
public UpdaterService(ILogger<UpdaterService> logger)
{
_httpClient = new HttpClient();
@@ -25,6 +28,8 @@ public class UpdaterService : IDisposable
_logger = logger;
}
+ /// <summary>Checks the GitHub API for a newer version of the application.</summary>
+ /// <returns>A tuple where <c>Result</c> is <see langword="true"/> if a newer version exists, and <c>Version</c> is the latest version string.</returns>
public async Task<(bool Result, string? Version)> CheckForUpdatesAsync()
{
_logger.LogInformation(
@@ -100,6 +105,7 @@ public class UpdaterService : IDisposable
return (false, null);
}
}
+ /// <summary>Releases the underlying <see cref="HttpClient"/> resources.</summary>
public void Dispose()
{
_httpClient.Dispose();
@@ -107,23 +113,30 @@ public class UpdaterService : IDisposable
}
// Helper classes for deserializing GitHub API response
+/// <summary>Represents a GitHub release fetched from the API. Used internally for deserialization.</summary>
public class GitHubRelease
{
+ /// <summary>Gets or sets the release tag name (e.g., "v1.2.0").</summary>
[JsonProperty("tag_name")]
public required string TagName { get; set; }
+ /// <summary>Gets or sets the list of assets attached to this release.</summary>
[JsonProperty("assets")]
public required List<GitHubAsset> Assets { get; set; }
+ /// <summary>Gets or sets the release body text (release notes).</summary>
[JsonProperty("body")]
public required string Body { get; set; }
}
+/// <summary>Represents a downloadable asset attached to a GitHub release.</summary>
public class GitHubAsset
{
+ /// <summary>Gets or sets the file name of the asset.</summary>
[JsonProperty("name")]
public required string Name { get; set; }
+ /// <summary>Gets or sets the browser-download URL for the asset.</summary>
[JsonProperty("browser_download_url")]
public required string BrowserDownloadUrl { get; set; }
}
diff --git a/optimizerDuck/Services/UI/StartupManagerService.cs b/optimizerDuck/Services/UI/StartupManagerService.cs
index feb30c7..cc6f900 100644
--- a/optimizerDuck/Services/UI/StartupManagerService.cs
+++ b/optimizerDuck/Services/UI/StartupManagerService.cs
@@ -15,6 +15,8 @@ namespace optimizerDuck.Services.UI;
public class StartupManagerService(ILogger<StartupManagerService> logger)
{
+ /// <summary>Retrieves all startup applications from registry Run/RunOnce keys and startup folders, including their enabled state and icons.</summary>
+ /// <returns>A list of <see cref="StartupApp"/> instances sorted by name.</returns>
public async Task<List<StartupApp>> GetStartupAppsAsync()
{
var apps = new List<StartupApp>();
@@ -201,6 +203,9 @@ public class StartupManagerService(ILogger<StartupManagerService> logger)
}
}
+ /// <summary>Enables or disables a startup application by writing the StartupApproved registry flag.</summary>
+ /// <param name="app">The startup app to toggle.</param>
+ /// <param name="enable"><see langword="true"/> to enable, <see langword="false"/> to disable.</param>
public async Task ToggleStartupApp(StartupApp app, bool enable)
{
await Task.Run(() =>
@@ -281,6 +286,8 @@ public class StartupManagerService(ILogger<StartupManagerService> logger)
approvedKey.SetValue(app.OriginalValueNameOrFileName, data, RegistryValueKind.Binary);
}
+ /// <summary>Retrieves all startup scheduled tasks from the Windows Task Scheduler, including their enabled state and icons.</summary>
+ /// <returns>A list of <see cref="StartupTask"/> instances sorted by name.</returns>
public Task<List<StartupTask>> GetStartupTasksAsync()
{
return Task.Run(() =>
@@ -323,6 +330,9 @@ public class StartupManagerService(ILogger<StartupManagerService> logger)
});
}
+ /// <summary>Enables or disables a startup scheduled task using the Task Scheduler API.</summary>
+ /// <param name="task">The startup task to toggle.</param>
+ /// <param name="enable"><see langword="true"/> to enable, <see langword="false"/> to disable.</param>
public Task ToggleStartupTask(StartupTask task, bool enable)
{
return Task.Run(() =>
@@ -348,6 +358,14 @@ public class StartupManagerService(ILogger<StartupManagerService> logger)
});
}
+ /// <summary>Extracts the associated icon from an executable path or command string. Expands environment variables and searches PATH if needed.</summary>
+ /// <param name="command">The command or file path to extract the icon from.</param>
+ /// <returns>A frozen <see cref="BitmapSource"/> suitable for cross-thread UI binding, or <see langword="null"/> if the icon cannot be extracted.</returns>
+ /// <example>
+ /// <code language="csharp">
+ /// var icon = StartupManagerService.ExtractIcon(@"C:\Windows\System32\notepad.exe");
+ /// </code>
+ /// </example>
public static BitmapSource? ExtractIcon(string command)
{
try
@@ -396,6 +414,9 @@ public class StartupManagerService(ILogger<StartupManagerService> logger)
return null;
}
+ /// <summary>Resolves a file name to its full path by searching the directories listed in the PATH environment variable.</summary>
+ /// <param name="fileName">The file name (e.g., "notepad.exe") to resolve.</param>
+ /// <returns>The full path if found, otherwise <see langword="null"/>.</returns>
public static string? GetFullPathFromEnvironment(string fileName)
{
if (File.Exists(fileName))
diff --git a/optimizerDuck/optimizerDuck.csproj b/optimizerDuck/optimizerDuck.csproj
index 8405501..226db6a 100644
--- a/optimizerDuck/optimizerDuck.csproj
+++ b/optimizerDuck/optimizerDuck.csproj
@@ -42,9 +42,9 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
- <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.8" />
- <PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
- <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.8" />
+ <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.9" />
+ <PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.9" />
+ <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.9" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Serilog" Version="4.3.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="10.0.0" />