Compare commits

...
Author SHA1 Message Date
poli0981andClaude Fable 5.1 77497dc728 fix(tests): the layer registration test deletes only its own registry subtree
It deleted SOFTWARE\FrameLedger.Test whole, which is shared with the GOG
reader's test; when the two overlapped on the runner the GOG keys vanished
mid-test (#188 round 2, 'expected a single item, collection empty').

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 19:40:50 +07:00
poli0981 de258e6bf3 Merge branch 'main' into fix/itch-butler-db 2026-09-16 19:37:02 +07:00
poli0981andClaude Fable 5.1 a4b5364404 style(tests): using order in StoreLibrarySourcesTests (dotnet format)
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 19:00:30 +07:00
poli0981andClaude Fable 5.1 6cccc5b58b fix(import): itch.io import reads butler's database, so an install location outside %APPDATA% is found
ItchLibrarySource scanned %APPDATA%\itch\apps\*\.itch\receipt.json.gz and nothing
else; on the owner's machine the itch app's one install location is
D:\another\it, apps\ is empty, and the import logged "itch — 0 title(s)" with
no reason. The app records its installs in %APPDATA%\itch\db\butler.db:
install_locations, caves, and butler's own verdict JSON naming the executable
it launches.

- Copy butler.db (+ -wal) to a temporary directory, open the copy read-only
  (the running app holds it in WAL mode), join the three tables, take the first
  Windows candidate of the verdict as the executable (an HTML/Love2D game leaves
  the locator's guess), still scan apps\ receipts for what the database does
  not list; an install found both ways is one row, the database's.
- One log line per run through the importer's sink says what was consulted
  and what each source yielded.
- The constructor now takes the itch directory, not apps\.
- Measured on this machine: 1 location, 2 caves, both titles with butler's
  executables.
- Tests: StoreLibrarySourcesTests (butler.db built in the test: a location
  elsewhere, a custom folder, a forward-slash verdict path, an HTML-only
  verdict, an unparsable verdict, a receipt beside a cave, a receipt-only
  install; no database and a garbage database fall back to receipts and say so).
- Docs: 05_DETECTION §Platform signatures, CHANGELOG.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 19:00:29 +07:00
6 changed files with 330 additions and 27 deletions

No files matched your search

+15
View File
@@ -260,6 +260,21 @@ under a `## [x.y.z] - date` heading in the same commit that bumps `VERSION`, the
### Fixed
- **itch.io import reads butler's database, so an install location outside `%APPDATA%` is found (2026-09-16).**
`ItchLibrarySource` scanned `%APPDATA%\itch\apps\*\.itch\receipt.json.gz` and nothing else; on the owner's machine
the itch app's one install location is `D:\another\it`, `apps\` is empty, and the import logged `itch — 0 title(s)`
with no reason — every itch title had to be added by hand. The app records its installs in
`%APPDATA%\itch\db\butler.db`: `install_locations` (the folders the user chose), `caves` (one per install, with the
folder name or a custom folder) and its own `verdict` JSON naming the executable butler launches. The adapter now
copies that database to a temporary directory (the running app holds it in WAL mode), opens the copy read-only,
joins the three tables, takes the first Windows candidate of the verdict as the executable (an HTML or Love2D game
leaves the locator's guess), and still scans `apps\` receipts for anything the database does not list; an install
found both ways is one row, the database's. It logs one line per run — what was consulted and what each source
yielded — through the importer's sink, so `0 title(s)` has a reason beside it. `ItchLibrarySource`'s constructor
now takes the itch directory (`%APPDATA%\itch`), not `apps\`. Tests: `StoreLibrarySourcesTests` (a butler.db built
in the test with a location elsewhere, a custom folder, a verdict path with forward slashes, an HTML-only verdict,
a verdict that will not parse, a receipt beside a cave and a receipt-only install; no database and a garbage
database both fall back to receipts and say so). Docs: `05_DETECTION` §Platform signatures.
- **The Games card's hooking chip reads at 2.6:1 no more, and the Dashboard's FG qualifier no longer clips
(2026-09-16).** "Hooking on/off" was `ui:Badge Appearance="Info"`: WPF UI paints that with `PaletteLightBlueBrush`,
a fixed Material colour outside both theme dictionaries, under the theme's white text — `#03A9F4` in dark, below
+10 -3
View File
@@ -174,7 +174,7 @@ Everything else in the table is in the data and has a fixture; `rules-validate.p
| Steam | `steam_api64.dll`/`steam_api.dll` sibling, or path contains `steamapps\common` | nearest `steamapps/appmanifest_<id>.acf` (walk up): `appid`, `name`, `buildid` → version |
| GOG | `goggame-<id>.info` sibling, or `Galaxy64.dll` | `.info` JSON: `gameId`, `name`, `version` |
| Epic | `EOSSDK-Win64-Shipping.dll`, or path under an Epic install | `%ProgramData%\Epic\EpicGamesLauncher\Data\Manifests\*.item` matched by `InstallLocation` |
| itch.io | `.itch\receipt.json.gz` | receipt JSON: title, id |
| itch.io | `.itch\receipt.json.gz` | **`%APPDATA%\itch\db\butler.db`** (`install_locations` + `caves`, butler's `verdict` names the executable) since 2026-09-16, then the receipt JSON: title, id |
| None/Manual | fallback | PE VersionInfo |
**Auto-import (FR-1.2):** Steam via `libraryfolders.vdf` → all `appmanifest_*.acf`; GOG via `HKLM\SOFTWARE\WOW6432Node\GOG.com\Games\*`; Epic via `Manifests\*.item`; itch by receipt scan. Import presents a review checklist; nothing is launched, nothing is hooked on import.
@@ -184,8 +184,15 @@ Everything else in the table is in the data and has a fixture; `rules-validate.p
> `ValveKeyValues`, the Steam root from `HKCU\Software\Valve\Steam\SteamPath`), `GogLibrarySource` (the HKLM
> keys, read-only, the first HKLM read in the tree), `EpicLibrarySource` (`*.item` JSON: `DisplayName`,
> `InstallLocation`, `LaunchExecutable`, `AppName`, `AppVersionString`), `ItchLibrarySource`
> (`%APPDATA%\itch\apps\*\.itch\receipt.json.gz`). **Two stores do not name the game's executable** (Steam,
> itch): `ExecutableLocator` walks the install three levels deep, drops the helpers by name fragment and takes
> (~~`%APPDATA%\itch\apps\*\.itch\receipt.json.gz`~~ — **since 2026-09-16 butler's database first**: the itch app
> records the install locations the user chose in `%APPDATA%\itch\db\butler.db`, and they need not be under
> `%APPDATA%` at all — on the owner's machine the one location was `D:\another\it` and `apps\` was empty, so the
> receipt scan returned nothing, silently; `install_locations` + `caves` give every install, butler's own `verdict`
> names the executable it launches, and `apps\` receipts are still scanned for what the database does not list. The
> database is copied to a temporary directory and the copy opened read-only, because the running app holds it in
> WAL mode. One log line says what was consulted: `import: itch — butler.db read: 1 location(s), 2 cave(s), …`).
> **Two stores do not name the game's executable** (Steam,
> itch-by-receipt): `ExecutableLocator` walks the install three levels deep, drops the helpers by name fragment and takes
> the largest — a *guess the review list marks as such*; GOG's `exe` and Epic's `LaunchExecutable` are the store's
> own. The review (`ImportReviewPrompt`) ticks only what can be imported: a row already in the library or with no
> executable on disk cannot be. Every added row lands exactly as File ▸ Add game… lands it — hooking off — and
+1 -1
View File
@@ -337,7 +337,7 @@ public partial class App : System.Windows.Application
services.AddSingleton<IStoreLibrarySource>(static _ => new SteamLibrarySource());
services.AddSingleton<IStoreLibrarySource>(static _ => new GogLibrarySource());
services.AddSingleton<IStoreLibrarySource>(static _ => new EpicLibrarySource());
services.AddSingleton<IStoreLibrarySource>(static _ => new ItchLibrarySource());
services.AddSingleton<IStoreLibrarySource>(static _ => new ItchLibrarySource(log: static line => Serilog.Log.Information("{Line}", line)));
services.AddSingleton<IExecutableLocator, ExecutableLocator>();
services.AddSingleton<IExecutableIdentitySource, ExecutableIdentitySource>();
services.AddSingleton(static sp => new LibraryImporter(
@@ -1,44 +1,205 @@
using System.IO.Compression;
using System.Text.Json;
using Dapper;
using FrameLedger.Application.Import;
using Microsoft.Data.Sqlite;
namespace FrameLedger.Infrastructure.Import;
/// <summary>
/// itch.io's installed library (FR-1.2): every install under <c>%APPDATA%\itch\apps</c> carries
/// <c>.itch\receipt.json.gz</c> — gzipped JSON whose <c>game</c> object names <c>title</c> and <c>id</c>. The receipt
/// does not say which executable is the game, so the locator guesses. A receipt that will not gunzip or parse
/// costs that one install.
/// itch.io's installed library (FR-1.2), from the two places the itch app records it.
/// </summary>
public sealed class ItchLibrarySource(string? appsDirectory = null) : IStoreLibrarySource
/// <remarks>
/// <para>
/// <b>butler's database first (2026-09-16).</b> The app keeps its installs in <c>%APPDATA%\itch\db\butler.db</c>:
/// <c>install_locations</c> (id, path) — the folders the user chose, which need not be under <c>%APPDATA%</c> at all —
/// and <c>caves</c>, one per install, with the location id, the folder name, and butler's own <c>verdict</c> JSON naming
/// the executable it decided the game is. Until this date the adapter read only <c>%APPDATA%\itch\apps\*</c>, the
/// default location, and on a machine whose one location was <c>D:\another\it</c> it returned nothing — silently,
/// because it logged nothing. The database is copied to a temporary directory and the copy opened read-only, because
/// the running itch app holds it in WAL mode; the copy is deleted afterwards.
/// </para>
/// <para>
/// <b>Receipts second.</b> Every install still carries <c>.itch\receipt.json.gz</c> — gzipped JSON whose <c>game</c> object
/// names <c>title</c> and <c>id</c> — and <c>apps\</c> under the itch directory is scanned as before, for a machine
/// whose database is missing or unreadable, or an install the database does not list. An install found both ways is
/// one row, the database's. The receipt does not say which executable is the game, so a receipt-only row leaves
/// <see cref="StoreGame.ExePath"/> null for the locator's guess; a database row carries butler's verdict.
/// </para>
/// <para>
/// One line per run goes to <paramref name="log"/> saying what was consulted and what each source yielded, so
/// "0 title(s)" has a reason beside it.
/// </para>
/// </remarks>
public sealed class ItchLibrarySource(string? itchDirectory = null, Action<string>? log = null) : IStoreLibrarySource
{
public static string DefaultDirectory => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "itch", "apps");
private const string _platform = "itch";
public string Platform => "itch";
/// <summary><c>%APPDATA%\itch</c> — the app's own directory; <c>db\butler.db</c> and <c>apps\</c> are under it.</summary>
public static string DefaultDirectory => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "itch");
public ValueTask<IReadOnlyList<StoreGame>> ListAsync(CancellationToken ct = default)
public string Platform => _platform;
public async ValueTask<IReadOnlyList<StoreGame>> ListAsync(CancellationToken ct = default)
{
string dir = appsDirectory ?? DefaultDirectory;
if (!Directory.Exists(dir))
string root = itchDirectory ?? DefaultDirectory;
if (!Directory.Exists(root))
{
return ValueTask.FromResult<IReadOnlyList<StoreGame>>([]);
log?.Invoke($"import: itch — not installed (no {root})");
return [];
}
List<StoreGame> games = [];
foreach (string install in Directory.EnumerateDirectories(dir))
// Keyed by install directory, so an install the database lists and a receipt also names is one row.
var byInstall = new Dictionary<string, StoreGame>(StringComparer.OrdinalIgnoreCase);
string database = Path.Combine(root, "db", "butler.db");
string databaseNote = await ReadDatabaseAsync(database, byInstall, ct).ConfigureAwait(false);
int fromDatabase = byInstall.Count;
int receipts = ScanReceipts(Path.Combine(root, "apps"), byInstall, ct);
log?.Invoke($"import: itch — {databaseNote}; apps\\ {receipts} receipt(s), {byInstall.Count - fromDatabase} new");
return [.. byInstall.Values];
}
/// <summary>Reads a copy of butler's database; returns the log fragment describing what happened.</summary>
private static async Task<string> ReadDatabaseAsync(string database, Dictionary<string, StoreGame> byInstall, CancellationToken ct)
{
if (!File.Exists(database))
{
return $"no {database}";
}
string temp = Path.Combine(Path.GetTempPath(), "fl-itch-" + Guid.NewGuid().ToString("N"));
try
{
Directory.CreateDirectory(temp);
string copy = Path.Combine(temp, "butler.db");
File.Copy(database, copy);
if (File.Exists(database + "-wal"))
{
File.Copy(database + "-wal", copy + "-wal"); // the frames since the app's last checkpoint; no -shm, so SQLite rebuilds the index
}
int locations;
List<CaveRow> caves;
var connection = new SqliteConnection(new SqliteConnectionStringBuilder { DataSource = copy, Mode = SqliteOpenMode.ReadOnly, Pooling = false }.ToString());
await using (connection.ConfigureAwait(false))
{
await connection.OpenAsync(ct).ConfigureAwait(false);
locations = await connection.ExecuteScalarAsync<int>(new CommandDefinition("SELECT COUNT(*) FROM install_locations", cancellationToken: ct)).ConfigureAwait(false);
// Tuples rather than a row type: Dapper maps a value tuple by position, and a private row class would be
// "never instantiated" to the analyzer (CA1812) though Dapper instantiates it.
caves = [.. (await connection.QueryAsync<(long GameId, string? LocationPath, string? FolderName, string? CustomFolder, string? Verdict, string? Title)>(new CommandDefinition(
"""
SELECT c.game_id, l.path, c.install_folder_name, c.custom_install_folder, c.verdict, g.title
FROM caves c
LEFT JOIN install_locations l ON l.id = c.install_location_id
LEFT JOIN games g ON g.id = c.game_id
""", cancellationToken: ct)).ConfigureAwait(false)).Select(static r => new CaveRow(r.GameId, r.LocationPath, r.FolderName, r.CustomFolder, r.Verdict, r.Title))];
}
int added = 0;
foreach (CaveRow cave in caves)
{
if (ToGame(cave) is { } game && byInstall.TryAdd(game.InstallDirectory, game))
{
added++;
}
}
return $"butler.db read: {locations} location(s), {caves.Count} cave(s), {added} title(s)";
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or SqliteException or InvalidOperationException)
{
return $"butler.db unreadable ({ex.GetType().Name}: {ex.Message})";
}
finally
{
try
{
Directory.Delete(temp, recursive: true);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
}
}
}
private static StoreGame? ToGame(CaveRow cave)
{
string? install = !string.IsNullOrWhiteSpace(cave.CustomFolder) ? cave.CustomFolder
: cave.LocationPath is { Length: > 0 } && cave.FolderName is { Length: > 0 } ? Path.Combine(cave.LocationPath, cave.FolderName)
: null;
if (install is null)
{
return null;
}
install = Path.GetFullPath(install);
string name = cave.Title is { Length: > 0 } ? cave.Title : ReadReceipt(Path.Combine(install, ".itch", "receipt.json.gz"))?.Title ?? Path.GetFileName(install);
return new StoreGame(_platform, cave.GameId.ToString(System.Globalization.CultureInfo.InvariantCulture), name, install, VerdictExecutable(cave.Verdict, install), Version: null);
}
/// <summary>
/// butler's verdict: <c>{"basePath":…,"candidates":[{"path":"Sub/Game.exe","flavor":"windows",…}]}</c>. The first
/// Windows candidate is the executable butler itself launches; anything else (an HTML5 or Love2D game, a
/// verdict that will not parse) leaves the guess to the locator.
/// </summary>
private static string? VerdictExecutable(string? verdict, string install)
{
if (string.IsNullOrWhiteSpace(verdict))
{
return null;
}
try
{
using JsonDocument doc = JsonDocument.Parse(verdict);
if (!doc.RootElement.TryGetProperty("candidates", out JsonElement candidates) || candidates.ValueKind != JsonValueKind.Array)
{
return null;
}
foreach (JsonElement candidate in candidates.EnumerateArray())
{
bool windows = candidate.TryGetProperty("flavor", out JsonElement flavor) && flavor.ValueKind == JsonValueKind.String
&& string.Equals(flavor.GetString(), "windows", StringComparison.Ordinal);
if (windows && candidate.TryGetProperty("path", out JsonElement path) && path.ValueKind == JsonValueKind.String && path.GetString() is { Length: > 0 } relative)
{
return Path.GetFullPath(Path.Combine(install, relative.Replace('/', Path.DirectorySeparatorChar)));
}
}
return null;
}
catch (JsonException)
{
return null;
}
}
private static int ScanReceipts(string apps, Dictionary<string, StoreGame> byInstall, CancellationToken ct)
{
if (!Directory.Exists(apps))
{
return 0;
}
int receipts = 0;
foreach (string install in Directory.EnumerateDirectories(apps))
{
ct.ThrowIfCancellationRequested();
string receipt = Path.Combine(install, ".itch", "receipt.json.gz");
if (File.Exists(receipt) && Read(receipt, install) is { } game)
if (File.Exists(receipt) && ReadReceipt(receipt) is { } r)
{
games.Add(game);
receipts++;
string full = Path.GetFullPath(install);
byInstall.TryAdd(full, new StoreGame(_platform, r.Id, r.Title, full, ExePath: null, Version: null));
}
}
return ValueTask.FromResult<IReadOnlyList<StoreGame>>(games);
return receipts;
}
private static StoreGame? Read(string receipt, string install)
private static (string Id, string Title)? ReadReceipt(string receipt)
{
try
{
@@ -57,11 +218,13 @@ public sealed class ItchLibrarySource(string? appsDirectory = null) : IStoreLibr
JsonValueKind.String => i.GetString(),
_ => null,
} : null;
return title is null || id is null ? null : new StoreGame("itch", id, title, install, ExePath: null, Version: null);
return title is null || id is null ? null : (id, title);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException or InvalidDataException)
{
return null;
}
}
private sealed record CaveRow(long GameId, string? LocationPath, string? FolderName, string? CustomFolder, string? Verdict, string? Title);
}
@@ -1,8 +1,11 @@
using System.Globalization;
using System.IO.Compression;
using System.Text;
using Dapper;
using FluentAssertions;
using FrameLedger.Application.Import;
using FrameLedger.Infrastructure.Import;
using Microsoft.Data.Sqlite;
using Microsoft.Win32;
namespace FrameLedger.Infrastructure.Tests.Import;
@@ -110,7 +113,7 @@ public sealed class StoreLibrarySourcesTests : IDisposable
aw.ExePath.Should().Be(@"D:\Epic Games\AlanWake2\AlanWake2.exe");
aw.Version.Should().Be("1.2.3");
string apps = Sub("itch", "apps");
string itch = Sub("itch");
string install = Sub("itch", "apps", "celeste");
Directory.CreateDirectory(Path.Combine(install, ".itch"));
using (FileStream f = File.Create(Path.Combine(install, ".itch", "receipt.json.gz")))
@@ -121,8 +124,8 @@ public sealed class StoreLibrarySourcesTests : IDisposable
}
Sub("itch", "apps", "empty");
IReadOnlyList<StoreGame> itch = await new ItchLibrarySource(apps).ListAsync(Ct);
StoreGame c = itch.Should().ContainSingle().Subject;
IReadOnlyList<StoreGame> receipts = await new ItchLibrarySource(itch).ListAsync(Ct);
StoreGame c = receipts.Should().ContainSingle().Subject;
c.Platform.Should().Be("itch");
c.StoreId.Should().Be("36776");
c.Name.Should().Be("Celeste");
@@ -133,6 +136,117 @@ public sealed class StoreLibrarySourcesTests : IDisposable
(await new ItchLibrarySource(Path.Combine(_dir, "nowhere")).ListAsync(Ct)).Should().BeEmpty();
}
/// <summary>
/// 2026-09-16: the itch app records its installs in butler.db — install locations the user chose (which need not be
/// under %APPDATA%), one cave per install, and butler's own verdict naming the executable. The adapter read only
/// the default apps\ folder and found nothing on a machine whose one location was elsewhere.
/// </summary>
[Fact]
public async Task ItchReadsButlersDatabaseFirstAndReceiptsSecond()
{
string itch = Sub("itch");
string location = Sub("elsewhere");
string pob = Sub("elsewhere", "plethora-of-bullets-2");
await File.WriteAllBytesAsync(Path.Combine(pob, "POB2.exe"), new byte[10], Ct);
string dontGo = Sub("elsewhere", "dont-go");
Directory.CreateDirectory(Path.Combine(dontGo, "DONT GO"));
await File.WriteAllBytesAsync(Path.Combine(dontGo, "DONT GO", "PIZZA MAN.exe"), new byte[10], Ct);
string custom = Sub("custom", "web-game");
await WriteReceiptAsync(Path.Combine(custom, ".itch", "receipt.json.gz"), 777, "Web Game", Ct);
string receiptOnly = Sub("itch", "apps", "celeste");
await WriteReceiptAsync(Path.Combine(receiptOnly, ".itch", "receipt.json.gz"), 36776, "Celeste", Ct);
Directory.CreateDirectory(Path.Combine(dontGo, ".itch"));
await WriteReceiptAsync(Path.Combine(dontGo, ".itch", "receipt.json.gz"), 3212881, "DONT GO (receipt)", Ct);
await WriteButlerAsync(Path.Combine(itch, "db", "butler.db"), location, [
(1659887, "plethora-of-bullets-2", "", "Plethora of Bullets 2", "{\"basePath\":\"x\",\"candidates\":[{\"path\":\"POB2.exe\",\"flavor\":\"windows\",\"arch\":\"amd64\"}]}"),
(3212881, "dont-go", "", "DONT GO", "{\"candidates\":[{\"path\":\"DONT GO/PIZZA MAN.exe\",\"flavor\":\"windows\"}]}"),
(777, "", custom, "Web Game", "{\"candidates\":[{\"path\":\"index.html\",\"flavor\":\"html\"}]}"),
(999, "gone", "", null, "not json"),
]);
List<string> log = [];
IReadOnlyList<StoreGame> games = await new ItchLibrarySource(itch, log.Add).ListAsync(Ct);
games.Should().HaveCount(5, "four caves and one receipt-only install; the receipt beside a cave is the same row");
StoreGame p = games.Single(g => string.Equals(g.StoreId, "1659887", StringComparison.Ordinal));
p.Name.Should().Be("Plethora of Bullets 2");
p.InstallDirectory.Should().Be(pob);
p.ExePath.Should().Be(Path.Combine(pob, "POB2.exe"), "butler's verdict names the executable");
StoreGame d = games.Single(g => string.Equals(g.StoreId, "3212881", StringComparison.Ordinal));
d.Name.Should().Be("DONT GO", "the database's title wins over the receipt's");
d.ExePath.Should().Be(Path.Combine(dontGo, "DONT GO", "PIZZA MAN.exe"), "a verdict path is relative to the install and uses forward slashes");
games.Single(g => string.Equals(g.StoreId, "777", StringComparison.Ordinal)).Should().BeEquivalentTo(new { InstallDirectory = custom, ExePath = (string?)null }, "a custom install folder is the install; an html flavor is not an executable");
games.Single(g => string.Equals(g.StoreId, "999", StringComparison.Ordinal)).Should().BeEquivalentTo(new { Name = "gone", ExePath = (string?)null }, "no title anywhere falls back to the folder name; a verdict that will not parse leaves the guess to the locator");
games.Single(g => string.Equals(g.StoreId, "36776", StringComparison.Ordinal)).InstallDirectory.Should().Be(receiptOnly, "apps\\ is still scanned for what the database does not list");
log.Should().ContainSingle().Which.Should().Contain("butler.db read: 1 location(s), 4 cave(s), 4 title(s)").And.Contain("1 receipt(s), 1 new", "only the apps folder is scanned for receipts; the one beside a cave elsewhere is read for its title, not counted here");
}
[Fact]
public async Task ItchWithoutADatabaseOrWithAnUnreadableOneStillReadsReceipts()
{
string itch = Sub("itch");
await WriteReceiptAsync(Path.Combine(Sub("itch", "apps", "celeste"), ".itch", "receipt.json.gz"), 36776, "Celeste", Ct);
List<string> log = [];
(await new ItchLibrarySource(itch, log.Add).ListAsync(Ct)).Should().ContainSingle().Which.StoreId.Should().Be("36776");
log.Should().ContainSingle().Which.Should().Contain("no ").And.Contain("butler.db");
Directory.CreateDirectory(Path.Combine(itch, "db"));
await File.WriteAllTextAsync(Path.Combine(itch, "db", "butler.db"), "this is not a database", Ct);
log.Clear();
(await new ItchLibrarySource(itch, log.Add).ListAsync(Ct)).Should().ContainSingle();
log.Should().ContainSingle().Which.Should().Contain("butler.db unreadable");
log.Clear();
(await new ItchLibrarySource(Path.Combine(_dir, "nowhere"), log.Add).ListAsync(Ct)).Should().BeEmpty();
log.Should().ContainSingle().Which.Should().Contain("not installed");
}
private static async Task WriteReceiptAsync(string path, long id, string title, CancellationToken ct)
{
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
FileStream f = File.Create(path);
await using (f.ConfigureAwait(false))
{
var gz = new GZipStream(f, CompressionLevel.Fastest);
await using (gz.ConfigureAwait(false))
{
byte[] json = Encoding.UTF8.GetBytes("{\"game\":{\"id\":" + id.ToString(CultureInfo.InvariantCulture) + ",\"title\":\"" + title + "\"}}");
await gz.WriteAsync(json, ct).ConfigureAwait(false);
}
}
}
/// <summary>The three butler tables the adapter reads, with the columns it names (the real ones carry more).</summary>
private static async Task WriteButlerAsync(string path, string locationPath,
IReadOnlyList<(long GameId, string Folder, string Custom, string? Title, string Verdict)> caves)
{
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
var c = new SqliteConnection(new SqliteConnectionStringBuilder { DataSource = path, Pooling = false }.ToString());
await using (c.ConfigureAwait(false))
{
await c.OpenAsync(Ct).ConfigureAwait(false);
await c.ExecuteAsync(new CommandDefinition(
"""
CREATE TABLE install_locations (id TEXT PRIMARY KEY, path TEXT);
CREATE TABLE games (id INTEGER PRIMARY KEY, title TEXT, classification TEXT);
CREATE TABLE caves (id TEXT PRIMARY KEY, game_id INTEGER, install_location_id TEXT, install_folder_name TEXT, custom_install_folder TEXT, verdict TEXT);
INSERT INTO install_locations VALUES ('loc-1', @location);
""", new { location = locationPath }, cancellationToken: Ct)).ConfigureAwait(false);
foreach ((long gameId, string folder, string custom, string? title, string verdict) in caves)
{
if (title is not null)
{
await c.ExecuteAsync(new CommandDefinition("INSERT INTO games VALUES (@id, @title, 'game')", new { id = gameId, title }, cancellationToken: Ct)).ConfigureAwait(false);
}
await c.ExecuteAsync(new CommandDefinition(
"INSERT INTO caves VALUES (@id, @gameId, 'loc-1', @folder, @custom, @verdict)",
new { id = Guid.NewGuid().ToString("N"), gameId, folder, custom, verdict }, cancellationToken: Ct)).ConfigureAwait(false);
}
}
}
[Fact]
public async Task TheLocatorTakesTheLargestNonHelperExecutableWithinThreeLevels()
{
@@ -10,7 +10,11 @@ public sealed class VkLayerRegistrationTests
[Fact]
public void RegistersReadsBackAndUnregistersIncludingAStaleEntry()
{
string key = @"SOFTWARE\FrameLedger.Test\" + Guid.NewGuid().ToString("N") + @"\ImplicitLayers";
// Its OWN subtree, and only that is deleted in the finally: SOFTWARE\FrameLedger.Test is shared with
// StoreLibrarySourcesTests (the GOG reader), and deleting the whole tree while that test runs emptied its
// keys under it — measured on CI 2026-09-16 (#188 round 2: "expected a single item, collection empty").
string own = @"SOFTWARE\FrameLedger.Test\" + Guid.NewGuid().ToString("N");
string key = own + @"\ImplicitLayers";
var registration = new VkLayerRegistration(key);
string manifest = @"C:\Users\x\AppData\Local\FrameLedger\vklayer\" + VkLayerLaunchEnvironment.ManifestFileName;
string stale = @"D:\old\vklayer\" + VkLayerLaunchEnvironment.ManifestFileName;
@@ -33,7 +37,7 @@ public sealed class VkLayerRegistrationTests
}
finally
{
Registry.CurrentUser.DeleteSubKeyTree(@"SOFTWARE\FrameLedger.Test", throwOnMissingSubKey: false);
Registry.CurrentUser.DeleteSubKeyTree(own, throwOnMissingSubKey: false);
}
}