private void buttonCreateAutoCustomFile_Click(object sender, EventArgs e) { Ex.Catch(() => { var fileEnd = Setting.FileEndOptions.Get(new SavingManager()).Value; var filePath = Path.Combine(PublicData.FolderConfigPath, $"autostart.{fileEnd}"); //if ( File.Exists(filePath) ) throw new IOException($"Файл уже существует.\n{filePath}"); var section = new IniFile(filePath, true).AddSection(PublicData.constAutoName); section.AddKey("code").SetValue(" "); section.AddKey("regex").SetValue(".+"); section.IniFile.SaveShowMessage(); }); VisualRefresh(); }
public static IniFile ReadString(string text) { if (string.IsNullOrWhiteSpace(text)) { return(new IniFile()); } var iniFile = new IniFile(); var lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); for (int index = 0; index < lines.Length; index++) { var line = lines[index].Trim(); if (string.IsNullOrWhiteSpace(line) || line.StartsWith(";") || line.StartsWith("#")) { continue; } var sectionName = Regex.Match(line, @"(?<=^\[).*(?=\]$)").Value.Trim(); var section = iniFile.AddSection(sectionName); if (section != null) { continue; } iniFile.AddKey(line); } return(iniFile); }
public void Ini_Save(string file, string section, string key, string value) { IniFile pIni = new IniFile(file); pIni.AddSection(section); pIni.DeleteKey(key, section); pIni.AddKey(key, value, section); pIni.Save(); }
public static IniFile ReadFromFile(string file) { if (string.IsNullOrWhiteSpace(file)) { return(null); } if (!File.Exists(file)) { return(new IniFile()); } var iniFile = new IniFile(); using (StreamReader reader = new StreamReader(file)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); if (string.IsNullOrWhiteSpace(line) || line.StartsWith(";") || line.StartsWith("#")) { continue; } var sectionName = Regex.Match(line, @"(?<=^\[).*(?=\]$)").Value.Trim(); var section = iniFile.AddSection(sectionName); if (section != null) { continue; } iniFile.AddKey(line); } reader.Close(); } return(iniFile); }