- src/HashTool.Cli: `hashtool hash | verify | check | algorithms` on top of Core, NativeAOT-ready (3.9 MB native binary), coreutils-style output and exit codes (0 ok, 1 failed/mismatch, 2 usage or unreadable checksum file); Windows paths are written with '/' so lines need no escaping. - tests/HashTool.Cli.Tests: commands, formats and exit codes. - tests/HashTool.App.Tests (Avalonia headless): every page in several languages including RTL, a folder create-and-verify flow, translation integrity (keys, placeholders, Languages.json/resx/project wiring, satellite assemblies, unused keys), system language detection, command line parsing and helpers. - tests/Compat/LegacyClient: drives Velopack 0.0.1298 (the library inside Hash Tool 1.1.x) against new release files for the upgrade gate. - build/macos/Info.plist keeps the 1.x bundle identity and adds "Open With" document types; build/linux/hashtool.png is the AppImage icon. - bench/HashTool.Benchmarks (BenchmarkDotNet) and a tool manifest pinning vpk 1.2.161, nuget-license and CycloneDX. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
2.3 KiB
C#
56 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Xml.Linq;
|
|
|
|
namespace HashTool.App.Tests;
|
|
|
|
/// <summary>Reads source files of the repository (translations, views) from the checkout the tests were built from.</summary>
|
|
internal static partial class RepositoryFiles
|
|
{
|
|
public static string Root { get; } = FindRoot();
|
|
|
|
public static string AppDirectory => Path.Combine(Root, "src", "HashTool.App");
|
|
|
|
public static string LangDirectory => Path.Combine(AppDirectory, "Lang");
|
|
|
|
/// <summary>The neutral (English) resx and every culture resx, keyed by file culture ("" for neutral).</summary>
|
|
public static IReadOnlyDictionary<string, IReadOnlyDictionary<string, string>> Translations { get; } = LoadTranslations();
|
|
|
|
public static IReadOnlyDictionary<string, string> Neutral => Translations[""];
|
|
|
|
public static IEnumerable<string> PlaceholdersOf(string value) =>
|
|
Placeholder().Matches(value).Select(m => m.Value).Order(StringComparer.Ordinal);
|
|
|
|
[GeneratedRegex(@"\{\d+(?:,[^}:]+)?(?::[^}]*)?\}")]
|
|
private static partial Regex Placeholder();
|
|
|
|
private static string FindRoot()
|
|
{
|
|
for (var directory = new DirectoryInfo(AppContext.BaseDirectory); directory is not null; directory = directory.Parent)
|
|
{
|
|
if (File.Exists(Path.Combine(directory.FullName, "HashTool.slnx"))) return directory.FullName;
|
|
}
|
|
|
|
throw new InvalidOperationException("Could not find the repository root (HashTool.slnx).");
|
|
}
|
|
|
|
private static Dictionary<string, IReadOnlyDictionary<string, string>> LoadTranslations()
|
|
{
|
|
var result = new Dictionary<string, IReadOnlyDictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
|
|
foreach (var file in Directory.GetFiles(LangDirectory, "Resources*.resx"))
|
|
{
|
|
var parts = Path.GetFileName(file).Split('.');
|
|
var culture = parts.Length == 2 ? "" : parts[1];
|
|
var entries = new Dictionary<string, string>(StringComparer.Ordinal);
|
|
foreach (var data in XDocument.Load(file, LoadOptions.PreserveWhitespace).Root!.Elements("data"))
|
|
entries[(string)data.Attribute("name")!] = (string?)data.Element("value") ?? "";
|
|
result[culture] = entries;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|