mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-19 15:02:15 +01:00
fix(settings): a profile or an ini exported takes the page's edits in a copy, so discarding them still works
Saving a profile or exporting eu07.ini captured the page's edits into the settings held, so discarding them before a start showed them again and the start's save wrote them. The export writes a copy with the edits in; the settings held stay as saved.
This commit is contained in:
@@ -1274,6 +1274,22 @@ public class SettingsStoreTests
|
|||||||
Assert.Contains("physicslog.trains yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
|
Assert.Contains("physicslog.trains yes", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void A_profile_exported_from_a_pages_edits_leaves_the_settings_held_and_the_ini_alone()
|
||||||
|
{
|
||||||
|
var files = new InMemoryFileSystem().WithFile(UserIni, "fieldofview 45\n");
|
||||||
|
var store = WithHome(files).SettingsStore;
|
||||||
|
store.Load();
|
||||||
|
var edited = store.Settings.Copy();
|
||||||
|
edited.FieldOfView = 60;
|
||||||
|
|
||||||
|
Assert.True(store.ExportTo(Profile, edited));
|
||||||
|
|
||||||
|
Assert.Contains("fieldofview 60", files.ReadAllText(Profile, System.Text.Encoding.UTF8));
|
||||||
|
Assert.Equal(45, store.Settings.FieldOfView);
|
||||||
|
Assert.Contains("fieldofview 45", files.ReadAllText(UserIni, System.Text.Encoding.UTF8));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void A_missing_profile_leaves_the_settings_as_they_are()
|
public void A_missing_profile_leaves_the_settings_as_they_are()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -245,7 +245,8 @@ public sealed class SettingsStore
|
|||||||
/// Writes the settings as a complete eu07.ini somewhere else - this user's file
|
/// Writes the settings as a complete eu07.ini somewhere else - this user's file
|
||||||
/// with the settings applied - leaving the file itself and its state alone.
|
/// with the settings applied - leaving the file itself and its state alone.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ExportTo(string path)
|
/// <param name="settings">What to write, when not the settings held: a page's edits, still not taken in.</param>
|
||||||
|
public bool ExportTo(string path, SimulatorSettings? settings = null)
|
||||||
{
|
{
|
||||||
if (LoadFailed)
|
if (LoadFailed)
|
||||||
{
|
{
|
||||||
@@ -254,7 +255,7 @@ public sealed class SettingsStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
var copy = ConfigFile.Parse(_config.ToText());
|
var copy = ConfigFile.Parse(_config.ToText());
|
||||||
ApplyChanges(copy, Changes(Settings));
|
ApplyChanges(copy, Changes(settings ?? Settings));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -328,9 +328,8 @@ public partial class Settings
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// The edits on screen go into the export as they would into a save, but the
|
// The edits on screen go into the export as they would into a save, but the
|
||||||
// user's own eu07.ini is not written.
|
// user's own eu07.ini is not written, nor the settings held: the edits stay the page's, not saved.
|
||||||
CaptureInto(AppServices.Current.Settings);
|
if (!AppServices.Current.SettingsStore.ExportTo(path, Trial()))
|
||||||
if (!AppServices.Current.SettingsStore.ExportTo(path))
|
|
||||||
{
|
{
|
||||||
await MessageBox.Show(owner, string.Format(App.Loc["ExportIniFailed"], path), App.Loc["ExportIni"],
|
await MessageBox.Show(owner, string.Format(App.Loc["ExportIniFailed"], path), App.Loc["ExportIni"],
|
||||||
MessageBoxButtons.Ok);
|
MessageBoxButtons.Ok);
|
||||||
|
|||||||
@@ -235,9 +235,8 @@ public partial class Settings : UserControl, ISettingsCapture
|
|||||||
App.Loc["ProfileSaveAs"], MessageBoxButtons.YesNo))
|
App.Loc["ProfileSaveAs"], MessageBoxButtons.YesNo))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Written beside the user's own eu07.ini, which stays as it is.
|
// Written beside the user's own eu07.ini, which stays as it is; the edits stay the page's, not saved
|
||||||
CaptureInto(AppServices.Current.Settings);
|
bool saved = AppServices.Current.SettingsStore.ExportTo(path, Trial());
|
||||||
bool saved = AppServices.Current.SettingsStore.ExportTo(path);
|
|
||||||
PopulateProfileCombo();
|
PopulateProfileCombo();
|
||||||
int idx = FindComboIndexByContent(ProfileCb, Path.GetFileNameWithoutExtension(path));
|
int idx = FindComboIndexByContent(ProfileCb, Path.GetFileNameWithoutExtension(path));
|
||||||
if (idx >= 0) ProfileCb.SelectedIndex = idx;
|
if (idx >= 0) ProfileCb.SelectedIndex = idx;
|
||||||
|
|||||||
Reference in New Issue
Block a user