Esempio n. 1
0
        private static Stream ReadPackage(Stream input)
        {
            var magic = input.ReadValueU32(Endian.Little);
            if (magic != 0x9E2A83C1 &&
                magic.Swap() != 0x9E2A83C1)
            {
                throw new FormatException("not a package");
            }
            var endian = magic == 0x9E2A83C1
                             ? Endian.Little
                             : Endian.Big;

            var versionLo = input.ReadValueU16(endian);
            var versionHi = input.ReadValueU16(endian);

            if (versionLo != 684 &&
                versionHi != 194)
            {
                throw new FormatException("unsupported version");
            }

            input.Seek(4, SeekOrigin.Current);

            var folderNameLength = input.ReadValueS32(endian);
            var folderNameByteLength =
                folderNameLength >= 0 ? folderNameLength : (-folderNameLength * 2);
            input.Seek(folderNameByteLength, SeekOrigin.Current);

            /*var packageFlagsOffset = input.Position;*/
            var packageFlags = input.ReadValueU32(endian);

            if ((packageFlags & 8) != 0)
            {
                input.Seek(4, SeekOrigin.Current);
            }

            input.Seek(24, SeekOrigin.Current);

            if ((packageFlags & 0x02000000) == 0)
            {
                return input;
            }

            input.Seek(36, SeekOrigin.Current);

            var generationsCount = input.ReadValueU32(endian);
            input.Seek(generationsCount * 12, SeekOrigin.Current);

            input.Seek(20, SeekOrigin.Current);

            var blockCount = input.ReadValueU32(endian);

            var blockStream = new BlockStream(input);
            for (int i = 0; i < blockCount; i++)
            {
                var uncompressedOffset = input.ReadValueU32(endian);
                var uncompressedSize = input.ReadValueU32(endian);
                var compressedOffset = input.ReadValueU32(endian);
                var compressedSize = input.ReadValueU32(endian);
                blockStream.AddBlock(
                    uncompressedOffset,
                    uncompressedSize,
                    compressedOffset,
                    compressedSize);
            }

            return blockStream;
        }
Esempio n. 2
0
        private static Stream ReadPackage(Stream input)
        {
            var magic = input.ReadValueU32(Endian.Little);

            if (magic != 0x9E2A83C1 &&
                magic.Swap() != 0x9E2A83C1)
            {
                throw new FormatException("not a package");
            }
            var endian = magic == 0x9E2A83C1
                             ? Endian.Little
                             : Endian.Big;

            var versionLo = input.ReadValueU16(endian);
            var versionHi = input.ReadValueU16(endian);

            if (versionLo != 684 &&
                versionHi != 194)
            {
                throw new FormatException("unsupported version");
            }

            input.Seek(4, SeekOrigin.Current);

            var folderNameLength     = input.ReadValueS32(endian);
            var folderNameByteLength =
                folderNameLength >= 0 ? folderNameLength : (-folderNameLength * 2);

            input.Seek(folderNameByteLength, SeekOrigin.Current);

            /*var packageFlagsOffset = input.Position;*/
            var packageFlags = input.ReadValueU32(endian);

            if ((packageFlags & 8) != 0)
            {
                input.Seek(4, SeekOrigin.Current);
            }

            input.Seek(24, SeekOrigin.Current);

            if ((packageFlags & 0x02000000) == 0)
            {
                return(input);
            }

            input.Seek(36, SeekOrigin.Current);

            var generationsCount = input.ReadValueU32(endian);

            input.Seek(generationsCount * 12, SeekOrigin.Current);

            input.Seek(20, SeekOrigin.Current);

            var blockCount = input.ReadValueU32(endian);

            var blockStream = new BlockStream(input);

            for (int i = 0; i < blockCount; i++)
            {
                var uncompressedOffset = input.ReadValueU32(endian);
                var uncompressedSize   = input.ReadValueU32(endian);
                var compressedOffset   = input.ReadValueU32(endian);
                var compressedSize     = input.ReadValueU32(endian);
                blockStream.AddBlock(
                    uncompressedOffset,
                    uncompressedSize,
                    compressedOffset,
                    compressedSize);
            }

            return(blockStream);
        }