Ejemplo n.º 1
0
            private uint Flush(Stream oldStream, Stream patchFileStream, Stream bufferStream, Stream newStream, bool withCrc, uint crc)
            {
                Stream srcStream = null;

                if (this.bufferStartIndex > -1) //使用缓冲流
                {
                    srcStream = bufferStream;
                    srcStream.Seek(this.bufferStartIndex, SeekOrigin.Begin);
                }
                else //使用原始流
                {
                    switch (this.OperType)
                    {
                    case 0:
                        srcStream = patchFileStream;
                        break;

                    case 2:
                        srcStream = oldStream;
                        srcStream.Seek(this.StartPosition, SeekOrigin.Begin);
                        break;
                    }
                }

                //执行更新
                switch (this.OperType)
                {
                case 0:
                case 2:
                    if (withCrc)
                    {
                        crc = StreamUtils.MoveStreamWithCrc32(srcStream, newStream, this.Length, crc);
                    }
                    else
                    {
                        StreamUtils.CopyStream(srcStream, newStream, this.Length);
                    }
                    break;

                case 1:
                    if (withCrc)
                    {
                        crc = StreamUtils.FillStreamWithCrc32(newStream, this.Length, this.FillByte, crc);
                    }
                    else
                    {
                        StreamUtils.FillStream(newStream, this.Length, this.FillByte);
                    }
                    break;
                }
                return(crc);
            }