Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public Mod()
        {
            RootDirectory = string.Empty;
            main = new IniFile();

            IniGroup mainGroup = new IniGroup("Main");
            mainGroup.AddParameter("IncludeDirCount", 0, typeof(int));

            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);
        }
Ejemplo n.º 3
0
        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]);
                                    break;
                            }

                            break;

                        case '=':
                            equalsPosition = stringBuilder.Length;
                            goto default;

                        case '#':
                        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);
                }
            }
        }
Ejemplo n.º 4
0
 public void AddGroup(string name)
 {
     IniGroup iniGroup = new IniGroup(name);
     AddGroup(iniGroup);
 }
Ejemplo n.º 5
0
        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);
        }