4using Newtonsoft.Json.Linq;
43 List<BadSettings> settings =
new List<BadSettings> {
m_RootSettings };
47 while (files.Count != 0)
49 string file = files.Dequeue();
50 BadLogger.
Log(
"Reading settings from file: " + file,
"SettingsReader");
55 s.
Populate(
true, settings.ToArray());
57 BadLogger.
Log(
"Resolving environment variables",
"SettingsReader");
73 JToken token = JToken.Parse(json);
86 not { Type: JTokenType.Object })
91 Dictionary<string, BadSettings> settings =
new Dictionary<string, BadSettings>();
92 JObject obj = (JObject)token;
94 foreach (KeyValuePair<string, JToken?> keyValuePair
in obj)
96 settings.Add(keyValuePair.Key,
CreateSettings(keyValuePair.Value, path));
109 BadLogger.
Log(
"Processing Dynamic Includes",
"SettingsReader");
111 string[]? includes = elems?.
GetValue<
string[]>();
113 if (includes ==
null)
122 List<BadSettings> setting =
new List<BadSettings>();
124 foreach (
string include
in includes)
126 if (include.Contains(
'*'))
128 bool allDirs = include.Contains(
"**");
130 string[] parts = include.Split(
new[] {
'*' },
131 StringSplitOptions.RemoveEmptyEntries
133 string path = parts[0];
134 string extension = parts[1];
141 setting.AddRange(files.Select(f =>
143 BadLogger.Log(
"Reading settings from file: " + f,
147 return CreateSettings(ReadJsonFile(f), f);
154 BadLogger.
Log(
"Reading settings from file: " + include,
"SettingsReader");
159 settings.
Populate(
true, setting.ToArray());
161 BadLogger.
Log(
"Resolving environment variables",
"SettingsReader");
164 elems = settings.
FindProperty(
"SettingsBuilder.Include");
165 includes = elems?.
GetValue<
string[]>();
167 while (includes !=
null);
Public facing interface for a logger.
static void Log(string message)
Writes a Log to the Message Handler.
Public Api for the Settings System.
void Populate(bool invokeOnChanged, params BadSettings[] settings)
Populates the current object with the settings provided.
BadSettings? FindProperty(string propertyPath)
Finds a property based on the property path relative to this object.
void SetValue(JToken? value, bool invokeOnChange=true)
Sets the Json Token of the Current Settings Object.
static string ResolveEnvironmentVariables(BadSettings root, BadSettings parent, string str)
Resolves Environment Variables in the current object.
JToken? GetValue()
Returns the Json Token of the Settings Object.
bool RemoveProperty(string propertyName, bool invokeOnChange=true)
Removes the Property with the given Name.
Reads a JSON file and returns the resulting BadSettings Object.
BadSettings ReadSettings()
Returns a new Instance of BadSettings with all source files loaded.
BadSettingsReader(BadSettings rootSettings, IFileSystem mFileSystem, params string[] sourceFiles)
Constructs a new BadSettingsReader.
void ReadDynamicSettings(BadSettings settings)
Processes Dynamic Include Statements inside a settings object.
readonly IFileSystem m_FileSystem
JToken ReadJsonFile(string fileName)
Parses a JSON File and returns the resulting JObject.
static BadSettings CreateSettings(JToken? token, string path)
Creates a Settings Object from a JToken.
readonly string[] m_SourceFiles
The Source Files that are used to read the Settings.
readonly BadSettings m_RootSettings
The Root Settings Object that all other Settings are added into.
Defines the interface for a file system.
IEnumerable< string > GetFiles(string path, string extension, bool recursive)
Returns all files in the given directory that match the specified extension.
Contains Logging system for the BadScript Runtime.
Contains IO Implementation for the BadScript2 Runtime.
Contains the Settings Implementation.