4using Newtonsoft.Json.Linq;
43 List<BadSettings> settings =
new List<BadSettings>
50 while (files.Count != 0)
52 string file = files.Dequeue();
53 BadLogger.
Log(
"Reading settings from file: " + file,
"SettingsReader");
58 s.
Populate(
true, settings.ToArray());
60 BadLogger.
Log(
"Resolving environment variables",
"SettingsReader");
76 JToken token = JToken.Parse(json);
91 Type: JTokenType.Object,
97 Dictionary<string, BadSettings> settings =
new Dictionary<string, BadSettings>();
98 JObject obj = (JObject)token;
100 foreach (KeyValuePair<string, JToken?> keyValuePair
in obj)
102 settings.Add(keyValuePair.Key,
CreateSettings(keyValuePair.Value, path));
115 BadLogger.
Log(
"Processing Dynamic Includes",
"SettingsReader");
117 string[]? includes = elems?.
GetValue<
string[]>();
119 if (includes ==
null)
128 List<BadSettings> setting =
new List<BadSettings>();
130 foreach (
string include
in includes)
132 if (include.Contains(
'*'))
134 bool allDirs = include.Contains(
"**");
135 string[] parts = include.Split(
140 StringSplitOptions.RemoveEmptyEntries
142 string path = parts[0];
143 string extension = parts[1];
153 BadLogger.Log(
"Reading settings from file: " + f,
"SettingsReader");
155 return CreateSettings(ReadJsonFile(f), f);
162 BadLogger.
Log(
"Reading settings from file: " + include,
"SettingsReader");
167 settings.
Populate(
true, setting.ToArray());
170 BadLogger.
Log(
"Resolving environment variables",
"SettingsReader");
173 elems = settings.
FindProperty(
"SettingsBuilder.Include");
174 includes = elems?.
GetValue<
string[]>();
176 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.