westor

/Download alias

Jan 18th, 2020
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 1.94 KB | None | 0 0
  1. ; Original code: http://hawkee.com/snippet/9318/
  2. ; Example Usage: //download $qt(echo -a) https://adiirc.com/AdiIRC64.3.7.exe $qt($mircdir $+ adiirc.exe)
  3.  
  4. alias download {
  5.   if ($isid) || (!$1) || (!$2) || (!$3) { return }
  6.   if ($1 == -c) {
  7.     var %callback = $gettok($1-,2,34)
  8.     var %url = $gettok($gettok($1-,3,34),1,32)
  9.     var %file = $gettok($1-,4,34)
  10.     var %com = $gettok($gettok($1-,5,34),1,32)
  11.     var %r = $iif($comerr,1,$com(%com).result)
  12.  
  13.     if ($com(%com)) { .comclose %com }
  14.     if (%r == -1) { %callback 1 S_OK %url $qt(%file) }
  15.   }
  16.   elseif ($1 !== -c) {
  17.     var %callback = $gettok($1-,1,34)
  18.     var %url = $gettok($gettok($1-,2,34),1,32)
  19.     var %file = $gettok($1-,3-,34)
  20.     var %com = download $+ $rand(1,1000000000) $+ .vbs
  21.     var %s = $mircdir $+ %com
  22.     var %n = $left(%com,-4)
  23.  
  24.     .fopen -ox %n $qt(%s)
  25.  
  26.     .fwrite -n %n On Error Resume Next
  27.     .fwrite -n %n Set args = WScript.Arguments
  28.     .fwrite -n %n Url = $qt(%url)
  29.     .fwrite -n %n Dim xHttp: Set xHttp = CreateObject("MSXML2.SERVERXMLHTTP.6.0")
  30.     .fwrite -n %n Dim bStrm: Set bStrm = CreateObject("Adodb.Stream")
  31.     .fwrite -n %n xHttp.Open "GET", Url, False
  32.     .fwrite -n %n xHttp.Send
  33.     .fwrite -n %n with bStrm
  34.     .fwrite -n %n    .Type = 1
  35.     .fwrite -n %n    .Mode = 3
  36.     .fwrite -n %n    .Open
  37.     .fwrite -n %n    .Write xHttp.ResponseBody
  38.     .fwrite -n %n    .SavetoFile $qt(%file) $+ , 2
  39.     .fwrite -n %n    .Close
  40.     .fwrite -n %n End with
  41.     .fwrite -n %n Err.Clear
  42.     .fwrite -n %n Set oFso = CreateObject("Scripting.FileSystemObject") : oFso.DeleteFile WScript.ScriptFullName, True
  43.     .fwrite -n %n WScript.Quit(-1)
  44.  
  45.     .fclose %n
  46.  
  47.     .comopen %com WScript.Shell
  48.     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 }
  49.     return
  50.   }
  51.   :error
  52.   if ($error) { reseterror }
  53.   if ($com(%com)) { .comclose %com }
  54. }
Add Comment
Please, Sign In to add comment