Skip to content

Commit fda0830

Browse files
committed
Refactor UserSettings and SettingsBase.
The settings store related parts are better defined in SettingsBase, as they are also used by other settings classes (via the fact that they are static). This is in prep for allowing the store to be changed (for the export tool).
1 parent 5d79907 commit fda0830

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Source/ORTS.Common/SettingsBase.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717

1818
using System;
19+
using System.IO;
1920
using System.Collections.Generic;
2021
using System.Diagnostics;
2122
using System.Linq;
@@ -27,6 +28,20 @@ namespace ORTS.Common
2728
/// </summary>
2829
public abstract class SettingsBase
2930
{
31+
public static string RegistryKey { get; protected set; } // ie @"SOFTWARE\OpenRails\ORTS"
32+
public static string SettingsFilePath { get; protected set; } // ie @"C:\Program Files\Open Rails\OpenRails.ini"
33+
34+
static SettingsBase()
35+
{
36+
// Only one of these is allowed; if the INI file exists, we use that, otherwise we use the registry.
37+
RegistryKey = "SOFTWARE\\OpenRails\\ORTS";
38+
SettingsFilePath = Path.Combine(ApplicationInfo.ProcessDirectory, "OpenRails.ini");
39+
if (File.Exists(SettingsFilePath))
40+
RegistryKey = null;
41+
else
42+
SettingsFilePath = null;
43+
}
44+
3045
/// <summary>
3146
/// Enumeration of the various sources for settings
3247
/// </summary>
@@ -42,6 +57,7 @@ protected enum Source
4257

4358
/// <summary>The store of the settings</summary>
4459
protected SettingsStore SettingStore { get; private set; }
60+
4561
/// <summary>Translates name of a setting to its source</summary>
4662
protected readonly Dictionary<string, Source> Sources = new Dictionary<string, Source>();
4763

Source/ORTS.Settings/UserSettings.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,12 @@ public sealed class DoNotSaveAttribute : Attribute
4343

4444
public class UserSettings : SettingsBase
4545
{
46-
public static readonly string RegistryKey; // ie @"SOFTWARE\OpenRails\ORTS"
47-
public static readonly string SettingsFilePath; // ie @"C:\Program Files\Open Rails\OpenRails.ini"
4846
public static readonly string UserDataFolder; // ie @"C:\Users\Wayne\AppData\Roaming\Open Rails"
4947
public static readonly string DeletedSaveFolder; // ie @"C:\Users\Wayne\AppData\Roaming\Open Rails\Deleted Saves"
5048
public static readonly string SavePackFolder; // ie @"C:\Users\Wayne\AppData\Roaming\Open Rails\Save Packs"
5149

5250
static UserSettings()
5351
{
54-
// Only one of these is allowed; if the INI file exists, we use that, otherwise we use the registry.
55-
RegistryKey = "SOFTWARE\\OpenRails\\ORTS";
56-
SettingsFilePath = Path.Combine(ApplicationInfo.ProcessDirectory, "OpenRails.ini");
57-
if (File.Exists(SettingsFilePath))
58-
RegistryKey = null;
59-
else
60-
SettingsFilePath = null;
61-
6252
UserDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ApplicationInfo.ProductName);
6353
// TODO: If using INI file, move these to application directory as well.
6454
if (!Directory.Exists(UserDataFolder)) Directory.CreateDirectory(UserDataFolder);

0 commit comments

Comments
 (0)