[Tutorial] Download mit 2 Prozentangaben

    • Offizieller Beitrag

    Hallo

    Habe mal ein kleines Tutorial geschrieben, wie man mehrere Dateien downloaden kann mit 2 Prozentangaben GUI.

    Falls fragen sind, werde ich die gerne beantworten.

    Spoiler anzeigen
    [autoit]

    ;Tutorial by GtaSpider

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

    #include <GUIConstants.au3>

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

    ;Hier werden die Downloads als array deklariert. $FileToDownload[Wieviele downloads] = [Download1,Download2,...]
    Global $FilesToDownload[3] = ["http://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.2.9.4-beta-setup.exe","http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe","http://ftp-mozilla.netscape.com/pub/mozilla.org/firefox/releases/2.0.0.8/win32/de/Firefox%20Setup%202.0.0.8.exe"]
    ;Wieviele downloads es sind
    Global $Downloads = UBound($FilesToDownload)
    ;Wo die daten hingeladen werden sollen
    Global $DownloadDir = @ScriptDir

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

    ;Gui
    GUICreate("Test", 276, 76, 193, 115)
    GUISetBkColor(0)

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

    $Progress1 = GUICtrlCreateProgress(8, 8, 262, 9,$PBS_SMOOTH)
    $Progress2 = GUICtrlCreateProgress(8, 24, 262, 9,$PBS_SMOOTH)
    $StatLab = GUICtrlCreateLabel("",8,59,262,15)
    GUICtrlSetColor(-1,0xffffff)
    $Button = GUICtrlCreateButton("Start", 8, 37, 262, 20, 0)

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

    GUISetState()

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

    ;Mainwhile
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button
    If Not _Download() Then
    ;Wenn es bei _Download ein error gab (Abbrechen wurde gedrückt)
    GUICtrlSetData($Progress1,0)
    GUICtrlSetData($Progress2,0)
    GUICtrlSetState($Button,$GUI_DISABLE)
    GUICtrlSetData($Button,"Abgebrochen")
    Sleep(1500)
    GUICtrlSetData($Button,"Neustart")
    GUICtrlSetState($Button,$GUI_ENABLE)
    Else
    ;Wenn es kein error gab
    GUICtrlSetData($Button,"Erfolgreich")
    GUICtrlSetData($StatLab,"Komplett")
    EndIf
    EndSwitch
    WEnd

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

    ;Funktionen
    Func _Download()
    Local $i,$iSize,$iBuf,$msg,$iProz,$iOldProz,$sFileName
    GUICtrlSetData($Button,"Abbrechen (0%)"); Setze button
    For $i = 0 To $Downloads - 1
    $iSize = InetGetSize($FilesToDownload[$i]);Holt sich die größe des downloads
    $sFileName = StringTrimLeft($FilesToDownload[$i],StringInStr($FilesToDownload[$i],"/",1,-1));Der Dateiname des downlaods
    InetGet($FilesToDownload[$i],$DownloadDir&"\"&$sFileName,0,1);Datei wird gedownloadet
    GUICtrlSetData($StatLab,"Download: "&$sFileName &" (0%)");Setze statuslabel
    While @InetGetActive; Solange der Download aktiv ist
    $msg = GUIGetMsg(); Falls Abbrechen gedrückt wird
    If $msg = $Button Then Return InetGet("abort")-1 ; Return ((Returnwert von Inetget = 1) - 1) = 0
    $iProz = Round(100*@InetGetBytesRead/$iSize);Gibt die Prozentzahl (gerundet) zurück
    If $iProz <> $iOldProz Then;Wenn neue Prozentangaben <> alte Prozentangaben dann.. (Verhinder mögliches Flickern von Label/Button)
    $iOldProz = $iProz;Setze alte Prozentangabe = neue Prozentangabe
    GUICtrlSetData($Progress1,$iProz);Setze Progress 1 mit Prozentangabe des momentanen downlaods
    GUICtrlSetData($Progress2,$iBuf+($iProz/$Downloads));Setze Progress 2 auf die Insgesamte Prozentanzahl
    GUICtrlSetData($Button,"Abbrechen ("&Round($iBuf+($iProz/$Downloads))&"%)");Setze Abbrechenbutton
    GUICtrlSetData($StatLab,"Download: "&$sFileName &" ("&$iProz&"%)");Setze Statuslabel mit Dateiname des downlaods und prozentangabe des downlaods
    EndIf

    Sleep(50) ;Damit Prozessorlast < 100% ;)
    WEnd
    $iBuf += (100/$Downloads)
    Next
    Return 1
    EndFunc

    [/autoit]

    Screenshot:
    [Blockierte Grafik: http://img-up.net/img/downloadFT34Sy.JPG]

    Mfg Spider

    Edit:
    So, zum Tutorial hinzugefügt. Finden tut ihr es HIER.