Exemplo n.º 1
0
        public static void ReadSubStreamsInfo(BinaryReader br, ref Folder[] Folders)
        {
            for (; ;)
            {
                HeaderProperty hp = (HeaderProperty)br.ReadByte();
                switch (hp)
                {
                case HeaderProperty.kNumUnPackStream:
                {
                    for (int f = 0; f < Folders.Length; f++)
                    {
                        int numStreams = (int)br.ReadEncodedUInt64();
                        Folders[f].UnpackedStreamInfo = new UnpackedStreamInfo[numStreams];
                        for (int i = 0; i < numStreams; i++)
                        {
                            Folders[f].UnpackedStreamInfo[i] = new UnpackedStreamInfo();
                        }
                    }

                    continue;
                }

                case HeaderProperty.kSize:
                {
                    for (int f = 0; f < Folders.Length; f++)
                    {
                        Folder folder = Folders[f];

                        if (folder.UnpackedStreamInfo.Length == 0)
                        {
                            continue;
                        }

                        ulong sum = 0;
                        for (int i = 0; i < folder.UnpackedStreamInfo.Length - 1; i++)
                        {
                            ulong size = br.ReadEncodedUInt64();
                            folder.UnpackedStreamInfo[i].UnpackedSize = size;
                            sum += size;
                        }

                        folder.UnpackedStreamInfo[folder.UnpackedStreamInfo.Length - 1].UnpackedSize =
                            folder.GetUnpackSize() - sum;
                    }

                    continue;
                }

                case HeaderProperty.kCRC:
                {
                    ulong numCRC = 0;
                    foreach (Folder folder in Folders)
                    {
                        if (folder.UnpackedStreamInfo == null)
                        {
                            folder.UnpackedStreamInfo    = new UnpackedStreamInfo[1];
                            folder.UnpackedStreamInfo[0] = new UnpackedStreamInfo();
                            folder.UnpackedStreamInfo[0].UnpackedSize = folder.GetUnpackSize();
                        }

                        if ((folder.UnpackedStreamInfo.Length != 1) || !folder.UnpackCRC.HasValue)
                        {
                            numCRC += (ulong)folder.UnpackedStreamInfo.Length;
                        }
                    }

                    int     crcIndex = 0;
                    uint?[] crc;
                    Util.UnPackCRCs(br, numCRC, out crc);
                    for (uint i = 0; i < Folders.Length; i++)
                    {
                        Folder folder = Folders[i];
                        if ((folder.UnpackedStreamInfo.Length == 1) && folder.UnpackCRC.HasValue)
                        {
                            folder.UnpackedStreamInfo[0].Crc = folder.UnpackCRC;
                        }
                        else
                        {
                            for (uint j = 0; j < folder.UnpackedStreamInfo.Length; j++, crcIndex++)
                            {
                                folder.UnpackedStreamInfo[j].Crc = crc[crcIndex];
                            }
                        }
                    }

                    continue;
                }

                case HeaderProperty.kEnd:
                    return;

                default:
                    throw new Exception(hp.ToString());
                }
            }
        }
Exemplo n.º 2
0
        public static void ReadUnPackInfo(BinaryReader br, out Folder[] Folders)
        {
            Folders = null;
            for (; ;)
            {
                HeaderProperty hp = (HeaderProperty)br.ReadByte();
                switch (hp)
                {
                case HeaderProperty.kFolder:
                {
                    ulong numFolders = br.ReadEncodedUInt64();

                    Folders = new Folder[numFolders];

                    byte external = br.ReadByte();
                    switch (external)
                    {
                    case 0:
                    {
                        ulong folderIndex = 0;
                        for (uint i = 0; i < numFolders; i++)
                        {
                            Folders[i] = new Folder();
                            Folders[i].ReadFolder(br);
                            Folders[i].PackedStreamIndexBase = folderIndex;
                            folderIndex += (ulong)Folders[i].PackedStreamIndices.Length;
                        }

                        break;
                    }

                    case 1:
                        throw new NotSupportedException("External flag");
                    }

                    continue;
                }


                case HeaderProperty.kCodersUnPackSize:
                {
                    for (uint i = 0; i < Folders.Length; i++)
                    {
                        Folders[i].ReadUnpackedStreamSize(br);
                    }

                    continue;
                }

                case HeaderProperty.kCRC:
                {
                    uint?[] crcs;
                    Util.UnPackCRCs(br, (ulong)Folders.Length, out crcs);
                    for (int i = 0; i < Folders.Length; i++)
                    {
                        Folders[i].UnpackCRC = crcs[i];
                    }

                    continue;
                }

                case HeaderProperty.kEnd:
                    return;

                default:
                    throw new Exception(hp.ToString());
                }
            }
        }