024673dcbe
## Summary Adds a safe in-app updater for ThreadPilot. This PR does not bump the app version and does not prepare a release; version and release metadata will be handled separately for v1.4.0. ## Type of Change - [x] Feature - [x] Security hardening - [x] Documentation - [x] Added/updated tests ## Update flow - Checks for updates on demand from Settings. - Performs background startup checks only when enabled and the last check is older than the configured interval. - Defaults to a 7-day interval. - Excludes prereleases by default. - Notifies users when an update is available. - Requires explicit user action before download/install. ## Security and safety - Uses release metadata from the official `PrimeBuild-pc/ThreadPilot` repository only. - Selects safe ThreadPilot installer assets from GitHub HTTPS release assets. - Downloads into a ThreadPilot-owned temp update directory. - Verifies SHA256 checksums when `SHA256SUMS.txt` is available. - Rejects checksum mismatches. - Performs best-effort Authenticode verification and rejects explicitly invalid signatures. - Starts the installer elevated without shell command construction. - Prevents concurrent install attempts. ## User data preservation - Update flow does not delete AppData, settings, profiles, CPU masks, rules, custom/imported power plans, or logs. - Only updater temp files are cleaned. - Full uninstall behavior remains separate. ## Validation - `dotnet restore ThreadPilot_1.sln`: passed - `dotnet build ThreadPilot_1.sln`: passed, 0 warnings, 0 errors - `dotnet test ThreadPilot_1.sln`: passed, 537 tests ## Release note This PR intentionally leaves `ThreadPilot.csproj` at `1.3.1`. The `1.4.0` version bump, changelog, packaging metadata, and tag should happen in a separate release-prep branch after this PR is merged.
65 lines
2.3 KiB
C#
65 lines
2.3 KiB
C#
/*
|
|
* ThreadPilot - elevated update installer launch.
|
|
*/
|
|
namespace ThreadPilot.Services
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
public sealed class UpdateInstallerService : IUpdateInstallerService
|
|
{
|
|
private readonly IUpdateTempDirectoryProvider tempDirectoryProvider;
|
|
private readonly IUpdateProcessLauncher processLauncher;
|
|
|
|
public UpdateInstallerService(
|
|
IUpdateTempDirectoryProvider tempDirectoryProvider,
|
|
IUpdateProcessLauncher processLauncher)
|
|
{
|
|
this.tempDirectoryProvider = tempDirectoryProvider ?? throw new ArgumentNullException(nameof(tempDirectoryProvider));
|
|
this.processLauncher = processLauncher ?? throw new ArgumentNullException(nameof(processLauncher));
|
|
}
|
|
|
|
public Task LaunchInstallerElevatedAsync(string installerPath, CancellationToken cancellationToken = default)
|
|
{
|
|
if (!File.Exists(installerPath))
|
|
{
|
|
throw new FileNotFoundException("Update installer was not found.", installerPath);
|
|
}
|
|
|
|
if (!string.Equals(Path.GetExtension(installerPath), ".exe", StringComparison.OrdinalIgnoreCase) ||
|
|
!this.tempDirectoryProvider.IsSafeUpdateTempPath(installerPath))
|
|
{
|
|
throw new InvalidOperationException("Update installer path is not trusted.");
|
|
}
|
|
|
|
return this.processLauncher.LaunchElevatedAsync(installerPath, Array.Empty<string>(), cancellationToken);
|
|
}
|
|
}
|
|
|
|
public sealed class ShellUpdateProcessLauncher : IUpdateProcessLauncher
|
|
{
|
|
public Task LaunchElevatedAsync(string fileName, IReadOnlyList<string> arguments, CancellationToken cancellationToken = default)
|
|
{
|
|
var startInfo = new ProcessStartInfo
|
|
{
|
|
FileName = fileName,
|
|
UseShellExecute = true,
|
|
Verb = "runas",
|
|
WorkingDirectory = Path.GetDirectoryName(fileName) ?? Environment.CurrentDirectory,
|
|
};
|
|
|
|
foreach (var argument in arguments)
|
|
{
|
|
startInfo.ArgumentList.Add(argument);
|
|
}
|
|
|
|
Process.Start(startInfo);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|