feat(sceneries): a release clears the .sbt files once, and a scenery's menu deletes its own

The simulator makes a scenery's .sbt on its first load and never checks it
against the text again, so an older simulator's file, or one made before a
scenery update, keeps showing the old terrain.

- CleanupGeneration, raised by a release, clears the .sbt files once per
  installation on the first start, ahead of the scenery list. A file goes only
  while its scenery's terrain files (*_ter.scm) are all there and no terrain
  directive brings terrain from elsewhere; an .sbt standing in for missing
  terrain stays, and the log says what is missing. Which cleanup each
  installation had is kept in sbt-cleanup.txt in the user's folder.
- "Delete SBT" in the scenery list's menu does the same for one scenery,
  asking first and refusing where nothing could make the file again.
- The .sbt is among the files a scenery is watched by, so one made or removed
  reaches the list without a reload.
This commit is contained in:
maj00r
2026-11-17 02:15:45 +01:00
parent c07ed2fb4d
commit 797e2e70a7
14 changed files with 504 additions and 1 deletions

View File

@@ -165,6 +165,39 @@ public partial class Scenarios : UserControl
favoriteMenuItem.Header = App.Loc[scenery is not null && AppServices.Current.Favorites.Contains(scenery)
? "FavoriteRemove"
: "FavoriteAdd"];
deleteSbtMenuItem.IsEnabled = scenery is not null
&& !AppServices.Current.State.SimulatorRunning
&& AppServices.Current.BinaryTerrain.Of(scenery.Path) is not null;
}
// Only a file the simulator can make again from the scenery's text goes: one
// standing in for terrain files the installation lacks takes the terrain with it.
private async void DeleteSbt_OnClick(object? sender, RoutedEventArgs e)
{
if (SelectedScenery is not { } scenery || TopLevel.GetTopLevel(this) is not Window owner)
return;
var sbt = AppServices.Current.BinaryTerrain;
if (sbt.Of(scenery.Path) is not { } file)
return;
string name = Path.GetFileName(file);
string title = App.Loc["DeleteSbt"];
if (await Task.Run(() => sbt.MissingOriginal(scenery.Path)) is { } missing)
{
await MessageBox.Show(owner, string.Format(App.Loc["DeleteSbtNoOriginal"], name, missing), title,
MessageBoxButtons.Ok);
return;
}
long megabytes = AppServices.Current.Files.GetFileSize(file) / (1024 * 1024);
if (!await MessageBox.Show(owner, string.Format(App.Loc["DeleteSbtConfirm"], name, megabytes), title,
MessageBoxButtons.YesNo))
return;
// Gone, the scenery follows by the watch on its files, as it would after any other change.
if (!await Task.Run(() => sbt.Delete(scenery.Path)))
await MessageBox.Show(owner, string.Format(App.Loc["DeleteSbtFailed"], name), title, MessageBoxButtons.Ok);
}
private void ToggleFavorite_OnClick(object? sender, RoutedEventArgs e)