Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        /// <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;
            }
        }
Esempio n. 4
0
 public static IEnumerable<DatFile> FindFilesRecursive(string directory, Pak pak)
 {
     return FindFilesRecursive(new DirectoryInfo(directory), pak);
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 public static IEnumerable<DatObject> FindObjectsRecursive(DirectoryInfo directory, Pak pak)
 {
     var files = DatFile.FindFilesRecursive(directory, pak);
     return files.SelectMany(f => f.Objects);
 }