mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-23 00:24:41 +01:00
fix(settings): an import or a profile keeps the mode, the move keeps the card and GLES
Importing an eu07.ini or applying a profile took starter.settings.standard and starter.settings.advanced from the other file. An older one says "standard no", so the next start moved the player again and reset what was just imported, this time with no copy kept; "advanced yes" opened the advanced mode past the warning. Both are now this installation's, like its simulator and its card. The one-time move to the standard mode no longer resets starter.gpu and gfx.usegles: some machines run the simulator only on the integrated card or with OpenGL ES, and the move is done without asking.
This commit is contained in:
@@ -1466,6 +1466,57 @@ public class SettingsStoreTests
|
|||||||
Assert.False(installation.SettingsStore.Settings.PhysicsLogTrains);
|
Assert.False(installation.SettingsStore.Settings.PhysicsLogTrains);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An older file says "standard no": taken in, it would move the player again on the next
|
||||||
|
// start, and its "advanced yes" would open the advanced mode past the warning.
|
||||||
|
private const string OlderModeLines = "starter.settings.standard no\nstarter.settings.advanced yes\nfieldofview 50\n";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void An_imported_ini_leaves_the_mode_as_this_installation_has_it()
|
||||||
|
{
|
||||||
|
string backup = Path.Combine("/home/kolejarz", "backup", "eu07.ini");
|
||||||
|
var files = new InMemoryFileSystem()
|
||||||
|
.WithFile(UserIni, "starter.settings.standard yes\nstarter.settings.advanced no\n")
|
||||||
|
.WithFile(backup, OlderModeLines);
|
||||||
|
var store = WithHome(files).SettingsStore;
|
||||||
|
store.Load();
|
||||||
|
|
||||||
|
Assert.True(store.ImportFrom(backup));
|
||||||
|
store.Save();
|
||||||
|
|
||||||
|
Assert.Equal(50, store.Settings.FieldOfView);
|
||||||
|
Assert.True(store.Settings.MovedToStandard);
|
||||||
|
Assert.False(store.Settings.AdvancedSettings);
|
||||||
|
string written = files.ReadAllText(UserIni, System.Text.Encoding.UTF8);
|
||||||
|
Assert.Contains("starter.settings.standard yes", written);
|
||||||
|
Assert.Contains("starter.settings.advanced no", written);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void A_profile_leaves_the_mode_as_this_installation_has_it()
|
||||||
|
{
|
||||||
|
var files = new InMemoryFileSystem()
|
||||||
|
.WithFile(UserIni, "starter.settings.standard yes\nstarter.settings.advanced no\n")
|
||||||
|
.WithFile(Profile, OlderModeLines);
|
||||||
|
var store = WithHome(files).SettingsStore;
|
||||||
|
store.Load();
|
||||||
|
|
||||||
|
Assert.True(store.TryLoadProfile(Profile));
|
||||||
|
store.Save();
|
||||||
|
|
||||||
|
Assert.Equal(50, store.Settings.FieldOfView);
|
||||||
|
Assert.True(store.Settings.MovedToStandard);
|
||||||
|
Assert.False(store.Settings.AdvancedSettings);
|
||||||
|
string written = files.ReadAllText(UserIni, System.Text.Encoding.UTF8);
|
||||||
|
Assert.Contains("starter.settings.standard yes", written);
|
||||||
|
Assert.Contains("starter.settings.advanced no", written);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("starter.gpu")]
|
||||||
|
[InlineData("gfx.usegles")]
|
||||||
|
public void The_move_to_the_standard_mode_keeps_what_lets_a_machine_run_the_simulator(string key) =>
|
||||||
|
Assert.Contains(key, StarterNG.Application.SettingsStore.KeptOnMoveToStandard);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void An_imported_ini_from_before_the_tapes_of_the_trains_is_moved_as_a_profile_is()
|
public void An_imported_ini_from_before_the_tapes_of_the_trains_is_moved_as_a_profile_is()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -144,6 +144,31 @@ public sealed class SettingsStore
|
|||||||
TouchConfigAge();
|
TouchConfigAge();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// What lets some machines run the simulator at all: the card it is put on (offloading
|
||||||
|
/// to the discrete one fails with some drivers) and OpenGL ES where desktop OpenGL does
|
||||||
|
/// not work. The move to the standard mode, done without asking, leaves them as they are.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly IReadOnlySet<string> KeptOnMoveToStandard =
|
||||||
|
new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "starter.gpu", "gfx.usegles" };
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The mode is this installation's, like its simulator and its card: another file, a
|
||||||
|
/// backup or a profile of an older starter, says nothing of it. Without this, its
|
||||||
|
/// "starter.settings.standard no" would move the player again on the next start, and its
|
||||||
|
/// "starter.settings.advanced yes" would open the advanced mode past the warning.
|
||||||
|
/// The returned action puts the mode back as it was when this was called.
|
||||||
|
/// </summary>
|
||||||
|
private Action KeepMode()
|
||||||
|
{
|
||||||
|
bool advanced = Settings.AdvancedSettings, moved = Settings.MovedToStandard;
|
||||||
|
return () =>
|
||||||
|
{
|
||||||
|
Settings.AdvancedSettings = advanced;
|
||||||
|
Settings.MovedToStandard = moved;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a profile into the settings; true when it read cleanly. A read that failed
|
/// Reads a profile into the settings; true when it read cleanly. A read that failed
|
||||||
/// would leave defaults to be saved over the real settings, so those are read again.
|
/// would leave defaults to be saved over the real settings, so those are read again.
|
||||||
@@ -152,10 +177,14 @@ public sealed class SettingsStore
|
|||||||
{
|
{
|
||||||
if (_files.FileExists(path))
|
if (_files.FileExists(path))
|
||||||
{
|
{
|
||||||
|
var mode = KeepMode();
|
||||||
LoadFrom(path);
|
LoadFrom(path);
|
||||||
if (!LoadFailed)
|
if (!LoadFailed)
|
||||||
|
{
|
||||||
|
mode();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (LoadFailed)
|
if (LoadFailed)
|
||||||
Load();
|
Load();
|
||||||
@@ -262,6 +291,7 @@ public sealed class SettingsStore
|
|||||||
var gpu = s.Gpu;
|
var gpu = s.Gpu;
|
||||||
string lastScenery = s.LastScenery;
|
string lastScenery = s.LastScenery;
|
||||||
bool maximized = s.WindowMaximized;
|
bool maximized = s.WindowMaximized;
|
||||||
|
var mode = KeepMode();
|
||||||
|
|
||||||
_serializer.Read(s, imported);
|
_serializer.Read(s, imported);
|
||||||
|
|
||||||
@@ -270,6 +300,7 @@ public sealed class SettingsStore
|
|||||||
s.Gpu = gpu;
|
s.Gpu = gpu;
|
||||||
s.LastScenery = lastScenery;
|
s.LastScenery = lastScenery;
|
||||||
s.WindowMaximized = maximized;
|
s.WindowMaximized = maximized;
|
||||||
|
mode();
|
||||||
// an ini of before the tapes of the trains goes the same way as a profile
|
// an ini of before the tapes of the trains goes the same way as a profile
|
||||||
SettingsSerializer.MoveToTrainTapes(s);
|
SettingsSerializer.MoveToTrainTapes(s);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1419,10 +1419,12 @@ public partial class Settings : UserControl, ISettingsCapture
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
store.KeepCopy(".before-standard");
|
store.KeepCopy(".before-standard");
|
||||||
|
var moved = AdvancedKeys();
|
||||||
|
moved.ExceptWith(SettingsStore.KeptOnMoveToStandard);
|
||||||
_clamping = true;
|
_clamping = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ShowDefaults(AdvancedKeys());
|
ShowDefaults(moved);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user