UpdateNow! — File Browser

UpdateNowv1.0 / UpdateNowv1.0 / UpdateNow / UpdateNow.mrc

UpdateNow.mrc — 8.6 KB — Download this file

;###################################
;# UpdateNow! v1.0
;# by cLeuS - eldorben@hotmail.com
;# it is free to use and modify.
;# but i will be happy if you
;# put a copyright line to your scripts :)
;# dowloader socket system is coded by:
;# Andy Dufilie (^Andy) - http://come.to/andys.site/
;#
;# type /unow to start downloading
;###################################

on 1:LOAD: {
  set %unow.ver2 50
  echo -a -------------------
  echo -a - UpdateNow! by cLeuS
  echo -a - Type /unow to start example download
  echo -a - Contact: eldorben@hotmail.com
  echo -a - -------------------
}

; ALIASES
alias unow {
  echo -a * UpdateNow! Please wait while connecting to server. A dialog will appear when newer version found.
  ; this command closes 'cupd'
  sockclose cupd
  ; and re-open :)
  sockopen cupd www.turkeychat.net 80
}
alias unowctl {
  var %ctl = $scriptdirctl_gen.mdx
  return %ctl 
}
ctl_gen.mdx
alias unow.ret { return }
alias unow.mdx {
  var %dll = $scriptdirmdx.dll
  return $dll(%dll,$1,$2-)
}
alias KBps {
  ; this is for calculate size of file as mb value
  return $bytes($calc(($sock($1).rcvd - %downloadoffset) / ($ctime - $2))),3k).suf
}
alias unow.y3 {
  ; opens dialog if closed
  if !$dialog(unow) { dialog -md unow unow }
  ; this is for progressbar.. /did -a unow 6 45 0 100 (ex)
  did -a unow 6 $remove($2,%) 0 100
  ; this writes percent and speed to dialog
  did -ra unow 5 Completed: $2 of $round($replace($bytes(%downloadlength,k),$chr(44),.),2) $+ mb $crlf $+ Speed: $iif($KBps($sockname,%session.start),$KBps($sockname,%session.start) $+ kB/s)
  ; this is for titlebar. if dialog is not active, changes it to let user see percent from taskbar
  if !$dialog(unow).active { dialog -t unow $2 of $round($replace($bytes(%downloadlength,k),$chr(44),.),2) $+ mb $iif($KBps($sockname,%session.start),$KBps($sockname,%session.start) $+ kB/s) UpdateNow! }
  ; if dialog is active, sets titlebar as UpdateNow!
  else { dialog -t unow UpdateNow! }
  ; and disables 'UpdateNow!' button :)
  did -b unow 10
}
; DIALOGS
dialog unow {
  title "UpdateNow!"
  size -1 -1 153 90
  option dbu
  icon $scriptdirnetvari.jpg, 0
  button "Close", 3, 101 78 50 11
  text "", 5, 32 50 84 13, center
  text "", 6, 3 64 147 10
  box "", 1, 1 -2 151 38
  text $chr(160) UpdateNow! for MyScript, 2, 2 2 122 33
  icon 7, 193 7 30 33,  netvari.jpg, 0, noborder
  text UpdateNow! found a newer version of MyScript. The version is %unow.up.ver , 8, 9 16 99 15
  icon 9, 122 2 30 33,  netvari.jpg, 0, noborder
  button "UpdateNow!", 10, 16 39 40 10
  button "Version info", 11, 56 39 40 10
  button "MyScript Web", 12, 96 39 40 10
  box "", 14, 1 32 151 44, disable
  text "UpdateNow! by cLeuS", 4, 2 80 80 8, disable
}

on *:dialog:unow:sclick:3: {
  if %downloadready == 0 {
    dialog -x unow unow
  }
  if %downloadready == 1 {
    var %nnn = $input(If you click yes updating process will be stopped. $crlf $+ Do you want to end this process now?,yh,Warning)
    if %nnn == $true {
      ; if user click yes, following commands closes socket and dialog and removes variables..
      sockclose unowDown
      dialog -x unow unow
      /.remove $remove(%unow.up.url,%unow.up.rem)
      set %downloadready 0
      unset %unow.up*
      unset %unow.tik
      unset %downloadlength
      echo -a * UpdateNow! Updating process has forcefully ended.
      set %downloadready 0
    }
    else dialog -v unow unow
  }
}
on *:dialog:unow:sclick:10: {
  downit %unow.up.url
  did -b unow 10
  did -ra unow 3 Connecting...
}
on *:dialog:unow:sclick:11: {
  unow.ret $input(New Version Info: $crlf $+ File size: $round($replace($bytes(%downloadlength,k),$chr(44),.),2) $+ mb $crlf $crlf $+ $read(unowTemp.txt),ogi,Info) | if $dialog(unow) { dialog -v unow unow }
}
on *:dialog:unow:sclick:12: {
  url -an %MyScriptURL
}
on *:dialog:unow:sclick:3: {
  dialog -x unow unow
}

