@@ -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().
0 commit comments