Hi,
da die interne InetGet Funktion ziemlich eingeschränkt ist und das WinHTTP & Co. blockierend wirkt habe ich mir gedacht das ich das mal ändern möchte. Diese Funktionen ermöglicht euch Dateien mit zustäzlichen Headern und mit mehreren Verbindungen gleichzeitig zu downloaden.
Dieses UDF ist NUR für Autoit v 3.3.8.1 verfügbar, da minimale Veränderungen in Autoit gemacht werden müssen.
Spoiler anzeigen
DWORD ad = 0x0044AADB;
BYTE jump[] = {0xE9,0x20,0x6B,0x03,0x00,0x90,0x90};
/*
JMP 00481600
NOP
NOP
*/
DWORD ad2 = 0x00481600;
BYTE jump2[] = {0x3D,0xC8,0x00,0x00,0x00,0x0F,0x84,0xD7,0x94,0xFC,0xFF,0x3D,0xCE,0x00,0x00,0x00,0x0F,0x84,0xCC,0x94,0xFC,0xFF,0xE9,0x41,0x95,0xFC,0xFF};
/*
CMP EAX,0C8 // HTTP Code 200
JE 0044AAE2
CMP EAX,0CE // HTTP Code 206 (Partitial-Content)
JE 0044AAE2
JMP 0044AB5C
*/
Einschränkung in der weiteren Nutzung von Autoit:
Spoiler anzeigen
- HttpSendRequestW ist nurnoch eingeschränkt nutzbar
- InetGet außerhalb des UDFs und andere Funktionen die auf InternetReadFile zugreifen wird auch von der Pause beeinflusst
Hier das UDF:
Spoiler anzeigen
#include-once
#include <WinAPI.au3>
$__default_path = @ScriptDir & "\_InetGet.dll"
[/autoit] [autoit][/autoit] [autoit]Func _InetGet_Startup($dll = "")
[/autoit] [autoit][/autoit] [autoit]GlobalVars_Set_Normal("Pause", "0")
GlobalVars_Set_Normal("Start", "0")
GlobalVars_Set_Normal("Cookie", "")
GlobalVars_Set_Normal("Referrer", "")
GlobalVars_Set_Normal("Post", "")
GlobalVars_Set_Normal("NewDL", "")
If $dll = "" Then $dll = $__default_path
Local $r = _WinAPI_LoadLibrary($dll)
If $r = 0 Then
Return SetError(1)
Else
Return SetError(0)
EndIf
EndFunc ;==>_InetGet_Startup
[/autoit] [autoit][/autoit] [autoit]Func _InetGet_Start($Seite, $file, $Referer = "", $Post = "", $Cookie = "", $verbindungen = 1)
Dim $con[1][2]
$file_size = InetGetSize($Seite)
If @error Then Return SetError(1)
GlobalVars_Set_Normal("Cookie", $Cookie)
GlobalVars_Set_Normal("Referrer", $Referer)
GlobalVars_Set_Normal("Post", $Post)
If $verbindungen <> 1 Then
$per = Int($file_size / $verbindungen)
$rest = 0
For $i = 1 To $verbindungen - 1
$con[UBound($con) - 1][0] = __InetGet($Seite, $file, ($per * ($i - 1)), $per * $i)
If @error Then Return SetError(2)
$con[UBound($con) - 1][1] = False
ReDim $con[UBound($con) + 1][2]
Next
$con[UBound($con) - 1][0] = __InetGet($Seite, $file, ($verbindungen - 1) * $per, $file_size)
If @error Then Return SetError(2)
$con[UBound($con) - 1][1] = False
ReDim $con[UBound($con) + 1][2]
Else
$con[UBound($con) - 1][0] = __InetGet($Seite, $file)
If @error Then Return SetError(2)
$con[UBound($con) - 1][1] = False
ReDim $con[UBound($con) + 1][2]
EndIf
Return SetExtended($file_size, $con)
EndFunc ;==>_InetGet_Start
Func _InetGet_CheckDownload($connections)
Local $dl = 0
Local $done = True
If UBound($connections) < 1 Then Return True
For $i = 0 To UBound($connections) - 2
$info = InetGetInfo($connections[$i][0])
If @error Then ContinueLoop
If $info[0] <> 0 Then $connections[$i][1] = True
$dl += $info[0]
If $info[2] = False And $done Then $done = False
If $connections[$i][1] = False Then $done = False
Next
Return SetExtended($dl, $done)
EndFunc ;==>_InetGet_CheckDownload
Func _InetGet_Pause($pause = True)
If $pause Then
GlobalVars_Set_Normal("Pause", "1")
Else
GlobalVars_Set_Normal("Pause", "0")
EndIf
EndFunc ;==>_InetGet_Pause
Func _InetGet_Cancel($connections)
_InetGet_Pause(False)
For $i = 0 To UBound($connections) - 2
InetClose($connections[$i][0])
Next
EndFunc ;==>_InetGet_Cancel
Func __InetGet($u, $f, $s = 0, $t = 0)
GlobalVars_Set_Normal("NewDL", $f)
GlobalVars_Set_Normal("NewPointer", $s)
GlobalVars_Set_Normal("NewPointerTo", $t)
GlobalVars_Set_Normal("Start", "0")
$a = InetGet($u, $f, 0, 1)
If @error Then Return SetError(1)
Do
Sleep(100)
Until GlobalVars_Get_Normal(@AutoItPID, "Start") = "1"
GlobalVars_Set_Normal("Start", "0")
GlobalVars_Set_Normal("Cookie", "")
GlobalVars_Set_Normal("Referrer", "")
GlobalVars_Set_Normal("Post", "")
GlobalVars_Set_Normal("NewDL", "")
Return $a
EndFunc ;==>__InetGet
Func GlobalVars_Set_Normal($key, $val)
RegWrite("HKCU\GlobalVars\" & @AutoItPID, $key, "REG_SZ", $val)
EndFunc ;==>GlobalVars_Set_Normal
Func GlobalVars_Get_Normal($p, $key)
Return RegRead("HKCU\GlobalVars\" & $p, $key)
EndFunc ;==>GlobalVars_Get_Normal
Beispiel zur Benutzung:
Spoiler anzeigen
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "_InetGet.au3"
[/autoit] [autoit][/autoit] [autoit]FileDelete(@ScriptDir & "\download.test")
Opt("GUIOnEventMode",1)
$Form1 = GUICreate("Download-Test", 346, 83)
$Label1 = GUICtrlCreateLabel("", 8, 8, 330, 20)
GUICtrlSetFont(-1, 10, 400, 0, "ariial")
$Button1 = GUICtrlCreateButton("Download pausieren", 8, 40, 179, 33)
GUICtrlSetFont(-1, 10, 400, 0, "arial")
GUISetOnEvent($GUI_EVENT_CLOSE,"exit_")
[/autoit] [autoit][/autoit] [autoit]GUICtrlSetOnEvent($Button1,"btn_click")
GUICtrlSetState($Button1,$GUI_DISABLE)
GUISetState(@SW_SHOW)
[/autoit] [autoit][/autoit] [autoit]$dl = 0
[/autoit] [autoit][/autoit] [autoit];####################################################
;Injecten der DLL und zurücksetzen der Variablen
_InetGet_Startup()
;####################################################
If @error Then
MsgBox(16,"","_InetGet_Startup war nicht erfolgreich")
Exit
EndIf
$referrer = ""
$post = ""
$cookie = ""
$verbindungen = 3
;$url = "http://speedtest.qsc.de/100MB.qsc"
$url = "http://www.autoitscript.com/files/autoit3/autoit-v3.3.8.1-setup.exe"
;####################################################
;Startet einen Download und gibt ein Array zurück
;1.Dimension = InetGet Handle
;2.Dimension = ob schon mindestens 1 Byte übertragen wurde (True|False)
;@extended = Downloadgröße
$connections = _InetGet_Start($url,@ScriptDir & "\download.test",$referrer,$post,$cookie,$verbindungen)
;####################################################
If @error Then
MsgBox(16,"","_InetGet_Start war nicht erfolgreich (Errorcode: " & @error & ")")
Exit
EndIf
$DL_SIZE = Int(@extended/1024)
[/autoit] [autoit][/autoit] [autoit]AdlibRegister("setlabel",500)
GUICtrlSetState($Button1,$GUI_ENABLE)
;####################################################
;Überpruft die Download
;Returns:
; True = Download beendet
; False = Download nicht beendet
;@extended Größe des bisherigen Downloads
While _InetGet_CheckDownload($connections) = False
;####################################################
$dl = Int(@extended/1024)
Sleep(300)
WEnd
AdlibUnRegister("setlabel")
ToolTip("")
MsgBox(0,"","Der Download ist erfolreich abgeschlossen :)")
[/autoit] [autoit][/autoit] [autoit]Exit
[/autoit] [autoit][/autoit] [autoit]Func setlabel()
GUICtrlSetData($Label1,$dl & " / " & $DL_SIZE & " KB")
EndFunc
Func exit_()
_InetGet_Cancel($connections)
Exit
EndFunc
Func btn_click()
If GUICtrlRead($Button1) = "Download pausieren" Then
GUICtrlSetData($Button1,"Download fortsetzen")
_InetGet_Pause(True)
Else
GUICtrlSetData($Button1,"Download pausieren")
_InetGet_Pause(False)
EndIf
EndFunc
Bei Fragen einfach stellen