fix(start): unsaved settings let go rather than started without, a failed save starts nothing

- the second answer discards the edits (as "Restore" does): kept, the starter would write
  them when it closes, with auto-close while the simulator reads the file
- a save that fails is said and the simulator is not started
- settings read again from a file changed outside leave the page with no edit of its own
- a closed tape window lets go of the file it read last, shown or not
This commit is contained in:
maj00r
2026-11-16 00:16:13 +01:00
parent b63ba8fe2e
commit 5b43e29f9e
8 changed files with 39 additions and 17 deletions

View File

@@ -610,16 +610,26 @@ public partial class MainWindow : Window
App.Loc["StartNoStaffTitle"], MessageBoxButtons.YesNo))
return;
// edits on the settings page not saved: said before they go to the simulator, or not
// edits on the settings page not saved: saved, or let go - kept, the starter would write them when it
// closes, perhaps while the simulator reads the file
if (saveSettings && SettingsView.HasUnsavedChanges)
{
var save = await MessageBox.Choose(this, App.Loc["StartUnsavedMessage"], App.Loc["UnsavedChanges"],
App.Loc["StartUnsavedSave"], App.Loc["StartUnsavedWithout"]);
if (save is null)
return;
if (save == true)
if (save == false)
SettingsView.DiscardChanges();
else
{
SettingsView.Save();
saveSettings = save == true;
if (AppServices.Current.SettingsStore.LastSaveFailed)
{
await MessageBox.Show(this, App.Loc["SettingsNotSaved"], App.Loc["UnsavedChanges"],
MessageBoxButtons.Ok);
return;
}
}
}
LoadingScreen.Prepare(trainset?.Logo, Path.GetFileNameWithoutExtension(scenery.Path));

View File