on *:dialog:unow:init:*: {
  unow.mdx SetMircVersion $version
  unow.mdx MarkDialog $dname
  unow.mdx SetFont $dname 2 +a 13 600 Tahoma
  unow.mdx SetColor $dname 2 background $rgb(255,255,255)
  unow.mdx SetColor $dname 2 textbg $rgb(255,255,255)
  unow.mdx SetColor $dname 8 textbg $rgb(255,255,255)
  unow.mdx SetColor $dname 8 background $rgb(255,255,255)
  unow.mdx SetControlMDX 6 ProgressBar smooth > $unowctl
  ; this writes file size to dialog on init
  did -ra unow 5 File Size: $round($replace($bytes(%downloadlength,k),$chr(44),.),2) $+ mb $crlf $+ Click UpdateNow! to start download
  set %unow.tik 10
}
; SOCKET CONNETION
on *:sockread:cupd: {
  ; we must read before process before understand what server sent us.
  sockread %tmp
  ; %tmp is 'uurl http://www.turkeychat.net/tchat/tchat736net.exe'
  if uurl isin %tmp { set %unow.up.url $gettok(%tmp,2,32) }
  ; %tmp is '1.1'
  if uverr isin %tmp { set %unow.up.ver $gettok(%tmp,2,32) }
  ; %tmp is '165...' (byte value of file size)
  if usize isin %tmp { set %downloadlength $gettok(%tmp,2,32) }
  ; %tmp includes newer version's info (ex: whats new..)
  if uozl isin %tmp { write unowTemp.txt $gettok(%tmp,2-,32) }
  ; %tmp is 'http://www.turkeychat.net/tchat/' (this is for remove process)
  if urem isin %tmp { set %unow.up.rem $gettok(%tmp,2,32) }
  ; this line checks detected version is older or same. %unow.ver2 is plain value of our script (1.0 must be 100, 1.1 must be 110)
  if uver2 isin %tmp && $gettok(%tmp,2,32) <= %unow.ver2 { echo -a * UpdateNow! There is no newer version of MyScript. }
  ; this line checks detected version is newer or not
  if uver2 isin %tmp && $gettok(%tmp,2,32) > %unow.ver2 {
    ; this line checks detected version is newer, opens dialog.
    if $dialog(unow) { dialog -x unow unow }
    dialog -md unow unow
  }
  if -End- isin %tmp { sockclose cupd }
}
on *:sockopen:cupd: { 
  ; this line triggered when error ocurred.
  if ($sockerr) { echo -a * UpdateNow! Couldn't connect to server. | if $dialog(unow) { did -e unow 10 | did -ra unow 3 Close } | return }
  ; we request which file we want :)
  sockwrite -n $sockname GET http://www.turkeychat.net/tchat/unow.txt HTTP/1.1 
  sockwrite -n $sockname Host: www.turkeychat.net $+ $crlf $+ $crlf
  write -c unowTemp.txt
}
; DOWNLOAD SOCKETS
alias downit {
  ; if socket is already open, do nothing.
  if ($sock(unowDown)) {
    return
  }
  sockopen unowDown www.turkeychat.net 80
}
on *:sockopen:unowDown:{
  ; this line triggered when error ocurred.
  if ($sockerr) {
    echo -a * UpdateNow! An unexpecting error has occured while file is downloading.
    if $dialog(unow) { did -e unow 10 | did -ra unow 3 Close }
    return
  }
  ; we check if we already have downloaded file. if yes, remove.
  if $exists($remove(%unow.up.url,%unow.up.rem)) == $true {  /.remove $remove(%unow.up.url,%unow.up.rem) }
  unset %downloadlength %downloadready
  ; we request which file we want :)
  sockwrite -n $sockname GET %unow.up.url HTTP/1.0
  sockwrite -n $sockname Accept: */*
  sockwrite -n $sockname Host: www.turkeychat.net
  sockwrite -n $sockname
  if $dialog(unow) { did -e unow 10 | did -ra unow 3 Cancel Download }
  ; this %var is used in $kbps
  set %session.start $ctime
}
on *:sockread:unowDown:{
  ; if we're not ready to start writing the file (didn't get header info yet)..
  if (%downloadready != 1) {
    var %header
    ; begin reading header info
    sockread %header
    while ($sockbr) {
      if (Content-length: * iswm %header) {
        ; web servers sends us size of file we want before begin download.
        ; %downloadlength will use for get percent, speed and set progressbar
        %downloadlength = $gettok(%header,2,32)
        unow.y3 File Size: %downloadlength byte
      }
      elseif (* !iswm %header) {
        %downloadready = 1
        ; we have received some bytes from the header. we need to offset the progress thingy a bit.
        %downloadoffset = $sock($sockname).rcvd
        ; we set it. so lets break :)
        break
      }
      sockread %header
    }
  }
  ; begin binary download
  sockread 4096 &d
  while ($sockbr) {
    unow.y3 Recieved: $round( $calc(100 * ($sock($sockname).rcvd - %downloadoffset) / %downloadlength) ,1) $+ %
    ; write to file.
    bwrite $remove(%unow.up.url,%unow.up.rem) -1 -1 &d
    ; this line reads next bit
    sockread 4096 &d
  }
}
on *:sockclose:unowDown:{
  ; when download is completed. socket automatically close.
  ; now it is time to close our dialogs and remove our %vars
  if $dialog(unow) { dialog -x unow unow }
  set %downloadready 0
  unset %unow.up*
  unset %unow.tik
  unset %downloadlength
  ; let's run the file :)
  run $remove(%unow.up.url,%unow.up.rem)
}