Skip to content

Commit c5d4667

Browse files
committed
Changes needed for exporter.
1 parent fdc6f2b commit c5d4667

File tree

8 files changed

+75
-20
lines changed

8 files changed

+75
-20
lines changed

Source/ORTS.Common/SettingsBase.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ namespace ORTS.Common
2828
/// </summary>
2929
public abstract class SettingsBase
3030
{
31-
private const string DefaultRegistryKey = "SOFTWARE\\OpenRails\\ORTS";
32-
private const string DefaultSettingsFileName = "OpenRails.ini";
31+
public const string DefaultRegistryKey = "SOFTWARE\\OpenRails\\ORTS";
32+
public const string DefaultSettingsFileName = "OpenRails.ini";
3333

3434
public static string RegistryKey { get; private set; } // ie @"SOFTWARE\OpenRails\ORTS"
3535
public static string SettingsFilePath { get; private set; } // ie @"C:\Program Files\Open Rails\OpenRails.ini"
@@ -47,19 +47,31 @@ static SettingsBase()
4747

4848
/// <summary>
4949
/// Override the location for the settings. This only changes the static names.
50+
/// Only one must be specified (see SettingsBase static constructor).
5051
/// If settings objects already exist, they need to be changed using ChangeSettingsStore().
5152
/// </summary>
52-
/// <param name="filePath">The new ini file path, relative to the OpenRails base directory.</param>
53-
/// <param name="registryKey">The new registry key, relative to the HKEY_CURRENT_USER. May be NULL.</param>
53+
/// <param name="filePath">The new ini file path, relative to the OpenRails base directory, or NULL.</param>
54+
/// <param name="registryKey">The new registry key, relative to the HKEY_CURRENT_USER, or NULL.</param>
5455
static public void OverrideSettingsLocations(string filePath, string registryKey)
5556
{
56-
// Only one of these is allowed; if the INI file exists, we use that, otherwise we use the registry.
57-
RegistryKey = registryKey;
58-
SettingsFilePath = Path.Combine(ApplicationInfo.ProcessDirectory, filePath);
59-
if (File.Exists(SettingsFilePath))
57+
if (!String.IsNullOrEmpty(filePath) && !String.IsNullOrEmpty(registryKey))
58+
{
59+
throw new ArgumentException("Only one of filePath and registryKey may be provided.");
60+
}
61+
else if (!String.IsNullOrEmpty(filePath))
62+
{
63+
SettingsFilePath = Path.Combine(ApplicationInfo.ProcessDirectory, filePath);
6064
RegistryKey = null;
61-
else
65+
}
66+
else if (!String.IsNullOrEmpty(registryKey))
67+
{
68+
RegistryKey = registryKey;
6269
SettingsFilePath = null;
70+
}
71+
else
72+
{
73+
throw new ArgumentException("One of filePath and registryKey must be provided.");
74+
}
6375
}
6476

6577
/// <summary>
@@ -136,6 +148,13 @@ protected SettingsBase(SettingsStore settings)
136148
/// </summary>
137149
public abstract void Reset();
138150

151+
public String GetSettingsStoreName()
152+
{
153+
string name = "none";
154+
if (SettingStore != null) { name = SettingStore.GetStoreName(); }
155+
return name;
156+
}
157+
139158
/// <summary>
140159
/// Change the settings store. Creates a new SettingsStore based on the provided parameters.
141160
/// See also SettingsStore.GetSettingStore().

Source/ORTS.Common/SettingsStore.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ public virtual void Discard()
147147
// default action is to do nothing. Concrete classes may override.
148148
}
149149

150+
/// <summary>
151+
/// Get the name of the settings store.
152+
/// </summary>
153+
public abstract String GetStoreName();
154+
155+
150156
/// <summary>
151157
/// Factory method to create a setting store (sub-class of SettingsStore)
152158
/// </summary>
@@ -330,6 +336,16 @@ public override void Discard()
330336
// cannot set to null, as Key (and string version) are readonly
331337
}
332338
}
339+
340+
/// <summary>
341+
/// Get the name of the settings store, in this case the registry key.
342+
/// </summary>
343+
public override String GetStoreName()
344+
{
345+
string name = "None (registry)";
346+
if (Key != null) { name = Key.Name; }
347+
return name;
348+
}
333349
}
334350

335351
/// <summary>
@@ -552,7 +568,17 @@ public override void DeleteUserValue(string name)
552568
{
553569
NativeMethods.WritePrivateProfileString(Section, name, null, FilePath);
554570
}
555-
}
571+
572+
/// <summary>
573+
/// Get the name of the settings store, in this case the INI file path.
574+
/// </summary>
575+
public override String GetStoreName()
576+
{
577+
string name = "None (file)";
578+
if (!String.IsNullOrEmpty(FilePath)) { name = FilePath; }
579+
return name;
580+
}
581+
}
556582

