public void LoadPath() { string filePath = "Test.ini"; StreamWriter writer = new StreamWriter(filePath); writer.WriteLine("; some comment"); writer.WriteLine("[new section]"); writer.WriteLine(" dog = Rover"); writer.WriteLine(""); // empty line writer.WriteLine("; a comment"); writer.WriteLine(" cat = Muffy"); writer.Close(); IniConfigSource source = new IniConfigSource(filePath); IConfig config = source.Configs["new section"]; Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Muffy", config.Get("cat")); config.Set("dog", "Spots"); config.Set("cat", "Misha"); config.Set("DoesNotExist", "SomeValue"); source.Load(filePath); config = source.Configs["new section"]; Assert.AreEqual("Rover", config.Get("dog")); Assert.AreEqual("Muffy", config.Get("cat")); File.Delete(filePath); }
private static void CreateOrLoadIniConfig(IniConfigSource config) { var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var configPath = Path.Combine(appDataPath, "sharphaven", "settings.ini"); try { config.Load(configPath); } catch (Exception) { Directory.CreateDirectory(Path.GetDirectoryName(configPath)); config.Save(configPath); } }
public void SetupSettings(string[] args) { var argConfig = new ArgvConfigSource(args); argConfig.AddSwitch("Args", "ini", "i"); var file = argConfig.Configs["Args"].Get("ini", defaultFileSettings); if (File.Exists(file)) { Settings.Load(file); CoreSettings = Settings.Configs["Core"]; NetworkSettings = Settings.Configs["Network"]; WebSettings = Settings.Configs["Web"]; } else { CoreSettings = Settings.Configs.Add("Core"); NetworkSettings = Settings.Configs.Add("Network"); WebSettings = Settings.Configs.Add("Web"); } }