Пример #1
0
        private static Stream CreateDecoderStream(Stream[] packStreams, long[] packSizes, Stream[] outStreams, CFolder folderInfo, int coderIndex, IPasswordProvider pass)
        {
            int        num2;
            CCoderInfo info = folderInfo.Coders[coderIndex];

            if (info.NumOutStreams != 1)
            {
                throw new NotSupportedException("Multiple output streams are not supported.");
            }
            int inStreamIndex = 0;

            for (num2 = 0; num2 < coderIndex; num2++)
            {
                inStreamIndex += folderInfo.Coders[num2].NumInStreams;
            }
            int num3 = 0;

            for (num2 = 0; num2 < coderIndex; num2++)
            {
                num3 += folderInfo.Coders[num2].NumOutStreams;
            }
            Stream[] inStreams = new Stream[info.NumInStreams];
            num2 = 0;
            while (num2 < inStreams.Length)
            {
                int num4 = folderInfo.FindBindPairForInStream(inStreamIndex);
                if (num4 >= 0)
                {
                    int outIndex = folderInfo.BindPairs[num4].OutIndex;
                    if (outStreams[outIndex] != null)
                    {
                        throw new NotSupportedException("Overlapping stream bindings are not supported.");
                    }
                    int num6 = FindCoderIndexForOutStreamIndex(folderInfo, outIndex);
                    inStreams[num2] = CreateDecoderStream(packStreams, packSizes, outStreams, folderInfo, num6, pass);
                    if (outStreams[outIndex] != null)
                    {
                        throw new NotSupportedException("Overlapping stream bindings are not supported.");
                    }
                    outStreams[outIndex] = inStreams[num2];
                }
                else
                {
                    int index = folderInfo.FindPackStreamArrayIndex(inStreamIndex);
                    if (index < 0)
                    {
                        throw new NotSupportedException("Could not find input stream binding.");
                    }
                    inStreams[num2] = packStreams[index];
                }
                num2++;
                inStreamIndex++;
            }
            long limit = folderInfo.UnpackSizes[num3];

            return(DecoderRegistry.CreateDecoderStream(info.MethodId, inStreams, info.Props, pass, limit));
        }
Пример #2
0
 private static int FindCoderIndexForOutStreamIndex(CFolder folderInfo, int outStreamIndex)
 {
     for (int i = 0; i < folderInfo.Coders.Count; i++)
     {
         CCoderInfo info = folderInfo.Coders[i];
         outStreamIndex -= info.NumOutStreams;
         if (outStreamIndex < 0)
         {
             return(i);
         }
     }
     throw new InvalidOperationException("Could not link output stream to coder.");
 }