public void Pack(PackagingInfo info, string outputFilePath)
        {
            // 创建额外数据块
            string extraDataFile = PathUtil.GetTempRandomFile(".tmp");

            using (var outputStream = System.IO.File.OpenWrite(extraDataFile))
            {
                // 封装基本信息
                WriteBaseInfo(outputStream, info);
                using (var writer = new BinaryWriter(outputStream))
                {
                    // 封装文件
                    WriteFile(writer, info.Option, info.Files);
                    // 写入随机序列
                    WriteRandomBytes(writer, info.Option);
                }
            }
            // 删除已存在的目标文件
            if (System.IO.File.Exists(outputFilePath))
            {
                System.IO.File.Delete(outputFilePath);
            }
            // 生成文件
            string templeteFile = PathUtil.GetEntryFileDir() + "\\ZZLH.PackagingTool.Execution.exe";

            using (var fs = System.IO.File.OpenWrite(outputFilePath))
            {
                // 写入模板数据
                long extraDataPos = CopyTo(templeteFile, fs);
                // 写入额外数据
                CopyTo(extraDataFile, fs);
                // 写入额外数据开始位置
                fs.Write(BitConverter.GetBytes, extraDataPos);
            }
        }
 public void SaveProject(PackagingInfo info, string outputFilePath)
 {
     // 删除已存在的目标文件
     if (System.IO.File.Exists(outputFilePath))
     {
         System.IO.File.Delete(outputFilePath);
     }
     using (var outputStream = System.IO.File.OpenWrite(outputFilePath))
     {
         // 封装基本信息
         WriteBaseInfo(outputStream, info);
     }
 }
        public PackagingInfo UnPack(string file)
        {
            PackagingInfo info = null;

            using (var fs = System.IO.File.OpenRead(file))
            {
                // 读取额外数据块的开始位置
                fs.Seek(fs.Length - 8, SeekOrigin.Begin);
                long extraDataPos = fs.Read(BitConverter.ToInt64, 8);
                fs.Seek(extraDataPos, SeekOrigin.Begin);
                // 读取基本信息
                info = ReadBaseInfo(fs, true);
                using (var br = new BinaryReader(fs))
                {
                    // 读取文件
                    ReadFile(br, info.Option, info.Files);
                    // 读取随机字节序列
                    ReadRandomBytes(br, info.Option);
                }
            }

            return(info);
        }
        private void WriteBaseInfo(Stream stream, PackagingInfo info)
        {
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(stream, info);
        }