private DatFile(FileInfo file, Pak pak) { Pak = pak; SourceFile = file; var s = file.OpenRead(); var sr = new StreamReader(s); var contents = sr.ReadToEnd(); var lines = contents.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); _objects = ParseObjects(lines).ToList(); Objects = new ReadOnlyCollection<DatObject>(_objects); }
public static IEnumerable<DatFile> FindFilesRecursive(DirectoryInfo directory, Pak pak) { if (!directory.Exists) yield break; var thisDirectory = directory .GetFiles("*.dat") .Select(f => DatFile.Create(f, pak)) .Where(f => f != null); foreach (var file in thisDirectory) yield return file; foreach (var subDirectory in directory.GetDirectories()) foreach (var subDirectoryFile in FindFilesRecursive(subDirectory, pak)) yield return subDirectoryFile; }
/// <summary> /// Factory pattern to return null for invalid input. /// </summary> public static DatFile Create(FileInfo file, Pak pak) { try { if (!file.Exists) return null; var instance = new DatFile(file, pak); return instance; } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return null; } }
public static IEnumerable<DatFile> FindFilesRecursive(string directory, Pak pak) { return FindFilesRecursive(new DirectoryInfo(directory), pak); }
public DatObject(Dictionary<string, string> elements, Pak pak, DatFile file) { Pak = pak; DatFile = file; _dictionary = elements.ToDictionary(x => (string)x.Key, x => (string)x.Value); }
public static IEnumerable<DatObject> FindObjectsRecursive(DirectoryInfo directory, Pak pak) { var files = DatFile.FindFilesRecursive(directory, pak); return files.SelectMany(f => f.Objects); }