Ejemplo n.º 1
0
        public static Mbdb LoadFrom(this MbdbReader item, string path)
        {
            Mbdb result = default;

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                result = item.LoadFrom(stream);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static Mbdb LoadFrom(this MbdbReader item, byte[] data)
        {
            Mbdb result = default;

            using (var stream = new MemoryStream(data, false))
            {
                result = item.LoadFrom(stream);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static Mbdb LoadFrom(this MbdbReader item, Stream stream)
        {
            Mbdb result = default;

            using (var reader = new BinaryReader(stream))
            {
                result = item.LoadFrom(reader);
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static bool IsSupportedFormat(this Mbdb item)
        {
            bool result = false;

            if (string.Equals(MbdbConstants.MagicNumber, item.MagicNumber, StringComparison.OrdinalIgnoreCase) &&
                item.MajorVersion == 5 && item.MinorVersion == 0)
            {
                result = true;
            }

            return(result);
        }
Ejemplo n.º 5
0
        public Mbdb LoadFrom(BinaryReader reader)
        {
            Mbdb result = default;

            if (reader.BaseStream.Length >= MbdbConstants.MinimumViableLength)
            {
                result = new Mbdb();

                result.MagicNumber  = reader.ReadAsciiString(4);
                result.MajorVersion = reader.ReadByte();
                result.MinorVersion = reader.ReadByte();

                if (result.IsSupportedFormat())
                {
                    long length   = reader.BaseStream.Length;
                    long position = reader.BaseStream.Position;

                    var entries = new List <MbdbEntry>();

                    while (position < length)
                    {
                        var entry = ReadMbdbEntry(reader);

                        entries.Add(entry);

                        position = reader.BaseStream.Position;
                    }

                    if (entries.Count > 0)
                    {
                        result.Items = entries.ToArray();
                    }
                }
            }

            return(result);
        }