public Mod() { RootDirectory = string.Empty; main = new IniFile(); IniGroup mainGroup = new IniGroup("Main"); mainGroup.AddParameter("IncludeDirCount", 0, typeof(int)); mainGroup.AddParameter("UpdateServer"); mainGroup.AddParameter("SaveFile"); mainGroup.AddParameter("DLLFile"); IniGroup descGroup = new IniGroup("Desc"); descGroup.AddParameter("Title"); descGroup.AddParameter("Description"); descGroup.AddParameter("Version"); descGroup.AddParameter("Date"); descGroup.AddParameter("Author"); descGroup.AddParameter("AuthorURL"); descGroup.AddParameter("URL"); main.AddGroup(mainGroup); main.AddGroup(descGroup); }
public void AddGroup(IniGroup iniGroup) { if (groups.Any(t => t.GroupName == iniGroup.GroupName)) { string message = $"{IniName} already contains a group named {iniGroup.GroupName}"; throw new Exception(message); } groups.Add(iniGroup); }
public ModsDatabase() { RootDirectory = string.Empty; mods = new List <Mod>(); modsDb = new IniFile(); IniGroup mainGroup = new IniGroup("Main"); mainGroup.AddParameter("ReverseLoadOrder", 0, typeof(int)); mainGroup.AddParameter("ActiveModCount", 0, typeof(int)); IniGroup modsGroup = new IniGroup("Mods"); modsDb.AddGroup(mainGroup); modsDb.AddGroup(modsGroup); }
public void Read(TextReader textReader) { while (textReader.Peek() != -1) { string nextLine = textReader.ReadLine(); bool hasBracketAtStart = false; int secondBracketPosition = -1; int equalsPosition = -1; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < nextLine.Length; i++) { switch (nextLine[i]) { case '[': if (i == 0) { hasBracketAtStart = true; } goto default; case ']': if (hasBracketAtStart) { secondBracketPosition = stringBuilder.Length; } goto default; case '\\': if (i + 1 == nextLine.Length) { goto default; } i++; switch (nextLine[i]) { case 'n': stringBuilder.Append('\n'); break; case 'r': stringBuilder.Append('\r'); break; default: stringBuilder.Append(nextLine[i - 1]); stringBuilder.Append(nextLine[i]); break; } break; case '=': if (equalsPosition == -1) { equalsPosition = stringBuilder.Length; } goto default; case ';': i = nextLine.Length; break; default: stringBuilder.Append(nextLine[i]); break; } } string stringResult = stringBuilder.ToString(); if (hasBracketAtStart && secondBracketPosition != -1) { IniGroup iniGroup = new IniGroup(stringResult.Substring(1, secondBracketPosition - 1)); groups.Add(iniGroup); } else if (equalsPosition != -1) { string parameterKey = stringResult.Substring(0, equalsPosition); string parameterValue = stringResult.Substring(equalsPosition + 1); groups[groups.Count - 1].AddParameter(parameterKey, parameterValue); } else if (equalsPosition == -1 && !hasBracketAtStart && groups.Count > 0) { groups[groups.Count - 1].AddParameter(stringResult, ""); } } }
public void AddGroup(string name) { IniGroup iniGroup = new IniGroup(name); AddGroup(iniGroup); }