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);
        }
 
 
    }
}





转载于:https://www.cnblogs.com/xe2011/p/3761870.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值