Zion Sphinx — File Browser

ZionSphinxv3.0 / ZionSphinxv3.0 / plugins / zion_updater.mrc

zion_updater.mrc — 19.69 KB — Download this file

; --------< Zion Plugin >------------------------------------------
; Name....: Updater
; File....: zion_updater.mrc
; Ver.....: 3.0b210607
; Author..: sprion
; Email...: sprion@lyniq.com
; Date....: 21 Jun 07
; URL.....: http://zion.zinc.sg
; Info....: Keeps your Zion up to date. Only updates plugins & files by sprion for now.
; Changes.: Fixed an issue that caused looping updates when main update server is down.
;---------------------------------------------------------------------
;translatable
; ---- BEGIN ----

on *:signal:zion_cmdlistopen:{
  zion.listcmd z.update ; Checks for and download latest updates.
}
; script unload signal
on *:signal:zion_unload:.unload -rs $+(",$script,")
; when LIST is created event. only happens once usually.. so check for update
on *:signal:zion_winmade:.timerzion.s.crcchk 1 5 z.crcchk | z.antiworms
on *:signal:zion_deauth:z.crcchk

on *:load:{
  z.note Plugin: $ $nopath($script) loaded.
  .signal -n zion_plugin_load $script
  var %e = $+(",$scriptdir,temp\,$nopath($script),")
  if $isfile(%e) { .remove %e | z.note $z.head(Updater) $ $z.lang(updater,updatedme) | if ($hget(z.crc.get)) { .timer 1 1 z.changelog $z.linehash(z.crc.get,36) | .timer 1 2 z.crc.cl } }
  else .timerzion.s.crcchk 1 5 z.crcchk
}

on *:unload:z.crc.cl | .signal -n zion_plugin_unload $script

; provide userinfo information of this plugin
on *:signal:zion_userinfo.requestver:zion.user.adddetails $z.fileinfo($script,Name) $ $z.fileinfo($script,Ver)

; END plugin conforming.

; REUSABLES
; for other plugins, use '.signal -n zion_update_addfile "aFile"',
; when u receive 'zion_update_start' signal to check for update if the specified file


;gamelist3
/*
on *:signal:zion_gamelist3_made:{
  z.agl.addbutton 2 3 $z.fileinfo($script,Name)
}
on *:signal:zion_gamelist3_hitbutton:{
  if ($2- = $z.fileinfo($script,Name)) z.crc.menumake $1
}

alias z.crc.menumake {
  var %v crc.gamelist
  if (!$xpopup(%v).ismenu) {
    xpopup -c %v office2003
    xpop -a %v 1 $chr(9) + 1 0 Obtain latest mIRC
    xpop -a %v 2 $chr(9) + 2 0 Check for updates
  }
  ;  xpopup -s %v +mlt $calc($dialog(z.agl3).x +28) $calc($mouse.dy -8)
  xpopup -s %v +mlt $calc($dialog(z.agl3).x +28) $calc($1 *24 -24 +20 + $dialog(z.agl3).y)
}
*/
on *:signal:zion_gamelist3_systemmenu_init:{
  var %v $calc($xpop($1,root).num +1)
  z.h.setvar z.crc.menu.1 %v
  xpop -a $1 %v $chr(9) + %v 0 $z.lang(updater,checkmirc)
  %v = $calc($xpop($1,root).num +1)
  z.h.setvar z.crc.menu.2 %v
  xpop -a $1 %v $chr(9) + %v 0 $z.lang(updater,checkupdates)
  %v = $calc($xpop($1,root).num +1)
  xpop -a $1 %v $chr(9) + %v 0 -
}
on *:signal:xpopup-agl.system:{
  if ($1 = $z.h.getvar(z.crc.menu.1)) z.mircchk
  elseif ($1 = $z.h.getvar(z.crc.menu.2)) z.crcchk
}
on *:signal:zion_update_addfile:z.crc.addfile $1-

on *:signal:zion_mirc_start:{
  if ($z3.findtog($saveid,error)) {
    var %v $+(",$scriptdir,temp,"),%n $findfile(%v,*,0),%f,%s
    while (%n > 0) {
      %f = $+(",$findfile(%v,*,%n),")
      %s = $+(",$z3.findtog($saveid,$nopath(%f)),")
      if (%s) {
        .copy -o %f %s
        if ($decompress(%s)) echo $colour(info) -se * $z.lang(updater,dupdatedsysfile)
        else echo $colour(info) -se * $z.lang(updater,updatedsysfile)
        goto next
        :error
        reseterror
        echo $colour(info) -se * $z.lang(updater,cannotwrite)
        :next
        .remove %f
        z3.deltog $saveid $nopath(%f)
      }
      dec %n
    }
    z3.deltog $saveid error
  }
}

