vs2013附件 :http://download.csdn.net/detail/u012663700/7427461

C# WPF 解压缩7zip文件 带进度条 sevenzipsharp

WPF PNG实现的图形进度条

.NET 3.5

 
 
 
 
 

http://sevenzipsharp.codeplex.com/

 
 
 

MainWindow.xaml
 
<Window x:Class="SevenZipTestWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SevenZipSharp WPF Demo" Height="157" Width="479" WindowStartupLocation="CenterScreen" >
    <Grid>
        <Image x:Name="image1" HorizontalAlignment="Left" Height="20" Margin="-13,25,0,0" VerticalAlignment="Top" Width="193" Source="progress-filled1.png" Stretch="None" RenderTransformOrigin="0.5,0.5">
            <Image.RenderTransform>
                <TransformGroup>
                    <ScaleTransform ScaleX="0.75" ScaleY="0.73"/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Image.RenderTransform>
        </Image>
        <Grid>
            <ProgressBar Height="15" HorizontalAlignment="Left" Margin="10,10,0,0" 
                                         Name="progressBar1" VerticalAlignment="Top" Width="355" />
            <Button Content="Extract"   HorizontalAlignment="Left" Margin="383,10,0,0" Name="b_Extract" Width="52" Click="b_Extract_Click" VerticalAlignment="Top" />
            <Label x:Name="label1" Content="Label" HorizontalAlignment="Left" Margin="10,50,0,0" VerticalAlignment="Top" Width="451"/>
        </Grid>
    </Grid>
</Window>

MainWindow.xaml.cs
 
using System;
using System.Windows;
 
using SevenZip;
 
namespace SevenZipTestWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Check7zAndSevenZipSharpDll();
        }
 
 
        private string fileName = @"D:\Administrator\wwwroot\CPW\wmgjUpdate.7z";
        private string directory = @"D:\Administrator\Desktop\完美世界国际版";
        private string dll7z = AppDomain.CurrentDomain.BaseDirectory + "7z.dll";
        private string dllSevenZipSharp = AppDomain.CurrentDomain.BaseDirectory + "SevenZipSharp.dll";
 
        private int MaxValue = 0;
        private int CurrentValue = 0;
 
 
        private void b_Extract_Click(object sender, RoutedEventArgs e)
        {
            if (System.IO.File.Exists(fileName) && System.IO.Directory.Exists(directory))
            {
                SevenZipExtractor.SetLibraryPath(dll7z);
                label1.Content = "开始更新客户端文件";
 
                var extractor = new SevenZipExtractor(fileName);
                progressBar1.Maximum = extractor.ArchiveFileData.Count;
                MaxValue = extractor.ArchiveFileData.Count;
 
                extractor.FileExtractionStarted += new EventHandler<FileInfoEventArgs>(extr_FileExtractionStarted);
                extractor.BeginExtractArchive(directory);
            }
        }
 
        void extr_FileExtractionStarted(object sender, FileInfoEventArgs e)
        {
            label1.Content = String.Format("更新文件 {0}", e.FileInfo.FileName);
            progressBar1.Value += 1;
            CurrentValue += 1;
            ImageProgressBar(CurrentValue, MaxValue, 193, image1);
 
            if (progressBar1.Maximum == progressBar1.Value)
                label1.Content = "游戏更新完成";
        }
 
 
        private void Check7zAndSevenZipSharpDll()
        {
            bool b1 = System.IO.File.Exists(dll7z);
            bool b2 = System.IO.File.Exists(dllSevenZipSharp);
 
            if (!b1)
            {
                MessageBox.Show("7z.dll 不存在!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
            }
 
            if (!b2)
            {
                MessageBox.Show("SevenZipSharp.dll 不存在!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
            }
        }
 
        /// <summary>
        /// 图片进度条
        /// </summary>
        /// <param name="current"></param>
        /// <param name="max"></param>
        /// <param name="imageWidth">图片的实际宽度</param>
        /// <param name="image1"></param>
        private static void ImageProgressBar(double current, double max, double imageWidth, System.Windows.Controls.Image image1)
        {
            if (max != 0)
                image1.Width = System.Math.Round((current / max) * imageWidth);
        }
 
 
    }
}

