Page 1 sur 1

Dl de fichier

Publié : sam. 21/mai/2005 15:37
par lionel_om
Bonjour à tous
Je voudrai créer un petit programme pour mettre à jour mon antivirus (pb avec le dl des update).

ACTUELLEMENT :
J'ai accès à une page internet que me donne le nom (et le lien) pour télécharger le nouveau "Virus pattern", puis je dézippe et copy dans le bon dossier, reboot mon PC et mon anti-V est up-to-date.

CE KE JE CHERCHE A FAIRE :
connu : page qui propose les MAJ
nom du dossier où sont les MAJ

Je voudrais donc soit :
* analyser le dossier comportant les MAJ, prendre le plus récent et le copier sur mon DD
* analyser la page web affichée, trouver le lien (pas trop dur à faire ça), puis copier l'update

Puis dézipper le fichier et le copier dans le bon dossier (ça je devrais pouvoir me débrouiller, faut juste que je trouve les paramètres pour WinAce pour dézipper un fichier).

Si qq1 peut m'aider ça serait cool !!! à moins ke pureBasic ne comporte pas les fonctions pour faire ceci ???

Merci @ ++

Publié : sam. 21/mai/2005 15:55
par Droopy
Pour le téléchargement depuis une URL il y a la lib de Num3

http://forums.purebasic.com/english/vie ... ght=geturl

Publié : sam. 21/mai/2005 22:02
par lionel_om
Merci, je vais jeter un oeil :wink:

Publié : dim. 22/mai/2005 8:52
par lionel_om
Merci, j'ai trouvé toutes les infos dont j'avais besoin.
Je posterai mon code une fois ce prog fini, au cas où ça intéresserai qq1 :lol:

Publié : dim. 22/mai/2005 14:25
par lionel_om
J'ai un petit problème avec mon programme qui, je précise au passe, n'a rien d'illégal.

@Droopy :
J'ai utilisé la lib et ça marche nikel, merci bien ! :D

