public void Read(Config cfg) { if (!File.Exists(Filename)) { File.Create(Filename).Close(); return; } try { using (var stream = new StreamReader(Filename)) { while (!stream.EndOfStream) { var line = stream.ReadLine(); line = line.Trim(); if (string.IsNullOrWhiteSpace(line)) continue; if(!line.Contains("=")) { var secstr = line.Substring(line.IndexOf('[') + 1, line.LastIndexOf(']') - 1); cfg.AddSection(secstr); cfg.SetSection(secstr); } else { var args = line.Split(new [] { '=' } , 2).Select(s => s.Trim()); cfg.Write(args.First(), args.Count() == 2 ? args.LastOrDefault() : ""); } } } } catch (Exception) { throw; } }