mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-18 06:25:59 +01:00
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:
157
StarterNG.Tests/BinaryTerrainFilesTests.cs
Normal file
157
StarterNG.Tests/BinaryTerrainFilesTests.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using StarterNG.Infrastructure.Adapters;
|
||||
using StarterNG.Infrastructure.Sceneries;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class BinaryTerrainFilesTests
|
||||
{
|
||||
private const string Record = "user/sbt-cleanup.txt";
|
||||
|
||||
private static BinaryTerrainFiles Build(InMemoryFileSystem files, string root = "game") =>
|
||||
new(files, new GamePaths(root), TestLog.Over(files), Record);
|
||||
|
||||
private static string Scenery(string name) => $"game/scenery/{name}";
|
||||
|
||||
[Fact]
|
||||
public void An_sbt_whose_terrain_files_are_all_there_goes()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithLegacyFile(Scenery("kato.scn"), "include kato/kato_ter.scm end\nFirstInit\n")
|
||||
.WithFile(Scenery("kato/kato_ter.scm"), "node")
|
||||
.WithFile(Scenery("kato.sbt"), "EU07SBT2");
|
||||
|
||||
var cleanup = Build(files).CleanUpOnce(1)!;
|
||||
|
||||
Assert.Equal("kato.sbt", Assert.Single(cleanup.Deleted));
|
||||
Assert.False(files.FileExists(Scenery("kato.sbt")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_sbt_standing_in_for_missing_terrain_files_stays()
|
||||
{
|
||||
var files = new InMemoryFileSystem(caseSensitive: true)
|
||||
.WithLegacyFile(Scenery("Lk2_Sandbox.scn"), "include nmt/nmt100_mazowieckie_ter.scm end\nFirstInit\n")
|
||||
.WithFile(Scenery("lk2_sandbox.sbt"), "EU07SBT2");
|
||||
|
||||
var cleanup = Build(files).CleanUpOnce(1)!;
|
||||
|
||||
Assert.Empty(cleanup.Deleted);
|
||||
Assert.Equal(("lk2_sandbox.sbt", "nmt/nmt100_mazowieckie_ter.scm"), Assert.Single(cleanup.Kept));
|
||||
Assert.True(files.FileExists(Scenery("lk2_sandbox.sbt")));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Terrain_included_through_another_file_is_looked_for_too(bool present)
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithLegacyFile(Scenery("td.scn"), "include td/base.inc end\nFirstInit\n")
|
||||
.WithLegacyFile(Scenery("td/base.inc"), "include td/td_ter.scm 1 2 end\n")
|
||||
.WithFile(Scenery("td.sbt"), "EU07SBT2");
|
||||
if (present)
|
||||
files.WithFile(Scenery("td/td_ter.scm"), "node");
|
||||
|
||||
var cleanup = Build(files).CleanUpOnce(1)!;
|
||||
|
||||
Assert.Equal(present, cleanup.Deleted.Count == 1);
|
||||
Assert.Equal(present, !files.FileExists(Scenery("td.sbt")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_missing_include_other_than_terrain_does_not_keep_the_sbt()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithLegacyFile(Scenery("tomaszewo.scn"), "include tomaszewo/modele.scm end\nFirstInit\n")
|
||||
.WithLegacyFile(Scenery("tomaszewo/modele.scm"),
|
||||
"include;przejazdy_kombud\\1t12m_0rog_2zar_1x_1dzw.inc;p_czernica15;0;0;0;end\n")
|
||||
.WithFile(Scenery("tomaszewo.sbt"), "EU07SBT2");
|
||||
|
||||
Assert.Single(Build(files).CleanUpOnce(1)!.Deleted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_include_commented_out_needs_no_file()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithLegacyFile(Scenery("td.scn"), "// include gone_ter.scm end\n/* include gone.inc end */\nFirstInit\n")
|
||||
.WithFile(Scenery("td.sbt"), "EU07SBT2");
|
||||
|
||||
Assert.Single(Build(files).CleanUpOnce(1)!.Deleted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_scenery_bringing_terrain_by_a_terrain_directive_keeps_its_sbt()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithLegacyFile(Scenery("td.scn"), "terrain td.sbt endterrain\nFirstInit\n")
|
||||
.WithFile(Scenery("td.sbt"), "EU07SBT2");
|
||||
|
||||
Assert.Equal("td.sbt", Assert.Single(Build(files).CleanUpOnce(1)!.Kept).File);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_sbt_of_no_scenery_stays()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithFile(Scenery("old.sbt"), "EU07SBT2");
|
||||
|
||||
Assert.Equal(("old.sbt", "old.scn"), Assert.Single(Build(files).CleanUpOnce(1)!.Kept));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Each_generation_clears_an_installation_once()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithLegacyFile(Scenery("td.scn"), "FirstInit\n")
|
||||
.WithFile(Scenery("td.sbt"), "EU07SBT2");
|
||||
var sbt = Build(files);
|
||||
|
||||
Assert.NotNull(sbt.CleanUpOnce(1));
|
||||
files.WithFile(Scenery("td.sbt"), "EU07SBT2");
|
||||
|
||||
Assert.Null(sbt.CleanUpOnce(1));
|
||||
Assert.True(files.FileExists(Scenery("td.sbt")));
|
||||
|
||||
Assert.Single(sbt.CleanUpOnce(2)!.Deleted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generation_zero_clears_nothing()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithLegacyFile(Scenery("td.scn"), "FirstInit\n")
|
||||
.WithFile(Scenery("td.sbt"), "EU07SBT2");
|
||||
|
||||
Assert.Null(Build(files).CleanUpOnce(0));
|
||||
Assert.True(files.FileExists(Scenery("td.sbt")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Another_installation_has_a_cleanup_of_its_own()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithLegacyFile(Scenery("td.scn"), "FirstInit\n")
|
||||
.WithLegacyFile("other/scenery/td.scn", "FirstInit\n")
|
||||
.WithFile("other/scenery/td.sbt", "EU07SBT2");
|
||||
|
||||
Assert.NotNull(Build(files).CleanUpOnce(1));
|
||||
|
||||
Assert.Single(Build(files, "other").CleanUpOnce(1)!.Deleted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void One_scenery_s_sbt_is_found_whatever_its_case_and_deleted()
|
||||
{
|
||||
var files = new InMemoryFileSystem(caseSensitive: true)
|
||||
.WithLegacyFile(Scenery("Kato.scn"), "FirstInit\n")
|
||||
.WithFile(Scenery("kato.sbt"), "EU07SBT2");
|
||||
var sbt = Build(files);
|
||||
|
||||
Assert.Equal(Path.Combine("game", "scenery", "kato.sbt"), sbt.Of(Scenery("Kato.scn")));
|
||||
Assert.Null(sbt.MissingOriginal(Scenery("Kato.scn")));
|
||||
Assert.True(sbt.Delete(Scenery("Kato.scn")));
|
||||
Assert.Null(sbt.Of(Scenery("Kato.scn")));
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,26 @@ public class SceneryFileWatchTests
|
||||
Assert.Equal("Katowice Główne", change.Fresh!.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void An_sbt_made_or_removed_makes_the_scenery_read_anew(bool there)
|
||||
{
|
||||
string sbt = TestInstallation.At("scenery", "kato.sbt");
|
||||
var files = Folder();
|
||||
if (there)
|
||||
files.WithFile(sbt, "EU07SBT2");
|
||||
var (installation, watch, _) = Rig(files);
|
||||
|
||||
if (there)
|
||||
files.DeleteFile(sbt);
|
||||
else
|
||||
files.WithFile(sbt, "EU07SBT2");
|
||||
|
||||
var change = Assert.Single(watch.Look(installation.Library.Sceneries));
|
||||
Assert.Equal(!there, change.Fresh!.HasCompanionTimetable);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_include_that_changed_or_came_makes_the_scenery_read_anew()
|
||||
{
|
||||
|
||||
@@ -160,6 +160,9 @@ public partial class App : Avalonia.Application
|
||||
});
|
||||
});
|
||||
|
||||
// Ahead of the sceneries, so the list knows which still have their .sbt.
|
||||
try { AppServices.Current.BinaryTerrain.CleanUpOnce(); }
|
||||
catch (Exception ex) { Diagnostics.Log("sbt cleanup", ex); }
|
||||
AppServices.Current.Library.Load(progress);
|
||||
}).ContinueWith(load =>
|
||||
{
|
||||
|
||||
@@ -43,6 +43,7 @@ public sealed class AppServices
|
||||
paths.FromRoot("starter"),
|
||||
paths.FromRoot("lang")));
|
||||
Sceneries = new SceneryRepository(files, paths, log, new SceneryParser(clock, random));
|
||||
BinaryTerrain = new BinaryTerrainFiles(files, paths, log, settingsPaths.SbtCleanupPath());
|
||||
SceneryImages = new SceneryImageLocator(files);
|
||||
MiniTextures = new MiniTextureIndex(files, paths);
|
||||
|
||||
@@ -111,6 +112,8 @@ public sealed class AppServices
|
||||
|
||||
public SceneryFileWatch SceneryFiles { get; }
|
||||
|
||||
public BinaryTerrainFiles BinaryTerrain { get; }
|
||||
|
||||
public SceneryImageLocator SceneryImages { get; }
|
||||
|
||||
public IMiniTextureIndex MiniTextures { get; }
|
||||
|
||||
257
StarterNG/Infrastructure/Sceneries/BinaryTerrainFiles.cs
Normal file
257
StarterNG/Infrastructure/Sceneries/BinaryTerrainFiles.cs
Normal file
@@ -0,0 +1,257 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using StarterNG.Application.Abstractions;
|
||||
using StarterNG.Domain;
|
||||
using StarterNG.Domain.Sceneries;
|
||||
using StarterNG.Infrastructure.Adapters;
|
||||
|
||||
namespace StarterNG.Infrastructure.Sceneries;
|
||||
|
||||
/// <summary>
|
||||
/// The sceneries' binary terrain files (.sbt): the simulator writes one beside a
|
||||
/// scenery on its first load and from then on takes the terrain from it, passing
|
||||
/// the scenery's terrain includes (<c>*_ter.scm</c>) over. It never asks whether
|
||||
/// the text changed since, so a file made by an older simulator, or before the
|
||||
/// scenery was updated, keeps showing what was there then.
|
||||
/// <para>
|
||||
/// A file goes only when the scenery's text still holds what it was made of: some
|
||||
/// sceneries come with the .sbt in place of their terrain includes, and without it
|
||||
/// they would have no terrain at all.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class BinaryTerrainFiles
|
||||
{
|
||||
/// <summary>
|
||||
/// Raised by a release that wants the .sbt files made anew: each installation is
|
||||
/// cleared once for each value, on the first start of a starter carrying it.
|
||||
/// Zero clears nothing.
|
||||
/// </summary>
|
||||
public const int CleanupGeneration = 1;
|
||||
|
||||
private const string Extension = ".sbt";
|
||||
|
||||
// The simulator splits its text into words at spaces, tabs, line ends and semicolons.
|
||||
private static readonly Regex Word = new(@"[^\s;]+", RegexOptions.CultureInvariant);
|
||||
|
||||
private readonly IFileSystem _files;
|
||||
private readonly IGamePaths _paths;
|
||||
private readonly IDiagnosticsLog _log;
|
||||
private readonly string _recordPath;
|
||||
|
||||
/// <param name="recordPath">Where the cleanups done are noted, for each installation.</param>
|
||||
public BinaryTerrainFiles(IFileSystem files, IGamePaths paths, IDiagnosticsLog log, string recordPath)
|
||||
{
|
||||
_files = files;
|
||||
_paths = paths;
|
||||
_log = log;
|
||||
_recordPath = recordPath;
|
||||
}
|
||||
|
||||
/// <summary>The scenery's own .sbt as it is on disk, whatever the case of its letters; null when it has none.</summary>
|
||||
public string? Of(string sceneryPath)
|
||||
{
|
||||
string? file = new CaseInsensitivePaths(_files)
|
||||
.Resolve(_paths.Scenery, Path.GetFileNameWithoutExtension(sceneryPath) + Extension);
|
||||
return file is null ? null : Path.Combine(_paths.Scenery, file);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the simulator would miss to make the scenery's .sbt again - the first
|
||||
/// terrain file its text names and the installation lacks, or the terrain directive
|
||||
/// that brings terrain from elsewhere; null when the text holds it all.
|
||||
/// </summary>
|
||||
public string? MissingOriginal(string sceneryPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var names = new CaseInsensitivePaths(_files, keepListings: true);
|
||||
string? own = names.Resolve(_paths.Scenery, Path.GetFileName(sceneryPath));
|
||||
if (own is null)
|
||||
return Path.GetFileName(sceneryPath);
|
||||
|
||||
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var pending = new Stack<string>();
|
||||
pending.Push(own);
|
||||
while (pending.Count > 0)
|
||||
{
|
||||
string file = pending.Pop();
|
||||
if (!seen.Add(file))
|
||||
continue;
|
||||
|
||||
if (Scan(file, names, pending) is { } missing)
|
||||
return missing;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Log($"sbt/{Path.GetFileName(sceneryPath)}", ex);
|
||||
return Path.GetFileName(sceneryPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads one file of the scenery for its includes: the terrain ones have to be
|
||||
/// there, the others are read in turn. Terrain files are not opened - they are the
|
||||
/// largest of all and include nothing.
|
||||
/// </summary>
|
||||
private string? Scan(string file, CaseInsensitivePaths names, Stack<string> pending)
|
||||
{
|
||||
string text = LegacyText.Decode(_files.ReadAllBytes(Path.Combine(_paths.Scenery, file)));
|
||||
string code = SceneryCode.Mask(text, out _);
|
||||
|
||||
bool includeNext = false;
|
||||
for (var word = Word.Match(code); word.Success; word = word.NextMatch())
|
||||
{
|
||||
string token = word.Value;
|
||||
if (includeNext)
|
||||
{
|
||||
includeNext = false;
|
||||
bool terrain = SimulatorNames.Lower(token).Contains("_ter.scm");
|
||||
string? found = names.Resolve(_paths.Scenery, token);
|
||||
if (found is null && terrain)
|
||||
return token;
|
||||
// Any other file the simulator reads from the text, .sbt or not: missing,
|
||||
// it is missing either way, and the .sbt made again lacks nothing.
|
||||
if (found is not null && !terrain)
|
||||
pending.Push(found);
|
||||
}
|
||||
else if (token.Equals("include", StringComparison.OrdinalIgnoreCase))
|
||||
includeNext = true;
|
||||
else if (token.Equals("terrain", StringComparison.OrdinalIgnoreCase))
|
||||
return token;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Removes the scenery's .sbt; false when it has none or it could not go.</summary>
|
||||
public bool Delete(string sceneryPath)
|
||||
{
|
||||
if (Of(sceneryPath) is not { } file)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
_files.DeleteFile(file);
|
||||
_log.Log($"{file} removed, the simulator makes it again on the next load of the scenery");
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Log($"sbt/{Path.GetFileName(file)}", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the .sbt files the simulator can make again, once for each
|
||||
/// <paramref name="generation"/> on this installation; null when it was done
|
||||
/// already. A file that could not go leaves the cleanup to the next start.
|
||||
/// </summary>
|
||||
public BinaryTerrainCleanup? CleanUpOnce(int generation = CleanupGeneration)
|
||||
{
|
||||
if (generation <= 0 || !_files.DirectoryExists(_paths.Scenery))
|
||||
return null;
|
||||
|
||||
var record = ReadRecord();
|
||||
string installation = Installation();
|
||||
if (record.TryGetValue(installation, out int done) && done >= generation)
|
||||
return null;
|
||||
|
||||
var deleted = new List<string>();
|
||||
var kept = new List<(string File, string Reason)>();
|
||||
var failed = new List<string>();
|
||||
var names = new CaseInsensitivePaths(_files);
|
||||
|
||||
foreach (string sbt in _files.GetFiles(_paths.Scenery)
|
||||
.Where(f => Path.GetExtension(f).Equals(Extension, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
string name = Path.GetFileName(sbt);
|
||||
string? scenery = names.Resolve(_paths.Scenery, Path.GetFileNameWithoutExtension(sbt) + ".scn");
|
||||
string? missing = scenery is null ? Path.GetFileNameWithoutExtension(sbt) + ".scn" : MissingOriginal(scenery);
|
||||
if (missing is not null)
|
||||
{
|
||||
kept.Add((name, missing));
|
||||
_log.Log($"{name} kept: the scenery cannot be made without it, {missing} is missing");
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_files.DeleteFile(sbt);
|
||||
deleted.Add(name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
failed.Add(name);
|
||||
_log.Log($"sbt/{name}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (deleted.Count > 0)
|
||||
_log.Log($"Binary terrain files removed, the simulator makes them again: {string.Join(", ", deleted)}");
|
||||
|
||||
if (failed.Count == 0)
|
||||
{
|
||||
record[installation] = generation;
|
||||
WriteRecord(record);
|
||||
}
|
||||
|
||||
return new BinaryTerrainCleanup(deleted, kept, failed);
|
||||
}
|
||||
|
||||
private string Installation() =>
|
||||
Path.TrimEndingDirectorySeparator(Path.GetFullPath(_paths.Root));
|
||||
|
||||
private Dictionary<string, int> ReadRecord()
|
||||
{
|
||||
var record = new Dictionary<string, int>(
|
||||
_files.IgnoresCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal);
|
||||
try
|
||||
{
|
||||
if (!_files.FileExists(_recordPath))
|
||||
return record;
|
||||
|
||||
foreach (string line in _files.ReadAllLines(_recordPath))
|
||||
{
|
||||
int tab = line.IndexOf('\t');
|
||||
if (tab > 0 && int.TryParse(line[..tab], out int generation))
|
||||
record[line[(tab + 1)..]] = generation;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Log("sbt cleanup record", ex);
|
||||
}
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
private void WriteRecord(Dictionary<string, int> record)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Path.GetDirectoryName(_recordPath) is { Length: > 0 } folder)
|
||||
_files.CreateDirectory(folder);
|
||||
_files.WriteAllTextAtomic(_recordPath,
|
||||
string.Concat(record.Select(entry => $"{entry.Value}\t{entry.Key}\n")));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Log("sbt cleanup record", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <param name="Deleted">The files removed.</param>
|
||||
/// <param name="Kept">The files left, as nothing could make them again, each with what is missing.</param>
|
||||
/// <param name="Failed">The files that could not be removed.</param>
|
||||
public sealed record BinaryTerrainCleanup(
|
||||
IReadOnlyList<string> Deleted,
|
||||
IReadOnlyList<(string File, string Reason)> Kept,
|
||||
IReadOnlyList<string> Failed);
|
||||
@@ -79,7 +79,12 @@ public sealed class SceneryRepository : ISceneryRepository
|
||||
|
||||
// With its own .sbt the scenery's terrain comes from it, and the simulator
|
||||
// passes its terrain includes over without opening them.
|
||||
bool binaryTerrain = Opens(Path.GetFileNameWithoutExtension(path) + ".sbt");
|
||||
// Watched with the text: made by the simulator on a load, or removed, it changes the scenery too.
|
||||
string sbtName = Path.GetFileNameWithoutExtension(path) + ".sbt";
|
||||
string? sbt = ResolveInclude(sbtName);
|
||||
bool binaryTerrain = sbt is not null;
|
||||
string sbtPath = Path.Combine(_paths.Scenery, sbt ?? sbtName);
|
||||
sources[sbtPath] = FileStamp.Of(_files, sbtPath);
|
||||
bool OpensInclude(string name) =>
|
||||
Opens(name) || (binaryTerrain && SimulatorNames.Lower(name).Contains("_ter.scm"));
|
||||
|
||||
|
||||
@@ -53,6 +53,9 @@ public sealed class SettingsPaths
|
||||
/// <summary>The sceneries starred in the list.</summary>
|
||||
public string FavoritesPath() => Path.Combine(UserConfigDirectory(), "favorites.txt");
|
||||
|
||||
/// <summary>Which cleanup of the .sbt files each installation had.</summary>
|
||||
public string SbtCleanupPath() => Path.Combine(UserConfigDirectory(), "sbt-cleanup.txt");
|
||||
|
||||
public string UserConfigDirectory() =>
|
||||
Path.GetDirectoryName(UserConfigPath()) ?? _environment.BaseDirectory;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
Header="{Binding [ReloadSceneries], Source={x:Static starterNg:App.Loc}}" />
|
||||
<MenuItem Click="OpenSceneryDir_OnClick"
|
||||
Header="{Binding [OpenSceneryFolder], Source={x:Static starterNg:App.Loc}}" />
|
||||
<MenuItem Name="deleteSbtMenuItem" Click="DeleteSbt_OnClick"
|
||||
Header="{Binding [DeleteSbt], Source={x:Static starterNg:App.Loc}}" />
|
||||
</ContextMenu>
|
||||
</TreeView.ContextMenu>
|
||||
</TreeView>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -69,6 +69,10 @@
|
||||
<String key="FavoriteAdd">Přidat do oblíbených</String>
|
||||
<String key="FavoriteRemove">Odebrat z oblíbených</String>
|
||||
<String key="OpenSceneryFolder">Otevřít složku</String>
|
||||
<String key="DeleteSbt">Smazat SBT</String>
|
||||
<String key="DeleteSbtConfirm">Smazat {0} ({1} MB)? Simulátor jej znovu sestaví ze souborů scenérie při jejím dalším načtení, které potrvá déle.</String>
|
||||
<String key="DeleteSbtNoOriginal">Soubor {0} zůstává: není z čeho jej znovu sestavit, chybí {1}. Bez něj by scenérie přišla o terén.</String>
|
||||
<String key="DeleteSbtFailed">Soubor {0} nelze smazat. Možná jej používá simulátor, nebo je složka jen pro čtení.</String>
|
||||
<String key="OptionalIncludes">Volitelné prvky</String>
|
||||
<String key="OpenTextureFolder">Otevřít složku s texturami</String>
|
||||
<String key="CopyTextureName">Kopírovat název</String>
|
||||
|
||||
@@ -69,6 +69,10 @@
|
||||
<String key="FavoriteAdd">Add to favourites</String>
|
||||
<String key="FavoriteRemove">Remove from favourites</String>
|
||||
<String key="OpenSceneryFolder">Open folder</String>
|
||||
<String key="DeleteSbt">Delete SBT</String>
|
||||
<String key="DeleteSbtConfirm">Delete {0} ({1} MB)? The simulator makes it again from the scenery files on its next load, which takes longer.</String>
|
||||
<String key="DeleteSbtNoOriginal">{0} stays: nothing is there to make it again, {1} is missing. Without it the scenery would lose its terrain.</String>
|
||||
<String key="DeleteSbtFailed">Could not delete {0}. The simulator may be using it, or the folder is read-only.</String>
|
||||
<String key="OptionalIncludes">Optional elements</String>
|
||||
<String key="OpenTextureFolder">Open texture folder</String>
|
||||
<String key="CopyTextureName">Copy name</String>
|
||||
|
||||
@@ -69,6 +69,10 @@
|
||||
<String key="FavoriteAdd">Hozzáadás a kedvencekhez</String>
|
||||
<String key="FavoriteRemove">Eltávolítás a kedvencek közül</String>
|
||||
<String key="OpenSceneryFolder">Mappa megnyitása</String>
|
||||
<String key="DeleteSbt">SBT törlése</String>
|
||||
<String key="DeleteSbtConfirm">Törlöd: {0} ({1} MB)? A szimulátor a színtér fájljaiból a következő betöltéskor újra elkészíti, ami tovább tart.</String>
|
||||
<String key="DeleteSbtNoOriginal">{0} megmarad: nincs miből újra elkészíteni, hiányzik: {1}. Nélküle a színtér elveszítené a terepet.</String>
|
||||
<String key="DeleteSbtFailed">Nem sikerült törölni: {0}. Lehet, hogy a szimulátor használja, vagy a mappa csak olvasható.</String>
|
||||
<String key="OptionalIncludes">Opcionális elemek</String>
|
||||
<String key="OpenTextureFolder">Textúramappa megnyitása</String>
|
||||
<String key="CopyTextureName">Név másolása</String>
|
||||
|
||||
@@ -69,6 +69,10 @@
|
||||
<String key="FavoriteAdd">Dodaj do ulubionych</String>
|
||||
<String key="FavoriteRemove">Usuń z ulubionych</String>
|
||||
<String key="OpenSceneryFolder">Otwórz folder</String>
|
||||
<String key="DeleteSbt">Usuń SBT</String>
|
||||
<String key="DeleteSbtConfirm">Usunąć {0} ({1} MB)? Symulator zbuduje go od nowa z plików scenerii przy jej następnym wczytaniu, które potrwa dłużej.</String>
|
||||
<String key="DeleteSbtNoOriginal">Plik {0} zostaje: sceneria nie ma z czego go odbudować, brakuje {1}. Bez niego straciłaby teren.</String>
|
||||
<String key="DeleteSbtFailed">Nie udało się usunąć {0}. Może używa go symulator albo folder jest tylko do odczytu.</String>
|
||||
<String key="OptionalIncludes">Elementy opcjonalne</String>
|
||||
<String key="OpenTextureFolder">Otwórz folder tekstury</String>
|
||||
<String key="CopyTextureName">Kopiuj nazwę</String>
|
||||
|
||||
@@ -69,6 +69,10 @@
|
||||
<String key="FavoriteAdd">Добавить в избранное</String>
|
||||
<String key="FavoriteRemove">Удалить из избранного</String>
|
||||
<String key="OpenSceneryFolder">Открыть папку</String>
|
||||
<String key="DeleteSbt">Удалить SBT</String>
|
||||
<String key="DeleteSbtConfirm">Удалить {0} ({1} МБ)? Симулятор заново соберёт его из файлов сценария при следующей загрузке, которая займёт больше времени.</String>
|
||||
<String key="DeleteSbtNoOriginal">Файл {0} остаётся: его не из чего собрать заново, нет {1}. Без него сценарий лишится рельефа.</String>
|
||||
<String key="DeleteSbtFailed">Не удалось удалить {0}. Возможно, его использует симулятор или папка только для чтения.</String>
|
||||
<String key="OptionalIncludes">Дополнительные элементы</String>
|
||||
<String key="OpenTextureFolder">Открыть папку с текстурами</String>
|
||||
<String key="CopyTextureName">Копировать название</String>
|
||||
|
||||
Reference in New Issue
Block a user