Etienne BAUDOUX

Forum sur les projets de Etienne BAUDOUX


Téléchargements...

Otto88
Otto88
Nouveau
Nouveau

Masculin Nombre de messages : 33
Date d'inscription : 01/10/2011

Téléchargements... Empty Téléchargements...

Message par Otto88 le Dim 15 Avr 2012 - 14:34

Bonjour!

Est-t-il possible de détecter quand un téléchargement est mis en route et de créer une gestion du téléchargement comme dans un navigateur web? ( estimation du temps restant... )

Otto88



Publiez vos meilleurs programmes sur mon site http://softsharing.fr.nf ! Vous pourrez aussi télécharger ceux publiés par les autres utilisateurs du site ! ( proposez moi un programme en suivant les indications dans la rubrique CREEZ / proposez un logiciel... )

RDV vite sur softsharing.fr.nf!!!
lereparateurdepc
lereparateurdepc


Masculin Nombre de messages : 5601
Age : 26
Localisation : Calvados
Emploi/loisirs : Electrotechnicien / électricité, HAUTE TENSION, électronique, informatique, automatisme , Arduino, bref le BRICOLAGE , ...
Humeur : toujours cool
Date d'inscription : 31/01/2010

Téléchargements... Empty Re: Téléchargements...

Message par lereparateurdepc le Dim 15 Avr 2012 - 16:21

re ,

OUI , c'est ce que j'ai fait il y as quelques temps mais sous VB .

Vu la quantité de code .... je ne pense pas que ce soit réalisable sous SZ .
Le code suivant n'est qu'une portion de code . C'est le code maître , il gère le téléchargement :
Code:
Option Strict On : Option Explicit On

Imports System.ComponentModel
Imports System.IO
Imports System.Net

Namespace Bn.Classes

#Region "Public Class FileDownloader"
    ''' <summary>Class for downloading files in the background that supports info about their progress, the total progress, cancellation, pausing, and resuming. The downloads will run on a separate thread so you don't have to worry about multihreading yourself. </summary>
    ''' <remarks>Class FileDownloader v1.0.3, by De Dauw Jeroen - May 2009</remarks>
    Public Class FileDownloader
        Inherits System.Object
        Implements IDisposable

#Region "Nested types"

#Region "Public Structure FileInfo"
        ''' <summary>Simple structure for managing file info</summary>
        Public Structure FileInfo
            ''' <summary>The complete path of the file (directory + filename)</summary>
            Public Path As String
            ''' <summary>The name of the file</summary>
            Public Name As String

            ''' <summary>Create a new instance of FileInfo</summary>
            ''' <param name="path">The complete path of the file (directory + filename)</param>
            Public Sub New(ByVal path As String)
                Me.Path = path
                Me.Name = Me.Path.Split("/"c)(Me.Path.Split("/"c).Length - 1)
            End Sub
        End Structure
#End Region

#Region "Private Enum [Event]"
        ''' <summary>Holder for events that are triggered in the background worker but need to be fired in the main thread</summary>
        Private Enum [Event]
            CalculationFileSizesStarted

            FileSizesCalculationComplete
            DeletingFilesAfterCancel

            FileDownloadAttempting
            FileDownloadStarted
            FileDownloadStopped
            FileDownloadSucceeded

            ProgressChanged
        End Enum
#End Region

