Files
frameledger/src/FrameLedger.App/Services/ImportLibraryFlow.cs
T
poli0981andClaude Fable 5.1 603795f49d feat(app): the library import -- Steam, GOG Galaxy, Epic and itch.io through a review checklist, hooking off for every row (P4 PR-4) (#173)
LibraryImporter over four IStoreLibrarySource adapters: Steam
(libraryfolders.vdf + appmanifest_*.acf through a ValveKeyValues
reader), GOG (the HKLM registry keys, read-only, under whichever hive
and key a caller names), Epic (Manifests\*.item), itch (gzipped
receipts). Steam and itch do not name the game's executable:
ExecutableLocator walks three levels, drops helpers by name fragment
and takes the largest -- a guess the review marks as such.

File > Import library... shows the checklist, adds what was ticked
exactly as File > Add game... would -- hooking off, FR-1.2 -- and
writes the store's platform, id and version through the new
IGameRepository.ApplyStoreMetadataAsync under the same provenance rule
as a detection write. Nothing is launched, nothing is fetched.

Tests: ValveKeyValuesTests, StoreLibrarySourcesTests,
LibraryImporterTests, ImportLibraryFlowTests, SqliteGameRepositoryTests.
15 App strings en/vi/ja. Docs: 05_DETECTION, 06_DATA_MODEL, 08_UI,
14_TESTING, HANDOFF, 15_ROADMAP, CHANGELOG.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-14 23:32:07 +07:00

55 lines
2.4 KiB
C#

using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using FrameLedger.App.Pages;
using FrameLedger.Application.Import;
namespace FrameLedger.App.Services;
/// <summary>
/// File ▸ Import library… (FR-1.2, P4 PR-4): discover every installed store's titles, show the review checklist,
/// add what the user ticked — hooking off for every one, as File ▸ Add game… would — and land on the Games page.
/// Nothing is launched, nothing is fetched, nothing is added without a tick.
/// </summary>
[SuppressMessage("Performance", "CA1863:Use 'CompositeFormat'", Justification = "the format strings are resources that follow the UI culture, which changes at runtime; a cached CompositeFormat would pin the first culture")]
public sealed class ImportLibraryFlow
{
private readonly LibraryImporter _importer;
private readonly IImportReview _review;
private readonly IMessageStrip _strip;
private readonly IPageNavigator _navigator;
public ImportLibraryFlow(LibraryImporter importer, IImportReview review, IMessageStrip strip, IPageNavigator navigator)
{
_importer = importer ?? throw new ArgumentNullException(nameof(importer));
_review = review ?? throw new ArgumentNullException(nameof(review));
_strip = strip ?? throw new ArgumentNullException(nameof(strip));
_navigator = navigator ?? throw new ArgumentNullException(nameof(navigator));
}
/// <summary>The report, or null when nothing was found or the user cancelled.</summary>
public async Task<ImportReport?> RunAsync(CancellationToken ct = default)
{
IReadOnlyList<ImportCandidate> candidates = await _importer.DiscoverAsync(ct).ConfigureAwait(true);
if (candidates.Count == 0)
{
_strip.Info(Strings.Import_Title, Strings.Import_NothingFound);
return null;
}
IReadOnlyList<ImportCandidate>? selected = await _review.ReviewAsync(candidates, ct).ConfigureAwait(true);
if (selected is null || selected.Count == 0)
{
return null;
}
ImportReport report = await _importer.ImportAsync(selected, ct).ConfigureAwait(true);
_strip.Success(Strings.Import_Title, string.Format(CultureInfo.CurrentCulture, Strings.Import_Done_Format, report.Added, report.Skipped));
if (report.Added > 0)
{
_navigator.Navigate<GamesPage>();
}
return report;
}
}