Exemplo n.º 1
0
        private void ReadMipMapsContent(Stream stream, IList <TgvMipMap> mipMaps, bool compressed)
        {
            for (int i = 0; i < mipMaps.Count; i++)
            {
                var buffer = new byte[4];

                stream.Seek(mipMaps[i].Offset, SeekOrigin.Begin);

                if (compressed)
                {
                    stream.Read(buffer, 0, buffer.Length);
                    if (!MiscUtilities.ComparerByteArrays(buffer, ZIPO))
                    {
                        throw new InvalidDataException("Mipmap has to start with \"ZIPO\"!");
                    }

                    stream.Read(buffer, 0, buffer.Length);
                    mipMaps[i].MipSize = (uint)BitConverter.ToInt32(buffer, 0); //Tu nie by³o rzutowania
                }

                // odejmujemy 8 bo rozmiar zawiera 8 bajtów dodatkowych, 4 magii i 4 rozmiaru mipampy
                buffer = new byte[mipMaps[i].Length - 8];
                stream.Read(buffer, 0, buffer.Length);

                if (compressed)
                {
                    ICompressor comp = new ZlibCompressor();
                    buffer = comp.Decompress(buffer);
                }

                mipMaps[i].Content = buffer;
            }
        }
        protected ContentFileType ResolveFileType(byte[] binData)
        {
            foreach (var containerType in KnownContainerTypes)
            {
                if (MiscUtilities.ComparerByteArrays(
                        containerType.MagicBytes,
                        binData.Take(containerType.MagicBytes.Length).ToArray()))
                {
                    return(containerType);
                }
            }

            return(ContentFileType.Unknown);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="headerData"></param>
        /// <returns></returns>
        protected ContentFileType GetFileTypeFromHeaderData(byte[] headerData)
        {
            foreach (var knownType in KnownContentFileTypes)
            {
                byte[] headerMagic = new byte[knownType.Value.Length];
                Array.Copy(headerData, headerMagic, knownType.Value.Length);

                if (MiscUtilities.ComparerByteArrays(headerMagic, knownType.Value))
                {
                    return(knownType.Key);
                }
            }

            return(ContentFileType.Unknown);
        }