示例#1
0
        public bool OpenXyz(string zipFileName)
        {
            if (File.Exists(zipFileName) == false)
            {
                return(false);
            }

            try
            {
                m_XyzFileStream = File.Open(zipFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
            }
            catch
            {
                if (m_XyzFileStream != null)
                {
                    m_XyzFileStream.Close();
                    m_XyzFileStream = null;
                }
            }

            if (m_XyzFileStream == null)
            {
                return(false);
            }

            m_XyzHeadReader = XyzHeadReader.ReadXyzHead(m_XyzFileStream);
            if (m_XyzHeadReader == null)
            {
                m_XyzFileStream.Close();
                m_XyzFileStream = null;
                return(false);
            }

            return(true);
        }
示例#2
0
        public void Close()
        {
            if (m_XyzFileStream == null)
            {
                return;
            }

            m_XyzFileStream.Flush();
            m_XyzFileStream.Close();
            m_XyzFileStream = null;
            m_XyzHeadReader = null;
        }
        public static bool WriteXyzHead( System.IO.Stream stream, XyzHeadReader xyzHead )
        {
            switch ( xyzHead.Version )
            {
                case XyzHeadVersion.XyzHeadVer01:

                    return WriteXyzHeadVer01( stream, xyzHead );
                default:
                    break;
            }

            return false;
        }
示例#4
0
        public static bool WriteXyzHead(System.IO.Stream stream, XyzHeadReader xyzHead)
        {
            switch (xyzHead.Version)
            {
            case XyzHeadVersion.XyzHeadVer01:

                return(WriteXyzHeadVer01(stream, xyzHead));

            default:
                break;
            }

            return(false);
        }
示例#5
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);
        }
        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;
        }
示例#7
0
        private static XyzHeadReader ReadXyzHeadVer01(System.IO.Stream stream)
        {
            XyzHeadReader xyzCommentReader = new XyzHeadReader();

            xyzCommentReader.m_HeadTag     = XyzHeadReader.XYZ_HEAD_TAG;
            xyzCommentReader.m_HeadVersion = XyzHeadVersion.XyzHeadVer01;

            // 04 ~ 05: XYZ文件内实体名称的加密方式 ( 0 为无加密, 1... 为其它加密方式 )(读取)
            int iEncryptType = stream.ReadByte();

            if (iEncryptType > (int)XyzHeadEncrypt.MaxValue)
            {
                return(null);
            }
            else
            {
                xyzCommentReader.m_EncryptType = (XyzHeadEncrypt)iEncryptType;
            }

            switch (xyzCommentReader.EncryptType)
            {
            case XyzHeadEncrypt.None:

                break;

            case XyzHeadEncrypt.Aes:

                break;

            case XyzHeadEncrypt.Des:

                break;

            case XyzHeadEncrypt.RC2:

                break;

            case XyzHeadEncrypt.Rijndael:

                break;

            case XyzHeadEncrypt.TripleDes:

                break;

            default:

                return(null);
            }

            byte[] byteULong = new byte[8];

            // 05 ~ 13: 主评论信息的文件偏移(读取)
            int iCount = stream.Read(byteULong, 0, byteULong.Length);

            if (iCount != byteULong.Length)
            {
                return(null);
            }
            else
            {
                xyzCommentReader.m_CommentOffset = byteULong.ConvertToUInt64();
            }

            // 13 ~ 21: 第一个XYZ文件内实体的文件偏移(读取)
            iCount = stream.Read(byteULong, 0, byteULong.Length);
            if (iCount != byteULong.Length)
            {
                return(null);
            }
            else
            {
                xyzCommentReader.m_FirstEntryOffset = byteULong.ConvertToUInt64();
            }


            if (xyzCommentReader.CommentOffset == 0)
            {
                return(xyzCommentReader);
            }
            else if ((ulong)stream.Length < xyzCommentReader.CommentOffset)
            {
                return(null);
            }
            else
            {
                stream.Seek((long)xyzCommentReader.CommentOffset, System.IO.SeekOrigin.Begin);

                // 13 ~ ..: 其它XYZ文件内实体或评论信息的数据(读取)
                xyzCommentReader.m_CommentReader = XyzCommentReader.GetXyzComment(stream);
            }

            return(xyzCommentReader);
        }
        private static XyzHeadReader ReadXyzHeadVer01( System.IO.Stream stream )
        {
            XyzHeadReader xyzCommentReader = new XyzHeadReader();
            xyzCommentReader.m_HeadTag = XyzHeadReader.XYZ_HEAD_TAG;
            xyzCommentReader.m_HeadVersion = XyzHeadVersion.XyzHeadVer01;

            // 04 ~ 05: XYZ文件内实体名称的加密方式 ( 0 为无加密, 1... 为其它加密方式 )(读取)
            int iEncryptType = stream.ReadByte();
            if ( iEncryptType > (int)XyzHeadEncrypt.MaxValue )
                return null;
            else
                xyzCommentReader.m_EncryptType = (XyzHeadEncrypt)iEncryptType;

            switch ( xyzCommentReader.EncryptType )
            {
                case XyzHeadEncrypt.None:

                    break;
                case XyzHeadEncrypt.Aes:

                    break;
                case XyzHeadEncrypt.Des:

                    break;
                case XyzHeadEncrypt.RC2:

                    break;
                case XyzHeadEncrypt.Rijndael:

                    break;
                case XyzHeadEncrypt.TripleDes:

                    break;
                default:

                    return null;
            }

            byte[] byteULong = new byte[8];

            // 05 ~ 13: 主评论信息的文件偏移(读取)
            int iCount = stream.Read( byteULong, 0, byteULong.Length );
            if ( iCount != byteULong.Length )
                return null;
            else
                xyzCommentReader.m_CommentOffset = byteULong.ConvertToUInt64();

            // 13 ~ 21: 第一个XYZ文件内实体的文件偏移(读取)
            iCount = stream.Read( byteULong, 0, byteULong.Length );
            if ( iCount != byteULong.Length )
                return null;
            else
                xyzCommentReader.m_FirstEntryOffset = byteULong.ConvertToUInt64();


            if ( xyzCommentReader.CommentOffset == 0 )
                return xyzCommentReader;
            else if ( (ulong)stream.Length < xyzCommentReader.CommentOffset )
                return null;
            else
            {
                stream.Seek( (long)xyzCommentReader.CommentOffset, System.IO.SeekOrigin.Begin );

                // 13 ~ ..: 其它XYZ文件内实体或评论信息的数据(读取)
                xyzCommentReader.m_CommentReader = XyzCommentReader.GetXyzComment( stream );
            }

            return xyzCommentReader;
        }