InetGet über Cancel Button abbrechen

  • Hi,

    das Beispiel stammt aus der Hilfe.

    Code
    ; Advanced example - downloading in the  background
    Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", @TempDir & "\update.dat", 1, 1)
    Do
        Sleep(250)
    Until InetGetInfo($hDownload, 2)    ; Check if the download is complete.
    Local $nBytes = InetGetInfo($hDownload, 0)
    InetClose($hDownload)   ; Close the handle to release  resourcs.

    Ich würde aber gerne die Do Until Schleife abrechen können, dazu habe ich ein Cancel Button
    auf meiner GUI und bisher

    Code
    While 1
    	$nMsg = GUIGetMsg()
    	Switch $nMsg
    		Case $GUI_EVENT_CLOSE
    			Exit
    		Case $Cancel
    			Exit
    	EndSwitch
    WEnd

    Ich weiß nicht wie ich die beiden Schleifen miteinander verheiraten soll?

    Geht das?

    Danke

  • Aus der Do-Until zu springen würde den Download nicht unterbrechen, sondern lediglich die Auswertung des Fortschritts.

    Zitat von "Deutsche Hilfe zu InetGet()"

    Um einen Download abzubrechen, ist InetClose() aufzurufen und das von InetGet() zurückgegebene Handle zu übergeben.

  • Spoiler anzeigen
    [autoit]


    ; Advanced example - downloading in the background
    Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", @TempDir & "\update.dat", 1, 1)
    Do
    Sleep(50)
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE, $Cancel
    InetClose($hDownload)
    Exit
    EndSwitch
    Until InetGetInfo($hDownload, 2) ; Check if the download is complete.
    Local $nBytes = InetGetInfo($hDownload, 0)
    InetClose($hDownload) ; Close the handle to release resourcs.

    [/autoit]


    würde der Lösung entsprechen, aber die Implementierung fehlt halt noch.

  • Hier ein Möglichkeit, die noch viel Erweiterungspotential hat!

    Spoiler anzeigen
    [autoit]


    ;Coded by UEZ 2010
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiStatusBar.au3>
    #include <ProgressConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    Opt("GUIOnEventMode", 1)
    Opt("MustDeclareVars", 1)

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

    Local $hGUI = GUICreate("Downloader by UEZ 2010", 615, 267, 192, 124)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    Local $Input_URL = GUICtrlCreateInput("http://www.autoitscript.com/autoit3/files/beta/autoit/autoit-v3.3.5.6-sfx.exe", 64, 24, 497, 21)
    Local $Label1 = GUICtrlCreateLabel("URL:", 32, 26, 29, 17)
    Local $Start_DL = GUICtrlCreateButton("Download", 64, 128, 75, 25)
    GUICtrlSetOnEvent(-1, "Start_DL")
    Local $Stop_DL = GUICtrlCreateButton("Cancel", 488, 128, 75, 25)
    GUICtrlSetOnEvent(-1, "Stop_DL")
    GUICtrlSetState(-1, $GUI_DISABLE)
    Local $Progress = GUICtrlCreateProgress(8, 192, 598, 17)
    Local $StatusBar = _GUICtrlStatusBar_Create($hGUI)
    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
    Local $Input_Save_To = GUICtrlCreateInput(@ScriptDir, 64, 80, 497, 21)
    Local $Label2 = GUICtrlCreateLabel("Save to:", 16, 84, 44, 17)
    GUISetState(@SW_SHOW)

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

    Local $hDownload, $nBytes, $nRead, $nSize, $calc, $file, $url
    Local $prog = 0
    Local $stop = 0

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

    While Sleep(1000000000)
    WEnd

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

    Func Start_DL()
    $url = GUICtrlRead($Input_URL)
    $file = GUICtrlRead($Input_Save_To)
    If $url <> "" And $file <> "" Then
    GUICtrlSetState($Start_DL, $GUI_DISABLE)
    GUICtrlSetState($Stop_DL, $GUI_ENABLE)
    $file &= "\" & StringRight($url, StringLen($url) - StringInStr($url, "/", 0, -1))
    $nSize = InetGetSize($url)
    $hDownload = InetGet($url, $file, 1, 1)
    AdlibRegister("DL_Check", 50)
    EndIf
    EndFunc

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

    Func DL_Check()
    If InetGetInfo($hDownload, 2) Or $stop Then
    InetClose($hDownload)
    GUICtrlSetState($Start_DL, $GUI_ENABLE)
    GUICtrlSetState($Stop_DL, $GUI_DISABLE)
    GUICtrlSetData($Progress, 0)
    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
    $stop = 0
    AdlibUnRegister("DL_Check")
    Else
    $nRead = InetGetInfo($hDownload, 0)
    $calc = Int(100 * $nRead / $nSize)
    GUICtrlSetData($Progress, $calc)
    _GUICtrlStatusBar_SetText($StatusBar, $nRead & " / " & $nSize & " bytes")
    EndIf
    EndFunc

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

    Func Stop_DL()
    $stop = 1
    EndFunc

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

    Func _Exit()
    InetClose($hDownload)
    GUIDelete($hGUI)
    Exit
    EndFunc

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