using System; using System.Collections.Generic; using System.IO; using System.Text; using AniNIX.Shared; namespace AniNIX.TheRaven { public static class RavenConfigure { /// /// Create a new list from the line-delimited entries in a file /// /// the file to read /// A List of Strings containing the lines. public static List ReadLineDelimitedFile(String filename) { String line = null; int count = 0; //Read all the file to join. ReportMessage.Log(Verbosity.Verbose,String.Format("Reading {0}",filename)); //Path.GetFileName(filename))); List newEntries = new List(); StreamReader fileReader = new StreamReader(filename); line = fileReader.ReadLine(); while (line != null) { if (line.Length < 1) { line = fileReader.ReadLine(); continue; } line = line.Trim(); if (line[0] == '#') { line = fileReader.ReadLine(); continue; } //Skip lines starting with a # String[] byHash = line.Split('#'); //Ignore everything after a # newEntries.Add(byHash[0]); count++; ReportMessage.Log(Verbosity.VeryVerbose,String.Format("Added entry {0} from {1}",line,Path.GetFileName(filename))); line = fileReader.ReadLine(); } fileReader.Close(); ReportMessage.Log(Verbosity.VeryVerbose,String.Format("Found {0} newEntries.",newEntries.Count)); return newEntries; } /// /// Get the String[] of lines in a file -- use this for random performance /// /// the file to read /// A String[] public static String[] ReadLineDelimitedFileToArr(String filename) { return RavenConfigure.ReadLineDelimitedFile(filename).ToArray(); } /// /// Read the first line from a file -- this is useful for allowing configuration of single strings. /// /// the file to read /// The first line as a String public static String ReadFirstLineFromFile(String filename) { StreamReader fileReader = new StreamReader(filename); String readString = fileReader.ReadLine(); fileReader.Close(); return readString; } } }