/// <summary> /// gets or sets a value of the given section. set: If the given section does not exist it will be created /// </summary> /// <param name="section"></param> /// <param name="key"></param> /// <returns>returns null when section or key not found</returns> public string this[string section, string key] { get { IniSection sec = IniSections.FirstOrDefault(f => f.Name == section); if (sec != null) { return(sec[key]); } return(null); } set { IniSection sec = IniSections.FirstOrDefault(f => f.Name == section); if (sec == null) { sec = new IniSection() { Name = section }; IniSections.Add(sec); } sec[key] = value; } }
/// <summary> /// converts into ini-format /// </summary> /// <returns></returns> public override string ToString() { StringBuilder sb = new StringBuilder(); foreach (IniSection s in IniSections.OrderBy(o => o.Name)) { sb.Append(s.ToString()); sb.Append("\r\n\r\n"); } return(sb.ToString()); }
/// <summary> /// Load confing.ini settings into a struct. /// </summary> public static void LoadSettings() { var INI = new IniFile("StreetEngine.ini"); // Load the settings file IniKeys keys = new IniKeys(); IniSections sections = new IniSections(); FieldInfo[] f_keys = keys.GetType().GetFields(); FieldInfo[] f_sections = sections.GetType().GetFields(); // IPs IniValues.h_auth = INI.Read(IniKeys.host, IniSections.auth); // IP of "Auth Server" IniValues.h_world = INI.Read(IniKeys.host, IniSections.game); // IP of "World Server" IniValues.h_lobby = INI.Read(IniKeys.host, IniSections.lobby); // IP of "Lobby Server" IniValues.h_msg = INI.Read(IniKeys.host, IniSections.msg); // IP of "Msg Server" // Ports IniValues.p_auth = int.Parse(INI.Read(IniKeys.port, IniSections.auth)); // Port of "Auth Server" IniValues.p_world = int.Parse(INI.Read(IniKeys.port, IniSections.game)); // Port of "World Server" IniValues.p_lobby = int.Parse(INI.Read(IniKeys.port, IniSections.lobby)); // Port of "Lobby Server" IniValues.p_msg = int.Parse(INI.Read(IniKeys.port, IniSections.msg)); // Port of "Msg Server" // Ingame stuff IniValues.gpotatos = int.Parse(INI.Read(IniKeys.gpotatos, IniSections.world)); // Gpotatos start number IniValues.rupees = int.Parse(INI.Read(IniKeys.rupees, IniSections.world)); // Rupees start number IniValues.questpoints = int.Parse(INI.Read(IniKeys.questpoints, IniSections.world)); // Questpoints start number IniValues.coins = int.Parse(INI.Read(IniKeys.coins, IniSections.world)); // Coins start number IniValues.level = int.Parse(INI.Read(IniKeys.level, IniSections.world)); // Level start number IniValues.type = int.Parse(INI.Read(IniKeys.type, IniSections.world)); // Char type start number IniValues.liscence = int.Parse(INI.Read(IniKeys.liscence, IniSections.world)); // Liscence start number // SQL Stuff IniValues.sql_backup = INI.Read(IniKeys.backup, IniSections.db); // SQL Backup file name IniValues.sql_connection = INI.Read(IniKeys.connection, IniSections.db); // SQL Connection string // I just use this to know how much keys are loaded foreach (var _keys in f_keys) keysList.Add(_keys.GetValue(keys).ToString()); // I just use this to know how much sections are loaded foreach (var _sections in f_sections) sectionsList.Add(_sections.GetValue(sections).ToString()); // Message... (Feel free to delete them) infos("'" + keysList.Count + "' Keys loaded"); infos("'" + sectionsList.Count + "' Sections loaded"); }
/// <summary> /// gets a section /// </summary> /// <param name="section"></param> /// <returns>get: returns null if section not found</returns> public IniSection this[string section] { get { return(IniSections.FirstOrDefault(f => f.Name == section)); } set { for (int i = 0; i < IniSections.Count; i++) { if (IniSections[i].Name == section) { IniSections[i] = value; return; } } IniSections.Add(value); } }
public IniFileEntryAttribute(IniFiles file, IniSections section, ServerProfileCategory category, string key = "") : base(file, section, category, key) { }