Beispiel #1
0
 /// <summary>
 /// 保存并解压更新文件
 /// </summary>
 string SaveAndExtractZip(byte[] bytes, string zipFilePath, string updateFile, double progress)
 {
     if (!Directory.Exists(zipFilePath))
         Directory.CreateDirectory(zipFilePath);
     var zipFile = Path.Combine(zipFilePath, updateFile);
     using (BinaryWriter writer = new BinaryWriter(new FileStream(zipFile, FileMode.OpenOrCreate)))
     {
         writer.Write(bytes);
         writer.Flush();
         writer.Close();
     }
     var extractPath = Path.Combine(zipFilePath, "extract");
     FastZipEvents events = new FastZipEvents();
     //events.CompletedFile = (sender, e) =>
     //{
     //    MainWindow.AppendInfo(Properties.Resources.ExtractedFile + ":" + e.Name);
     //};
     double value = 0;
     events.TotalProgress = (sender, e) =>
     {
         var i = e.PercentComplete * progress / 100 - value;
         value = e.PercentComplete * progress / 100;
         MainWindow.UpdateProgress(i);
     };
     FastZip zip = new FastZip(events);
     zip.ExtractZip(zipFile, extractPath, "");
     return extractPath;
 }
 void DownloadAndExtractFile(IList<Manifest.ModuleInfo> newer)
 {
     double x = 80 / Math.Max(1, newer.Count());
     int progress = 10;
     foreach (var module in newer)
     {
         OnDownloadProgressChanged(new ModuleDownloadProgressChangedEventArgs(progress));
         List<string> extractFiles = new List<string>();
         double y = x / Math.Max(1, module.Files.Count());
         foreach (var file in module.Files)
         {
             var data = DownloadFile(file, progress, (int)y);
             var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, m_UpdateFileFolder, Guid.NewGuid().ToString("N"));
             if (!Directory.Exists(filePath))
                 Directory.CreateDirectory(filePath);
             var savedFile = Path.Combine(filePath, file);
             using (BinaryWriter writer = new BinaryWriter(new FileStream(savedFile, FileMode.OpenOrCreate)))
             {
                 writer.Write(data);
                 writer.Flush();
                 writer.Close();
             }
             var extractPath = Path.Combine(filePath, "extract");
             FastZipEvents events = new FastZipEvents();
             FastZip zip = new FastZip(events);
             zip.ExtractZip(savedFile, extractPath, "");
             extractFiles.AddRange(CopyDirectory(extractPath, AppDomain.CurrentDomain.BaseDirectory));
             progress = (int)(progress + y);
             OnDownloadProgressChanged(new ModuleDownloadProgressChangedEventArgs(progress));
         }
         module.Files.Clear();
         module.Files.AddRange(extractFiles);
     }
 }
Beispiel #3
0
		/// <summary>
		/// Initialise a new instance of <see cref="FastZip"/>
		/// </summary>
		/// <param name="events">The <see cref="FastZipEvents">events</see> to use during operations.</param>
		public FastZip(FastZipEvents events)
		{
			events_ = events;
		}
Beispiel #4
0
        //创建信息的具体操作函数
        private void CreatePackage(object sender, RunworkEventArgs e)
        {
            var info = new UpdateInfo
                           {
                               AppName = txtAppName.Text,
                               AppVersion = txtAppVersion.Text,
                               Desc = txtDesc.Text,
                               ExecuteArgumentAfter = txtAfterExecuteArgs.Text,
                               ExecuteArgumentBefore = txtPreExecuteArgs.Text,
                               PublishUrl = txtPublishUrl.Text,
                               FileExecuteAfter = fileAfterExecute.SelectedFileName,
                               FileExecuteBefore = filePreExecute.SelectedFileName,
                               MD5 = "",
                               Package = Path.GetFileName(txtPackagePath.Text),
                               ExecuteTimeout = txtTimeout.Text.ToInt32(),
                               PackageSize = 0,
                               RequiredMinVersion = ""
                           };
            options.SaveSetting(info);

            var evt = new FastZipEvents();
            evt.ProcessFile += (s, f) => e.ReportProgress(0, 0, "正在压缩文件 " + Path.GetFileName(f.Name));
            var zip = new FastZip(evt);
            if (!info.PackagePassword.IsNullOrEmpty()) zip.Password = info.PackagePassword;
            //zip.CreateZip(this.txtPackagePath.Text, this.txtNewSoftDir.Text, true, "");

            if (ckbModifyTime.Checked)
            {
                IScanFilter df = new DateTimeFilter(DateTime.Parse(dateTimePicker1.Text));
                zip.CreateZip(File.Create(txtPackagePath.Text), txtNewSoftDir.Text, true, df, null);
            }
            else
            {
                zip.CreateZip(txtPackagePath.Text, txtNewSoftDir.Text, true, "", null);
            }

            //校验MD5
            byte[] hash = null;
            int size = 0;
            using (var fs = new ExtendFileStream(SelectedPackagePath, FileMode.Open))
            {
                e.ReportProgress((int) fs.Length, 0, "");
                fs.ProgressChanged += (s, f) => { e.ReportProgress((int) fs.Position); };
                MD5 md5 = MD5.Create();

                hash = md5.ComputeHash(fs);
                size = (int) fs.Length;
            }
            info.MD5 = BitConverter.ToString(hash).Replace("-", "").ToUpper();
            info.PackageSize = size;
            info.XmlSerilizeToFile(GetXmlPath(SelectedPackagePath));

            e.ReportProgress(0, 0, "生成成功,MD5校验:" + info.MD5);
        }
Beispiel #5
0
 /// <summary>
 /// Initialise a new instance of <see cref="FastZip"/>
 /// </summary>
 /// <param name="events">The <see cref="FastZipEvents">events</see> to use during operations.</param>
 public FastZip(FastZipEvents events)
 {
     this.events = events;
 }
Beispiel #6
0
 /// <summary>
 /// Initialise a new instance of <see cref="FastZip"/>
 /// </summary>
 /// <param name="events">The <see cref="FastZipEvents">events</see> to use during operations.</param>
 public FastZip(FastZipEvents events)
 {
     events_ = events;
 }