public void SchemeTest() { const string file = "test3.1.ini"; File.WriteAllText(file, "key1 = false\nkey2 = 1338\n"); var config = new IniManager(file); config.Load(); config.EnsureScheme(typeof(Config)); Assert.Equal(ulong.MaxValue, config["count"].ValueAs <ulong>()); Assert.Equal(default, config["port"].ValueAs <int>());
public void TypeConversionsTest() { const string file = "test2.ini"; File.WriteAllText(file, "key1 = false\nkey2 = 1338\n"); var config = new IniManager(file); config.Load(); var key1 = config["key1"].ValueAs <bool>(); var key2 = config["key2"].ValueAs <int>(); Assert.False(key1); Assert.Equal(1338, key2); }
/// <summary> /// Processes the INI file, applying any changes. /// </summary> static void ProcessINI() { var ini = new IniManager(IniFile) { ReturnDefaultIfEmpty = true }; ini.Load(); if (ini.Contains(IniSectionLauncher)) { // Fallout Launcher PathLauncher = ini.GetString(IniSectionLauncher, IniKeyPath, PathLauncher); ArgumentsLauncher = ini.GetString(IniSectionLauncher, IniKeyArguments, ArgumentsLauncher); } if (ini.Contains(IniSectionFOSE)) { // FOSE PathFOSE = ini.GetString(IniSectionFOSE, IniKeyPath, PathFOSE); ArgumentsFOSE = ini.GetString(IniSectionFOSE, IniKeyArguments, ArgumentsFOSE); } if (ini.Contains(IniSectionMO)) { // Mod Organizer PathModOrganizer = ini.GetString(IniSectionMO, IniKeyPath, PathModOrganizer); ArgumentsModOrganizer = ini.GetString(IniSectionMO, IniKeyArguments, ArgumentsModOrganizer); } if (ini.Contains(IniSectionCustom)) { // Custom NameCustom = ini.GetString(IniSectionCustom, IniKeyName, NameCustom); PathCustom = ini.GetString(IniSectionCustom, IniKeyPath, PathCustom); ArgumentsCustom = ini.GetString(IniSectionCustom, IniKeyArguments, ArgumentsCustom); } }
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); }