Ejemplo n.º 1
0
        public void IniTest()
        {
            const string file = "test1.ini";

            File.WriteAllText(file, "\n\n\r\nsome_key =some value\r\n# some comment\n\nsome_second_key = \"some val\"");

            var config = new IniManager(file);

            config.Load();

            Assert.Equal("some value", config["some_key"].Value);
            Assert.Equal("some val", config["some_second_key"].Value);

            config.Save();

            config["another_key"] = "ok";

            config["another_key"] = new IniSection("another_key", "ok2", null, false);

            config.Save();

            Assert.True(File.ReadAllText(file).Length != 0);
            Assert.True(config.Sections.Count() == 3);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an empty INI file for the user to configure.
        /// </summary>
        static void CreateEmptyIni()
        {
            var ini = new IniManager(IniFile)
            {
                ReturnDefaultIfEmpty = true
            };

            // Fallout Launcher
            ini.GetSection(IniSectionLauncher)
            .InsertComment("Leave empty to ignore")
            .Add(IniKeyPath, string.Empty)
            .Add(IniKeyArguments, string.Empty)
            .InsertEmptyLine();

            // FOSE
            ini.GetSection(IniSectionFOSE)
            .InsertComment("Leave empty to ignore")
            .Add(IniKeyPath, string.Empty)
            .Add(IniKeyArguments, string.Empty)
            .InsertEmptyLine();

            // Mod Organizer
            ini.GetSection(IniSectionMO)
            .InsertComment("Leave empty to ignore")
            .Add(IniKeyPath, string.Empty)
            .Add(IniKeyArguments, string.Empty)
            .InsertEmptyLine();

            // Custom
            ini.GetSection(IniSectionCustom)
            .InsertComment("Leave empty to ignore")
            .Add(IniKeyName, string.Empty)
            .Add(IniKeyPath, string.Empty)
            .Add(IniKeyArguments, string.Empty);

            ini.Save();
        }