Esempio n. 1
0
        /// <summary>
        /// Call this before calling decode
        /// This expects at least the header part of the delta file
        /// is available in the stream
        /// </summary>
        /// <returns></returns>
        public VCDiffResult Start()
        {
            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte V = delta.ReadByte();

            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte C = delta.ReadByte();

            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte D = delta.ReadByte();

            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte version = delta.ReadByte();

            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte hdr = delta.ReadByte();

            if (V != MagicBytes[0])
            {
                return(VCDiffResult.Error);
            }

            if (C != MagicBytes[1])
            {
                return(VCDiffResult.Error);
            }

            if (D != MagicBytes[2])
            {
                return(VCDiffResult.Error);
            }

            if (version != 0x00 && version != 'S')
            {
                return(VCDiffResult.Error);
            }

            //compression not supported
            if ((hdr & (int)VCDiffCodeFlags.VCDDECOMPRESS) != 0)
            {
                return(VCDiffResult.Error);
            }

            //custom code table!
            if ((hdr & (int)VCDiffCodeFlags.VCDCODETABLE) != 0)
            {
                if (!delta.CanRead)
                {
                    return(VCDiffResult.EOD);
                }

                //try decoding the custom code table
                //since we don't support the compress the next line should be the length of the code table
                customTable = new CustomCodeTableDecoder();
                VCDiffResult result = customTable.Decode(delta);

                if (result != VCDiffResult.Succes)
                {
                    return(result);
                }
            }

            IsSDHCFormat = version == 'S';

            IsStarted = true;

            //buffer all the dictionary up front
            dict.BufferAll();

            return(VCDiffResult.Succes);
        }