Пример #1
0
        private static void WriteSection(TextWriter writer, XwaIniSection section)
        {
            foreach (string line in section.Lines)
            {
                writer.WriteLine(line);
            }

            if (section.Lines.Count == 0 || !string.IsNullOrWhiteSpace(section.Lines.Last()))
            {
                writer.WriteLine();
            }

            if (section.Settings.Count != 0)
            {
                foreach (string line in section.Settings)
                {
                    writer.WriteLine(line);
                }

                writer.WriteLine();
            }
        }
Пример #2
0
        public void Read(string iniKey, string txtKey = null, bool parseSettings = false)
        {
            if (string.IsNullOrEmpty(iniKey))
            {
                throw new ArgumentNullException(nameof(iniKey));
            }

            var section = new XwaIniSection();

            if (!string.IsNullOrEmpty(txtKey))
            {
                string txtPath = this.BasePath + txtKey + ".txt";

                if (File.Exists(txtPath))
                {
                    foreach (string fileLine in ReadFileLines(txtPath))
                    {
                        section.Lines.Add(fileLine);
                    }

                    section.TxtKey = txtKey;
                }
            }

            foreach (string fileLine in ReadFileLines(this.BasePath + this.Extension, iniKey))
            {
                section.Lines.Add(fileLine);
            }

            this.Sections[iniKey] = section;

            if (parseSettings)
            {
                this.ParseSettings(iniKey);
            }
        }