Problem mit Download-Status Anzeige

  • Ich habe zur Übung einen kleinen Script geschrieben, um Datein runterzuladen und den Download-Status anzeigen zu lassen.
    Aber der Script zeigt weder in der ProgressBar den Fortschritt an, noch verändert er die Anzeige der runtergeladenen Bytes.
    Und wenn die Datei runtergeladen wurde, beendet er sich auch nicht.
    Wo liegt hier der Fehler?

    [autoit]


    $title = "Download"
    $maintext = "Datei wird heruntergeladen"
    $subtext = " Byte heruntergeladen"
    $var = 100
    $size_current = 0

    [/autoit][autoit][/autoit][autoit]

    Do
    $url = InputBox ( $title, "URL eingeben" & @CRLF & "Bsp. http://www.site.com/game.exe" )
    $filename = InputBox ( $title, "Lokalen Dateinamen eingeben" & @CRLF & "Bsp. game.exe" )
    Until $url <> "" And $filename <> ""
    $size_full = InetGetSize ( $url )
    $percent = $size_full / $var
    ProgressOn ( $title, $maintext, $size_current & $subtext )

    [/autoit][autoit][/autoit][autoit]

    $file = InetGet ( $url, $filename, "", 1 )

    [/autoit][autoit][/autoit][autoit]

    Do

    [/autoit][autoit][/autoit][autoit]

    Sleep ( $var )
    $size_current = InetGetInfo ( $file )
    $size_percent = $size_current * $percent
    ProgressSet ( $size_percent, $size_current & $subtext, $maintext )

    [/autoit][autoit][/autoit][autoit]

    Until $size_percent = $var

    [/autoit][autoit][/autoit][autoit]

    ProgressOff ()

    [/autoit]

    Einmal editiert, zuletzt von CodaXYZ (13. Februar 2011 um 18:19)

  • Hallo CodaXYZ,

    um festzustellen wann der Download beendet ist solltest du das 2. Element der Array-Rückgabe von InetGetInfo verwenden siehe mein Downloader-Beispiel:

    Spoiler anzeigen
    [autoit]

    #region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_UseUpx=n
    #endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <Date.au3>
    #include <array.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    HttpSetUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.7) Gecko/20100713 Firefox/3.6.7") ; User-Agent (Header) von AutoIt3 ändern, da beim Webhoster dieser gesperrt ist

    [/autoit] [autoit][/autoit] [autoit]

    Global $tDiff, $iToDo, $iRTime, $sMSG, $nKBPerSec
    $sUrl = "http://translation.autoit.de/autoitinfo/hilfedateien/AutoIt-Hilfe-Deutsch-3.3.6.1-Stand-07_09_10.zip"
    ;url eventell gegen einen anderen größeren Download tauschen, dann aber bitte auch $sPath ändern
    $sPath = @ScriptDir & "\AutoIt-Hilfe-Deutsch-3.3.6.1-Stand-07_09_10.zip"
    Global $iSize = InetGetSize($sUrl) ;siehe Hilfe zu InetgetSize
    Global $tStart = TimerInit()
    $hDownLoad = InetGet($sUrl, $sPath, 1, 1)
    Dim $aData[3]

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Sleep(250)
    If $aData[0] > 0 Then
    _CalcPerformance($aData[0], $aData[2])
    TrayTip("downloading", $sMSG, 10, 16)
    EndIf
    $aData = InetGetInfo($hDownLoad, -1)
    Until $aData[2]
    $aData = InetGetInfo($hDownLoad, -1)
    _CalcPerformance($aData[0], $aData[2])

    [/autoit] [autoit][/autoit] [autoit]

    InetClose($hDownLoad) ; Handle schließen um die Resourcen freizugeben.
    MsgBox(0, "", "Bytes gelesen: " & $aData[0] & @CRLF & _
    "Größe: " & $aData[1] & @CRLF & _
    "beendet?: " & $aData[2] & @CRLF & _
    "Erfolgreich?: " & $aData[3] & @CRLF & _
    "@error: " & $aData[4] & @CRLF & _
    "@extended: " & $aData[5] & @CRLF & @CRLF & _
    "KiloBytes/sec: " & $nKBPerSec & @CRLF & _
    "benötigte Teit: " & Round($tDiff / 1000, 0) & " Sekunden")
    ConsoleWrite("Bytes gelesen: " & $aData[0] & @CRLF & _
    "Größe: " & $aData[1] & @CRLF & _
    "beendet?: " & $aData[2] & @CRLF & _
    "Erfolgreich?: " & $aData[3] & @CRLF & _
    "@error: " & $aData[4] & @CRLF & _
    "@extended: " & $aData[5] & @CRLF & @CRLF & _
    "KiloBytes/sec: " & $nKBPerSec & @CRLF & _
    "benötigte Teit: " & Round($tDiff / 1000, 0) & " Sekunden")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;FileDelete(@ScriptDir & "\Testdownload.htm")

    [/autoit] [autoit][/autoit] [autoit]

    Func _CalcPerformance($iRead, $bDone)

    [/autoit] [autoit][/autoit] [autoit]

    $tDiff = TimerDiff($tStart)
    $iToDo = Round(($iSize - $iRead) / 1024, 2)
    $nKBPerSec = Round($iRead / $tDiff * 1000 / 1024, 2)
    $iPercent = Round($iRead / $iSize * 100, 2)
    if ($iSize = 0) And Not $bDone Then
    $iRTime = "unbekannt"
    Else
    $iRTime = Round($iToDo / $nKBPerSec, 0)
    EndIf
    $sMSG = Round($iRead / 1024, 0) & "/" & Round($iSize / 1024, 0) & " KB " & " = " & $iPercent & "%" & @CRLF
    $sMSG &= "durchschnittlich KB/s = " & $nKBPerSec & @CRLF ;& "aktuell: KB/s " & $nKBAct & @CRLF
    If Not $bDone Then
    $sMSG = $sMSG & "vermutlich zu Ende:" & StringLeft(StringRight(_DateAdd('s', $iRTime, _NowCalc()), 8), 5)
    ;ConsoleWrite($sMSG & @CRLF)
    Else
    $sMSG = $sMSG & "benötigte Zeit = " & Round($tDiff / 1000, 0)
    EndIf
    ;if $iSize > 0 Then $sMSG = $sMSG & " sec"
    EndFunc ;==>_CalcPerformance

    [/autoit]
  • Thx, das funtioniert.
    Aber die Progressbar beendet sich trodzdem nicht und verändert sich auch nicht.
    Bleibt immer auf 0.

  • hier mal ein beispiel wie ich es in einem meiner scirpte verwende:

    Spoiler anzeigen
    [autoit]


    #include <StaticConstants.au3>
    #include <EditConstants.au3>
    #include <ComboConstants.au3>
    #include <GuiConstants.au3>
    #include <WindowsConstants.au3>
    $update = 0
    while $update = 0
    $url = InputBox ( "Download", "URL eingeben" & @CRLF & "Bsp. http://www.site.com/game.exe" )
    $fn = $url
    while StringInStr($fn, "/") > 0
    $fn = StringTrimLeft($fn, StringInStr($fn, "/"))
    wend
    $download = InetGetSize ($url, 1)
    $Form1 = GUICreate("Download", 300, 120)
    $Button1 = GUICtrlCreateButton("Cancel", 100, 84, 100, 25, $WS_GROUP)
    $Progress1 = GUICtrlCreateProgress(20, 30, 260, 25)
    $label1 = GUICtrlCreatelabel($fn, 21, 13, 260, 15)
    $label2 = GUICtrlCreatelabel("0 KB von " & int($download/1024) & " KB", 21, 59, 260, 15 )
    GUISetState(@SW_SHOW)
    Opt("GuiOnEventMode", 0)
    if $download > 0 then
    $update = InetGet ($url, @ScriptDir & "\"&$fn, 1, 1)
    local $sofar, $diff2
    GUICtrlSetData($button1,"Cancel")
    do
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
    GUICtrlSetData($button1,".")
    EndSwitch
    $sofar=InetGetInfo($update, 0)
    sleep(50)
    $diff2=InetGetInfo($update, 0)
    GUICtrlSetData($Progress1, int(($sofar/$download)*100))
    GUICtrlSetData($label2, int($sofar/1024) & " KB von " & int($download/1024) & " KB (" & round(($diff2-$sofar)/51.2, 1) & " KB/s)")
    if InetGetInfo($update, 2) then GUICtrlSetData($button1,".")
    until GUICtrlRead ($button1) = "."
    if InetGetInfo($update, 2) and InetGetInfo($update, 3) then
    InetClose($update)
    GUIDelete($form1)
    Else
    GUIDelete($form1)
    InetClose($update)
    if msgbox (21,"Download","Download fehlgeschlagen!") = 4 then $update = 0
    endif
    Else
    GUIDelete($form1)
    if msgbox (21,"Download","Download fehlgeschlagen!") = 2 then $update = -1
    endif
    Opt("GuiOnEventMode", 1)
    wend

    [/autoit]