Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Original code: http://hawkee.com/snippet/9318/
- ; Example Usage: //download $qt(echo -a) https://adiirc.com/AdiIRC64.3.7.exe $qt($mircdir $+ adiirc.exe)
- alias download {
- if ($isid) || (!$1) || (!$2) || (!$3) { return }
- if ($1 == -c) {
- var %callback = $gettok($1-,2,34)
- var %url = $gettok($gettok($1-,3,34),1,32)
- var %file = $gettok($1-,4,34)
- var %com = $gettok($gettok($1-,5,34),1,32)
- var %r = $iif($comerr,1,$com(%com).result)
- if ($com(%com)) { .comclose %com }
- if (%r == -1) { %callback 1 S_OK %url $qt(%file) }
- }
- elseif ($1 !== -c) {
- var %callback = $gettok($1-,1,34)
- var %url = $gettok($gettok($1-,2,34),1,32)
- var %file = $gettok($1-,3-,34)
- var %com = download $+ $rand(1,1000000000) $+ .vbs
- var %s = $mircdir $+ %com
- var %n = $left(%com,-4)
- .fopen -ox %n $qt(%s)
- .fwrite -n %n On Error Resume Next
- .fwrite -n %n Set args = WScript.Arguments
- .fwrite -n %n Url = $qt(%url)
- .fwrite -n %n Dim xHttp: Set xHttp = CreateObject("MSXML2.SERVERXMLHTTP.6.0")
- .fwrite -n %n Dim bStrm: Set bStrm = CreateObject("Adodb.Stream")
- .fwrite -n %n xHttp.Open "GET", Url, False
- .fwrite -n %n xHttp.Send
- .fwrite -n %n with bStrm
- .fwrite -n %n .Type = 1
- .fwrite -n %n .Mode = 3
- .fwrite -n %n .Open
- .fwrite -n %n .Write xHttp.ResponseBody
- .fwrite -n %n .SavetoFile $qt(%file) $+ , 2
- .fwrite -n %n .Close
- .fwrite -n %n End with
- .fwrite -n %n Err.Clear
- .fwrite -n %n Set oFso = CreateObject("Scripting.FileSystemObject") : oFso.DeleteFile WScript.ScriptFullName, True
- .fwrite -n %n WScript.Quit(-1)
- .fclose %n
- .comopen %com WScript.Shell
- if ($lines(%s) !== 18 || $comerr || !$comcall(%com,download -c $qt(%callback) %url $qt(%file),run,1,bstr*,$qt(%s),uint,1,bool,true)) { goto error }
- return
- }
- :error
- if ($error) { reseterror }
- if ($com(%com)) { .comclose %com }
- }
Add Comment
Please, Sign In to add comment