Ejemplo n.º 1
0
        public MSCabCompression(Stream stream)
        {
            this.stream = stream;

            var signature = stream.ReadASCII(4);
            if (signature != "MSCF")
                throw new InvalidDataException("Not a Microsoft CAB package!");

            stream.Position += 12;
            var filesOffset = stream.ReadUInt32();
            stream.Position += 6;
            var folderCount = stream.ReadUInt16();
            var fileCount = stream.ReadUInt16();
            if (stream.ReadUInt16() != 0)
                throw new InvalidDataException("Only plain packages (without reserved header space or prev/next archives) are supported!");

            stream.Position += 4;

            folders = new CabFolder[folderCount];
            for (var i = 0; i < folderCount; i++)
            {
                folders[i] = new CabFolder(stream);
                if (folders[i].CompressionType != 1)
                    throw new InvalidDataException("Compression type is not supported");
            }

            files = new CabFile[fileCount];
            stream.Seek(filesOffset, SeekOrigin.Begin);
            for (var i = 0; i < fileCount; i++)
                files[i] = new CabFile(stream);
        }
Ejemplo n.º 2
0
        public MSCabCompression(Stream stream)
        {
            this.stream = stream;

            var signature = stream.ReadASCII(4);

            if (signature != "MSCF")
            {
                throw new InvalidDataException("Not a Microsoft CAB package!");
            }

            stream.Position += 12;
            var filesOffset = stream.ReadUInt32();

            stream.Position += 6;
            var folderCount = stream.ReadUInt16();
            var fileCount   = stream.ReadUInt16();

            if (stream.ReadUInt16() != 0)
            {
                throw new InvalidDataException("Only plain packages (without reserved header space or prev/next archives) are supported!");
            }

            stream.Position += 4;

            folders = new CabFolder[folderCount];
            for (var i = 0; i < folderCount; i++)
            {
                folders[i] = new CabFolder(stream);
                if (folders[i].CompressionType != 1)
                {
                    throw new InvalidDataException("Compression type is not supported");
                }
            }

            files = new CabFile[fileCount];
            stream.Seek(filesOffset, SeekOrigin.Begin);
            for (var i = 0; i < fileCount; i++)
            {
                files[i] = new CabFile(stream);
            }
        }