// Get group-range int[] GroupPos(string group = "") { if (group == "") { return(new[] { 0, 0 });// No Group. } string lowerline; int[] ret = new[] { -1, -1 }; for (int i = 0; i < lines.Length; i++) { lowerline = lines[i].ToLower(); if (ret[0] < 0) { if (lowerline.Contains("[" + group.ToLower() + "]")) { ret[0] = i; // Group found. } } else { if (lowerline.StartsWith("[") || i == lines.Length - 1) // next group or end of file. { ret[1] = --i; // End of group found. return(ret); } } } WriteConsole.Error("Unable to find Group '" + group + "' in configuration file '" + fn + "'."); return(ret); // Group not found. }
// Constructor public IniFile(string filename) { _file = filename; filename = AppDomain.CurrentDomain.BaseDirectory + filename; try { using (StreamReader stream = new StreamReader(filename)) { fn = _file; lines = stream.ReadToEnd().Split(new[] { "\n", "\r\n" }, StringSplitOptions.None); } } catch (Exception e) { WriteConsole.Error("The file could not be read:"); WriteConsole.Error(e.Message); return; } }
/// <summary> /// Construtor /// </summary> /// <param name="_filename">nome do arquivo</param> public IniFile(string _filename) { try { //caso o arquivo não existir, é lançado uma exceção if (File.Exists(_filename) == false) { throw new Exception($"File no Exist: {_filename}"); } else { //caso o arquivo existir, é adicionado um local + nome do arquivo FilePath = AppDomain.CurrentDomain.BaseDirectory + _filename; } } //caso caia no exception catch (Exception ex) { WriteConsole.WriteLine(ex.Message); } }