public static VConfig Create(string file) { var cfg = new VConfig(new VCSection[0], new FileInfo(file)); cfg.Add("Default"); return(cfg); }
public static VConfig Parse(string[] lines, string file) { var r_section = new Regex(@"^\[([A-Za-z0-9_]+)\]$"); var r_item = new Regex(@"^([A-Za-z0-9_]+)=([^=]*)$"); var cfg = new VConfig(new VCSection[0], new FileInfo(file)); string section = "Default"; cfg.Add(section); foreach (string line in lines) { Match m = r_section.Match(line); if (m.Success) { section = m.Groups[1].Value; if (!cfg.SectionExist(section)) { cfg.Add(section); } } else if ((m = r_item.Match(line)).Success) { cfg.GetSection(section).Add(m.Groups[1].Value, m.Groups[2].Value); } } return(cfg); }
public VConfig AddConfig(string cfgName) { if (ConfigExists(cfgName)) { throw new InvalidOperationException("Такой конфиг уже существует."); } cfgName += ".ini"; string full_path = Path.Combine(path.FullName, cfgName); var cfg = VConfig.Create(full_path); cfg.Save(); return(cfg); }
public VConfig GetConfig(string cfgName) { cfgName += ".ini"; string full_path = Path.Combine(path.FullName, cfgName); if (!File.Exists(full_path)) { return(null); } List <string> lines = new List <string>(); using (var sr = new StreamReader(full_path)) { string text; while ((text = sr.ReadLine()) != null) { lines.Add(text); } } return(VConfig.Parse(lines.ToArray(), full_path)); }