rendered paste bodyalias updates dodialog update
dialog update {
size -1 -1 329 137
title "Updates"
button "Check",1,8 104 75 25
button "Download",2,104 104 75 25
button "Sluit",3,248 104 75 25, ok
list 4,2 3 327 92,extsel size
}
on *:dialog:update:init:*:{
mdx.load
mdx SetControlMDX $dname 4 ListView report checkboxes single grid fullrowselect > $views
mdx SetBorderStyle $dname 1,2,3 staticedge
did -i $dname 4 1 headerdims 150 150
did -i $dname 4 1 headertext Bestand $chr(9) Notitie
}
on *:dialog:update:sclick:*:{
if ($did(1)) { chk.updates }
if ($did(2)) {
var %l = $did(Update,1).lines
var %i = 1
while (%i <= %l) {
if (%l != 1) {
if ($gettok($did(Update,1,%i),5,32) == 2) { upd.getfile $gettok($did(Update,1,%i),6,32) }
}
inc %i
}
upd.list
}
if ($did(3)) { .remove systeem\data\updates.cwm }
}
alias chk.updates {
write -c systeem\data\updates.cwm
if ($sock(upchk)) { return }
sockopen upchk www.chattersweb.nl 80
}
on *:SOCKOPEN:upchk: {
if ($sockerr) { return }
if ($sock(upchk)) {
sockwrite -n $sockname GET /cwmirc/updates.cwm HTTP/1.1
sockwrite -n $sockname Host: www.chattersweb.nl
sockwrite -n $sockname Connection: Close $+ $crlf $crlf
}
}
on *:SOCKREAD:upchk: {
if ($sockerr) { return }
if ($sock(upchk)) {
sockread %z
if ($left(%z,1) != $chr(63)) { return }
write systeem\data\updates.cwm %z
}
}
on *:SOCKCLOSE:upchk: { .timer -m 1 1 upd.list }
alias -l upd.list {
if ($Dialog(Update)) { did -r Update 4 }
var %i = 1, %l = $lines(systeem\data\updates.cwm), %u = 0
while (%i <= %l) {
var %z = $read(systeem\data\updates.cwm,%i)
var %z = $remove(%z,$chr(63))
tokenize 58 %z
if (((!$script($1)) || ($readini($sysdir($1),versie,script) < $2))) {
if ($dialog(Update)) { did -a Update 4 0 0 2 $1 $chr(9) $3 }
}
inc %u
}
if ((!$Dialog(Update)) && (%u > 0)) {
var %d = $input(Er $iif(%u == 1,is %u update,zijn %u updates) verkrijgbaar. Naar update scherm gaan?,yvi,$iif(%u == 1,Update,Updates) Verkrijgbaar)
if (%d = $yes) { set -u2 %updatelist 1 | updates }
}
}
alias -l upd.getfile { download -o $1 $+(http://chattersweb.nl/cwmirc/,$1) $sysdir }
on *:SIGNAL:Download_Complete: {
echo -a $1-
if ($1 == updates.cwm) { .timer -m 1 1 upd.list }
else { upd.updfile $1 }
}
on *:SIGNAL:download_fail:echo -s * Failed to download $download($1).file - $2-
alias -l upd.updfile {
.timer -m 1 200 upd.finish $1
.reload -rs $+(Systeem\scripts\,$1)
}
alias -l upd.finish {
kte_echo -s $1 Geupdate
upd.list
}
alias sysdir { return $shortfn($+($mircdir,Systeem\scripts\,$1)) }
;;
; HTTP Downloader v1.2 by ^BeAsT^
;===============================
; The /download command:
; The /download command is used to start a dwonload.
; Notice that the filename will be the same as the original filename in the url.
; Format: /download [-o] <name> <url> <directory>
; Example: /download mIRC http://www.mirc.co.za/download/mirc603.exe C:\mIRC\Download\
;
; If the -o switch is specified, the download will overwrite the file if it exists. Otherwise, the download will try to resume.
; Note: to stop a download use /close -d <name>
;
; The $download(<name/N>) identifier:
; This identifier can be used to retrieve information about current downloads.
; Properties: ip, status, url, file, type, size, rcvd, cps, pc, secs
; $download(0) returns the total number of http downloads.
; $download(1) returns the name of the 1st download.
; $download(2).ip returns the ip address of the 2nd download.
; $download(2).rcvd returns the number of bytes received for the 2nd download.
; $download(2).cps returns the character per second rate for the 2nd download.
; $download(2).secs returns the number of seconds connection has been open.
;
; Events triggers:
; The following event is triggered when a download succeeds:
; Format: on *:SIGNAL:download_complete:<command>
; Info returned: <name>
; Example: on *:SIGNAL:download_complete:echo -s * Completed $download($1).file
;
; The following event is triggered when a download fails:
; Format: on *:SIGNAL:download_fail:<command>
; Info returned: <name> <error specification>
; Example: on *:SIGNAL:download_fail:echo -s * Failed to download $download($1).file - $2-
;
; Version History:
; * 1.0 - First public release.
; * 1.12 - Changed download method.
; - Improved some features.
; - Fixed socket bugs.
; * 1.2 - Added resume capability (-o switch for overwriting).
; - Changed download method (again).
; - Now cleans variables on exit/unload.
; - More bugs fixes.
;
; Feel free to use this snippet in your script, just don't forget the credits.
alias 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),") }
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
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: Keep-Alive
sockwrite -tn $sockname $crlf
}
on *:sockclose:download*:{ if ($dl.var($sockname,status) != done) { dl.fail $sockname Disconnected } }
on *:sockread:download*:{
var %b | sockread %b | tokenize 32 %b
echo -a $1-
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-) | echo -a 2 } }
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
}
}
else {
var %1 = $dl.var($sockname,file)
:sockread
sockread &1
echo -a &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
}
}
}
on *:exit:{ unset %download* | sockclose download* }
on *:unload:{ unset %download* | sockclose download* }
; End of file.