示例#1
0
        private void Save(Stream stream)
        {
            using BinaryWriter bw = new BinaryWriter(stream, Encoding.UTF8, true);
            bw.Write(FullPath ?? "");
            bw.Write((long)fileSize);
            //保存xml文件
            bw.Write(0);
            long start = stream.Position;

            xml.Save(stream);
            long end    = stream.Position;
            int  length = Convert.ToInt32(end - start);

            if (length > 0)
            {
                stream.Position = start - 4;
                bw.Write(length);
                stream.Position = end;
            }
            bool isnull = lines == null;

            bw.Write(isnull);
            if (!isnull)
            {
                //保存未翻译完的行
                bw.Write(lines.Count);
                IReadWriter <XmlFileOfVSLine> readWriter = XmlFileOfVSLine.GetLineReadWriter(null);
                foreach (ITranslatingLine line in lines)
                {
                    if (line is XmlFileOfVSLine vsLine)
                    {
                        readWriter.Write(stream, vsLine);
                    }
                }
            }
            bw.Flush();
        }
示例#2
0
        /// <summary>
        /// 从指定的流的当前位置加载数据。
        /// </summary>
        /// <param name="stream"></param>
        private void Load(Stream stream)
        {
            using BinaryReader br = new BinaryReader(stream, Encoding.UTF8, true);
            FullPath = br.ReadString();
            IsFile   = !string.IsNullOrWhiteSpace(FullPath);
            fileSize = (FileSize)br.ReadInt64();
            int length = br.ReadInt32();

            if (length == 0)
            {
                fileSize = 0;
            }
            else
            {
                byte[] date = new byte[length];
                stream.Read(date, 0, date.Length);
                using MemoryStream xmlStream = new MemoryStream(date);
                xml.Load(xmlStream);
                fileSize = (FileSize)stream.Length;
            }
            bool isnull = br.ReadBoolean();

            if (isnull)
            {
                lines = null;
            }
            else
            {
                length = br.ReadInt32();
                lines  = new List <ITranslatingLine>(length);
                IReadWriter <XmlFileOfVSLine> readWriter = XmlFileOfVSLine.GetLineReadWriter(this);
                for (int i = 0; i < length; i++)
                {
                    lines.Add(readWriter.Read(stream));
                }
            }
        }