Par contre j(ai un pb avec les Threads, ma fenêtre està moitié "gelée" : elle n'est pas bien réactialiser et certains Gadgets sont affichés que 5 secondes après le lancement du programme.

SI vous pouvez m'aider ça serait cool !!!

voici mon code (juste la partie concernée par le problème :

Code : Tout sélectionner

IncludeFile "http.pb"



#PROJECT_NAME.s = "Update PCC 2005"

;- Window Constants
;

Enumeration
  #Window_1
EndEnumeration


Enumeration
  #Frame3D_0
  #ProgressBar_1
  #Text_0
  #Text_1
  #Text_2
  #Text_3
  #Text_4
  #Button_1
EndEnumeration


Procedure Open_Window_1()
  If OpenWindow(#Window_1, 545, 215, 317, 153,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , #PROJECT_NAME)
    If CreateGadgetList(WindowID())
      Frame3DGadget(#Frame3D_0, 10, 0, 300, 125, "")
      ProgressBarGadget(#ProgressBar_1, 20, 50, 280, 20, 0, 100)
      TextGadget(#Text_0, 20, 30, 170, 20, "Version de la mise à jour :")
      TextGadget(#Text_1, 20, 80, 140, 20, "Etat du téléchargement : ")
      TextGadget(#Text_2, 200, 80, 90, 20, "")
      TextGadget(#Text_3, 20, 100, 110, 20, "Vitesse de transfert :")
      TextGadget(#Text_4, 200, 100, 90, 20, "")
      ButtonGadget(#Button_1, 120, 130, 80, 20, "Annuler")
    EndIf
  EndIf
EndProcedure


Procedure.s GetWebFilePart(lastUpdate.s)

  lastUpdate = ReplaceString(lastUpdate, "http://www." , "c:\")
  lastUpdate = ReplaceString(lastUpdate, "/" , "\")
  ProcedureReturn GetFilePart(lastUpdate)

EndProcedure



Procedure SetTransfertRate(gadget, nbOctets.f, rate)

  unite$ = "o/s"
  nbOctets = nbOctets * (1000 / rate)
  
  If nbOctets > 1000
  
    nbOctets = nbOctets / 100
    nbOctets = nbOctets / 10.0
    unite$ = "Ko/s"
    
    If nbOctets > 1000
    
      nbOctets = nbOctets / 100
      nbOctets = nbOctets / 10.0
      unite$ = "Mo/s"
      
    EndIf
  
  EndIf    

  SetGadgetText(gadget, Str(nbOctets) + " " + unite$)

EndProcedure



Procedure SetTransfertState(gadget, actuel, total)

  SetGadgetText(gadget, Str(actuel) + "/" + Str(total))

EndProcedure



; *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*

; fichier à télécharger
url$ = "http://www.trendmicro.com/ftp/products/pattern/lpt637.zip"


  ; Téléchargement du fichier
  ; -------------------------
  If HTTP_Init()

    Result= HTTP_New_Connection(url$,80)  
    If Result>0 ;All error are negative numbers
    
      size.l=HTTP_File_Size(Result)
      Open_Window_1()  ; Création de la fenêtre
      Delay(200)
      
      ; Fonction pour Dl le fichier
      ThreadID = HTTP_Download_ToFile(Result,GetWebFilePart(url$))
      If ThreadID
      
        current = 0
        rate = 500
        
        ; Boucle
        Repeat
        
          EventID.l = WindowEvent()
          
          
          If EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button
            KillThread(ThreadID)
            End
          EndIf
          
          If EventID = #PB_Event_Gadget
            If EventGadgetID() = #Button_1
              KillThread(ThreadID)
              End
            EndIf
          EndIf

          ; Actualisation de la fenêtre
          exSize = current
          current.l=HTTP_Get_Progress(Result)
          SetTransfertRate(#Text_4, current - exSize, rate)
          Debug current
          SetTransfertState(#Text_2, current, size)
          SetGadgetState(#ProgressBar_1, (current*100)/size)
          SetWindowTitle(#Window_1, #PROJECT_NAME + " - " + Str((current*100)/size) + "%")
         
          ; On attend (pour ne pas oqp tout l'UC)
          Delay(rate)
          
        Until size=current
        
      Else
      
        MessageRequester("Erreur", HTTP_LastError_Description(),#MB_ICONERROR)
        End
        
      EndIf
      
    Else
    
      MessageRequester("Erreur",HTTP_LastError_Description(),#MB_ICONERROR )
      End
      
    EndIf
    
  EndIf

Et le fichier à inclure (la LIB, un peu épurée et modifiée) :

Code : Tout sélectionner


#HTTP_Ok = 1
#HTTP_Error = 0
#HTTP_ProxyData_Needed = -2
#HTTP_Authentication_Needed =-3
#HTTP_Invalid_URL = -4
#HTTP_FileNotFound = -5
#HTTP_FileMoved = -6
#HTTP_TimeOut = -7
#HTTP_UnknowFileSize = -8
#HTTP_UnknowDate = -9
#HTTP_Downloading = 2
#HTTP_DownloadEnd = 3

#HTTP_Action_Get2File = 2
#HTTP_Action_Get2Mem = 3
#HTTP_Action_GetInfo = 4


Structure http
  in_buffer.l
  server.s
  path.s
  file.s
  
  url_port.l
  file_progress.l
  
  savefile.s
  membuffer.l
  
  file_size.l
  file_date.l
  
  proxy.s
  puser.s
  ppass.s
  pport.l
  
  wwwuser.s
  wwwpass.s
EndStructure






Procedure HTTP_Init();Start HTTP library
  If InitNetwork()
    
    Global InBuffer.l,Last_Error.l
    InBuffer=10240
    
    NewList http_data.http()
    If AddElement(http_data()) : EndIf
    
    
    ;-URL-Commands
    ;{Day,Month
    Dim wkday$(6)
    Dim weekday$(6)
    Dim Month$(12)
    wkday$(1)="MON"
    wkday$(2)="TUE"
    wkday$(3)="WED"
    wkday$(4)="THU"
    wkday$(5)="FRI"
    wkday$(6)="SAT"
    wkday$(0)="SUN"
    weekday$(1)="MONDAY"
    weekday$(2)="TUESDAY"
    weekday$(3)="WEDNESDAY"
    weekday$(4)="THURSDAY"
    weekday$(5)="FRIDAY"
    weekday$(6)="SATURDAY"
    weekday$(0)="SUNDAY"
    Month$(1)="JAN"
    Month$(2)="FEB"
    Month$(3)="MAR"
    Month$(4)="APR"
    Month$(5)="MAY"
    Month$(6)="JUN"
    Month$(7)="JUL"
    Month$(8)="AUG"
    Month$(9)="SEP"
    Month$(10)="OCT"
    Month$(11)="NOV"
    Month$(12)="DEC"
    ;} 
    
    ProcedureReturn #HTTP_Ok
  Else
    ProcedureReturn #HTTP_Error
  EndIf
EndProcedure
  
Procedure.s HTTP_LastError_Description();Textual error description
  
  Select Last_Error
    Case #HTTP_Invalid_URL
      text.s="L'URL est invalide."
      
    Case #HTTP_ProxyData_Needed
      text.s="Proxy authentication needed"
      
    Case #HTTP_Authentication_Needed
      text.s="Vous devez vous identifier."
      
    Case #HTTP_FileNotFound
      text.s="Fichier introuvable."
      
    Case #HTTP_FileMoved
      text.s="Fichier déplacé."
      
    Case #HTTP_TimeOut
      text.s="Délai de connexion expiré."
      
    Default
      text.s="Une erreur est survenue."
  EndSelect
  
  ProcedureReturn text.s
  
EndProcedure
  
  
Procedure HTTP_LastError_ID();Last error return code
  ProcedureReturn Last_Error
EndProcedure

;///// internal procedures

Procedure int_AnalyseDate(TestTime$)
  ;Thank to GPI for this code :P
  
  TestTime$=ReplaceString(Trim(UCase(TestTime$)),"  "," ")
  day=0:Month$="":year=0:Time$=""
  For i=0 To 6
    If Left(TestTime$,4)=wkday$(i)+","                        ;{"rfc1123-Date"
      day=Val(StringField(TestTime$,2," "))
      Month$=StringField(TestTime$,3," ")
      year=Val(StringField(TestTime$,4," "))
      Time$=StringField(TestTime$,5," ")
      Break
      ;}
    ElseIf Left(TestTime$,Len(weekday$(i))+1)=weekday$(i)+"," ;{"rfc850-Date"
      SubTime$=StringField(TestTime$,2," ")
      day=Val(StringField(SubTime$,1,"-"))
      Month$=StringField(SubTime$,2,"-")
      year=Val(StringField(SubTime$,3,"-"))
      If year>80:year+1900:Else:year+2000:EndIf
      Time$=StringField(TestTime$,3," ")
      Break
      ;}
    ElseIf Left(TestTime$,4)=wkday$(i)+" "                    ;{"asctime-Date"
      day=Val(StringField(TestTime$,3," "))
      Month$=StringField(TestTime$,2," ")
      year=Val(StringField(TestTime$,5," "))
      Time$=StringField(TestTime$,4," ")
      Break
      ;}
    EndIf
  Next
  For i=1 To 12
    If Month$(i)=Month$ : month=i:Break : EndIf
  Next
  Date=ParseDate("%hh:%ii:%ss",Time$)
  Hour=Hour(Date)
  Min=Minute(Date)
  Sec=Second(Date)
  
  ProcedureReturn Date(year,month,day,Hour,Min,Sec)
EndProcedure  



Procedure int_Parse_URL(ConnectionID.l,Url.s)
  Url=LCase(Url)
  
  If FindString(Url,"http://",0)=#True
    Url=RemoveString(Url,"http://")
  EndIf
  
  Url=ReplaceString(Url,"\","/",1)
  
  server.s=StringField(Url,1,"/")
  If server<>""
    http_data()\server=StringField(Url,1,"/")
    
    out.s=""
    For a=2 To CountString(Url,"/")
      out.s+"/"+StringField(Url,a,"/")
    Next
    out.s+"/"
    
    If out<>"/"
      http_data()\path=out
    Else
      http_data()\path=""
    EndIf
    
    file.s=StringField(Url,CountString(Url,"/")+1,"/")
    
    If file<>"" 
      http_data()\file=file
    Else
      ProcedureReturn #HTTP_Invalid_URL
    EndIf
    
    ProcedureReturn #HTTP_Ok
    
  Else
    
    ProcedureReturn #HTTP_Invalid_URL
    
  EndIf
  
EndProcedure



Procedure int_Action(in_data.l)
  
  command.s=PeekS(in_data)
  
  Debug command
  
  ConnectionID.l=Val(StringField(command,1,"|"))
  Action.l=Val(StringField(command,2,"|"))
  
  If SelectElement(http_data(),ConnectionID)=0
    ProcedureReturn #HTTP_Error
  EndIf
  
  Debug ListIndex(http_data())
  
  If http_data()\proxy<>""
    conc$=http_data()\puser+":"+http_data()\ppass
    OutputBuffer = AllocateMemory(Len(conc$))
    Base64Encoder(conc$,Len(conc$),OutputBuffer,OutputBuffer*2)
    penc$=PeekS(OutputBuffer)
    internetID = OpenNetworkConnection(proxyserver$, Val(proxyport$))
  Else
    internetID = OpenNetworkConnection(server$, Val(port$))
  EndIf
  
  If http_data()\wwwpass<>""
    conc$=http_data()\wwwuser +":"+http_data()\wwwpass
    OutputBuffer = AllocateMemory(Len(conc$))
    Base64Encoder(conc$,Len(conc$),OutputBuffer,OutputBuffer*2)
    wenc$=PeekS(OutputBuffer)
  EndIf
  
  header=#False
  download=#False
  file_size=0
  
  resend:
  
  If http_data()\proxy<>""
    internetID = OpenNetworkConnection(http_data()\proxy, http_data()\pport)
  Else
    internetID = OpenNetworkConnection(http_data()\server,http_data()\url_port)
  EndIf
  
  If internetID
    
    ;{ /// File Information
    com$="HEAD "+http_data()\path+http_data()\file+" HTTP/1.1"+Chr(13)+Chr(10)
    com$+"Accept: */*"+Chr(13)+Chr(10)
    com$+"Host: "+http_data()\server+Chr(13)+Chr(10) 
    com$+"User-Agent: PureDownload 1.0"+Chr(13)+Chr(10)
    If http_data()\proxy<>""
      com$+"Proxy-Authorization: Basic "+enc$+Chr(13)+Chr(10)
    EndIf
    If http_data()\wwwuser<>""
      com$+"Authorization: Basic "+wenc$+Chr(13)+Chr(10)
    EndIf
    If cookie$<>""
      com$+"Cookie: "+cookie$+Chr(13)+Chr(10)
    EndIf
    If location$<>""
      com$+"Location: "+location$+Chr(13)+Chr(10)
    EndIf
    
    com$+Chr(13)+Chr(10)
    res = SendNetworkData(internetID,@com$,Len(com$))
    
    If res < 0
      CloseNetworkConnection(internetID)
      Last_Error=#HTTP_Error
      ProcedureReturn #HTTP_Error
    EndIf
    
    Repeat
      
      index.l=ListIndex(http_data())
      
      If index<0
        ProcedureReturn
      EndIf
      
      Result = NetworkClientEvent(internetID)
      
      If Result=2 ;/// Raw data received
        Content$ = Space(14500)
        ReceiveNetworkData(internetID,@Content$,14500)
        
        Content$=Trim(LCase(Content$))
        
        ;/// File not found handle
        If FindString(Content$,"404",1)
          CloseNetworkConnection(internetID)
          Last_Error=#HTTP_FileNotFound
          ProcedureReturn #HTTP_FileNotFound
        EndIf
        
        ;/// File moved
        If FindString(Content$,"301",1)
          CloseNetworkConnection(internetID)
          Last_Error=#HTTP_FileMoved
          ProcedureReturn #HTTP_FileMoved
        EndIf
        
        ;/// www authorization required
        If FindString(Content$,"401",1)
          CloseNetworkConnection(internetID)
          Last_Error=#HTTP_Authentication_Needed
          ProcedureReturn #HTTP_Authentication_Needed
        EndIf
        
        ;/// File found handle but redirect
        If FindString(Content$,"302",1)
          location$=""
          loc=FindString(Content$,"location: ",1)
          If loc>0
            temploc.s=Mid(Content$,loc+10,Len(Content$))
            For a=1 To Len(temploc)
              tcok.s=Mid(temploc,a,1)
              If tcok<>Chr(13)
                location$+tcok
              Else
                Break 1
              EndIf
            Next
          EndIf
        EndIf
        
        ;/// Site sends cookie authentication
        cok=FindString(Content$,"set-cookie: ",1)
        cookie$=""
        
        If cok>0
          tempcok.s=Mid(Content$,cok+12,Len(Content$))
          For a=1 To Len(tempcok)
            tcok.s=Mid(tempcok,a,1)
            If tcok<>";"
              cookie$+tcok
            Else
              Break 1
            EndIf
          Next
          Goto resend
        EndIf
        
        
        ;/// File found handle
        If FindString(Content$,"200",1)
          
          pos=FindString(Content$,"content-length:" , 1)
          If pos
            pos=FindString(Content$," " , pos+15)
            file_size=Val(Mid(Content$,pos+1,Len(Content$)))
            http_data()\file_size=file_size
          Else
            CloseNetworkConnection(internetID)
            Last_Error=#HTTP_UnknowFileSize
            ProcedureReturn #HTTP_UnknowFileSize
          EndIf
          
          pos=FindString(LCase(Content$),"modified: " , 1)
          pos1=FindString(Content$,Chr(13)+Chr(10),pos)
          If pos
            Date.s=Mid(Content$,pos+10,(pos1-pos-10)) 
            http_data()\file_date=int_AnalyseDate(Date.s)
          Else
            CloseNetworkConnection(internetID)
            Last_Error=#HTTP_UnknowDate
            ProcedureReturn #HTTP_UnknowDate
          EndIf
          
          
        Else
          CloseNetworkConnection(internetID)
          Last_Error=#HTTP_FileNotFound
          ProcedureReturn #HTTP_FileNotFound
        EndIf
        header=#True
      EndIf
      
      
      
    Until header=#True
    ;}
    
    If Action=#HTTP_Action_Get2File
      ;{ /// File Download
      com$="GET "+http_data()\path+http_data()\file+" HTTP/1.1"+Chr(13)+Chr(10)
      com$+"Accept: */*"+Chr(13)+Chr(10)
      com$+"Host: "+http_data()\server+Chr(13)+Chr(10) 
      com$+"User-Agent: PureDownload 1.0"+Chr(13)+Chr(10)
      If http_data()\proxy<>""
        com$+"Proxy-Authorization: Basic "+enc$+Chr(13)+Chr(10)
      EndIf
      If http_data()\wwwuser<>""
        com$+"Authorization: Basic "+wenc$+Chr(13)+Chr(10)
      EndIf
      If cookie$<>""
        com$+"Cookie: "+cookie$+Chr(13)+Chr(10)
      EndIf
      If location$<>""
        com$+"Location: "+location$+Chr(13)+Chr(10)
      EndIf
      
      com$+Chr(13)+Chr(10)
      res = SendNetworkData(internetID,@com$,Len(com$))
      
      If res < 0
        CloseNetworkConnection(internetID)
        Last_Error=#HTTP_Error
        ProcedureReturn #HTTP_Error
      EndIf
      
      http_data()\file_progress=0
      
      Debug "file : " + http_data()\file
      If CreateFile(0,http_data()\file)
        incoming_buffer=AllocateMemory(http_data()\in_buffer)
        
        time.l=ElapsedMilliseconds()
        
        Repeat
          Delay(1)
          
          index.l=ListIndex(http_data())
          
          If index<0
            ProcedureReturn
          EndIf
          
          Result = NetworkClientEvent(internetID)
          
          If Result=0 ;/// time out counter
            now=ElapsedMilliseconds()
            If now-time > 2000 
              Last_Error=#HTTP_TimeOut
              ProcedureReturn #HTTP_TimeOut
            EndIf
            
          ElseIf Result=2 ;/// Raw data received
            size=ReceiveNetworkData(internetID,incoming_buffer,http_data()\in_buffer)
            
            offset.l=FindString(PeekS(incoming_buffer),Chr(13)+Chr(10)+Chr(13)+Chr(10),1)
            If offset>0
              offset+3
            EndIf
            
            http_data()\file_progress+size-offset
            ; Debug http_data()\file_progress
            
            If size>0
              WriteData(incoming_buffer+offset,size-offset)
              If http_data()\file_size=http_data()\file_progress
                file=#True
              EndIf
              time=ElapsedMilliseconds()
            EndIf
            
          EndIf
        Until file=#True
        CloseFile(0)
        FreeMemory(incoming_buffer)
        
        CloseNetworkConnection(internetID)
        
        ProcedureReturn #HTTP_DownloadEnd
      EndIf
      
      ;}
      
    EndIf
    
    
    If Action=#HTTP_Action_Get2Mem
      ;{ /// Memory Download
      com$="GET "+http_data()\path+http_data()\file+" HTTP/1.1"+Chr(13)+Chr(10)
      com$+"Accept: */*"+Chr(13)+Chr(10)
      com$+"Host: "+http_data()\server+Chr(13)+Chr(10) 
      com$+"User-Agent: PureDownload 1.0"+Chr(13)+Chr(10)
      If http_data()\proxy<>""
        com$+"Proxy-Authorization: Basic "+enc$+Chr(13)+Chr(10)
      EndIf
      If http_data()\wwwuser<>""
        com$+"Authorization: Basic "+wenc$+Chr(13)+Chr(10)
      EndIf
      If cookie$<>""
        com$+"Cookie: "+cookie$+Chr(13)+Chr(10)
      EndIf
      If location$<>""
        com$+"Location: "+location$+Chr(13)+Chr(10)
      EndIf
      
      com$+Chr(13)+Chr(10)
      res = SendNetworkData(internetID,@com$,Len(com$))
      
      If res < 0
        CloseNetworkConnection(internetID)
        Last_Error=#HTTP_Error
        ProcedureReturn #HTTP_Error
      EndIf
      
      http_data()\file_progress=0
      
      If http_data()\membuffer
        incoming_buffer=AllocateMemory(http_data()\in_buffer)
        
        time.l=ElapsedMilliseconds()
        
        Repeat
          Delay(1)
          
          index.l=ListIndex(http_data())
          
          If index<0
            ProcedureReturn
          EndIf
          
          Result = NetworkClientEvent(internetID)
          
          If Result=0 ;/// time out counter
            now=ElapsedMilliseconds()
            If now-time > 2000 
              Last_Error=#HTTP_TimeOut
              ProcedureReturn #HTTP_TimeOut
            EndIf
            
          ElseIf Result=2 ;/// Raw data received
            size=ReceiveNetworkData(internetID,incoming_buffer,http_data()\in_buffer)
            
            offset.l=FindString(PeekS(incoming_buffer),Chr(13)+Chr(10)+Chr(13)+Chr(10),1)
            If offset>0
              offset+3
            EndIf
            
            If size>0
              CopyMemory(incoming_buffer+offset,http_data()\membuffer+http_data()\file_progress,size-offset)
              If http_data()\file_size=http_data()\file_progress
                file=#True
              EndIf
              time=ElapsedMilliseconds()
            EndIf
            
            http_data()\file_progress+size-offset
            
          EndIf
        Until file=#True
        FreeMemory(incoming_buffer)
      EndIf
        CloseNetworkConnection(internetID)
        
        ProcedureReturn #HTTP_DownloadEnd
        ;}
      EndIf
      
    CloseNetworkConnection(internetID)
    ProcedureReturn #HTTP_Ok
    
  EndIf
  
EndProcedure
  
  
  
  ;///// External procedures
Procedure HTTP_New_Connection(Url.s,Port.l) ;Create a new HTTP connection, if file exists returns ConnectionID
  
  If Port=0
    Port=80
  EndIf
  
  
  If AddElement(http_data())
    Result = int_Parse_URL(ListIndex(http_data()),Url)
    
    If Result<>#HTTP_Ok
      DeleteElement(http_data())
      Last_Error=#HTTP_Invalid_URL
      ProcedureReturn #HTTP_Error
    EndIf
    index.l=ListIndex(http_data())
    
    http_data()\url_port=Port
    http_data()\in_buffer=InBuffer
    
    line.s=Str(index)+"|0"
    size=int_Action(@line)
    
    If size<>#HTTP_Ok
      ProcedureReturn HTTP_LastError_ID()
    EndIf
    
    ProcedureReturn index
    
  Else
    ProcedureReturn #HTTP_Error
  EndIf
  
EndProcedure
  
  
Procedure HTTP_Delete_Connection(ConnectionID.l);Delete specified connection
  If SelectElement(http_data(),ConnectionID)
    DeleteElement(http_data())
    ProcedureReturn #HTTP_Ok
  Else
    ProcedureReturn #HTTP_Error
  EndIf
EndProcedure
  
  
  
Procedure HTTP_Set_InBuffer(Buffer_size.l) ;Set Global incoming data buffer size
  InBuffer=Buffer_size
EndProcedure
  
  
  
Procedure HTTP_Get_InBuffer();Get Global incoming data buffer size
  ProcedureReturn InBuffer
EndProcedure
  

  

  
Procedure HTTP_File_Size(ConnectionID.l);Get file size

    If SelectElement(http_data(),ConnectionID)
      ProcedureReturn http_data()\file_size
    Else
      ProcedureReturn #HTTP_Error
    EndIf
  
EndProcedure
  
  
  
  
  
Procedure HTTP_Download_ToFile(ConnectionID.l ,Filename.s);Download HTTP data to file
  http_data()\file_progress=0
  
  If SelectElement(http_data(),ConnectionID)
    http_data()\savefile=Filename
    ThreadID = CreateThread(@int_Action(),Str(ConnectionID)+"|"+Str(#HTTP_Action_Get2File))
    If ThreadID
      ProcedureReturn ThreadID
    Else
      ProcedureReturn #HTTP_Error
    EndIf
  Else
    ProcedureReturn #HTTP_Error
  EndIf

EndProcedure
  

  
  
Procedure HTTP_Get_Progress(ConnectionID.l);Returns downloaded size in bytes
  If SelectElement(http_data(),ConnectionID)
    ProcedureReturn http_data()\file_progress
  Else
    ProcedureReturn #HTTP_Error
  EndIf
EndProcedure
  
  
  
Procedure HTTP_Stop();Stops HTTP library
  ClearList(http_data())
EndProcedure
Merci d'avance !!! :lol:

Publié : dim. 22/mai/2005 15:38
par Droopy
Cela semble fonctionner comme ça :

Code : Tout sélectionner

;{/ Librairie HTTP
#HTTP_Ok = 1 
#HTTP_Error = 0 
#HTTP_ProxyData_Needed = -2 
#HTTP_Authentication_Needed =-3 
#HTTP_Invalid_URL = -4 
#HTTP_FileNotFound = -5 
#HTTP_FileMoved = -6 
#HTTP_TimeOut = -7 
#HTTP_UnknowFileSize = -8 
#HTTP_UnknowDate = -9 
#HTTP_Downloading = 2 
#HTTP_DownloadEnd = 3 

#HTTP_Action_Get2File = 2 
#HTTP_Action_Get2Mem = 3 
#HTTP_Action_GetInfo = 4 


Procedure HTTP_Init();Start HTTP library 
  If InitNetwork() 
    
    Global InBuffer.l,Last_Error.l 
    InBuffer=10240 
    
    NewList http_data.http() 
    If AddElement(http_data()) : EndIf 
    
    
    ;-URL-Commands 
    ;{Day,Month 
    Dim wkday$(6) 
    Dim weekday$(6) 
    Dim Month$(12) 
    wkday$(1)="MON" 
    wkday$(2)="TUE" 
    wkday$(3)="WED" 
    wkday$(4)="THU" 
    wkday$(5)="FRI" 
    wkday$(6)="SAT" 
    wkday$(0)="SUN" 
    weekday$(1)="MONDAY" 
    weekday$(2)="TUESDAY" 
    weekday$(3)="WEDNESDAY" 
    weekday$(4)="THURSDAY" 
    weekday$(5)="FRIDAY" 
    weekday$(6)="SATURDAY" 
    weekday$(0)="SUNDAY" 
    Month$(1)="JAN" 
    Month$(2)="FEB" 
    Month$(3)="MAR" 
    Month$(4)="APR" 
    Month$(5)="MAY" 
    Month$(6)="JUN" 
    Month$(7)="JUL" 
    Month$(8)="AUG" 
    Month$(9)="SEP" 
    Month$(10)="OCT" 
    Month$(11)="NOV" 
    Month$(12)="DEC" 
    ;} 
    
    ProcedureReturn #HTTP_Ok 
  Else 
    ProcedureReturn #HTTP_Error 
  EndIf 
EndProcedure 
  
Procedure.s HTTP_LastError_Description();Textual error description 
  
  Select Last_Error 
    Case #HTTP_Invalid_URL 
      text.s="L'URL est invalide." 
      
    Case #HTTP_ProxyData_Needed 
      text.s="Proxy authentication needed" 
      
    Case #HTTP_Authentication_Needed 
      text.s="Vous devez vous identifier." 
      
    Case #HTTP_FileNotFound 
      text.s="Fichier introuvable." 
      
    Case #HTTP_FileMoved 
      text.s="Fichier déplacé." 
      
    Case #HTTP_TimeOut 
      text.s="Délai de connexion expiré." 
      
    Default 
      text.s="Une erreur est survenue." 
  EndSelect 
  
  ProcedureReturn text.s 
  
EndProcedure 
  
Procedure HTTP_LastError_ID();Last error return code 
  ProcedureReturn Last_Error 
EndProcedure 

;///// internal procedures 

Procedure int_AnalyseDate(TestTime$) 
  ;Thank to GPI for this code :P 
  
  TestTime$=ReplaceString(Trim(UCase(TestTime$)),"  "," ") 
  day=0:Month$="":year=0:Time$="" 
  For i=0 To 6 
    If Left(TestTime$,4)=wkday$(i)+","                        ;{"rfc1123-Date" 
      day=Val(StringField(TestTime$,2," ")) 
      Month$=StringField(TestTime$,3," ") 
      year=Val(StringField(TestTime$,4," ")) 
      Time$=StringField(TestTime$,5," ") 
      Break 
      ;} 
    ElseIf Left(TestTime$,Len(weekday$(i))+1)=weekday$(i)+"," ;{"rfc850-Date" 
      SubTime$=StringField(TestTime$,2," ") 
      day=Val(StringField(SubTime$,1,"-")) 
      Month$=StringField(SubTime$,2,"-") 
      year=Val(StringField(SubTime$,3,"-")) 
      If year>80:year+1900:Else:year+2000:EndIf 
      Time$=StringField(TestTime$,3," ") 
      Break 
      ;} 
    ElseIf Left(TestTime$,4)=wkday$(i)+" "                    ;{"asctime-Date" 
      day=Val(StringField(TestTime$,3," ")) 
      Month$=StringField(TestTime$,2," ") 
      year=Val(StringField(TestTime$,5," ")) 
      Time$=StringField(TestTime$,4," ") 
      Break 
      ;} 
    EndIf 
  Next 
  For i=1 To 12 
    If Month$(i)=Month$ : month=i:Break : EndIf 
  Next 
  Date=ParseDate("%hh:%ii:%ss",Time$) 
  Hour=Hour(Date) 
  Min=Minute(Date) 
  Sec=Second(Date) 
  
  ProcedureReturn Date(year,month,day,Hour,Min,Sec) 
EndProcedure  

Procedure int_Parse_URL(ConnectionID.l,Url.s) 
  Url=LCase(Url) 
  
  If FindString(Url,"http://",0)=#True 
    Url=RemoveString(Url,"http://") 
  EndIf 
  
  Url=ReplaceString(Url,"\","/",1) 
  
  server.s=StringField(Url,1,"/") 
  If server<>"" 
    http_data()\server=StringField(Url,1,"/") 
    
    out.s="" 
    For a=2 To CountString(Url,"/") 
      out.s+"/"+StringField(Url,a,"/") 
    Next 
    out.s+"/" 
    
    If out<>"/" 
      http_data()\path=out 
    Else 
      http_data()\path="" 
    EndIf 
    
    file.s=StringField(Url,CountString(Url,"/")+1,"/") 
    
    If file<>"" 
      http_data()\file=file 
    Else 
      ProcedureReturn #HTTP_Invalid_URL 
    EndIf 
    
    ProcedureReturn #HTTP_Ok 
    
  Else 
    
    ProcedureReturn #HTTP_Invalid_URL 
    
  EndIf 
  
EndProcedure 

Procedure int_Action(in_data.l) 
  
  command.s=PeekS(in_data) 
  
  
  
  ConnectionID.l=Val(StringField(command,1,"|")) 
  Action.l=Val(StringField(command,2,"|")) 
  
  If SelectElement(http_data(),ConnectionID)=0 
    ProcedureReturn #HTTP_Error 
  EndIf 
  
  
  
  If http_data()\proxy<>"" 
    conc$=http_data()\puser+":"+http_data()\ppass 
    OutputBuffer = AllocateMemory(Len(conc$)) 
    Base64Encoder(conc$,Len(conc$),OutputBuffer,OutputBuffer*2) 
    penc$=PeekS(OutputBuffer) 
    internetID = OpenNetworkConnection(proxyserver$, Val(proxyport$)) 
  Else 
    internetID = OpenNetworkConnection(server$, Val(port$)) 
  EndIf 
  
  If http_data()\wwwpass<>"" 
    conc$=http_data()\wwwuser +":"+http_data()\wwwpass 
    OutputBuffer = AllocateMemory(Len(conc$)) 
    Base64Encoder(conc$,Len(conc$),OutputBuffer,OutputBuffer*2) 
    wenc$=PeekS(OutputBuffer) 
  EndIf 
  
  header=#False 
  download=#False 
  file_size=0 
  
  resend: 
  
  If http_data()\proxy<>"" 
    internetID = OpenNetworkConnection(http_data()\proxy, http_data()\pport) 
  Else 
    internetID = OpenNetworkConnection(http_data()\server,http_data()\url_port) 
  EndIf 
  
  If internetID 
    
    ;{ /// File Information 
    com$="HEAD "+http_data()\path+http_data()\file+" HTTP/1.1"+Chr(13)+Chr(10) 
    com$+"Accept: */*"+Chr(13)+Chr(10) 
    com$+"Host: "+http_data()\server+Chr(13)+Chr(10) 
    com$+"User-Agent: PureDownload 1.0"+Chr(13)+Chr(10) 
    If http_data()\proxy<>"" 
      com$+"Proxy-Authorization: Basic "+enc$+Chr(13)+Chr(10) 
    EndIf 
    If http_data()\wwwuser<>"" 
      com$+"Authorization: Basic "+wenc$+Chr(13)+Chr(10) 
    EndIf 
    If cookie$<>"" 
      com$+"Cookie: "+cookie$+Chr(13)+Chr(10) 
    EndIf 
    If location$<>"" 
      com$+"Location: "+location$+Chr(13)+Chr(10) 
    EndIf 
    
    com$+Chr(13)+Chr(10) 
    res = SendNetworkData(internetID,@com$,Len(com$)) 
    
    If res < 0 
      CloseNetworkConnection(internetID) 
      Last_Error=#HTTP_Error 
      ProcedureReturn #HTTP_Error 
    EndIf 
    
    Repeat 
      
      index.l=ListIndex(http_data()) 
      
      If index<0 
        ProcedureReturn 
      EndIf 
      
      Result = NetworkClientEvent(internetID) 
      
      If Result=2 ;/// Raw data received 
        Content$ = Space(14500) 
        ReceiveNetworkData(internetID,@Content$,14500) 
        
        Content$=Trim(LCase(Content$)) 
        
        ;/// File not found handle 
        If FindString(Content$,"404",1) 
          CloseNetworkConnection(internetID) 
          Last_Error=#HTTP_FileNotFound 
          ProcedureReturn #HTTP_FileNotFound 
        EndIf 
        
        ;/// File moved 
        If FindString(Content$,"301",1) 
          CloseNetworkConnection(internetID) 
          Last_Error=#HTTP_FileMoved 
          ProcedureReturn #HTTP_FileMoved 
        EndIf 
        
        ;/// www authorization required 
        If FindString(Content$,"401",1) 
          CloseNetworkConnection(internetID) 
          Last_Error=#HTTP_Authentication_Needed 
          ProcedureReturn #HTTP_Authentication_Needed 
        EndIf 
        
        ;/// File found handle but redirect 
        If FindString(Content$,"302",1) 
          location$="" 
          loc=FindString(Content$,"location: ",1) 
          If loc>0 
            temploc.s=Mid(Content$,loc+10,Len(Content$)) 
            For a=1 To Len(temploc) 
              tcok.s=Mid(temploc,a,1) 
              If tcok<>Chr(13) 
                location$+tcok 
              Else 
                Break 1 
              EndIf 
            Next 
          EndIf 
        EndIf 
        
        ;/// Site sends cookie authentication 
        cok=FindString(Content$,"set-cookie: ",1) 
        cookie$="" 
        
        If cok>0 
          tempcok.s=Mid(Content$,cok+12,Len(Content$)) 
          For a=1 To Len(tempcok) 
            tcok.s=Mid(tempcok,a,1) 
            If tcok<>";" 
              cookie$+tcok 
            Else 
              Break 1 
            EndIf 
          Next 
          Goto resend 
        EndIf 
        
        
        ;/// File found handle 
        If FindString(Content$,"200",1) 
          
          pos=FindString(Content$,"content-length:" , 1) 
          If pos 
            pos=FindString(Content$," " , pos+15) 
            file_size=Val(Mid(Content$,pos+1,Len(Content$))) 
            http_data()\file_size=file_size 
          Else 
            CloseNetworkConnection(internetID) 
            Last_Error=#HTTP_UnknowFileSize 
            ProcedureReturn #HTTP_UnknowFileSize 
          EndIf 
          
          pos=FindString(LCase(Content$),"modified: " , 1) 
          pos1=FindString(Content$,Chr(13)+Chr(10),pos) 
          If pos 
            Date.s=Mid(Content$,pos+10,(pos1-pos-10)) 
            http_data()\file_date=int_AnalyseDate(Date.s) 
          Else 
            CloseNetworkConnection(internetID) 
            Last_Error=#HTTP_UnknowDate 
            ProcedureReturn #HTTP_UnknowDate 
          EndIf 
          
          
        Else 
          CloseNetworkConnection(internetID) 
          Last_Error=#HTTP_FileNotFound 
          ProcedureReturn #HTTP_FileNotFound 
        EndIf 
        header=#True 
      EndIf 
      
      
      
    Until header=#True 
    ;} 
    
    If Action=#HTTP_Action_Get2File 
      ;{ /// File Download 
      com$="GET "+http_data()\path+http_data()\file+" HTTP/1.1"+Chr(13)+Chr(10) 
      com$+"Accept: */*"+Chr(13)+Chr(10) 
      com$+"Host: "+http_data()\server+Chr(13)+Chr(10) 
      com$+"User-Agent: PureDownload 1.0"+Chr(13)+Chr(10) 
      If http_data()\proxy<>"" 
        com$+"Proxy-Authorization: Basic "+enc$+Chr(13)+Chr(10) 
      EndIf 
      If http_data()\wwwuser<>"" 
        com$+"Authorization: Basic "+wenc$+Chr(13)+Chr(10) 
      EndIf 
      If cookie$<>"" 
        com$+"Cookie: "+cookie$+Chr(13)+Chr(10) 
      EndIf 
      If location$<>"" 
        com$+"Location: "+location$+Chr(13)+Chr(10) 
      EndIf 
      
      com$+Chr(13)+Chr(10) 
      res = SendNetworkData(internetID,@com$,Len(com$)) 
      
      If res < 0 
        CloseNetworkConnection(internetID) 
        Last_Error=#HTTP_Error 
        ProcedureReturn #HTTP_Error 
      EndIf 
      
      http_data()\file_progress=0 
      
      
      If CreateFile(0,http_data()\file) 
        incoming_buffer=AllocateMemory(http_data()\in_buffer) 
        
        time.l=ElapsedMilliseconds() 
        
        Repeat 
          Delay(1) 
          
          index.l=ListIndex(http_data()) 
          
          If index<0 
            ProcedureReturn 
          EndIf 
          
          Result = NetworkClientEvent(internetID) 
          
          If Result=0 ;/// time out counter 
            now=ElapsedMilliseconds() 
            If now-time > 2000 
              Last_Error=#HTTP_TimeOut 
              ProcedureReturn #HTTP_TimeOut 
            EndIf 
            
          ElseIf Result=2 ;/// Raw data received 
            size=ReceiveNetworkData(internetID,incoming_buffer,http_data()\in_buffer) 
            
            offset.l=FindString(PeekS(incoming_buffer),Chr(13)+Chr(10)+Chr(13)+Chr(10),1) 
            If offset>0 
              offset+3 
            EndIf 
            
            http_data()\file_progress+size-offset 
            
            
            If size>0 
              WriteData(incoming_buffer+offset,size-offset) 
              If http_data()\file_size=http_data()\file_progress 
                file=#True 
              EndIf 
              time=ElapsedMilliseconds() 
            EndIf 
            
          EndIf 
        Until file=#True 
        CloseFile(0) 
        FreeMemory(incoming_buffer) 
        
        CloseNetworkConnection(internetID) 
        
        ProcedureReturn #HTTP_DownloadEnd 
      EndIf 
      
      ;} 
      
    EndIf 
    
    
    If Action=#HTTP_Action_Get2Mem 
      ;{ /// Memory Download 
      com$="GET "+http_data()\path+http_data()\file+" HTTP/1.1"+Chr(13)+Chr(10) 
      com$+"Accept: */*"+Chr(13)+Chr(10) 
      com$+"Host: "+http_data()\server+Chr(13)+Chr(10) 
      com$+"User-Agent: PureDownload 1.0"+Chr(13)+Chr(10) 
      If http_data()\proxy<>"" 
        com$+"Proxy-Authorization: Basic "+enc$+Chr(13)+Chr(10) 
      EndIf 
      If http_data()\wwwuser<>"" 
        com$+"Authorization: Basic "+wenc$+Chr(13)+Chr(10) 
      EndIf 
      If cookie$<>"" 
        com$+"Cookie: "+cookie$+Chr(13)+Chr(10) 
      EndIf 
      If location$<>"" 
        com$+"Location: "+location$+Chr(13)+Chr(10) 
      EndIf 
      
      com$+Chr(13)+Chr(10) 
      res = SendNetworkData(internetID,@com$,Len(com$)) 
      
      If res < 0 
        CloseNetworkConnection(internetID) 
        Last_Error=#HTTP_Error 
        ProcedureReturn #HTTP_Error 
      EndIf 
      
      http_data()\file_progress=0 
      
      If http_data()\membuffer 
        incoming_buffer=AllocateMemory(http_data()\in_buffer) 
        
        time.l=ElapsedMilliseconds() 
        
        Repeat 
          Delay(1) 
          
          index.l=ListIndex(http_data()) 
          
          If index<0 
            ProcedureReturn 
          EndIf 
          
          Result = NetworkClientEvent(internetID) 
          
          If Result=0 ;/// time out counter 
            now=ElapsedMilliseconds() 
            If now-time > 2000 
              Last_Error=#HTTP_TimeOut 
              ProcedureReturn #HTTP_TimeOut 
            EndIf 
            
          ElseIf Result=2 ;/// Raw data received 
            size=ReceiveNetworkData(internetID,incoming_buffer,http_data()\in_buffer) 
            
            offset.l=FindString(PeekS(incoming_buffer),Chr(13)+Chr(10)+Chr(13)+Chr(10),1) 
            If offset>0 
              offset+3 
            EndIf 
            
            If size>0 
              CopyMemory(incoming_buffer+offset,http_data()\membuffer+http_data()\file_progress,size-offset) 
              If http_data()\file_size=http_data()\file_progress 
                file=#True 
              EndIf 
              time=ElapsedMilliseconds() 
            EndIf 
            
            http_data()\file_progress+size-offset 
            
          EndIf 
        Until file=#True 
        FreeMemory(incoming_buffer) 
      EndIf 
      CloseNetworkConnection(internetID) 
      
      ProcedureReturn #HTTP_DownloadEnd 
      ;} 
    EndIf 
    
    CloseNetworkConnection(internetID) 
    ProcedureReturn #HTTP_Ok 
    
  EndIf 
  
EndProcedure 
  
  ;///// External procedures 
Procedure HTTP_New_Connection(Url.s,Port.l) ;Create a new HTTP connection, if file exists returns ConnectionID 
  
  If Port=0 
    Port=80 
  EndIf 
  
  
  If AddElement(http_data()) 
    Result = int_Parse_URL(ListIndex(http_data()),Url) 
    
    If Result<>#HTTP_Ok 
      DeleteElement(http_data()) 
      Last_Error=#HTTP_Invalid_URL 
      ProcedureReturn #HTTP_Error 
    EndIf 
    index.l=ListIndex(http_data()) 
    
    http_data()\url_port=Port 
    http_data()\in_buffer=InBuffer 
    
    line.s=Str(index)+"|0" 
    size=int_Action(@line) 
    
    If size<>#HTTP_Ok 
      ProcedureReturn HTTP_LastError_ID() 
    EndIf 
    
    ProcedureReturn index 
    
  Else 
    ProcedureReturn #HTTP_Error 
  EndIf 
  
EndProcedure 
  
Procedure HTTP_Delete_Connection(ConnectionID.l);Delete specified connection 
  If SelectElement(http_data(),ConnectionID) 
    DeleteElement(http_data()) 
    ProcedureReturn #HTTP_Ok 
  Else 
    ProcedureReturn #HTTP_Error 
  EndIf 
EndProcedure 
  
Procedure HTTP_Set_InBuffer(Buffer_size.l) ;Set Global incoming data buffer size 
  InBuffer=Buffer_size 
EndProcedure 
  
Procedure HTTP_Get_InBuffer();Get Global incoming data buffer size 
  ProcedureReturn InBuffer 
EndProcedure 
  
Procedure HTTP_File_Size(ConnectionID.l);Get file size 
  
  If SelectElement(http_data(),ConnectionID) 
    ProcedureReturn http_data()\file_size 
  Else 
    ProcedureReturn #HTTP_Error 
  EndIf 
  
EndProcedure 
 
Procedure HTTP_Download_ToFile(ConnectionID.l ,Filename.s);Download HTTP data to file 
  http_data()\file_progress=0 
  
  If SelectElement(http_data(),ConnectionID) 
    http_data()\savefile=Filename 
    ThreadID = CreateThread(@int_Action(),Str(ConnectionID)+"|"+Str(#HTTP_Action_Get2File)) 
    If ThreadID 
      ProcedureReturn ThreadID 
    Else 
      ProcedureReturn #HTTP_Error 
    EndIf 
  Else 
    ProcedureReturn #HTTP_Error 
  EndIf 
  
EndProcedure 
  
Procedure HTTP_Get_Progress(ConnectionID.l);Returns downloaded size in bytes 
  If SelectElement(http_data(),ConnectionID) 
    ProcedureReturn http_data()\file_progress 
  Else 
    ProcedureReturn #HTTP_Error 
  EndIf 
EndProcedure 
  
Procedure HTTP_Stop();Stops HTTP library 
  ClearList(http_data()) 
EndProcedure
;}


#PROJECT_NAME = "Update PCC 2005" 

;- Window Constants 
; 

Enumeration 
  #Window_1 
EndEnumeration 

Enumeration 
  #Frame3D_0 
  #ProgressBar_1 
  #Text_0 
  #Text_1 
  #Text_2 
  #Text_3 
  #Text_4 
  #Button_1 
EndEnumeration 

Procedure Open_Window_1() 
  If OpenWindow(#Window_1, 545, 215, 317, 153,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , #PROJECT_NAME) 
    If CreateGadgetList(WindowID()) 
      Frame3DGadget(#Frame3D_0, 10, 0, 300, 125, "") 
      ProgressBarGadget(#ProgressBar_1, 20, 50, 280, 20, 0, 100) 
      TextGadget(#Text_0, 20, 30, 170, 20, "Version de la mise à jour :") 
      TextGadget(#Text_1, 20, 80, 140, 20, "Etat du téléchargement : ") 
      TextGadget(#Text_2, 200, 80, 90, 20, "") 
      TextGadget(#Text_3, 20, 100, 110, 20, "Vitesse de transfert :") 
      TextGadget(#Text_4, 200, 100, 90, 20, "") 
      ButtonGadget(#Button_1, 120, 130, 80, 20, "Annuler") 
    EndIf 
  EndIf 
EndProcedure 

Procedure.s GetWebFilePart(lastUpdate.s) 
  
  lastUpdate = ReplaceString(lastUpdate, "http://www." , "c:\") 
  lastUpdate = ReplaceString(lastUpdate, "/" , "\") 
  ProcedureReturn GetFilePart(lastUpdate) 
  
EndProcedure 

Procedure SetTransfertRate(gadget, nbOctets.f, rate) 
  
  unite$ = "o/s" 
  nbOctets = nbOctets * (1000 / rate) 
  
  If nbOctets > 1000 
    
    nbOctets = nbOctets / 100 
    nbOctets = nbOctets / 10.0 
    unite$ = "Ko/s" 
    
    If nbOctets > 1000 
      
      nbOctets = nbOctets / 100 
      nbOctets = nbOctets / 10.0 
      unite$ = "Mo/s" 
      
    EndIf 
    
  EndIf    
  
  SetGadgetText(gadget, Str(nbOctets) + " " + unite$) 
  
EndProcedure 

Procedure SetTransfertState(gadget, actuel, total) 
  
  SetGadgetText(gadget, Str(actuel) + "/" + Str(total)) 
  
EndProcedure 

; *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_* 

; fichier à télécharger 
url$ = "http://www.trendmicro.com/ftp/products/pattern/lpt637.zip" 

  ; Téléchargement du fichier 
  ; ------------------------- 
If HTTP_Init() 
  
  Result= HTTP_New_Connection(url$,80)  
  If Result>0 ;All error are negative numbers 
    
    size.l=HTTP_File_Size(Result) 
    Open_Window_1()  ; Création de la fenêtre 
     
    ; Fonction pour Dl le fichier 
    ThreadID = HTTP_Download_ToFile(Result,GetWebFilePart(url$)) 
    If ThreadID 
      
      current = 0 
      rate = 500 
      
      ; Boucle 
      Repeat 
        
        EventID.l = WindowEvent() 
        
        
        If EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button 
          KillThread(ThreadID) 
          End 
        EndIf 
        
        If EventID = #PB_Event_Gadget 
          If EventGadgetID() = #Button_1 
            KillThread(ThreadID) 
            End 
          EndIf 
        EndIf 
        
        Tempo+1
        If Tempo=rate
          ; Actualisation de la fenêtre 
          exSize = current 
          current.l=HTTP_Get_Progress(Result) 
          SetTransfertRate(#Text_4, current - exSize, rate) 
          SetTransfertState(#Text_2, current, size) 
          SetGadgetState(#ProgressBar_1, (current*100)/size) 
          SetWindowTitle(#Window_1, #PROJECT_NAME + " - " + Str((current*100)/size) + "%") 
          Tempo=0
        EndIf
         
        ; On attend (pour ne pas oqp tout l'UC) 
        Delay(1) 
        
      Until size=current 
      
    Else 
      
      MessageRequester("Erreur", HTTP_LastError_Description(),#MB_ICONERROR) 
      End 
      
    EndIf 
    
  Else 
    
    MessageRequester("Erreur",HTTP_LastError_Description(),#MB_ICONERROR ) 
    End 
    
  EndIf 
  
EndIf
En fait tu ne gère pas les évènements suffisament rapidement ( rate = 500 = 500ms ! ) ce qui génère un défaut de raffraichessement de la fenêtre

J'ai mis 1 ms, et raffraichis la fenêtre chaque 500ms ( rate )

Publié : dim. 22/mai/2005 16:15
par lionel_om
Merci de ta réponse.
J'ai fais un truc qui resemble à ca !! :D
avec un Delay(25) et un compteur qui attend 500ms pour réactualiser le texte...

Merci, qd mm :wink:

Je pourrai bientot mettre ça en dl

Faut juste que je rejoute le dézippage du fichier (je recherche le dossier de l'install par rapport au registre...) et trouver comment faire pour proposer un reboot ...

Publié : dim. 22/mai/2005 16:37
par Droopy
J'ai une fonction de reboot dans ma Lib si ça peut te servir

http://www.penguinbyte.com/apps/pbwebst ... Droopy.exe

Publié : dim. 22/mai/2005 19:24
par lionel_om
Merci, mais je fais comment pour l'exécuter et pour avoir le nom de ta fct ???

Sinon ça y est mon prog est fini :
http://luchezl.free.fr/Programmation/PB/PCC_update.rar (26 ko)

Ce lien comprend les sources, l'exe et l'icone.

Ce programme s'adresse à ceux qui ont Trend Micro Internet Security 2005 (antiVirus). ce programme n'est pas illicite. Il ne fait que rendre une tâche automatisée : dl d'update qui sont mises en ligne et téléchargeables librement.

Je n'ai pas pu tester complétement les dernières étapes (ayant déjà la dernière MaJ) mais je le ferais rapidement.

Ce programme dl donc la dernière MaJ mise en ligne la copie et dézippe le bon fichier dans le répertoire du logiciel.

Si qq1 à cette antivirus, s'il pouvait faire une petite remarque ca serait simpa (suggestion, report de bug, etc.)

Merci @ Droopy ... [/code]

Publié : dim. 22/mai/2005 19:24
par lionel_om
Merci, mais je fais comment pour l'exécuter et pour avoir le nom de ta fct ???

Sinon ça y est mon prog est fini :
http://luchezl.free.fr/Programmation/PB/PCC_update.rar (26 ko)

Ce lien comprend les sources, l'exe et l'icone.

Ce programme s'adresse à ceux qui ont Trend Micro Internet Security 2005 (antiVirus). ce programme n'est pas illicite. Il ne fait que rendre une tâche automatisée : dl d'update qui sont mises en ligne et téléchargeables librement.

Je n'ai pas pu tester complétement les dernières étapes (ayant déjà la dernière MaJ) mais je le ferais rapidement.

Ce programme dl donc la dernière MaJ mise en ligne la copie et dézippe le bon fichier dans le répertoire du logiciel.

Si qq1 à cette antivirus, s'il pouvait faire une petite remarque ca serait simpa (suggestion, report de bug, etc.)

Merci @ Droopy ...

Publié : dim. 22/mai/2005 20:08
par Droopy
Tu ferme ton editeur purebasic
Tu télécharge la lib ( que tu met sur ton disque )
Tu l'installe
Tu lance ton editeur purebasic
Dans l'éditeur tu tape Reboot et tu presse F1

Publié : dim. 22/mai/2005 20:33
par Oliv
Droopy a écrit :Tu ferme ton editeur purebasic
Tu télécharge la lib ( que tu met sur ton disque )
Tu l'installe
Tu lance ton editeur purebasic
Dans l'éditeur tu tape Reboot et tu presse F1
Pas besoin de fermer/réouvrir le compilateur :wink: Il suffit de faire Compilateur=>Redémarrer le compilateur

Publié : dim. 22/mai/2005 21:00
par Droopy
Merci Oliv, je rajoute ça de suite dans mes astuces :D

Publié : lun. 23/mai/2005 19:35
par lionel_om
Je dois etre nul ou biglouche, mais qd je fais F1 je ne vois rien de nouveau... :? :roll:

EDIT : non c bon j'ai trouvé, merici
Faudra ke je regarde comment on crée des lib de cette forme, ca m'évitera d'inclure des fichiers....