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

 
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 senderRoutedEventArgs 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 senderFileInfoEventArgs e)
        {
            label1.Content = String.Format("更新文件 {0}"e.FileInfo.FileName);
            progressBar1.Value += 1;
            CurrentValue += 1;
            ImageProgressBar(CurrentValueMaxValue, 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.OKMessageBoxImage.Error);
                Close();
            }
 
            if (!b2)
            {
                MessageBox.Show("SevenZipSharp.dll 不存在!""错误"MessageBoxButton.OKMessageBoxImage.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 currentdouble maxdouble imageWidthSystem.Windows.Controls.Image image1)
        {
            if (max != 0)
                image1.Width = System.Math.Round((current / max) * imageWidth);
        }
 
 
    }
}





posted @   XE2011  阅读(4251)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
历史上的今天:
2012-05-30 ini写配置信息 列表框
2012-05-30 开机 关机执行命令
2012-05-30 模拟安键F5 SendKeys
2012-05-30 按键模拟_注入线程之后国F也可以按键模拟
2012-05-30 01 用CE查找游戏基址
2012-05-30 红蓝保护(按键模拟)
2012-05-30 过QQ游戏大厅的SX保护 - Evil0r's Blog - 博客频道 - CSDN_NET
点击右上角即可分享
微信分享提示