1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
   |  
Imports System.Net
Imports ICSharpCode.SharpZipLib.Zip
Imports System.IO
 
Public Class Form1
#Region "Variables"
 
    Private WithEvents WClient As New WebClient
    Private ActualVersion As Integer
    Private NewVersion As Integer
 
#End Region
 
#Region "Style"
 
 
    Private Sub UpdateGround()
        PictureBox1.ImageLocation = ("logo.jpg")
    End Sub
 
#End Region
 
#Region "Events"
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ProgressBar1.Visible = False
        Label1.Visible = False
 
        Config.loadConfig()
        UpdateGround()
        ReadActualVersion()
        DownloadVersionFile()
        If ActualVersion = NewVersion Then
            AppendLog("Votre version est a jour !")
        Else
            Button1.Enabled = False
            AppendLog("Votre version n'est pas a jour , telechargement des mises a jours !")
            ProgressBar1.Visible = True
            Label1.Visible = True
            StartUpdate()
        End If
    End Sub
 
    Private Sub StatsChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles WClient.DownloadProgressChanged
        Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
        Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
        Dim percentage As Double = bytesIn / totalBytes * 100
        ProgressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
        Label1.Text = (ProgressBar1.Value & "%")
    End Sub
 
    Private Sub Finish() Handles WClient.DownloadFileCompleted
        AppendLog("Dezippage de la mise a jour en cours ...")
        ExtractArchive(NewVersion & ".zip", Application.StartupPath)
        AppendLog("Mise a jour terminer !")
        ProgressBar1.Visible = False
        Label1.Visible = False
        Button1.Enabled = True
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Shell("dofus.exe")
 
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Hide()
    End Sub
#End Region
 
#Region "Procédures"
 
    Private Sub StartUpdate()
        WClient.DownloadFileAsync(New Uri(Config._Get("updateLink") & "/" & NewVersion & ".zip"), NewVersion & ".zip")
    End Sub
 
    Public Sub DownloadVersionFile()
        WClient.DownloadFile(New Uri(Config._Get("versionLink")), "v.txt")
        Dim R As New IO.StreamReader("v.txt")
        NewVersion = R.ReadToEnd
        R.Close()
    End Sub
 
    Private Sub ReadActualVersion()
        If IO.File.Exists("actualv.txt") Then
            Dim R As New IO.StreamReader("actualv.txt")
            ActualVersion = R.ReadToEnd
            R.Close()
        Else
            Dim R As New IO.StreamWriter("actualv.txt")
            R.Write("1")
            R.Close()
            ActualVersion = 1
            AppendLog("Version actuel non trouver , remise a zero effectuer !")
        End If
    End Sub
 
    Public Sub AppendLog(ByVal M As String)
        RichTextBox1.AppendText(M & vbCrLf)
    End Sub
 
    Public Sub ExtractArchive(ByVal zipFilename As String, ByVal ExtractDir As String)
        Dim Redo As Integer = 1
        Dim MyZipInputStream As ZipInputStream
        Dim MyFileStream As FileStream = Nothing
        MyZipInputStream = New ZipInputStream(New FileStream(zipFilename, FileMode.Open, FileAccess.Read))
        Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
        Directory.CreateDirectory(ExtractDir)
        While Not MyZipEntry Is Nothing
            If (MyZipEntry.IsDirectory) Then
                Directory.CreateDirectory(ExtractDir & "\" & MyZipEntry.Name)
            Else
                If Not Directory.Exists(ExtractDir & "\" & Path.GetDirectoryName(MyZipEntry.Name)) Then
                    Directory.CreateDirectory(ExtractDir & "\" & Path.GetDirectoryName(MyZipEntry.Name))
                End If
                MyFileStream = New FileStream(ExtractDir & "\" & MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write)
                Dim count As Integer
                Dim buffer(4096) As Byte
                count = MyZipInputStream.Read(buffer, 0, 4096)
                While count > 0
                    MyFileStream.Write(buffer, 0, count)
                    count = MyZipInputStream.Read(buffer, 0, 4096)
                End While
                MyFileStream.Close()
            End If
            Try
                MyZipEntry = MyZipInputStream.GetNextEntry
            Catch ex As Exception
                MyZipEntry = Nothing
            End Try
        End While
        If Not (MyZipInputStream Is Nothing) Then MyZipInputStream.Close()
        If Not (MyFileStream Is Nothing) Then MyFileStream.Close()
    End Sub
 
#End Region
 
End Class |