Dim Liste As New List(Of clsFichier) Dim WithEvents WC As New System.Net.WebClient Dim _nb As Integer = -1 Private Sub B_dl3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_dl3.Click 'comparaison... Using reader_dist As New IO.StreamReader(Application.StartupPath & "\liste.txt") Do While Not reader_dist.EndOfStream 'lecture de la ligne du fichier Dim ligne_dist As String = reader_dist.ReadLine 'séparation des informations Dim fichier_dist As String = ligne_dist.Split(" "c)(0) Dim sha256_dist As String = ligne_dist.Split(" "c)(1) Dim taille As String = ligne_dist.Split(" "c)(2) Dim fichier_loc As String = "" Using reader_loc As New IO.StreamReader(Application.StartupPath & "\listelocale.txt") Dim fichierexiste As Boolean = False Do While Not reader_loc.EndOfStream Dim ligne_loc As String = reader_loc.ReadLine fichier_loc = ligne_loc.Split("@"c)(0) Dim sha256_loc As String = ligne_loc.Split("@"c)(1) 'fichiers de même nom If fichier_dist = fichier_loc Then 'le sha256 est différent If sha256_dist <> sha256_loc Then My.Computer.FileSystem.DeleteFile(Application.StartupPath & "" & fichier_dist) Liste.Add(New clsFichier(New Uri("http://www.xxx.fr/updater/pack/" & fichier_dist), Application.StartupPath & "" & fichier_dist)) 'Il faudrait rajouter ici une condition qui oblige d'attendre 'que l'évènement de fin de téléchargement soit levé pour continer la 'boucle (cela consisterait à lancer les téléchargements un par un). Else 'le hash est le même (on peut effectuer une action ici) End If fichierexiste = True Exit Do End If Loop 'si le fichier n'existe pas on le télécharge If Not fichierexiste Then Liste.Add(New clsFichier(New Uri("http://www.xxxx.fr/updater/pack/" & fichier_dist), Application.StartupPath & "" & fichier_dist)) 'Il faudrait rajouter ici une condition qui oblige d'attendre 'que l'évènement de fin de téléchargement soit levé pour continer la 'boucle (cela consisterait à lancer les téléchargements un par un). End If End Using Loop End Using WC_DownloadFileCompleted(Nothing, Nothing) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub Public Class clsFichier Dim _adresse As Uri Dim _fichier, _destination As String Sub New(ByVal Adresse As Uri, ByVal Destination As String) _adresse = Adresse _destination = Destination _fichier = _adresse.OriginalString.Substring(_adresse.OriginalString.LastIndexOf("") + 1) End Sub ReadOnly Property Adresse() As Uri Get Return _adresse End Get End Property ReadOnly Property Destination() As String Get Return _destination End Get End Property ReadOnly Property Fichier() As String Get Return _fichier End Get End Property End Class Private Sub WC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WC.DownloadFileCompleted _nb += 1 If _nb >= Liste.Count Then Exit Sub WC.DownloadFileAsync(Liste.Item(_nb).Adresse, Liste.Item(_nb).Destination) pb.Maximum = 100 End Sub Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WC.DownloadProgressChanged pb.Value = e.ProgressPercentage L_Info.Text = "Etat d'avancement : " & Liste.Item(_nb).Fichier & " " & e.ProgressPercentage.ToString & "%" End Sub
If _nb >= Liste.Count Then L_Info.Text = "terminé" Exit Sub end if
Private Sub WC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WC.DownloadFileCompleted _nb += 1 If _nb >= Liste.Count Then L_Info.Text = "Client à jour" B_dl3.Enabled = True Exit Sub End If WC.DownloadFileAsync(Liste.Item(_nb).Adresse, Liste.Item(_nb).Destination) pb.Maximum = 100 End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Dl_Debut_Dl1(ByVal Taille_Fichier As Long, ByVal resumepos As Long, ByVal Temps_Depart As Long) Handles Dl.Debut_Dl SizeFile = Taille_Fichier 'stocke la taille du fichier L_Info.Text = "Debut du dl : Taille du fichier : " & Taille_Fichier.ToString StartTime = Date.Now.Ticks 'stocke le temps de départ End Sub Private Sub Dl_Fin_Dl1(ByVal actual_pos As Long) Handles Dl.Fin_Dl pb.Value = 0 'reinitialise la progressbar SizeFile = 0 'idem StartTime = 0 'idem L_Info.Text = "Liste des mises à jour chargée" End Sub Private Sub Dl_Progression_Dl(ByVal actual_pos As Long) Handles Dl.Progression_Dl Try pb.Value = CInt((actual_pos / SizeFile) * 100) 'etat de la progression du dl Dim speed As Long = CLng((actual_pos * 10000000) / (DateTime.Now.Ticks - StartTime)) 'calcule de la vitesse If speed <> 0 Then Dim TpsEstime As Date L_Info.Text = "Vitesse de téléchargement : " & ConvertLen(speed) & " Temps estimé : " & CStr(DateAdd(DateInterval.Second, Math.Round((SizeFile - actual_pos) / speed), TpsEstime)) End If Catch ex As OverflowException Exit Sub Catch e As Exception MsgBox("Erreur fatale : " & e.Message) End Try End Sub
Public Sub Donwload_File_3(ByVal Source As String, ByVal Path As String, ByVal IsResume As Boolean, ByVal overwrite As Boolean) b = True bresume = IsResume timestart = 0 pathname = Path urlz = Source Dim threadz As New System.Threading.Thread(AddressOf thread_launch) threadz.Start() End Sub
Public Event Fin_Dl(ByVal actual_pos As Long)
RaiseEvent Fin_Dl(1)
L_Info.Text = "Client à jour" B_dl3.Enabled = True
WC_DownloadFileCompleted(Nothing, Nothing)
Private Sub WC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WC.DownloadFileCompleted _nb += 1 If _nb >= Liste.Count Then Exit Sub WC.DownloadFileAsync(Liste.Item(_nb).Adresse, Liste.Item(_nb).Destination) pb.Maximum = 100 If _nb >= Liste.Count Then L_Info.Text = "Client à jour" B_dl3.Enabled = True Exit Sub End If End Sub
Private Sub WC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WC.DownloadFileCompleted _nb += 1 If _nb >= Liste.Count Then WC.DownloadFileAsync(Liste.Item(_nb).Adresse, Liste.Item(_nb).Destination) pb.Maximum = 100 L_Info.Text = "Client à jour" B_dl3.Enabled = True Exit Sub End If End Sub