public static BheProject FromFile(string fileName) { string directory = Path.GetDirectoryName(fileName); var project = new BheProject(); project.FileName = fileName; project.DirectoryName = directory; project.ProjectText = File.ReadAllText(Path.Combine(directory, "Project.txt"), Encoding.Default); project.Summary = BheSummary.FromFile(Path.Combine(directory, "Summary.txt")); project.Sections.AddRange(BheSection.ListFromFile(Path.Combine(directory, "Sections.csv"))); foreach (string pattern in project.Summary.Patterns) { string path = Path.Combine(directory, "pat_" + pattern + ".csv"); project.Patterns.Add(BhePatternItem.ListFromFile(path)); } project.Comments.Add(string.Empty); foreach (string comment in project.Summary.Comments.Skip(1)) { string path = Path.Combine(directory, "com_" + comment + ".txt"); project.Comments.Add(File.ReadAllText(path, Encoding.Default)); } return(project); }
public static List <BheSection> ListFromFile(string fileName) { var sections = new List <BheSection>(); using (var file = new StreamReader(fileName)) { int count = int.Parse(file.ReadLine().Split(',')[0], CultureInfo.InvariantCulture); for (int i = 0; i < count; i++) { var section = new BheSection(); string[] parts = file.ReadLine().Split(','); section.Id = i + 1; section.Name = parts[0]; section.PatternId = int.Parse(parts[1], CultureInfo.InvariantCulture); section.BaseOffset = int.Parse(parts[2], CultureInfo.InvariantCulture); sections.Add(section); } } return(sections); }