#Region "Private Enum InvokeType"
        ''' <summary>Holder for the action that needs to be invoked</summary>
        Private Enum InvokeType
            EventRaiser
            FileDownloadFailedRaiser
            CalculatingFileNrRaiser
        End Enum
#End Region

#End Region

#Region "Events"
        ''' <summary>Occurs when the file downloading has started</summary>
        Public Event Started As EventHandler
        ''' <summary>Occurs when the file downloading has been paused</summary>
        Public Event Paused As EventHandler
        ''' <summary>Occurs when the file downloading has been resumed</summary>
        Public Event Resumed As EventHandler
        ''' <summary>Occurs when the user has requested to cancel the downloads</summary>
        Public Event CancelRequested As EventHandler
        ''' <summary>Occurs when the user has requested to cancel the downloads and the cleanup of the downloaded files has started</summary>
        Public Event DeletingFilesAfterCancel As EventHandler
        ''' <summary>Occurs when the file downloading has been canceled by the user</summary>
        Public Event Canceled As EventHandler
        ''' <summary>Occurs when the file downloading has been completed (without canceling it)</summary>
        Public Event Completed As EventHandler
        ''' <summary>Occurs when the file downloading has been stopped by either cancellation or completion</summary>
        Public Event Stopped As EventHandler

        ''' <summary>Occurs when the busy state of the FileDownloader has changed</summary>
        Public Event IsBusyChanged As EventHandler
        ''' <summary>Occurs when the pause state of the FileDownloader has changed</summary>
        Public Event IsPausedChanged As EventHandler
        ''' <summary>Occurs when the either the busy or pause state of the FileDownloader have changed</summary>
        Public Event StateChanged As EventHandler

        ''' <summary>Occurs when the calculation of the file sizes has started</summary>
        Public Event CalculationFileSizesStarted As EventHandler
        ''' <summary>Occurs when the calculation of the file sizes has started</summary>
        Public Event CalculatingFileSize As FileSizeCalculationEventHandler
        ''' <summary>Occurs when the calculation of the file sizes has been completed</summary>
        Public Event FileSizesCalculationComplete As EventHandler

        ''' <summary>Occurs when the FileDownloader attempts to get a web response to download the file</summary>
        Public Event FileDownloadAttempting As EventHandler
        ''' <summary>Occurs when a file download has started</summary>
        Public Event FileDownloadStarted As EventHandler
        ''' <summary>Occurs when a file download has stopped</summary>
        Public Event FileDownloadStopped As EventHandler
        ''' <summary>Occurs when a file download has been completed successfully</summary>
        Public Event FileDownloadSucceeded As EventHandler
        ''' <summary>Occurs when a file download has been completed unsuccessfully</summary>
        Public Event FileDownloadFailed(ByVal sender As Object, ByVal e As Exception)

        ''' <summary>Occurs every time a block of data has been downloaded</summary>
        Public Event ProgressChanged As EventHandler
#End Region

#Region "Fields"
        Public Delegate Sub FileSizeCalculationEventHandler(ByVal sender As Object, ByVal fileNumber As Int32)

        Private WithEvents bgwDownloader As New BackgroundWorker
        Private trigger As New Threading.ManualResetEvent(True)

        ' Preferences
        Private m_supportsProgress, m_deleteCompletedFiles As Boolean
        Private m_packageSize, m_stopWatchCycles As Int32

        ' State
        Private m_disposed As Boolean = False
        Private m_busy, m_paused, m_canceled As Boolean
        Private m_currentFileProgress, m_totalProgress, m_currentFileSize As Int64
        Private m_currentSpeed, m_fileNr As Int32

        ' Data
        Private m_localDirectory As String
        Private m_files As New List(Of FileInfo)
        Private m_totalSize As Int64
#End Region

#Region "Constructors"
        ''' <summary>Create a new instance of a FileDownloader</summary>
        ''' <param name="supportsProgress">Optional. Boolean. Should the FileDownloader support total progress statistics?</param>
        Public Sub New(Optional ByVal supportsProgress As Boolean = False)
            ' Set the bgw properties
            bgwDownloader.WorkerReportsProgress = True
            bgwDownloader.WorkerSupportsCancellation = True

            ' Set the default class preferences
            Me.SupportsProgress = supportsProgress
            Me.PackageSize = 4096
            Me.StopWatchCyclesAmount = 5
            Me.DeleteCompletedFilesAfterCancel = False
        End Sub
#End Region

#Region "Public methods"
        ''' <summary>Start the downloads</summary>
        Public Sub Start()
            Me.IsBusy = True
        End Sub

        ''' <summary>pause the downloads</summary>
        Public Sub Pause()
            Me.IsPaused = True
        End Sub

        ''' <summary>Resume the downloads</summary>
        Public Sub [Resume]()
            Me.IsPaused = False
        End Sub

        ''' <summary>Stop the downloads</summary>
        Public Overloads Sub [Stop]()
            Me.IsBusy = False
        End Sub

        ''' <summary>Stop the downloads</summary>
        ''' <param name="deleteCompletedFiles">Required. Boolean. Indicates wether the complete downloads should be deleted</param>
        Public Overloads Sub [Stop](ByVal deleteCompletedFiles As Boolean)
            Me.DeleteCompletedFilesAfterCancel = deleteCompletedFiles
            Me.Stop()
        End Sub

        ''' <summary>Release the recources held by the FileDownloader</summary>
        Public Sub Dispose() Implements IDisposable.Dispose
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub

        ''' <summary>Format an amount of bytes to a more readible notation with binary notation symbols</summary>
        ''' <param name="size">Required. Int64. The raw amount of bytes</param>
        ''' <param name="decimals">Optional. Int32. The amount of decimals you want to have displayed in the notation</param>
        Public Shared Function FormatSizeBinary(ByVal size As Int64, Optional ByVal decimals As Int32 = 2) As String
            ' By De Dauw Jeroen - April 2009 - jeroen_dedauw@yahoo.com
            Dim sizes() As String = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
            Dim formattedSize As Double = size
            Dim sizeIndex As Int32 = 0
            While formattedSize >= 1024 And sizeIndex < sizes.Length
                formattedSize /= 1024
                sizeIndex += 1
            End While
            Return Math.Round(formattedSize, decimals).ToString & sizes(sizeIndex)
        End Function

        ''' <summary>Format an amount of bytes to a more readible notation with decimal notation symbols</summary>
        ''' <param name="size">Required. Int64. The raw amount of bytes</param>
        ''' <param name="decimals">Optional. Int32. The amount of decimals you want to have displayed in the notation</param>
        Public Shared Function FormatSizeDecimal(ByVal size As Int64, Optional ByVal decimals As Int32 = 2) As String
            ' By De Dauw Jeroen - April 2009 - jeroen_dedauw@yahoo.com
            Dim sizes() As String = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
            Dim formattedSize As Double = size
            Dim sizeIndex As Int32 = 0
            While formattedSize >= 1000 And sizeIndex < sizes.Length
                formattedSize /= 1000
                sizeIndex += 1
            End While
            Return Math.Round(formattedSize, decimals).ToString & sizes(sizeIndex)
        End Function
