Esempio n. 1
0
        private static bool WriteXyzHeadVer01(System.IO.Stream stream, XyzHeadReader xyzHead)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (xyzHead == null)
            {
                throw new ArgumentNullException("xyzHead");
            }

            byte[] byteULong = new byte[8];

            // 00 ~ 03: 标识符号 : 是否是XYZ的标识(写入)
            stream.Write(xyzHead.Tag, 0, xyzHead.Tag.Length);

            // 03 ~ 04: XYZ文件版本号(写入)
            stream.WriteByte((byte)xyzHead.Version);

            // 04 ~ 05: XYZ文件内实体名称的加密方式 ( 0 为无加密, 1... 为其它加密方式 )(写入)
            stream.WriteByte((byte)xyzHead.EncryptType);

            // 05 ~ 13: 主评论信息的文件偏移(写入)
            xyzHead.CommentOffset.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 13 ~ 21: 第一个XYZ文件内实体的文件偏移(写入)
            xyzHead.FirstEntryOffset.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // XYZ文件内实体评论的信息(写入)
            if (xyzHead.CommentReader == null)
            {
                if (xyzHead.CommentOffset > 0)
                {
                    throw new ArgumentException("xyzHead.CommentReader == null && xyzHead.CommentOffset > 0 error!", "xyzComment.CommentReader & xyzComment.CommentOffset");
                }
                else
                {
                    return(true);
                }
            }

            stream.Seek((long)xyzHead.CommentOffset, SeekOrigin.Begin);
            XyzCommentWriter.WriteComment(stream, xyzHead.CommentReader);

            return(true);
        }
Esempio n. 2
0
        private static bool WriteEntryVer01(System.IO.Stream stream, XyzEntryReader xyzEntry)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (xyzEntry == null)
            {
                throw new ArgumentNullException("xyzEntry");
            }

            byte[] byteULong = new byte[8];

            // 000 ~ 001: 标识符号 : 是否是XYZ文件内实体的标识 ( 0x01 标识为XYZ文件内的实体 )(写入)
            stream.WriteByte(xyzEntry.Tag);

            // 001 ~ 002: XYZ文件内实体的版本号 ( 当前支持 0x01 版本 )(写入)
            stream.WriteByte((byte)xyzEntry.Version);

            // 002 ~ 010: XYZ文件内实体的唯一序号 ( 1... 以后的数字 )(写入)
            xyzEntry.EntryId.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 010 ~ 012: XYZ文件内实体名称的有效长度(写入)
            xyzEntry.NameLength.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 012 ~ 028: 校验原XYZ文件内实体名称的CRC字节码(写入)
            stream.Write(xyzEntry.NameCrc, 0, xyzEntry.NameCrc.Length);

            // 028 ~ 029: XYZ文件内实体的加密方式 ( 0 为无加密, 1... 为其它加密方式 )(写入)
            stream.WriteByte((byte)xyzEntry.EncryptType);

            // 029 ~ 030: XYZ文件内实体的压缩方式 ( 0xFF 为该XYZ文件内实体信息已删除, 0 为无压缩, 1... 为其它压缩方式 )(写入)
            stream.WriteByte((byte)xyzEntry.CompressionType);

            // 030 ~ 031: XYZ文件内实体的压缩等级 ( 0 为默认, 1... 为其它压缩等级 )(写入)
            stream.WriteByte(xyzEntry.CompressionLevel);

            // 031 ~ 039: XYZ文件内实体被压缩后的有效长度 ( 0 是目录或0字节文件 ) ( 如果该XYZ文件内实体已删除,当有新增的XYZ文件内实体压缩后的有效长度小于此评论信息的有效长度则覆盖掉此评论信息,然后在此评论信息尾部新增一个新的空XYZ文件内实体来填充剩余的字节 )(写入)
            xyzEntry.CompressedLength.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 039 ~ 047: XYZ文件内原文件的有效长度 ( 当压缩后的有效长度等于0时,值为0x0000000000000000是个0字节文件,值为0xFFFFFFFFFFFFFFFF是个目录文件)(写入)
            xyzEntry.UncompressedLength.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 039 ~ 047: XYZ文件内原文件的有效长度 ( 当压缩后的有效长度等于0时,值为0x0000000000000000是个0字节文件,值为0xFFFFFFFFFFFFFFFF是个目录文件)(写入)
            xyzEntry.UncompressedLength.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 047 ~ 055: XYZ文件内原文件的修改日期(写入)
            xyzEntry.DateTime.ToFileTimeUtc().ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 055 ~ 071: 原XYZ文件内实体的CRC校验字节码(写入)
            stream.Write(xyzEntry.Crc, 0, xyzEntry.Crc.Length);

            // 071 ~ 079: XYZ文件内实体评论信息的文件偏移 ( 0 为该评论信息不存在 )(写入)
            xyzEntry.CommentOffset.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 071 ~ 079: XYZ文件内实体评论信息的文件偏移 ( 0 为该评论信息不存在 )(写入)
            xyzEntry.CommentOffset.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 079 ~ 087: 下一个XYZ文件内实体的文件偏移 ( 0 为下一个XYZ文件内实体信息已不存在 )(写入)
            xyzEntry.NextEntryOffset.ToArrayInByte(ref byteULong, 0);
            stream.Write(byteULong, 0, byteULong.Length);

            // 087 ~ ...: XYZ文件内实体名称的字节(写入)
            if (xyzEntry.NameData == null)
            {
                if (xyzEntry.NameLength > 0)
                {
                    throw new ArgumentException("xyzComment.CompressedData == null && xyzComment.CompressedData.Length > 0 error!", "xyzComment.CompressedData & xyzComment.CompressedLength");
                }
            }
            else
            {
                if (xyzEntry.NameLength > (ulong)xyzEntry.NameData.Length)
                {
                    throw new ArgumentException("xyzComment.CompressedLength > xyzComment.CompressedData.Length error!", "xyzComment.CompressedData & xyzComment.CompressedLength");
                }

                stream.Write(xyzEntry.NameData, 0, (int)xyzEntry.NameLength);
            }

            // ... ~ ???: XYZ文件内实体信息被压缩后的字节(写入)
            if (xyzEntry.CompressedData == null)
            {
                if (xyzEntry.CompressedLength > 0)
                {
                    throw new ArgumentException("xyzComment.CompressedData == null && xyzComment.CompressedData.Length > 0 error!", "xyzComment.CompressedData & xyzComment.CompressedLength");
                }
                else
                {
                    return(true);
                }
            }

            if (xyzEntry.CompressedLength > (ulong)xyzEntry.CompressedData.Length)
            {
                throw new ArgumentException("xyzComment.CompressedLength > xyzComment.CompressedData.Length error!", "xyzComment.CompressedData & xyzComment.CompressedLength");
            }

            stream.Write(xyzEntry.CompressedData, 0, (int)xyzEntry.CompressedLength);

            // XYZ文件内实体评论的信息(写入)
            if (xyzEntry.CommentReader == null)
            {
                if (xyzEntry.CommentOffset > 0)
                {
                    throw new ArgumentException("xyzEntry.CommentReader == null && xyzEntry.CommentOffset > 0 error!", "xyzEntry.CommentReader & xyzEntry.CommentOffset");
                }
            }

            stream.Seek((long)xyzEntry.CommentOffset, SeekOrigin.Begin);
            XyzCommentWriter.WriteComment(stream, xyzEntry.CommentReader);

            return(false);
        }