C# WPF 解压缩7zip文件 带进度条 sevenzipsharp的更多相关文章

  1. WPF 下载网络文件 带进度条

      附件:http://files.cnblogs.com/xe2011/WpfApplication3_downloadFile.rar 使用         private void Button ...

  2. Asp.Net上传大文件带进度条swfupload

    Asp.Net基于swfupload上传大文件带进度条百分比显示,漂亮大气上档次,大文件无压力,先看效果 一.上传效果图 1.上传前界面:图片不喜欢可以自己换 2.上传中界面:百分比显示 3.上传后返 ...

  3. Extjs 使用fileupload插件上传文件 带进度条显示

    一.首先我们看看官方给出的插件的解释: 一个文件上传表单项具有自定义的样式,并且可以控制按钮的文本和 像文本表单的空文本类似的其他特性. 它使用一个隐藏的文件输入元素,并在用户选择文件后 在form提 ...

  4. ASP.NET Jquery+ajax上传文件(带进度条)

    效果图 支持ie6+,chrome,ie6中文文件名会显示乱码. 上传时候会显示进度条. 需要jquery.uploadify.js插件,稍后会给出下载 前台代码 <%@ Page Langua ...

  5. Springmvc+uploadify实现文件带进度条批量上传

    网上看了很多关于文件上传的帖子,众口不一,感觉有点乱,最近正好公司的项目里用到JQuery的uploadify控件做文件上传,所以整理下头绪,搞篇文档出来,供亲们分享. Uploadify控件的主要优 ...

  6. webclient下载文件 带进度条

    private void button1_Click(object sender, EventArgs e) { doDownload(textBox1.Text.Trim()); } private ...

  7. asp.net mvc 实现上传文件带进度条

    本文乃是博主早期写的,此种思路虽然实现了,但固然不是最好的,仅做参考学习. 可以用js onprogress .fileinput .webuploader.jq ajaxsubmit等实现 思路:a ...

  8. FormData上传文件 带进度条

    * jQuery ajax  FormData 上传文件 template $.ajax({ url: url, type: 'POST', data: new FormData(form), dat ...

  9. UrlDownloadFile, 线程下载文件, 带进度条

    unit FileDownLoadThread; interface uses Classes, SysUtils, Windows, ActiveX, UrlMon; const S_ABORT = ...

随机推荐

  1. Jmeter Constant Throughput Timer 使用

    Jmeter提供了一个非常有用的定时器,称为Constant Throughput Timer (常数吞吐量定时器),该定时器可以方便地控制给定的取样器发送请求的吞吐量. 右键点击fnng.cnblo ...

  2. 环信_EaseUI 使用指南

    EaseUI 使用指南 简介 EaseUI 封装了 IM 功能常用的控件(如聊天会话.会话列表.联系人列表).旨在帮助开发者快速集成环信 SDK. 源码地址: EaseUI:https://githu ...

  3. JAVA 字符串编码总结

    java 为了解决跨平台,字符串编码的有点特殊 String newStr = new String(oldStr.getBytes(), "UTF-8");java中的Strin ...

  4. function(a)

    问题:  问个初级的问题int a = 8;function(a);这里在function中的a值是引用a内存中的数据,还是新开辟内存后将a的值赋值到新内存供函数调用.  回答: int a = 8; ...

  5. RHEL/CentOS/Fedora常用的 CentOS 5/6/7 yum 源(EPEL、Remi、RPMForge、RPMFusion, ius,163,sohu,阿里云)配置

    RHEL以及他的衍生发行版如CentOS.Scientific Linux为了稳定,官方的rpm repository提供的rpm包往往是很滞后的,当然了,这样做这是无可厚非的,毕竟这是服务器版本,安 ...

  6. Linux kernel ‘qeth_snmp_command’函数缓冲区溢出漏洞

    漏洞名称: Linux kernel ‘qeth_snmp_command’函数缓冲区溢出漏洞 CNNVD编号: CNNVD-201311-423 发布时间: 2013-11-29 更新时间: 201 ...

  7. Google Chrome中的高性能网络(一)

    以下内容是"The Performance of Open Source Applications" (POSA)的草稿, 也是The Architecture of Open S ...

  8. c#集合类的线程安全

    即位于System.Collections命名空间下的集合,如Hashtable,ArrayList,Stack,Queue等.其均提供了线程同步的一个实现 集合线程同步的问题 public clas ...

  9. Chrome 控制台console的用法(学了之后对于调试js可是大大有用的哦)

    大家都有用过各种类型的浏览器,每种浏览器都有自己的特色,本人拙见,在我用过的浏览器当中,我是最喜欢Chrome的,因为它对于调试脚本及前端设计调试都有它比其它浏览器有过之而无不及的地方.可能大家对co ...

  10. 如何判断 Android 应用的 Apk 签名是否一致?

    可以比对apk签名的fingerprint. 假定安装了JDK,如果想查HelloWorld.apk所使用的签名的fingerprint,可以这样做: 1. 查找apk里的rsa文件 (Windows ...