From 7c247de18c80892fc3aff3e6bc17c0cb8f998ce3 Mon Sep 17 00:00:00 2001 From: soul Date: Sat, 28 Nov 2026 12:35:42 +0100 Subject: [PATCH] AetherDb: every booted read tool disposes its scratch; the shipped-only open is OpenShipped; save throws on an excluded package Soul s1 findings booted-scratch-leak, shipped-named-overclaimed, save-excluded-package-not-pinned. The name OpenShipped says why, so the per-site comments on the apply paths are not needed. Co-Authored-By: Claude Sonnet 5.5 --- .../BootedCatalogReadToolsTests.cs | 31 ++++++++ .../ConsumablesFirstSetCommandTests.cs | 2 +- .../EconomyCommandTests.cs | 4 +- .../Aetheria.Shared.Tests/EconomyLoopTests.cs | 6 +- .../GenericDesignsCommandTests.cs | 4 +- .../InspectionScannerCommandTests.cs | 2 +- .../LaunchSuppressorCommandTests.cs | 2 +- .../LauncherAmmunitionCatalogTests.cs | 2 +- .../Aetheria.Shared.Tests/MinorPowersTests.cs | 4 +- .../MunitionsSourcingCatalogTests.cs | 6 +- .../PiratesFactionCommandTests.cs | 14 ++-- .../Aetheria.Shared.Tests/PlaceNamesTests.cs | 8 +- .../RolesBackfillCommandTests.cs | 26 +++---- .../ShipSchemaPinTests.cs | 2 +- .../SmokeHullCommandTests.cs | 2 +- .../SmokeRoundsCommandTests.cs | 2 +- .../StationKindDescriptionTests.cs | 8 +- .../StationKindsCatalogTests.cs | 6 +- tools/AetherDb/AetherDb.cs | 4 +- tools/AetherDb/EconomyPrices.cs | 2 +- tools/AetherDb/HardpointRotationCommand.cs | 2 +- tools/AetherDb/MinorPowerFactionsCommand.cs | 2 +- tools/AetherDb/PlaceNamesCommand.cs | 2 +- tools/AetherDb/ProductLinesCommand.cs | 4 +- tools/AetherDb/Program.cs | 75 ++++++++----------- tools/AetherDb/ShipAuthoringCommands.cs | 6 +- tools/AetherDb/ShipAuthoringPush.cs | 2 +- 27 files changed, 126 insertions(+), 104 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/BootedCatalogReadToolsTests.cs b/tests/Aetheria.Shared.Tests/BootedCatalogReadToolsTests.cs index b29fe35ce..6c9aef1f3 100644 --- a/tests/Aetheria.Shared.Tests/BootedCatalogReadToolsTests.cs +++ b/tests/Aetheria.Shared.Tests/BootedCatalogReadToolsTests.cs @@ -38,6 +38,8 @@ public sealed class BootedCatalogReadToolsTests : IDisposable Directory.CreateDirectory(Path.Combine(_broken.Path, "GameData", "Mods", "mod.broken")); File.Copy(Path.Combine(_repo, "GameData", "Aetheria.cc"), Path.Combine(_broken.Path, "GameData", "Aetheria.cc")); File.WriteAllBytes(Path.Combine(_broken.Path, "GameData", "Mods", "mod.broken", "ship.cc"), new byte[] { 1, 2, 3 }); + // The save viewer returns early without a run store, so the fixture holds one; the compose throws before it is read. + File.WriteAllBytes(Path.Combine(_broken.Path, "GameData", "run.cc"), Array.Empty()); return _broken.Path; } @@ -70,6 +72,7 @@ public sealed class BootedCatalogReadToolsTests : IDisposable [InlineData("hardpoint-fit")] [InlineData("factions")] [InlineData("weapon-ammo")] + [InlineData("save")] [InlineData("economy", "report")] [InlineData("economy", "balance")] public void AReadToolThrowsNamingAnExcludedPackage(params string[] args) @@ -79,6 +82,34 @@ public sealed class BootedCatalogReadToolsTests : IDisposable Assert.Contains("mod.broken", error.Message); } + // A read tool's composed scratch (aetherdb-mods-*) is removed when the tool returns or throws. This class runs alone (its collection + // disables parallelization), so no other test is making one meanwhile. + [Theory] + [InlineData("census")] + [InlineData("station-fit")] + [InlineData("loadout", "2")] + [InlineData("hardpoint-fit")] + [InlineData("factions")] + [InlineData("weapon-ammo")] + [InlineData("economy", "report")] + public void AReadToolLeavesNoScratchBehind(params string[] args) + { + var before = Scratches(); + Run(args); + Assert.Equal(before, Scratches()); + } + + [Fact] + public void TheSaveViewerLeavesNoScratchBehindWhenItThrows() + { + var before = Scratches(); + Environment.CurrentDirectory = BrokenRoot(); + Assert.Throws(() => ConsoleProbe.WrittenBy(() => Program.Main(new[] { "save" }))); + Assert.Equal(before, Scratches()); + } + + private static string[] Scratches() => Directory.GetDirectories(Path.GetTempPath(), "aetherdb-mods-*"); + [Fact] public void ComposeBootedThrowsNamingAnExcludedPackage() { diff --git a/tests/Aetheria.Shared.Tests/ConsumablesFirstSetCommandTests.cs b/tests/Aetheria.Shared.Tests/ConsumablesFirstSetCommandTests.cs index 96010e26a..7fbfb3a2c 100644 --- a/tests/Aetheria.Shared.Tests/ConsumablesFirstSetCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/ConsumablesFirstSetCommandTests.cs @@ -37,7 +37,7 @@ public sealed class ConsumablesFirstSetCommandTests : IDisposable private (ConsumableItemData[] Designs, FactionProductData[] Products) Read() { - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { var designs = db.Cache.GetAll().Where(c => DesignNames.Contains(c.Name)).ToArray(); diff --git a/tests/Aetheria.Shared.Tests/EconomyCommandTests.cs b/tests/Aetheria.Shared.Tests/EconomyCommandTests.cs index ec371df8d..eef44b82c 100644 --- a/tests/Aetheria.Shared.Tests/EconomyCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/EconomyCommandTests.cs @@ -337,7 +337,7 @@ public sealed class EconomyCommandTests [Fact] public void BalanceOnTheShippedCatalogPrintsEveryLinkAndBeltRow() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var report = EconomyBalance.Balance(db.Cache); var output = new StringWriter(); EconomyCommand.Balance(db.Cache, 2, output); @@ -352,7 +352,7 @@ public sealed class EconomyCommandTests [Fact] public void ReportOnTheShippedCatalogGoesToTheGivenWriterAndNeverToConsole() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var expected = new StringWriter(); var expectedCode = EconomyCommand.Report(db.Cache, expected); var output = new StringWriter(); diff --git a/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs b/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs index 5bfafdd10..cedbf6926 100644 --- a/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs +++ b/tests/Aetheria.Shared.Tests/EconomyLoopTests.cs @@ -101,7 +101,7 @@ public sealed class EconomyLoopTests [Fact] public void TheBallisticLadderAndItsTopGunSitInsideTheShippedBands() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var settings = new GameplaySettings(); Assert.Equal((10f, 30f, 10f, 20f), (settings.EconomyLadderMin, settings.EconomyLadderMax, settings.EconomySortiesMin, settings.EconomySortiesMax)); var report = EconomyLoop.Report(db.Cache, settings, new[] { Sample(1, 1734, 0, 183, 150) }); @@ -210,7 +210,7 @@ public sealed class EconomyLoopTests // The price the catalog authors for a simple commodity of that name. private static int PriceOf(string name) { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); return db.Cache.GetAll().Single(c => c.Name == name).Price; } @@ -317,7 +317,7 @@ public sealed class EconomyLoopTests [Fact] public void BalanceLoopPrintsTheLoopAndTheLaddersAndLetsTheirFaultsFailTheCommand() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var settings = AuthoredSettings.Load(db.Root).Read("GameplaySettings"); var report = EconomyLoop.Report(db.Cache, settings, new[] { Sample(7, 100, 100, 0, 60) }); var plain = new StringWriter(); diff --git a/tests/Aetheria.Shared.Tests/GenericDesignsCommandTests.cs b/tests/Aetheria.Shared.Tests/GenericDesignsCommandTests.cs index 87d5ed74c..23c7149c8 100644 --- a/tests/Aetheria.Shared.Tests/GenericDesignsCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/GenericDesignsCommandTests.cs @@ -26,14 +26,14 @@ public sealed class GenericDesignsCommandTests : IDisposable private void Edit(Action edit) { - var db = AetherDb.Open(catalogWritable: true, root: _root); + var db = AetherDb.OpenShipped(catalogWritable: true, root: _root); try { edit(db); } finally { db.Cache.Dispose(); } } private T Read(Func read) { - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { return read(db); } finally { db.Cache.Dispose(); } } diff --git a/tests/Aetheria.Shared.Tests/InspectionScannerCommandTests.cs b/tests/Aetheria.Shared.Tests/InspectionScannerCommandTests.cs index 666d6fae7..cc87e061c 100644 --- a/tests/Aetheria.Shared.Tests/InspectionScannerCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/InspectionScannerCommandTests.cs @@ -54,7 +54,7 @@ public sealed class InspectionScannerCommandTests : IDisposable private (GearData[] Designs, string[] Products) Read() { - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { var designs = db.Cache.GetAll().Where(g => g.Name == DesignName).ToArray(); diff --git a/tests/Aetheria.Shared.Tests/LaunchSuppressorCommandTests.cs b/tests/Aetheria.Shared.Tests/LaunchSuppressorCommandTests.cs index 1d7fb2cd6..2f7d41863 100644 --- a/tests/Aetheria.Shared.Tests/LaunchSuppressorCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/LaunchSuppressorCommandTests.cs @@ -53,7 +53,7 @@ public sealed class LaunchSuppressorCommandTests : IDisposable private (GearData[] Designs, string[] Products) Read() { - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { var designs = db.Cache.GetAll().Where(g => DesignNames.Contains(g.Name)).ToArray(); diff --git a/tests/Aetheria.Shared.Tests/LauncherAmmunitionCatalogTests.cs b/tests/Aetheria.Shared.Tests/LauncherAmmunitionCatalogTests.cs index 209a0caa9..f57a648b1 100644 --- a/tests/Aetheria.Shared.Tests/LauncherAmmunitionCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/LauncherAmmunitionCatalogTests.cs @@ -13,7 +13,7 @@ public sealed class LauncherAmmunitionCatalogTests [Fact] public void EveryShippedLauncherReloadsFromMissilesAndMissilesCanBeMade() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var missiles = db.Cache.GetAll().Single(c => c.Name == "Missiles"); var key = db.Cache.RefOf(missiles).Key; var launchers = db.Cache.GetAll().SelectMany(i => i.Behaviors.OfType().Where(IsLauncher).Select(d => (i.Name, d))).ToArray(); diff --git a/tests/Aetheria.Shared.Tests/MinorPowersTests.cs b/tests/Aetheria.Shared.Tests/MinorPowersTests.cs index cf133ecb8..14d7622bc 100644 --- a/tests/Aetheria.Shared.Tests/MinorPowersTests.cs +++ b/tests/Aetheria.Shared.Tests/MinorPowersTests.cs @@ -81,7 +81,7 @@ public sealed class MinorPowersTests : IDisposable Assert.Equal(0, MinorPowerFactionsCommand.Run(new[] { "apply" }, _root)); var landed = File.ReadAllBytes(CatalogPath); Assert.NotEqual(before, landed); - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { var factions = db.Cache.GetAll().ToArray(); @@ -108,7 +108,7 @@ public sealed class MinorPowersTests : IDisposable public void ANameHeldUnderAnotherKeyIsRefusedWithNothingWritten() { StripTheMinorPowers(); - var squatter = AetherDb.Open(catalogWritable: true, root: _root); + var squatter = AetherDb.OpenShipped(catalogWritable: true, root: _root); squatter.Cache.Commit(batch => batch.Upsert(typeof(Faction), new Faction { Name = "Megiddo", ShortName = "Megiddo" })); squatter.Cache.Dispose(); var before = File.ReadAllBytes(CatalogPath); diff --git a/tests/Aetheria.Shared.Tests/MunitionsSourcingCatalogTests.cs b/tests/Aetheria.Shared.Tests/MunitionsSourcingCatalogTests.cs index 45c8db147..7100eddbc 100644 --- a/tests/Aetheria.Shared.Tests/MunitionsSourcingCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/MunitionsSourcingCatalogTests.cs @@ -17,7 +17,7 @@ public sealed class MunitionsSourcingCatalogTests [Fact] public void EveryRoundFiringGunNamesAnAmmunitionCommodityAndHoldsARealMagazine() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var guns = db.Cache.GetAll() .SelectMany(i => i.Behaviors.OfType().Where(d => FiresRounds(i, d)).Select(d => (i.Name, d))).ToArray(); Assert.True(guns.Length >= 14, $"fixture: the catalog holds its round-firing guns ({guns.Length})"); @@ -34,7 +34,7 @@ public sealed class MunitionsSourcingCatalogTests [Fact] public void EveryDrawnAmmunitionHasAFiniteProductionDepth() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var depth = EconomyChecks.Deep(db.Cache); var drawn = db.Cache.GetAll().SelectMany(i => i.Behaviors.OfType()).Where(d => d.AmmoType.IsSet()) .Select(d => d.AmmoType.Key.Value).Distinct().ToArray(); @@ -47,7 +47,7 @@ public sealed class MunitionsSourcingCatalogTests [Fact] public void TheMunitionsChainHasNoSourceSinkFault() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var chain = new HashSet(ChainOf(db.Cache), System.StringComparer.Ordinal); Assert.True(chain.Count >= 25, $"fixture: the chain is walked ({chain.Count} goods)"); var faults = EconomyChecks.SourceSink(db.Cache).Where(f => chain.Contains(KeyOfRecipe(f.Record))).ToArray(); diff --git a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs index 1dee99d84..7b83c8525 100644 --- a/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/PiratesFactionCommandTests.cs @@ -42,14 +42,14 @@ public sealed class PiratesFactionCommandTests : IDisposable private int AllFactionsButThePirates() { - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { return db.Cache.GetAll().Count(f => f.Name != "Pirates"); } finally { db.Cache.Dispose(); } } private (Faction[] Pirates, FactionProductData[] Products) Read() { - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { var pirates = db.Cache.GetAll().Where(faction => faction.Name == "Pirates").ToArray(); @@ -80,7 +80,7 @@ public sealed class PiratesFactionCommandTests : IDisposable Assert.Equal(AllFactionsButThePirates(), faction.Allegiance.Count); Assert.All(faction.Allegiance.Values, value => Assert.Equal(1f, value)); - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { var expected = new (string Design, string Name, string Description)[] @@ -118,7 +118,7 @@ public sealed class PiratesFactionCommandTests : IDisposable [Fact] public void An_existing_Pirates_faction_is_topped_up_with_allegiance_and_nothing_else() { - var db = AetherDb.Open(catalogWritable: true, root: _root); + var db = AetherDb.OpenShipped(catalogWritable: true, root: _root); db.Cache.Commit(batch => batch.Upsert(typeof(Faction), new Faction { Name = "Pirates", ShortName = "Mine", Description = "authored by hand" })); var key = db.Cache.RefOf(db.Cache.GetAll().Single(f => f.Name == "Pirates")).Key; db.Cache.Dispose(); @@ -135,14 +135,14 @@ public sealed class PiratesFactionCommandTests : IDisposable Assert.Empty(products); var topped = File.ReadAllBytes(CatalogPath); - var late = AetherDb.Open(catalogWritable: true, root: _root); + var late = AetherDb.OpenShipped(catalogWritable: true, root: _root); late.Cache.Commit(batch => batch.Upsert(typeof(Faction), new Faction { Name = "Latecomer", ShortName = "Late" })); var lateRef = late.Cache.RefOf(late.Cache.GetAll().Single(f => f.Name == "Latecomer")); var others = late.Cache.GetAll().Count(f => f.Name != "Pirates"); late.Cache.Dispose(); Assert.Equal(0, Program.PiratesFaction(apply: true, root: _root)); - var check = AetherDb.Open(root: _root); + var check = AetherDb.OpenShipped(root: _root); try { var after = check.Cache.GetAll().Single(f => f.Name == "Pirates"); @@ -163,7 +163,7 @@ public sealed class PiratesFactionCommandTests : IDisposable [Fact] public void A_missing_design_refuses_and_lands_nothing() { - var db = AetherDb.Open(catalogWritable: true, root: _root); + var db = AetherDb.OpenShipped(catalogWritable: true, root: _root); var autocannon = db.Cache.GetAll().Single(weapon => weapon.Name == "Autocannon"); autocannon.Name = "Autocannon (renamed)"; db.Cache.Commit(batch => batch.Upsert(typeof(WeaponItemData), autocannon, db.Cache.RefOf(autocannon).Key)); diff --git a/tests/Aetheria.Shared.Tests/PlaceNamesTests.cs b/tests/Aetheria.Shared.Tests/PlaceNamesTests.cs index 0d53a1706..6856b6eb9 100644 --- a/tests/Aetheria.Shared.Tests/PlaceNamesTests.cs +++ b/tests/Aetheria.Shared.Tests/PlaceNamesTests.cs @@ -297,7 +297,7 @@ public sealed class PlaceNamesTests : IDisposable Assert.Equal(0, PlaceNamesCommand.Run(new[] { "apply" }, root)); var landed = File.ReadAllBytes(CatalogOf(root)); Assert.NotEqual(before, landed); - var db = AetherDb.Open(root: root); + var db = AetherDb.OpenShipped(root: root); try { foreach (var row in PlaceNamesCommand.Table) @@ -308,7 +308,7 @@ public sealed class PlaceNamesTests : IDisposable Assert.Equal(landed, File.ReadAllBytes(CatalogOf(root))); // Aya's ShortName changed under its key: identity is the key, so the row no longer describes that faction. - var squatter = AetherDb.Open(catalogWritable: true, root: root); + var squatter = AetherDb.OpenShipped(catalogWritable: true, root: root); var aya = squatter.Cache.GetAll().Single(f => f.ShortName == "Aya"); aya.ShortName = "Ayx"; squatter.Cache.Commit(batch => batch.Upsert(typeof(Faction), aya, squatter.Cache.RefOf(aya).Key)); @@ -325,7 +325,7 @@ public sealed class PlaceNamesTests : IDisposable var root = ScratchWithoutLists(); Assert.Equal(0, PlaceNamesCommand.Run(new[] { "apply" }, root)); var row = PlaceNamesCommand.Table.First(); - var edited = AetherDb.Open(catalogWritable: true, root: root); + var edited = AetherDb.OpenShipped(catalogWritable: true, root: root); var faction = edited.Cache.GetAll().Single(f => edited.Cache.RefOf(f).Key.Value == row.RecordKey); faction.Places = row.Names.Reverse().Select(n => new FactionPlace { Name = n }).ToArray(); edited.Cache.Commit(batch => batch.Upsert(typeof(Faction), faction, edited.Cache.RefOf(faction).Key)); @@ -333,7 +333,7 @@ public sealed class PlaceNamesTests : IDisposable Assert.Equal(0, PlaceNamesCommand.Run(new[] { "apply" }, root)); - var db = AetherDb.Open(root: root); + var db = AetherDb.OpenShipped(root: root); try { Assert.Equal(row.Names, db.Cache.GetAll().Single(f => db.Cache.RefOf(f).Key.Value == row.RecordKey).Places.Select(p => p.Name)); } finally { db.Cache.Dispose(); } } diff --git a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs index 2630291cb..64dc7ac33 100644 --- a/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/RolesBackfillCommandTests.cs @@ -123,7 +123,7 @@ public sealed class RolesBackfillCommandTests : IDisposable private Dictionary Read() { - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { var products = db.Cache.GetAll().ToArray(); @@ -189,7 +189,7 @@ public sealed class RolesBackfillCommandTests : IDisposable Reset(flattened: true, unnamed: true); Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root)); - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); Dictionary> after; try { after = Read(db.Cache.GetAll().ToArray()); } finally { db.Cache.Dispose(); } @@ -201,7 +201,7 @@ public sealed class RolesBackfillCommandTests : IDisposable public void A_seller_with_one_of_two_roles_authored_gains_only_the_missing_role() { Reset(flattened: false, unnamed: false); - var db = AetherDb.Open(catalogWritable: true, root: _root); + var db = AetherDb.OpenShipped(catalogWritable: true, root: _root); var autocannon = db.Cache.GetAll().Single(weapon => weapon.Name == "Autocannon"); var seller = db.Cache.GetAll().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key) && p.Roles.Count == 2); var kept = seller.Roles.OrderBy(r => r.Role, StringComparer.Ordinal).First(); @@ -213,7 +213,7 @@ public sealed class RolesBackfillCommandTests : IDisposable db.Cache.Dispose(); Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root)); - db = AetherDb.Open(root: _root); + db = AetherDb.OpenShipped(root: _root); try { var after = db.Cache.GetAll().Single(p => p.Name == sellerName); @@ -228,7 +228,7 @@ public sealed class RolesBackfillCommandTests : IDisposable public void A_binned_seller_gains_no_roles() { Reset(flattened: false, unnamed: false); - var db = AetherDb.Open(catalogWritable: true, root: _root); + var db = AetherDb.OpenShipped(catalogWritable: true, root: _root); var autocannon = db.Cache.GetAll().Single(weapon => weapon.Name == "Autocannon"); var seller = db.Cache.GetAll().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key) && p.Roles.Count == 2); var sellerName = seller.Name; @@ -246,7 +246,7 @@ public sealed class RolesBackfillCommandTests : IDisposable db.Cache.Dispose(); Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root)); - db = AetherDb.Open(root: _root); + db = AetherDb.OpenShipped(root: _root); try { Assert.Equal(2, db.Cache.GetAll().Single(p => p.Name == sellerName).Roles.Count); @@ -259,7 +259,7 @@ public sealed class RolesBackfillCommandTests : IDisposable [Fact] public void The_census_reports_a_roleless_seller_and_never_a_bin() { - var db = AetherDb.Open(catalogWritable: true, root: _root); + var db = AetherDb.OpenShipped(catalogWritable: true, root: _root); var autocannon = db.Cache.GetAll().Single(weapon => weapon.Name == "Autocannon"); var seller = db.Cache.GetAll().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key)); var sellerName = seller.Name; @@ -275,7 +275,7 @@ public sealed class RolesBackfillCommandTests : IDisposable }); db.Cache.Dispose(); - db = AetherDb.Open(root: _root); + db = AetherDb.OpenShipped(root: _root); try { var gaps = Program.RoleGaps(db.Cache, db.Cache.GetAll().ToArray(), db.Cache.GetAll().ToArray()).ToArray(); @@ -289,7 +289,7 @@ public sealed class RolesBackfillCommandTests : IDisposable [Fact] public void A_binned_seller_gains_no_roles_from_roles_migrate() { - var db = AetherDb.Open(catalogWritable: true, root: _root); + var db = AetherDb.OpenShipped(catalogWritable: true, root: _root); var autocannon = db.Cache.GetAll().Single(weapon => weapon.Name == "Autocannon"); var seller = db.Cache.GetAll().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key)); var bin = new FactionProductData @@ -301,7 +301,7 @@ public sealed class RolesBackfillCommandTests : IDisposable db.Cache.Dispose(); Assert.Equal(0, Program.RolesMigrate(apply: true, root: _root)); - db = AetherDb.Open(root: _root); + db = AetherDb.OpenShipped(root: _root); try { Assert.Empty(db.Cache.GetAll().Single(p => p.Name == "Binned " + seller.Name).Roles); } finally { db.Cache.Dispose(); } } @@ -310,7 +310,7 @@ public sealed class RolesBackfillCommandTests : IDisposable [Fact] public void A_binned_seller_gains_no_roles_from_sensor_stat_set() { - var db = AetherDb.Open(catalogWritable: true, root: _root); + var db = AetherDb.OpenShipped(catalogWritable: true, root: _root); var sensor = db.Cache.GetAll().Where(d => d.Behaviors != null && d.Behaviors.OfType().Any()).OrderBy(d => d.Name, StringComparer.Ordinal).First(); var seller = db.Cache.GetAll().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Bin == null && p.Design.Key.Equals(db.Cache.RefOf(sensor).Key)); var bin = new FactionProductData @@ -322,7 +322,7 @@ public sealed class RolesBackfillCommandTests : IDisposable db.Cache.Dispose(); Assert.Equal(0, Program.SensorStatSet(apply: true, root: _root)); - db = AetherDb.Open(root: _root); + db = AetherDb.OpenShipped(root: _root); try { Assert.Empty(db.Cache.GetAll().Single(p => p.Name == "Binned " + seller.Name).Roles); } finally { db.Cache.Dispose(); } } @@ -331,7 +331,7 @@ public sealed class RolesBackfillCommandTests : IDisposable public void A_design_the_catalog_does_not_hold_refuses_and_lands_nothing() { Reset(flattened: false, unnamed: false); - var db = AetherDb.Open(catalogWritable: true, root: _root); + var db = AetherDb.OpenShipped(catalogWritable: true, root: _root); var autocannon = db.Cache.GetAll().Single(weapon => weapon.Name == "Autocannon"); autocannon.Name = "Autocannon (renamed)"; db.Cache.Commit(batch => batch.Upsert(typeof(WeaponItemData), autocannon, db.Cache.RefOf(autocannon).Key)); diff --git a/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs b/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs index 37eb4fcbe..9cbc5bb57 100644 --- a/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs +++ b/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs @@ -72,7 +72,7 @@ public sealed class ShipSchemaPinTests var scad = File.ReadAllText(Locate("tools", "blender", "aetheria_ships", "factions", file)); var literal = Regex.Match(scad, @"^[A-Z]+_LANG = \[[^;]*""([^""]+)""\];", RegexOptions.Multiline); Assert.True(literal.Success, $"{file} has no *_LANG with a maker as its last element"); - var db = AetherDb.Open(root: AetherDb.FindRoot()); + var db = AetherDb.OpenShipped(root: AetherDb.FindRoot()); try { var record = Assert.Single(db.Cache.GetAll().Where(f => f.Name == faction)); diff --git a/tests/Aetheria.Shared.Tests/SmokeHullCommandTests.cs b/tests/Aetheria.Shared.Tests/SmokeHullCommandTests.cs index 4084f377b..bcef02ce4 100644 --- a/tests/Aetheria.Shared.Tests/SmokeHullCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/SmokeHullCommandTests.cs @@ -31,7 +31,7 @@ public sealed class SmokeHullCommandTests : IDisposable private (HullData[] Hulls, HullData Longinus, EquippableItemData[] Fitted, int Products) Read() { - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { var hulls = db.Cache.GetAll().Where(h => h.Name == HullName).ToArray(); diff --git a/tests/Aetheria.Shared.Tests/SmokeRoundsCommandTests.cs b/tests/Aetheria.Shared.Tests/SmokeRoundsCommandTests.cs index 83013d766..5a1484b69 100644 --- a/tests/Aetheria.Shared.Tests/SmokeRoundsCommandTests.cs +++ b/tests/Aetheria.Shared.Tests/SmokeRoundsCommandTests.cs @@ -45,7 +45,7 @@ public sealed class SmokeRoundsCommandTests : IDisposable private (WeaponItemData[] Smoke, WeaponItemData LightLaser, WeaponItemData ChargedScatterBlaster, int Products) Read() { - var db = AetherDb.Open(root: _root); + var db = AetherDb.OpenShipped(root: _root); try { var smoke = db.Cache.GetAll().Where(w => Names.Contains(w.Name)).ToArray(); diff --git a/tests/Aetheria.Shared.Tests/StationKindDescriptionTests.cs b/tests/Aetheria.Shared.Tests/StationKindDescriptionTests.cs index df714cd53..5384ab3de 100644 --- a/tests/Aetheria.Shared.Tests/StationKindDescriptionTests.cs +++ b/tests/Aetheria.Shared.Tests/StationKindDescriptionTests.cs @@ -11,7 +11,7 @@ public sealed class StationKindDescriptionTests [Fact] public void EveryRawGoodAKindExtractsIsNamedInItsDescription() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var cache = db.Cache; var unnamed = cache.GetAll().Where(recipe => Recipes.IsRaw(cache, recipe) && recipe.StationKind.IsSet()) .Select(recipe => (Kind: cache.Get(recipe.StationKind), Output: cache.Get(recipe.Output))) @@ -25,7 +25,7 @@ public sealed class StationKindDescriptionTests [Fact] public void MiningExtractsDiamondAndVolatilesAmmonia() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var cache = db.Cache; string RawAt(string kindId) => string.Join(",", cache.GetAll() .Where(recipe => Recipes.IsRaw(cache, recipe) && recipe.StationKind.IsSet() && recipe.StationKind.Key.Equals(StationKindData.KeyOf(kindId))) @@ -41,7 +41,7 @@ public sealed class StationKindDescriptionTests [Fact] public void EveryCommodityAStationKindNamesIsMadeOrTakenByARecipe() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var c = db.Cache; var used = c.GetAll().SelectMany(r => r.Inputs.Select(i => i.Commodity.Key.Value).Append(r.Output.Key.Value)).ToHashSet(); var commodities = c.GetAll().ToArray(); @@ -59,7 +59,7 @@ public sealed class StationKindDescriptionTests [Fact] public void TheShippedDescriptionsAreTheAuthoredTable() { - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); foreach (var id in new[] { "mining", "volatiles", "agriculture", "habitat-support", "power" }) Assert.Equal(StationKindsCatalog.DescriptionOf(id), db.Cache.Get(StationKindData.KeyOf(id)).Description); } diff --git a/tests/Aetheria.Shared.Tests/StationKindsCatalogTests.cs b/tests/Aetheria.Shared.Tests/StationKindsCatalogTests.cs index cc926afa6..677545697 100644 --- a/tests/Aetheria.Shared.Tests/StationKindsCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/StationKindsCatalogTests.cs @@ -84,7 +84,7 @@ public sealed class StationKindsCatalogTests : IDisposable var warned = new List(); var applied = new StringWriter(); - using (var db = AetherDb.Open(catalogWritable: true, root: root, warn: warned.Add)) + using (var db = AetherDb.OpenShipped(catalogWritable: true, root: root, warn: warned.Add)) { Assert.Contains(warned, line => line.Contains("Zenith")); Assert.Contains(warned, line => line.Contains("Second Station")); @@ -94,7 +94,7 @@ public sealed class StationKindsCatalogTests : IDisposable } Assert.Throws(() => AetheriaStores.Open(catalog)); - using (var db = AetherDb.Open(catalogWritable: true, root: root, warn: _ => { })) + using (var db = AetherDb.OpenShipped(catalogWritable: true, root: root, warn: _ => { })) { var dry = new StringWriter(); Assert.Equal(0, StationKindsCatalog.SetHullKind(db.Cache, "Second Station", "mining", false, dry)); @@ -112,7 +112,7 @@ public sealed class StationKindsCatalogTests : IDisposable public void SetHullKindRefusesWhatIsNotAStationHullOrAHeldKind() { var root = SeedRoot("Zenith"); - using var db = AetherDb.Open(catalogWritable: true, root: root, warn: _ => { }); + using var db = AetherDb.OpenShipped(catalogWritable: true, root: root, warn: _ => { }); StationKindsCatalog.Run(db.Cache, true, new StringWriter()); string Refusal(string hull, string kind) { diff --git a/tools/AetherDb/AetherDb.cs b/tools/AetherDb/AetherDb.cs index 0d7dd6035..319dbecf9 100644 --- a/tools/AetherDb/AetherDb.cs +++ b/tools/AetherDb/AetherDb.cs @@ -4,7 +4,7 @@ using System.Linq; using GameCult.Caching; // Opens the catalog through AetheriaStores, the game's own store composition: OpenBooted for a read tool (the catalog the game boots), -// Open for the shipped GameData/Aetheria.cc alone, which attaches read-only unless a command writes it, so a command that only reads cannot write. A station hull with no kind does not lock the +// OpenShipped for the shipped GameData/Aetheria.cc alone, which attaches read-only unless a command writes it, so a command that only reads cannot write. A station hull with no kind does not lock the // catalog: it is named to warn (stderr by default) and the commands that repair it stay reachable. public sealed class AetherDb : IDisposable { @@ -61,7 +61,7 @@ public sealed class AetherDb : IDisposable // The shipped GameData/Aetheria.cc alone, which is what an apply path (and its dry run) reads and writes. With no root given, walks up // from the working directory to the game folder: the first folder whose GameData holds Aetheria.cc. - public static AetherDb Open(bool catalogWritable = false, bool withRun = false, string root = null, Action warn = null) => + public static AetherDb OpenShipped(bool catalogWritable = false, bool withRun = false, string root = null, Action warn = null) => new AetherDb(root ?? FindRoot(), false, withRun, warn, catalogWritable); // The catalog the game boots (see ComposeBooted), read-only: every read tool opens this. diff --git a/tools/AetherDb/EconomyPrices.cs b/tools/AetherDb/EconomyPrices.cs index 03b8dc73d..331f7f717 100644 --- a/tools/AetherDb/EconomyPrices.cs +++ b/tools/AetherDb/EconomyPrices.cs @@ -24,7 +24,7 @@ public static class EconomyPrices } // The shipped file alone, on purpose: a package's hull price is read from its ship.cc below, so a composed catalog would list the // same hull twice, and the second catalog an old side is compared against is a shipped file. - using var db = AetherDb.Open(); + using var db = AetherDb.OpenShipped(); var now = Read(db.Cache, mods ?? Path.Combine(db.Root, "GameData", "Mods")); if (other == null) { diff --git a/tools/AetherDb/HardpointRotationCommand.cs b/tools/AetherDb/HardpointRotationCommand.cs index daf32df62..44319edaf 100644 --- a/tools/AetherDb/HardpointRotationCommand.cs +++ b/tools/AetherDb/HardpointRotationCommand.cs @@ -15,7 +15,7 @@ public static class HardpointRotationCommand { var apply = args.Contains("apply"); var positional = args.Where(a => a != "apply").ToArray(); - using var db = AetherDb.Open(catalogWritable: apply); + using var db = AetherDb.OpenShipped(catalogWritable: apply); var code = Run(db.Cache, positional, apply, Console.Out); if (apply && code == 0) db.Cache.FlushAsync().GetAwaiter().GetResult(); return code; diff --git a/tools/AetherDb/MinorPowerFactionsCommand.cs b/tools/AetherDb/MinorPowerFactionsCommand.cs index 9853d07ba..d16a98bc4 100644 --- a/tools/AetherDb/MinorPowerFactionsCommand.cs +++ b/tools/AetherDb/MinorPowerFactionsCommand.cs @@ -48,7 +48,7 @@ public static class MinorPowerFactionsCommand public static int Run(string[] args, string root = null) { var apply = args.Contains("apply"); - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var existing = db.Cache.GetAll().ToArray(); // Refuse before any write: a name or short name held by a faction under another key. diff --git a/tools/AetherDb/PlaceNamesCommand.cs b/tools/AetherDb/PlaceNamesCommand.cs index 0bb0700b9..b45a78e9b 100644 --- a/tools/AetherDb/PlaceNamesCommand.cs +++ b/tools/AetherDb/PlaceNamesCommand.cs @@ -66,7 +66,7 @@ public static class PlaceNamesCommand internal static int Run(string[] args, string root, Row[] table) { var apply = args.Contains("apply"); - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var factions = db.Cache.GetAll().ToArray(); var keyOf = factions.ToDictionary(f => db.Cache.RefOf(f).Key.Value, StringComparer.Ordinal); diff --git a/tools/AetherDb/ProductLinesCommand.cs b/tools/AetherDb/ProductLinesCommand.cs index 2c82d5ebf..442cac59d 100644 --- a/tools/AetherDb/ProductLinesCommand.cs +++ b/tools/AetherDb/ProductLinesCommand.cs @@ -126,7 +126,7 @@ public static class ProductLinesCommand return 1; } - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var designs = db.Cache.GetAll().ToArray(); var factions = db.Cache.GetAll().ToArray(); var products = db.Cache.GetAll().ToArray(); @@ -204,7 +204,7 @@ public static class ProductLinesCommand // so the same command is the first apply and the replay onto a merged catalog. internal static int RunTiers(IReadOnlyList tiers, bool apply, string root) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var designs = db.Cache.GetAll().ToArray(); var products = db.Cache.GetAll().ToArray(); diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 0a3d0a5fa..ecf1dcf5a 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -28,7 +28,7 @@ public static class Program case "shield-catalog": { var apply = args.Contains("apply"); - using var db = AetherDb.Open(catalogWritable: apply); + using var db = AetherDb.OpenShipped(catalogWritable: apply); var code = ShieldCatalog.Run(db.Cache, apply, Console.Out); if (apply) db.Cache.FlushAsync().GetAwaiter().GetResult(); return code; @@ -67,8 +67,8 @@ public static class Program case "inspection-scanner": return InspectionScannerCatalog(args.Contains("apply")); case "product-lines": return ProductLinesCommand.Run(args.Skip(1).ToArray()); case "minor-power-factions": return MinorPowerFactionsCommand.Run(args.Skip(1).ToArray()); - case "station-reactor-spread": return StationReactorSpreadCommand.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); - case "assembly-from-maker": return AssemblyFromMakerCommand.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); + case "station-reactor-spread": return StationReactorSpreadCommand.Run(AetherDb.OpenShipped(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); + case "assembly-from-maker": return AssemblyFromMakerCommand.Run(AetherDb.OpenShipped(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); case "place-names": Console.OutputEncoding = new System.Text.UTF8Encoding(false); return PlaceNamesCommand.Run(args.Skip(1).ToArray()); @@ -77,7 +77,7 @@ public static class Program var apply = args.Contains("apply"); // Shipped file alone, on purpose: every form here (the kinds report included) is the dry run of an apply that writes the shipped // file, so it reads what apply would change; its report is identical over the composed catalog. - using var db = AetherDb.Open(catalogWritable: apply); + using var db = AetherDb.OpenShipped(catalogWritable: apply); int code; if (args.Length > 1 && args[1] == "hull") { @@ -99,12 +99,12 @@ public static class Program if (args.Length < 2 || args[1] != "resave") { Console.WriteLine("catalog resave [apply]"); return 1; } var apply = args.Contains("apply"); // Shipped file alone, on purpose: a resave restamps GameData/Aetheria.cc itself, so a composed catalog would write the packages into it. - using var db = AetherDb.Open(catalogWritable: apply); + using var db = AetherDb.OpenShipped(catalogWritable: apply); return CatalogResaveCommand.Run(db.Cache, apply, Console.Out); } case "economy": return EconomyCommand.Run(args.Skip(1).ToArray(), Console.Out); - case "auto-guns": return AutoGunsCatalog.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); - case "doctrine-catalog": return DoctrineCatalog.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); + case "auto-guns": return AutoGunsCatalog.Run(AetherDb.OpenShipped(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); + case "doctrine-catalog": return DoctrineCatalog.Run(AetherDb.OpenShipped(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); default: Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, hardpoint-rotation \"\" , [apply], loadout [seed], loadout-commit [,,,[@]]... [--group ,...]... [--replace] [--boss-of ], save, settings, settings-dump, dangling [clear ]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], range-falloff [apply] [--effective ] [--end ], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, mine-launcher [apply], smoke-hull [apply], smoke-rounds [apply], roles-backfill [apply], pd-gear [apply], consumables-first-set [apply], launch-suppressor [apply], pirates-faction [apply], verse-grammar [apply], generic-designs [apply], sensor-stat-set [apply], inspection-scanner [apply], minor-power-factions [apply], place-names [apply], product-lines weapons|minor-powers|gear|tiers [apply], doctrine-catalog [apply], auto-guns [apply], assembly-from-maker [apply], shield-catalog [apply], station-kinds [hull \"\" | facilities \"\" ,:...] [apply], economy report|prices|author ... [apply]|balance"); return 1; @@ -114,7 +114,7 @@ public static class Program // Designs by kind and manufacturer, designs no product sells, and products with authored role quality. private static int Census() { - var db = AetherDb.OpenBooted(); + using var db = AetherDb.OpenBooted(); var items = db.Cache.GetAll().ToArray(); var products = db.Cache.GetAll() .OrderBy(p => db.Cache.RefOf(p).Key.Value, StringComparer.Ordinal).ToArray(); @@ -373,7 +373,7 @@ public static class Program // the operator review table (grouped by item kind) either way. public static int RolesMigrate(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var items = db.Cache.GetAll().ToArray(); var products = db.Cache.GetAll().ToArray(); var changedDesigns = new List<(object Document, CultRecordKey Key)>(); @@ -537,7 +537,7 @@ public static class Program // generation equips hardpoint gear first and only the first of those is guaranteed. private static int StationFit() { - var db = AetherDb.OpenBooted(); + using var db = AetherDb.OpenBooted(); var bays = db.Cache.GetAll().ToArray(); var failures = 0; foreach (var hull in db.Cache.GetAll().Where(h => h.HullType == HullType.Station)) @@ -663,7 +663,7 @@ public static class Program var clear = new HashSet(args.Select((arg, i) => (arg, i)) .Where(p => p.arg == "clear" && p.i + 1 < args.Length) .Select(p => args[p.i + 1])); - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); var changed = new List<(object Document, CultRecordKey Key)>(); var found = 0; @@ -771,7 +771,7 @@ public static class Program // Galaxy.NamePlaces falls back to catalogue designations for a faction without one. private static int Factions() { - var db = AetherDb.OpenBooted(); + using var db = AetherDb.OpenBooted(); var products = db.Cache.GetAll().ToArray(); Console.WriteLine($"{"faction",-26} {"short",-13} {"places",-22} {"boss loadout",-14} {"influence",-9} {"doctrine",-10} products"); var broken = 0; @@ -800,16 +800,7 @@ public static class Program return 0; } - AetherDb db; - try - { - db = AetherDb.OpenBooted(withRun: true); - } - catch (Exception e) - { - Console.WriteLine($"save does not open: {e.GetType().Name}: {e.Message}"); - return 1; - } + using var db = AetherDb.OpenBooted(withRun: true); var run = db.Cache.GetGlobal(); if (run?.Zones == null) @@ -860,7 +851,7 @@ public static class Program private static int Loadout(string[] args) { var seed = uint.TryParse(args.FirstOrDefault(), out var parsed) ? parsed : 1u; - var db = AetherDb.OpenBooted(); + using var db = AetherDb.OpenBooted(); var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), @@ -935,7 +926,7 @@ public static class Program // operator review either way). private static int ShieldMigrate(bool apply) { - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); // ShieldData nests inside either host's Behaviors list (GearData: an equipped item with a hardpoint // Shape to size from; ConsumableItemData: a consumable effect with no Shape -- cells reads 0 there, and @@ -1033,7 +1024,7 @@ public static class Program // same contract as ShieldMigrate. private static int BrownoutMigrate(bool apply) { - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); const float gentleExponent = 1f; // (behaviour type, target performance-stat field, short label) -- one of these is also a request field @@ -1120,7 +1111,7 @@ public static class Program // otherwise. Dry run unless passed "apply", same contract as ShieldMigrate/BrownoutMigrate. private static int FiringArcMigrate(bool apply) { - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); var hulls = db.Cache.GetAll().Where(h => h.Name == "Turret").ToArray(); if (hulls.Length == 0) @@ -1173,7 +1164,7 @@ public static class Program // against the catalog and not against names. private static int WeaponAmmo() { - var db = AetherDb.OpenBooted(); + using var db = AetherDb.OpenBooted(); Console.WriteLine($"{"weapon",-28} {"behaviour",-20} {"energy",-11} {"mag",5} {"reload",6} ammo"); foreach (var item in db.Cache.GetAll().OrderBy(i => i.Name, StringComparer.Ordinal)) foreach (var w in item.Behaviors.OfType()) @@ -1197,7 +1188,7 @@ public static class Program } var fraction = Option("--effective", .5f); var end = Option("--end", 0f); - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); // A record is rewritten only when what it would store differs from what is stored: that is what drops the retired // key 7 from a record the command leaves otherwise unchanged, and what makes a second apply change no byte. var persisted = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(Path.Combine(db.Root, "GameData", "Aetheria.cc"))) @@ -1252,7 +1243,7 @@ public static class Program // Dry run unless passed "apply", same contract as the other *-migrate commands. private static int TargetingCatalog(bool apply) { - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); Faction FactionByShortName(string shortName) { @@ -1467,7 +1458,7 @@ public static class Program // Dry run unless passed "apply", same contract as the other *-migrate commands. private static int TargetingCatalog6c(bool apply) { - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); Faction FactionByShortName(string shortName) { @@ -1577,7 +1568,7 @@ public static class Program // Dry run unless passed "apply", same contract as the other *-migrate commands. private static int TargetingCatalog6d(bool apply) { - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); GearData DesignByName(string name) { @@ -1638,7 +1629,7 @@ public static class Program // each carries several products, and branding lives in the products alone. Dry run unless passed "apply". private static int PdGearCatalog(bool apply) { - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); var weapons = db.Cache.GetAll().ToArray(); var designNames = new[] { "Point Defense Gun", "Point Defense Laser", "Flak Gun" }; @@ -1784,7 +1775,7 @@ public static class Program // "apply"; idempotent, so a second apply writes nothing and a catalog another cut changed is rerun, never merged. internal static int SensorStatSet(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var designs = db.Cache.GetAll().ToArray(); var products = db.Cache.GetAll().ToArray(); Faction MakerOf(FactionProductData p) => db.Cache.Get(p.Manufacturer); @@ -1941,7 +1932,7 @@ public static class Program public static int SmokeHullCatalog(bool apply, string root = null) { const string name = "Smoke Test Hull"; - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); if (db.Cache.GetAll().Any(h => h.Name == name)) { Console.WriteLine($"\"{name}\" is already authored; nothing to do."); @@ -2004,7 +1995,7 @@ public static class Program // (Velocity 150) so a scenario can kill the target while one is in the air. Dry run unless passed "apply". public static int SmokeRoundsCatalog(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var weapons = db.Cache.GetAll().ToArray(); var names = new[] { "Smoke Proximity", "Smoke Delayed", "Smoke Refused", "Smoke Refused Beam", "Smoke Refused Charge" }; var already = names.Count(name => weapons.Any(w => w.Name == name)); @@ -2100,7 +2091,7 @@ public static class Program private static int MineLauncherCatalog(bool apply) { const string name = "Mine Launcher"; - var db = AetherDb.Open(catalogWritable: apply); + var db = AetherDb.OpenShipped(catalogWritable: apply); const float minimumTemperature = 173.15f, maximumTemperature = 473.15f, optimalTemperature = 249.65f, plateauWidth = 36f; if (db.Cache.GetAll().SingleOrDefault(gear => gear.Name == name) is { } authored) { @@ -2229,7 +2220,7 @@ public static class Program public static int RolesBackfill(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var items = db.Cache.GetAll().ToArray(); var products = db.Cache.GetAll().ToArray(); var targets = BackfillDesigns.Select(name => items.Where(i => i.Name == name).ToArray()) @@ -2342,7 +2333,7 @@ public static class Program public static int PiratesFaction(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var existing = db.Cache.GetAll().FirstOrDefault(f => f.Name == "Pirates"); if (existing != null) @@ -2460,7 +2451,7 @@ public static class Program // unless passed "apply". public static int ConsumablesFirstSetCatalog(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var designNames = new[] { "Thruster Overdrive", "Coolant Vent" }; var already = designNames.Count(name => db.Cache.GetAll().Any(c => c.Name == name)); if (already == designNames.Length) @@ -2722,7 +2713,7 @@ public static class Program // shipped product text ending in the authoring note loses it. Dry run unless passed "apply". public static int GenericDesigns(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var designs = db.Cache.GetAll().ToArray(); var products = db.Cache.GetAll().ToArray(); string MakerOf(FactionProductData product) => db.Cache.Get(product.Manufacturer)?.ShortName; @@ -2827,7 +2818,7 @@ public static class Program // unless passed "apply". public static int LaunchSuppressorCatalog(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); var designNames = new[] { "Launch Suppressor", "Launch Baffle" }; var template = db.Cache.GetAll().Single(g => g.Name == "Targeting Computer"); @@ -2961,7 +2952,7 @@ public static class Program // 1x1 tool. Dry run unless passed "apply"; a catalog that is neither untouched nor fully authored is refused. public static int InspectionScannerCatalog(bool apply, string root = null) { - var db = AetherDb.Open(catalogWritable: apply, root: root); + var db = AetherDb.OpenShipped(catalogWritable: apply, root: root); const string designName = "Inspection Scanner"; const string scanArray = "scan array"; var template = db.Cache.GetAll().Single(g => g.Name == "Targeting Computer"); diff --git a/tools/AetherDb/ShipAuthoringCommands.cs b/tools/AetherDb/ShipAuthoringCommands.cs index 4d7aff2e6..cc947be96 100644 --- a/tools/AetherDb/ShipAuthoringCommands.cs +++ b/tools/AetherDb/ShipAuthoringCommands.cs @@ -223,7 +223,7 @@ public static class ShipAuthoringCommands if (judged == "records and model") ShipModCatalog.Bind(hull, ship, products, Path.GetDirectoryName(full), full); // Shipped file alone, on purpose: a package is judged against the shipped catalog it will be composed over, never against itself. // Compose's verdict on a package's bins and its offered hull's schematic; the author sees it here, before compose. - using var catalog = products.Length > 0 || hull.HullType == HullType.Station ? AetherDb.Open().Cache : null; + using var catalog = products.Length > 0 || hull.HullType == HullType.Station ? AetherDb.OpenShipped().Cache : null; if (ShipModCatalog.MarketFault(catalog, ship, products) is { } fault) throw new InvalidOperationException(fault); // A station package names a kind the shipped catalog holds (the rule Compose applies), so Package refuses it before compose does. if (hull.HullType == HullType.Station && StationKinds.HullKindFault(catalog, hull) is { } kindFault) @@ -235,7 +235,7 @@ public static class ShipAuthoringCommands internal static (CultRecordKey Key, string Name) ShippedFaction(string text) { // Shipped file alone, on purpose: this resolves a shipped faction, the one a package names by key. - using var catalog = AetherDb.Open().Cache; + using var catalog = AetherDb.OpenShipped().Cache; var matches = catalog.GetAll() .Where(faction => string.Equals(faction.Name, text, StringComparison.Ordinal) || string.Equals(faction.ShortName, text, StringComparison.Ordinal) || @@ -249,7 +249,7 @@ public static class ShipAuthoringCommands private static HullData ShippedHull(string name, params HullType[] allowed) { // Shipped file alone, on purpose: --like copies a shipped hull, not a package's. - using var catalog = AetherDb.Open().Cache; + using var catalog = AetherDb.OpenShipped().Cache; var hull = catalog.GetAll().FirstOrDefault(candidate => candidate.Name == name) ?? throw new InvalidOperationException($"--like: the shipped catalog has no hull named '{name}'."); if (!allowed.Contains(hull.HullType)) diff --git a/tools/AetherDb/ShipAuthoringPush.cs b/tools/AetherDb/ShipAuthoringPush.cs index b43ced165..d734d224e 100644 --- a/tools/AetherDb/ShipAuthoringPush.cs +++ b/tools/AetherDb/ShipAuthoringPush.cs @@ -362,7 +362,7 @@ public static class ShipAuthoringPush // kindless draft that stays kindless is not, so it still takes stats and price (and needs no catalog). if (derived.Kind.IsSet() || held.Kind.IsSet()) // Shipped file alone, on purpose: a station kind is the shipped catalog's, the rule Compose applies to a package. - using (var catalog = AetherDb.Open().Cache) + using (var catalog = AetherDb.OpenShipped().Cache) if (StationKinds.HullKindFault(catalog, derived) is { } fault) throw new InvalidOperationException($"{shipId}: {fault}"); FlatDiff(lines, key, HullFields(held), HullFields(derived)); }