Page 1 sur 1

Barre de Progression Téléchargment

Posté : mar. 23 mai 2023 16:12
par Antho
Bonjour à toutes et à tous,

Cela fais quelques jours que je me creuse le crane sur un système de barre de progression pour mes téléchargements.

J'ai beau essayer les différents codes trouvés sur le forum ou sur le guide Autioit, rien n'y fais, ma barre va jusqu'à la fin sans prendre en compte l'avancée du réel téléchargement..

J'ai tout essayé, je sèche...

Merci à ceux qui pourront m'aider

Voici mon code:

Code : Tout sélectionner

Func DL_VCDS()
	   Global $Url = $vcdsmanager_url & $nom_fichier_vcds
	   Global $Fichier = $vcdsmanager_dir & $nom_fichier_vcds

	 $FileSize = InetGetSize ($vcdsmanager_url & $nom_fichier_vcds)
	  MsgBox(64, $vcdsmanager_dir, $FileSize, $vcdsmanager_dir)
	  InetGet ( $Url , $Fichier , 1 , 1 )

	  ProgressOn ( " test " , " " , " " )
	  While @InetGetActive
		 $Prog = Int ((50000 * 100 ) / $FileSize )
		 ProgressSet ( $Prog , @InetGetBytesRead & " / " & $FileSize & " bytes " , " Téléchargement du fichier hosts " )
		 Sleep ( 100 )
	  WEnd

	  ProgressSet ( 100 , " Terminé " , " Complete " )
	  Sleep ( 5000 )
	  ProgressOff ( )
 EndFunc
J'ai aussi essayé celui là, il ne donne absolument rien:

Code : Tout sélectionner

Func DL_VCDS()
	  $FileSize = InetGetSize($vcdsmanager_url & $nom_fichier_vcds)
	  MsgBox(64, $vcdsmanager_dir, $FileSize, $vcdsmanager_dir)
	  InetGet($vcdsmanager_url & $nom_fichier_vcds, $vcdsmanager_dir & $nom_fichier_vcds, 1, 1)

	  HotKeySet("{ESC}", "_InetGetAbort")

	  ProgressOn("Téléchargement de "&$nom_fichier_vcds, "", "0%")
	  While @InetGetActive
		 $Prog = Int((100 * @InetGetBytesRead) / $FileSize)
		 ProgressSet($prog, @InetGetBytesRead & "/" & $FileSize & " bytes", "Downloading "&$nom_fichier_vcds)
		 Sleep(250)
	  WEnd
 EndFunc

Re: Barre de Progression Téléchargment

Posté : mar. 23 mai 2023 16:48
par mikell
ça fait une paye que je n'utilise plus Inet... tu connais Curl ? c'est plus fiable

Re: Barre de Progression Téléchargment

Posté : mar. 23 mai 2023 17:12
par Antho
Je l'utilise en PHP, j'ai jamais regardé sur AutoIt, tu penses que j'aurais mieux?

Car selon mes test la taille du fichier est bien récupérée, ce serait @InetGetBytesRead qui ne lit pas correctement

Re: Barre de Progression Téléchargment

Posté : mar. 23 mai 2023 21:30
par mikell
C'est à dire que Curl offre beaucoup de possibilités tout en restant très maniable
Essaie ça pour voir
Le ConsoleWrite te montre exactement comment ça marche, après mettre ça dans un code devient hyper simple Image

#include <AutoItConstants.au3>

$source = "https://www.autoitscript.com/autoit3/files/archive/autoit/autoit-v3.3.14.5.zip"
$file = StringRegExpReplace($source, '.*/([^/]+)$', "$1")

$cmd = 'curl -L -k ' & $source & ' -o "' & @scriptdir & '\' & $file & '"'
Local $iPID = Run($cmd, "", @SW_HIDE, $STDERR_CHILD)

ProgressOn($file, "")
While 1
   $stderr = StderrRead($iPID)
   If @error Then Exitloop
   If $stderr <> "" and StringRegExp($stderr, '(?i)[kmg]') Then
      ; Consolewrite($stderr) ; display the progress data
      $pc = StringRegExp($stderr, '(\d+)', 1)
      If not @error Then ProgressSet($pc[0], $pc[0] & " %")
   EndIf
Wend
ProgressOff()
Msgbox(0,"", $file & " : done")

Re: Barre de Progression Téléchargment

Posté : jeu. 25 mai 2023 13:10
par Nine
Meh, tu as une version antédiluvienne de AutoIt ! Serait peut-être temps de mettre à jour...