@@ -316,7 +316,13 @@ public partial class Settings : UserControl, ISettingsCapture
SelectExeCb.SelectedIndex = index;
}
public void ReloadFromSettings() => ApplyToUi();
/// <summary>The settings read again from the file: the page shows them, no edit of its own left.</summary>
public void ReloadFromSettings()
{
ApplyToUi();
_dirty = false;
UpdateSaveState();
}
/// <summary>
/// True while a cab-control binding is waiting for a keypress. The window's own
@@ -1145,7 +1151,10 @@ public partial class Settings : UserControl, ISettingsCapture
ThumbnailSizeChanged?.Invoke();
}
private void ResetButton_OnClick(object? sender, RoutedEventArgs e)
private void ResetButton_OnClick(object? sender, RoutedEventArgs e) => DiscardChanges();
/// <summary>The edits not saved let go, the page and the keys as the files have them: "Przywróć".</summary>
public void DiscardChanges()
{
AppServices.Current.SettingsStore.Load();
ApplyToUi();

View File

@@ -75,6 +75,8 @@ public sealed class HaslerTapeWindow : Window
private bool _looking;
// closed: a read already under way when it closed is let go, not kept followed
private bool _closed;
// the file read last, kept by the tapes to be followed even once another is picked or none is shown
private string? _read;
/// <summary>A setting went on from here; the settings page's boxes have to follow it.</summary>
public event Action? LogEnabled;
@@ -230,8 +232,8 @@ public sealed class HaslerTapeWindow : Window
{
_closed = true;
_timer.Stop();
if (_shown is { } shown)
_tapes.Forget(shown.Path);
if (_read is { } read)
_tapes.Forget(read);
};
}
@@ -646,6 +648,7 @@ public sealed class HaslerTapeWindow : Window
{
// the same tape grown, as the simulator writes it: only what was added is read
bool follow = file.Path == _shown?.Path && file.Size >= _shown.Size;
_read = file.Path;
var tape = await Task.Run(() => _tapes.Load(file, follow));
if (_closed)
{

View File

@@ -632,9 +632,9 @@
<String key="WarehouseAppend">Připojit soupravu ze skladu</String>
<String key="WarehouseImportFile">Přidat soupravy ze souboru...</String>
<String key="StartWithoutSaving">Spustit bez uložení nastavení</String>
<String key="StartUnsavedMessage">Nastavení obsahuje neuložené změny. Simulátor se s nimi spustí, jen pokud budou uloženy.</String>
<String key="StartUnsavedMessage">Nastavení obsahuje neuložené změny. Uložit je před spuštěním simulátoru?</String>
<String key="StartUnsavedSave">Uložit a spustit</String>
<String key="StartUnsavedWithout">Spustit bez uložení</String>
<String key="StartUnsavedWithout">Zahodit změny a spustit</String>
<String key="StartMore">Další způsoby spuštění</String>
<String key="StartFreeFly">Spustit bez vozidla</String>
<String key="StartEditorShort">Editor scenérie</String>

View File

@@ -658,9 +658,9 @@
<String key="WarehouseAppend">Append warehouse consist</String>
<String key="WarehouseImportFile">Add consists from file...</String>
<String key="StartWithoutSaving">Start without saving settings</String>
<String key="StartUnsavedMessage">The settings have unsaved changes. The simulator starts with them only if they are saved.</String>
<String key="StartUnsavedMessage">The settings have unsaved changes. Save them before starting the simulator?</String>
<String key="StartUnsavedSave">Save and start</String>
<String key="StartUnsavedWithout">Start without saving</String>
<String key="StartUnsavedWithout">Discard changes and start</String>
<String key="StartMore">More ways to start</String>
<String key="StartFreeFly">Start with no vehicle</String>
<String key="StartEditorShort">Scenery editor</String>

View File

@@ -632,9 +632,9 @@
<String key="WarehouseAppend">Raktári szerelvény hozzáfűzése</String>
<String key="WarehouseImportFile">Szerelvények hozzáadása fájlból...</String>
<String key="StartWithoutSaving">Indítás a beállítások mentése nélkül</String>
<String key="StartUnsavedMessage">A beállításokban nem mentett módosítások vannak. A szimulátor csak akkor indul velük, ha mentve lesznek.</String>
<String key="StartUnsavedMessage">A beállításokban nem mentett módosítások vannak. Menti őket a szimulátor indítása előtt?</String>
<String key="StartUnsavedSave">Mentés és indítás</String>
<String key="StartUnsavedWithout">Indítás mentés nélkül</String>
<String key="StartUnsavedWithout">Módosítások elvetése és indítás</String>
<String key="StartMore">További indítási módok</String>
<String key="StartFreeFly">Indítás jármű nélkül</String>
<String key="StartEditorShort">Pályaszerkesztő</String>

View File

@@ -658,9 +658,9 @@
<String key="WarehouseAppend">Dołącz skład z magazynu</String>
<String key="WarehouseImportFile">Dodaj składy z pliku...</String>
<String key="StartWithoutSaving">Uruchom bez zapisu ustawień</String>
<String key="StartUnsavedMessage">Ustawienia mają niezapisane zmiany. Symulator uruchomi się z nimi tylko wtedy, gdy zostaną zapisane.</String>
<String key="StartUnsavedMessage">Ustawienia mają niezapisane zmiany. Zapisać je przed uruchomieniem symulatora?</String>
<String key="StartUnsavedSave">Zapisz i uruchom</String>
<String key="StartUnsavedWithout">Uruchom bez zapisu</String>
<String key="StartUnsavedWithout">Odrzuć zmiany i uruchom</String>
<String key="StartMore">Inne sposoby uruchomienia</String>
<String key="StartFreeFly">Uruchom bez pojazdu</String>
<String key="StartEditorShort">Edytor scenerii</String>

View File

@@ -632,9 +632,9 @@
<String key="WarehouseAppend">Присоединить состав со склада</String>
<String key="WarehouseImportFile">Добавить составы из файла...</String>
<String key="StartWithoutSaving">Запустить без сохранения настроек</String>
<String key="StartUnsavedMessage">В настройках есть несохранённые изменения. Симулятор запустится с ними, только если их сохранить.</String>
<String key="StartUnsavedMessage">В настройках есть несохранённые изменения. Сохранить их перед запуском симулятора?</String>
<String key="StartUnsavedSave">Сохранить и запустить</String>
<String key="StartUnsavedWithout">Запустить без сохранения</String>
<String key="StartUnsavedWithout">Отменить изменения и запустить</String>
<String key="StartMore">Другие способы запуска</String>
<String key="StartFreeFly">Запустить без транспорта</String>
<String key="StartEditorShort">Редактор сценария</String>