Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43f94f1b65 | ||
|
|
bfc1b8c219 | ||
|
|
4c1be876f7 | ||
|
|
fa2bc278ce | ||
|
|
1bd91115d8 | ||
|
|
d9af1c5fcb | ||
|
|
dec3efaf68 | ||
|
|
1732f9371c | ||
|
|
ee90b5b746 | ||
|
|
200645e623 | ||
|
|
52aad7d7ff | ||
|
|
279aa3a24c | ||
|
|
de3ed23687 | ||
|
|
68e62f3f22 | ||
|
|
5126561937 | ||
|
|
c386021b81 | ||
|
|
594499d604 | ||
|
|
bc132b82e6 | ||
|
|
f1f974768b | ||
|
|
17d5a5cc19 | ||
|
|
60774a59c6 | ||
|
|
9332722997 | ||
|
|
3c20113651 | ||
|
|
fc985d259a | ||
|
|
a371cd1e48 | ||
|
|
3713c8189a | ||
|
|
ad91973a3f | ||
|
|
ef83c88083 |
No files matched your search
@@ -0,0 +1,94 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to **CommandForge** are documented here.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.2.0] — 2026-06-21
|
||||
|
||||
### Added
|
||||
- **38 new commands** across all ten categories (catalog grew from 78 to 116): installed
|
||||
updates / drivers / BIOS / programs / displays; active connections, ARP cache, routing table,
|
||||
Wi-Fi profiles and WinHTTP proxy; dark/light mode and Windows 11 taskbar-alignment and
|
||||
clock-seconds tweaks; thumbnail / font / Prefetch cleanup; the Balanced power plan, power
|
||||
requests and a Fast Startup toggle; Task Manager, Device Manager, Services and Group Policy
|
||||
result; winget source list and Microsoft Store reset; Defender status and full scan; firewall
|
||||
on/off; WSL shutdown, Windows Sandbox off and a long-paths toggle.
|
||||
- **Japanese (日本語) language.** A full Japanese translation joins English and Vietnamese,
|
||||
selectable in Settings and the View menu and switching live without a restart.
|
||||
|
||||
### Changed
|
||||
- **Version-aware command list.** Commands that only apply to a specific Windows version (such as
|
||||
the Windows 11 taskbar and clock tweaks) are now hidden automatically when they do not apply to
|
||||
your build of Windows.
|
||||
|
||||
## [1.1.1] — 2026-06-19
|
||||
|
||||
### Fixed
|
||||
- **User commands hanging on `cmd`.** A user-defined command using `cmd` (e.g.
|
||||
`ping google.com`) could stay "running" forever without responding. The process runner now
|
||||
redirects and immediately closes the child's standard input, so an interactive `cmd` receives
|
||||
EOF and exits instead of blocking. User commands that use `cmd` also get `/c` prepended
|
||||
automatically (`cmd` + `ping google.com` runs as `cmd /c ping google.com`), and the run
|
||||
confirmation shows the exact command line. PowerShell and other executables are unchanged.
|
||||
- **Recipes — duplicate steps.** A command already in a recipe can no longer be added again, so a
|
||||
recipe never runs the same command multiple times.
|
||||
- **Sidebar.** Hid the vertical scrollbar on the command-groups list (still scrollable by wheel).
|
||||
|
||||
## [1.1.0] — 2026-06-19
|
||||
|
||||
### Added
|
||||
- **Package & assembly metadata.** Product, author, company, copyright and repository information
|
||||
are embedded in the assemblies (shown in About and file properties) and in the Velopack
|
||||
installer.
|
||||
- **Execution history.** A new History screen lists finished runs (newest first) with time, status
|
||||
and duration, plus **Run again** and **Clear history**. Stored locally; no telemetry.
|
||||
- **Import / export & profiles.** Export your appearance, behavior and favorites to a `.json` file
|
||||
and import them on another machine. Save the current configuration as a named **profile**
|
||||
(e.g. "Gaming PC", "Office") and switch between them.
|
||||
- **Recipes (command chains).** Build a named sequence of vetted catalog commands and run them with
|
||||
a single aggregated confirmation, **one UAC prompt** for an all-admin chain, and **stop-on-error**
|
||||
(and stop-on-reboot-required) for safety.
|
||||
- **User-defined commands ("My commands").** Add your own commands. They are kept entirely separate
|
||||
from the vetted catalog and **always run without administrator rights**.
|
||||
- **Registry before/after & undo.** For applicable tweaks, the affected registry values are read
|
||||
before and after the run and a diff is shown in the console (read-only). History entries for
|
||||
reversible commands offer **Undo**, which runs the command's vetted revert command — no arbitrary
|
||||
registry writes.
|
||||
- **Home maintenance suggestions** (e.g. low disk space → Disk Cleanup; long uptime → restart) and
|
||||
**local natural-language search** (everyday phrases such as "clean disk" suggest a catalog
|
||||
keyword). Both are 100% local — no cloud, no LLM.
|
||||
|
||||
## [1.0.0] — 2026-06-18
|
||||
|
||||
Initial public release.
|
||||
|
||||
### Added
|
||||
- **Command catalog.** An embedded, vetted, read-only catalog of Windows commands organized by
|
||||
category, with fuzzy search and a Command Palette (Ctrl+K) and an exact command-line preview.
|
||||
- **Execution engine.** Real-time console output streamed off the UI thread, cancellation, and
|
||||
restart-required detection (exit code `3010`).
|
||||
- **Admin / UAC.** Elevated commands run through a separate `CommandForge.Elevator` broker over a
|
||||
named pipe (one UAC prompt per session); the main UI stays non-elevated.
|
||||
- **Safety.** Confirmation dialogs for Caution/Dangerous commands (type-to-confirm for Dangerous,
|
||||
which cannot be disabled), optional System Restore Point, and revert for reversible tweaks.
|
||||
- **Self-update** via Velopack (per-user, delta updates) from GitHub Releases.
|
||||
- **Localization & theming.** Full English/Vietnamese UI, light/dark/system themes, and font
|
||||
scaling.
|
||||
- **Home dashboard** with recent commands, favorites and a read-only system-status widget.
|
||||
- **Diagnostics.** Settings screen, Log Viewer (filter/export), Debug panel, a global crash handler
|
||||
and a "Report a bug" flow.
|
||||
- **Accessibility** (automation names, keyboard navigation, AA contrast) and a first-run Legal Gate
|
||||
(EULA / GPLv3 / Disclaimer / Privacy).
|
||||
- **CI/CD.** Build, test and CodeQL on every change; tag-triggered releases publish SHA-256
|
||||
checksums (and an optional VirusTotal scan). No telemetry — the only network use is checking
|
||||
GitHub for updates.
|
||||
|
||||
[Unreleased]: https://github.com/poli0981/CommandForge/compare/v1.2.0...HEAD
|
||||
[1.2.0]: https://github.com/poli0981/CommandForge/compare/v1.1.1...v1.2.0
|
||||
[1.1.1]: https://github.com/poli0981/CommandForge/compare/v1.1.0...v1.1.1
|
||||
[1.1.0]: https://github.com/poli0981/CommandForge/compare/v1.0.0...v1.1.0
|
||||
[1.0.0]: https://github.com/poli0981/CommandForge/releases/tag/v1.0.0
|
||||
@@ -23,4 +23,26 @@
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
Package / assembly metadata, inherited by every project. Surfaced in Settings -> About
|
||||
and the Report-Bug template (via Assembly.GetName().Version), in the file properties, and
|
||||
in the Velopack installer (scripts/pack.ps1 passes Authors via the packAuthors flag).
|
||||
|
||||
Version here is only the dev-build default; scripts/pack.ps1 overrides it at publish time
|
||||
with the Version/FileVersion/InformationalVersion properties off the git tag. AssemblyVersion is
|
||||
intentionally NOT pinned, so it follows Version and the in-app "App version" stays accurate
|
||||
(binding-redirect churn is a non-issue for a self-contained app, not a shared library).
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<Product>CommandForge</Product>
|
||||
<Authors>poli0981</Authors>
|
||||
<Company>poli0981</Company>
|
||||
<Copyright>Copyright © 2026 poli0981</Copyright>
|
||||
<Description>Run complex Windows system commands through a visual, categorized interface.</Description>
|
||||
<RepositoryUrl>https://github.com/poli0981/CommandForge</RepositoryUrl>
|
||||
<PackageProjectUrl>https://github.com/poli0981/CommandForge</PackageProjectUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<Version>1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -78,6 +78,7 @@ Velopack update mechanism works.
|
||||
|
||||
| Topic | File |
|
||||
|---|---|
|
||||
| Release history | [CHANGELOG.md](CHANGELOG.md) |
|
||||
| Build, test, publish, release | [BUILD.md](BUILD.md) · [RELEASING.md](RELEASING.md) |
|
||||
| Update mechanism (Velopack) | [UPDATES.md](UPDATES.md) |
|
||||
| Contributing & contribution rules | [CONTRIBUTING.md](.github/CONTRIBUTING.md) |
|
||||
|
||||
+3
-1
@@ -37,7 +37,7 @@ Write-Host "Publishing CommandForge $Version ($Runtime, $Configuration)..." -For
|
||||
dotnet publish $wpfProject `
|
||||
-c $Configuration -r $Runtime --self-contained true `
|
||||
-p:PublishSingleFile=false `
|
||||
-p:Version=$Version -p:InformationalVersion=$Version `
|
||||
-p:Version=$Version -p:FileVersion=$Version -p:InformationalVersion=$Version `
|
||||
-o $publishDir
|
||||
|
||||
# vpk is the Velopack CLI: dotnet tool install -g vpk
|
||||
@@ -48,6 +48,8 @@ if (-not (Get-Command vpk -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "Packing with Velopack..." -ForegroundColor Cyan
|
||||
vpk pack `
|
||||
--packId CommandForge `
|
||||
--packTitle CommandForge `
|
||||
--packAuthors poli0981 `
|
||||
--packVersion $Version `
|
||||
--packDir $publishDir `
|
||||
--mainExe CommandForge.Wpf.exe
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Application.History;
|
||||
|
||||
/// <summary>
|
||||
/// Pure helper for the execution-history list: newest first, capped at <see cref="MaxItems"/>.
|
||||
/// Unlike recent commands, history is NOT de-duplicated — each run is a distinct event.
|
||||
/// </summary>
|
||||
public static class ExecutionHistory
|
||||
{
|
||||
/// <summary>Maximum number of records retained (oldest are dropped beyond this).</summary>
|
||||
public const int MaxItems = 200;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new list with <paramref name="record"/> prepended (newest first) and capped at
|
||||
/// <see cref="MaxItems"/>. The input list is not mutated.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<ExecutionRecord> Add(IReadOnlyList<ExecutionRecord> current, ExecutionRecord record)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(current);
|
||||
ArgumentNullException.ThrowIfNull(record);
|
||||
|
||||
var result = new List<ExecutionRecord>(Math.Min(current.Count + 1, MaxItems)) { record };
|
||||
foreach (var existing in current)
|
||||
{
|
||||
if (result.Count >= MaxItems)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
result.Add(existing);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Application.Ports;
|
||||
|
||||
/// <summary>
|
||||
/// Persists a local history of finished command executions (newest first). All data stays on
|
||||
/// the machine (golden rule: no telemetry).
|
||||
/// </summary>
|
||||
public interface IExecutionHistoryService
|
||||
{
|
||||
/// <summary>The recorded executions, newest first.</summary>
|
||||
public IReadOnlyList<ExecutionRecord> GetRecent();
|
||||
|
||||
/// <summary>Appends a record (newest first), trims to the cap, and persists.</summary>
|
||||
public void Record(ExecutionRecord record);
|
||||
|
||||
/// <summary>Clears all history and persists.</summary>
|
||||
public void Clear();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CommandForge.Application.Settings;
|
||||
|
||||
namespace CommandForge.Application.Ports;
|
||||
|
||||
/// <summary>
|
||||
/// Stores named profiles — bundles of portable settings + favorites by context
|
||||
/// (e.g. "Gaming PC", "Office"). Persisted locally (golden rule: no telemetry).
|
||||
/// </summary>
|
||||
public interface IProfileService
|
||||
{
|
||||
/// <summary>Profile names, in stored order.</summary>
|
||||
public IReadOnlyList<string> GetNames();
|
||||
|
||||
/// <summary>The settings stored under <paramref name="name"/>, or null if none.</summary>
|
||||
public PortableSettings? Get(string name);
|
||||
|
||||
/// <summary>Creates or overwrites the profile <paramref name="name"/> and persists.</summary>
|
||||
public void Save(string name, PortableSettings settings);
|
||||
|
||||
/// <summary>Deletes the profile <paramref name="name"/> (no-op if absent) and persists.</summary>
|
||||
public void Delete(string name);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Application.Ports;
|
||||
|
||||
/// <summary>
|
||||
/// Stores user-defined recipes (named command chains) locally (golden rule: no telemetry).
|
||||
/// Recipes reference only vetted catalog command ids — never raw command lines.
|
||||
/// </summary>
|
||||
public interface IRecipeStore
|
||||
{
|
||||
/// <summary>All saved recipes, in stored order.</summary>
|
||||
public IReadOnlyList<Recipe> GetAll();
|
||||
|
||||
/// <summary>Creates or overwrites a recipe (matched by name, case-insensitive) and persists.</summary>
|
||||
public void Save(Recipe recipe);
|
||||
|
||||
/// <summary>Deletes the recipe <paramref name="name"/> (no-op if absent) and persists.</summary>
|
||||
public void Delete(string name);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Application.Ports;
|
||||
|
||||
/// <summary>
|
||||
/// Reads registry values for read-only before/after comparison. CommandForge never writes the
|
||||
/// registry through this service — changes happen only via vetted catalog commands.
|
||||
/// </summary>
|
||||
public interface IRegistryService
|
||||
{
|
||||
/// <summary>Reads the current value as a string, or null if the key/value does not exist.</summary>
|
||||
public string? Read(RegistryValueRef reference);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using CommandForge.Application.Settings;
|
||||
|
||||
namespace CommandForge.Application.Ports;
|
||||
|
||||
/// <summary>
|
||||
/// Reads/writes portable settings to a user-chosen file (import/export between machines).
|
||||
/// </summary>
|
||||
public interface ISettingsFile
|
||||
{
|
||||
/// <summary>Writes <paramref name="settings"/> to <paramref name="path"/> as JSON.</summary>
|
||||
public void Write(string path, PortableSettings settings);
|
||||
|
||||
/// <summary>Reads portable settings from <paramref name="path"/>; null if missing or invalid.</summary>
|
||||
public PortableSettings? Read(string path);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public interface ISettingsService
|
||||
/// <summary>The UI color theme (default <see cref="AppTheme.System"/>).</summary>
|
||||
public AppTheme Theme { get; set; }
|
||||
|
||||
/// <summary>UI language: <c>""</c> = follow OS, otherwise a culture code such as <c>"en"</c> or <c>"vi"</c>.</summary>
|
||||
/// <summary>UI language: <c>""</c> = follow OS, otherwise a culture code such as <c>"en"</c>, <c>"vi"</c> or <c>"ja"</c>.</summary>
|
||||
public string Language { get; set; }
|
||||
|
||||
/// <summary>The overall UI font size (default <see cref="FontScale.Medium"/>).</summary>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Application.Ports;
|
||||
|
||||
/// <summary>
|
||||
/// Stores user-defined commands locally, fully separate from the vetted embedded catalog
|
||||
/// (golden rule #1). These commands always run without elevation.
|
||||
/// </summary>
|
||||
public interface IUserCommandStore
|
||||
{
|
||||
/// <summary>All user-defined commands, in stored order.</summary>
|
||||
public IReadOnlyList<UserCommand> GetAll();
|
||||
|
||||
/// <summary>Creates or overwrites a command (matched by id) and persists.</summary>
|
||||
public void Save(UserCommand command);
|
||||
|
||||
/// <summary>Deletes the command <paramref name="id"/> (no-op if absent) and persists.</summary>
|
||||
public void Delete(string id);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Application.Recipes;
|
||||
|
||||
/// <summary>Pure decision logic for running a recipe sequentially.</summary>
|
||||
public static class RecipeFlow
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the recipe must stop after a step that produced this result: a failure, a
|
||||
/// cancellation, or a reboot-required signal (remaining steps may depend on the restart, so
|
||||
/// the safe default is to stop and let the user reboot).
|
||||
/// </summary>
|
||||
public static bool ShouldStop(ExecutionResult result)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(result);
|
||||
|
||||
return result.Cancelled || !result.Success || result.RequiresRestart;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Application.Registry;
|
||||
|
||||
/// <summary>A single before→after change of a registry value.</summary>
|
||||
public sealed record RegistryChange(RegistryValueRef Reference, string? Before, string? After);
|
||||
|
||||
/// <summary>Pure helpers to snapshot and diff a set of registry values (read-only).</summary>
|
||||
public static class RegistrySnapshot
|
||||
{
|
||||
/// <summary>Reads the current value of each reference into a snapshot.</summary>
|
||||
public static IReadOnlyDictionary<RegistryValueRef, string?> Capture(
|
||||
IRegistryService registry,
|
||||
IReadOnlyList<RegistryValueRef> references)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(registry);
|
||||
ArgumentNullException.ThrowIfNull(references);
|
||||
|
||||
var snapshot = new Dictionary<RegistryValueRef, string?>();
|
||||
foreach (var reference in references)
|
||||
{
|
||||
snapshot[reference] = registry.Read(reference);
|
||||
}
|
||||
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
/// <summary>Returns the references whose value changed between the two snapshots.</summary>
|
||||
public static IReadOnlyList<RegistryChange> Diff(
|
||||
IReadOnlyList<RegistryValueRef> references,
|
||||
IReadOnlyDictionary<RegistryValueRef, string?> before,
|
||||
IReadOnlyDictionary<RegistryValueRef, string?> after)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(references);
|
||||
ArgumentNullException.ThrowIfNull(before);
|
||||
ArgumentNullException.ThrowIfNull(after);
|
||||
|
||||
var changes = new List<RegistryChange>();
|
||||
foreach (var reference in references)
|
||||
{
|
||||
before.TryGetValue(reference, out var b);
|
||||
after.TryGetValue(reference, out var a);
|
||||
if (!string.Equals(b, a, StringComparison.Ordinal))
|
||||
{
|
||||
changes.Add(new RegistryChange(reference, b, a));
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace CommandForge.Application.Search;
|
||||
|
||||
/// <summary>
|
||||
/// Local natural-language search: maps everyday EN/VI phrases to a catalog search keyword
|
||||
/// (e.g. "clean disk" / "dọn ổ đĩa" → "cleanup"). 100% LOCAL — no LLM, no network (golden rule #5).
|
||||
/// </summary>
|
||||
public static class NaturalLanguageSearch
|
||||
{
|
||||
// Lower-cased phrase fragment -> canonical keyword fed back into the existing fuzzy search.
|
||||
private static readonly (string Phrase, string Keyword)[] Map =
|
||||
[
|
||||
("free space", "cleanup"),
|
||||
("disk space", "cleanup"),
|
||||
("clean", "cleanup"),
|
||||
("dọn", "cleanup"),
|
||||
("dung lượng", "cleanup"),
|
||||
("slow", "cleanup"),
|
||||
("chậm", "cleanup"),
|
||||
("internet", "network"),
|
||||
("wifi", "network"),
|
||||
("network", "network"),
|
||||
("mạng", "network"),
|
||||
("dns", "network"),
|
||||
("update", "update"),
|
||||
("cập nhật", "update"),
|
||||
("battery", "battery"),
|
||||
("pin", "battery"),
|
||||
("driver", "driver"),
|
||||
("trình điều khiển", "driver"),
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Returns a suggested search keyword for a natural-language query, or null if nothing matches
|
||||
/// (or the query already equals the keyword, so we don't suggest what the user typed).
|
||||
/// </summary>
|
||||
public static string? Suggest(string? query)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var text = query.Trim().ToLowerInvariant();
|
||||
foreach (var (phrase, keyword) in Map)
|
||||
{
|
||||
if (text.Contains(phrase, StringComparison.Ordinal)
|
||||
&& !string.Equals(text, keyword, StringComparison.Ordinal))
|
||||
{
|
||||
return keyword;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using CommandForge.Application.Logging;
|
||||
|
||||
namespace CommandForge.Application.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// The machine-portable subset of settings — appearance, behavior/safety preferences and favorites —
|
||||
/// used for import/export and named profiles. Excludes machine-specific state (window placement,
|
||||
/// accepted terms version, recent commands, execution history).
|
||||
/// </summary>
|
||||
public sealed record PortableSettings
|
||||
{
|
||||
/// <summary>Schema version of the portable payload (for forward-compat).</summary>
|
||||
public int Version { get; init; } = 1;
|
||||
|
||||
public AppTheme Theme { get; init; } = AppTheme.System;
|
||||
|
||||
public string Language { get; init; } = "";
|
||||
|
||||
public FontScale FontSize { get; init; } = FontScale.Medium;
|
||||
|
||||
public bool CollapseSidebarByDefault { get; init; }
|
||||
|
||||
public bool ShowAdminRestartBadges { get; init; } = true;
|
||||
|
||||
public bool ConfirmCaution { get; init; } = true;
|
||||
|
||||
public bool AutoCreateRestorePoint { get; init; } = true;
|
||||
|
||||
public bool AutoScrollConsole { get; init; } = true;
|
||||
|
||||
public bool WarnOnCancel { get; init; } = true;
|
||||
|
||||
public bool AutoCheckForUpdates { get; init; } = true;
|
||||
|
||||
public LogLevel LogLevel { get; init; } = LogLevel.Information;
|
||||
|
||||
/// <summary>Pinned favorite command ids, in pin order.</summary>
|
||||
public IReadOnlyList<string> FavoriteCommandIds { get; init; } = [];
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using CommandForge.Application.Ports;
|
||||
|
||||
namespace CommandForge.Application.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Pure mapping between the live <see cref="ISettingsService"/> and the portable subset
|
||||
/// (<see cref="PortableSettings"/>) used for import/export and profiles.
|
||||
/// </summary>
|
||||
public static class SettingsTransfer
|
||||
{
|
||||
/// <summary>Reads the current portable settings from the live settings service.</summary>
|
||||
public static PortableSettings Capture(ISettingsService settings)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
|
||||
return new PortableSettings
|
||||
{
|
||||
Theme = settings.Theme,
|
||||
Language = settings.Language,
|
||||
FontSize = settings.FontSize,
|
||||
CollapseSidebarByDefault = settings.CollapseSidebarByDefault,
|
||||
ShowAdminRestartBadges = settings.ShowAdminRestartBadges,
|
||||
ConfirmCaution = settings.ConfirmCaution,
|
||||
AutoCreateRestorePoint = settings.AutoCreateRestorePoint,
|
||||
AutoScrollConsole = settings.AutoScrollConsole,
|
||||
WarnOnCancel = settings.WarnOnCancel,
|
||||
AutoCheckForUpdates = settings.AutoCheckForUpdates,
|
||||
LogLevel = settings.LogLevel,
|
||||
FavoriteCommandIds = settings.FavoriteCommandIds,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the portable settings into the live settings service (does NOT call Save, and does
|
||||
/// not apply live UI effects — callers persist and re-apply). Used in non-UI contexts and tests.
|
||||
/// </summary>
|
||||
public static void Apply(PortableSettings portable, ISettingsService settings)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(portable);
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
|
||||
settings.Theme = portable.Theme;
|
||||
settings.Language = portable.Language;
|
||||
settings.FontSize = portable.FontSize;
|
||||
settings.CollapseSidebarByDefault = portable.CollapseSidebarByDefault;
|
||||
settings.ShowAdminRestartBadges = portable.ShowAdminRestartBadges;
|
||||
settings.ConfirmCaution = portable.ConfirmCaution;
|
||||
settings.AutoCreateRestorePoint = portable.AutoCreateRestorePoint;
|
||||
settings.AutoScrollConsole = portable.AutoScrollConsole;
|
||||
settings.WarnOnCancel = portable.WarnOnCancel;
|
||||
settings.AutoCheckForUpdates = portable.AutoCheckForUpdates;
|
||||
settings.LogLevel = portable.LogLevel;
|
||||
settings.FavoriteCommandIds = portable.FavoriteCommandIds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using CommandForge.Application.Ports;
|
||||
|
||||
namespace CommandForge.Application.SystemInfo;
|
||||
|
||||
/// <summary>A maintenance hint derived from system status: a reason and an optional catalog command to run.</summary>
|
||||
public sealed record MaintenanceSuggestion(string ReasonKey, string? CommandId);
|
||||
|
||||
/// <summary>
|
||||
/// Pure, local heuristics mapping a <see cref="SystemStatus"/> to maintenance suggestions for the
|
||||
/// Home dashboard. No network, no telemetry — just thresholds over the read-only status snapshot.
|
||||
/// </summary>
|
||||
public static class MaintenanceSuggestions
|
||||
{
|
||||
/// <summary>Free system-drive space below this fraction triggers a cleanup suggestion.</summary>
|
||||
public const double LowDiskFreeFraction = 0.10;
|
||||
|
||||
/// <summary>Uptime at or above this triggers a restart suggestion.</summary>
|
||||
public static readonly TimeSpan HighUptime = TimeSpan.FromDays(7);
|
||||
|
||||
/// <summary>Returns the maintenance suggestions that apply to the given status (possibly empty).</summary>
|
||||
public static IReadOnlyList<MaintenanceSuggestion> For(SystemStatus status)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(status);
|
||||
|
||||
var suggestions = new List<MaintenanceSuggestion>();
|
||||
|
||||
if (status.SystemDriveTotalBytes > 0
|
||||
&& (double)status.SystemDriveFreeBytes / status.SystemDriveTotalBytes < LowDiskFreeFraction)
|
||||
{
|
||||
suggestions.Add(new MaintenanceSuggestion("Maint_LowDisk", "cleanup.cleanmgr"));
|
||||
}
|
||||
|
||||
if (status.Uptime >= HighUptime)
|
||||
{
|
||||
suggestions.Add(new MaintenanceSuggestion("Maint_HighUptime", null));
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Application.UserCommands;
|
||||
|
||||
/// <summary>
|
||||
/// Builds an executable <see cref="CommandDefinition"/> for a user-defined command.
|
||||
///
|
||||
/// SAFETY (golden rule #1): the produced definition ALWAYS has <see cref="CommandDefinition.RequiresAdmin"/>
|
||||
/// = false, so user commands run as the current (non-elevated) user and can never be routed to the
|
||||
/// elevation broker by <c>RunCommandUseCase</c>. The id is namespaced with <see cref="IdPrefix"/> so it
|
||||
/// can never collide with — or be mistaken for — a vetted catalog id; even if a bug routed it to the
|
||||
/// Elevator, the Elevator validates ids against its own embedded catalog and rejects anything else.
|
||||
/// </summary>
|
||||
public static class UserCommandFactory
|
||||
{
|
||||
/// <summary>Prefix marking an id as user-defined (never present in the vetted catalog).</summary>
|
||||
public const string IdPrefix = "user:";
|
||||
|
||||
/// <summary>Converts a user command to a non-elevated executable definition.</summary>
|
||||
public static CommandDefinition ToDefinition(UserCommand command)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
return new CommandDefinition
|
||||
{
|
||||
Id = IdPrefix + command.Id,
|
||||
CategoryId = "user",
|
||||
TitleKey = command.Name,
|
||||
DescriptionKey = command.Name,
|
||||
Executable = command.Executable,
|
||||
ArgsTemplate = NormalizeArguments(command.Executable, command.Arguments),
|
||||
ExecutionMode = ExecutionMode.Capture,
|
||||
RequiresAdmin = false, // INVARIANT — a user command must never elevate.
|
||||
DangerLevel = DangerLevel.Caution,
|
||||
Restart = RestartPolicy.No,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes arguments so a one-shot command actually runs and then exits. <c>cmd.exe</c>
|
||||
/// without <c>/c</c> (or <c>/k</c>) opens an interactive shell that blocks forever waiting on
|
||||
/// stdin, so for cmd we prepend <c>/c</c>. Other executables (e.g. powershell) are left as-is.
|
||||
/// </summary>
|
||||
public static string NormalizeArguments(string executable, string? arguments)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(executable);
|
||||
|
||||
var args = arguments ?? string.Empty;
|
||||
if (IsCmd(executable) && !HasCmdRunSwitch(args))
|
||||
{
|
||||
return args.Length == 0 ? "/c" : "/c " + args;
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
private static bool IsCmd(string executable)
|
||||
=> string.Equals(Path.GetFileNameWithoutExtension(executable.Trim()), "cmd", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static bool HasCmdRunSwitch(string arguments)
|
||||
{
|
||||
var trimmed = arguments.TrimStart();
|
||||
return StartsWithSwitch(trimmed, "/c") || StartsWithSwitch(trimmed, "/k");
|
||||
}
|
||||
|
||||
private static bool StartsWithSwitch(string text, string flag)
|
||||
=> text.StartsWith(flag, StringComparison.OrdinalIgnoreCase)
|
||||
&& (text.Length == flag.Length || char.IsWhiteSpace(text[flag.Length]));
|
||||
}
|
||||
@@ -53,6 +53,9 @@ public sealed record CommandDefinition
|
||||
/// <summary>Id of the command that reverts this one, if reversible.</summary>
|
||||
public string? RevertCommandId { get; init; }
|
||||
|
||||
/// <summary>Registry values this command may change, for read-only before/after comparison (optional).</summary>
|
||||
public IReadOnlyList<RegistryValueRef> AffectedRegistryValues { get; init; } = [];
|
||||
|
||||
/// <summary>Rough duration hint for the UI.</summary>
|
||||
public EstimatedDuration EstimatedDuration { get; init; } = EstimatedDuration.Short;
|
||||
|
||||
@@ -61,4 +64,23 @@ public sealed record CommandDefinition
|
||||
|
||||
/// <summary>Free-form search tags.</summary>
|
||||
public IReadOnlyList<string> Tags { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Inclusive lowest Windows build this command applies to (e.g. <c>22000</c> for Windows 11+).
|
||||
/// <see langword="null"/> means no lower bound.
|
||||
/// </summary>
|
||||
public int? MinOsBuild { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Inclusive highest Windows build this command applies to (e.g. <c>19045</c> for Windows 10 only).
|
||||
/// <see langword="null"/> means no upper bound.
|
||||
/// </summary>
|
||||
public int? MaxOsBuild { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this command applies to the given OS build. Pure logic (no Win32) so the presentation
|
||||
/// layer can hide commands that do not apply to the current Windows version.
|
||||
/// </summary>
|
||||
public bool AppliesToOsBuild(int build)
|
||||
=> (MinOsBuild is null || build >= MinOsBuild) && (MaxOsBuild is null || build <= MaxOsBuild);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace CommandForge.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// A record of one finished command execution, persisted for the execution-history view.
|
||||
/// </summary>
|
||||
public sealed record ExecutionRecord
|
||||
{
|
||||
/// <summary>The catalog id of the command that ran.</summary>
|
||||
public required string CommandId { get; init; }
|
||||
|
||||
/// <summary>When the run finished (clock instant, with offset).</summary>
|
||||
public required DateTimeOffset Timestamp { get; init; }
|
||||
|
||||
/// <summary>The process exit code.</summary>
|
||||
public required int ExitCode { get; init; }
|
||||
|
||||
/// <summary>Whether the run was considered successful (exit 0 or the reboot-required code).</summary>
|
||||
public required bool Success { get; init; }
|
||||
|
||||
/// <summary>Wall-clock duration in milliseconds.</summary>
|
||||
public required long DurationMs { get; init; }
|
||||
|
||||
/// <summary>Whether the run signalled that a restart is required (e.g. exit code 3010).</summary>
|
||||
public bool RequiresRestart { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace CommandForge.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// A named, ordered sequence of catalog command ids run together as one "recipe" (macro),
|
||||
/// e.g. CheckHealth → ScanHealth → RestoreHealth → SFC.
|
||||
/// </summary>
|
||||
public sealed record Recipe
|
||||
{
|
||||
/// <summary>User-visible recipe name (also the identity — matched case-insensitively).</summary>
|
||||
public required string Name { get; init; }
|
||||
|
||||
/// <summary>The catalog command ids to run, in order.</summary>
|
||||
public required IReadOnlyList<string> CommandIds { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace CommandForge.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to a single registry value that a command may modify, used for read-only
|
||||
/// before/after comparison. Reading only — CommandForge never writes the registry directly.
|
||||
/// </summary>
|
||||
public sealed record RegistryValueRef
|
||||
{
|
||||
/// <summary>Full key path including the hive prefix, e.g. <c>HKCU\Software\…\Advanced</c>.</summary>
|
||||
public required string Path { get; init; }
|
||||
|
||||
/// <summary>Value name under the key (empty string means the key's default value).</summary>
|
||||
public required string Name { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace CommandForge.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// A user-defined command. These are NOT part of the vetted, embedded catalog and ALWAYS run
|
||||
/// without elevation (asInvoker) — see golden rule #1. Stored separately from the catalog.
|
||||
/// </summary>
|
||||
public sealed record UserCommand
|
||||
{
|
||||
/// <summary>Stable local id (generated when the command is created).</summary>
|
||||
public required string Id { get; init; }
|
||||
|
||||
/// <summary>User-visible name.</summary>
|
||||
public required string Name { get; init; }
|
||||
|
||||
/// <summary>Executable to run (e.g. <c>cmd</c>, <c>powershell</c>, or a full path).</summary>
|
||||
public required string Executable { get; init; }
|
||||
|
||||
/// <summary>Command-line arguments (optional).</summary>
|
||||
public string Arguments { get; init; } = "";
|
||||
}
|
||||
@@ -20,6 +20,18 @@ public static class AppPaths
|
||||
/// <summary><c>%AppData%\CommandForge\config.json</c>.</summary>
|
||||
public static string ConfigFilePath { get; } = Path.Combine(DataDirectory, "config.json");
|
||||
|
||||
/// <summary><c>%AppData%\CommandForge\history.json</c> — persisted execution history.</summary>
|
||||
public static string HistoryFilePath { get; } = Path.Combine(DataDirectory, "history.json");
|
||||
|
||||
/// <summary><c>%AppData%\CommandForge\profiles.json</c> — named settings/favorites profiles.</summary>
|
||||
public static string ProfilesFilePath { get; } = Path.Combine(DataDirectory, "profiles.json");
|
||||
|
||||
/// <summary><c>%AppData%\CommandForge\recipes.json</c> — user-defined recipes (command chains).</summary>
|
||||
public static string RecipesFilePath { get; } = Path.Combine(DataDirectory, "recipes.json");
|
||||
|
||||
/// <summary><c>%AppData%\CommandForge\user-commands.json</c> — user-defined (non-elevated) commands.</summary>
|
||||
public static string UserCommandsFilePath { get; } = Path.Combine(DataDirectory, "user-commands.json");
|
||||
|
||||
/// <summary>Ensures the data and logs directories exist.</summary>
|
||||
public static void EnsureCreated()
|
||||
{
|
||||
|
||||
@@ -32,4 +32,14 @@ internal sealed record CommandDto
|
||||
public EstimatedDuration EstimatedDuration { get; init; }
|
||||
public string? DocUrl { get; init; }
|
||||
public string[]? Tags { get; init; }
|
||||
public RegistryValueDto[]? AffectedRegistryValues { get; init; }
|
||||
public int? MinOsBuild { get; init; }
|
||||
public int? MaxOsBuild { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>JSON shape of a registry-value reference (for before/after comparison).</summary>
|
||||
internal sealed record RegistryValueDto
|
||||
{
|
||||
public string? Path { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
@@ -73,6 +73,9 @@ public static class CatalogLoader
|
||||
if (string.IsNullOrWhiteSpace(dto.DescriptionKey)) { errors.Add($"Command '{dto.Id}' is missing descriptionKey."); continue; }
|
||||
if (string.IsNullOrWhiteSpace(dto.Executable)) { errors.Add($"Command '{dto.Id}' is missing executable."); continue; }
|
||||
if (dto.Restart == RestartPolicy.FromOutputRegex && !IsValidRegex(dto.RestartRegex)) { errors.Add($"Command '{dto.Id}' has an invalid restartRegex."); continue; }
|
||||
if (dto.MinOsBuild is <= 0) { errors.Add($"Command '{dto.Id}' has a non-positive minOsBuild."); continue; }
|
||||
if (dto.MaxOsBuild is <= 0) { errors.Add($"Command '{dto.Id}' has a non-positive maxOsBuild."); continue; }
|
||||
if (dto.MinOsBuild is { } minBuild && dto.MaxOsBuild is { } maxBuild && maxBuild < minBuild) { errors.Add($"Command '{dto.Id}' has maxOsBuild ({maxBuild}) less than minOsBuild ({minBuild})."); continue; }
|
||||
|
||||
commands.Add(new CommandDefinition
|
||||
{
|
||||
@@ -94,6 +97,14 @@ public static class CatalogLoader
|
||||
EstimatedDuration = dto.EstimatedDuration,
|
||||
DocUrl = dto.DocUrl,
|
||||
Tags = dto.Tags ?? [],
|
||||
AffectedRegistryValues = dto.AffectedRegistryValues is null
|
||||
? []
|
||||
: dto.AffectedRegistryValues
|
||||
.Where(r => !string.IsNullOrWhiteSpace(r.Path))
|
||||
.Select(r => new RegistryValueRef { Path = r.Path!, Name = r.Name ?? string.Empty })
|
||||
.ToList(),
|
||||
MinOsBuild = dto.MinOsBuild,
|
||||
MaxOsBuild = dto.MaxOsBuild,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -246,7 +246,10 @@
|
||||
"revertCommandId": "tweak.hideext",
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["explorer", "file extension", "registry", "tweak"]
|
||||
"tags": ["explorer", "file extension", "registry", "tweak"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "name": "HideFileExt" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "tweak.showhidden",
|
||||
@@ -265,7 +268,10 @@
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["explorer", "hidden files", "registry", "tweak"]
|
||||
"tags": ["explorer", "hidden files", "registry", "tweak"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "name": "Hidden" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "cleanup.cleanmgr",
|
||||
@@ -914,6 +920,7 @@
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.win11.modernmenu",
|
||||
"minOsBuild": 22000,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "context menu", "classic", "registry", "tweak"]
|
||||
@@ -933,6 +940,7 @@
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.win11.classicmenu",
|
||||
"minOsBuild": 22000,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "context menu", "modern", "registry", "tweak"]
|
||||
@@ -1466,7 +1474,7 @@
|
||||
"createsRestorePoint": false,
|
||||
"restart": "Always",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"revertCommandId": "dev.sandbox.off",
|
||||
"estimatedDuration": "Long",
|
||||
"docUrl": null,
|
||||
"tags": ["windows sandbox", "feature", "isolation", "developer"]
|
||||
@@ -1489,5 +1497,767 @@
|
||||
"estimatedDuration": "Long",
|
||||
"docUrl": null,
|
||||
"tags": [".net framework 3.5", "netfx3", "feature", "developer"]
|
||||
},
|
||||
{
|
||||
"id": "info.hotfixes",
|
||||
"categoryId": "system-info",
|
||||
"titleKey": "Cmd_info.hotfixes_Title",
|
||||
"descriptionKey": "Cmd_info.hotfixes_Desc",
|
||||
"icon": "Update",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object HotFixID,Description,InstalledOn | Format-Table -AutoSize\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Medium",
|
||||
"docUrl": null,
|
||||
"tags": ["updates", "hotfix", "patches", "history"]
|
||||
},
|
||||
{
|
||||
"id": "info.drivers",
|
||||
"categoryId": "system-info",
|
||||
"titleKey": "Cmd_info.drivers_Title",
|
||||
"descriptionKey": "Cmd_info.drivers_Desc",
|
||||
"icon": "Chip",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Get-CimInstance Win32_PnPSignedDriver | Select-Object DeviceName,DriverVersion,DriverProviderName | Sort-Object DeviceName | Format-Table -AutoSize\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Medium",
|
||||
"docUrl": null,
|
||||
"tags": ["drivers", "devices", "hardware", "info"]
|
||||
},
|
||||
{
|
||||
"id": "info.bios",
|
||||
"categoryId": "system-info",
|
||||
"titleKey": "Cmd_info.bios_Title",
|
||||
"descriptionKey": "Cmd_info.bios_Desc",
|
||||
"icon": "Chip",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Get-CimInstance Win32_BIOS | Format-List Manufacturer,Name,SMBIOSBIOSVersion,SerialNumber,ReleaseDate\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["bios", "firmware", "uefi", "hardware"]
|
||||
},
|
||||
{
|
||||
"id": "info.env",
|
||||
"categoryId": "system-info",
|
||||
"titleKey": "Cmd_info.env_Title",
|
||||
"descriptionKey": "Cmd_info.env_Desc",
|
||||
"icon": "ClipboardListOutline",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Get-ChildItem Env: | Sort-Object Name | Format-Table -AutoSize Name,Value\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["environment", "variables", "path", "info"]
|
||||
},
|
||||
{
|
||||
"id": "info.installedapps",
|
||||
"categoryId": "system-info",
|
||||
"titleKey": "Cmd_info.installedapps_Title",
|
||||
"descriptionKey": "Cmd_info.installedapps_Desc",
|
||||
"icon": "PackageVariant",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Get-ItemProperty 'HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*','HKLM:\\Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*' | Where-Object DisplayName | Select-Object DisplayName,DisplayVersion,Publisher | Sort-Object DisplayName | Format-Table -AutoSize\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Medium",
|
||||
"docUrl": null,
|
||||
"tags": ["installed", "apps", "programs", "uninstall"]
|
||||
},
|
||||
{
|
||||
"id": "info.monitors",
|
||||
"categoryId": "system-info",
|
||||
"titleKey": "Cmd_info.monitors_Title",
|
||||
"descriptionKey": "Cmd_info.monitors_Desc",
|
||||
"icon": "Monitor",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Get-CimInstance Win32_VideoController | Select-Object Name,CurrentHorizontalResolution,CurrentVerticalResolution,CurrentRefreshRate | Format-List\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["monitor", "display", "resolution", "refresh rate"]
|
||||
},
|
||||
{
|
||||
"id": "net.netstat",
|
||||
"categoryId": "network",
|
||||
"titleKey": "Cmd_net.netstat_Title",
|
||||
"descriptionKey": "Cmd_net.netstat_Desc",
|
||||
"icon": "Lan",
|
||||
"executable": "netstat",
|
||||
"argsTemplate": "-ano",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["network", "connections", "ports", "netstat"]
|
||||
},
|
||||
{
|
||||
"id": "net.arp",
|
||||
"categoryId": "network",
|
||||
"titleKey": "Cmd_net.arp_Title",
|
||||
"descriptionKey": "Cmd_net.arp_Desc",
|
||||
"icon": "Ethernet",
|
||||
"executable": "arp",
|
||||
"argsTemplate": "-a",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["network", "arp", "cache", "mac"]
|
||||
},
|
||||
{
|
||||
"id": "net.route",
|
||||
"categoryId": "network",
|
||||
"titleKey": "Cmd_net.route_Title",
|
||||
"descriptionKey": "Cmd_net.route_Desc",
|
||||
"icon": "Lan",
|
||||
"executable": "route",
|
||||
"argsTemplate": "print",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["network", "route", "routing", "table"]
|
||||
},
|
||||
{
|
||||
"id": "net.wifi.profiles",
|
||||
"categoryId": "network",
|
||||
"titleKey": "Cmd_net.wifi.profiles_Title",
|
||||
"descriptionKey": "Cmd_net.wifi.profiles_Desc",
|
||||
"icon": "Wifi",
|
||||
"executable": "netsh",
|
||||
"argsTemplate": "wlan show profiles",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["network", "wifi", "wlan", "profiles"]
|
||||
},
|
||||
{
|
||||
"id": "net.proxy.show",
|
||||
"categoryId": "network",
|
||||
"titleKey": "Cmd_net.proxy.show_Title",
|
||||
"descriptionKey": "Cmd_net.proxy.show_Desc",
|
||||
"icon": "Ip",
|
||||
"executable": "netsh",
|
||||
"argsTemplate": "winhttp show proxy",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["network", "proxy", "winhttp"]
|
||||
},
|
||||
{
|
||||
"id": "tweak.darkmode.on",
|
||||
"categoryId": "tweaks-shortcuts",
|
||||
"titleKey": "Cmd_tweak.darkmode.on_Title",
|
||||
"descriptionKey": "Cmd_tweak.darkmode.on_Desc",
|
||||
"icon": "Brightness4",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"$p='HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize'; Set-ItemProperty -Path $p -Name AppsUseLightTheme -Value 0 -Type DWord; Set-ItemProperty -Path $p -Name SystemUsesLightTheme -Value 0 -Type DWord; Write-Output 'Dark mode enabled.'\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.darkmode.off",
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["dark mode", "theme", "appearance", "registry", "tweak"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "name": "AppsUseLightTheme" },
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "name": "SystemUsesLightTheme" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "tweak.darkmode.off",
|
||||
"categoryId": "tweaks-shortcuts",
|
||||
"titleKey": "Cmd_tweak.darkmode.off_Title",
|
||||
"descriptionKey": "Cmd_tweak.darkmode.off_Desc",
|
||||
"icon": "Brightness7",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"$p='HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize'; Set-ItemProperty -Path $p -Name AppsUseLightTheme -Value 1 -Type DWord; Set-ItemProperty -Path $p -Name SystemUsesLightTheme -Value 1 -Type DWord; Write-Output 'Light mode enabled.'\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.darkmode.on",
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["light mode", "theme", "appearance", "registry", "tweak"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "name": "AppsUseLightTheme" },
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "name": "SystemUsesLightTheme" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "tweak.win11.taskbarleft",
|
||||
"categoryId": "tweaks-shortcuts",
|
||||
"titleKey": "Cmd_tweak.win11.taskbarleft_Title",
|
||||
"descriptionKey": "Cmd_tweak.win11.taskbarleft_Desc",
|
||||
"icon": "FileCog",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced' -Name TaskbarAl -Value 0 -Type DWord; Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue; Start-Sleep -Seconds 1; if (-not (Get-Process -Name explorer -ErrorAction SilentlyContinue)) { Start-Process explorer }; Write-Output 'Taskbar aligned to the left.'\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.win11.taskbarcenter",
|
||||
"minOsBuild": 22000,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "taskbar", "align", "left", "registry", "tweak"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "name": "TaskbarAl" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "tweak.win11.taskbarcenter",
|
||||
"categoryId": "tweaks-shortcuts",
|
||||
"titleKey": "Cmd_tweak.win11.taskbarcenter_Title",
|
||||
"descriptionKey": "Cmd_tweak.win11.taskbarcenter_Desc",
|
||||
"icon": "FileCog",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced' -Name TaskbarAl -Value 1 -Type DWord; Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue; Start-Sleep -Seconds 1; if (-not (Get-Process -Name explorer -ErrorAction SilentlyContinue)) { Start-Process explorer }; Write-Output 'Taskbar aligned to the center.'\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.win11.taskbarleft",
|
||||
"minOsBuild": 22000,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "taskbar", "align", "center", "registry", "tweak"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "name": "TaskbarAl" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "tweak.clockseconds.on",
|
||||
"categoryId": "tweaks-shortcuts",
|
||||
"titleKey": "Cmd_tweak.clockseconds.on_Title",
|
||||
"descriptionKey": "Cmd_tweak.clockseconds.on_Desc",
|
||||
"icon": "ClockOutline",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced' -Name ShowSecondsInSystemClock -Value 1 -Type DWord; Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue; Start-Sleep -Seconds 1; if (-not (Get-Process -Name explorer -ErrorAction SilentlyContinue)) { Start-Process explorer }; Write-Output 'Seconds shown in the system clock.'\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.clockseconds.off",
|
||||
"minOsBuild": 22621,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "clock", "seconds", "taskbar", "registry", "tweak"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "name": "ShowSecondsInSystemClock" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "tweak.clockseconds.off",
|
||||
"categoryId": "tweaks-shortcuts",
|
||||
"titleKey": "Cmd_tweak.clockseconds.off_Title",
|
||||
"descriptionKey": "Cmd_tweak.clockseconds.off_Desc",
|
||||
"icon": "ClockOutline",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced' -Name ShowSecondsInSystemClock -Value 0 -Type DWord; Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue; Start-Sleep -Seconds 1; if (-not (Get-Process -Name explorer -ErrorAction SilentlyContinue)) { Start-Process explorer }; Write-Output 'Seconds hidden from the system clock.'\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "tweak.clockseconds.on",
|
||||
"minOsBuild": 22621,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["windows 11", "clock", "seconds", "taskbar", "registry", "tweak"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "name": "ShowSecondsInSystemClock" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "clean.thumbnailcache",
|
||||
"categoryId": "cleanup",
|
||||
"titleKey": "Cmd_clean.thumbnailcache_Title",
|
||||
"descriptionKey": "Cmd_clean.thumbnailcache_Desc",
|
||||
"icon": "Broom",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue; Remove-Item -Path (Join-Path $env:LocalAppData 'Microsoft\\Windows\\Explorer\\thumbcache_*.db') -Force -ErrorAction SilentlyContinue; Start-Process explorer; Write-Output 'Thumbnail cache cleared.'\"",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["cleanup", "thumbnail", "cache", "explorer"]
|
||||
},
|
||||
{
|
||||
"id": "clean.fontcache",
|
||||
"categoryId": "cleanup",
|
||||
"titleKey": "Cmd_clean.fontcache_Title",
|
||||
"descriptionKey": "Cmd_clean.fontcache_Desc",
|
||||
"icon": "Broom",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Stop-Service -Name FontCache -Force -ErrorAction SilentlyContinue; Remove-Item -Path (Join-Path $env:SystemRoot 'ServiceProfiles\\LocalService\\AppData\\Local\\FontCache\\*') -Recurse -Force -ErrorAction SilentlyContinue; Start-Service -Name FontCache -ErrorAction SilentlyContinue; Write-Output 'Font cache cleared.'\"",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Medium",
|
||||
"docUrl": null,
|
||||
"tags": ["cleanup", "font", "cache", "service"]
|
||||
},
|
||||
{
|
||||
"id": "clean.prefetch",
|
||||
"categoryId": "cleanup",
|
||||
"titleKey": "Cmd_clean.prefetch_Title",
|
||||
"descriptionKey": "Cmd_clean.prefetch_Desc",
|
||||
"icon": "Broom",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Remove-Item -Path (Join-Path $env:SystemRoot 'Prefetch\\*') -Recurse -Force -ErrorAction SilentlyContinue; Write-Output 'Prefetch folder cleared.'\"",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["cleanup", "prefetch", "boot", "cache"]
|
||||
},
|
||||
{
|
||||
"id": "power.set.balanced",
|
||||
"categoryId": "power",
|
||||
"titleKey": "Cmd_power.set.balanced_Title",
|
||||
"descriptionKey": "Cmd_power.set.balanced_Desc",
|
||||
"icon": "PowerPlug",
|
||||
"executable": "powercfg",
|
||||
"argsTemplate": "/setactive 381b4222-f694-41f0-9685-ff5bb260df2e",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["power", "balanced", "plan", "scheme"]
|
||||
},
|
||||
{
|
||||
"id": "power.requests",
|
||||
"categoryId": "power",
|
||||
"titleKey": "Cmd_power.requests_Title",
|
||||
"descriptionKey": "Cmd_power.requests_Desc",
|
||||
"icon": "Power",
|
||||
"executable": "powercfg",
|
||||
"argsTemplate": "/requests",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["power", "requests", "sleep", "awake"]
|
||||
},
|
||||
{
|
||||
"id": "power.fastboot.off",
|
||||
"categoryId": "power",
|
||||
"titleKey": "Cmd_power.fastboot.off_Title",
|
||||
"descriptionKey": "Cmd_power.fastboot.off_Desc",
|
||||
"icon": "Power",
|
||||
"executable": "reg",
|
||||
"argsTemplate": "add \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power\" /v HiberbootEnabled /t REG_DWORD /d 0 /f",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "power.fastboot.on",
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["power", "fast startup", "hiberboot", "registry"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power", "name": "HiberbootEnabled" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "power.fastboot.on",
|
||||
"categoryId": "power",
|
||||
"titleKey": "Cmd_power.fastboot.on_Title",
|
||||
"descriptionKey": "Cmd_power.fastboot.on_Desc",
|
||||
"icon": "Power",
|
||||
"executable": "reg",
|
||||
"argsTemplate": "add \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power\" /v HiberbootEnabled /t REG_DWORD /d 1 /f",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "power.fastboot.off",
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["power", "fast startup", "hiberboot", "registry"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power", "name": "HiberbootEnabled" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "diag.taskmgr",
|
||||
"executionMode": "Launch",
|
||||
"categoryId": "diagnostics",
|
||||
"titleKey": "Cmd_diag.taskmgr_Title",
|
||||
"descriptionKey": "Cmd_diag.taskmgr_Desc",
|
||||
"icon": "ChartBar",
|
||||
"executable": "taskmgr",
|
||||
"argsTemplate": "",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["task manager", "processes", "performance", "diagnostics"]
|
||||
},
|
||||
{
|
||||
"id": "diag.devmgmt",
|
||||
"executionMode": "Launch",
|
||||
"categoryId": "diagnostics",
|
||||
"titleKey": "Cmd_diag.devmgmt_Title",
|
||||
"descriptionKey": "Cmd_diag.devmgmt_Desc",
|
||||
"icon": "Chip",
|
||||
"executable": "devmgmt.msc",
|
||||
"argsTemplate": "",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["device manager", "drivers", "hardware", "diagnostics"]
|
||||
},
|
||||
{
|
||||
"id": "diag.services",
|
||||
"executionMode": "Launch",
|
||||
"categoryId": "diagnostics",
|
||||
"titleKey": "Cmd_diag.services_Title",
|
||||
"descriptionKey": "Cmd_diag.services_Desc",
|
||||
"icon": "FormatListChecks",
|
||||
"executable": "services.msc",
|
||||
"argsTemplate": "",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["services", "management", "diagnostics"]
|
||||
},
|
||||
{
|
||||
"id": "diag.gpresult",
|
||||
"categoryId": "diagnostics",
|
||||
"titleKey": "Cmd_diag.gpresult_Title",
|
||||
"descriptionKey": "Cmd_diag.gpresult_Desc",
|
||||
"icon": "ClipboardListOutline",
|
||||
"executable": "gpresult",
|
||||
"argsTemplate": "/r",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Medium",
|
||||
"docUrl": null,
|
||||
"tags": ["group policy", "gpresult", "rsop", "diagnostics"]
|
||||
},
|
||||
{
|
||||
"id": "winget.source.list",
|
||||
"categoryId": "updates-packages",
|
||||
"titleKey": "Cmd_winget.source.list_Title",
|
||||
"descriptionKey": "Cmd_winget.source.list_Desc",
|
||||
"icon": "PackageVariant",
|
||||
"executable": "winget",
|
||||
"argsTemplate": "source list",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["winget", "source", "list", "repositories"]
|
||||
},
|
||||
{
|
||||
"id": "store.reset",
|
||||
"executionMode": "Launch",
|
||||
"categoryId": "updates-packages",
|
||||
"titleKey": "Cmd_store.reset_Title",
|
||||
"descriptionKey": "Cmd_store.reset_Desc",
|
||||
"icon": "PackageVariant",
|
||||
"executable": "wsreset.exe",
|
||||
"argsTemplate": "",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Medium",
|
||||
"docUrl": null,
|
||||
"tags": ["microsoft store", "reset", "cache", "wsreset"]
|
||||
},
|
||||
{
|
||||
"id": "sec.defender.status",
|
||||
"categoryId": "security-privacy",
|
||||
"titleKey": "Cmd_sec.defender.status_Title",
|
||||
"descriptionKey": "Cmd_sec.defender.status_Desc",
|
||||
"icon": "ShieldCheck",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Get-MpComputerStatus | Format-List AMServiceEnabled,AntivirusEnabled,RealTimeProtectionEnabled,AntivirusSignatureVersion,QuickScanAge\"",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Safe",
|
||||
"confirmBeforeRun": false,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["defender", "antivirus", "status", "security"]
|
||||
},
|
||||
{
|
||||
"id": "sec.defender.fullscan",
|
||||
"categoryId": "security-privacy",
|
||||
"titleKey": "Cmd_sec.defender.fullscan_Title",
|
||||
"descriptionKey": "Cmd_sec.defender.fullscan_Desc",
|
||||
"icon": "ShieldSearch",
|
||||
"executable": "powershell",
|
||||
"argsTemplate": "-NoProfile -Command \"Start-MpScan -ScanType FullScan\"",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Long",
|
||||
"docUrl": null,
|
||||
"tags": ["defender", "antivirus", "full scan", "security"]
|
||||
},
|
||||
{
|
||||
"id": "sec.firewall.on",
|
||||
"categoryId": "security-privacy",
|
||||
"titleKey": "Cmd_sec.firewall.on_Title",
|
||||
"descriptionKey": "Cmd_sec.firewall.on_Desc",
|
||||
"icon": "ShieldCheck",
|
||||
"executable": "netsh",
|
||||
"argsTemplate": "advfirewall set allprofiles state on",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "sec.firewall.off",
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["firewall", "security", "enable", "network"]
|
||||
},
|
||||
{
|
||||
"id": "sec.firewall.off",
|
||||
"categoryId": "security-privacy",
|
||||
"titleKey": "Cmd_sec.firewall.off_Title",
|
||||
"descriptionKey": "Cmd_sec.firewall.off_Desc",
|
||||
"icon": "ShieldOff",
|
||||
"executable": "netsh",
|
||||
"argsTemplate": "advfirewall set allprofiles state off",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Dangerous",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "sec.firewall.on",
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["firewall", "security", "disable", "network"]
|
||||
},
|
||||
{
|
||||
"id": "dev.wsl.shutdown",
|
||||
"categoryId": "developer",
|
||||
"titleKey": "Cmd_dev.wsl.shutdown_Title",
|
||||
"descriptionKey": "Cmd_dev.wsl.shutdown_Desc",
|
||||
"icon": "Console",
|
||||
"executable": "wsl",
|
||||
"argsTemplate": "--shutdown",
|
||||
"requiresAdmin": false,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": null,
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["wsl", "linux", "shutdown", "developer"]
|
||||
},
|
||||
{
|
||||
"id": "dev.sandbox.off",
|
||||
"categoryId": "developer",
|
||||
"titleKey": "Cmd_dev.sandbox.off_Title",
|
||||
"descriptionKey": "Cmd_dev.sandbox.off_Desc",
|
||||
"icon": "ShieldCheck",
|
||||
"executable": "dism",
|
||||
"argsTemplate": "/Online /Disable-Feature /FeatureName:Containers-DisposableClientVM",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "Always",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "dev.sandbox.on",
|
||||
"estimatedDuration": "Long",
|
||||
"docUrl": null,
|
||||
"tags": ["windows sandbox", "feature", "disable", "developer"]
|
||||
},
|
||||
{
|
||||
"id": "dev.longpaths.on",
|
||||
"categoryId": "developer",
|
||||
"titleKey": "Cmd_dev.longpaths.on_Title",
|
||||
"descriptionKey": "Cmd_dev.longpaths.on_Desc",
|
||||
"icon": "FileCog",
|
||||
"executable": "reg",
|
||||
"argsTemplate": "add \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem\" /v LongPathsEnabled /t REG_DWORD /d 1 /f",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "dev.longpaths.off",
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["long paths", "filesystem", "max_path", "registry", "developer"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem", "name": "LongPathsEnabled" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "dev.longpaths.off",
|
||||
"categoryId": "developer",
|
||||
"titleKey": "Cmd_dev.longpaths.off_Title",
|
||||
"descriptionKey": "Cmd_dev.longpaths.off_Desc",
|
||||
"icon": "FileCog",
|
||||
"executable": "reg",
|
||||
"argsTemplate": "add \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem\" /v LongPathsEnabled /t REG_DWORD /d 0 /f",
|
||||
"requiresAdmin": true,
|
||||
"dangerLevel": "Caution",
|
||||
"confirmBeforeRun": true,
|
||||
"createsRestorePoint": false,
|
||||
"restart": "No",
|
||||
"restartRegex": null,
|
||||
"revertCommandId": "dev.longpaths.on",
|
||||
"estimatedDuration": "Short",
|
||||
"docUrl": null,
|
||||
"tags": ["long paths", "filesystem", "max_path", "registry", "developer"],
|
||||
"affectedRegistryValues": [
|
||||
{ "path": "HKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem", "name": "LongPathsEnabled" }
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -36,6 +36,12 @@ public static class ServiceCollectionExtensions
|
||||
services.AddSingleton<ILogMaintenance, LogMaintenance>();
|
||||
services.AddSingleton<IClock, SystemClock>();
|
||||
services.AddSingleton<ISettingsService, JsonSettingsService>();
|
||||
services.AddSingleton<IExecutionHistoryService, History.JsonExecutionHistoryService>();
|
||||
services.AddSingleton<ISettingsFile, Portability.JsonSettingsFile>();
|
||||
services.AddSingleton<IProfileService, Portability.JsonProfileService>();
|
||||
services.AddSingleton<IRecipeStore, Recipes.JsonRecipeStore>();
|
||||
services.AddSingleton<IUserCommandStore, UserCommands.JsonUserCommandStore>();
|
||||
services.AddSingleton<IRegistryService, Registry.WindowsRegistryService>();
|
||||
services.AddSingleton<ISystemInfoService, WindowsSystemInfoService>();
|
||||
services.AddSingleton<ICatalogProvider, JsonCatalogProvider>();
|
||||
services.AddSingleton<IProcessRunner, SystemProcessRunner>();
|
||||
|
||||
@@ -25,6 +25,9 @@ internal sealed class SystemProcessRunner : IProcessRunner
|
||||
Arguments = arguments,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
// Redirect stdin so we can close it immediately: a process that reads input (e.g. an
|
||||
// interactive "cmd" with no /c) gets EOF and exits instead of hanging forever.
|
||||
RedirectStandardInput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
// Pin the working directory to System32 so the CreateProcess search order can't
|
||||
@@ -52,6 +55,11 @@ internal sealed class SystemProcessRunner : IProcessRunner
|
||||
try
|
||||
{
|
||||
process.Start();
|
||||
|
||||
// Signal EOF on the child's stdin right away — nothing here ever feeds it input, and
|
||||
// leaving it open lets an interactive process block indefinitely.
|
||||
process.StandardInput.Close();
|
||||
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Infrastructure.History;
|
||||
|
||||
/// <summary>
|
||||
/// Persisted shape of <c>history.json</c>: a schema <see cref="Version"/> (for forward-compat)
|
||||
/// plus the records, newest first.
|
||||
/// </summary>
|
||||
internal sealed record HistoryFile
|
||||
{
|
||||
/// <summary>Schema version of the file.</summary>
|
||||
public int Version { get; init; } = 1;
|
||||
|
||||
/// <summary>Recorded executions, newest first.</summary>
|
||||
public IReadOnlyList<ExecutionRecord> Records { get; init; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// System.Text.Json source-generation context for <c>history.json</c> (camelCase, indented).
|
||||
/// </summary>
|
||||
[JsonSourceGenerationOptions(
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
|
||||
UseStringEnumConverter = true,
|
||||
WriteIndented = true)]
|
||||
[JsonSerializable(typeof(HistoryFile))]
|
||||
internal sealed partial class ExecutionHistoryJsonContext : JsonSerializerContext;
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Text.Json;
|
||||
using CommandForge.Application.History;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Infrastructure.History;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IExecutionHistoryService"/> backed by a local <c>history.json</c>. All data stays
|
||||
/// on the machine (see Privacy policy / golden rule "no telemetry").
|
||||
/// </summary>
|
||||
public sealed class JsonExecutionHistoryService : IExecutionHistoryService
|
||||
{
|
||||
private readonly string _path;
|
||||
private IReadOnlyList<ExecutionRecord> _records;
|
||||
|
||||
/// <summary>Creates a service backed by the default <see cref="AppPaths.HistoryFilePath"/>.</summary>
|
||||
public JsonExecutionHistoryService()
|
||||
: this(AppPaths.HistoryFilePath)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Creates a service backed by an explicit path (used in tests).</summary>
|
||||
public JsonExecutionHistoryService(string path)
|
||||
{
|
||||
_path = path;
|
||||
_records = Load(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<ExecutionRecord> GetRecent() => _records;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Record(ExecutionRecord record)
|
||||
{
|
||||
_records = ExecutionHistory.Add(_records, record);
|
||||
Save();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Clear()
|
||||
{
|
||||
_records = [];
|
||||
Save();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
var directory = Path.GetDirectoryName(_path);
|
||||
if (!string.IsNullOrEmpty(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
var file = new HistoryFile { Records = _records };
|
||||
var json = JsonSerializer.Serialize(file, ExecutionHistoryJsonContext.Default.HistoryFile);
|
||||
File.WriteAllText(_path, json);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<ExecutionRecord> Load(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(path);
|
||||
var file = JsonSerializer.Deserialize(json, ExecutionHistoryJsonContext.Default.HistoryFile);
|
||||
return file?.Records ?? [];
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
// Corrupt history: fall back to empty rather than crashing on startup.
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System.Text.Json;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Application.Settings;
|
||||
|
||||
namespace CommandForge.Infrastructure.Portability;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IProfileService"/> backed by a local <c>profiles.json</c>. All data stays on the
|
||||
/// machine (golden rule: no telemetry). Profile names are matched case-insensitively.
|
||||
/// </summary>
|
||||
public sealed class JsonProfileService : IProfileService
|
||||
{
|
||||
private readonly string _path;
|
||||
private List<ProfileEntry> _profiles;
|
||||
|
||||
/// <summary>Creates a service backed by the default <see cref="AppPaths.ProfilesFilePath"/>.</summary>
|
||||
public JsonProfileService()
|
||||
: this(AppPaths.ProfilesFilePath)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Creates a service backed by an explicit path (used in tests).</summary>
|
||||
public JsonProfileService(string path)
|
||||
{
|
||||
_path = path;
|
||||
_profiles = Load(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<string> GetNames() => _profiles.Select(p => p.Name).ToList();
|
||||
|
||||
/// <inheritdoc />
|
||||
public PortableSettings? Get(string name)
|
||||
=> _profiles.FirstOrDefault(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase))?.Settings;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save(string name, PortableSettings settings)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(name);
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
|
||||
_profiles.RemoveAll(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase));
|
||||
_profiles.Add(new ProfileEntry { Name = name, Settings = settings });
|
||||
SaveFile();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Delete(string name)
|
||||
{
|
||||
if (_profiles.RemoveAll(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)) > 0)
|
||||
{
|
||||
SaveFile();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveFile()
|
||||
{
|
||||
var directory = Path.GetDirectoryName(_path);
|
||||
if (!string.IsNullOrEmpty(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
var file = new ProfilesFile { Profiles = _profiles };
|
||||
var json = JsonSerializer.Serialize(file, PortableSettingsJsonContext.Default.ProfilesFile);
|
||||
File.WriteAllText(_path, json);
|
||||
}
|
||||
|
||||
private static List<ProfileEntry> Load(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(path);
|
||||
var file = JsonSerializer.Deserialize(json, PortableSettingsJsonContext.Default.ProfilesFile);
|
||||
return file?.Profiles.ToList() ?? [];
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
// Corrupt profiles file: start empty rather than crashing on startup.
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Text.Json;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Application.Settings;
|
||||
|
||||
namespace CommandForge.Infrastructure.Portability;
|
||||
|
||||
/// <summary><see cref="ISettingsFile"/> backed by System.Text.Json (used for import/export).</summary>
|
||||
public sealed class JsonSettingsFile : ISettingsFile
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Write(string path, PortableSettings settings)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
|
||||
var json = JsonSerializer.Serialize(settings, PortableSettingsJsonContext.Default.PortableSettings);
|
||||
File.WriteAllText(path, json);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public PortableSettings? Read(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(path);
|
||||
return JsonSerializer.Deserialize(json, PortableSettingsJsonContext.Default.PortableSettings);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
// Not a valid settings file — caller surfaces a friendly error.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using CommandForge.Application.Settings;
|
||||
|
||||
namespace CommandForge.Infrastructure.Portability;
|
||||
|
||||
/// <summary>One named profile entry stored in <c>profiles.json</c>.</summary>
|
||||
internal sealed record ProfileEntry
|
||||
{
|
||||
public required string Name { get; init; }
|
||||
|
||||
public required PortableSettings Settings { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>Persisted shape of <c>profiles.json</c>: a schema version plus the named profiles.</summary>
|
||||
internal sealed record ProfilesFile
|
||||
{
|
||||
public int Version { get; init; } = 1;
|
||||
|
||||
public IReadOnlyList<ProfileEntry> Profiles { get; init; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// System.Text.Json source-generation context for portable settings: import/export files
|
||||
/// (<see cref="PortableSettings"/>) and the profile store (<see cref="ProfilesFile"/>).
|
||||
/// camelCase, enums as strings, indented.
|
||||
/// </summary>
|
||||
[JsonSourceGenerationOptions(
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
|
||||
UseStringEnumConverter = true,
|
||||
WriteIndented = true,
|
||||
AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(PortableSettings))]
|
||||
[JsonSerializable(typeof(ProfilesFile))]
|
||||
internal sealed partial class PortableSettingsJsonContext : JsonSerializerContext;
|
||||
@@ -0,0 +1,83 @@
|
||||
using System.Text.Json;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Infrastructure.Recipes;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IRecipeStore"/> backed by a local <c>recipes.json</c>. All data stays on the
|
||||
/// machine (golden rule: no telemetry). Recipe names are matched case-insensitively.
|
||||
/// </summary>
|
||||
public sealed class JsonRecipeStore : IRecipeStore
|
||||
{
|
||||
private readonly string _path;
|
||||
private List<Recipe> _recipes;
|
||||
|
||||
/// <summary>Creates a store backed by the default <see cref="AppPaths.RecipesFilePath"/>.</summary>
|
||||
public JsonRecipeStore()
|
||||
: this(AppPaths.RecipesFilePath)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Creates a store backed by an explicit path (used in tests).</summary>
|
||||
public JsonRecipeStore(string path)
|
||||
{
|
||||
_path = path;
|
||||
_recipes = Load(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<Recipe> GetAll() => _recipes;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save(Recipe recipe)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(recipe);
|
||||
|
||||
_recipes.RemoveAll(r => string.Equals(r.Name, recipe.Name, StringComparison.OrdinalIgnoreCase));
|
||||
_recipes.Add(recipe);
|
||||
SaveFile();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Delete(string name)
|
||||
{
|
||||
if (_recipes.RemoveAll(r => string.Equals(r.Name, name, StringComparison.OrdinalIgnoreCase)) > 0)
|
||||
{
|
||||
SaveFile();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveFile()
|
||||
{
|
||||
var directory = Path.GetDirectoryName(_path);
|
||||
if (!string.IsNullOrEmpty(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
var file = new RecipesFile { Recipes = _recipes };
|
||||
var json = JsonSerializer.Serialize(file, RecipeJsonContext.Default.RecipesFile);
|
||||
File.WriteAllText(_path, json);
|
||||
}
|
||||
|
||||
private static List<Recipe> Load(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(path);
|
||||
var file = JsonSerializer.Deserialize(json, RecipeJsonContext.Default.RecipesFile);
|
||||
return file?.Recipes.ToList() ?? [];
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
// Corrupt recipes file: start empty rather than crashing on startup.
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Infrastructure.Recipes;
|
||||
|
||||
/// <summary>Persisted shape of <c>recipes.json</c>: a schema version plus the saved recipes.</summary>
|
||||
internal sealed record RecipesFile
|
||||
{
|
||||
public int Version { get; init; } = 1;
|
||||
|
||||
public IReadOnlyList<Recipe> Recipes { get; init; } = [];
|
||||
}
|
||||
|
||||
/// <summary>System.Text.Json source-generation context for <c>recipes.json</c> (camelCase, indented).</summary>
|
||||
[JsonSourceGenerationOptions(
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
|
||||
WriteIndented = true,
|
||||
AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(RecipesFile))]
|
||||
internal sealed partial class RecipeJsonContext : JsonSerializerContext;
|
||||
@@ -0,0 +1,54 @@
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Domain;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace CommandForge.Infrastructure.Registry;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IRegistryService"/> over <see cref="Microsoft.Win32.Registry"/> — read-only.
|
||||
/// Unknown hives, missing keys/values, or access errors all read as <c>null</c>.
|
||||
/// </summary>
|
||||
public sealed class WindowsRegistryService : IRegistryService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string? Read(RegistryValueRef reference)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reference);
|
||||
|
||||
var (hive, subKey) = Split(reference.Path);
|
||||
if (hive is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var baseKey = RegistryKey.OpenBaseKey(hive.Value, RegistryView.Default);
|
||||
using var key = baseKey.OpenSubKey(subKey);
|
||||
return key?.GetValue(reference.Name)?.ToString();
|
||||
}
|
||||
catch (Exception ex) when (ex is System.Security.SecurityException or UnauthorizedAccessException or IOException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static (RegistryHive? Hive, string SubKey) Split(string path)
|
||||
{
|
||||
var separator = path.IndexOf('\\', StringComparison.Ordinal);
|
||||
var prefix = separator < 0 ? path : path[..separator];
|
||||
var subKey = separator < 0 ? string.Empty : path[(separator + 1)..];
|
||||
|
||||
RegistryHive? hive = prefix.ToUpperInvariant() switch
|
||||
{
|
||||
"HKLM" or "HKEY_LOCAL_MACHINE" => RegistryHive.LocalMachine,
|
||||
"HKCU" or "HKEY_CURRENT_USER" => RegistryHive.CurrentUser,
|
||||
"HKCR" or "HKEY_CLASSES_ROOT" => RegistryHive.ClassesRoot,
|
||||
"HKU" or "HKEY_USERS" => RegistryHive.Users,
|
||||
"HKCC" or "HKEY_CURRENT_CONFIG" => RegistryHive.CurrentConfig,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
return (hive, subKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System.Text.Json;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Infrastructure.UserCommands;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IUserCommandStore"/> backed by a local <c>user-commands.json</c>, kept entirely
|
||||
/// separate from the embedded catalog (golden rule #1). All data stays on the machine (no telemetry).
|
||||
/// </summary>
|
||||
public sealed class JsonUserCommandStore : IUserCommandStore
|
||||
{
|
||||
private readonly string _path;
|
||||
private List<UserCommand> _commands;
|
||||
|
||||
/// <summary>Creates a store backed by the default <see cref="AppPaths.UserCommandsFilePath"/>.</summary>
|
||||
public JsonUserCommandStore()
|
||||
: this(AppPaths.UserCommandsFilePath)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Creates a store backed by an explicit path (used in tests).</summary>
|
||||
public JsonUserCommandStore(string path)
|
||||
{
|
||||
_path = path;
|
||||
_commands = Load(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<UserCommand> GetAll() => _commands;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save(UserCommand command)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
_commands.RemoveAll(c => string.Equals(c.Id, command.Id, StringComparison.Ordinal));
|
||||
_commands.Add(command);
|
||||
SaveFile();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Delete(string id)
|
||||
{
|
||||
if (_commands.RemoveAll(c => string.Equals(c.Id, id, StringComparison.Ordinal)) > 0)
|
||||
{
|
||||
SaveFile();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveFile()
|
||||
{
|
||||
var directory = Path.GetDirectoryName(_path);
|
||||
if (!string.IsNullOrEmpty(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
var file = new UserCommandsFile { Commands = _commands };
|
||||
var json = JsonSerializer.Serialize(file, UserCommandJsonContext.Default.UserCommandsFile);
|
||||
File.WriteAllText(_path, json);
|
||||
}
|
||||
|
||||
private static List<UserCommand> Load(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(path);
|
||||
var file = JsonSerializer.Deserialize(json, UserCommandJsonContext.Default.UserCommandsFile);
|
||||
return file?.Commands.ToList() ?? [];
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
// Corrupt file: start empty rather than crashing on startup.
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Infrastructure.UserCommands;
|
||||
|
||||
/// <summary>Persisted shape of <c>user-commands.json</c>: a schema version plus the user commands.</summary>
|
||||
internal sealed record UserCommandsFile
|
||||
{
|
||||
public int Version { get; init; } = 1;
|
||||
|
||||
public IReadOnlyList<UserCommand> Commands { get; init; } = [];
|
||||
}
|
||||
|
||||
/// <summary>System.Text.Json source-generation context for <c>user-commands.json</c> (camelCase, indented).</summary>
|
||||
[JsonSourceGenerationOptions(
|
||||
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
|
||||
WriteIndented = true,
|
||||
AllowTrailingCommas = true)]
|
||||
[JsonSerializable(typeof(UserCommandsFile))]
|
||||
internal sealed partial class UserCommandJsonContext : JsonSerializerContext;
|
||||
File diff suppressed because it is too large.
Load diff
@@ -118,6 +118,15 @@
|
||||
<data name="SidebarFavorites" xml:space="preserve">
|
||||
<value>Favorites</value>
|
||||
</data>
|
||||
<data name="SidebarHistory" xml:space="preserve">
|
||||
<value>History</value>
|
||||
</data>
|
||||
<data name="SidebarRecipes" xml:space="preserve">
|
||||
<value>Recipes</value>
|
||||
</data>
|
||||
<data name="SidebarUserCommands" xml:space="preserve">
|
||||
<value>My commands</value>
|
||||
</data>
|
||||
<data name="SidebarSettings" xml:space="preserve">
|
||||
<value>Settings</value>
|
||||
</data>
|
||||
@@ -217,6 +226,21 @@
|
||||
<data name="Search_Placeholder" xml:space="preserve">
|
||||
<value>Search commands… (Ctrl+K)</value>
|
||||
</data>
|
||||
<data name="Search_Suggestion" xml:space="preserve">
|
||||
<value>Did you mean:</value>
|
||||
</data>
|
||||
<data name="Home_Suggestions" xml:space="preserve">
|
||||
<value>Maintenance suggestions</value>
|
||||
</data>
|
||||
<data name="Maint_LowDisk" xml:space="preserve">
|
||||
<value>Your system drive is low on free space — consider Disk Cleanup.</value>
|
||||
</data>
|
||||
<data name="Maint_HighUptime" xml:space="preserve">
|
||||
<value>Your PC has been running for over a week — a restart may help.</value>
|
||||
</data>
|
||||
<data name="Maint_Open" xml:space="preserve">
|
||||
<value>Open</value>
|
||||
</data>
|
||||
<data name="Palette_Placeholder" xml:space="preserve">
|
||||
<value>Type to search the whole catalog…</value>
|
||||
</data>
|
||||
@@ -853,6 +877,60 @@
|
||||
<data name="Settings_CheckNow" xml:space="preserve">
|
||||
<value>Check now</value>
|
||||
</data>
|
||||
<data name="Settings_Profiles" xml:space="preserve">
|
||||
<value>Backup & profiles</value>
|
||||
</data>
|
||||
<data name="Settings_ExportImport" xml:space="preserve">
|
||||
<value>Import / export</value>
|
||||
</data>
|
||||
<data name="Settings_ExportImportHint" xml:space="preserve">
|
||||
<value>Copy your appearance, behavior and favorites to a file to move them to another machine.</value>
|
||||
</data>
|
||||
<data name="Settings_ExportSettings" xml:space="preserve">
|
||||
<value>Export…</value>
|
||||
</data>
|
||||
<data name="Settings_ImportSettings" xml:space="preserve">
|
||||
<value>Import…</value>
|
||||
</data>
|
||||
<data name="Settings_SavedProfiles" xml:space="preserve">
|
||||
<value>Saved profiles</value>
|
||||
</data>
|
||||
<data name="Settings_ProfilesHint" xml:space="preserve">
|
||||
<value>Save the current settings + favorites as a named profile, then switch between contexts (e.g. Gaming PC, Office).</value>
|
||||
</data>
|
||||
<data name="Settings_ApplyProfile" xml:space="preserve">
|
||||
<value>Apply</value>
|
||||
</data>
|
||||
<data name="Settings_DeleteProfile" xml:space="preserve">
|
||||
<value>Delete</value>
|
||||
</data>
|
||||
<data name="Settings_SaveCurrentAsProfile" xml:space="preserve">
|
||||
<value>Save current as a new profile</value>
|
||||
</data>
|
||||
<data name="Settings_ProfileName" xml:space="preserve">
|
||||
<value>Profile name</value>
|
||||
</data>
|
||||
<data name="Settings_SaveProfile" xml:space="preserve">
|
||||
<value>Save profile</value>
|
||||
</data>
|
||||
<data name="Settings_ExportSuccess" xml:space="preserve">
|
||||
<value>Settings exported to {0}.</value>
|
||||
</data>
|
||||
<data name="Settings_ImportConfirm" xml:space="preserve">
|
||||
<value>Replace your current appearance, behavior and favorites with the imported values?</value>
|
||||
</data>
|
||||
<data name="Settings_ImportInvalid" xml:space="preserve">
|
||||
<value>The selected file is not a valid CommandForge settings file.</value>
|
||||
</data>
|
||||
<data name="Settings_ImportSuccess" xml:space="preserve">
|
||||
<value>Settings imported.</value>
|
||||
</data>
|
||||
<data name="Settings_ProfileApplied" xml:space="preserve">
|
||||
<value>Applied profile "{0}".</value>
|
||||
</data>
|
||||
<data name="Settings_DeleteProfileConfirm" xml:space="preserve">
|
||||
<value>Delete profile "{0}"?</value>
|
||||
</data>
|
||||
<data name="Settings_NoDataCollected" xml:space="preserve">
|
||||
<value>This app does not collect any of your data.</value>
|
||||
</data>
|
||||
@@ -1069,6 +1147,133 @@
|
||||
<data name="Home_NoFavorites" xml:space="preserve">
|
||||
<value>No favorites yet. Pin a command with the star icon.</value>
|
||||
</data>
|
||||
<data name="History_Title" xml:space="preserve">
|
||||
<value>Execution history</value>
|
||||
</data>
|
||||
<data name="History_Empty" xml:space="preserve">
|
||||
<value>No commands have been run yet.</value>
|
||||
</data>
|
||||
<data name="History_RunAgain" xml:space="preserve">
|
||||
<value>Run again</value>
|
||||
</data>
|
||||
<data name="History_Clear" xml:space="preserve">
|
||||
<value>Clear history</value>
|
||||
</data>
|
||||
<data name="History_Undo" xml:space="preserve">
|
||||
<value>Undo</value>
|
||||
</data>
|
||||
<data name="Registry_ChangesHeader" xml:space="preserve">
|
||||
<value>— Registry before/after —</value>
|
||||
</data>
|
||||
<data name="Registry_ChangeFormat" xml:space="preserve">
|
||||
<value>{0}: {1} → {2}</value>
|
||||
</data>
|
||||
<data name="Registry_NotSet" xml:space="preserve">
|
||||
<value>(not set)</value>
|
||||
</data>
|
||||
<data name="Registry_NoChanges" xml:space="preserve">
|
||||
<value>No registry changes detected.</value>
|
||||
</data>
|
||||
<data name="Recipes_Saved" xml:space="preserve">
|
||||
<value>Saved recipes</value>
|
||||
</data>
|
||||
<data name="Recipes_New" xml:space="preserve">
|
||||
<value>New</value>
|
||||
</data>
|
||||
<data name="Recipe_Delete" xml:space="preserve">
|
||||
<value>Delete recipe</value>
|
||||
</data>
|
||||
<data name="Recipes_NameHint" xml:space="preserve">
|
||||
<value>Recipe name</value>
|
||||
</data>
|
||||
<data name="Recipes_NoSteps" xml:space="preserve">
|
||||
<value>No steps yet. Add commands below to build the chain.</value>
|
||||
</data>
|
||||
<data name="Recipes_AddHint" xml:space="preserve">
|
||||
<value>Add a command…</value>
|
||||
</data>
|
||||
<data name="Recipes_AddStep" xml:space="preserve">
|
||||
<value>Add</value>
|
||||
</data>
|
||||
<data name="Recipes_Save" xml:space="preserve">
|
||||
<value>Save</value>
|
||||
</data>
|
||||
<data name="Recipes_Run" xml:space="preserve">
|
||||
<value>Run recipe</value>
|
||||
</data>
|
||||
<data name="Recipes_MoveUp" xml:space="preserve">
|
||||
<value>Move up</value>
|
||||
</data>
|
||||
<data name="Recipes_MoveDown" xml:space="preserve">
|
||||
<value>Move down</value>
|
||||
</data>
|
||||
<data name="Recipes_RemoveStep" xml:space="preserve">
|
||||
<value>Remove step</value>
|
||||
</data>
|
||||
<data name="Recipe_StepHeader" xml:space="preserve">
|
||||
<value>▶ Step {0}/{1}: {2}</value>
|
||||
</data>
|
||||
<data name="Recipe_StoppedOnError" xml:space="preserve">
|
||||
<value>Recipe stopped: a step failed.</value>
|
||||
</data>
|
||||
<data name="Recipe_StoppedRestart" xml:space="preserve">
|
||||
<value>Recipe paused: a restart is required before continuing.</value>
|
||||
</data>
|
||||
<data name="Recipe_Cancelled" xml:space="preserve">
|
||||
<value>Recipe cancelled.</value>
|
||||
</data>
|
||||
<data name="Recipe_ContainsDangerous" xml:space="preserve">
|
||||
<value>This recipe contains dangerous steps.</value>
|
||||
</data>
|
||||
<data name="Recipe_ConfirmTitle" xml:space="preserve">
|
||||
<value>Run recipe?</value>
|
||||
</data>
|
||||
<data name="Recipe_DeleteConfirm" xml:space="preserve">
|
||||
<value>Delete recipe "{0}"?</value>
|
||||
</data>
|
||||
<data name="UserCmd_Warning" xml:space="preserve">
|
||||
<value>These commands are not part of the vetted catalog and always run without administrator rights. You alone are responsible for what they do.</value>
|
||||
</data>
|
||||
<data name="UserCmd_Saved" xml:space="preserve">
|
||||
<value>Saved commands</value>
|
||||
</data>
|
||||
<data name="UserCmd_New" xml:space="preserve">
|
||||
<value>New</value>
|
||||
</data>
|
||||
<data name="UserCmd_Delete" xml:space="preserve">
|
||||
<value>Delete</value>
|
||||
</data>
|
||||
<data name="UserCmd_NameHint" xml:space="preserve">
|
||||
<value>Name</value>
|
||||
</data>
|
||||
<data name="UserCmd_ExecutableHint" xml:space="preserve">
|
||||
<value>Executable (e.g. cmd, powershell)</value>
|
||||
</data>
|
||||
<data name="UserCmd_ArgumentsHint" xml:space="preserve">
|
||||
<value>Arguments</value>
|
||||
</data>
|
||||
<data name="UserCmd_Save" xml:space="preserve">
|
||||
<value>Save</value>
|
||||
</data>
|
||||
<data name="UserCmd_Run" xml:space="preserve">
|
||||
<value>Run</value>
|
||||
</data>
|
||||
<data name="UserCmd_NoCommands" xml:space="preserve">
|
||||
<value>No commands yet.</value>
|
||||
</data>
|
||||
<data name="UserCmd_RunTitle" xml:space="preserve">
|
||||
<value>Run this command?</value>
|
||||
</data>
|
||||
<data name="UserCmd_RunConfirm" xml:space="preserve">
|
||||
<value>This runs WITHOUT administrator rights:
|
||||
|
||||
{0}
|
||||
|
||||
Continue?</value>
|
||||
</data>
|
||||
<data name="UserCmd_DeleteConfirm" xml:space="preserve">
|
||||
<value>Delete "{0}"?</value>
|
||||
</data>
|
||||
<data name="Favorite_Toggle" xml:space="preserve">
|
||||
<value>Toggle favorite</value>
|
||||
</data>
|
||||
@@ -1132,4 +1337,232 @@
|
||||
<data name="PortableInfo_LogFolder" xml:space="preserve">
|
||||
<value>Log folder</value>
|
||||
</data>
|
||||
<data name="Cmd_info.hotfixes_Title" xml:space="preserve">
|
||||
<value>Installed Updates</value>
|
||||
</data>
|
||||
<data name="Cmd_info.hotfixes_Desc" xml:space="preserve">
|
||||
<value>List installed Windows updates and hotfixes, newest first.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.drivers_Title" xml:space="preserve">
|
||||
<value>Installed Drivers</value>
|
||||
</data>
|
||||
<data name="Cmd_info.drivers_Desc" xml:space="preserve">
|
||||
<value>List signed device drivers with their versions and providers.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.bios_Title" xml:space="preserve">
|
||||
<value>BIOS / Firmware Info</value>
|
||||
</data>
|
||||
<data name="Cmd_info.bios_Desc" xml:space="preserve">
|
||||
<value>Show BIOS manufacturer, version, serial number and release date.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.env_Title" xml:space="preserve">
|
||||
<value>Environment Variables</value>
|
||||
</data>
|
||||
<data name="Cmd_info.env_Desc" xml:space="preserve">
|
||||
<value>List the current environment variables and their values.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.installedapps_Title" xml:space="preserve">
|
||||
<value>Installed Programs</value>
|
||||
</data>
|
||||
<data name="Cmd_info.installedapps_Desc" xml:space="preserve">
|
||||
<value>List installed programs from the registry uninstall keys.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.monitors_Title" xml:space="preserve">
|
||||
<value>Display Info</value>
|
||||
</data>
|
||||
<data name="Cmd_info.monitors_Desc" xml:space="preserve">
|
||||
<value>Show connected displays with current resolution and refresh rate.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.netstat_Title" xml:space="preserve">
|
||||
<value>Active Connections</value>
|
||||
</data>
|
||||
<data name="Cmd_net.netstat_Desc" xml:space="preserve">
|
||||
<value>Show active TCP/UDP connections and listening ports with their PIDs.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.arp_Title" xml:space="preserve">
|
||||
<value>ARP Cache</value>
|
||||
</data>
|
||||
<data name="Cmd_net.arp_Desc" xml:space="preserve">
|
||||
<value>Display the ARP table mapping IP addresses to MAC addresses.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.route_Title" xml:space="preserve">
|
||||
<value>Routing Table</value>
|
||||
</data>
|
||||
<data name="Cmd_net.route_Desc" xml:space="preserve">
|
||||
<value>Print the IPv4/IPv6 routing table.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.wifi.profiles_Title" xml:space="preserve">
|
||||
<value>Wi-Fi Profiles</value>
|
||||
</data>
|
||||
<data name="Cmd_net.wifi.profiles_Desc" xml:space="preserve">
|
||||
<value>List saved Wi-Fi (WLAN) network profiles.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.proxy.show_Title" xml:space="preserve">
|
||||
<value>WinHTTP Proxy</value>
|
||||
</data>
|
||||
<data name="Cmd_net.proxy.show_Desc" xml:space="preserve">
|
||||
<value>Show the system WinHTTP proxy configuration.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.darkmode.on_Title" xml:space="preserve">
|
||||
<value>Enable Dark Mode</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.darkmode.on_Desc" xml:space="preserve">
|
||||
<value>Switch apps and the system theme to dark mode.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.darkmode.off_Title" xml:space="preserve">
|
||||
<value>Enable Light Mode</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.darkmode.off_Desc" xml:space="preserve">
|
||||
<value>Switch apps and the system theme back to light mode.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.win11.taskbarleft_Title" xml:space="preserve">
|
||||
<value>Taskbar: Align Left (Win11)</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.win11.taskbarleft_Desc" xml:space="preserve">
|
||||
<value>Align the Windows 11 taskbar to the left and restart Explorer.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.win11.taskbarcenter_Title" xml:space="preserve">
|
||||
<value>Taskbar: Align Center (Win11)</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.win11.taskbarcenter_Desc" xml:space="preserve">
|
||||
<value>Center the Windows 11 taskbar and restart Explorer.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.clockseconds.on_Title" xml:space="preserve">
|
||||
<value>Show Seconds in Clock (Win11)</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.clockseconds.on_Desc" xml:space="preserve">
|
||||
<value>Show seconds in the Windows 11 taskbar clock and restart Explorer.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.clockseconds.off_Title" xml:space="preserve">
|
||||
<value>Hide Seconds in Clock (Win11)</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.clockseconds.off_Desc" xml:space="preserve">
|
||||
<value>Hide seconds from the Windows 11 taskbar clock and restart Explorer.</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.thumbnailcache_Title" xml:space="preserve">
|
||||
<value>Clear Thumbnail Cache</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.thumbnailcache_Desc" xml:space="preserve">
|
||||
<value>Delete cached thumbnails and restart Explorer to rebuild them.</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.fontcache_Title" xml:space="preserve">
|
||||
<value>Clear Font Cache</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.fontcache_Desc" xml:space="preserve">
|
||||
<value>Stop the Font Cache service, clear its cache and restart it.</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.prefetch_Title" xml:space="preserve">
|
||||
<value>Clear Prefetch</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.prefetch_Desc" xml:space="preserve">
|
||||
<value>Empty the Windows Prefetch folder (rebuilt automatically).</value>
|
||||
</data>
|
||||
<data name="Cmd_power.set.balanced_Title" xml:space="preserve">
|
||||
<value>Set Balanced Plan</value>
|
||||
</data>
|
||||
<data name="Cmd_power.set.balanced_Desc" xml:space="preserve">
|
||||
<value>Activate the Balanced power plan.</value>
|
||||
</data>
|
||||
<data name="Cmd_power.requests_Title" xml:space="preserve">
|
||||
<value>Power Requests</value>
|
||||
</data>
|
||||
<data name="Cmd_power.requests_Desc" xml:space="preserve">
|
||||
<value>Show apps and drivers currently preventing sleep or display off.</value>
|
||||
</data>
|
||||
<data name="Cmd_power.fastboot.off_Title" xml:space="preserve">
|
||||
<value>Disable Fast Startup</value>
|
||||
</data>
|
||||
<data name="Cmd_power.fastboot.off_Desc" xml:space="preserve">
|
||||
<value>Turn off Fast Startup (hybrid boot) for a full shutdown.</value>
|
||||
</data>
|
||||
<data name="Cmd_power.fastboot.on_Title" xml:space="preserve">
|
||||
<value>Enable Fast Startup</value>
|
||||
</data>
|
||||
<data name="Cmd_power.fastboot.on_Desc" xml:space="preserve">
|
||||
<value>Turn on Fast Startup (hybrid boot).</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.taskmgr_Title" xml:space="preserve">
|
||||
<value>Task Manager</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.taskmgr_Desc" xml:space="preserve">
|
||||
<value>Open Task Manager.</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.devmgmt_Title" xml:space="preserve">
|
||||
<value>Device Manager</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.devmgmt_Desc" xml:space="preserve">
|
||||
<value>Open Device Manager.</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.services_Title" xml:space="preserve">
|
||||
<value>Services</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.services_Desc" xml:space="preserve">
|
||||
<value>Open the Services management console.</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.gpresult_Title" xml:space="preserve">
|
||||
<value>Group Policy Result</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.gpresult_Desc" xml:space="preserve">
|
||||
<value>Show the Resultant Set of Policy (RSoP) summary for this PC and user.</value>
|
||||
</data>
|
||||
<data name="Cmd_winget.source.list_Title" xml:space="preserve">
|
||||
<value>List winget Sources</value>
|
||||
</data>
|
||||
<data name="Cmd_winget.source.list_Desc" xml:space="preserve">
|
||||
<value>List the configured winget package sources.</value>
|
||||
</data>
|
||||
<data name="Cmd_store.reset_Title" xml:space="preserve">
|
||||
<value>Reset Microsoft Store</value>
|
||||
</data>
|
||||
<data name="Cmd_store.reset_Desc" xml:space="preserve">
|
||||
<value>Clear the Microsoft Store cache (wsreset).</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.defender.status_Title" xml:space="preserve">
|
||||
<value>Defender Status</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.defender.status_Desc" xml:space="preserve">
|
||||
<value>Show Microsoft Defender protection status and signature version.</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.defender.fullscan_Title" xml:space="preserve">
|
||||
<value>Defender Full Scan</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.defender.fullscan_Desc" xml:space="preserve">
|
||||
<value>Run a full Microsoft Defender antivirus scan (can take a while).</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.firewall.on_Title" xml:space="preserve">
|
||||
<value>Enable Firewall</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.firewall.on_Desc" xml:space="preserve">
|
||||
<value>Turn the Windows Firewall on for all profiles.</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.firewall.off_Title" xml:space="preserve">
|
||||
<value>Disable Firewall</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.firewall.off_Desc" xml:space="preserve">
|
||||
<value>Turn the Windows Firewall off for all profiles. This leaves the PC exposed — re-enable it as soon as possible.</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.wsl.shutdown_Title" xml:space="preserve">
|
||||
<value>Shut Down WSL</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.wsl.shutdown_Desc" xml:space="preserve">
|
||||
<value>Stop all running WSL distributions and the WSL virtual machine.</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.sandbox.off_Title" xml:space="preserve">
|
||||
<value>Disable Windows Sandbox</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.sandbox.off_Desc" xml:space="preserve">
|
||||
<value>Turn off the Windows Sandbox optional feature. Requires a restart.</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.longpaths.on_Title" xml:space="preserve">
|
||||
<value>Enable Long Paths</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.longpaths.on_Desc" xml:space="preserve">
|
||||
<value>Enable Win32 long path (over 260 characters) support.</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.longpaths.off_Title" xml:space="preserve">
|
||||
<value>Disable Long Paths</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.longpaths.off_Desc" xml:space="preserve">
|
||||
<value>Disable Win32 long path support (back to the default).</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -118,6 +118,15 @@
|
||||
<data name="SidebarFavorites" xml:space="preserve">
|
||||
<value>Yêu thích</value>
|
||||
</data>
|
||||
<data name="SidebarHistory" xml:space="preserve">
|
||||
<value>Lịch sử</value>
|
||||
</data>
|
||||
<data name="SidebarRecipes" xml:space="preserve">
|
||||
<value>Chuỗi lệnh</value>
|
||||
</data>
|
||||
<data name="SidebarUserCommands" xml:space="preserve">
|
||||
<value>Lệnh của tôi</value>
|
||||
</data>
|
||||
<data name="SidebarSettings" xml:space="preserve">
|
||||
<value>Cài đặt</value>
|
||||
</data>
|
||||
@@ -217,6 +226,21 @@
|
||||
<data name="Search_Placeholder" xml:space="preserve">
|
||||
<value>Tìm lệnh… (Ctrl+K)</value>
|
||||
</data>
|
||||
<data name="Search_Suggestion" xml:space="preserve">
|
||||
<value>Gợi ý:</value>
|
||||
</data>
|
||||
<data name="Home_Suggestions" xml:space="preserve">
|
||||
<value>Gợi ý bảo trì</value>
|
||||
</data>
|
||||
<data name="Maint_LowDisk" xml:space="preserve">
|
||||
<value>Ổ hệ thống sắp đầy — cân nhắc dọn dẹp ổ đĩa.</value>
|
||||
</data>
|
||||
<data name="Maint_HighUptime" xml:space="preserve">
|
||||
<value>Máy đã chạy hơn một tuần — khởi động lại có thể giúp ích.</value>
|
||||
</data>
|
||||
<data name="Maint_Open" xml:space="preserve">
|
||||
<value>Mở</value>
|
||||
</data>
|
||||
<data name="Palette_Placeholder" xml:space="preserve">
|
||||
<value>Gõ để tìm trên toàn bộ catalog…</value>
|
||||
</data>
|
||||
@@ -853,6 +877,60 @@
|
||||
<data name="Settings_CheckNow" xml:space="preserve">
|
||||
<value>Kiểm tra ngay</value>
|
||||
</data>
|
||||
<data name="Settings_Profiles" xml:space="preserve">
|
||||
<value>Sao lưu & Hồ sơ</value>
|
||||
</data>
|
||||
<data name="Settings_ExportImport" xml:space="preserve">
|
||||
<value>Nhập / xuất</value>
|
||||
</data>
|
||||
<data name="Settings_ExportImportHint" xml:space="preserve">
|
||||
<value>Sao chép giao diện, hành vi và mục yêu thích ra tệp để chuyển sang máy khác.</value>
|
||||
</data>
|
||||
<data name="Settings_ExportSettings" xml:space="preserve">
|
||||
<value>Xuất…</value>
|
||||
</data>
|
||||
<data name="Settings_ImportSettings" xml:space="preserve">
|
||||
<value>Nhập…</value>
|
||||
</data>
|
||||
<data name="Settings_SavedProfiles" xml:space="preserve">
|
||||
<value>Hồ sơ đã lưu</value>
|
||||
</data>
|
||||
<data name="Settings_ProfilesHint" xml:space="preserve">
|
||||
<value>Lưu cài đặt + mục yêu thích hiện tại thành hồ sơ có tên, rồi chuyển giữa các ngữ cảnh (vd Gaming PC, Văn phòng).</value>
|
||||
</data>
|
||||
<data name="Settings_ApplyProfile" xml:space="preserve">
|
||||
<value>Áp dụng</value>
|
||||
</data>
|
||||
<data name="Settings_DeleteProfile" xml:space="preserve">
|
||||
<value>Xóa</value>
|
||||
</data>
|
||||
<data name="Settings_SaveCurrentAsProfile" xml:space="preserve">
|
||||
<value>Lưu hiện tại thành hồ sơ mới</value>
|
||||
</data>
|
||||
<data name="Settings_ProfileName" xml:space="preserve">
|
||||
<value>Tên hồ sơ</value>
|
||||
</data>
|
||||
<data name="Settings_SaveProfile" xml:space="preserve">
|
||||
<value>Lưu hồ sơ</value>
|
||||
</data>
|
||||
<data name="Settings_ExportSuccess" xml:space="preserve">
|
||||
<value>Đã xuất cài đặt ra {0}.</value>
|
||||
</data>
|
||||
<data name="Settings_ImportConfirm" xml:space="preserve">
|
||||
<value>Thay thế giao diện, hành vi và mục yêu thích hiện tại bằng giá trị đã nhập?</value>
|
||||
</data>
|
||||
<data name="Settings_ImportInvalid" xml:space="preserve">
|
||||
<value>Tệp đã chọn không phải tệp cài đặt CommandForge hợp lệ.</value>
|
||||
</data>
|
||||
<data name="Settings_ImportSuccess" xml:space="preserve">
|
||||
<value>Đã nhập cài đặt.</value>
|
||||
</data>
|
||||
<data name="Settings_ProfileApplied" xml:space="preserve">
|
||||
<value>Đã áp dụng hồ sơ "{0}".</value>
|
||||
</data>
|
||||
<data name="Settings_DeleteProfileConfirm" xml:space="preserve">
|
||||
<value>Xóa hồ sơ "{0}"?</value>
|
||||
</data>
|
||||
<data name="Settings_NoDataCollected" xml:space="preserve">
|
||||
<value>Ứng dụng này không thu thập bất kỳ dữ liệu nào của bạn.</value>
|
||||
</data>
|
||||
@@ -1069,6 +1147,133 @@
|
||||
<data name="Home_NoFavorites" xml:space="preserve">
|
||||
<value>Chưa có mục yêu thích. Ghim lệnh bằng biểu tượng ngôi sao.</value>
|
||||
</data>
|
||||
<data name="History_Title" xml:space="preserve">
|
||||
<value>Lịch sử thực thi</value>
|
||||
</data>
|
||||
<data name="History_Empty" xml:space="preserve">
|
||||
<value>Chưa có lệnh nào được chạy.</value>
|
||||
</data>
|
||||
<data name="History_RunAgain" xml:space="preserve">
|
||||
<value>Chạy lại</value>
|
||||
</data>
|
||||
<data name="History_Clear" xml:space="preserve">
|
||||
<value>Xóa lịch sử</value>
|
||||
</data>
|
||||
<data name="History_Undo" xml:space="preserve">
|
||||
<value>Hoàn tác</value>
|
||||
</data>
|
||||
<data name="Registry_ChangesHeader" xml:space="preserve">
|
||||
<value>— Registry trước/sau —</value>
|
||||
</data>
|
||||
<data name="Registry_ChangeFormat" xml:space="preserve">
|
||||
<value>{0}: {1} → {2}</value>
|
||||
</data>
|
||||
<data name="Registry_NotSet" xml:space="preserve">
|
||||
<value>(chưa đặt)</value>
|
||||
</data>
|
||||
<data name="Registry_NoChanges" xml:space="preserve">
|
||||
<value>Không phát hiện thay đổi registry.</value>
|
||||
</data>
|
||||
<data name="Recipes_Saved" xml:space="preserve">
|
||||
<value>Chuỗi đã lưu</value>
|
||||
</data>
|
||||
<data name="Recipes_New" xml:space="preserve">
|
||||
<value>Tạo mới</value>
|
||||
</data>
|
||||
<data name="Recipe_Delete" xml:space="preserve">
|
||||
<value>Xóa chuỗi</value>
|
||||
</data>
|
||||
<data name="Recipes_NameHint" xml:space="preserve">
|
||||
<value>Tên chuỗi lệnh</value>
|
||||
</data>
|
||||
<data name="Recipes_NoSteps" xml:space="preserve">
|
||||
<value>Chưa có bước nào. Thêm lệnh bên dưới để dựng chuỗi.</value>
|
||||
</data>
|
||||
<data name="Recipes_AddHint" xml:space="preserve">
|
||||
<value>Thêm lệnh…</value>
|
||||
</data>
|
||||
<data name="Recipes_AddStep" xml:space="preserve">
|
||||
<value>Thêm</value>
|
||||
</data>
|
||||
<data name="Recipes_Save" xml:space="preserve">
|
||||
<value>Lưu</value>
|
||||
</data>
|
||||
<data name="Recipes_Run" xml:space="preserve">
|
||||
<value>Chạy chuỗi</value>
|
||||
</data>
|
||||
<data name="Recipes_MoveUp" xml:space="preserve">
|
||||
<value>Lên</value>
|
||||
</data>
|
||||
<data name="Recipes_MoveDown" xml:space="preserve">
|
||||
<value>Xuống</value>
|
||||
</data>
|
||||
<data name="Recipes_RemoveStep" xml:space="preserve">
|
||||
<value>Bỏ bước</value>
|
||||
</data>
|
||||
<data name="Recipe_StepHeader" xml:space="preserve">
|
||||
<value>▶ Bước {0}/{1}: {2}</value>
|
||||
</data>
|
||||
<data name="Recipe_StoppedOnError" xml:space="preserve">
|
||||
<value>Đã dừng chuỗi: một bước thất bại.</value>
|
||||
</data>
|
||||
<data name="Recipe_StoppedRestart" xml:space="preserve">
|
||||
<value>Tạm dừng chuỗi: cần khởi động lại trước khi tiếp tục.</value>
|
||||
</data>
|
||||
<data name="Recipe_Cancelled" xml:space="preserve">
|
||||
<value>Đã hủy chuỗi.</value>
|
||||
</data>
|
||||
<data name="Recipe_ContainsDangerous" xml:space="preserve">
|
||||
<value>Chuỗi này có các bước nguy hiểm.</value>
|
||||
</data>
|
||||
<data name="Recipe_ConfirmTitle" xml:space="preserve">
|
||||
<value>Chạy chuỗi lệnh?</value>
|
||||
</data>
|
||||
<data name="Recipe_DeleteConfirm" xml:space="preserve">
|
||||
<value>Xóa chuỗi "{0}"?</value>
|
||||
</data>
|
||||
<data name="UserCmd_Warning" xml:space="preserve">
|
||||
<value>Các lệnh này không thuộc catalog đã kiểm duyệt và luôn chạy KHÔNG có quyền quản trị. Bạn hoàn toàn chịu trách nhiệm về những gì chúng thực hiện.</value>
|
||||
</data>
|
||||
<data name="UserCmd_Saved" xml:space="preserve">
|
||||
<value>Lệnh đã lưu</value>
|
||||
</data>
|
||||
<data name="UserCmd_New" xml:space="preserve">
|
||||
<value>Tạo mới</value>
|
||||
</data>
|
||||
<data name="UserCmd_Delete" xml:space="preserve">
|
||||
<value>Xóa</value>
|
||||
</data>
|
||||
<data name="UserCmd_NameHint" xml:space="preserve">
|
||||
<value>Tên</value>
|
||||
</data>
|
||||
<data name="UserCmd_ExecutableHint" xml:space="preserve">
|
||||
<value>Tệp thực thi (vd cmd, powershell)</value>
|
||||
</data>
|
||||
<data name="UserCmd_ArgumentsHint" xml:space="preserve">
|
||||
<value>Đối số</value>
|
||||
</data>
|
||||
<data name="UserCmd_Save" xml:space="preserve">
|
||||
<value>Lưu</value>
|
||||
</data>
|
||||
<data name="UserCmd_Run" xml:space="preserve">
|
||||
<value>Chạy</value>
|
||||
</data>
|
||||
<data name="UserCmd_NoCommands" xml:space="preserve">
|
||||
<value>Chưa có lệnh nào.</value>
|
||||
</data>
|
||||
<data name="UserCmd_RunTitle" xml:space="preserve">
|
||||
<value>Chạy lệnh này?</value>
|
||||
</data>
|
||||
<data name="UserCmd_RunConfirm" xml:space="preserve">
|
||||
<value>Lệnh này chạy KHÔNG có quyền quản trị:
|
||||
|
||||
{0}
|
||||
|
||||
Tiếp tục?</value>
|
||||
</data>
|
||||
<data name="UserCmd_DeleteConfirm" xml:space="preserve">
|
||||
<value>Xóa "{0}"?</value>
|
||||
</data>
|
||||
<data name="Favorite_Toggle" xml:space="preserve">
|
||||
<value>Bật/tắt yêu thích</value>
|
||||
</data>
|
||||
@@ -1132,4 +1337,232 @@
|
||||
<data name="PortableInfo_LogFolder" xml:space="preserve">
|
||||
<value>Thư mục nhật ký</value>
|
||||
</data>
|
||||
<data name="Cmd_info.hotfixes_Title" xml:space="preserve">
|
||||
<value>Bản cập nhật đã cài</value>
|
||||
</data>
|
||||
<data name="Cmd_info.hotfixes_Desc" xml:space="preserve">
|
||||
<value>Liệt kê các bản cập nhật & hotfix Windows đã cài, mới nhất trước.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.drivers_Title" xml:space="preserve">
|
||||
<value>Driver đã cài</value>
|
||||
</data>
|
||||
<data name="Cmd_info.drivers_Desc" xml:space="preserve">
|
||||
<value>Liệt kê driver thiết bị đã ký kèm phiên bản và nhà cung cấp.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.bios_Title" xml:space="preserve">
|
||||
<value>Thông tin BIOS / Firmware</value>
|
||||
</data>
|
||||
<data name="Cmd_info.bios_Desc" xml:space="preserve">
|
||||
<value>Hiện hãng, phiên bản, số sê-ri và ngày phát hành BIOS.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.env_Title" xml:space="preserve">
|
||||
<value>Biến môi trường</value>
|
||||
</data>
|
||||
<data name="Cmd_info.env_Desc" xml:space="preserve">
|
||||
<value>Liệt kê các biến môi trường hiện tại và giá trị.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.installedapps_Title" xml:space="preserve">
|
||||
<value>Chương trình đã cài</value>
|
||||
</data>
|
||||
<data name="Cmd_info.installedapps_Desc" xml:space="preserve">
|
||||
<value>Liệt kê chương trình đã cài từ khóa Uninstall trong registry.</value>
|
||||
</data>
|
||||
<data name="Cmd_info.monitors_Title" xml:space="preserve">
|
||||
<value>Thông tin màn hình</value>
|
||||
</data>
|
||||
<data name="Cmd_info.monitors_Desc" xml:space="preserve">
|
||||
<value>Hiện màn hình đang kết nối kèm độ phân giải và tần số quét.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.netstat_Title" xml:space="preserve">
|
||||
<value>Kết nối đang hoạt động</value>
|
||||
</data>
|
||||
<data name="Cmd_net.netstat_Desc" xml:space="preserve">
|
||||
<value>Hiện kết nối TCP/UDP và cổng đang lắng nghe kèm PID.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.arp_Title" xml:space="preserve">
|
||||
<value>Bộ nhớ ARP</value>
|
||||
</data>
|
||||
<data name="Cmd_net.arp_Desc" xml:space="preserve">
|
||||
<value>Hiện bảng ARP ánh xạ địa chỉ IP sang MAC.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.route_Title" xml:space="preserve">
|
||||
<value>Bảng định tuyến</value>
|
||||
</data>
|
||||
<data name="Cmd_net.route_Desc" xml:space="preserve">
|
||||
<value>In bảng định tuyến IPv4/IPv6.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.wifi.profiles_Title" xml:space="preserve">
|
||||
<value>Hồ sơ Wi-Fi</value>
|
||||
</data>
|
||||
<data name="Cmd_net.wifi.profiles_Desc" xml:space="preserve">
|
||||
<value>Liệt kê các hồ sơ mạng Wi-Fi (WLAN) đã lưu.</value>
|
||||
</data>
|
||||
<data name="Cmd_net.proxy.show_Title" xml:space="preserve">
|
||||
<value>Proxy WinHTTP</value>
|
||||
</data>
|
||||
<data name="Cmd_net.proxy.show_Desc" xml:space="preserve">
|
||||
<value>Hiện cấu hình proxy WinHTTP của hệ thống.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.darkmode.on_Title" xml:space="preserve">
|
||||
<value>Bật chế độ tối</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.darkmode.on_Desc" xml:space="preserve">
|
||||
<value>Chuyển ứng dụng và giao diện hệ thống sang chế độ tối.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.darkmode.off_Title" xml:space="preserve">
|
||||
<value>Bật chế độ sáng</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.darkmode.off_Desc" xml:space="preserve">
|
||||
<value>Chuyển ứng dụng và giao diện hệ thống về chế độ sáng.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.win11.taskbarleft_Title" xml:space="preserve">
|
||||
<value>Thanh tác vụ: căn trái (Win11)</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.win11.taskbarleft_Desc" xml:space="preserve">
|
||||
<value>Căn thanh tác vụ Windows 11 về bên trái và khởi động lại Explorer.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.win11.taskbarcenter_Title" xml:space="preserve">
|
||||
<value>Thanh tác vụ: căn giữa (Win11)</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.win11.taskbarcenter_Desc" xml:space="preserve">
|
||||
<value>Căn giữa thanh tác vụ Windows 11 và khởi động lại Explorer.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.clockseconds.on_Title" xml:space="preserve">
|
||||
<value>Hiện giây trên đồng hồ (Win11)</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.clockseconds.on_Desc" xml:space="preserve">
|
||||
<value>Hiện giây trên đồng hồ thanh tác vụ Windows 11 và khởi động lại Explorer.</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.clockseconds.off_Title" xml:space="preserve">
|
||||
<value>Ẩn giây trên đồng hồ (Win11)</value>
|
||||
</data>
|
||||
<data name="Cmd_tweak.clockseconds.off_Desc" xml:space="preserve">
|
||||
<value>Ẩn giây trên đồng hồ thanh tác vụ Windows 11 và khởi động lại Explorer.</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.thumbnailcache_Title" xml:space="preserve">
|
||||
<value>Xóa cache ảnh thu nhỏ</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.thumbnailcache_Desc" xml:space="preserve">
|
||||
<value>Xóa ảnh thu nhỏ đã lưu và khởi động lại Explorer để dựng lại.</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.fontcache_Title" xml:space="preserve">
|
||||
<value>Xóa cache phông chữ</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.fontcache_Desc" xml:space="preserve">
|
||||
<value>Dừng dịch vụ Font Cache, xóa cache và khởi động lại dịch vụ.</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.prefetch_Title" xml:space="preserve">
|
||||
<value>Xóa Prefetch</value>
|
||||
</data>
|
||||
<data name="Cmd_clean.prefetch_Desc" xml:space="preserve">
|
||||
<value>Làm trống thư mục Prefetch của Windows (tự dựng lại).</value>
|
||||
</data>
|
||||
<data name="Cmd_power.set.balanced_Title" xml:space="preserve">
|
||||
<value>Đặt gói Cân bằng</value>
|
||||
</data>
|
||||
<data name="Cmd_power.set.balanced_Desc" xml:space="preserve">
|
||||
<value>Kích hoạt gói nguồn Cân bằng (Balanced).</value>
|
||||
</data>
|
||||
<data name="Cmd_power.requests_Title" xml:space="preserve">
|
||||
<value>Yêu cầu nguồn</value>
|
||||
</data>
|
||||
<data name="Cmd_power.requests_Desc" xml:space="preserve">
|
||||
<value>Hiện ứng dụng/driver đang ngăn máy ngủ hoặc tắt màn hình.</value>
|
||||
</data>
|
||||
<data name="Cmd_power.fastboot.off_Title" xml:space="preserve">
|
||||
<value>Tắt Khởi động nhanh</value>
|
||||
</data>
|
||||
<data name="Cmd_power.fastboot.off_Desc" xml:space="preserve">
|
||||
<value>Tắt Fast Startup (hybrid boot) để tắt máy hoàn toàn.</value>
|
||||
</data>
|
||||
<data name="Cmd_power.fastboot.on_Title" xml:space="preserve">
|
||||
<value>Bật Khởi động nhanh</value>
|
||||
</data>
|
||||
<data name="Cmd_power.fastboot.on_Desc" xml:space="preserve">
|
||||
<value>Bật Fast Startup (hybrid boot).</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.taskmgr_Title" xml:space="preserve">
|
||||
<value>Trình quản lý tác vụ</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.taskmgr_Desc" xml:space="preserve">
|
||||
<value>Mở Task Manager.</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.devmgmt_Title" xml:space="preserve">
|
||||
<value>Trình quản lý thiết bị</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.devmgmt_Desc" xml:space="preserve">
|
||||
<value>Mở Device Manager.</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.services_Title" xml:space="preserve">
|
||||
<value>Dịch vụ</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.services_Desc" xml:space="preserve">
|
||||
<value>Mở bảng quản lý Dịch vụ (Services).</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.gpresult_Title" xml:space="preserve">
|
||||
<value>Kết quả Group Policy</value>
|
||||
</data>
|
||||
<data name="Cmd_diag.gpresult_Desc" xml:space="preserve">
|
||||
<value>Hiện tóm tắt Resultant Set of Policy (RSoP) cho máy và người dùng này.</value>
|
||||
</data>
|
||||
<data name="Cmd_winget.source.list_Title" xml:space="preserve">
|
||||
<value>Liệt kê nguồn winget</value>
|
||||
</data>
|
||||
<data name="Cmd_winget.source.list_Desc" xml:space="preserve">
|
||||
<value>Liệt kê các nguồn gói winget đã cấu hình.</value>
|
||||
</data>
|
||||
<data name="Cmd_store.reset_Title" xml:space="preserve">
|
||||
<value>Đặt lại Microsoft Store</value>
|
||||
</data>
|
||||
<data name="Cmd_store.reset_Desc" xml:space="preserve">
|
||||
<value>Xóa cache Microsoft Store (wsreset).</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.defender.status_Title" xml:space="preserve">
|
||||
<value>Trạng thái Defender</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.defender.status_Desc" xml:space="preserve">
|
||||
<value>Hiện trạng thái bảo vệ và phiên bản định nghĩa của Microsoft Defender.</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.defender.fullscan_Title" xml:space="preserve">
|
||||
<value>Defender quét toàn bộ</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.defender.fullscan_Desc" xml:space="preserve">
|
||||
<value>Chạy quét toàn bộ Microsoft Defender (có thể lâu).</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.firewall.on_Title" xml:space="preserve">
|
||||
<value>Bật tường lửa</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.firewall.on_Desc" xml:space="preserve">
|
||||
<value>Bật Windows Firewall cho mọi hồ sơ.</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.firewall.off_Title" xml:space="preserve">
|
||||
<value>Tắt tường lửa</value>
|
||||
</data>
|
||||
<data name="Cmd_sec.firewall.off_Desc" xml:space="preserve">
|
||||
<value>Tắt Windows Firewall cho mọi hồ sơ. Việc này khiến máy mất bảo vệ — hãy bật lại sớm nhất có thể.</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.wsl.shutdown_Title" xml:space="preserve">
|
||||
<value>Tắt WSL</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.wsl.shutdown_Desc" xml:space="preserve">
|
||||
<value>Dừng mọi distro WSL đang chạy và máy ảo WSL.</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.sandbox.off_Title" xml:space="preserve">
|
||||
<value>Tắt Windows Sandbox</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.sandbox.off_Desc" xml:space="preserve">
|
||||
<value>Tắt tính năng tùy chọn Windows Sandbox. Cần khởi động lại.</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.longpaths.on_Title" xml:space="preserve">
|
||||
<value>Bật đường dẫn dài</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.longpaths.on_Desc" xml:space="preserve">
|
||||
<value>Bật hỗ trợ đường dẫn dài Win32 (hơn 260 ký tự).</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.longpaths.off_Title" xml:space="preserve">
|
||||
<value>Tắt đường dẫn dài</value>
|
||||
</data>
|
||||
<data name="Cmd_dev.longpaths.off_Desc" xml:space="preserve">
|
||||
<value>Tắt hỗ trợ đường dẫn dài Win32 (về mặc định).</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -17,7 +17,12 @@ internal sealed record CatalogViewModels(
|
||||
/// </summary>
|
||||
internal static class CatalogViewModelBuilder
|
||||
{
|
||||
public static CatalogViewModels Build(ICatalogProvider catalog)
|
||||
/// <summary>
|
||||
/// Projects the catalog to view-models, hiding commands that do not apply to the current OS build
|
||||
/// (e.g. Windows 11-only tweaks on Windows 10). The hidden commands never reach the list, palette,
|
||||
/// category counts or any dashboard.
|
||||
/// </summary>
|
||||
public static CatalogViewModels Build(ICatalogProvider catalog, int currentOsBuild)
|
||||
{
|
||||
var categoryTitles = catalog.GetCategories()
|
||||
.ToDictionary(c => c.Id, c => Strings.Get(c.TitleKey), StringComparer.Ordinal);
|
||||
@@ -26,6 +31,11 @@ internal static class CatalogViewModelBuilder
|
||||
var searchable = new List<SearchableCommand>();
|
||||
foreach (var command in catalog.GetCommands())
|
||||
{
|
||||
if (!command.AppliesToOsBuild(currentOsBuild))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var title = Strings.Get(command.TitleKey);
|
||||
var description = Strings.Get(command.DescriptionKey);
|
||||
items.Add(new CommandItemViewModel(command, title, description));
|
||||
|
||||
@@ -12,10 +12,11 @@ public sealed partial class CommandPaletteViewModel : ObservableObject
|
||||
private readonly IReadOnlyList<SearchableCommand> _searchable;
|
||||
private readonly Dictionary<string, CommandItemViewModel> _itemsById;
|
||||
|
||||
public CommandPaletteViewModel(ICatalogProvider catalog)
|
||||
public CommandPaletteViewModel(ICatalogProvider catalog, ISystemInfoService systemInfo)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(catalog);
|
||||
var vms = CatalogViewModelBuilder.Build(catalog);
|
||||
ArgumentNullException.ThrowIfNull(systemInfo);
|
||||
var vms = CatalogViewModelBuilder.Build(catalog, systemInfo.GetStatus().OsBuild);
|
||||
_searchable = vms.Searchable;
|
||||
_itemsById = vms.Items.ToDictionary(i => i.Command.Id, StringComparer.Ordinal);
|
||||
ApplyFilter();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Channels;
|
||||
using System.Windows;
|
||||
using CommandForge.Application.Recipes;
|
||||
using CommandForge.Application.UseCases;
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Wpf.Resources;
|
||||
@@ -52,6 +54,12 @@ public sealed partial class ExecutionViewModel : ObservableObject
|
||||
/// <summary>Whether the console panel should be visible (running or has a result).</summary>
|
||||
public bool ShowConsole => IsRunning || HasResult;
|
||||
|
||||
/// <summary>
|
||||
/// The result of the most recent finished run (the main command, not the restore point),
|
||||
/// or null if nothing has run yet. Used by callers to record execution history.
|
||||
/// </summary>
|
||||
public ExecutionResult? LastResult { get; private set; }
|
||||
|
||||
/// <summary>Localized result status (Success / Failed / Cancelled).</summary>
|
||||
public string StatusText => Cancelled
|
||||
? Strings.Get("Result_Cancelled")
|
||||
@@ -103,6 +111,73 @@ public sealed partial class ExecutionViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a recipe's <paramref name="steps"/> sequentially through the same broker session (one
|
||||
/// UAC prompt for an all-admin chain), streaming output with a header per step. Stops on the
|
||||
/// first failure, cancellation, or reboot-required step (see <see cref="RecipeFlow.ShouldStop"/>).
|
||||
/// Returns the (commandId, result) of each executed step, for history recording.
|
||||
/// </summary>
|
||||
public async Task<IReadOnlyList<(string CommandId, ExecutionResult Result)>> RunRecipeAsync(
|
||||
IReadOnlyList<CommandDefinition> steps)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(steps);
|
||||
|
||||
var executed = new List<(string CommandId, ExecutionResult Result)>();
|
||||
if (IsRunning || steps.Count == 0)
|
||||
{
|
||||
return executed;
|
||||
}
|
||||
|
||||
OutputLines.Clear();
|
||||
HasResult = false;
|
||||
IsRunning = true;
|
||||
_cancellation = new CancellationTokenSource();
|
||||
var token = _cancellation.Token;
|
||||
ExecutionResult? last = null;
|
||||
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < steps.Count; i++)
|
||||
{
|
||||
var step = steps[i];
|
||||
OutputLines.Add(new OutputLine(
|
||||
string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
Strings.Get("Recipe_StepHeader"),
|
||||
i + 1,
|
||||
steps.Count,
|
||||
Strings.Get(step.TitleKey)),
|
||||
IsError: false));
|
||||
|
||||
var result = await RunOneAsync(step, token);
|
||||
last = result;
|
||||
executed.Add((step.Id, result));
|
||||
|
||||
if (RecipeFlow.ShouldStop(result))
|
||||
{
|
||||
var key = result.Cancelled ? "Recipe_Cancelled"
|
||||
: result.RequiresRestart ? "Recipe_StoppedRestart"
|
||||
: "Recipe_StoppedOnError";
|
||||
OutputLines.Add(new OutputLine(Strings.Get(key), IsError: !result.Success && !result.Cancelled));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (last is not null)
|
||||
{
|
||||
ApplyResult(last);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsRunning = false;
|
||||
_cancellation.Dispose();
|
||||
_cancellation = null;
|
||||
}
|
||||
|
||||
return executed;
|
||||
}
|
||||
|
||||
private async Task<ExecutionResult> RunOneAsync(CommandDefinition command, CancellationToken token)
|
||||
{
|
||||
var channel = Channel.CreateBounded<OutputLine>(
|
||||
@@ -121,6 +196,7 @@ public sealed partial class ExecutionViewModel : ObservableObject
|
||||
|
||||
private void ApplyResult(ExecutionResult result)
|
||||
{
|
||||
LastResult = result;
|
||||
ExitCode = result.ExitCode;
|
||||
Success = result.Success;
|
||||
Cancelled = result.Cancelled;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace CommandForge.Wpf.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Execution-history screen: past command runs (newest first) with re-run and clear.
|
||||
/// Titles are resolved from the catalog's shared <see cref="CommandItemViewModel"/> instances;
|
||||
/// runs of commands no longer in the catalog show their id and cannot be re-run.
|
||||
/// </summary>
|
||||
public sealed partial class HistoryViewModel : ObservableObject
|
||||
{
|
||||
private readonly IReadOnlyDictionary<string, CommandItemViewModel> _itemsById;
|
||||
private readonly IExecutionHistoryService _history;
|
||||
private readonly Action<string> _openCommand;
|
||||
private readonly Func<string, Task> _runCommand;
|
||||
|
||||
public HistoryViewModel(
|
||||
IReadOnlyDictionary<string, CommandItemViewModel> itemsById,
|
||||
IExecutionHistoryService history,
|
||||
Action<string> openCommand,
|
||||
Func<string, Task> runCommand)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(itemsById);
|
||||
ArgumentNullException.ThrowIfNull(history);
|
||||
ArgumentNullException.ThrowIfNull(openCommand);
|
||||
ArgumentNullException.ThrowIfNull(runCommand);
|
||||
|
||||
_itemsById = itemsById;
|
||||
_history = history;
|
||||
_openCommand = openCommand;
|
||||
_runCommand = runCommand;
|
||||
}
|
||||
|
||||
/// <summary>Past runs, newest first.</summary>
|
||||
public ObservableCollection<HistoryEntryViewModel> Entries { get; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _hasEntries;
|
||||
|
||||
/// <summary>Rebuilds the list from the history store, resolving titles against the current catalog.</summary>
|
||||
public void Refresh()
|
||||
{
|
||||
Entries.Clear();
|
||||
foreach (var record in _history.GetRecent())
|
||||
{
|
||||
_itemsById.TryGetValue(record.CommandId, out var item);
|
||||
var title = item?.Title ?? record.CommandId;
|
||||
|
||||
// Undo is offered only when the run's command has a vetted revert command in the catalog.
|
||||
var revertCommandId = item?.Command.RevertCommandId is { } revertId && _itemsById.ContainsKey(revertId)
|
||||
? revertId
|
||||
: null;
|
||||
|
||||
Entries.Add(new HistoryEntryViewModel(record, title, item?.Icon, canRun: item is not null, revertCommandId));
|
||||
}
|
||||
|
||||
HasEntries = Entries.Count > 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Open(HistoryEntryViewModel? entry)
|
||||
{
|
||||
if (entry is { CanRun: true })
|
||||
{
|
||||
_openCommand(entry.CommandId);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private Task RunAgain(HistoryEntryViewModel? entry)
|
||||
=> entry is { CanRun: true } ? _runCommand(entry.CommandId) : Task.CompletedTask;
|
||||
|
||||
/// <summary>Undoes a run by executing its (vetted catalog) revert command. No arbitrary writes.</summary>
|
||||
[RelayCommand]
|
||||
private Task Undo(HistoryEntryViewModel? entry)
|
||||
=> entry?.RevertCommandId is { } revertId ? _runCommand(revertId) : Task.CompletedTask;
|
||||
|
||||
[RelayCommand]
|
||||
private void Clear()
|
||||
{
|
||||
_history.Clear();
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Application.SystemInfo;
|
||||
using CommandForge.Wpf.Resources;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
@@ -44,12 +45,18 @@ public sealed partial class HomeViewModel : ObservableObject
|
||||
/// <summary>Pinned favorite commands, in pin order.</summary>
|
||||
public ObservableCollection<CommandItemViewModel> Favorites { get; } = [];
|
||||
|
||||
/// <summary>Local maintenance suggestions derived from the current system status.</summary>
|
||||
public ObservableCollection<MaintenanceSuggestionViewModel> Suggestions { get; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _hasRecent;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _hasFavorites;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _hasSuggestions;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _osValue = string.Empty;
|
||||
|
||||
@@ -105,6 +112,15 @@ public sealed partial class HomeViewModel : ObservableObject
|
||||
FormatGigabytes((ulong)Math.Max(0L, status.SystemDriveTotalBytes)));
|
||||
DiskValue = string.Format(culture, Strings.Get("Home_DiskFormat"), status.SystemDriveName, diskStorage);
|
||||
UptimeValue = FormatUptime(status.Uptime);
|
||||
|
||||
Suggestions.Clear();
|
||||
foreach (var suggestion in MaintenanceSuggestions.For(status))
|
||||
{
|
||||
var command = suggestion.CommandId is { } id ? _itemsById.GetValueOrDefault(id) : null;
|
||||
Suggestions.Add(new MaintenanceSuggestionViewModel(Strings.Get(suggestion.ReasonKey), command));
|
||||
}
|
||||
|
||||
HasSuggestions = Suggestions.Count > 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Application.Registry;
|
||||
using CommandForge.Application.Search;
|
||||
using CommandForge.Application.Settings;
|
||||
using CommandForge.Domain;
|
||||
@@ -24,8 +26,12 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
private readonly IUpdateDialogService _updateDialog;
|
||||
private readonly IReportBugDialogService _reportBug;
|
||||
private readonly ISettingsService _settings;
|
||||
private readonly IExecutionHistoryService _history;
|
||||
private readonly IClock _clock;
|
||||
private readonly IRegistryService _registry;
|
||||
private readonly Dictionary<string, CommandItemViewModel> _itemsById;
|
||||
private readonly CommandDefinition? _restorePointCommand;
|
||||
private readonly int _osBuild;
|
||||
private IReadOnlyList<SearchableCommand> _searchable;
|
||||
private IReadOnlyDictionary<string, string> _categoryTitles;
|
||||
|
||||
@@ -36,6 +42,11 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
IUpdateDialogService updateDialog,
|
||||
IReportBugDialogService reportBug,
|
||||
ISettingsService settings,
|
||||
IExecutionHistoryService history,
|
||||
IClock clock,
|
||||
IRecipeStore recipeStore,
|
||||
IUserCommandStore userCommandStore,
|
||||
IRegistryService registry,
|
||||
ISystemInfoService systemInfo,
|
||||
SettingsViewModel settingsViewModel,
|
||||
LogViewerViewModel logViewer,
|
||||
@@ -47,6 +58,11 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
ArgumentNullException.ThrowIfNull(updateDialog);
|
||||
ArgumentNullException.ThrowIfNull(reportBug);
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
ArgumentNullException.ThrowIfNull(history);
|
||||
ArgumentNullException.ThrowIfNull(clock);
|
||||
ArgumentNullException.ThrowIfNull(recipeStore);
|
||||
ArgumentNullException.ThrowIfNull(userCommandStore);
|
||||
ArgumentNullException.ThrowIfNull(registry);
|
||||
ArgumentNullException.ThrowIfNull(systemInfo);
|
||||
ArgumentNullException.ThrowIfNull(settingsViewModel);
|
||||
ArgumentNullException.ThrowIfNull(logViewer);
|
||||
@@ -57,6 +73,9 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
_updateDialog = updateDialog;
|
||||
_reportBug = reportBug;
|
||||
_settings = settings;
|
||||
_history = history;
|
||||
_clock = clock;
|
||||
_registry = registry;
|
||||
Settings = settingsViewModel;
|
||||
LogViewer = logViewer;
|
||||
Debug = debug;
|
||||
@@ -71,7 +90,8 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
}
|
||||
};
|
||||
|
||||
var vms = CatalogViewModelBuilder.Build(catalog);
|
||||
_osBuild = systemInfo.GetStatus().OsBuild;
|
||||
var vms = CatalogViewModelBuilder.Build(catalog, _osBuild);
|
||||
_searchable = vms.Searchable;
|
||||
_categoryTitles = vms.CategoryTitles;
|
||||
_itemsById = vms.Items.ToDictionary(i => i.Command.Id, StringComparer.Ordinal);
|
||||
@@ -85,6 +105,9 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
}
|
||||
|
||||
Home = new HomeViewModel(_itemsById, settings, systemInfo, item => SelectCommandById(item.Command.Id));
|
||||
History = new HistoryViewModel(_itemsById, history, SelectCommandById, RunCommandByIdAsync);
|
||||
Recipes = new RecipesViewModel(_itemsById, execution, recipeStore, history, clock);
|
||||
UserCommands = new UserCommandsViewModel(userCommandStore, execution);
|
||||
|
||||
Categories.Add(new CategoryViewModel(null, "Sidebar_AllCommands", "ViewGridOutline", vms.Items.Count));
|
||||
foreach (var category in catalog.GetCategories())
|
||||
@@ -102,11 +125,23 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
|
||||
// Live language switching: re-resolve catalog display strings in place (keeps selection/scroll).
|
||||
LocalizationManager.Instance.CultureChanged += OnCultureChanged;
|
||||
|
||||
// Import / apply-profile can change favorites — re-sync stars and dashboards when it does.
|
||||
Settings.PortableSettingsApplied += OnPortableSettingsApplied;
|
||||
}
|
||||
|
||||
/// <summary>The Home dashboard view-model (shown when <see cref="CurrentSection"/> is Home).</summary>
|
||||
public HomeViewModel Home { get; }
|
||||
|
||||
/// <summary>The execution-history view-model (shown when <see cref="CurrentSection"/> is History).</summary>
|
||||
public HistoryViewModel History { get; }
|
||||
|
||||
/// <summary>The recipes view-model (shown when <see cref="CurrentSection"/> is Recipes).</summary>
|
||||
public RecipesViewModel Recipes { get; }
|
||||
|
||||
/// <summary>The user-defined commands view-model (shown when <see cref="CurrentSection"/> is UserCommands).</summary>
|
||||
public UserCommandsViewModel UserCommands { get; }
|
||||
|
||||
/// <summary>The Settings screen view-model (shown when <see cref="CurrentSection"/> is Settings).</summary>
|
||||
public SettingsViewModel Settings { get; }
|
||||
|
||||
@@ -154,6 +189,10 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private bool _hasResults;
|
||||
|
||||
/// <summary>A natural-language search keyword suggestion for the current query (null if none).</summary>
|
||||
[ObservableProperty]
|
||||
private string? _searchSuggestion;
|
||||
|
||||
[RelayCommand]
|
||||
private void ToggleSidebar() => IsSidebarCollapsed = !IsSidebarCollapsed;
|
||||
|
||||
@@ -164,6 +203,27 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
CurrentSection = ShellSection.Home;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ShowHistory()
|
||||
{
|
||||
History.Refresh();
|
||||
CurrentSection = ShellSection.History;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ShowRecipes()
|
||||
{
|
||||
Recipes.Refresh();
|
||||
CurrentSection = ShellSection.Recipes;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ShowUserCommands()
|
||||
{
|
||||
UserCommands.Refresh();
|
||||
CurrentSection = ShellSection.UserCommands;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ShowSettings() => CurrentSection = ShellSection.Settings;
|
||||
|
||||
@@ -284,16 +344,83 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
restorePoint = _restorePointCommand;
|
||||
}
|
||||
|
||||
// Read-only before snapshot of any registry values this command may change.
|
||||
var registryBefore = command.AffectedRegistryValues.Count > 0
|
||||
? RegistrySnapshot.Capture(_registry, command.AffectedRegistryValues)
|
||||
: null;
|
||||
|
||||
await Execution.RunAsync(command, restorePoint);
|
||||
|
||||
// Record the run for the Home "recent commands" list (skip user-cancelled runs).
|
||||
// Record the run for the Home "recent commands" list and the execution history
|
||||
// (skip user-cancelled runs, matching the recent-commands behaviour).
|
||||
if (!Execution.Cancelled)
|
||||
{
|
||||
_settings.RecentCommandIds = RecentCommands.Add(_settings.RecentCommandIds, command.Id);
|
||||
_settings.Save();
|
||||
|
||||
if (Execution.LastResult is { } result)
|
||||
{
|
||||
_history.Record(new ExecutionRecord
|
||||
{
|
||||
CommandId = command.Id,
|
||||
Timestamp = _clock.Now,
|
||||
ExitCode = result.ExitCode,
|
||||
Success = result.Success,
|
||||
DurationMs = (long)result.Duration.TotalMilliseconds,
|
||||
RequiresRestart = result.RequiresRestart,
|
||||
});
|
||||
}
|
||||
|
||||
if (registryBefore is not null)
|
||||
{
|
||||
AppendRegistryDiff(command.AffectedRegistryValues, registryBefore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Re-reads the affected registry values and appends a before/after summary to the console.</summary>
|
||||
private void AppendRegistryDiff(
|
||||
IReadOnlyList<RegistryValueRef> references,
|
||||
IReadOnlyDictionary<RegistryValueRef, string?> before)
|
||||
{
|
||||
var after = RegistrySnapshot.Capture(_registry, references);
|
||||
var changes = RegistrySnapshot.Diff(references, before, after);
|
||||
|
||||
Execution.OutputLines.Add(new OutputLine(Strings.Get("Registry_ChangesHeader"), IsError: false));
|
||||
if (changes.Count == 0)
|
||||
{
|
||||
Execution.OutputLines.Add(new OutputLine(Strings.Get("Registry_NoChanges"), IsError: false));
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var change in changes)
|
||||
{
|
||||
var label = string.IsNullOrEmpty(change.Reference.Name)
|
||||
? change.Reference.Path
|
||||
: change.Reference.Path + "\\" + change.Reference.Name;
|
||||
Execution.OutputLines.Add(new OutputLine(
|
||||
string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
Strings.Get("Registry_ChangeFormat"),
|
||||
label,
|
||||
change.Before ?? Strings.Get("Registry_NotSet"),
|
||||
change.After ?? Strings.Get("Registry_NotSet")),
|
||||
IsError: false));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Re-runs a command by id (used by the History view's "Run again"); ignores unknown ids.</summary>
|
||||
public Task RunCommandByIdAsync(string commandId)
|
||||
{
|
||||
if (!_itemsById.TryGetValue(commandId, out var item))
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
SelectCommandById(commandId);
|
||||
return ConfirmAndRunAsync(item.Command);
|
||||
}
|
||||
|
||||
/// <summary>Selects a command by id (used by the palette and Home), clearing filters so it is visible.</summary>
|
||||
public void SelectCommandById(string commandId)
|
||||
{
|
||||
@@ -311,7 +438,22 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSearchTextChanged(string value) => ApplyFilter();
|
||||
partial void OnSearchTextChanged(string value)
|
||||
{
|
||||
// Suggest a catalog keyword for natural-language queries (local; no LLM/network).
|
||||
SearchSuggestion = NaturalLanguageSearch.Suggest(value);
|
||||
ApplyFilter();
|
||||
}
|
||||
|
||||
/// <summary>Applies the natural-language keyword suggestion as the search query.</summary>
|
||||
[RelayCommand]
|
||||
private void ApplySuggestion()
|
||||
{
|
||||
if (SearchSuggestion is { } suggestion)
|
||||
{
|
||||
SearchText = suggestion;
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedCategoryChanged(CategoryViewModel? value)
|
||||
{
|
||||
@@ -332,7 +474,7 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
{
|
||||
// Rebuild the search corpus + category-title map in the new language, and refresh the
|
||||
// already-displayed item/category/detail view-models in place.
|
||||
var vms = CatalogViewModelBuilder.Build(_catalog);
|
||||
var vms = CatalogViewModelBuilder.Build(_catalog, _osBuild);
|
||||
_searchable = vms.Searchable;
|
||||
_categoryTitles = vms.CategoryTitles;
|
||||
|
||||
@@ -348,6 +490,26 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
|
||||
UpdateDetail();
|
||||
Home.Refresh();
|
||||
History.Refresh();
|
||||
}
|
||||
|
||||
private void OnPortableSettingsApplied()
|
||||
{
|
||||
// Favorites may have changed (import / apply-profile); re-sync the shared item view-models
|
||||
// (drives the star icon everywhere) and the dashboards. Theme/font/language already applied
|
||||
// live via the Settings observable-property setters.
|
||||
var favoriteIds = new HashSet<string>(_settings.FavoriteCommandIds, StringComparer.Ordinal);
|
||||
foreach (var item in _itemsById.Values)
|
||||
{
|
||||
item.IsFavorite = favoriteIds.Contains(item.Command.Id);
|
||||
}
|
||||
|
||||
Home.Refresh();
|
||||
History.Refresh();
|
||||
if (_browseMode == BrowseMode.Favorites)
|
||||
{
|
||||
ApplyFilter();
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyFilter()
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace CommandForge.Wpf.ViewModels;
|
||||
|
||||
/// <summary>One Home maintenance suggestion: a reason and an optional catalog command to open.</summary>
|
||||
public sealed class MaintenanceSuggestionViewModel
|
||||
{
|
||||
public MaintenanceSuggestionViewModel(string reason, CommandItemViewModel? command)
|
||||
{
|
||||
Reason = reason;
|
||||
Command = command;
|
||||
}
|
||||
|
||||
/// <summary>Localized reason text.</summary>
|
||||
public string Reason { get; }
|
||||
|
||||
/// <summary>The catalog command this suggestion can open, or null if it's informational only.</summary>
|
||||
public CommandItemViewModel? Command { get; }
|
||||
|
||||
/// <summary>Whether there is a command to open.</summary>
|
||||
public bool CanOpen => Command is not null;
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Wpf.Resources;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace CommandForge.Wpf.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Recipes screen: build a named chain of catalog commands and run it sequentially (one
|
||||
/// aggregated confirmation, one UAC for an all-admin chain, stop-on-error). Steps reference the
|
||||
/// shared catalog <see cref="CommandItemViewModel"/> instances.
|
||||
/// </summary>
|
||||
public sealed partial class RecipesViewModel : ObservableObject
|
||||
{
|
||||
private readonly IReadOnlyDictionary<string, CommandItemViewModel> _itemsById;
|
||||
private readonly ExecutionViewModel _execution;
|
||||
private readonly IRecipeStore _store;
|
||||
private readonly IExecutionHistoryService _history;
|
||||
private readonly IClock _clock;
|
||||
|
||||
public RecipesViewModel(
|
||||
IReadOnlyDictionary<string, CommandItemViewModel> itemsById,
|
||||
ExecutionViewModel execution,
|
||||
IRecipeStore store,
|
||||
IExecutionHistoryService history,
|
||||
IClock clock)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(itemsById);
|
||||
ArgumentNullException.ThrowIfNull(execution);
|
||||
ArgumentNullException.ThrowIfNull(store);
|
||||
ArgumentNullException.ThrowIfNull(history);
|
||||
ArgumentNullException.ThrowIfNull(clock);
|
||||
|
||||
_itemsById = itemsById;
|
||||
_execution = execution;
|
||||
_store = store;
|
||||
_history = history;
|
||||
_clock = clock;
|
||||
|
||||
AllCommands = itemsById.Values.OrderBy(i => i.Title, StringComparer.CurrentCulture).ToList();
|
||||
|
||||
// Re-evaluate Save/Run availability when the step list changes.
|
||||
Steps.CollectionChanged += (_, _) =>
|
||||
{
|
||||
SaveRecipeCommand.NotifyCanExecuteChanged();
|
||||
RunRecipeCommand.NotifyCanExecuteChanged();
|
||||
};
|
||||
|
||||
// Disable Run while any execution is in progress (shared console).
|
||||
_execution.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(ExecutionViewModel.IsRunning))
|
||||
{
|
||||
RunRecipeCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
};
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
/// <summary>The shared execution view-model — drives the recipe console output panel.</summary>
|
||||
public ExecutionViewModel Execution => _execution;
|
||||
|
||||
/// <summary>Names of saved recipes.</summary>
|
||||
public ObservableCollection<string> RecipeNames { get; } = [];
|
||||
|
||||
/// <summary>All catalog commands (for the add-step picker), sorted by title.</summary>
|
||||
public IReadOnlyList<CommandItemViewModel> AllCommands { get; }
|
||||
|
||||
/// <summary>The steps of the recipe currently being edited, in order.</summary>
|
||||
public ObservableCollection<CommandItemViewModel> Steps { get; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(DeleteRecipeCommand))]
|
||||
private string? _selectedRecipeName;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(SaveRecipeCommand))]
|
||||
private string _recipeName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private CommandItemViewModel? _commandToAdd;
|
||||
|
||||
/// <summary>Reloads the saved-recipe name list from the store.</summary>
|
||||
public void Refresh()
|
||||
{
|
||||
var previous = SelectedRecipeName;
|
||||
RecipeNames.Clear();
|
||||
foreach (var recipe in _store.GetAll())
|
||||
{
|
||||
RecipeNames.Add(recipe.Name);
|
||||
}
|
||||
|
||||
if (previous is not null && RecipeNames.Contains(previous))
|
||||
{
|
||||
SelectedRecipeName = previous;
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedRecipeNameChanged(string? value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var recipe = _store.GetAll().FirstOrDefault(r => string.Equals(r.Name, value, StringComparison.OrdinalIgnoreCase));
|
||||
if (recipe is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RecipeName = recipe.Name;
|
||||
Steps.Clear();
|
||||
foreach (var id in recipe.CommandIds)
|
||||
{
|
||||
if (_itemsById.TryGetValue(id, out var item))
|
||||
{
|
||||
Steps.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void NewRecipe()
|
||||
{
|
||||
SelectedRecipeName = null;
|
||||
RecipeName = string.Empty;
|
||||
Steps.Clear();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AddStep()
|
||||
{
|
||||
// Avoid duplicate steps — a recipe runs each command once (don't run one command N times).
|
||||
if (CommandToAdd is { } command && !Steps.Contains(command))
|
||||
{
|
||||
Steps.Add(command);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void RemoveStep(CommandItemViewModel? step)
|
||||
{
|
||||
if (step is not null)
|
||||
{
|
||||
Steps.Remove(step);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void MoveStepUp(CommandItemViewModel? step)
|
||||
{
|
||||
var index = step is null ? -1 : Steps.IndexOf(step);
|
||||
if (index > 0)
|
||||
{
|
||||
Steps.Move(index, index - 1);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void MoveStepDown(CommandItemViewModel? step)
|
||||
{
|
||||
var index = step is null ? -1 : Steps.IndexOf(step);
|
||||
if (index >= 0 && index < Steps.Count - 1)
|
||||
{
|
||||
Steps.Move(index, index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanSaveRecipe))]
|
||||
private void SaveRecipe()
|
||||
{
|
||||
var name = RecipeName.Trim();
|
||||
if (name.Length == 0 || Steps.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_store.Save(new Recipe { Name = name, CommandIds = Steps.Select(s => s.Command.Id).ToList() });
|
||||
Refresh();
|
||||
SelectedRecipeName = name;
|
||||
}
|
||||
|
||||
private bool CanSaveRecipe() => !string.IsNullOrWhiteSpace(RecipeName) && Steps.Count > 0;
|
||||
|
||||
[RelayCommand(CanExecute = nameof(HasSelectedRecipe))]
|
||||
private void DeleteRecipe()
|
||||
{
|
||||
if (SelectedRecipeName is not { } name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show(
|
||||
string.Format(System.Globalization.CultureInfo.CurrentCulture, Strings.Get("Recipe_DeleteConfirm"), name),
|
||||
Strings.Get("Recipe_Delete"),
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning) != MessageBoxResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_store.Delete(name);
|
||||
SelectedRecipeName = null;
|
||||
NewRecipe();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private bool HasSelectedRecipe() => SelectedRecipeName is not null;
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanRunRecipe))]
|
||||
private async Task RunRecipeAsync()
|
||||
{
|
||||
var steps = Steps.Select(s => s.Command).ToList();
|
||||
if (steps.Count == 0 || _execution.IsRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ConfirmRecipe())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var executed = await _execution.RunRecipeAsync(steps);
|
||||
|
||||
// Record each finished (non-cancelled) step in the execution history.
|
||||
foreach (var (commandId, result) in executed)
|
||||
{
|
||||
if (result.Cancelled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_history.Record(new ExecutionRecord
|
||||
{
|
||||
CommandId = commandId,
|
||||
Timestamp = _clock.Now,
|
||||
ExitCode = result.ExitCode,
|
||||
Success = result.Success,
|
||||
DurationMs = (long)result.Duration.TotalMilliseconds,
|
||||
RequiresRestart = result.RequiresRestart,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanRunRecipe() => Steps.Count > 0 && !_execution.IsRunning;
|
||||
|
||||
/// <summary>Shows a single aggregated confirmation listing all steps (a warning if any is Dangerous).</summary>
|
||||
private bool ConfirmRecipe()
|
||||
{
|
||||
var anyDangerous = Steps.Any(s => s.DangerLevel == DangerLevel.Dangerous);
|
||||
var list = string.Join(Environment.NewLine, Steps.Select((s, i) => $"{i + 1}. {s.Title}"));
|
||||
var header = string.IsNullOrWhiteSpace(RecipeName)
|
||||
? string.Empty
|
||||
: RecipeName + Environment.NewLine + Environment.NewLine;
|
||||
var message = header + list;
|
||||
if (anyDangerous)
|
||||
{
|
||||
message += Environment.NewLine + Environment.NewLine + Strings.Get("Recipe_ContainsDangerous");
|
||||
}
|
||||
|
||||
return MessageBox.Show(
|
||||
message,
|
||||
Strings.Get("Recipe_ConfirmTitle"),
|
||||
MessageBoxButton.YesNo,
|
||||
anyDangerous ? MessageBoxImage.Warning : MessageBoxImage.Question) == MessageBoxResult.Yes;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@ public enum SettingsSection
|
||||
/// <summary>Update preferences and manual check.</summary>
|
||||
Updates,
|
||||
|
||||
/// <summary>Import/export settings + favorites, and named profiles.</summary>
|
||||
Profiles,
|
||||
|
||||
/// <summary>Log level, size, open/export/clear.</summary>
|
||||
Logs,
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
@@ -28,6 +29,8 @@ public sealed partial class SettingsViewModel : ObservableObject
|
||||
private readonly IUpdateDialogService _updateDialog;
|
||||
private readonly ILogLevelController _logLevel;
|
||||
private readonly ILogMaintenance _maintenance;
|
||||
private readonly ISettingsFile _settingsFile;
|
||||
private readonly IProfileService _profiles;
|
||||
|
||||
public SettingsViewModel(
|
||||
ISettingsService settings,
|
||||
@@ -36,6 +39,8 @@ public sealed partial class SettingsViewModel : ObservableObject
|
||||
IUpdateDialogService updateDialog,
|
||||
ILogLevelController logLevel,
|
||||
ILogMaintenance maintenance,
|
||||
ISettingsFile settingsFile,
|
||||
IProfileService profiles,
|
||||
IUpdateService updates)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
@@ -44,6 +49,8 @@ public sealed partial class SettingsViewModel : ObservableObject
|
||||
ArgumentNullException.ThrowIfNull(updateDialog);
|
||||
ArgumentNullException.ThrowIfNull(logLevel);
|
||||
ArgumentNullException.ThrowIfNull(maintenance);
|
||||
ArgumentNullException.ThrowIfNull(settingsFile);
|
||||
ArgumentNullException.ThrowIfNull(profiles);
|
||||
ArgumentNullException.ThrowIfNull(updates);
|
||||
|
||||
_settings = settings;
|
||||
@@ -52,12 +59,15 @@ public sealed partial class SettingsViewModel : ObservableObject
|
||||
_updateDialog = updateDialog;
|
||||
_logLevel = logLevel;
|
||||
_maintenance = maintenance;
|
||||
_settingsFile = settingsFile;
|
||||
_profiles = profiles;
|
||||
|
||||
Languages =
|
||||
[
|
||||
new LanguageOption("", Strings.Get("LanguageOption_System")),
|
||||
new LanguageOption("en", "English"),
|
||||
new LanguageOption("vi", "Tiếng Việt"),
|
||||
new LanguageOption("ja", "日本語"),
|
||||
];
|
||||
|
||||
// Initialize from persisted settings directly (field assignment skips the apply/save hooks).
|
||||
@@ -81,8 +91,17 @@ public sealed partial class SettingsViewModel : ObservableObject
|
||||
|
||||
var version = typeof(SettingsViewModel).Assembly.GetName().Version;
|
||||
CurrentVersionText = version is null ? "—" : $"{version.Major}.{version.Minor}.{version.Build}";
|
||||
|
||||
RefreshProfiles();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised after import / apply-profile changes the live settings (incl. favorites), so the shell
|
||||
/// can re-sync favorite stars and dashboards. Appearance/language apply themselves via the
|
||||
/// observable-property setters.
|
||||
/// </summary>
|
||||
public event Action? PortableSettingsApplied;
|
||||
|
||||
[ObservableProperty]
|
||||
private SettingsSection _selectedSection = SettingsSection.Appearance;
|
||||
|
||||
@@ -191,6 +210,172 @@ public sealed partial class SettingsViewModel : ObservableObject
|
||||
LastCheckedText = DateTime.Now.ToString("g", CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
// ---- Profiles (import/export + named profiles) ----
|
||||
|
||||
/// <summary>Saved profile names, for the picker.</summary>
|
||||
public ObservableCollection<string> ProfileNames { get; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(ApplyProfileCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(DeleteProfileCommand))]
|
||||
private string? _selectedProfile;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(SaveProfileCommand))]
|
||||
private string _newProfileName = string.Empty;
|
||||
|
||||
[RelayCommand]
|
||||
private void ExportSettings()
|
||||
{
|
||||
var dialog = new SaveFileDialog
|
||||
{
|
||||
Title = Strings.Get("Settings_ExportSettings"),
|
||||
Filter = "JSON (*.json)|*.json",
|
||||
FileName = $"commandforge-settings-{DateTime.Now:yyyyMMdd-HHmmss}.json",
|
||||
};
|
||||
if (dialog.ShowDialog() != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_settingsFile.Write(dialog.FileName, SettingsTransfer.Capture(_settings));
|
||||
MessageBox.Show(
|
||||
string.Format(CultureInfo.CurrentCulture, Strings.Get("Settings_ExportSuccess"), dialog.FileName),
|
||||
Strings.Get("Settings_Profiles"),
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ImportSettings()
|
||||
{
|
||||
var dialog = new OpenFileDialog
|
||||
{
|
||||
Title = Strings.Get("Settings_ImportSettings"),
|
||||
Filter = "JSON (*.json)|*.json",
|
||||
};
|
||||
if (dialog.ShowDialog() != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var imported = _settingsFile.Read(dialog.FileName);
|
||||
if (imported is null)
|
||||
{
|
||||
MessageBox.Show(
|
||||
Strings.Get("Settings_ImportInvalid"),
|
||||
Strings.Get("Settings_Profiles"),
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show(
|
||||
Strings.Get("Settings_ImportConfirm"),
|
||||
Strings.Get("Settings_ImportSettings"),
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyPortable(imported);
|
||||
MessageBox.Show(
|
||||
Strings.Get("Settings_ImportSuccess"),
|
||||
Strings.Get("Settings_Profiles"),
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanSaveProfile))]
|
||||
private void SaveProfile()
|
||||
{
|
||||
var name = NewProfileName.Trim();
|
||||
if (name.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_profiles.Save(name, SettingsTransfer.Capture(_settings));
|
||||
NewProfileName = string.Empty;
|
||||
RefreshProfiles();
|
||||
SelectedProfile = name;
|
||||
}
|
||||
|
||||
private bool CanSaveProfile() => !string.IsNullOrWhiteSpace(NewProfileName);
|
||||
|
||||
[RelayCommand(CanExecute = nameof(HasSelectedProfile))]
|
||||
private void ApplyProfile()
|
||||
{
|
||||
if (SelectedProfile is not { } name || _profiles.Get(name) is not { } portable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyPortable(portable);
|
||||
MessageBox.Show(
|
||||
string.Format(CultureInfo.CurrentCulture, Strings.Get("Settings_ProfileApplied"), name),
|
||||
Strings.Get("Settings_Profiles"),
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(HasSelectedProfile))]
|
||||
private void DeleteProfile()
|
||||
{
|
||||
if (SelectedProfile is not { } name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show(
|
||||
string.Format(CultureInfo.CurrentCulture, Strings.Get("Settings_DeleteProfileConfirm"), name),
|
||||
Strings.Get("Settings_DeleteProfile"),
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning) != MessageBoxResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_profiles.Delete(name);
|
||||
RefreshProfiles();
|
||||
}
|
||||
|
||||
private bool HasSelectedProfile() => SelectedProfile is not null;
|
||||
|
||||
private void RefreshProfiles()
|
||||
{
|
||||
ProfileNames.Clear();
|
||||
foreach (var name in _profiles.GetNames())
|
||||
{
|
||||
ProfileNames.Add(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a portable payload to the live app: appearance/behavior via the observable setters
|
||||
/// (which apply + persist), favorites straight to settings, then notifies the shell to re-sync.
|
||||
/// </summary>
|
||||
private void ApplyPortable(PortableSettings portable)
|
||||
{
|
||||
SelectedTheme = portable.Theme;
|
||||
SelectedLanguage = Languages.FirstOrDefault(l => l.Code == portable.Language) ?? Languages[0];
|
||||
SelectedFontSize = portable.FontSize;
|
||||
CollapseSidebarByDefault = portable.CollapseSidebarByDefault;
|
||||
ShowAdminRestartBadges = portable.ShowAdminRestartBadges;
|
||||
ConfirmCaution = portable.ConfirmCaution;
|
||||
AutoCreateRestorePoint = portable.AutoCreateRestorePoint;
|
||||
AutoScrollConsole = portable.AutoScrollConsole;
|
||||
WarnOnCancel = portable.WarnOnCancel;
|
||||
AutoCheckForUpdates = portable.AutoCheckForUpdates;
|
||||
SelectedLogLevel = portable.LogLevel;
|
||||
|
||||
// Favorites have no observable property here — write them to settings + notify the shell.
|
||||
_settings.FavoriteCommandIds = portable.FavoriteCommandIds;
|
||||
_settings.Save();
|
||||
PortableSettingsApplied?.Invoke();
|
||||
}
|
||||
|
||||
// ---- Logs ----
|
||||
|
||||
public IReadOnlyList<LogLevel> LogLevels { get; } = [LogLevel.Information, LogLevel.Debug, LogLevel.Verbose];
|
||||
|
||||
@@ -9,6 +9,15 @@ public enum ShellSection
|
||||
/// <summary>The command catalog (browse/search/run).</summary>
|
||||
Catalog,
|
||||
|
||||
/// <summary>The execution-history screen (past runs, re-run).</summary>
|
||||
History,
|
||||
|
||||
/// <summary>The recipes screen (build/run command chains).</summary>
|
||||
Recipes,
|
||||
|
||||
/// <summary>The user-defined commands screen (non-elevated, separate from the catalog).</summary>
|
||||
UserCommands,
|
||||
|
||||
/// <summary>The Settings screen.</summary>
|
||||
Settings,
|
||||
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Application.UserCommands;
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Wpf.Resources;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace CommandForge.Wpf.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// "My commands" screen: create and run user-defined commands. These are kept entirely separate
|
||||
/// from the vetted catalog and ALWAYS run without elevation (golden rule #1) — the run path uses
|
||||
/// <see cref="UserCommandFactory.ToDefinition"/>, which forces RequiresAdmin = false.
|
||||
/// </summary>
|
||||
public sealed partial class UserCommandsViewModel : ObservableObject
|
||||
{
|
||||
private readonly IUserCommandStore _store;
|
||||
private readonly ExecutionViewModel _execution;
|
||||
private string? _editingId;
|
||||
|
||||
public UserCommandsViewModel(IUserCommandStore store, ExecutionViewModel execution)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(store);
|
||||
ArgumentNullException.ThrowIfNull(execution);
|
||||
|
||||
_store = store;
|
||||
_execution = execution;
|
||||
|
||||
_execution.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(ExecutionViewModel.IsRunning))
|
||||
{
|
||||
RunCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
};
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
/// <summary>The shared execution view-model — drives the console output panel.</summary>
|
||||
public ExecutionViewModel Execution => _execution;
|
||||
|
||||
/// <summary>Saved user commands.</summary>
|
||||
public ObservableCollection<UserCommand> Commands { get; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(DeleteCommand))]
|
||||
private UserCommand? _selectedCommand;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
|
||||
private string _editName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(RunCommand))]
|
||||
private string _editExecutable = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _editArguments = string.Empty;
|
||||
|
||||
/// <summary>Reloads the saved-command list from the store.</summary>
|
||||
public void Refresh()
|
||||
{
|
||||
Commands.Clear();
|
||||
foreach (var command in _store.GetAll())
|
||||
{
|
||||
Commands.Add(command);
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedCommandChanged(UserCommand? value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_editingId = value.Id;
|
||||
EditName = value.Name;
|
||||
EditExecutable = value.Executable;
|
||||
EditArguments = value.Arguments;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void New()
|
||||
{
|
||||
SelectedCommand = null;
|
||||
_editingId = null;
|
||||
EditName = string.Empty;
|
||||
EditExecutable = string.Empty;
|
||||
EditArguments = string.Empty;
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanSave))]
|
||||
private void Save()
|
||||
{
|
||||
var name = EditName.Trim();
|
||||
var executable = EditExecutable.Trim();
|
||||
if (name.Length == 0 || executable.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var id = _editingId ?? Guid.NewGuid().ToString("N");
|
||||
_store.Save(new UserCommand { Id = id, Name = name, Executable = executable, Arguments = EditArguments.Trim() });
|
||||
_editingId = id;
|
||||
Refresh();
|
||||
SelectedCommand = Commands.FirstOrDefault(c => string.Equals(c.Id, id, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
private bool CanSave() => !string.IsNullOrWhiteSpace(EditName) && !string.IsNullOrWhiteSpace(EditExecutable);
|
||||
|
||||
[RelayCommand(CanExecute = nameof(HasSelected))]
|
||||
private void Delete()
|
||||
{
|
||||
if (SelectedCommand is not { } command)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show(
|
||||
string.Format(CultureInfo.CurrentCulture, Strings.Get("UserCmd_DeleteConfirm"), command.Name),
|
||||
Strings.Get("UserCmd_Delete"),
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning) != MessageBoxResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_store.Delete(command.Id);
|
||||
New();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private bool HasSelected() => SelectedCommand is not null;
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanRun))]
|
||||
private async Task RunAsync()
|
||||
{
|
||||
var executable = EditExecutable.Trim();
|
||||
if (executable.Length == 0 || _execution.IsRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var userCommand = new UserCommand
|
||||
{
|
||||
Id = _editingId ?? "unsaved",
|
||||
Name = string.IsNullOrWhiteSpace(EditName) ? executable : EditName.Trim(),
|
||||
Executable = executable,
|
||||
Arguments = EditArguments.Trim(),
|
||||
};
|
||||
|
||||
// Transparency (Security.md §3): show the exact command line that will run (including the
|
||||
// cmd /c normalization applied by ToDefinition) and that it runs without admin.
|
||||
var effectiveArgs = UserCommandFactory.NormalizeArguments(executable, userCommand.Arguments);
|
||||
var commandLine = string.IsNullOrEmpty(effectiveArgs)
|
||||
? executable
|
||||
: executable + " " + effectiveArgs;
|
||||
if (MessageBox.Show(
|
||||
string.Format(CultureInfo.CurrentCulture, Strings.Get("UserCmd_RunConfirm"), commandLine),
|
||||
Strings.Get("UserCmd_RunTitle"),
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning) != MessageBoxResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// SAFETY: ToDefinition forces RequiresAdmin = false → runs asInvoker, never via the broker.
|
||||
await _execution.RunAsync(UserCommandFactory.ToDefinition(userCommand));
|
||||
}
|
||||
|
||||
private bool CanRun() => !string.IsNullOrWhiteSpace(EditExecutable) && !_execution.IsRunning;
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
@@ -33,8 +34,28 @@
|
||||
materialDesign:HintAssist.Hint="{res:Loc Search_Placeholder}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Natural-language search suggestion (local; shown when a NL phrase maps to a keyword) -->
|
||||
<Button Grid.Row="1" HorizontalAlignment="Left" Margin="44,0,14,8" Padding="8,2" Height="28" MinWidth="0"
|
||||
Command="{Binding ApplySuggestionCommand}">
|
||||
<Button.Style>
|
||||
<Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding SearchSuggestion}" Value="{x:Null}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="LightbulbOnOutline" Width="16" Height="16" VerticalAlignment="Center" Margin="0,0,6,0" />
|
||||
<TextBlock Text="{res:Loc Search_Suggestion}" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding SearchSuggestion}" FontWeight="Medium" Margin="4,0,0,0" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<!-- Body: command list + detail/console -->
|
||||
<Grid Grid.Row="1" Margin="8,0,8,8">
|
||||
<Grid Grid.Row="2" Margin="8,0,8,8">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" MinWidth="220" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<UserControl x:Class="CommandForge.Wpf.Views.HistoryView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:res="clr-namespace:CommandForge.Wpf.Resources"
|
||||
xmlns:conv="clr-namespace:CommandForge.Wpf.Converters">
|
||||
<UserControl.Resources>
|
||||
<conv:StringToPackIconKindConverter x:Key="IconConverter" />
|
||||
<BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||
|
||||
<!-- One past run: icon, title + metadata line (time · status · duration), and a Run-again button. -->
|
||||
<DataTemplate x:Key="HistoryItem">
|
||||
<Border Padding="10,8" Margin="0,1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<materialDesign:PackIcon Grid.Column="0"
|
||||
Kind="{Binding Icon, Converter={StaticResource IconConverter}}"
|
||||
Width="20" Height="20" VerticalAlignment="Center" Margin="0,0,10,0" />
|
||||
<StackPanel Grid.Column="1" VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Title}" FontWeight="Medium" TextTrimming="CharacterEllipsis" />
|
||||
<StackPanel Orientation="Horizontal" Opacity="0.6">
|
||||
<TextBlock Text="{Binding TimeText}" FontSize="12" />
|
||||
<TextBlock Text=" · " FontSize="12" />
|
||||
<TextBlock Text="{Binding StatusText}" FontSize="12" />
|
||||
<TextBlock Text=" · " FontSize="12" />
|
||||
<TextBlock Text="{Binding DurationText}" FontSize="12" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" Content="{res:Loc History_Undo}"
|
||||
Visibility="{Binding CanUndo, Converter={StaticResource BoolToVis}}"
|
||||
Command="{Binding DataContext.UndoCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}" />
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" Content="{res:Loc History_RunAgain}"
|
||||
IsEnabled="{Binding CanRun}"
|
||||
Command="{Binding DataContext.RunAgainCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</UserControl.Resources>
|
||||
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" Padding="28,20,28,24">
|
||||
<StackPanel MaxWidth="1000" HorizontalAlignment="Left">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="{res:Loc History_Title}" FontSize="24" FontWeight="Bold"
|
||||
VerticalAlignment="Center" AutomationProperties.HeadingLevel="Level1" />
|
||||
<Button Grid.Column="1" Style="{StaticResource MaterialDesignFlatButton}"
|
||||
Content="{res:Loc History_Clear}" Command="{Binding ClearCommand}"
|
||||
Visibility="{Binding HasEntries, Converter={StaticResource BoolToVis}}" />
|
||||
</Grid>
|
||||
|
||||
<materialDesign:Card Padding="6" Margin="0,12,0,8">
|
||||
<Grid>
|
||||
<ItemsControl ItemsSource="{Binding Entries}" ItemTemplate="{StaticResource HistoryItem}"
|
||||
Visibility="{Binding HasEntries, Converter={StaticResource BoolToVis}}" />
|
||||
<TextBlock Text="{res:Loc History_Empty}" Opacity="0.6" Margin="10" TextWrapping="Wrap">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding HasEntries}" Value="False">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CommandForge.Wpf.Views;
|
||||
|
||||
/// <summary>The execution-history view (past runs, re-run, clear).</summary>
|
||||
public partial class HistoryView : UserControl
|
||||
{
|
||||
public HistoryView() => InitializeComponent();
|
||||
}
|
||||
@@ -99,6 +99,34 @@
|
||||
</materialDesign:Card>
|
||||
</WrapPanel>
|
||||
|
||||
<!-- Maintenance suggestions (local heuristics over the read-only status) -->
|
||||
<StackPanel Visibility="{Binding HasSuggestions, Converter={StaticResource BoolToVis}}">
|
||||
<TextBlock Text="{res:Loc Home_Suggestions}" Style="{StaticResource SectionHeaderStyle}" />
|
||||
<ItemsControl ItemsSource="{Binding Suggestions}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<materialDesign:Card Padding="12,8" Margin="0,0,0,6">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<materialDesign:PackIcon Grid.Column="0" Kind="LightbulbOnOutline" Width="20" Height="20"
|
||||
VerticalAlignment="Center" Margin="0,0,10,0" Opacity="0.8" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding Reason}" TextWrapping="Wrap" VerticalAlignment="Center" />
|
||||
<Button Grid.Column="2" Content="{res:Loc Maint_Open}"
|
||||
Style="{StaticResource MaterialDesignFlatButton}"
|
||||
Visibility="{Binding CanOpen, Converter={StaticResource BoolToVis}}"
|
||||
Command="{Binding DataContext.OpenCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding Command}" />
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Recently-run commands -->
|
||||
<TextBlock Text="{res:Loc Home_Recent}" Style="{StaticResource SectionHeaderStyle}" />
|
||||
<materialDesign:Card Padding="6">
|
||||
|
||||
@@ -26,6 +26,15 @@
|
||||
<DataTemplate x:Key="CatalogTemplate">
|
||||
<views:CatalogView />
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="HistoryTemplate">
|
||||
<views:HistoryView DataContext="{Binding History}" />
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="RecipesTemplate">
|
||||
<views:RecipesView DataContext="{Binding Recipes}" />
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="UserCommandsTemplate">
|
||||
<views:UserCommandsView DataContext="{Binding UserCommands}" />
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="SettingsTemplate">
|
||||
<views:SettingsView DataContext="{Binding Settings}" />
|
||||
</DataTemplate>
|
||||
@@ -65,6 +74,9 @@
|
||||
<MenuItem Header="{res:Loc MenuView}">
|
||||
<MenuItem Header="{res:Loc SidebarHome}" Command="{Binding ShowHomeCommand}" InputGestureText="Ctrl+H" />
|
||||
<MenuItem Header="{res:Loc SidebarFavorites}" Command="{Binding ShowFavoritesCommand}" />
|
||||
<MenuItem Header="{res:Loc SidebarHistory}" Command="{Binding ShowHistoryCommand}" />
|
||||
<MenuItem Header="{res:Loc SidebarRecipes}" Command="{Binding ShowRecipesCommand}" />
|
||||
<MenuItem Header="{res:Loc SidebarUserCommands}" Command="{Binding ShowUserCommandsCommand}" />
|
||||
<Separator />
|
||||
<MenuItem Header="{res:Loc Settings_Theme}">
|
||||
<MenuItem Header="{res:Loc Settings_ThemeSystem}" Command="{Binding Settings.SetThemeCommand}"
|
||||
@@ -98,6 +110,9 @@
|
||||
<MenuItem Header="Tiếng Việt" Command="{Binding Settings.SetLanguageCommand}"
|
||||
CommandParameter="vi"
|
||||
IsChecked="{Binding Settings.SelectedLanguage.Code, Converter={StaticResource StringEquals}, ConverterParameter=vi, Mode=OneWay}" />
|
||||
<MenuItem Header="日本語" Command="{Binding Settings.SetLanguageCommand}"
|
||||
CommandParameter="ja"
|
||||
IsChecked="{Binding Settings.SelectedLanguage.Code, Converter={StaticResource StringEquals}, ConverterParameter=ja, Mode=OneWay}" />
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="{res:Loc MenuToggleSidebar}" Command="{Binding ToggleSidebarCommand}" InputGestureText="Ctrl+B" />
|
||||
@@ -175,6 +190,36 @@
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button DockPanel.Dock="Top" Style="{StaticResource SidebarButtonStyle}"
|
||||
Command="{Binding ShowHistoryCommand}"
|
||||
AutomationProperties.Name="{res:Loc SidebarHistory}"
|
||||
ToolTip="{res:Loc SidebarHistory}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="History" Width="22" Height="22" />
|
||||
<TextBlock Text="{res:Loc SidebarHistory}" Style="{StaticResource SidebarLabelStyle}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button DockPanel.Dock="Top" Style="{StaticResource SidebarButtonStyle}"
|
||||
Command="{Binding ShowRecipesCommand}"
|
||||
AutomationProperties.Name="{res:Loc SidebarRecipes}"
|
||||
ToolTip="{res:Loc SidebarRecipes}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="PlaylistPlay" Width="22" Height="22" />
|
||||
<TextBlock Text="{res:Loc SidebarRecipes}" Style="{StaticResource SidebarLabelStyle}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button DockPanel.Dock="Top" Style="{StaticResource SidebarButtonStyle}"
|
||||
Command="{Binding ShowUserCommandsCommand}"
|
||||
AutomationProperties.Name="{res:Loc SidebarUserCommands}"
|
||||
ToolTip="{res:Loc SidebarUserCommands}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="ScriptTextOutline" Width="22" Height="22" />
|
||||
<TextBlock Text="{res:Loc SidebarUserCommands}" Style="{StaticResource SidebarLabelStyle}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button DockPanel.Dock="Bottom" Style="{StaticResource SidebarButtonStyle}"
|
||||
Margin="0,0,0,10"
|
||||
Command="{Binding ShowSettingsCommand}"
|
||||
@@ -189,7 +234,8 @@
|
||||
<ListBox ItemsSource="{Binding Categories}" SelectedItem="{Binding SelectedCategory}"
|
||||
Background="Transparent" BorderThickness="0" Padding="4,4"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Hidden">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
|
||||
<Setter Property="Padding" Value="12,8" />
|
||||
@@ -227,6 +273,15 @@
|
||||
<DataTrigger Binding="{Binding CurrentSection}" Value="Home">
|
||||
<Setter Property="ContentTemplate" Value="{StaticResource HomeTemplate}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding CurrentSection}" Value="History">
|
||||
<Setter Property="ContentTemplate" Value="{StaticResource HistoryTemplate}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding CurrentSection}" Value="Recipes">
|
||||
<Setter Property="ContentTemplate" Value="{StaticResource RecipesTemplate}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding CurrentSection}" Value="UserCommands">
|
||||
<Setter Property="ContentTemplate" Value="{StaticResource UserCommandsTemplate}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding CurrentSection}" Value="Settings">
|
||||
<Setter Property="ContentTemplate" Value="{StaticResource SettingsTemplate}" />
|
||||
</DataTrigger>
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
<UserControl x:Class="CommandForge.Wpf.Views.RecipesView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:res="clr-namespace:CommandForge.Wpf.Resources"
|
||||
xmlns:conv="clr-namespace:CommandForge.Wpf.Converters"
|
||||
xmlns:beh="clr-namespace:CommandForge.Wpf.Behaviors">
|
||||
<UserControl.Resources>
|
||||
<conv:StringToPackIconKindConverter x:Key="IconConverter" />
|
||||
<conv:DangerLevelToBrushConverter x:Key="DangerBrush" />
|
||||
<BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||
|
||||
<Style x:Key="IconBtn" TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}">
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="MinWidth" Value="0" />
|
||||
<Setter Property="Width" Value="30" />
|
||||
<Setter Property="Height" Value="30" />
|
||||
</Style>
|
||||
|
||||
<!-- One recipe step: icon + title + danger dot + reorder/remove buttons. -->
|
||||
<DataTemplate x:Key="StepItem">
|
||||
<Grid Margin="2,1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<materialDesign:PackIcon Grid.Column="0" VerticalAlignment="Center" Margin="2,0,10,0"
|
||||
Width="18" Height="18"
|
||||
Kind="{Binding Icon, Converter={StaticResource IconConverter}}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding Title}" VerticalAlignment="Center"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
<Ellipse Grid.Column="2" Width="9" Height="9" VerticalAlignment="Center" Margin="6,0"
|
||||
Fill="{Binding DangerLevel, Converter={StaticResource DangerBrush}}" />
|
||||
<StackPanel Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Button Style="{StaticResource IconBtn}" ToolTip="{res:Loc Recipes_MoveUp}"
|
||||
AutomationProperties.Name="{res:Loc Recipes_MoveUp}"
|
||||
Command="{Binding DataContext.MoveStepUpCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}">
|
||||
<materialDesign:PackIcon Kind="ArrowUp" Width="16" Height="16" />
|
||||
</Button>
|
||||
<Button Style="{StaticResource IconBtn}" ToolTip="{res:Loc Recipes_MoveDown}"
|
||||
AutomationProperties.Name="{res:Loc Recipes_MoveDown}"
|
||||
Command="{Binding DataContext.MoveStepDownCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}">
|
||||
<materialDesign:PackIcon Kind="ArrowDown" Width="16" Height="16" />
|
||||
</Button>
|
||||
<Button Style="{StaticResource IconBtn}" ToolTip="{res:Loc Recipes_RemoveStep}"
|
||||
AutomationProperties.Name="{res:Loc Recipes_RemoveStep}"
|
||||
Command="{Binding DataContext.RemoveStepCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}">
|
||||
<materialDesign:PackIcon Kind="Close" Width="16" Height="16" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid Margin="16">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="230" />
|
||||
<ColumnDefinition Width="*" MinWidth="360" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Left: saved recipes -->
|
||||
<DockPanel Grid.Column="0" Margin="0,0,12,0">
|
||||
<TextBlock DockPanel.Dock="Top" Text="{res:Loc Recipes_Saved}" FontWeight="Bold" Margin="0,0,0,8"
|
||||
AutomationProperties.HeadingLevel="Level2" />
|
||||
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="0,8,0,0">
|
||||
<Button Content="{res:Loc Recipes_New}" Command="{Binding NewRecipeCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Margin="0,0,8,0"
|
||||
AutomationProperties.Name="{res:Loc Recipes_New}" />
|
||||
<Button Content="{res:Loc Recipe_Delete}" Command="{Binding DeleteRecipeCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}"
|
||||
AutomationProperties.Name="{res:Loc Recipe_Delete}" />
|
||||
</StackPanel>
|
||||
<ListBox ItemsSource="{Binding RecipeNames}" SelectedItem="{Binding SelectedRecipeName}"
|
||||
BorderThickness="0" Background="Transparent"
|
||||
AutomationProperties.Name="{res:Loc Recipes_Saved}" />
|
||||
</DockPanel>
|
||||
|
||||
<!-- Right: editor + console -->
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" MinHeight="120" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Text="{res:Loc SidebarRecipes}" FontSize="20" FontWeight="Bold"
|
||||
Margin="0,0,0,8" AutomationProperties.HeadingLevel="Level1" />
|
||||
|
||||
<TextBox Grid.Row="0" VerticalAlignment="Bottom" Margin="0,28,0,8"
|
||||
materialDesign:HintAssist.Hint="{res:Loc Recipes_NameHint}"
|
||||
AutomationProperties.Name="{res:Loc Recipes_NameHint}"
|
||||
Text="{Binding RecipeName, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
<!-- Steps -->
|
||||
<materialDesign:Card Grid.Row="1" Padding="6">
|
||||
<Grid>
|
||||
<ItemsControl ItemsSource="{Binding Steps}" ItemTemplate="{StaticResource StepItem}">
|
||||
<ItemsControl.Template>
|
||||
<ControlTemplate TargetType="ItemsControl">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<ItemsPresenter />
|
||||
</ScrollViewer>
|
||||
</ControlTemplate>
|
||||
</ItemsControl.Template>
|
||||
</ItemsControl>
|
||||
<TextBlock Text="{res:Loc Recipes_NoSteps}" Opacity="0.6" Margin="10" TextWrapping="Wrap"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Steps.Count}" Value="0">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</materialDesign:Card>
|
||||
|
||||
<!-- Add step + actions -->
|
||||
<Grid Grid.Row="2" Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||
<ComboBox Width="240" VerticalAlignment="Center"
|
||||
ItemsSource="{Binding AllCommands}" SelectedItem="{Binding CommandToAdd}"
|
||||
DisplayMemberPath="Title"
|
||||
materialDesign:HintAssist.Hint="{res:Loc Recipes_AddHint}"
|
||||
AutomationProperties.Name="{res:Loc Recipes_AddHint}" />
|
||||
<Button Content="{res:Loc Recipes_AddStep}" Command="{Binding AddStepCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Margin="8,0,0,0"
|
||||
AutomationProperties.Name="{res:Loc Recipes_AddStep}" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
<Button Content="{res:Loc Recipes_Save}" Command="{Binding SaveRecipeCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Margin="8,0,0,0"
|
||||
AutomationProperties.Name="{res:Loc Recipes_Save}" />
|
||||
<Button Content="{res:Loc Recipes_Run}" Command="{Binding RunRecipeCommand}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}" Margin="8,0,0,0"
|
||||
AutomationProperties.Name="{res:Loc Recipes_Run}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Console + result (shared execution VM) -->
|
||||
<materialDesign:Card Grid.Row="3" Margin="0,8,0,0" Padding="12" MaxHeight="300"
|
||||
Visibility="{Binding Execution.ShowConsole, Converter={StaticResource BoolToVis}}">
|
||||
<DockPanel>
|
||||
<Grid DockPanel.Dock="Top">
|
||||
<TextBlock Text="{res:Loc PaneConsole}" FontWeight="Bold" VerticalAlignment="Center" />
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right"
|
||||
Visibility="{Binding Execution.IsRunning, Converter={StaticResource BoolToVis}}">
|
||||
<ProgressBar IsIndeterminate="True" Width="90" Height="4" VerticalAlignment="Center" Margin="0,0,8,0" />
|
||||
<Button Content="{res:Loc Console_Cancel}" Command="{Binding Execution.CancelCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Padding="8,2" Height="28" MinWidth="0" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="0,8,0,0"
|
||||
Visibility="{Binding Execution.HasResult, Converter={StaticResource BoolToVis}}">
|
||||
<TextBlock Text="{Binding Execution.StatusText}" FontWeight="Medium" />
|
||||
<TextBlock Text="{res:Loc Result_ExitCode}" Opacity="0.7" Margin="14,0,4,0" />
|
||||
<TextBlock Text="{Binding Execution.ExitCode}" Opacity="0.7" />
|
||||
<TextBlock Text="{Binding Execution.DurationText}" Opacity="0.7" Margin="14,0,0,0" />
|
||||
</StackPanel>
|
||||
|
||||
<Border Background="{DynamicResource MaterialDesignToolBarBackground}" CornerRadius="4" Margin="0,8,0,0">
|
||||
<ScrollViewer beh:AutoScroll.Enabled="True" VerticalScrollBarVisibility="Auto" MaxHeight="200" Padding="8">
|
||||
<ItemsControl ItemsSource="{Binding Execution.OutputLines}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Text}" TextWrapping="Wrap"
|
||||
FontFamily="Cascadia Mono, Consolas, Courier New" FontSize="12">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsError}" Value="True">
|
||||
<Setter Property="Foreground" Value="#E0884D" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
</materialDesign:Card>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CommandForge.Wpf.Views;
|
||||
|
||||
/// <summary>The recipes view (build/run command chains).</summary>
|
||||
public partial class RecipesView : UserControl
|
||||
{
|
||||
public RecipesView() => InitializeComponent();
|
||||
}
|
||||
@@ -41,6 +41,9 @@
|
||||
<RadioButton Content="{res:Loc Settings_Updates}" GroupName="Section" Style="{StaticResource NavRadio}"
|
||||
AutomationProperties.Name="{res:Loc Settings_Updates}"
|
||||
IsChecked="{Binding SelectedSection, Converter={StaticResource EnumBool}, ConverterParameter=Updates}" />
|
||||
<RadioButton Content="{res:Loc Settings_Profiles}" GroupName="Section" Style="{StaticResource NavRadio}"
|
||||
AutomationProperties.Name="{res:Loc Settings_Profiles}"
|
||||
IsChecked="{Binding SelectedSection, Converter={StaticResource EnumBool}, ConverterParameter=Profiles}" />
|
||||
<RadioButton Content="{res:Loc Settings_Logs}" GroupName="Section" Style="{StaticResource NavRadio}"
|
||||
AutomationProperties.Name="{res:Loc Settings_Logs}"
|
||||
IsChecked="{Binding SelectedSection, Converter={StaticResource EnumBool}, ConverterParameter=Logs}" />
|
||||
@@ -181,6 +184,60 @@
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Backup & profiles (import/export + named profiles) -->
|
||||
<StackPanel>
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding SelectedSection}" Value="Profiles">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
|
||||
<TextBlock Text="{res:Loc Settings_Profiles}" Style="{StaticResource SectionHeader}" />
|
||||
|
||||
<TextBlock Text="{res:Loc Settings_ExportImport}" Style="{StaticResource RowLabel}" />
|
||||
<TextBlock Text="{res:Loc Settings_ExportImportHint}" Opacity="0.7" TextWrapping="Wrap" Margin="0,0,0,8" />
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Content="{res:Loc Settings_ExportSettings}" Command="{Binding ExportSettingsCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Margin="0,0,8,0"
|
||||
AutomationProperties.Name="{res:Loc Settings_ExportSettings}" />
|
||||
<Button Content="{res:Loc Settings_ImportSettings}" Command="{Binding ImportSettingsCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}"
|
||||
AutomationProperties.Name="{res:Loc Settings_ImportSettings}" />
|
||||
</StackPanel>
|
||||
|
||||
<Separator Margin="0,20,0,0" />
|
||||
|
||||
<TextBlock Text="{res:Loc Settings_SavedProfiles}" Style="{StaticResource RowLabel}" />
|
||||
<TextBlock Text="{res:Loc Settings_ProfilesHint}" Opacity="0.7" TextWrapping="Wrap" Margin="0,0,0,8" />
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ComboBox Width="220" HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||
AutomationProperties.Name="{res:Loc Settings_SavedProfiles}"
|
||||
ItemsSource="{Binding ProfileNames}" SelectedItem="{Binding SelectedProfile}" />
|
||||
<Button Content="{res:Loc Settings_ApplyProfile}" Command="{Binding ApplyProfileCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Margin="8,0,0,0"
|
||||
AutomationProperties.Name="{res:Loc Settings_ApplyProfile}" />
|
||||
<Button Content="{res:Loc Settings_DeleteProfile}" Command="{Binding DeleteProfileCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Margin="8,0,0,0"
|
||||
AutomationProperties.Name="{res:Loc Settings_DeleteProfile}" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Text="{res:Loc Settings_SaveCurrentAsProfile}" Style="{StaticResource RowLabel}" />
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox Width="220" HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||
materialDesign:HintAssist.Hint="{res:Loc Settings_ProfileName}"
|
||||
AutomationProperties.Name="{res:Loc Settings_ProfileName}"
|
||||
Text="{Binding NewProfileName, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<Button Content="{res:Loc Settings_SaveProfile}" Command="{Binding SaveProfileCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Margin="8,0,0,0"
|
||||
AutomationProperties.Name="{res:Loc Settings_SaveProfile}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Logs -->
|
||||
<StackPanel>
|
||||
<StackPanel.Style>
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
<UserControl x:Class="CommandForge.Wpf.Views.UserCommandsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:res="clr-namespace:CommandForge.Wpf.Resources"
|
||||
xmlns:conv="clr-namespace:CommandForge.Wpf.Converters"
|
||||
xmlns:beh="clr-namespace:CommandForge.Wpf.Behaviors">
|
||||
<UserControl.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||
<Style x:Key="RowLabel" TargetType="TextBlock">
|
||||
<Setter Property="FontWeight" Value="Medium" />
|
||||
<Setter Property="Margin" Value="0,12,0,4" />
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Text="{res:Loc SidebarUserCommands}" FontSize="20" FontWeight="Bold"
|
||||
AutomationProperties.HeadingLevel="Level1" />
|
||||
|
||||
<!-- Prominent, always-visible warning: these are untrusted and never elevated. -->
|
||||
<Border Grid.Row="1" Margin="0,8,0,4" CornerRadius="4" Padding="12,8"
|
||||
Background="#33E0884D" BorderBrush="#E0884D" BorderThickness="1">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="AlertOutline" Width="20" Height="20" VerticalAlignment="Center"
|
||||
Margin="0,0,10,0" Foreground="#E0884D" />
|
||||
<TextBlock Text="{res:Loc UserCmd_Warning}" TextWrapping="Wrap" VerticalAlignment="Center"
|
||||
MaxWidth="820" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Row="2" Margin="0,8,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="220" />
|
||||
<ColumnDefinition Width="*" MinWidth="340" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Left: saved commands -->
|
||||
<DockPanel Grid.Column="0" Margin="0,0,12,0">
|
||||
<TextBlock DockPanel.Dock="Top" Text="{res:Loc UserCmd_Saved}" FontWeight="Bold" Margin="0,0,0,8"
|
||||
AutomationProperties.HeadingLevel="Level2" />
|
||||
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="0,8,0,0">
|
||||
<Button Content="{res:Loc UserCmd_New}" Command="{Binding NewCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Margin="0,0,8,0"
|
||||
AutomationProperties.Name="{res:Loc UserCmd_New}" />
|
||||
<Button Content="{res:Loc UserCmd_Delete}" Command="{Binding DeleteCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}"
|
||||
AutomationProperties.Name="{res:Loc UserCmd_Delete}" />
|
||||
</StackPanel>
|
||||
<Grid>
|
||||
<ListBox ItemsSource="{Binding Commands}" SelectedItem="{Binding SelectedCommand}"
|
||||
DisplayMemberPath="Name" BorderThickness="0" Background="Transparent"
|
||||
AutomationProperties.Name="{res:Loc UserCmd_Saved}" />
|
||||
<TextBlock Text="{res:Loc UserCmd_NoCommands}" Opacity="0.6" Margin="6,8" TextWrapping="Wrap"
|
||||
VerticalAlignment="Top">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Commands.Count}" Value="0">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
|
||||
<!-- Right: editor + console -->
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Grid.Row="0">
|
||||
<TextBlock Text="{res:Loc UserCmd_NameHint}" Style="{StaticResource RowLabel}" />
|
||||
<TextBox Text="{Binding EditName, UpdateSourceTrigger=PropertyChanged}"
|
||||
AutomationProperties.Name="{res:Loc UserCmd_NameHint}" />
|
||||
<TextBlock Text="{res:Loc UserCmd_ExecutableHint}" Style="{StaticResource RowLabel}" />
|
||||
<TextBox Text="{Binding EditExecutable, UpdateSourceTrigger=PropertyChanged}"
|
||||
FontFamily="Cascadia Mono, Consolas, Courier New"
|
||||
AutomationProperties.Name="{res:Loc UserCmd_ExecutableHint}" />
|
||||
<TextBlock Text="{res:Loc UserCmd_ArgumentsHint}" Style="{StaticResource RowLabel}" />
|
||||
<TextBox Text="{Binding EditArguments, UpdateSourceTrigger=PropertyChanged}"
|
||||
FontFamily="Cascadia Mono, Consolas, Courier New" TextWrapping="Wrap"
|
||||
AcceptsReturn="False"
|
||||
AutomationProperties.Name="{res:Loc UserCmd_ArgumentsHint}" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,16,0,0">
|
||||
<Button Content="{res:Loc UserCmd_Save}" Command="{Binding SaveCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Margin="0,0,8,0"
|
||||
AutomationProperties.Name="{res:Loc UserCmd_Save}" />
|
||||
<Button Content="{res:Loc UserCmd_Run}" Command="{Binding RunCommand}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
AutomationProperties.Name="{res:Loc UserCmd_Run}" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Console + result (shared execution VM) -->
|
||||
<materialDesign:Card Grid.Row="2" Margin="0,12,0,0" Padding="12" MaxHeight="280"
|
||||
VerticalAlignment="Top"
|
||||
Visibility="{Binding Execution.ShowConsole, Converter={StaticResource BoolToVis}}">
|
||||
<DockPanel>
|
||||
<Grid DockPanel.Dock="Top">
|
||||
<TextBlock Text="{res:Loc PaneConsole}" FontWeight="Bold" VerticalAlignment="Center" />
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right"
|
||||
Visibility="{Binding Execution.IsRunning, Converter={StaticResource BoolToVis}}">
|
||||
<ProgressBar IsIndeterminate="True" Width="90" Height="4" VerticalAlignment="Center" Margin="0,0,8,0" />
|
||||
<Button Content="{res:Loc Console_Cancel}" Command="{Binding Execution.CancelCommand}"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}" Padding="8,2" Height="28" MinWidth="0" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="0,8,0,0"
|
||||
Visibility="{Binding Execution.HasResult, Converter={StaticResource BoolToVis}}">
|
||||
<TextBlock Text="{Binding Execution.StatusText}" FontWeight="Medium" />
|
||||
<TextBlock Text="{res:Loc Result_ExitCode}" Opacity="0.7" Margin="14,0,4,0" />
|
||||
<TextBlock Text="{Binding Execution.ExitCode}" Opacity="0.7" />
|
||||
<TextBlock Text="{Binding Execution.DurationText}" Opacity="0.7" Margin="14,0,0,0" />
|
||||
</StackPanel>
|
||||
|
||||
<Border Background="{DynamicResource MaterialDesignToolBarBackground}" CornerRadius="4" Margin="0,8,0,0">
|
||||
<ScrollViewer beh:AutoScroll.Enabled="True" VerticalScrollBarVisibility="Auto" MaxHeight="180" Padding="8">
|
||||
<ItemsControl ItemsSource="{Binding Execution.OutputLines}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Text}" TextWrapping="Wrap"
|
||||
FontFamily="Cascadia Mono, Consolas, Courier New" FontSize="12">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsError}" Value="True">
|
||||
<Setter Property="Foreground" Value="#E0884D" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
</materialDesign:Card>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace CommandForge.Wpf.Views;
|
||||
|
||||
/// <summary>The user-defined commands view (non-elevated, separate from the catalog).</summary>
|
||||
public partial class UserCommandsView : UserControl
|
||||
{
|
||||
public UserCommandsView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Reflection;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the package/assembly metadata declared in Directory.Build.props is stamped into
|
||||
/// the built assemblies. This metadata is surfaced in Settings -> About, the Report-Bug
|
||||
/// template, the file properties, and the Velopack installer (--packAuthors).
|
||||
/// </summary>
|
||||
public sealed class AssemblyMetadataTests
|
||||
{
|
||||
// Domain is the lowest layer and inherits the same Directory.Build.props metadata as the rest.
|
||||
private static readonly Assembly Target = typeof(CommandDefinition).Assembly;
|
||||
|
||||
[Fact]
|
||||
public void Assembly_HasExpectedCompany()
|
||||
=> Assert.Equal("poli0981", Target.GetCustomAttribute<AssemblyCompanyAttribute>()?.Company);
|
||||
|
||||
[Fact]
|
||||
public void Assembly_HasExpectedProduct()
|
||||
=> Assert.Equal("CommandForge", Target.GetCustomAttribute<AssemblyProductAttribute>()?.Product);
|
||||
|
||||
[Fact]
|
||||
public void Assembly_HasCopyrightWithOwner()
|
||||
{
|
||||
var copyright = Target.GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright;
|
||||
|
||||
Assert.NotNull(copyright);
|
||||
Assert.Contains("poli0981", copyright, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
@@ -47,4 +47,72 @@ public sealed class CatalogValidationErrorsTests
|
||||
|
||||
Assert.Empty(result.Errors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_MaxOsBuildBelowMinOsBuild_ProducesError()
|
||||
{
|
||||
var categories = new[] { new CategoryDto { Id = "cat", TitleKey = "Cat_K" } };
|
||||
var commands = new[]
|
||||
{
|
||||
new CommandDto
|
||||
{
|
||||
Id = "c1",
|
||||
CategoryId = "cat",
|
||||
TitleKey = "T",
|
||||
DescriptionKey = "D",
|
||||
Executable = "cmd",
|
||||
MinOsBuild = 22000,
|
||||
MaxOsBuild = 19045,
|
||||
},
|
||||
};
|
||||
|
||||
var result = CatalogLoader.Build(categories, commands);
|
||||
|
||||
Assert.Contains(result.Errors, e => e.Contains("c1", StringComparison.Ordinal) && e.Contains("maxOsBuild", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_NonPositiveOsBuild_ProducesError()
|
||||
{
|
||||
var categories = new[] { new CategoryDto { Id = "cat", TitleKey = "Cat_K" } };
|
||||
var commands = new[]
|
||||
{
|
||||
new CommandDto
|
||||
{
|
||||
Id = "c1",
|
||||
CategoryId = "cat",
|
||||
TitleKey = "T",
|
||||
DescriptionKey = "D",
|
||||
Executable = "cmd",
|
||||
MinOsBuild = 0,
|
||||
},
|
||||
};
|
||||
|
||||
var result = CatalogLoader.Build(categories, commands);
|
||||
|
||||
Assert.Contains(result.Errors, e => e.Contains("c1", StringComparison.Ordinal) && e.Contains("minOsBuild", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_ValidOsBuildRange_HasNoErrors()
|
||||
{
|
||||
var categories = new[] { new CategoryDto { Id = "cat", TitleKey = "Cat_K" } };
|
||||
var commands = new[]
|
||||
{
|
||||
new CommandDto
|
||||
{
|
||||
Id = "c1",
|
||||
CategoryId = "cat",
|
||||
TitleKey = "T",
|
||||
DescriptionKey = "D",
|
||||
Executable = "cmd",
|
||||
MinOsBuild = 22000,
|
||||
},
|
||||
};
|
||||
|
||||
var result = CatalogLoader.Build(categories, commands);
|
||||
|
||||
Assert.Empty(result.Errors);
|
||||
Assert.Equal(22000, result.Commands[0].MinOsBuild);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Infrastructure.Catalog;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Verifies the OS-build applicability predicate and the embedded catalog's version gating.</summary>
|
||||
public sealed class CommandDefinitionTests
|
||||
{
|
||||
private static CommandDefinition Command(int? min = null, int? max = null) => new()
|
||||
{
|
||||
Id = "t",
|
||||
CategoryId = "c",
|
||||
TitleKey = "T",
|
||||
DescriptionKey = "D",
|
||||
Executable = "cmd",
|
||||
MinOsBuild = min,
|
||||
MaxOsBuild = max,
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData(19045, true)] // no bounds -> always applies
|
||||
[InlineData(22631, true)]
|
||||
public void AppliesToOsBuild_NoBounds_AlwaysTrue(int build, bool expected)
|
||||
=> Assert.Equal(expected, Command().AppliesToOsBuild(build));
|
||||
|
||||
[Theory]
|
||||
[InlineData(19045, false)] // Windows 10 excluded by min 22000
|
||||
[InlineData(21999, false)]
|
||||
[InlineData(22000, true)] // inclusive lower bound
|
||||
[InlineData(26100, true)]
|
||||
public void AppliesToOsBuild_MinOnly_GatesBelow(int build, bool expected)
|
||||
=> Assert.Equal(expected, Command(min: 22000).AppliesToOsBuild(build));
|
||||
|
||||
[Theory]
|
||||
[InlineData(19045, true)] // inclusive upper bound (Windows 10 only)
|
||||
[InlineData(22000, false)] // Windows 11 excluded by max 19045
|
||||
public void AppliesToOsBuild_MaxOnly_GatesAbove(int build, bool expected)
|
||||
=> Assert.Equal(expected, Command(max: 19045).AppliesToOsBuild(build));
|
||||
|
||||
[Theory]
|
||||
[InlineData(21999, false)]
|
||||
[InlineData(22000, true)]
|
||||
[InlineData(22621, true)]
|
||||
[InlineData(22622, false)]
|
||||
public void AppliesToOsBuild_Range_GatesBothEnds(int build, bool expected)
|
||||
=> Assert.Equal(expected, Command(min: 22000, max: 22621).AppliesToOsBuild(build));
|
||||
|
||||
[Theory]
|
||||
[InlineData("tweak.win11.classicmenu", 22000)]
|
||||
[InlineData("tweak.win11.modernmenu", 22000)]
|
||||
[InlineData("tweak.win11.taskbarleft", 22000)]
|
||||
[InlineData("tweak.win11.taskbarcenter", 22000)]
|
||||
[InlineData("tweak.clockseconds.on", 22621)]
|
||||
[InlineData("tweak.clockseconds.off", 22621)]
|
||||
public void EmbeddedCatalog_Win11Commands_AreGated(string id, int expectedMinBuild)
|
||||
{
|
||||
var catalog = CatalogLoader.LoadEmbedded();
|
||||
var command = catalog.Commands.Single(c => c.Id == id);
|
||||
Assert.Equal(expectedMinBuild, command.MinOsBuild);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmbeddedCatalog_Win11Tweaks_HiddenOnWindows10()
|
||||
{
|
||||
const int windows10Build = 19045;
|
||||
var catalog = CatalogLoader.LoadEmbedded();
|
||||
var hiddenOnWin10 = catalog.Commands.Where(c => !c.AppliesToOsBuild(windows10Build)).Select(c => c.Id).ToHashSet();
|
||||
|
||||
Assert.Contains("tweak.win11.taskbarleft", hiddenOnWin10);
|
||||
Assert.Contains("tweak.clockseconds.on", hiddenOnWin10);
|
||||
Assert.DoesNotContain("dism.checkhealth", hiddenOnWin10); // ungated commands stay visible
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Infrastructure.History;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Verifies execution history persists to / loads from history.json, with graceful fallbacks.</summary>
|
||||
public sealed class ExecutionHistoryRoundTripTests
|
||||
{
|
||||
private static ExecutionRecord Rec(string id, bool success = true) => new()
|
||||
{
|
||||
CommandId = id,
|
||||
Timestamp = new DateTimeOffset(2026, 6, 19, 10, 30, 0, TimeSpan.Zero),
|
||||
ExitCode = success ? 0 : 1,
|
||||
Success = success,
|
||||
DurationMs = 1234,
|
||||
RequiresRestart = false,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void Record_Persists_And_Reloads_NewestFirst()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-history-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
var writer = new JsonExecutionHistoryService(path);
|
||||
writer.Record(Rec("a"));
|
||||
writer.Record(Rec("b", success: false));
|
||||
|
||||
var records = new JsonExecutionHistoryService(path).GetRecent();
|
||||
|
||||
Assert.Equal(["b", "a"], records.Select(r => r.CommandId));
|
||||
Assert.False(records[0].Success);
|
||||
Assert.Equal(1, records[0].ExitCode);
|
||||
Assert.Equal(1234, records[0].DurationMs);
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Clear_EmptiesHistory()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-history-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
var svc = new JsonExecutionHistoryService(path);
|
||||
svc.Record(Rec("a"));
|
||||
|
||||
svc.Clear();
|
||||
|
||||
Assert.Empty(svc.GetRecent());
|
||||
Assert.Empty(new JsonExecutionHistoryService(path).GetRecent());
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CorruptFile_FallsBackToEmpty()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-history-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
File.WriteAllText(path, "{ not valid json ");
|
||||
|
||||
Assert.Empty(new JsonExecutionHistoryService(path).GetRecent());
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MissingFile_IsEmpty()
|
||||
=> Assert.Empty(new JsonExecutionHistoryService(
|
||||
Path.Combine(Path.GetTempPath(), $"cf-history-{Guid.NewGuid():N}.json")).GetRecent());
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using CommandForge.Application.History;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Tests the pure execution-history helper (newest-first, cap, no de-dupe, no mutation).</summary>
|
||||
public sealed class ExecutionHistoryTests
|
||||
{
|
||||
private static ExecutionRecord Rec(string id) => new()
|
||||
{
|
||||
CommandId = id,
|
||||
Timestamp = DateTimeOffset.UnixEpoch,
|
||||
ExitCode = 0,
|
||||
Success = true,
|
||||
DurationMs = 10,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void Add_PutsNewestFirst()
|
||||
{
|
||||
var result = ExecutionHistory.Add([Rec("a")], Rec("b"));
|
||||
|
||||
Assert.Equal(["b", "a"], result.Select(r => r.CommandId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Add_KeepsDuplicateCommandIds()
|
||||
{
|
||||
// Unlike recent commands, every run is a distinct event — no de-duplication.
|
||||
var result = ExecutionHistory.Add([Rec("a")], Rec("a"));
|
||||
|
||||
Assert.Equal(2, result.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Add_CapsAtMaxItems()
|
||||
{
|
||||
IReadOnlyList<ExecutionRecord> current =
|
||||
Enumerable.Range(0, ExecutionHistory.MaxItems).Select(i => Rec($"c{i}")).ToList();
|
||||
|
||||
var result = ExecutionHistory.Add(current, Rec("newest"));
|
||||
|
||||
Assert.Equal(ExecutionHistory.MaxItems, result.Count);
|
||||
Assert.Equal("newest", result[0].CommandId);
|
||||
Assert.DoesNotContain($"c{ExecutionHistory.MaxItems - 1}", result.Select(r => r.CommandId)); // oldest dropped
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Add_DoesNotMutateInput()
|
||||
{
|
||||
var current = new List<ExecutionRecord> { Rec("a") };
|
||||
|
||||
ExecutionHistory.Add(current, Rec("b"));
|
||||
|
||||
Assert.Single(current);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Application.SystemInfo;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Tests the local maintenance-suggestion heuristics over system status.</summary>
|
||||
public sealed class MaintenanceSuggestionsTests
|
||||
{
|
||||
private static SystemStatus Status(long driveTotal, long driveFree, TimeSpan uptime)
|
||||
=> new("Windows 11", 26100, 16_000_000_000UL, 8_000_000_000UL, "C:", driveTotal, driveFree, uptime);
|
||||
|
||||
[Fact]
|
||||
public void For_LowDisk_SuggestsCleanup()
|
||||
{
|
||||
var suggestions = MaintenanceSuggestions.For(Status(driveTotal: 100, driveFree: 5, uptime: TimeSpan.FromHours(1)));
|
||||
|
||||
Assert.Contains(suggestions, s => s.CommandId == "cleanup.cleanmgr");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void For_HealthyDisk_NoCleanup()
|
||||
=> Assert.DoesNotContain(
|
||||
MaintenanceSuggestions.For(Status(driveTotal: 100, driveFree: 50, uptime: TimeSpan.FromHours(1))),
|
||||
s => s.ReasonKey == "Maint_LowDisk");
|
||||
|
||||
[Fact]
|
||||
public void For_HighUptime_SuggestsRestart()
|
||||
=> Assert.Contains(
|
||||
MaintenanceSuggestions.For(Status(driveTotal: 100, driveFree: 50, uptime: TimeSpan.FromDays(8))),
|
||||
s => s.ReasonKey == "Maint_HighUptime");
|
||||
|
||||
[Fact]
|
||||
public void For_FreshHealthy_NoSuggestions()
|
||||
=> Assert.Empty(MaintenanceSuggestions.For(Status(driveTotal: 100, driveFree: 80, uptime: TimeSpan.FromHours(2))));
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using CommandForge.Application.Search;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Tests the local natural-language → keyword mapping (no LLM/network).</summary>
|
||||
public sealed class NaturalLanguageSearchTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("dọn ổ đĩa", "cleanup")]
|
||||
[InlineData("free space please", "cleanup")]
|
||||
[InlineData("reset my network", "network")]
|
||||
[InlineData("kiểm tra cập nhật", "update")]
|
||||
[InlineData("battery report", "battery")]
|
||||
public void Suggest_MapsNaturalPhrase_ToKeyword(string query, string expected)
|
||||
=> Assert.Equal(expected, NaturalLanguageSearch.Suggest(query));
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("systeminfo")]
|
||||
[InlineData("cleanup")] // already the keyword — don't suggest what was typed
|
||||
public void Suggest_ReturnsNull_WhenNoMappingOrAlreadyKeyword(string query)
|
||||
=> Assert.Null(NaturalLanguageSearch.Suggest(query));
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using CommandForge.Application.Logging;
|
||||
using CommandForge.Application.Settings;
|
||||
using CommandForge.Infrastructure.Portability;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Verifies import/export files and the named-profile store round-trip and fall back gracefully.</summary>
|
||||
public sealed class PortabilityTests
|
||||
{
|
||||
private static PortableSettings Sample() => new()
|
||||
{
|
||||
Theme = AppTheme.Dark,
|
||||
Language = "vi",
|
||||
FontSize = FontScale.Large,
|
||||
ConfirmCaution = false,
|
||||
LogLevel = LogLevel.Debug,
|
||||
FavoriteCommandIds = ["a", "b"],
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void SettingsFile_Write_Then_Read_RoundTrips()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-export-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
var file = new JsonSettingsFile();
|
||||
file.Write(path, Sample());
|
||||
|
||||
var read = file.Read(path);
|
||||
|
||||
Assert.NotNull(read);
|
||||
Assert.Equal(AppTheme.Dark, read!.Theme);
|
||||
Assert.Equal("vi", read.Language);
|
||||
Assert.Equal(FontScale.Large, read.FontSize);
|
||||
Assert.False(read.ConfirmCaution);
|
||||
Assert.Equal(["a", "b"], read.FavoriteCommandIds);
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsFile_Read_MissingOrInvalid_ReturnsNull()
|
||||
{
|
||||
var file = new JsonSettingsFile();
|
||||
Assert.Null(file.Read(Path.Combine(Path.GetTempPath(), $"cf-missing-{Guid.NewGuid():N}.json")));
|
||||
|
||||
var bad = Path.Combine(Path.GetTempPath(), $"cf-bad-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
File.WriteAllText(bad, "{ not json ");
|
||||
Assert.Null(file.Read(bad));
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(bad);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProfileService_Save_Get_Delete_Persists()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-profiles-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
var svc = new JsonProfileService(path);
|
||||
svc.Save("Gaming PC", Sample());
|
||||
svc.Save("Office", new PortableSettings { Theme = AppTheme.Light });
|
||||
|
||||
Assert.Equal(["Gaming PC", "Office"], svc.GetNames());
|
||||
Assert.Equal(AppTheme.Dark, svc.Get("Gaming PC")!.Theme);
|
||||
|
||||
// Reload from disk — profiles persist.
|
||||
var reloaded = new JsonProfileService(path);
|
||||
Assert.Equal(2, reloaded.GetNames().Count);
|
||||
Assert.Equal(AppTheme.Light, reloaded.Get("Office")!.Theme);
|
||||
Assert.Equal(["a", "b"], reloaded.Get("Gaming PC")!.FavoriteCommandIds);
|
||||
|
||||
reloaded.Delete("Office");
|
||||
Assert.Equal(["Gaming PC"], reloaded.GetNames());
|
||||
Assert.Null(new JsonProfileService(path).Get("Office"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProfileService_Save_OverwritesByName_CaseInsensitive()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-profiles-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
var svc = new JsonProfileService(path);
|
||||
svc.Save("Office", new PortableSettings { Theme = AppTheme.Light });
|
||||
svc.Save("office", new PortableSettings { Theme = AppTheme.Dark });
|
||||
|
||||
Assert.Single(svc.GetNames());
|
||||
Assert.Equal(AppTheme.Dark, svc.Get("Office")!.Theme);
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using CommandForge.Application.Recipes;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Tests the pure recipe stop-on-error/restart/cancel decision.</summary>
|
||||
public sealed class RecipeFlowTests
|
||||
{
|
||||
private static ExecutionResult Result(bool success = true, bool cancelled = false, bool restart = false)
|
||||
=> new()
|
||||
{
|
||||
ExitCode = success ? 0 : 1,
|
||||
Success = success,
|
||||
Duration = TimeSpan.Zero,
|
||||
Cancelled = cancelled,
|
||||
RequiresRestart = restart,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void ShouldStop_False_OnPlainSuccess()
|
||||
=> Assert.False(RecipeFlow.ShouldStop(Result()));
|
||||
|
||||
[Fact]
|
||||
public void ShouldStop_True_OnFailure()
|
||||
=> Assert.True(RecipeFlow.ShouldStop(Result(success: false)));
|
||||
|
||||
[Fact]
|
||||
public void ShouldStop_True_OnCancelled()
|
||||
=> Assert.True(RecipeFlow.ShouldStop(Result(cancelled: true)));
|
||||
|
||||
[Fact]
|
||||
public void ShouldStop_True_OnRestartRequired()
|
||||
=> Assert.True(RecipeFlow.ShouldStop(Result(restart: true))); // 3010: success-with-reboot, still stop
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Infrastructure.Recipes;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Verifies the recipe store round-trips, overwrites by name, and falls back on corruption.</summary>
|
||||
public sealed class RecipeStoreTests
|
||||
{
|
||||
[Fact]
|
||||
public void Save_Get_Delete_Persists()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-recipes-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
var store = new JsonRecipeStore(path);
|
||||
store.Save(new Recipe { Name = "Maintenance", CommandIds = ["dism.checkhealth", "sfc.scannow"] });
|
||||
store.Save(new Recipe { Name = "Network", CommandIds = ["net.flushdns"] });
|
||||
|
||||
Assert.Equal(["Maintenance", "Network"], store.GetAll().Select(r => r.Name));
|
||||
|
||||
// Reload from disk — recipes persist with their ordered steps.
|
||||
var reloaded = new JsonRecipeStore(path);
|
||||
Assert.Equal(2, reloaded.GetAll().Count);
|
||||
Assert.Equal(
|
||||
["dism.checkhealth", "sfc.scannow"],
|
||||
reloaded.GetAll().First(r => r.Name == "Maintenance").CommandIds);
|
||||
|
||||
reloaded.Delete("Network");
|
||||
Assert.Single(reloaded.GetAll());
|
||||
Assert.DoesNotContain(new JsonRecipeStore(path).GetAll(), r => r.Name == "Network");
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_OverwritesByName_CaseInsensitive()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-recipes-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
var store = new JsonRecipeStore(path);
|
||||
store.Save(new Recipe { Name = "Maint", CommandIds = ["a"] });
|
||||
store.Save(new Recipe { Name = "maint", CommandIds = ["b", "c"] });
|
||||
|
||||
Assert.Single(store.GetAll());
|
||||
Assert.Equal(["b", "c"], store.GetAll()[0].CommandIds);
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CorruptFile_FallsBackToEmpty()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-recipes-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
File.WriteAllText(path, "{ not json ");
|
||||
Assert.Empty(new JsonRecipeStore(path).GetAll());
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Application.Registry;
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Infrastructure.Catalog;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Tests the read-only registry snapshot/diff helpers and the catalog schema field.</summary>
|
||||
public sealed class RegistrySnapshotTests
|
||||
{
|
||||
private static RegistryValueRef Ref(string name) => new() { Path = "HKCU\\Software\\X", Name = name };
|
||||
|
||||
[Fact]
|
||||
public void Diff_ReturnsOnlyChangedValues()
|
||||
{
|
||||
var a = Ref("A");
|
||||
var b = Ref("B");
|
||||
var before = new Dictionary<RegistryValueRef, string?> { [a] = "1", [b] = "x" };
|
||||
var after = new Dictionary<RegistryValueRef, string?> { [a] = "0", [b] = "x" };
|
||||
|
||||
var change = Assert.Single(RegistrySnapshot.Diff([a, b], before, after));
|
||||
|
||||
Assert.Equal(a, change.Reference);
|
||||
Assert.Equal("1", change.Before);
|
||||
Assert.Equal("0", change.After);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Diff_TreatsNullToValueAsChange()
|
||||
{
|
||||
var a = Ref("A");
|
||||
var before = new Dictionary<RegistryValueRef, string?> { [a] = null };
|
||||
var after = new Dictionary<RegistryValueRef, string?> { [a] = "1" };
|
||||
|
||||
var change = Assert.Single(RegistrySnapshot.Diff([a], before, after));
|
||||
|
||||
Assert.Null(change.Before);
|
||||
Assert.Equal("1", change.After);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Capture_ReadsEachReference()
|
||||
{
|
||||
var a = Ref("A");
|
||||
var registry = new FakeRegistry(new Dictionary<RegistryValueRef, string?> { [a] = "42" });
|
||||
|
||||
Assert.Equal("42", RegistrySnapshot.Capture(registry, [a])[a]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Catalog_ShowExt_DeclaresAffectedRegistryValue()
|
||||
{
|
||||
var catalog = CatalogLoader.LoadEmbedded();
|
||||
var showExt = catalog.Commands.Single(c => c.Id == "tweak.showext");
|
||||
|
||||
var value = Assert.Single(showExt.AffectedRegistryValues);
|
||||
Assert.Equal("HideFileExt", value.Name);
|
||||
Assert.Contains("Explorer", value.Path, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private sealed class FakeRegistry(Dictionary<RegistryValueRef, string?> values) : IRegistryService
|
||||
{
|
||||
public string? Read(RegistryValueRef reference) => values.GetValueOrDefault(reference);
|
||||
}
|
||||
}
|
||||
@@ -6,45 +6,48 @@ using CommandForge.Wpf.Resources;
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Cross-checks that every catalog title/description resource key exists in both the neutral
|
||||
/// (EN) resources and the Vietnamese satellite (no parent fallback).
|
||||
/// Cross-checks that every catalog title/description and UI resource key exists in the neutral
|
||||
/// (EN) resources and in both the Vietnamese and Japanese satellites (no parent fallback), so a
|
||||
/// missing translation fails the build rather than silently falling back to English.
|
||||
/// </summary>
|
||||
public sealed class ResxKeyTests
|
||||
{
|
||||
private static readonly CatalogLoadResult Catalog = CatalogLoader.LoadEmbedded();
|
||||
|
||||
[Fact]
|
||||
public void Catalog_AllKeys_ExistInResx_EN_and_VI()
|
||||
/// <summary>Asserts every key resolves in EN (neutral) and in the VI and JA satellites without fallback.</summary>
|
||||
private static void AssertKeysExist(IEnumerable<string> keys)
|
||||
{
|
||||
var manager = new ResourceManager("CommandForge.Wpf.Resources.Strings", typeof(Strings).Assembly);
|
||||
var english = manager.GetResourceSet(CultureInfo.InvariantCulture, createIfNotExists: true, tryParents: true);
|
||||
var vietnamese = manager.GetResourceSet(new CultureInfo("vi"), createIfNotExists: true, tryParents: false);
|
||||
var japanese = manager.GetResourceSet(new CultureInfo("ja"), createIfNotExists: true, tryParents: false);
|
||||
|
||||
Assert.NotNull(english);
|
||||
Assert.NotNull(vietnamese);
|
||||
|
||||
var keys = new List<string>();
|
||||
keys.AddRange(Catalog.Categories.Select(c => c.TitleKey));
|
||||
keys.AddRange(Catalog.Commands.Select(c => c.TitleKey));
|
||||
keys.AddRange(Catalog.Commands.Select(c => c.DescriptionKey));
|
||||
Assert.NotNull(japanese);
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
Assert.True(english!.GetString(key) is not null, $"Missing EN resource for key '{key}'.");
|
||||
Assert.True(vietnamese!.GetString(key) is not null, $"Missing VI resource for key '{key}'.");
|
||||
Assert.True(japanese!.GetString(key) is not null, $"Missing JA resource for key '{key}'.");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsUiKeys_ExistInResx_EN_and_VI()
|
||||
public void Catalog_AllKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
var manager = new ResourceManager("CommandForge.Wpf.Resources.Strings", typeof(Strings).Assembly);
|
||||
var english = manager.GetResourceSet(CultureInfo.InvariantCulture, createIfNotExists: true, tryParents: true);
|
||||
var vietnamese = manager.GetResourceSet(new CultureInfo("vi"), createIfNotExists: true, tryParents: false);
|
||||
var keys = new List<string>();
|
||||
keys.AddRange(Catalog.Categories.Select(c => c.TitleKey));
|
||||
keys.AddRange(Catalog.Commands.Select(c => c.TitleKey));
|
||||
keys.AddRange(Catalog.Commands.Select(c => c.DescriptionKey));
|
||||
|
||||
Assert.NotNull(english);
|
||||
Assert.NotNull(vietnamese);
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SettingsUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
string[] keys =
|
||||
[
|
||||
"Menu_OpenSettings", "LanguageOption_System",
|
||||
@@ -56,25 +59,19 @@ public sealed class ResxKeyTests
|
||||
"Settings_AutoRestorePoint", "Settings_AutoScroll", "Settings_WarnOnCancel",
|
||||
"Settings_AutoCheckUpdates", "Settings_CurrentVersion", "Settings_LastChecked", "Settings_CheckNow",
|
||||
"Settings_NoDataCollected", "Settings_License", "Settings_GitHub",
|
||||
"Settings_Profiles", "Settings_ExportImport", "Settings_ExportImportHint",
|
||||
"Settings_ExportSettings", "Settings_ImportSettings", "Settings_SavedProfiles", "Settings_ProfilesHint",
|
||||
"Settings_ApplyProfile", "Settings_DeleteProfile", "Settings_SaveCurrentAsProfile",
|
||||
"Settings_ProfileName", "Settings_SaveProfile", "Settings_ExportSuccess", "Settings_ImportConfirm",
|
||||
"Settings_ImportInvalid", "Settings_ImportSuccess", "Settings_ProfileApplied", "Settings_DeleteProfileConfirm",
|
||||
];
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
Assert.True(english!.GetString(key) is not null, $"Missing EN resource for key '{key}'.");
|
||||
Assert.True(vietnamese!.GetString(key) is not null, $"Missing VI resource for key '{key}'.");
|
||||
}
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DiagnosticsUiKeys_ExistInResx_EN_and_VI()
|
||||
public void DiagnosticsUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
var manager = new ResourceManager("CommandForge.Wpf.Resources.Strings", typeof(Strings).Assembly);
|
||||
var english = manager.GetResourceSet(CultureInfo.InvariantCulture, createIfNotExists: true, tryParents: true);
|
||||
var vietnamese = manager.GetResourceSet(new CultureInfo("vi"), createIfNotExists: true, tryParents: false);
|
||||
|
||||
Assert.NotNull(english);
|
||||
Assert.NotNull(vietnamese);
|
||||
|
||||
string[] keys =
|
||||
[
|
||||
"Menu_LogViewer", "Menu_ExportLogs", "Menu_DebugPanel", "Menu_ReportBug",
|
||||
@@ -92,23 +89,12 @@ public sealed class ResxKeyTests
|
||||
"Settings_OpenDebugPanel", "Settings_ResetDefaults", "Settings_ResetConfirm",
|
||||
];
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
Assert.True(english!.GetString(key) is not null, $"Missing EN resource for key '{key}'.");
|
||||
Assert.True(vietnamese!.GetString(key) is not null, $"Missing VI resource for key '{key}'.");
|
||||
}
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HomeUiKeys_ExistInResx_EN_and_VI()
|
||||
public void HomeUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
var manager = new ResourceManager("CommandForge.Wpf.Resources.Strings", typeof(Strings).Assembly);
|
||||
var english = manager.GetResourceSet(CultureInfo.InvariantCulture, createIfNotExists: true, tryParents: true);
|
||||
var vietnamese = manager.GetResourceSet(new CultureInfo("vi"), createIfNotExists: true, tryParents: false);
|
||||
|
||||
Assert.NotNull(english);
|
||||
Assert.NotNull(vietnamese);
|
||||
|
||||
string[] keys =
|
||||
[
|
||||
"SidebarHome", "SidebarFavorites", "Favorite_Toggle",
|
||||
@@ -118,23 +104,12 @@ public sealed class ResxKeyTests
|
||||
"Home_Recent", "Home_NoRecent", "Home_NoFavorites",
|
||||
];
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
Assert.True(english!.GetString(key) is not null, $"Missing EN resource for key '{key}'.");
|
||||
Assert.True(vietnamese!.GetString(key) is not null, $"Missing VI resource for key '{key}'.");
|
||||
}
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LegalUiKeys_ExistInResx_EN_and_VI()
|
||||
public void LegalUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
var manager = new ResourceManager("CommandForge.Wpf.Resources.Strings", typeof(Strings).Assembly);
|
||||
var english = manager.GetResourceSet(CultureInfo.InvariantCulture, createIfNotExists: true, tryParents: true);
|
||||
var vietnamese = manager.GetResourceSet(new CultureInfo("vi"), createIfNotExists: true, tryParents: false);
|
||||
|
||||
Assert.NotNull(english);
|
||||
Assert.NotNull(vietnamese);
|
||||
|
||||
string[] keys =
|
||||
[
|
||||
"LegalGateTitle", "LegalGateIntro", "LegalGateAgree", "LegalGateContinue", "LegalGateExit",
|
||||
@@ -143,23 +118,12 @@ public sealed class ResxKeyTests
|
||||
"LegalViewer_Title",
|
||||
];
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
Assert.True(english!.GetString(key) is not null, $"Missing EN resource for key '{key}'.");
|
||||
Assert.True(vietnamese!.GetString(key) is not null, $"Missing VI resource for key '{key}'.");
|
||||
}
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MenuUiKeys_ExistInResx_EN_and_VI()
|
||||
public void MenuUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
var manager = new ResourceManager("CommandForge.Wpf.Resources.Strings", typeof(Strings).Assembly);
|
||||
var english = manager.GetResourceSet(CultureInfo.InvariantCulture, createIfNotExists: true, tryParents: true);
|
||||
var vietnamese = manager.GetResourceSet(new CultureInfo("vi"), createIfNotExists: true, tryParents: false);
|
||||
|
||||
Assert.NotNull(english);
|
||||
Assert.NotNull(vietnamese);
|
||||
|
||||
string[] keys =
|
||||
[
|
||||
"MenuFile", "MenuView", "MenuTools", "MenuAbout", "MenuHelp", "MenuExit", "MenuToggleSidebar",
|
||||
@@ -171,23 +135,12 @@ public sealed class ResxKeyTests
|
||||
"Menu_KeyboardShortcuts", "Menu_PortableInfo", "Menu_RestorePoint",
|
||||
];
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
Assert.True(english!.GetString(key) is not null, $"Missing EN resource for key '{key}'.");
|
||||
Assert.True(vietnamese!.GetString(key) is not null, $"Missing VI resource for key '{key}'.");
|
||||
}
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DialogUiKeys_ExistInResx_EN_and_VI()
|
||||
public void DialogUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
var manager = new ResourceManager("CommandForge.Wpf.Resources.Strings", typeof(Strings).Assembly);
|
||||
var english = manager.GetResourceSet(CultureInfo.InvariantCulture, createIfNotExists: true, tryParents: true);
|
||||
var vietnamese = manager.GetResourceSet(new CultureInfo("vi"), createIfNotExists: true, tryParents: false);
|
||||
|
||||
Assert.NotNull(english);
|
||||
Assert.NotNull(vietnamese);
|
||||
|
||||
string[] keys =
|
||||
[
|
||||
"Shortcuts_Palette", "Shortcuts_ListNav", "Shortcuts_OpenSelected", "Shortcuts_CloseDialog",
|
||||
@@ -196,10 +149,56 @@ public sealed class ResxKeyTests
|
||||
"Settings_CurrentVersion", "Settings_NoDataCollected", "LanguageOption_System",
|
||||
];
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
Assert.True(english!.GetString(key) is not null, $"Missing EN resource for key '{key}'.");
|
||||
Assert.True(vietnamese!.GetString(key) is not null, $"Missing VI resource for key '{key}'.");
|
||||
}
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RecipesUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
string[] keys =
|
||||
[
|
||||
"SidebarRecipes", "Recipes_Saved", "Recipes_New", "Recipe_Delete", "Recipes_NameHint",
|
||||
"Recipes_NoSteps", "Recipes_AddHint", "Recipes_AddStep", "Recipes_Save", "Recipes_Run",
|
||||
"Recipes_MoveUp", "Recipes_MoveDown", "Recipes_RemoveStep",
|
||||
"Recipe_StepHeader", "Recipe_StoppedOnError", "Recipe_StoppedRestart", "Recipe_Cancelled",
|
||||
"Recipe_ContainsDangerous", "Recipe_ConfirmTitle", "Recipe_DeleteConfirm",
|
||||
];
|
||||
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UserCommandsUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
string[] keys =
|
||||
[
|
||||
"SidebarUserCommands", "UserCmd_Warning", "UserCmd_Saved", "UserCmd_New", "UserCmd_Delete",
|
||||
"UserCmd_NameHint", "UserCmd_ExecutableHint", "UserCmd_ArgumentsHint", "UserCmd_Save", "UserCmd_Run",
|
||||
"UserCmd_NoCommands", "UserCmd_RunTitle", "UserCmd_RunConfirm", "UserCmd_DeleteConfirm",
|
||||
];
|
||||
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegistryAndUndoUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
string[] keys =
|
||||
[
|
||||
"History_Undo", "Registry_ChangesHeader", "Registry_ChangeFormat", "Registry_NotSet", "Registry_NoChanges",
|
||||
];
|
||||
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DashboardAndSearchUiKeys_ExistInResx_AllCultures()
|
||||
{
|
||||
string[] keys =
|
||||
[
|
||||
"Search_Suggestion", "Home_Suggestions", "Maint_LowDisk", "Maint_HighUptime", "Maint_Open",
|
||||
];
|
||||
|
||||
AssertKeysExist(keys);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using CommandForge.Application.Logging;
|
||||
using CommandForge.Application.Settings;
|
||||
using CommandForge.Infrastructure;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Verifies the portable-settings capture/apply mapping covers every field (round-trip).</summary>
|
||||
public sealed class SettingsTransferTests
|
||||
{
|
||||
[Fact]
|
||||
public void Capture_Then_Apply_RoundTripsAllFields()
|
||||
{
|
||||
var srcPath = Path.Combine(Path.GetTempPath(), $"cf-src-{Guid.NewGuid():N}.json");
|
||||
var dstPath = Path.Combine(Path.GetTempPath(), $"cf-dst-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
var src = new JsonSettingsService(srcPath)
|
||||
{
|
||||
Theme = AppTheme.Dark,
|
||||
Language = "vi",
|
||||
FontSize = FontScale.Large,
|
||||
CollapseSidebarByDefault = true,
|
||||
ShowAdminRestartBadges = false,
|
||||
ConfirmCaution = false,
|
||||
AutoCreateRestorePoint = false,
|
||||
AutoScrollConsole = false,
|
||||
WarnOnCancel = false,
|
||||
AutoCheckForUpdates = false,
|
||||
LogLevel = LogLevel.Verbose,
|
||||
FavoriteCommandIds = ["info.systeminfo", "net.flushdns"],
|
||||
};
|
||||
|
||||
var captured = SettingsTransfer.Capture(src);
|
||||
|
||||
Assert.Equal(AppTheme.Dark, captured.Theme);
|
||||
Assert.Equal("vi", captured.Language);
|
||||
Assert.Equal(FontScale.Large, captured.FontSize);
|
||||
Assert.Equal(["info.systeminfo", "net.flushdns"], captured.FavoriteCommandIds);
|
||||
|
||||
var dst = new JsonSettingsService(dstPath);
|
||||
SettingsTransfer.Apply(captured, dst);
|
||||
|
||||
Assert.Equal(AppTheme.Dark, dst.Theme);
|
||||
Assert.Equal("vi", dst.Language);
|
||||
Assert.Equal(FontScale.Large, dst.FontSize);
|
||||
Assert.True(dst.CollapseSidebarByDefault);
|
||||
Assert.False(dst.ShowAdminRestartBadges);
|
||||
Assert.False(dst.ConfirmCaution);
|
||||
Assert.False(dst.AutoCreateRestorePoint);
|
||||
Assert.False(dst.AutoScrollConsole);
|
||||
Assert.False(dst.WarnOnCancel);
|
||||
Assert.False(dst.AutoCheckForUpdates);
|
||||
Assert.Equal(LogLevel.Verbose, dst.LogLevel);
|
||||
Assert.Equal(["info.systeminfo", "net.flushdns"], dst.FavoriteCommandIds);
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(srcPath);
|
||||
File.Delete(dstPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using CommandForge.Application.UserCommands;
|
||||
using CommandForge.Domain;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests the cmd argument normalization that fixes user commands hanging on an interactive
|
||||
/// cmd.exe (e.g. "cmd" + "ping google.com" must run as "cmd /c ping google.com").
|
||||
/// </summary>
|
||||
public sealed class UserCommandNormalizationTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("cmd", "ping google.com", "/c ping google.com")]
|
||||
[InlineData("cmd.exe", "dir", "/c dir")]
|
||||
[InlineData("CMD", "echo hi", "/c echo hi")]
|
||||
[InlineData("C:\\Windows\\System32\\cmd.exe", "whoami", "/c whoami")]
|
||||
[InlineData("cmd", "", "/c")]
|
||||
public void NormalizeArguments_PrependsSlashC_ForCmd(string exe, string args, string expected)
|
||||
=> Assert.Equal(expected, UserCommandFactory.NormalizeArguments(exe, args));
|
||||
|
||||
[Theory]
|
||||
[InlineData("cmd", "/c ping x")] // already has /c
|
||||
[InlineData("cmd", "/k keep open")] // explicit /k
|
||||
[InlineData("cmd", "/C UPPER")] // case-insensitive switch
|
||||
[InlineData("powershell", "ping x")] // not cmd — leave as-is (powershell runs it)
|
||||
[InlineData("ping", "google.com")] // direct executable
|
||||
public void NormalizeArguments_LeavesAsIs_WhenNotPlainCmd(string exe, string args)
|
||||
=> Assert.Equal(args, UserCommandFactory.NormalizeArguments(exe, args));
|
||||
|
||||
[Fact]
|
||||
public void ToDefinition_AppliesCmdNormalization()
|
||||
{
|
||||
var def = UserCommandFactory.ToDefinition(new UserCommand
|
||||
{
|
||||
Id = "x",
|
||||
Name = "n",
|
||||
Executable = "cmd",
|
||||
Arguments = "ping google.com",
|
||||
});
|
||||
|
||||
Assert.Equal("/c ping google.com", def.ArgsTemplate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using System.Threading.Channels;
|
||||
using CommandForge.Application.Ports;
|
||||
using CommandForge.Application.UseCases;
|
||||
using CommandForge.Application.UserCommands;
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Infrastructure.UserCommands;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Safety tests for user-defined commands (golden rule #1): they must never elevate, carry the
|
||||
/// namespaced id (so the Elevator rejects them), and persist locally.
|
||||
/// </summary>
|
||||
public sealed class UserCommandsTests
|
||||
{
|
||||
private static UserCommand Sample(string id = "abc") => new()
|
||||
{
|
||||
Id = id,
|
||||
Name = "My tool",
|
||||
Executable = "cmd",
|
||||
Arguments = "/c echo hi",
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void ToDefinition_NeverRequiresAdmin()
|
||||
=> Assert.False(UserCommandFactory.ToDefinition(Sample()).RequiresAdmin);
|
||||
|
||||
[Fact]
|
||||
public void ToDefinition_NamespacesId_SoElevatorRejectsIt()
|
||||
{
|
||||
var def = UserCommandFactory.ToDefinition(Sample("abc"));
|
||||
|
||||
Assert.StartsWith(UserCommandFactory.IdPrefix, def.Id, StringComparison.Ordinal);
|
||||
Assert.Equal("user:abc", def.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UserCommand_RoutesToExecutor_NotElevation()
|
||||
{
|
||||
var executor = new RecordingExecutor();
|
||||
var elevation = new RecordingElevation();
|
||||
var useCase = new RunCommandUseCase(executor, elevation);
|
||||
|
||||
await useCase.RunAsync(
|
||||
UserCommandFactory.ToDefinition(Sample()),
|
||||
Channel.CreateUnbounded<OutputLine>().Writer);
|
||||
|
||||
Assert.True(executor.Called);
|
||||
Assert.False(elevation.Called); // never elevated
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Store_Save_Get_Delete_Persists()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"cf-usercmd-{Guid.NewGuid():N}.json");
|
||||
try
|
||||
{
|
||||
var store = new JsonUserCommandStore(path);
|
||||
store.Save(Sample("a"));
|
||||
store.Save(Sample("b") with { Name = "Second" });
|
||||
|
||||
Assert.Equal(2, store.GetAll().Count);
|
||||
|
||||
var reloaded = new JsonUserCommandStore(path);
|
||||
Assert.Equal(2, reloaded.GetAll().Count);
|
||||
Assert.Equal("cmd", reloaded.GetAll()[0].Executable);
|
||||
|
||||
reloaded.Delete("a");
|
||||
Assert.Single(reloaded.GetAll());
|
||||
Assert.DoesNotContain(new JsonUserCommandStore(path).GetAll(), c => c.Id == "a");
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class RecordingExecutor : ICommandExecutor
|
||||
{
|
||||
public bool Called { get; private set; }
|
||||
|
||||
public Task<ExecutionResult> ExecuteAsync(CommandDefinition command, ChannelWriter<OutputLine> output, CancellationToken cancellationToken)
|
||||
{
|
||||
Called = true;
|
||||
output.TryComplete();
|
||||
return Task.FromResult(new ExecutionResult { ExitCode = 0, Success = true, Duration = TimeSpan.Zero });
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class RecordingElevation : IElevationService
|
||||
{
|
||||
public bool Called { get; private set; }
|
||||
|
||||
public bool IsElevationAvailable => true;
|
||||
|
||||
public Task<ExecutionResult> RunElevatedAsync(CommandDefinition command, ChannelWriter<OutputLine> output, CancellationToken cancellationToken)
|
||||
{
|
||||
Called = true;
|
||||
output.TryComplete();
|
||||
return Task.FromResult(new ExecutionResult { ExitCode = 0, Success = true, Duration = TimeSpan.Zero });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using CommandForge.Domain;
|
||||
using CommandForge.Infrastructure.Registry;
|
||||
|
||||
namespace CommandForge.Tests;
|
||||
|
||||
/// <summary>Smoke tests for the read-only Win32 registry service against well-known keys.</summary>
|
||||
public sealed class WindowsRegistryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Read_KnownValue_ReturnsNonNull()
|
||||
{
|
||||
var service = new WindowsRegistryService();
|
||||
|
||||
var value = service.Read(new RegistryValueRef
|
||||
{
|
||||
Path = "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
|
||||
Name = "ProductName",
|
||||
});
|
||||
|
||||
Assert.False(string.IsNullOrEmpty(value));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Read_MissingKey_ReturnsNull()
|
||||
{
|
||||
var service = new WindowsRegistryService();
|
||||
|
||||
Assert.Null(service.Read(new RegistryValueRef
|
||||
{
|
||||
Path = "HKCU\\Software\\CommandForge\\Missing_" + Guid.NewGuid().ToString("N"),
|
||||
Name = "Nope",
|
||||
}));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Read_UnknownHive_ReturnsNull()
|
||||
{
|
||||
var service = new WindowsRegistryService();
|
||||
|
||||
Assert.Null(service.Read(new RegistryValueRef { Path = "BOGUS\\Whatever", Name = "X" }));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user