-
-
Save Pandahisham/19f52083b3b3553aa2cc to your computer and use it in GitHub Desktop.
AutoHotkey: Download()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Derived from Wicked - can't locate his thread but found this in the ff thread: | |
http://www.autohotkey.com/board/topic/97642-urldownloadtofile/#entry614852 | |
*/ | |
Download(url, dest) { | |
static r | |
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") | |
if (!r || whr.Option(1) != url) | |
whr.Open("GET", url) | |
whr.Send() | |
if (whr.ResponseText = "failed" || whr.Status != 200 || ComObjType(whr.ResponseStream) != 0xd) | |
return false | |
p := ComObjQuery(whr.ResponseStream, "{0000000c-0000-0000-C000-000000000046}") | |
file := FileOpen(dest, "w") | |
Loop { | |
VarSetCapacity(bin, 8192) | |
r := DllCall(NumGet(NumGet(p+0)+3*A_PtrSize), "Ptr", p, "Ptr", &bin, "UInt", 8192, "Ptr*", c) | |
file.RawWrite(&bin, c) | |
} until (c == 0) | |
ObjRelease(p) | |
file.Close() | |
return whr.ResponseText | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment