Public Class fExtractZip
    Dim zip As Ionic.Zip.ZipFile
    Public Sub New(filename As String)

        ' 디자이너에서 이 호출이 필요합니다.
        InitializeComponent()

        If System.IO.File.Exists(filename) = False Then
            RunComplete = True
        Else
            Dim ro As New Ionic.Zip.ReadOptions()
            ro.Encoding = System.Text.Encoding.Default
            zip = Ionic.Zip.ZipFile.Read(filename, ro)
            AddHandler zip.ExtractProgress, AddressOf extractevents
        End If
        ' InitializeComponent() 호출 뒤에 초기화 코드를 추가하세요.
        Me.Text = "스타일 팩 적용 중 - 기다려 주세요"
    End Sub



    Delegate Sub extranhandler(sender As Object, e As Ionic.Zip.ExtractProgressEventArgs)
    Sub extractevents(sender As Object, e As Ionic.Zip.ExtractProgressEventArgs)

        If Me.InvokeRequired Then
            Me.Invoke(New extranhandler(AddressOf extractevents), sender, e)
        Else
            Me.ProgressBar1.Value = e.EntriesExtracted
            If e.CurrentEntry Is Nothing Then
                lbFileName.Text = "----"
            Else
                lbFileName.Text = e.CurrentEntry.FileName

            End If
            lbFileName.Refresh()
        End If


    End Sub

    Private Sub fExtractZip_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Show()
        Application.DoEvents()
        Timer1.Start()
    End Sub

    Dim mre As New System.Threading.ManualResetEvent(True)

    Dim RunExtract As Boolean = False
    Dim RunComplete As Boolean = False


    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        If mre.WaitOne(10) = False Then Return
        mre.Reset()

        '//완료여부확인
        If RunComplete Then
            Timer1.Enabled = False
            mre.Set()
            If Not zip Is Nothing Then
                zip.Dispose()
                zip = Nothing
            End If
            Me.DialogResult = DialogResult.OK
        Else
            '//처음시작
            If RunExtract = False Then
                Me.ProgressBar1.Value = 0
                Me.ProgressBar1.Maximum = zip.Count
                ' Me.ProgressBar1.Style = ProgressBarStyle.Marquee
                RunExtract = True
            End If

            If RunExtract Then
                zip.ExtractAll(AppDomain.CurrentDomain.BaseDirectory, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
                RunComplete = True
            End If

        End If


        mre.Set()
    End Sub
End Class