Beispiel #1
0
        public PatchPart ReadPart()
        {
            PatchPart     part       = new PatchPart();
            int           switchByte = 0;
            StringBuilder sb         = new StringBuilder();

            while ((switchByte = reader.BaseStream.ReadByte()) > 2)
            {
                sb.Append((char)switchByte);
            }

            if (switchByte == -1) //失败
            {
                return(null);
            }

            part.Type     = (PatchType)switchByte;
            part.FileName = sb.ToString();

            switch (part.Type)
            {
            case PatchType.Create:
                if (Path.HasExtension(part.FileName))
                {
                    part.FileLength = reader.ReadInt32();
                    part.Checksum   = reader.ReadUInt32();
                }
                break;

            case PatchType.Rebuild:
                part.OldChecksum = reader.ReadUInt32();
                part.Checksum    = reader.ReadUInt32();
                break;

            case PatchType.Delete:
                break;
            }

            return(part);
        }
Beispiel #2
0
        public void WritePart(PatchPart part)
        {
            this.deflateWriter.Write(part.FileName.ToCharArray());
            this.deflateWriter.Write((byte)part.Type); //尾部标识

            switch (part.Type)
            {
            case PatchType.Create:
                if (Path.HasExtension(part.FileName))
                {
                    this.deflateWriter.Write(part.FileLength);
                    this.deflateWriter.Write(part.Checksum);
                }
                break;

            case PatchType.Rebuild:
                this.deflateWriter.Write(part.OldChecksum);
                this.deflateWriter.Write(part.Checksum);
                break;

            case PatchType.Delete:
                break;
            }
        }