#End Region

#Region "Private/protected methods"
        Private Sub bgwDownloader_DoWork() Handles bgwDownloader.DoWork
            Dim fileNr As Int32 = 0

            If Me.SupportsProgress Then calculateFilesSize()

            If Not Directory.Exists(Me.LocalDirectory) Then Directory.CreateDirectory(Me.LocalDirectory)

            While fileNr < Me.Files.Count And Not bgwDownloader.CancellationPending
                m_fileNr = fileNr
                downloadFile(fileNr)

                If bgwDownloader.CancellationPending Then
                    fireEventFromBgw([Event].DeletingFilesAfterCancel)
                    cleanUpFiles(If(Me.DeleteCompletedFilesAfterCancel, 0, m_fileNr), If(Me.DeleteCompletedFilesAfterCancel, m_fileNr + 1, 1))
                Else
                    fileNr += 1
                End If
            End While
        End Sub

        Private Sub fireEventFromBgw(ByVal eventName As [Event])
            bgwDownloader.ReportProgress(InvokeType.EventRaiser, eventName)
        End Sub

        Private Sub bwgDownloader_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles bgwDownloader.ProgressChanged
            Select Case CType(e.ProgressPercentage, InvokeType)
                Case InvokeType.EventRaiser
                    Select Case CType(e.UserState, [Event])
                        Case [Event].CalculationFileSizesStarted
                            RaiseEvent CalculationFileSizesStarted(Me, New EventArgs)
                        Case [Event].FileSizesCalculationComplete
                            RaiseEvent FileSizesCalculationComplete(Me, New EventArgs)
                        Case [Event].DeletingFilesAfterCancel
                            RaiseEvent DeletingFilesAfterCancel(Me, New EventArgs)

                        Case [Event].FileDownloadAttempting
                            RaiseEvent FileDownloadAttempting(Me, New EventArgs)
                        Case [Event].FileDownloadStarted
                            RaiseEvent FileDownloadStarted(Me, New EventArgs)
                        Case [Event].FileDownloadStopped
                            RaiseEvent FileDownloadStopped(Me, New EventArgs)
                        Case [Event].FileDownloadSucceeded
                            RaiseEvent FileDownloadSucceeded(Me, New EventArgs)
                        Case [Event].ProgressChanged
                            RaiseEvent ProgressChanged(Me, New EventArgs)
                    End Select
                Case InvokeType.FileDownloadFailedRaiser
                    RaiseEvent FileDownloadFailed(Me, CType(e.UserState, Exception))
                Case InvokeType.CalculatingFileNrRaiser
                    RaiseEvent CalculatingFileSize(Me, CInt(e.UserState))
            End Select
        End Sub

        Private Sub cleanUpFiles(Optional ByVal start As Int32 = 0, Optional ByVal length As Int32 = -1)
            Dim last As Int32 = If(length < 0, Me.Files.Count - 1, start + length - 1)
            For fileNr As Int32 = start To last
                Dim fullPath As String = Me.LocalDirectory & "\" & Me.Files(fileNr).Name
                If IO.File.Exists(fullPath) Then IO.File.Delete(fullPath)
            Next
        End Sub

        Private Sub calculateFilesSize()
            fireEventFromBgw([Event].CalculationFileSizesStarted)
            m_totalSize = 0

            For fileNr As Int32 = 0 To Me.Files.Count - 1
                bgwDownloader.ReportProgress(InvokeType.CalculatingFileNrRaiser, fileNr + 1)
                Try
                    Dim webReq As HttpWebRequest = CType(Net.WebRequest.Create(Me.Files(fileNr).Path), HttpWebRequest)
                    Dim webResp As HttpWebResponse = CType(webReq.GetResponse, HttpWebResponse)
                    m_totalSize += webResp.ContentLength
                    webResp.Close()
                Catch ex As Exception
                End Try
            Next
            fireEventFromBgw([Event].FileSizesCalculationComplete)
        End Sub

        Private Sub downloadFile(ByVal fileNr As Int32)

            m_currentFileSize = 0
            fireEventFromBgw([Event].FileDownloadAttempting)

            Dim file As FileInfo = Me.Files(fileNr)
            Dim size As Int64 = 0

            Dim readBytes(Me.PackageSize - 1) As Byte
            Dim currentPackageSize As Int32
            Dim writer As New FileStream(Me.LocalDirectory & "\" & file.Name, IO.FileMode.Create)
            Dim speedTimer As New Stopwatch
            Dim readings As Int32 = 0
            Dim exc As Exception

            Dim webReq As HttpWebRequest
            Dim webResp As HttpWebResponse
            Try

                webReq = CType(Net.WebRequest.Create(Me.Files(fileNr).Path), HttpWebRequest)
                webResp = CType(webReq.GetResponse, HttpWebResponse)

                size = webResp.ContentLength
            Catch ex As Exception
                exc = ex
            End Try

            m_currentFileSize = size
            fireEventFromBgw([Event].FileDownloadStarted)

            If exc IsNot Nothing Then
                bgwDownloader.ReportProgress(InvokeType.FileDownloadFailedRaiser, exc)
            Else
                m_currentFileProgress = 0
                While m_currentFileProgress < size
                    If bgwDownloader.CancellationPending Then
                        speedTimer.Stop()
                        writer.Close()
                        webResp.Close()
                        Exit Sub
                    End If
                    trigger.WaitOne()

                    speedTimer.Start()

                    currentPackageSize = webResp.GetResponseStream().Read(readBytes, 0, Me.PackageSize)
                    m_currentFileProgress += currentPackageSize
                    m_totalProgress += currentPackageSize
                    fireEventFromBgw([Event].ProgressChanged)

                    writer.Write(readBytes, 0, currentPackageSize)
                    readings += 1

                    If readings >= Me.StopWatchCyclesAmount Then
                        m_currentSpeed = CInt(Me.PackageSize * StopWatchCyclesAmount * 1000 / (speedTimer.ElapsedMilliseconds + 1))
                        speedTimer.Reset()
                        readings = 0
                    End If
                End While

                speedTimer.Stop()
                writer.Close()
                webResp.Close()
                fireEventFromBgw([Event].FileDownloadSucceeded)
            End If
            fireEventFromBgw([Event].FileDownloadStopped)
        End Sub

        Private Sub bgwDownloader_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgwDownloader.RunWorkerCompleted
            Me.IsPaused = False
            m_busy = False

            If Me.HasBeenCanceled Then
                RaiseEvent Canceled(Me, New EventArgs)
            Else
                RaiseEvent Completed(Me, New EventArgs)
            End If

            RaiseEvent Stopped(Me, New EventArgs)
            RaiseEvent IsBusyChanged(Me, New EventArgs)
            RaiseEvent StateChanged(Me, New EventArgs)
        End Sub

        Protected Overridable Sub Dispose(ByVal disposing As Boolean)
            If Not m_disposed Then
                If disposing Then
                    ' Free other state (managed objects)
                    bgwDownloader.Dispose()
                End If
                ' Free your own state (unmanaged objects)
                ' Set large fields to null
                Me.Files = Nothing
            End If
            m_disposed = True
        End Sub
#End Region

#Region "Properties"
        ''' <summary>Gets or sets the list of files to download</summary>
        Public Property Files() As List(Of FileInfo)
            Get
                Return m_files
            End Get
            Set(ByVal value As List(Of FileInfo))
                If Me.IsBusy Then
                    Throw New InvalidOperationException("La modification de la liste d'attente ne peut pas être modifiée pendant un téléchargement ")
                Else
                    If Me.Files IsNot value Then m_files = value
                End If
            End Set
        End Property

        ''' <summary>Gets or sets the local directory in which files will be stored</summary>
        Public Property LocalDirectory() As String
            Get
                Return m_localDirectory
            End Get
            Set(ByVal value As String)
                If value <> Me.LocalDirectory Then
                    m_localDirectory = value
                End If
            End Set
        End Property

        ''' <summary>Gets or sets if the FileDownloader should support total progress statistics. Note that when enabled, the FileDownloader will have to get the size of each file before starting to download them, which can delay the operation.</summary>
        Public Property SupportsProgress() As Boolean
            Get
                Return m_supportsProgress
            End Get
            Set(ByVal value As Boolean)
                If Me.IsBusy Then
                    Throw New InvalidOperationException("Vous ne pouvez pas changer la propriété SupportsProgress pendant un téléchargement ")
                Else
                    m_supportsProgress = value
                End If
            End Set
        End Property

        ''' <summary>Gets or sets if when the download process is cancelled the complete downloads should be deleted</summary>
        Public Property DeleteCompletedFilesAfterCancel() As Boolean
            Get
                Return m_deleteCompletedFiles
            End Get
            Set(ByVal value As Boolean)
                m_deleteCompletedFiles = value
            End Set
        End Property

        ''' <summary>Gets or sets the size of the blocks that will be downloaded</summary>
        Public Property PackageSize() As Int32
            Get
                Return m_packageSize
            End Get
            Set(ByVal value As Int32)
                If value > 0 Then
                    m_packageSize = value
                Else
                    Throw New InvalidOperationException("Le PackageSize doit-être plus grand que 0")
                End If
            End Set
        End Property

        ''' <summary>Gets or sets the amount of blocks that need to be downloaded before the progress speed is re-calculated. Note: setting this to a low value might decrease the accuracy</summary>
        Public Property StopWatchCyclesAmount() As Int32
            Get
                Return m_stopWatchCycles
            End Get
            Set(ByVal value As Int32)
                If value > 0 Then
                    m_stopWatchCycles = value
                Else
                    Throw New InvalidOperationException("Le StopWatchCyclesAmount doit-être plus grand que 0")
                End If
            End Set
        End Property

        ''' <summary>Gets or sets the busy state of the FileDownloader</summary>
        Public Property IsBusy() As Boolean
            Get
                Return m_busy
            End Get
            Set(ByVal value As Boolean)
                If Me.IsBusy <> value Then
                    m_busy = value
                    m_canceled = Not value
                    If Me.IsBusy Then
                        m_totalProgress = 0
                        bgwDownloader.RunWorkerAsync()
                        RaiseEvent Started(Me, New EventArgs)
                        RaiseEvent IsBusyChanged(Me, New EventArgs)
                        RaiseEvent StateChanged(Me, New EventArgs)
                    Else
                        m_paused = False
                        bgwDownloader.CancelAsync()
                        RaiseEvent CancelRequested(Me, New EventArgs)
                        RaiseEvent StateChanged(Me, New EventArgs)
                    End If
                End If
            End Set
        End Property

        ''' <summary>Gets or sets the pause state of the FileDownloader</summary>
        Public Property IsPaused() As Boolean
            Get
                Return m_paused
            End Get
            Set(ByVal value As Boolean)
                If Me.IsBusy Then
                    If value <> Me.IsPaused Then
                        m_paused = value
                        If Me.IsPaused Then
                            trigger.Reset()
                            RaiseEvent Paused(Me, New EventArgs)
                        Else
                            trigger.Set()
                            RaiseEvent Resumed(Me, New EventArgs)
                        End If
                        RaiseEvent IsPausedChanged(Me, New EventArgs)
                        RaiseEvent StateChanged(Me, New EventArgs)
                    End If
                End If
            End Set
        End Property

        ''' <summary>Gets if the FileDownloader can start</summary>
        Public ReadOnly Property CanStart() As Boolean
            Get
                Return Not Me.IsBusy
            End Get
        End Property

        ''' <summary>Gets if the FileDownloader can pause</summary>
        Public ReadOnly Property CanPause() As Boolean
            Get
                Return Me.IsBusy And Not Me.IsPaused And Not bgwDownloader.CancellationPending
            End Get
        End Property

        ''' <summary>Gets if the FileDownloader can resume</summary>
        Public ReadOnly Property CanResume() As Boolean
            Get
                Return Me.IsBusy And Me.IsPaused And Not bgwDownloader.CancellationPending
            End Get
        End Property

        ''' <summary>Gets if the FileDownloader can stop</summary>
        Public ReadOnly Property CanStop() As Boolean
            Get
                Return Me.IsBusy And Not bgwDownloader.CancellationPending
            End Get
        End Property

        ''' <summary>Gets the total size of all files together. Only avaible when the FileDownloader suports progress</summary>
        Public ReadOnly Property TotalSize() As Int64
            Get
                If Me.SupportsProgress Then
                    Return m_totalSize
                Else
                    Throw New InvalidOperationException("Ce FileDownloader ne supporte pas la progression. Modifez SupportsProgress pour qu'il supporte la progression affin de récupérer la taille totale .")
                End If
            End Get
        End Property

        ''' <summary>Gets the total amount of bytes downloaded</summary>
        Public ReadOnly Property TotalProgress() As Int64
            Get
                Return m_totalProgress
            End Get
        End Property

        ''' <summary>Gets the amount of bytes downloaded of the current file</summary>
        Public ReadOnly Property CurrentFileProgress() As Int64
            Get
                Return m_currentFileProgress
            End Get
        End Property

        ''' <summary>Gets the total download percentage. Only avaible when the FileDownloader suports progress</summary>
        Public ReadOnly Property TotalPercentage(Optional ByVal decimals As Int32 = 0) As Double
            Get
                If Me.SupportsProgress Then
                    Return Math.Round(Me.TotalProgress / Me.TotalSize * 100, decimals)
                Else
                    Throw New InvalidOperationException("Ce FileDownloader ne supporte pas la progression. Modifez SupportsProgress pour qu'il supporte la progression .")
                End If
            End Get
        End Property

        ''' <summary>Gets the percentage of the current file progress</summary>
        Public ReadOnly Property CurrentFilePercentage(Optional ByVal decimals As Int32 = 0) As Double
            Get
                Return Math.Round(Me.CurrentFileProgress / Me.CurrentFileSize * 100, decimals)
            End Get
        End Property

        ''' <summary>Gets the current download speed in bytes</summary>
        Public ReadOnly Property DownloadSpeed() As Int32
            Get
                Return m_currentSpeed
            End Get
        End Property

        ''' <summary>Gets the FileInfo object representing the current file</summary>
        Public ReadOnly Property CurrentFile() As FileInfo
            Get
                Return Me.Files(m_fileNr)
            End Get
        End Property

        ''' <summary>Gets the size of the current file in bytes</summary>
        Public ReadOnly Property CurrentFileSize() As Int64
            Get
                Return m_currentFileSize
            End Get
        End Property

        ''' <summary>Gets if the last download was canceled by the user</summary>
        Private ReadOnly Property HasBeenCanceled() As Boolean
            Get
                Return m_canceled
            End Get
        End Property
#End Region

    End Class
#End Region

End Namespace

reste as ajouter ce code à SZ car il ne fait pas partie de la Form .
Voici le code complet de la Form :
Code:
'Option Strict On : Option Explicit On
Imports FPDownloader.Bn.Classes

Public Class Form1
    Private WithEvents downloader As New FileDownloader
    Dim FolderSaveInfo As String
    Dim AppCanClose As Boolean
    Dim InfoBadWebAcces As Boolean
    Dim FileAddListExist As Boolean

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        downloader.SupportsProgress = True
        downloader.DeleteCompletedFilesAfterCancel = True

        Timer1.Start()
        ToolStripStatusLabel1.Text = "Etat : Démarré"
        ToolStripStatusLabel1.ForeColor = Color.Green
        ToolStripStatusLabel1.Image = My.Resources.OK
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        If InternetAccess.IsConnected = False Then
            Panel1.Enabled = False
            ToolStripStatusLabel1.Text = "Etat : Connection WEB perdue"
            ToolStripStatusLabel1.ForeColor = Color.Orange
            ToolStripStatusLabel1.Image = My.Resources.Earth_no2
            InfoBadWebAcces = True
        Else
            Panel1.Enabled = True
            If InfoBadWebAcces = True Then
                ToolStripStatusLabel1.Text = "Etat : Connection WEB restaurée"
                ToolStripStatusLabel1.ForeColor = Color.Green
                ToolStripStatusLabel1.Image = My.Resources.Earth
            End If
           
        End If
    End Sub

    Private Sub ButParcFolder_Click(sender As System.Object, e As System.EventArgs) Handles ButParcFolder.Click
        If Me.FolderBrowserDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            FolderSaveInfo = Me.FolderBrowserDialog1.SelectedPath
            TBFolderSelection.Text = FolderSaveInfo
        Else : FolderSaveInfo = Nothing
        End If
    End Sub

    Private Sub TBUrl_TextChanged(sender As System.Object, e As System.EventArgs) Handles TBUrl.TextChanged
        If TBUrl.Text = "" Then
            ButAddUrl.Enabled = False
        Else
            ButAddUrl.Enabled = True
        End If
    End Sub

    Private Sub ButAddUrl_Click(sender As System.Object, e As System.EventArgs) Handles ButAddUrl.Click

        If FilesToDownload.Items.Count = 0 Then
            FilesToDownload.Items.Add(TBUrl.Text)
            TBUrl.Text = ""
        Else
            For ListeFile = 0 To FilesToDownload.Items.Count - 1

                If FilesToDownload.Items(ListeFile) = TBUrl.Text Then
                    FileAddListExist = True
                    Exit For
                Else
                    FileAddListExist = False
                End If

            Next

            If FileAddListExist = False Then
                FilesToDownload.Items.Add(TBUrl.Text)
                TBUrl.Text = ""
            Else
                MsgBox("Le fichier que vous souhaitez ajouter existe déjà dans la liste de téléchargement .")
            End If

        End If

    End Sub

    Private Sub ButDelLigne_Click(sender As System.Object, e As System.EventArgs) Handles ButDelLigne.Click
        FilesToDownload.Items.Remove(FilesToDownload.SelectedItem)
    End Sub

    Private Sub ButClearList_Click(sender As System.Object, e As System.EventArgs) Handles ButClearList.Click
        FilesToDownload.Items.Clear()
    End Sub
   
    Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click

        If TBFolderSelection.Text <> "" And FilesToDownload.Items.Count <> 0 Then

            With downloader

                .Files.Clear()
                .LocalDirectory = FolderSaveInfo
                For Each path As String In FilesToDownload.Items
                    .Files.Add(New FileDownloader.FileInfo(path))
                Next
                .Start()

            End With

        Else

            If TBFolderSelection.Text = "" And FilesToDownload.Items.Count = 0 Then
                MsgBox("Le dossier de destination n'a pas été déterminé et la liste de téléchargement est vide !")
            ElseIf TBFolderSelection.Text = "" Then
                MsgBox("Le dossier de destination n'a pas été déterminé !")
            ElseIf FilesToDownload.Items.Count = 0 Then
                MsgBox("La liste de téléchargement est vide !")
            End If

        End If

    End Sub

    Private Sub btnPause_Click(sender As System.Object, e As System.EventArgs) Handles btnPause.Click
        downloader.Pause()
    End Sub

    Private Sub btnResume_Click(sender As System.Object, e As System.EventArgs) Handles btnResume.Click
        downloader.Resume()
    End Sub

    Private Sub btnStop_Click(sender As System.Object, e As System.EventArgs) Handles btnStop.Click
        downloader.Stop()
    End Sub

    Private Sub downloader_StateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles downloader.StateChanged 'This is equal to: Handles downloader.IsBusyChanged, downloader.IsPausedChanged
        btnStart.Enabled = downloader.CanStart
        btnStop.Enabled = downloader.CanStop
        btnPause.Enabled = downloader.CanPause
        btnResume.Enabled = downloader.CanResume
        FilesToDownload.Enabled = downloader.IsBusy
        pBarFileProgress.Enabled = Not downloader.IsBusy
    End Sub

    Private Sub downloader_CalculationFileSizesStarted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downloader.CalculationFileSizesStarted
        lblStatus.Text = "Etat : Calcul en cours ..."
    End Sub

    Private Sub downloader_CalculationFileSize(ByVal sender As Object, ByVal fileNumber As Int32) Handles downloader.CalculatingFileSize
        lblStatus.Text = String.Format("Etat : Calcul de la taille du fichier {0} sur {1}", fileNumber, downloader.Files.Count)
    End Sub

    Private Sub downloader_ProgressChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downloader.ProgressChanged
        On Error Resume Next
        pBarFileProgress.Value = CInt(downloader.CurrentFilePercentage)
        lblFileProgressDetails.Text = String.Format("Téléchargé {0} sur {1} ({2}%)", FileDownloader.FormatSizeBinary(downloader.CurrentFileProgress), FileDownloader.FormatSizeBinary(downloader.CurrentFileSize), downloader.CurrentFilePercentage) & String.Format(" - {0}/s", FileDownloader.FormatSizeBinary(downloader.DownloadSpeed))
        If downloader.SupportsProgress Then
            pBarTotalProgress.Value = CInt(downloader.TotalPercentage)
            lblTotalProgressDetails.Text = String.Format("Téléchargé {0} sur {1} ({2}%)", FileDownloader.FormatSizeBinary(downloader.TotalProgress), FileDownloader.FormatSizeBinary(downloader.TotalSize), downloader.TotalPercentage)
        End If
    End Sub

    Private Sub downloader_FileDownloadAttempting(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downloader.FileDownloadAttempting
        lblStatus.Text = String.Format("Etat : Preparation {0}", downloader.CurrentFile.Path)
    End Sub

    Private Sub downloader_FileDownloadStarted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downloader.FileDownloadStarted
        lblStatus.Text = String.Format("Etat : Téléchargement de {0}", downloader.CurrentFile.Path)
        lblFileSize.Text = String.Format("Taille du fichier : {0}", FileDownloader.FormatSizeBinary(downloader.CurrentFileSize))
        lblTargetPath.Text = String.Format("Enregistrer dans {0}\{1}", downloader.LocalDirectory, downloader.CurrentFile.Name)
    End Sub

    Private Sub downloader_Completed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downloader.Completed
        lblStatus.Text = String.Format("Etat : Téléchargement terminé , {0} fichiers téléchargés .", downloader.Files.Count.ToString)
        FilesToDownload.Items.Clear()
    End Sub

    Private Sub downloader_CancelRequested(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downloader.CancelRequested
        lblStatus.Text = "Etat : Annulation du téléchargement ..."
    End Sub

    Private Sub downloader_DeletingFilesAfterCancel(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downloader.DeletingFilesAfterCancel
        lblStatus.Text = "Etat : Annulation du téléchargement , suppression des fichiers temporaires ..."
    End Sub

    Private Sub downloader_Canceled(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downloader.Canceled
        lblStatus.Text = "Etat : Téléchargement(s) annulé(s)"
        pBarFileProgress.Value = 0
        pBarTotalProgress.Value = 0
        lblFileProgressDetails.Text = "-"
        lblTotalProgressDetails.Text = "-"
        lblFileSize.Text = "-"
        lblTargetPath.Text = "-"
    End Sub

    Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If downloader.CanStart = True Then
            e.Cancel = False

        Else
            e.Cancel = True
            MsgBox("Un téléchargement est en cours." & System.Environment.NewLine & "Veuillez le terminer")
        End If
    End Sub

   
End Class
Et maintenent , l'interface :

Téléchargements... Sz22

Le lien de téléchargement :
ATTENTION , ce programme as été réalisé sous VisualBasic 2010 express
par François Production , tous droits réservés .
Lien : http://lereparateurdepc.olympe-network.com/sz_tmp/FPDownloader.exe
NOTE : L'hébergeur de mon site as des petits problèmes DNS depuis ce matin ( 15/04/12) .

Cordialement ,
Le réparateur de PC



Modérateur & Administrateur du forum
Merci de contacter les membres par MP ou mail que pour "urgences". Le forum est fait pour ça. Merci

@ Contact : franleboss@gmail.com  Smile
Arrow  Visitez mon site : désolé l'hébergeur à fermé Sad

Ma chaine tutube : https://www.youtube.com/channel/UC7iU59NNAHz-tW5wqcgONHA


Téléchargements... Wp_20110Téléchargements... 10_32010Téléchargements... Wp_20111Téléchargements... 07_sig10
Dr. :)
Dr. :)
On s'intègre
On s'intègre

Masculin Nombre de messages : 197
Localisation : Savoie
Emploi/loisirs : Programation,Youtuber
Humeur : Sur un nuage
Date d'inscription : 17/07/2011

Téléchargements... Empty Re: Téléchargements...

Message par Dr. :) le Jeu 19 Avr 2012 - 0:53

@Lerepdepc : J'avait essayer ses codes , c'est vraiment galère a mettre en place , j'ai laisser tomber.



Dark , alias Darkinounais pour les intimes. Développeur , webmaster , touche-a-tout et co-créateur de la team BloodyShadows.

Site web : http://bloodyshadows.fr
Chaîne Youtube : https://www.youtube.com/user/MWgamersfr

Contenu sponsorisé

Téléchargements... Empty Re: Téléchargements...

Message par Contenu sponsorisé


    La date/heure actuelle est Mar 16 Juil 2019 - 4:46