2026-09-11 23:23:20 +02:00
using System ;
using System.IO ;
2026-11-27 17:13:16 +01:00
using System.Linq ;
Rewrite AetherDb over AetheriaStores and CultRecordRef
Cut 8b. AetherDb.Open composes GameData/Aetheria.cc through
AetheriaStores.Open, read-only unless clear-boss-hulls runs with apply;
save attaches GameData/run.cc when present and reads the SavedGame global.
- census, factions, station-fit, hardpoint-fit, loadout, settings,
settings-dump and clear-boss-hulls read references through the null-safe
Get(ref) and compare identity by record key (RefOf, from TryGetHandle).
Their output formats are unchanged so Cut 9 can compare them with the
Cut 0 captures.
- clear-boss-hulls lands every cleared faction in one Commit.
- The help line lists every command.
- Deleted: doctor, migrate-products, AetherDb.Save(), and
OpenWithNameFiles. The last was Cut 9's delete, but it needs the removed
multi-file store, and NameFile now routes to the catalog.
- FindRoot looks for Aetheria.Shared.csproj; AetherDB.msgpack leaves in
Cut 9.
It compiles. It cannot run until Cut 9 writes Aetheria.cc, so the pre-cut
captures do not apply to this cut.
Builds: Aetheria.Shared, AetherDb.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:05:14 +02:00
using GameCult.Caching ;
2026-09-11 23:23:20 +02:00
AetherDb: one owner of the catalog the game boots (AetherDb.ComposeBooted); every read tool opens it and throws on an excluded package
The AetherDb constructor, LoadoutCommitCommand and EconomyLoop each composed the packages in their own way; census, station-fit,
loadout, factions, weapon-ammo, save and the economy report/balance opened the shipped file alone and answered for a catalog the game
does not boot. Apply paths, dry runs, catalog resave, economy prices and the ship-authoring shipped lookups keep the shipped file alone,
each named at its open site. Pinned by BootedCatalogReadToolsTests.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 11:55:28 +01:00
// Opens the catalog through AetheriaStores, the game's own store composition: OpenBooted for a read tool (the catalog the game boots),
2026-11-28 12:35:42 +01:00
// 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
2026-10-23 01:21:04 +02:00
// catalog: it is named to warn (stderr by default) and the commands that repair it stay reachable.
2026-10-23 01:26:00 +02:00
public sealed class AetherDb : IDisposable
2026-09-11 23:23:20 +02:00
{
public string Root { get ; }
public CultCache Cache { get ; }
2026-11-27 17:13:16 +01:00
// The compose directory withMods made, owned by this instance: the derived catalog is read from it until Dispose.
private readonly string _composed ;
2026-10-23 01:26:00 +02:00
2026-11-27 17:13:16 +01:00
public void Dispose ( )
{
Cache . Dispose ( ) ;
if ( _composed ! = null ) try { Directory . Delete ( _composed , true ) ; } catch ( IOException ) { }
}
AetherDb: one owner of the catalog the game boots (AetherDb.ComposeBooted); every read tool opens it and throws on an excluded package
The AetherDb constructor, LoadoutCommitCommand and EconomyLoop each composed the packages in their own way; census, station-fit,
loadout, factions, weapon-ammo, save and the economy report/balance opened the shipped file alone and answered for a catalog the game
does not boot. Apply paths, dry runs, catalog resave, economy prices and the ship-authoring shipped lookups keep the shipped file alone,
each named at its open site. Pinned by BootedCatalogReadToolsTests.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 11:55:28 +01:00
private AetherDb ( string root , bool booted , bool withRun , Action < string > warn , bool catalogWritable )
2026-09-11 23:23:20 +02:00
{
Root = root ;
var gameData = Path . Combine ( root , "GameData" ) ;
2026-11-27 17:13:16 +01:00
var catalog = Path . Combine ( gameData , "Aetheria.cc" ) ;
AetherDb: one owner of the catalog the game boots (AetherDb.ComposeBooted); every read tool opens it and throws on an excluded package
The AetherDb constructor, LoadoutCommitCommand and EconomyLoop each composed the packages in their own way; census, station-fit,
loadout, factions, weapon-ammo, save and the economy report/balance opened the shipped file alone and answered for a catalog the game
does not boot. Apply paths, dry runs, catalog resave, economy prices and the ship-authoring shipped lookups keep the shipped file alone,
each named at its open site. Pinned by BootedCatalogReadToolsTests.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 11:55:28 +01:00
if ( booted )
2026-11-27 17:13:16 +01:00
{
AetherDb: one owner of the catalog the game boots (AetherDb.ComposeBooted); every read tool opens it and throws on an excluded package
The AetherDb constructor, LoadoutCommitCommand and EconomyLoop each composed the packages in their own way; census, station-fit,
loadout, factions, weapon-ammo, save and the economy report/balance opened the shipped file alone and answered for a catalog the game
does not boot. Apply paths, dry runs, catalog resave, economy prices and the ship-authoring shipped lookups keep the shipped file alone,
each named at its open site. Pinned by BootedCatalogReadToolsTests.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 11:55:28 +01:00
// Derived and read-only, so a write through it would land in a temp file, never in Aetheria.cc: a write opens the shipped file alone.
2026-11-27 17:13:16 +01:00
_composed = Directory . CreateDirectory ( Path . Combine ( Path . GetTempPath ( ) , "aetherdb-mods-" + Guid . NewGuid ( ) . ToString ( "N" ) ) ) . FullName ;
AetherDb: one owner of the catalog the game boots (AetherDb.ComposeBooted); every read tool opens it and throws on an excluded package
The AetherDb constructor, LoadoutCommitCommand and EconomyLoop each composed the packages in their own way; census, station-fit,
loadout, factions, weapon-ammo, save and the economy report/balance opened the shipped file alone and answered for a catalog the game
does not boot. Apply paths, dry runs, catalog resave, economy prices and the ship-authoring shipped lookups keep the shipped file alone,
each named at its open site. Pinned by BootedCatalogReadToolsTests.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 11:55:28 +01:00
try { catalog = ComposeBooted ( root , _composed ) ; }
2026-11-27 17:13:16 +01:00
catch { try { Directory . Delete ( _composed , true ) ; } catch ( IOException ) { } throw ; }
}
try
{
Cache = AetheriaStores . Open (
catalog ,
runPath : withRun ? Path . Combine ( gameData , "run.cc" ) : null ,
catalogWritable : catalogWritable ,
kindlessStation : warn ? ? Console . Error . WriteLine ) ;
}
catch { if ( _composed ! = null ) try { Directory . Delete ( _composed , true ) ; } catch ( IOException ) { } throw ; }
2026-09-11 23:23:20 +02:00
}
AetherDb: one owner of the catalog the game boots (AetherDb.ComposeBooted); every read tool opens it and throws on an excluded package
The AetherDb constructor, LoadoutCommitCommand and EconomyLoop each composed the packages in their own way; census, station-fit,
loadout, factions, weapon-ammo, save and the economy report/balance opened the shipped file alone and answered for a catalog the game
does not boot. Apply paths, dry runs, catalog resave, economy prices and the ship-authoring shipped lookups keep the shipped file alone,
each named at its open site. Pinned by BootedCatalogReadToolsTests.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 11:55:28 +01:00
// The one owner of "the catalog the game boots": the first-party packages in GameData/Mods composed (ShipModCatalog.ResolveCatalog)
// over a scratch copy of GameData/Aetheria.cc, inside the caller's scratch directory, which the caller owns and removes. Returns
// the path of the composed catalog to open read-only; the shipped file is never written. The game skips a broken package so a
// player still boots; a tool reading the catalog does not, so a package left out throws, naming it.
public static string ComposeBooted ( string root , string scratch )
{
var copy = Path . Combine ( scratch , "Aetheria.cc" ) ;
File . Copy ( Path . Combine ( root , "GameData" , "Aetheria.cc" ) , copy ) ;
new FileInfo ( copy ) . IsReadOnly = false ;
var ( composed , excluded ) = ShipModCatalog . ResolveCatalog ( copy , Path . Combine ( scratch , "derived.cc" ) , Path . Combine ( root , "GameData" , "Mods" ) ) ;
if ( excluded . Length > 0 )
throw new InvalidOperationException ( "First-party packages were excluded from the catalog: " +
string . Join ( "; " , excluded . Select ( entry = > entry . Package + ": " + entry . Reason ) ) ) ;
return composed ;
}
// 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.
2026-11-28 12:35:42 +01:00
public static AetherDb OpenShipped ( bool catalogWritable = false , bool withRun = false , string root = null , Action < string > warn = null ) = >
AetherDb: one owner of the catalog the game boots (AetherDb.ComposeBooted); every read tool opens it and throws on an excluded package
The AetherDb constructor, LoadoutCommitCommand and EconomyLoop each composed the packages in their own way; census, station-fit,
loadout, factions, weapon-ammo, save and the economy report/balance opened the shipped file alone and answered for a catalog the game
does not boot. Apply paths, dry runs, catalog resave, economy prices and the ship-authoring shipped lookups keep the shipped file alone,
each named at its open site. Pinned by BootedCatalogReadToolsTests.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 11:55:28 +01:00
new AetherDb ( root ? ? FindRoot ( ) , false , withRun , warn , catalogWritable ) ;
// The catalog the game boots (see ComposeBooted), read-only: every read tool opens this.
public static AetherDb OpenBooted ( bool withRun = false , string root = null , Action < string > warn = null ) = >
new AetherDb ( root ? ? FindRoot ( ) , true , withRun , warn , false ) ;
Clear dangling boss hull links, and stop the tool writing on read
Eight factions pointed at one boss hull GUID that no longer resolves,
shared wreckage from the database loss. PlaceFactionsMain gives a boss zone
to every faction carrying a BossHull, so each dangling link claimed a
chokepoint that could never spawn a boss.
AetherDb.Open no longer registers the name file store. CultCache subscribes
Add to a store EntryAdded, MultiFileBackingStore.PullAll re-emits what it
loads, and Add pushes to that type store, whose Push writes a file: opening
the cache rewrote all twelve name files, 4.4 MB, on every command. They were
byte identical, and it only surfaced as an error because Unity had one of
them memory mapped. Name files now load only on request, and the scope doc
records the underlying smell.
Adds commands: factions, clear-boss-hulls, save, loadout (runs the real
LoadoutGenerator against every hull), hardpoint-fit.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 02:05:33 +02:00
Rewrite AetherDb over AetheriaStores and CultRecordRef
Cut 8b. AetherDb.Open composes GameData/Aetheria.cc through
AetheriaStores.Open, read-only unless clear-boss-hulls runs with apply;
save attaches GameData/run.cc when present and reads the SavedGame global.
- census, factions, station-fit, hardpoint-fit, loadout, settings,
settings-dump and clear-boss-hulls read references through the null-safe
Get(ref) and compare identity by record key (RefOf, from TryGetHandle).
Their output formats are unchanged so Cut 9 can compare them with the
Cut 0 captures.
- clear-boss-hulls lands every cleared faction in one Commit.
- The help line lists every command.
- Deleted: doctor, migrate-products, AetherDb.Save(), and
OpenWithNameFiles. The last was Cut 9's delete, but it needs the removed
multi-file store, and NameFile now routes to the catalog.
- FindRoot looks for Aetheria.Shared.csproj; AetherDB.msgpack leaves in
Cut 9.
It compiles. It cannot run until Cut 9 writes Aetheria.cc, so the pre-cut
captures do not apply to this cut.
Builds: Aetheria.Shared, AetherDb.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:05:14 +02:00
public static string FindRoot ( )
2026-09-11 23:23:20 +02:00
{
for ( var dir = new DirectoryInfo ( Environment . CurrentDirectory ) ; dir ! = null ; dir = dir . Parent )
2026-10-10 06:53:03 +02:00
if ( File . Exists ( Path . Combine ( dir . FullName , "GameData" , "Aetheria.cc" ) ) )
2026-09-11 23:23:20 +02:00
return dir . FullName ;
2026-10-10 06:53:03 +02:00
throw new DirectoryNotFoundException ( "Run from a folder whose GameData holds Aetheria.cc." ) ;
2026-09-11 23:23:20 +02:00
}
}