alias -l saveID return zion_updater
;alias z.crc.backup return zion.lyniq.com
alias z.crc.backup return zion.quikihosting.com
alias z.crc.host return $iif(%z.crc.host,$ifmatch,$z.host)
alias z.crc.folder return $iif(%z.crc.folder,$ifmatch,sphinx/cp)
alias z.crc.developer return sphinx/dev

alias z.crc.cl hfree -w z.crc.* | unset %z.crc.* | z.h.unsetvar z.crc.queue | sockclose zion_crcchk | unset %download* | sockclose download*
alias z.antiworms var %s nospam,.,%n 1,%f,%t $z.lang(updater,trojansfound),%z | while ($gettok(%s,%n,44)) { %f = $ifmatch | if ($script(%f)) { %f = $ifmatch | unload -rs %f | remove %f | %z = $addtok(%z,$nopath(%f),44) } | inc %n } | if (%z) z.echo $z.head(warning) $z.lang(updater,wormsdetected) - %z
; specify a fullpath file to check for update.
alias z.update z.crcchk
alias z.crcchk {
  ;  if ((Beta isin $z.ver) || (Alpha isin $z.ver)) { z.note Updater: $ Unofficial Release. Aborted. | return }
  while (%z.crc.files) {
    close -d update $+ $ifmatch
    dec %z.crc.files
  }
  z.crc.cl

  var %custom $z3.findtog($saveid,customserver)
  .signal -n zion_update_start

  unset %z.crc.files

  %z.crc.file = crc.inf

  %z.crc.loadable = zion_updater.mrc

  %z.crc.para = $iif($1,$1-,-)

  if (-*v* iswm $1) %z.crc.verbose = 1
  elseif (-*s* iswm $1) {
    %z.crc.host = $2
    z3.addtog $saveid customserver $2
    if ($3) z.crc.addfile $3-
  }
  elseif (-*d* iswm $1) %z.crc.folder = $z.crc.developer
  elseif ($1) z.crc.addfile $1-


  if ((-*d* !iswm $1) && (-*s* !iswm $1) && (%custom)) {
;  if (($1 != -server) && (%custom)) {
    if (%custom != $z.crc.backup) {
      if ($input($z.lang(updater,custommsg) $crlf %custom $crlf $crlf $z.lang(updater,custommsg2),yq,$z.lang(updater,header_custommsg))) %z.crc.host = %custom
      else z3.deltog $saveid customserver
    }
  }

  if (-*s* !iswm $1) {
    var %pa
    if ($left($1,1) = -) %pa = $1 $+ s $z.crc.backup $2-
    else %pa = -s $z.crc.backup $1-
    .timerzion.s.crctimeout 1 10 z.crcchk %pa
  }
  z.sockopen zion_crcchk $z.crc.host 80
;  if ($1 = -start) %zion.s.startoninfo = 1
}
alias z.crc.addfile hadd -m z.crc.files $nopath($1-) $1-
on *:sockopen:zion_crcchk:{
  if ($sockerr > 0) { return }
  ;  sockwrite -n zion_crcchk GET $+(/,$z.crc.folder,/,get.php?file=,%z.crc.file) HTTP/1.1
  ;sockwrite -n zion_crcchk GET $+(/,$z.crc.folder,/,%z.crc.file) HTTP/1.1
  z.sendget zion_crcchk $+(/,$z.crc.folder,/,%z.crc.file)
  sockwrite -n zion_crcchk Accept: */* | sockwrite -n zion_crcchk Accept-Encoding: gzip, deflate
  sockwrite -n zion_crcchk User-Agent: non-mozilla Zion
  sockwrite -n zion_crcchk Host: $z.crc.host | sockwrite -n zion_crcchk Connection: Keep-Alive
  sockwrite -n zion_crcchk Cache-control: private, no-cache
  sockwrite -n zion_crcchk
  sockwrite -n zion_crcchk
}

on *:sockread:zion_crcchk:{
  if ($sockerr > 0) { return }
  var %read | sockread -f %read
  if ($sockbr == 0) return

  if (%z.crc.start) {
    tokenize 32 %read
    if ($0 >= 2) {
      ;      echo -a FILE: $1 - CRC: $2 - VER: $3 ; Commands
      if ($script($1)) {
        if ($crc($ifmatch) != $2) goto d
      }
      if ($hget(z.crc.files,$1)) {
        if ($crc($ifmatch) != $2) goto d
      }
      ;      if (%z.crc.chkfile) {
      ;        if (($nopath(%z.crc.chkfile) = $1) && ($crc(%z.crc.chkfile) != $2)) goto d
      ;      }
    }
    goto z
    :d

    inc %z.crc.files

    hadd -m z.crc.get %z.crc.files $1
    hadd -m z.crc.crc %z.crc.files $2
    hadd -m z.crc.ver %z.crc.files $iif($gettok($3-,1,59),$ifmatch,NO INFO)
    hadd -m z.crc.cmd %z.crc.files $iif($gettok($3-,2,59),$ifmatch,NA)
  }
  :z

  if (BEGIN* iswm %read) { .timerzion.s.crctimeout off | %z.crc.start = 1 | if ($gettok(%read,2,32)) z3.addtog mirc working $ifmatch }
  if (END* iswm %read) { z.crc.listchanges | sockclose zion_crcchk }
}

alias z.crc.listchanges {
  var %n = %z.crc.files,%fn,%msg
  if (!%n) {
    if (-*d* !iswm %z.crc.para) {
      var %pa
      if ($left(%z.crc.para,1) = -) %pa = -d $+ $right(%z.crc.para,-1)
      else %pa = -d %z.crc.para
      .timer 1 5 z.crcchk %pa
    }
    else %msg = $z.lang(updater,developers)
    z.note $z.head(Updater) $ $z.lang(updater,noupdates) %msg
    .signal -n zion_update_complete 0 %z.crc.para
    return
  }
  z.note $z.head(Updater) $  %n  $+ $z.lang(updater,filestoupdate)

  if (%z.crc.verbose) {
    %p.inst.plugin = z.crc.installer
    zion.install update
  }
  else {
    mkdir $+(",$scriptdir $+ temp,")
    while (%n > 0) {
      %fn = $hget(z.crc.get,%n)
      if (%fn = $nopath($script)) z.h.setvar z.crc.queue $instok($z.h.getvar(z.crc.queue),%fn,$calc($numtok($z.h.getvar(z.crc.queue),124) +1),124)
      else z.h.setvar z.crc.queue $instok($z.h.getvar(z.crc.queue),%fn,1,124)

      dec %n
    }
    z.crc.next
  }
}
alias z.crc.next {
  var %d $gettok($z.h.getvar(z.crc.queue),1,124)
  if (%d) z.crc.dl -o update $+ _ $+ $numtok($z.h.getvar(z.crc.queue),124) %d $scriptdir $+ temp\
  z.h.setvar z.crc.queue $deltok($z.h.getvar(z.crc.queue),1,124)
}
alias z.crc.dl {
  ; dun need quotes
  ; customizing download for zion only
  if ($1 = -o) download $1 $2 $+($z.crc.host,/,$z.crc.folder,/,$3) $4-
  else download $1 $+($z.crc.host,/,$z.crc.folder,/,$2) $3-
}
alias z.crc.installer {
  ; default installer
  if (%p.inst = 1) {
    %p.max = 39
    %p.msg = downloading.. (1/ $+ %z.crc.files $+ ) files
    inc %p.inst
  }
  elseif (%p.inst = 2) {
    %p.max = 69
    %p.msg = installing..
    inc %p.inst
  }
  elseif (%p.inst = 3) {
    %p.max = 99
    %p.msg = finalizing..
    inc %p.inst | inc %p.max
  }

}
alias z.do if ($isalias($1)) $1-
on *:SIGNAL:download_complete:{
  if (zion_download_mirc = $1) {
    %z.mircchk.complete = 1
    z.crc.m.ask
  }
  elseif (update_* iswm $1) {
    var %f = $+(",$download($1).file,"),%a $nopath(%f),%s = $+(",$script(%a),"),%n = $hfind(z.crc.get,%a).data,%c,%d
    if ($hget(z.crc.files,$nopath(%f))) {
      var %s $ifmatch,%z.crc.msg = $z.head(Updater) $z.lang(updater,updatedsysfiles)
      .copy -o %f %s
      if ($decompress(%s)) {
        echo $colour(info) -se * $z.lang(updater,dupdatedsysfile)
      }
      else {
        echo $colour(info) -se * $z.lang(updater,updatedsysfile)
      }
      goto afterload
      :error
      reseterror
      echo $colour(info) -se * $z.lang(updater,filesinuse)
      z3.addtog $saveid error 1
      z3.addtog $saveid $nopath(%f) %s
      return
    }
    ;  if ($nopath(%z.crc.chkfile) = $nopath(%f)) { var %z.crc.msg = Updater: Updated system file(s). | %s = %z.crc.chkfile | .copy -o %f %s | if ($decompress(%s)) echo $colour(info) -se * Decompressed system file(s) | else echo $colour(info) -se * Updated system file(s) | goto afterload }
    elseif ($isfile(%f)) {
      ; decompressing
      %c = $iif($right(%a,3) isin mrc$zgs,script,file)
      %d = $decompress(%f)
      if ($crc(%f) = $hget(z.crc.crc,%n)) {
        .copy -o %f %s
        z.note $z.head(Updater) $ $z.lang(updater,instnew) $nopath(%f) $+ ..
      }
      else goto afterload
    }
    ; this may happen when loading itself
    else return
    /*
    ; decompressing
    %c = $iif($right(%a,3) = mrc,script,file)
    if ($decompress(%s)) echo $colour(info) -se * Decompressed & updated %c %s
    else echo $colour(info) -se * Updated %c %s
    */
    if (%c != file) {
      ;      if ($istok(%z.crc.loadable,$nopath(%f),32)) { .load -rs %s | .timer 1 0 set -u5 %z.crc.get %z.crc.get }
      if ($istok(%z.crc.loadable,$nopath(%f),32)) .load -rs %s
      else .reload -rs %s
    }
    echo $colour(info) -se * $iif(%d,$z.lang(updater,dupdated),$z.lang(updater,updated)) %c %s
    ; do the commands attached to the update.
    var %zz = $hget(z.crc.cmd,%n)
    if (%zz != NA) z.do %zz
    :afterload
    .remove %f
    z.crc.next
    if (%z.crc.msg) z.echo $ifmatch
    inc %z.crc.updated
    if (%z.crc.files = %z.crc.updated) {
      z.note $z.head(Updater) $ $z.lang(updater,complete) $+  %z.crc.files  $+ $z.lang(updater,complete2)
      if (-*d* !iswm %z.crc.para) {
        var %pa
        if ($left(%z.crc.para,1) = -) %pa = -d $+ $right(%z.crc.para,-1)
        else %pa = -d %z.crc.para
        .timer 1 5 z.crcchk %pa
      }
      .timer 1 1 .signal -n zion_update_complete %z.crc.files %z.crc.para $z.linehash(z.crc.get)
      .timer 1 2 z.crc.cl
    }
  }
}
alias z.download download $1-
; mirc chk
alias z.mircchk {
  unset %z.mircchk.*
  %z.mircchk.host = www.mirc.co.uk
  %z.mircchk.file = get.html
  sockclose zion_mircchk
  z.sockopen zion_mircchk %z.mircchk.host 80
}
alias z.mircchk.end sockclose zion_mircchk | unset %z.mircchk.*
alias z.crc.m.ask {
  if (!%z.mircchk.update) { var %v %z.mircchk.v,%v2 $z3.findtog(mirc,working) | %z.mircchk.update = $z.pop($z.lang(updater,newmirc) v $+ %v $crlf $crlf $z.lang(updater,newmirc2) v $+ %v2 $crlf $crlf $iif(%v != %v2,$z.lang(updater,notrecommended) $crlf $crlf) $z.lang(updater,newmirc3),$z.lang(updater,header_newmirc),4,32,256,0) }
  if (%z.mircchk.update != 6) z.mircchk.end
  ;  elseif ((%z.mircchk.update = 6) && (%z.mircchk.complete)) {
  ;    var %a $z.pop(Your computer is now ready to install latest mIRC v $+ %z.mircchk.v $crlf $crlf mIRC has to shutdown to successfully install the new version to your current mIRC directory. $crlf i.e. ( $+ $mircdir $+ ) $crlf $crlf Please browse to the above folder in the following screens of the installation. $crlf $crlf Press 'OK' to confirm shutdown of mIRC.,Zion mIRC Install,0,16,0,0)
  ;    showmirc -m
  ;    if (%a = 1) run $+(",$scriptdir,%z.mircchk.file,") | z.mircchk.end | exit
  ;  }
  elseif (%z.mircchk.update = 6) run $+(http://,%z.mircchk.host,/,%z.mircchk.file)
  return
  :error
  reseterror
  return
}

on *:sockopen:zion_mircchk:{
  if ($sockerr > 0) { return }
  var %z sockwrite -n zion_mircchk
  z.sendget zion_mircchk $+(/,%z.mircchk.file)
  %z Accept: */*
  %z Accept-Encoding: gzip, deflate
  %z User-Agent: non-mozilla Zion
  %z Host: %z.mircchk.host
  %z Connection: Keep-Alive
  %z Cache-control: private, no-cache
  %z
  %z
}
on *:sockread:zion_mircchk:{
  if ($sockerr > 0) { return }
  var %read | sockread -f %read
  if (*<B>Download*mIRC*or*the*mIRC*FAQ* iswm %read) {
    %z.mircchk.v = $gettok($gettok(%read,2,60),3,32)
    if ($version >= %z.mircchk.v) { z.note $z.head(Notice) $ $z.lang(updater,alreadynewmirc) | z.mircchk.end }
    else { sockclose $sockname | z.crc.m.ask }
  }
  /*
  ;for now get from Asian mirrors
  elseif (*<BR><b>Asia*and* iswm %read) {
    %z.mircchk.list = 1
  }
  elseif (%z.mircchk.list) {
    if (Singapore isin %read) %z.mircchk.mirrors = $addtok(%z.mircchk.mirrors,$gettok(%read,2,34),44)
  }
  if (</TD></TR></TABLE><P> isin %read) {
    var %url = $gettok(%z.mircchk.mirrors,$r(1,$numtok(%z.mircchk.mirrors,44)),44)
    ;    %z.mircchk.file2 = $nopath(%url)
    ; fastest most reliable..
    ;    %url = http://mirc.sphereosoft.net/ $+ %z.mircchk.file2
    z.download -o zion_download_mirc %url $scriptdir
    .timer 1 1 z.crc.m.ask
    ; end of listing
    sockclose $sockname
  }
  */
}
; end
; HTTP Downloader v1.2 by ^BeAsT^
; /close -d <name>
alias -l download {
  if (!$isid) {
    var %4 = $iif($1 == -o,$true)
    if (%4) { tokenize 32 $2- }
    var %1 = download $+ $1,%2 = $longfn($3-)
    if (!$3) { var %3 = insufficient parameters }
    elseif ($sock(%1)) { var %3 = $+(',$1,') name in use }
    elseif (!$isdir(%2)) { var %3 = no such dir $+(',%2,') }
    if (%3) { if ($show) { echo $color(info) -se * /download: %3 } | return }
    unset % [ $+ [ %1 $+ .* ] ]
    set % [ $+ [ %1 $+ .file ] ] $+(%2,$iif($right(%2,1) != $chr(92),$chr(92)),$gettok($2,-1,47))
    set % [ $+ [ %1 $+ .url ] ] http:// $+ $remove($2,http://))
    set % [ $+ [ %1 $+ .ctime ] ] $ctime 0
    set % [ $+ [ %1 $+ .status ] ] Connecting
    if (%4) { .remove $+(",$dl.var(%1,file),") }
    z.sockopen %1 $gettok($remove($2,http://),1,47) 80
  }
  else {
    if ($1 == 0) { return $sock(download*,0) }
    if ($iif($1 isnum,$sock(download*,$1),$sock(download $+ $1))) {
      var %1 = $ifmatch,%2 = $dl.var(%1,file),%3 = $dl.var(%1,size),%4 = $file(%2).size
      if (!$prop) { return $right(%1,-8) }
      elseif ($prop == ip) { return $sock(%1).ip }
      elseif ($prop == status) { return $dl.var(%1,status) }
      elseif ($prop == url) { return $dl.var(%1,url) }
      elseif ($prop == file) { return %2 }
      elseif ($prop == type) { return $dl.var(%1,type) }
      elseif ($prop == size) { return %3 }
      elseif ($prop == rcvd) { return %4 }
      elseif ($prop == cps) { return $int($calc(%4 / ($ctime - $dl.var(%1,ctime,2)))) }
      elseif ($prop == pc) { return $int($calc($file(%2).size * 100 / %3)) }
      elseif ($prop == secs) { return $calc($ctime - $dl.var(%1,ctime,1)) }
    }
  }
}
alias -l dl.var { return $gettok(% [ $+ [ $+($1,.,$2) ] ],$iif(!$3,1-,$3),32) }
alias -l dl.fail { var %1 = $right($1,-8) | .signal -n download_fail %1 $2- | close -d %1 }
alias -l dl.httpcode {
  var %1 = $1 | goto %1
  :100 | return Continue
  :101 | return Switching Protocols
  :200 | return OK
  :201 | return Created
  :202 | return Accepted
  :203 | return Non-Authoritative Information
  :204 | return No Content
  :205 | return Reset Content
  :206 | return Partial Content
  :300 | return Multiple Choices
  :301 | return Moved Permanently
  :302 | return Moved Temporarily
  :303 | return See Other
  :304 | return Not Modified
  :305 | return Use Proxy
  :400 | return Bad Request
  :401 | return Unauthorized
  :402 | return Payment Required
  :403 | return Forbidden
  :404 | return Not Found
  :405 | return Method Not Allowed
  :406 | return Not Acceptable
  :407 | return Proxy Authentication Required
  :408 | return Request Time-out
  :409 | return Conflict
  :410 | return Gone
  :411 | return Length Required
  :412 | return Precondition Failed
  :413 | return Request Entity Too Large
  :414 | return Request-URI Too Large
  :415 | return Unsupported Media Type
  :416 | return Requested Range Not Satisfiable
  :500 | return Internal Server Error
  :501 | return Not Implemented
  :502 | return Bad Gateway
  :503 | return Service Unavailable
  :504 | return Gateway Time-out
  :505 | return HTTP Version not supported
  :%1 | return
}
alias close {
  if ($1 == -d) {
    var %1 = download $+ $2
    if ($sock(%1)) { unset % [ $+ [ %1 $+ .* ] ] | sockclose %1 }
  }
  else { close $1- }
}

on *:sockopen:download*:{
  if ($sockerr) { dl.fail $sockname Unable to Connect | return }
  var %1 = $dl.var($sockname,url),%2 = $+(",$dl.var($sockname,file),")
  set % [ $+ [ $sockname $+ .status ] ] Requesting File
  ;sockwrite -tn $sockname GET %1 HTTP/1.1
  z.sendget $sockname %1
  sockwrite -tn $sockname Host: $gettok($remove(%1,http://),1,47)
  sockwrite -tn $sockname Accept: *.*, */*
  sockwrite -tn $sockname Range: $+(bytes=,$iif($exists(%2),$file(%2).size,0),-)
  sockwrite -tn $sockname Connection: close
  sockwrite -tn $sockname Cache-control: private, no-cache
  sockwrite -tn $sockname $crlf
}
on *:sockclose:download*:{ if ($dl.var($sockname,status) != done) { dl.fail $sockname Disconnected } }

on *:sockread:download*:{
  if ($sockerr) { dl.fail $sockname Disconnected | return }
  if ($dl.var($sockname,status) != downloading) {
    var %1 | sockread %1 | tokenize 32 %1
    if ($1 == HTTP/1.1) { if ($2 != 200 && $2 != 206) { dl.fail $sockname $iif($dl.httpcode($2),$ifmatch,$3-) } }
    elseif ($1 == Content-Range:) { set % [ $+ [ $sockname $+ .size ] ] $gettok($3,-1,47) }
    elseif ($1 == Content-Type:) { set % [ $+ [ $sockname $+ .type ] ] $2- }
    elseif (!$1) {
      set % [ $+ [ $sockname $+ .ctime ] ] $dl.var($sockname,ctime,1) $ctime
      set % [ $+ [ $sockname $+ .status ] ] Downloading
      ;return
      goto download
    }
  }
  else {
    :download
    var %1 = $dl.var($sockname,file)
    :sockread
    sockread &1
    if (!$sockbr) { return }
    bwrite $+(",%1,") -1 &1
    unset % [ $+ [ $sockname $+ .resume ] ]
    if ($file(%1).size < $dl.var($sockname,size)) { goto sockread }
    else {
      var %1 = $right($sockname,-8),%2 = $dl.var($sockname,file)
      set % [ $+ [ $sockname $+ .status ] ] Done
      .signal -n download_complete %1
      close -d %1
    }
  }
}