feat(app): download the update and verify it against SHA256SUMS

Download now fetches the desktop setup of the latest release into
%TEMP%\Titano\updates\<tag>, keeps it only when its SHA-256 matches the
release's SHA256SUMS line, and shows it in Explorer. BRIEF 8.6 does not list
starting an installer among the allowed shell actions, so the user runs it.
A release without a setup or SHA256SUMS still opens its page; capture runs
never download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 22:20:45 +00:00
1 parent d0beb7d3bf
commit 85d091d1fe
11 files changed
+436 -15

No files matched your search

+3
View File
@@ -57,6 +57,9 @@
<Button Style="{StaticResource Button.Link}" FontSize="13" Margin="12,0,0,0" VerticalAlignment="Center" Content="{l:Loc About.Update.Download}"
Command="{Binding DownloadCommand}" ToolTip="{l:Loc Tooltips.About.Download}"
Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Link}" FontSize="13" Margin="12,0,0,0" VerticalAlignment="Center" Content="{l:Loc About.Update.ShowSetup}"
Command="{Binding ShowSetupCommand}" ToolTip="{l:Loc Tooltips.About.ShowSetup}"
Visibility="{Binding IsSetupReady, Converter={StaticResource BoolToVisibility}}" />
</StackPanel>
</Grid>
+71 -9
View File
@@ -15,22 +15,27 @@ namespace Titano.App.Sections;
/// <summary>
/// About (BRIEF §12.9): version and build, licence link, third-party notice (none), translation notice,
/// diagnostics bundle and the update check against the public releases repository (BRIEF §18).
/// diagnostics bundle and the update check against the public releases repository (BRIEF §18). Download fetches the
/// setup and verifies it against the release's SHA256SUMS, then shows it in Explorer: BRIEF §8.6 does not allow Titano
/// to start an installer, so the user runs it.
/// </summary>
public sealed class AboutViewModel : SectionViewModel
{
private ReleaseInfo? _release;
private UpdateState _state = UpdateState.Unknown;
private double _downloaded;
private string? _setupPath;
public AboutViewModel(ShellViewModel shell)
: base(SectionKey.About, "Icon.About")
{
Shell = shell;
CheckCommand = new AsyncRelayCommand(() => CheckAsync(notify: false), () => _state != UpdateState.Checking);
DownloadCommand = new RelayCommand(() =>
CheckCommand = new AsyncRelayCommand(() => CheckAsync(notify: false), () => _state is not (UpdateState.Checking or UpdateState.Downloading));
DownloadCommand = new AsyncRelayCommand(DownloadAsync, () => _release is not null && _state != UpdateState.Downloading);
ShowSetupCommand = new RelayCommand(() =>
{
if (_release is { } release) ShellActions.OpenUrl(release.PageUrl);
}, () => _release is not null);
if (_setupPath is { } path) ShellActions.Reveal(path);
}, () => _setupPath is not null);
OpenReleasesCommand = new RelayCommand(() => ShellActions.OpenUrl(ProductLinks.Releases));
OpenLicenceCommand = new RelayCommand(() => ShellActions.OpenUrl(ProductLinks.Licence));
ReviewTranslationCommand = new RelayCommand(() => ShellActions.OpenUrl(ProductLinks.Issues));
@@ -45,6 +50,10 @@ public sealed class AboutViewModel : SectionViewModel
UpToDate,
Available,
Failed,
Downloading,
Downloaded,
DownloadFailed,
NotVerified,
}
public ShellViewModel Shell { get; }
@@ -66,6 +75,7 @@ public sealed class AboutViewModel : SectionViewModel
public ICommand CheckCommand { get; }
public ICommand DownloadCommand { get; }
public ICommand ShowSetupCommand { get; }
public ICommand OpenReleasesCommand { get; }
public ICommand OpenLicenceCommand { get; }
public ICommand ReviewTranslationCommand { get; }
@@ -79,20 +89,28 @@ public sealed class AboutViewModel : SectionViewModel
UpdateState.UpToDate => Loc.L("About.Update.Current"),
UpdateState.Available when _release is { } r => Loc.L("About.Update.Available", UpdateCheck.Display(r.Version)),
UpdateState.Failed => Loc.L("About.Update.Failed"),
UpdateState.Downloading => Loc.L("About.Update.Downloading", _downloaded),
UpdateState.Downloaded when _release is { } r => Loc.L("About.Update.Ready", UpdateCheck.Display(r.Version)),
UpdateState.DownloadFailed => Loc.L("About.Update.DownloadFailed"),
UpdateState.NotVerified => Loc.L("About.Update.NotVerified"),
_ => null,
};
public StatusKind UpdateKind => _state switch
{
UpdateState.Checking => StatusKind.Running,
UpdateState.UpToDate => StatusKind.Done,
UpdateState.Checking or UpdateState.Downloading => StatusKind.Running,
UpdateState.UpToDate or UpdateState.Downloaded => StatusKind.Done,
UpdateState.Available => StatusKind.Warning,
_ => StatusKind.Error,
};
public bool HasUpdateText => UpdateText is not null;
public bool IsUpdateAvailable => _state == UpdateState.Available;
/// <summary>Download is offered: a newer release exists and no verified setup is waiting (a failed download can be retried).</summary>
public bool IsUpdateAvailable => _state is UpdateState.Available or UpdateState.DownloadFailed or UpdateState.NotVerified;
/// <summary>The verified setup is in the temporary folder.</summary>
public bool IsSetupReady => _state == UpdateState.Downloaded;
/// <summary>Starts the update check on start when allowed (opt-out, BRIEF §18).</summary>
public void Attach()
@@ -105,6 +123,7 @@ public sealed class AboutViewModel : SectionViewModel
{
_release = release is not null && UpdateCheck.IsNewer(release, UpdateCheck.RunningVersion(Version)) ? release : null;
_state = failed ? UpdateState.Failed : _release is null ? UpdateState.UpToDate : UpdateState.Available;
_setupPath = null;
RaiseUpdate();
}
@@ -120,7 +139,7 @@ public sealed class AboutViewModel : SectionViewModel
if (notify && _release is { } newer)
{
Shell.Notify(Loc.L("About.Update.Available", UpdateCheck.Display(newer.Version)), actionText: Loc.L("About.Update.Download"),
actionToolTip: Loc.L("Tooltips.About.Download"), action: () => ShellActions.OpenUrl(newer.PageUrl));
actionToolTip: Loc.L("Tooltips.About.Download"), action: () => DownloadCommand.Execute(null));
}
}
catch (Exception ex) when (ex is HttpRequestException or OperationCanceledException or IOException)
@@ -130,6 +149,48 @@ public sealed class AboutViewModel : SectionViewModel
}
}
/// <summary>
/// Downloads and verifies the setup, then shows it in Explorer. A release without a setup or SHA256SUMS only opens
/// the release page; a capture run never touches the network.
/// </summary>
private async Task DownloadAsync()
{
if (_release is not { } release || Shell.Services.Environment.IsCapture) return;
if (!UpdateDownload.CanDownload(release))
{
ShellActions.OpenUrl(release.PageUrl);
return;
}
_state = UpdateState.Downloading;
_downloaded = 0;
RaiseUpdate();
var progress = new Progress<double>(fraction =>
{
if (_state != UpdateState.Downloading || fraction - _downloaded < 0.01) return;
_downloaded = fraction;
OnPropertyChanged(nameof(UpdateText));
});
try
{
using var timeout = new CancellationTokenSource(TimeSpan.FromMinutes(30));
_setupPath = await Shell.Services.DownloadUpdateAsync(release, progress, timeout.Token);
_state = UpdateState.Downloaded;
Log.Info("update", $"Setup of {release.Tag} downloaded and verified: {_setupPath}");
ShellActions.Reveal(_setupPath);
}
catch (UpdateVerificationException ex)
{
Log.Warning("update", "Update download refused: " + ex.Message);
_state = UpdateState.NotVerified;
}
catch (Exception ex) when (ex is HttpRequestException or OperationCanceledException or IOException or UnauthorizedAccessException)
{
Log.Warning("update", "Update download failed: " + ex.Message);
_state = UpdateState.DownloadFailed;
}
RaiseUpdate();
}
private async Task DiagnosticsAsync()
{
var folder = Shell.Services.Dialogs.PickFolder(Loc.L("Settings.Advanced.DiagnosticsTitle"));
@@ -144,6 +205,7 @@ public sealed class AboutViewModel : SectionViewModel
OnPropertyChanged(nameof(UpdateKind));
OnPropertyChanged(nameof(HasUpdateText));
OnPropertyChanged(nameof(IsUpdateAvailable));
OnPropertyChanged(nameof(IsSetupReady));
CommandManager.InvalidateRequerySuggested();
}
}
@@ -294,6 +294,9 @@
<Button Style="{StaticResource Button.Link}" Content="{l:Loc About.Update.Download}" Command="{Binding Shell.About.DownloadCommand}" ToolTip="{l:Loc Tooltips.About.Download}"
VerticalAlignment="Center" Margin="12,0,0,0" FontSize="13"
Visibility="{Binding Shell.About.IsUpdateAvailable, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Link}" Content="{l:Loc About.Update.ShowSetup}" Command="{Binding Shell.About.ShowSetupCommand}" ToolTip="{l:Loc Tooltips.About.ShowSetup}"
VerticalAlignment="Center" Margin="12,0,0,0" FontSize="13"
Visibility="{Binding Shell.About.IsSetupReady, Converter={StaticResource BoolToVisibility}}" />
</WrapPanel>
</HeaderedContentControl>
</StackPanel>