/// <summary> /// Loads all the settings into the memory, if no properties file is found nothing will happen /// </summary> public void LoadSettings() { if (!File.Exists(PropertiesPath)) { return; } string[] text = File.ReadAllLines(PropertiesPath); Values.Clear(); for (int i = 0; i < text.Count(); i++) { string read = text[i]; SettingNode pair; if (String.IsNullOrWhiteSpace(read)) { Values.Add(new SettingNode(null, read, null)); continue; } if (read[0] == '#' && ((i + 1 < text.Length) ? text[i + 1][0] == '#' || String.IsNullOrWhiteSpace(text[i + 1]) : true)) { Values.Add(new SettingNode(null, read, null)); continue; } if (read[0] == '#' && (i + 1 < text.Length) ? text[i + 1][0] != '#' && !String.IsNullOrWhiteSpace(text[i + 1]) : false) { i++; var split = text[i].Split('='); pair = new SettingNode(split[0].Trim().ToLower(), String.Join("=", split, 1, split.Length - 1).Trim(), read.Substring(1)); } else { if (read[0] != '#') { var split = text[i].Split('='); pair = new SettingNode(split[0].Trim().ToLower(), String.Join("=", split, 1, split.Length - 1).Trim(), null); } else { pair = new SettingNode(null, read, null); } } Values.Add(pair); } }
/// <summary> /// Set the setting /// </summary> /// <param name="key">key to save value to</param> /// <param name="description">Write a description (optional)</param> /// <param name="values">for each string in values, it will be seperated by a comma ','</param> /// <remarks>If the setting does not exist, it will create a new one</remarks> public void SetSetting(string key, string description = null, params string[] values) { key = key.ToLower(); var pair = GetNode(key); if (pair == null) { pair = new SettingNode(key, string.Join(",", values), description); Values.Add(pair); if (OnSettingChanged != null) { OnSettingChanged(null, new SettingsChangedEventArgs(key, null, pair.Value)); } return; } if (OnSettingChanged != null) { OnSettingChanged(null, new SettingsChangedEventArgs(key, pair.Value, string.Join(",", values))); } pair.Description = description ?? pair.Description;; pair.Value = string.Join(",", values); }
/// <summary> /// Set the setting /// </summary> /// <param name="key">key to save value to</param> /// <param name="value">value to set setting to</param> /// <param name="description">Write a description (optional)</param> /// <remarks>If the setting does not exist, it will create a new one</remarks> public void SetSetting(string key, bool value, string description = null) { key = key.ToLower(); var pair = GetNode(key); if (pair == null) { pair = new SettingNode(key, value.ToString(CultureInfo.InvariantCulture), description); Values.Add(pair); if (OnSettingChanged != null) { OnSettingChanged(null, new SettingsChangedEventArgs(key, null, pair.Value)); } return; } if (OnSettingChanged != null) { OnSettingChanged(null, new SettingsChangedEventArgs(key, pair.Value, value.ToString(CultureInfo.InvariantCulture))); } pair.Description = description; pair.Value = string.Join(",", value.ToString(CultureInfo.InvariantCulture)); }
public ExtraSettings(string settingsName, SettingNode[] defaultValues, bool init=true) : this(settingsName, false) { this.defaultValues = defaultValues; if (init) Init(); }
public OnSettingLoadArgs(SettingNode setting) { this.setting = setting; }
/// <summary> /// Set the setting /// </summary> /// <param name="key">key to save value to</param> /// <param name="value">value to set setting to</param> /// <param name="description">Write a description (optional)</param> /// <remarks>If the setting does not exist, it will create a new one</remarks> public void SetSetting(string key, bool value, string description = null) { key = key.ToLower(); var pair = GetNode(key); if (pair == null) { pair = new SettingNode(key, value.ToString(CultureInfo.InvariantCulture), description); Values.Add(pair); if (OnSettingChanged != null) OnSettingChanged(null, new SettingsChangedEventArgs(key, null, pair.Value)); return; } if (OnSettingChanged != null) OnSettingChanged(null, new SettingsChangedEventArgs(key, pair.Value, value.ToString(CultureInfo.InvariantCulture))); pair.Description = description; pair.Value = string.Join(",", value.ToString(CultureInfo.InvariantCulture)); }
/// <summary> /// Set the setting /// </summary> /// <param name="key">key to save value to</param> /// <param name="description">Write a description (optional)</param> /// <param name="values">for each string in values, it will be seperated by a comma ','</param> /// <remarks>If the setting does not exist, it will create a new one</remarks> public void SetSetting(string key, string description = null, params string[] values) { key = key.ToLower(); var pair = GetNode(key); if (pair == null) { pair = new SettingNode(key, string.Join(",", values), description); Values.Add(pair); if (OnSettingChanged != null) OnSettingChanged(null, new SettingsChangedEventArgs(key, null, pair.Value)); return; } if (OnSettingChanged != null) OnSettingChanged(null, new SettingsChangedEventArgs(key, pair.Value, string.Join(",", values))); pair.Description = description ?? pair.Description; ; pair.Value = string.Join(",", values); }
/// <summary> /// Loads all the settings into the memory, if no properties file is found nothing will happen /// </summary> public void LoadSettings() { if (!File.Exists(PropertiesPath)) return; string[] text = File.ReadAllLines(PropertiesPath); Values.Clear(); for (int i = 0; i < text.Count(); i++) { string read = text[i]; SettingNode pair; if (String.IsNullOrWhiteSpace(read)) { Values.Add(new SettingNode(null, read, null)); continue; } if (read[0] == '#' && ((i + 1 < text.Length) ? text[i + 1][0] == '#' || String.IsNullOrWhiteSpace(text[i + 1]) : true)) { Values.Add(new SettingNode(null, read, null)); continue; } if (read[0] == '#' && (i + 1 < text.Length) ? text[i + 1][0] != '#' && !String.IsNullOrWhiteSpace(text[i + 1]) : false) { i++; var split = text[i].Split('='); pair = new SettingNode(split[0].Trim().ToLower(), String.Join("=", split, 1, split.Length - 1).Trim(), read.Substring(1)); } else { if (read[0] != '#') { var split = text[i].Split('='); pair = new SettingNode(split[0].Trim().ToLower(), String.Join("=", split, 1, split.Length - 1).Trim(), null); } else pair = new SettingNode(null, read, null); } Values.Add(pair); } }
/// <summary> /// Set the setting /// </summary> /// <param name="key">key to save value to</param> /// <param name="description">Write a description (optional)</param> /// <param name="values">for each string in values, it will be seperated by a comma ','</param> /// <remarks>If the setting does not exist, it will create a new one</remarks> public void SetSetting(string key, string description = null, params string[] values) { key = key.ToLower(); var pair = GetPair(key); if (pair == null) { pair = new SettingNode(key, string.Join(",", values), description); Values.Add(pair); return; } pair.Description = description; pair.Value = string.Join(",", values); }
/// <summary> /// Set the setting /// </summary> /// <param name="key">key to save value to</param> /// <param name="value">value to set setting to</param> /// <param name="description">Write a description (optional)</param> /// <remarks>If the setting does not exist, it will create a new one</remarks> public void SetSetting(string key, bool value, string description = null) { key = key.ToLower(); var pair = GetPair(key); if (pair == null) { pair = new SettingNode(key, value.ToString(CultureInfo.InvariantCulture), description); Values.Add(pair); return; } pair.Description = description; pair.Value = string.Join(",", value.ToString(CultureInfo.InvariantCulture)); }