DotNetZip extraction progress reporting\event help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madlan
    New Member
    • Jun 2010
    • 6

    DotNetZip extraction progress reporting\event help

    Hi All.

    Could someone give me some advice on reporting progress from a zip extraction using the DotNetZip Library?

    I'm not an experienced programmer so having trouble understanding this.

    I've created an event to report the progress (ProgressEventH andler) but the progress bar is still not updating.

    The ExtractProgress EventArgs class TotalBytesToTra nsfer and BytesTransferre d which I believe I need to use to set the maximum and increment value of the progress bar.

    I'm trying to report the whole extraction (Resulting in a smooth progress bar for the whole unzip) rather than a steped progress bar per file as the examples given on the DotNetZip site.

    So far I have:

    Code:
    Imports Ionic.Zip
    Imports System.Threading
    Imports System.Reflection
    
    Public Class Form1
    
        Dim zipfileName As String = "C:\Test\test123.zip"
        Dim extractDirectory As String = "C:\Test\"
        Private Delegate Sub UpdateProgressBarInvoker(ByVal Value As Integer)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        End Sub
    
        Private Sub Unzip()
            Dim args(2) As String
            args(0) = Me.zipfileName
            args(1) = Me.extractDirectory
            Dim t = New Thread(AddressOf Me.UnzipFile)
            t.Start(args)
            While Me.BackgroundWorker1.IsBusy
                ' Keep UI messages moving, so the form remains 
                ' responsive during the asynchronous operation.
                Application.DoEvents()
            End While
        End Sub
    
        Private Sub UnzipFile(ByVal args As String())
            Using zip As ZipFile = ZipFile.Read(args(0))
                AddHandler zip.ExtractProgress, AddressOf ProgressEventHandler
    
                Dim entry As ZipEntry
                For Each entry In zip
                    entry.Extract(args(1), ExtractExistingFileAction.OverwriteSilently)
                Next
            End Using
        End Sub
    
        Private Sub ProgressEventHandler(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
            SetControlPropertyValue(ProgressBar1, "Maximum", e.TotalBytesToTransfer)
            SetControlPropertyValue(ProgressBar1, "value", e.BytesTransferred)
        End Sub
    
    
    
    
        Delegate Sub SetControlValueCallback(ByVal oControl As Control, ByVal propName As String, ByVal propValue As Object)
    
        Private Sub SetControlPropertyValue(ByVal oControl As Control, ByVal propName As String, ByVal propValue As Object)
            If (oControl.InvokeRequired) Then
    
                Dim d As New SetControlValueCallback(AddressOf SetControlPropertyValue)
                oControl.Invoke(d, New Object() {oControl, propName, propValue})
            Else
                Dim t As Type = oControl.[GetType]()
                Dim props As PropertyInfo() = t.GetProperties()
                For Each p As PropertyInfo In props
                    If p.Name.ToUpper() = propName.ToUpper() Then
                        p.SetValue(oControl, propValue, Nothing)
                    End If
                Next
            End If
        End Sub
    
        Private Sub BtnUnzip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUnzip.Click
            Unzip()
        End Sub
    
    End Class

    I'm using examples from here(Half way down):
    http://dotnetzip.codep lex.com/wikipage?title= VB-Examples&referr ingTitle=Exampl es

    Thank you in advance.
Working...