none
Descompactar ao terminar download? RRS feed

  • Pergunta

  • Eu tenho um sisteam de udpater e gostaria que ele descompacta-se o arquivo zip somento quando o download termina-se , como faço isso?  sou novo na area de vb 

    Imports System.Net
    Imports Ionic.Zip
    
    Public Class Form1
        WithEvents WebClient1 As New WebClient
        Public LAUNCHER As String = Application.StartupPath.Replace("\", "/") & "/"
        Public Sub Atualizar()
            If System.IO.File.Exists(Application.StartupPath & "\update.zip") Then
                System.IO.File.Delete(Application.StartupPath & "\update.zip")
            End If
            WebClient1.DownloadFileAsync(New Uri("http://127.0.0.1/update.zip"), Application.StartupPath & "\update.zip")
            AddHandler WebClient1.DownloadProgressChanged, AddressOf Me.DownloadProgressChangedCallback
            AddHandler WebClient1.DownloadFileCompleted, AddressOf Me.DownloadFileCompletedCallback
        End Sub
        Private Sub DownloadProgressChangedCallback(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
            ' Atualiza ProgressBar
            ProgressBar1.Value = e.ProgressPercentage
        End Sub
        Private Sub DownloadFileCompletedCallback(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
            ' Remove eventos
            RemoveHandler WebClient1.DownloadProgressChanged, AddressOf Me.DownloadProgressChangedCallback
            RemoveHandler WebClient1.DownloadFileCompleted, AddressOf Me.DownloadFileCompletedCallback
        End Sub
        Public Function GetSettingItem(ByVal File As String, ByVal Identifier As String) As String
            Dim S As New IO.StreamReader(File) : Dim Result As String = ""
            Do While (S.Peek <> -1)
                Dim Line As String = S.ReadLine
                If Line.ToLower.StartsWith(Identifier.ToLower & ":") Then
                    Result = Line.Substring(Identifier.Length + 2)
                End If
            Loop
            Return Result
        End Function
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If ProgressBar1.Value < 100 Then
                MsgBox("ESPERA COMPLETAR O UPDATE")
                Return
            End If
            If CheckBox1.Checked = True Then
                System.Diagnostics.Process.Start("PNA_OPENGL.exe")
            ElseIf CheckBox2.Checked = True Then
                System.Diagnostics.Process.Start("PNA_DX9.exe")
            ElseIf CheckBox3.Checked = True Then
                System.Diagnostics.Process.Start("PNA.exe")
            Else
                MsgBox("Escolhe seu Client")
            End If
        End Sub
    
        Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
            If CheckBox2.Checked = True Then
                CheckBox2.Checked = False
            End If
            If CheckBox3.Checked = True Then
                CheckBox3.Checked = False
            End If
        End Sub
    
        Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
            If CheckBox1.Checked = True Then
                CheckBox1.Checked = False
            End If
            If CheckBox3.Checked = True Then
                CheckBox3.Checked = False
            End If
        End Sub
    
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
        End Sub
    
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    
        End Sub
        Private Sub descompactarArquivo()
            Dim ZipToUnpack As String = Application.StartupPath & "\update.zip"
            Dim TargetDir As String = LAUNCHER
            Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
                Dim e As ZipEntry
                For Each e In zip1
                    e.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
                Next
            End Using
            MessageBox.Show("PRONTO! PODE JOGAR.")
        End Sub
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim VersaoSite As String = WebClient1.DownloadString("http://127.0.0.1/versao.txt")
            Dim VersaoAtual As String = GetSettingItem("config.txt", "VERSAO")
            If VersaoSite > VersaoAtual Then
                Atualizar()
                descompactarArquivo()
            End If
        End Sub
    
        Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.CheckedChanged
            If CheckBox1.Checked = True Then
                CheckBox1.Checked = False
            End If
            If CheckBox2.Checked = True Then
                CheckBox2.Checked = False
            End If
        End Sub
    
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            Me.Close()
        End Sub
        Private WM_NCHITTEST As Integer = &H84
        Private HTCLIENT As Integer = &H1
        Private HTCAPTION As Integer = &H2
    
        Protected Overrides Sub WndProc(ByRef m As Message)
            MyBase.WndProc(m)
    
            Select Case m.Msg
                Case WM_NCHITTEST
                    If m.Result = New IntPtr(HTCLIENT) Then
                        m.Result = New IntPtr(HTCAPTION)
                    End If
            End Select
        End Sub
    
    End Class
    DESDE JA OBRIGADO PELA ATENÇÃO ^^

    sábado, 30 de agosto de 2014 19:31

Respostas

  • Boa tarde Aberos,

    Da uma olhada nesses tutoriais:

    http://www.macoratti.net/vbn5_pck.htm

    http://www.maestrodotnet.com.br/?p=592

    Att,


    Ricardo Cortes Microsoft Contingent Staff

    Esse contedo e fornecido sem garantias de qualquer tipo, seja expressa ou implicita.

    MSDN Community Support

    segunda-feira, 1 de setembro de 2014 17:43