Example #1
0
        void szReadUnPackInfo(SzData sd, out uint numFolders, out Folder[] folders )
        {
            //Console.WriteLine("szReadUnPackInfo >>>");
            szWaitAttribute( sd, EIdEnum.k7zIdFolder );
            numFolders = szReadNumber32( sd );
            //Console.WriteLine("numfolders: " + numFolders);
            szReadSwitch(sd);
            
            folders = new Folder[ numFolders ];

            for ( uint i = 0; i < numFolders; i++)
            {
                folders[i] = szGetNextFolderItem(sd);
                //Console.WriteLine(folders[i]);
            }
            
            szWaitAttribute( sd, EIdEnum.k7zIdCodersUnPackSize );

            for ( uint i = 0; i < numFolders; i++)
            {
                Folder folder = folders[i];
                uint numOutStreams = folder.GetNumOutStreams();

                folder.UnPackSizes = new ulong[numOutStreams];

                for ( uint j = 0; j < numOutStreams; j++)
                {
                    folder.UnPackSizes[j] = szReadSize(sd);
                    //Console.WriteLine("unpacksize: " + folder.UnPackSizes[j]);
                }
            }
            
            while( true )
            {
                EIdEnum type = szReadID( sd );
                //Console.WriteLine( "got type: " + type );
                if (type == EIdEnum.k7zIdEnd)
                {
                    //Console.WriteLine("szReadUnPackInfo <<<");
                    return;
                }
                if (type == EIdEnum.k7zIdCRC)
                {
                    bool[] crcsDefined;
                    uint[] crcs;
                    szReadHashDigests( sd, numFolders, out crcsDefined, out crcs );
                    for ( uint i = 0; i < numFolders; i++)
                    {
                        Folder folder = folders[i];
                        folder.UnPackCRCDefined = crcsDefined[i];
                        folder.UnPackCRC = crcs[i];
                    }
                    continue;
                }
                szSkeepData(sd);
            }
            //Console.WriteLine("szReadUnPackInfo <<<");
            //return;
        }
Example #2
0
        void szReadSubStreamsInfo( SzData sd, Folder[] folders,
            out uint numUnPackStreams, out ulong[] unPackSizes, out bool[] digestsDefined,
            out uint[] digests )
        {
            uint numDigests = 0;
            uint numFolders = Convert.ToUInt32( folders.GetUpperBound(0) + 1 );

            for ( uint i = 0; i < numFolders; i++)
            {
                folders[i].NumUnPackStreams = 1;
            }

            numUnPackStreams = numFolders;

            EIdEnum type = EIdEnum.k7zIdEnd;
            while( true )
            {
                type = szReadID(sd);
                //Console.WriteLine("ReadSubStreamsInfo, got type: " + type);
                if (type == EIdEnum.k7zIdNumUnPackStream)
                {
                    numUnPackStreams = 0;
                    for ( uint i = 0; i < numFolders; i++)
                    {
                        uint numStreams = szReadNumber32(sd);
                        folders[i].NumUnPackStreams = numStreams;
                        numUnPackStreams += numStreams;
                    }
                    continue;
                }
                if (type == EIdEnum.k7zIdCRC || type == EIdEnum.k7zIdSize)
                    break;
                if (type == EIdEnum.k7zIdEnd)
                    break;
                szSkeepData(sd );
            }

            unPackSizes = null;
            digestsDefined = null;
            digests = null;
            if (numUnPackStreams > 0)
            {
                unPackSizes = new ulong[numUnPackStreams];
                digestsDefined = new bool[numUnPackStreams];
                digests = new uint[numUnPackStreams];
                //*unPackSizes = (CFileSize*)allocTemp->Alloc((size_t) * numUnPackStreams * sizeof(CFileSize));
                //RINOM(*unPackSizes);
                //*digestsDefined = (Byte*)allocTemp->Alloc((size_t) * numUnPackStreams * sizeof(Byte));
                //RINOM(*digestsDefined);
                //*digests = (UInt32*)allocTemp->Alloc((size_t) * numUnPackStreams * sizeof(UInt32));
                //RINOM(*digests);
            }

            uint si = 0;
            for ( uint i = 0; i < numFolders; i++)
            {
                //
                //v3.13 incorrectly worked with empty folders
                //v4.07: we check that folder is empty
                //
                ulong sum = 0;
                uint numSubstreams = folders[i].NumUnPackStreams;
                if (numSubstreams == 0)
                    continue;
                if (type == EIdEnum.k7zIdSize)
                {
                    for ( uint j = 1; j < numSubstreams; j++)
                    {
                        ulong size = szReadSize( sd );
                        unPackSizes[si] = size;
                        sum += size;
                        si++;
                    }
                }
                unPackSizes[ si ] = folders[i].GetUnPackSize() - sum;
                //Console.Write("unpacksize[" + si + "] : " + unPackSizes[si]);
                si++;
                //(*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;
            }
            if (type == EIdEnum.k7zIdSize)
            {
                type = szReadID( sd );
                //Console.WriteLine("ReadSubStreamsInfo: 3, got type " + type);
            }

            for ( uint i = 0; i < numUnPackStreams; i++)
            {
                digestsDefined[i] = false;
                digests[i] = 0;
            }

            for ( uint i = 0; i < numFolders; i++)
            {
                uint numSubstreams = folders[i].NumUnPackStreams;
                if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)
                {
                    numDigests += numSubstreams;
                }
            }

            si = 0;
            while( true )
            {
                if (type == EIdEnum.k7zIdCRC)
                {
                    int digestIndex = 0;
                    bool[] digestsDefined2;
                    uint[] digests2;
                    szReadHashDigests(sd, numDigests, out digestsDefined2, out digests2);
                    for ( uint i = 0; i < numFolders; i++)
                    {
                        Folder folder = folders[i];
                        uint numSubstreams = folder.NumUnPackStreams;
                        if (numSubstreams == 1 && folder.UnPackCRCDefined)
                        {
                            digestsDefined[si] = true;
                            digests[si] = folder.UnPackCRC;
                            si++;
                        }
                        else
                        {
                            for (uint j = 0; j < numSubstreams; j++, digestIndex++)
                            {
                                digestsDefined[si] = digestsDefined2[digestIndex];
                                digests[si] = digests2[digestIndex];
                                si++;
                            }
                        }
                    }
                }
                else if (type == EIdEnum.k7zIdEnd)
                    return;
                else
                {
                    szSkeepData( sd );
                }
                type = szReadID( sd );
            }
        }
