Implements C6 + C2 from docs/Extra.md Part 2, with a safe design that preserves the Elevator invariant (no new privileged write path). - Catalog: optional affectedRegistryValues field (RegistryValueRef in Domain + DTO + mapping), declared on tweak.showext / tweak.showhidden. - Application: IRegistryService (read-only) + pure RegistrySnapshot (Capture + Diff -> RegistryChange). - Infrastructure: WindowsRegistryService over Microsoft.Win32.Registry; unknown hive / missing key / access error all read as null. - WPF: after a run with affectedRegistryValues, MainViewModel re-reads the values and appends a localized before/after diff to the console. - Undo (C2): History entries whose command has a vetted RevertCommandId get an "Undo" button that runs that catalog revert command — NO arbitrary registry writes, the Elevator still only accepts catalog ids. - EN/VI .resx; docs (Changelog/roadmap/Security.md §4). - Tests: snapshot diff (null/changed), Win32 read smoke (known/missing/ bad hive), and the catalog schema field. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
55 lines
2.3 KiB
C#
55 lines
2.3 KiB
C#
using System.Globalization;
|
|
using CommandForge.Domain;
|
|
using CommandForge.Wpf.Resources;
|
|
|
|
namespace CommandForge.Wpf.ViewModels;
|
|
|
|
/// <summary>One row in the execution-history list: a past run with its resolved title and display strings.</summary>
|
|
public sealed class HistoryEntryViewModel
|
|
{
|
|
private readonly ExecutionRecord _record;
|
|
|
|
public HistoryEntryViewModel(ExecutionRecord record, string title, string? icon, bool canRun, string? revertCommandId)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(record);
|
|
|
|
_record = record;
|
|
Title = title;
|
|
Icon = icon;
|
|
CanRun = canRun;
|
|
RevertCommandId = revertCommandId;
|
|
}
|
|
|
|
/// <summary>The catalog id of the command that ran.</summary>
|
|
public string CommandId => _record.CommandId;
|
|
|
|
/// <summary>Resolved command title, or the raw id if the command is no longer in the catalog.</summary>
|
|
public string Title { get; }
|
|
|
|
/// <summary>Material icon name, or null if the command is no longer in the catalog.</summary>
|
|
public string? Icon { get; }
|
|
|
|
/// <summary>Whether the command still exists in the catalog (so it can be opened / re-run).</summary>
|
|
public bool CanRun { get; }
|
|
|
|
/// <summary>Id of the vetted catalog command that reverts this run, or null if not reversible.</summary>
|
|
public string? RevertCommandId { get; }
|
|
|
|
/// <summary>Whether this run can be undone by running its (vetted) revert command.</summary>
|
|
public bool CanUndo => RevertCommandId is not null;
|
|
|
|
/// <summary>The run time, formatted in the local time zone and current culture.</summary>
|
|
public string TimeText => _record.Timestamp.ToLocalTime().ToString("g", CultureInfo.CurrentCulture);
|
|
|
|
/// <summary>Localized status — reuses the execution-result strings (Success / Failed).</summary>
|
|
public string StatusText => Strings.Get(_record.Success ? "Result_Success" : "Result_Failed");
|
|
|
|
/// <summary>Whether the run succeeded (drives the status colour in the view).</summary>
|
|
public bool Success => _record.Success;
|
|
|
|
/// <summary>Human-readable duration (milliseconds under one second, otherwise seconds).</summary>
|
|
public string DurationText => _record.DurationMs < 1000
|
|
? string.Format(CultureInfo.CurrentCulture, "{0} ms", _record.DurationMs)
|
|
: string.Format(CultureInfo.CurrentCulture, "{0:F1} s", _record.DurationMs / 1000d);
|
|
}
|