557583
// TODO: This class and its methods should be internal visibility.
558584
/// <summary>

Source/ORTS.Settings/ContentSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ namespace ORTS.Settings
2424
{
2525
public class ContentSettings : SettingsBase
2626
{
27+
public static readonly string SectionName = "ContentRoutes";
28+
2729
#region User Settings
2830
public ContentRouteSettings ContentRouteSettings;
2931
#endregion
3032

3133
public ContentSettings(IEnumerable<string> options)
32-
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, "ContentRoutes"))
34+
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, SectionName))
3335
{
3436
ContentRouteSettings = new ContentRouteSettings();
3537
Load(options);

Source/ORTS.Settings/FolderSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ namespace ORTS.Settings
2626
{
2727
public class FolderSettings : SettingsBase
2828
{
29+
public static readonly string SectionName = "Folders";
30+
2931
public readonly Dictionary<string, string> Folders;
3032

3133
public FolderSettings(IEnumerable<string> options)
32-
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, "Folders"))
34+
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, SectionName))
3335
{
3436
Folders = new Dictionary<string, string>();
3537
Load(options);

Source/ORTS.Settings/InputSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public enum KeyModifiers
6262
/// </remarks>
6363
public class InputSettings : SettingsBase
6464
{
65+
public static readonly string SectionName = "Keys";
66+
6567
static GettextResourceManager commonCatalog = new GettextResourceManager("ORTS.Common");
6668
static GettextResourceManager settingsCatalog = new GettextResourceManager("ORTS.Settings");
6769

@@ -79,7 +81,7 @@ static InputSettings()
7981
/// </summary>
8082
/// <param name="options">The list of one-time options to override persisted settings, if any.</param>
8183
public InputSettings(IEnumerable<string> options)
82-
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, "Keys"))
84+
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, SectionName))
8385
{
8486
InitializeCommands(Commands);
8587
Load(options);

Source/ORTS.Settings/RailDriverSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public enum RailDriverCalibrationSetting
4444

4545
public class RailDriverSettings : SettingsBase
4646
{
47+
public static readonly string SectionName = "RailDriver";
48+
4749
static readonly GettextResourceManager catalog = new GettextResourceManager("ORTS.Settings");
4850
private static readonly byte[] DefaultCalibrationSettings;
4951
private static readonly Dictionary<UserCommand, byte> DefaultUserCommands;
@@ -119,7 +121,7 @@ static RailDriverSettings()
119121
/// </summary>
120122
/// <param name="options">The list of one-time options to override persisted settings, if any.</param>
121123
public RailDriverSettings(IEnumerable<string> options)
122-
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, "RailDriver"))
124+
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, SectionName))
123125
{
124126
CalibrationSettings = new byte[DefaultCalibrationSettings.Length];
125127

Source/ORTS.Settings/UpdateState.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace ORTS.Settings
2626
{
2727
public class UpdateState : SettingsBase
2828
{
29+
public static readonly string SectionName = "UpdateState";
30+
2931
#region User Settings
3032

3133
// Please put all update settings in here as auto-properties. Public properties
@@ -41,7 +43,7 @@ public class UpdateState : SettingsBase
4143
#endregion
4244

4345
public UpdateState()
44-
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, "UpdateState"))
46+
: base(SettingsStore.GetSettingStore(SettingsBase.SettingsFilePath, SettingsBase.RegistryKey, SectionName))
4547
{
4648
Load(new string[0]);
4749
}

Source/ORTS.Settings/UserSettings.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,11 @@ public override void Reset()
594594
/// <param name="section">Optional, the name of the section / subkey.</param>
595595
public override void ChangeSettingsStore(string filePath, string registryKey, string section)
596596
{
597-
base.ChangeSettingsStore(filePath, registryKey, section);
598-
Folders.ChangeSettingsStore(filePath, registryKey, section);
599-
Input.ChangeSettingsStore(filePath, registryKey, section);
600-
RailDriver.ChangeSettingsStore(filePath, registryKey, section);
601-
Content.ChangeSettingsStore(filePath, registryKey, section);
597+
base.ChangeSettingsStore(filePath, registryKey, section); // section is defined in SettingsStoreLocalIni
598+
Folders.ChangeSettingsStore(filePath, registryKey, FolderSettings.SectionName);
599+
Input.ChangeSettingsStore(filePath, registryKey, InputSettings.SectionName);
600+
RailDriver.ChangeSettingsStore(filePath, registryKey, RailDriverSettings.SectionName);
601+
Content.ChangeSettingsStore(filePath, registryKey, ContentSettings.SectionName);
602602
}
603603

604604
public void Log()

0 commit comments

Comments
 (0)