Page 1 sur 1

Taille fichier à télécharger

Publié : dim. 24/févr./2008 16:07
par Atomo
Salut à tous, j'essai de faire un downloader du même genre que celui de Windows, j'ai donc récupérer ce bout de code de Droopy (que je remercie au passage :wink: ) provenant de son Youtube Downloader, il permet de connaître la taille du fichier à télécharger.
Quand je test ce code chez moi il n'y a pas de problème, le message requester m'affiche bien la taille en Ko du fichier, cependant chez certaines personnes la taille renvoyée est de 0.
Une des personnes utilise Windows XP sp2 comme moi, je ne vois pas d'où vient le problème, quelqu'un pourrait m'aider ? Merci.

Code : Tout sélectionner

Procedure Taille()
  ;Calcule de la taille du fichier à télécharger
  DownloadURL.s = "http://www.purebasic.com/download/PureBasic_Demo.exe" ;adresse de telechargement
    
  Protected hInet, hURL, Bytes
  Protected BufferLength = 2048, Buffer.s = Space(BufferLength) 
    
  Protected Url.s      = DownloadURL.s 
  Protected Filename.s = DownloadFilename.s 
  Protected File
  Protected CurrentSize.f, PreviousSize.f, FileSize.f, time, BytesPerSecond
  Protected Domain.s, String.s, i, BufferLengthWas = BufferLength
  Protected hInetCon, hHttpOpenRequest, iretval 
  
  hInet = InternetOpen_("Downloader",0,0,0,0) 
  hURL  = InternetOpenUrl_(hInet,Url.s,0,0,$80000000,0) 
    
  Domain.s  = StringField(Url.s,3,"/") 
  hInetCon = InternetConnect_(hInet,Domain.s,80,#Null,#Null,3,0,0) 
  If hInetCon 
    hHttpOpenRequest = HttpOpenRequest_(hInetCon,"HEAD",ReplaceString(Url.s,"http://"+Domain.s+"/",""),#Null,#Null,0,$80000000,0) 
    If hHttpOpenRequest 
      iretval = HttpSendRequest_(hHttpOpenRequest,#Null,0,0,0) 
      If iretval 
        HttpQueryInfo_(hHttpOpenRequest,19,@Buffer.s,@BufferLength,0) ;changes the buffer length 
        String.s = PeekS(@Buffer.s,BufferLength): BufferLength = BufferLengthWas 
        If Trim(String.s) = "200" 
          HttpQueryInfo_(hHttpOpenRequest,22,@Buffer.s,@BufferLength,0) 
          String.s = PeekS(@Buffer.s,BufferLength): BufferLength = BufferLengthWas 
          If FindString(String.s,"Content-Length:",1) 
            i = FindString(String.s,"Content-Length:",1) + Len("Content-Length:") 
            String.s = Mid(String.s,i,Len(String.s)-i) 
            FileSize = Val(Trim(String.s))/1024
          EndIf 
        EndIf 
      EndIf 
    EndIf 
  EndIf
    
  MessageRequester("Taille", Str(FileSize))
EndProcedure

taille()
End

Publié : dim. 24/févr./2008 22:28
par Ar-S
Je ne peux pas te dire, le code fonctionne chez moi...
XP Pro SP2

Publié : lun. 25/févr./2008 23:38
par Atomo
D'autres personnes peuvent tester s'il vous plaît et me dire si ça marche bien chez vous ?

Publié : lun. 25/févr./2008 23:45
par Neosis
chez moi ça marche :)

Publié : mar. 26/févr./2008 0:39
par Le psychopathe
Neosis a écrit :chez moi ça marche :)
idem

Publié : mar. 26/févr./2008 6:32
par venom
bonjour,

chez moi aussi sa fonctionne j'ai même essayer sur mon site perso sa renvoie la bonne valeur bravo Atomo :wink:


@++

Re: Taille fichier à télécharger

Publié : mar. 26/févr./2008 18:05
par lionel_om
Atomo a écrit :requester m'affiche bien la taille en Ko du fichier, cependant chez certaines personnes la taille renvoyée est de 0.
Une des personnes utilise Windows XP sp2 comme moi, je ne vois pas d'où vient le problème, quelqu'un pourrait m'aider ? Merci.
Ils ont bien leur connexion Internet active ou y'a pas un parefeu qui bloque ?

Lio :wink:

Publié : mar. 26/févr./2008 20:19
par Atomo
J'ai crée un programme de mise à jour automatique pour mon application, ces personnes n'arrivent pas à voir la taille du fichier, par contre le téléchargement ne cause pas de soucis.
Il n'y à pas de pare-feu d'après leur dires.

Il n'existe pas une autre façon de connaître la taille d'un fichier ?

Publié : mar. 26/févr./2008 20:24
par wolfjeremy
Le demander à une page php !

Publié : mar. 26/févr./2008 20:35
par Atomo
Le demander à une page php !
Ca reste envisageable dans mon cas, merci du conseil. :)