private IFormat ReadSimple(Structures.Meta.FileInfo file)
        {
            if (!_options.IncludeUnsupportedAndInvalidFiles)
            {
                return(null);
            }

            return(new SimpleFormat()
            {
                FileName = file.Name,
                FileInfo = _readFileInfo ? file : null
            });
        }
        private IFormat ReadMeta <T>(Stream stream, Structures.Meta.FileInfo file) where T : Format, Structures.Meta.IMetaFormat
        {
            if (stream.CanRead)
            {
                T format = (T)Activator.CreateInstance(typeof(T), file.Name, Build.Build, stream);
                if (_readFileInfo)
                {
                    format.FileInfo = file;
                }

                return(format);
            }

            return(ReadSimple(file));
        }
        public IFormat Read(Stream stream, Structures.Meta.FileInfo file)
        {
            stream.Position = 0;

            try
            {
                if (_readData && _readers.TryGetValue(file.Format, out var readerFunc))
                {
                    return(readerFunc.Invoke(stream, file));
                }
            }
            catch (System.Reflection.TargetInvocationException) { }
            catch (EndOfStreamException) { }

            return(ReadSimple(file));
        }
        private IFormat ReadVersioned <T>(Stream stream, Structures.Meta.FileInfo file) where T : Format, IVersioned
        {
            if (stream.CanRead)
            {
                using var br = new BinaryReader(stream);
                T chunked = (T)Activator.CreateInstance(typeof(T), br, Build.Build);
                chunked.FileName = file.Name;
                if (_readFileInfo)
                {
                    chunked.FileInfo = file;
                }

                return(chunked);
            }

            return(ReadSimple(file));
        }
        private IFormat ReadFormat <T>(Stream stream, Structures.Meta.FileInfo file) where T : Format
        {
            if (stream.CanRead)
            {
                using var br = new BinaryReader(stream);
                T format = (T)Activator.CreateInstance(typeof(T), br);
                format.FileName = file.Name;
                if (_readFileInfo)
                {
                    format.FileInfo = file;
                }

                return(format);
            }

            return(ReadSimple(file));
        }
        public IFormat Read(string filename)
        {
            var entry = new Structures.Meta.FileInfo()
            {
                Build = Build.Build,
                Name  = filename.WoWNormalize()
            };

            using var md5    = MD5.Create();
            using var stream = File.OpenRead(filename);
            if (_readFileInfo)
            {
                entry.Checksum = md5.ComputeHash(stream).ToChecksum();
                entry.Created  = Utils.GetLocalFileCreated(filename);
                entry.Size     = (uint)stream.Length;
            }

            return(Read(stream, entry));
        }