Example #3
0
        Folder szGetNextFolderItem(SzData sd)
        {
            Folder folder = new Folder();
            //Console.WriteLine("szGetNextFolderItem >>>");
            uint numCoders = szReadNumber32(sd);
            folder.NumCoders = numCoders;

            //Console.WriteLine("numcoders: " + numCoders);
            folder.Coders = new CoderInfo[numCoders];

            uint numInStreams = 0;
            uint numOutStreams = 0;

            for (uint i = 0; i < numCoders; i++)
            {
                CoderInfo coder = new CoderInfo();
                folder.Coders[i] = coder;
                byte mainByte = szReadByte(sd);
                coder.MethodID.IDSize = (byte)(mainByte & 0xF);
                coder.MethodID.ID = szReadBytes(sd, coder.MethodID.IDSize);
                if ((mainByte & 0x10) != 0)
                {
                    coder.NumInStreams = szReadNumber32(sd);
                    coder.NumOutStreams = szReadNumber32(sd);
                }
                else
                {
                    coder.NumInStreams = 1;
                    coder.NumOutStreams = 1;
                }
                if ((mainByte & 0x20) != 0)
                {
                    UInt64 propertiesSize = szReadNumber(sd);
                    coder.Properties = szReadBytes(sd, propertiesSize);
                }
                while ((mainByte & 0x80) != 0)
                {
                    mainByte = szReadByte(sd);
                    szSkeepDataSize(sd, (ulong)(mainByte & 0xF));
                    //RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));
                    if ((mainByte & 0x10) != 0)
                    {
                        //UInt32 n;
                        szReadNumber32(sd);
                        szReadNumber32(sd);
                    }
                    if ((mainByte & 0x20) != 0)
                    {
                        UInt64 propertiesSize = szReadNumber(sd);
                        szSkeepDataSize(sd, propertiesSize);
                    }
                }
                numInStreams += coder.NumInStreams;
                numOutStreams += coder.NumOutStreams;
                //Console.WriteLine(coder);
            }

            uint numBindPairs = numOutStreams - 1;
            folder.NumBindPairs = numBindPairs;

            //Console.WriteLine("numbindpairs: " + numBindPairs);
            folder.BindPairs = new BindPair[numBindPairs];

            for (uint i = 0; i < numBindPairs; i++)
            {
                BindPair bindpair = new BindPair();
                folder.BindPairs[i] = bindpair;
                //CBindPair *bindPair = folder->BindPairs + i;;
                bindpair.InIndex = szReadNumber32(sd);
                bindpair.OutIndex = szReadNumber32(sd);
                //Console.WriteLine("Bind pair: " + i + " " + bindpair.ToString());
            }

            uint numPackedStreams = numInStreams - numBindPairs;

            folder.NumPackStreams = numPackedStreams;
            folder.PackStreams = new uint[numPackedStreams];

            if (numPackedStreams == 1)
            {
                UInt32 pi = 0;
                for (uint j = 0; j < numInStreams; j++)
                {
                    if (folder.FindBindPairForInStream(j) < 0)
                    {
                        folder.PackStreams[pi++] = j;
                        break;
                    }
                }
            }
            else
            {
                for (uint i = 0; i < numPackedStreams; i++)
                {
                    folder.PackStreams[i] = szReadNumber32(sd);
                }
            }

            //Console.WriteLine("szGetNextFolderItem <<<");
            return folder;
        }