Basic — File Browser
Basicv23042002 / Basicv23042002 / basic / sys / misc.mrc
misc.mrc — 16.8 KB — Download this file
; ###################################
;
; Basic v23042002
; blue-elf, belf@mircscripter.com
;
; misc stuff
;
; ###################################
;
; SCRIPT UPDATE
;
dialog update {
title "Basic Update"
size -1 -1 126 75
option dbu
box "Check for updates automatically:", 1, 3 3 119 52
radio "By event:", 2, 10 14 35 10, group a
combo 3, 48 13 70 50, drop
radio "By day:", 4, 10 27 35 10
combo 5, 48 26 70 50, drop
radio "By date:", 6, 10 40 35 10
combo 7, 48 39 70 50, drop
button "&Update now", 8, 16 60 45 12, ok
button "&Close", 9, 64 60 45 12, cancel
}
on *:dialog:update:init:*:{
didtok -a $dname 3 46 After opening mIRC.Upon connecting to IRC
didtok -a $dname 5 46 $ae(Mon Tues Wednes Thurs Fri Satur Sun)
var %i = 1
while (%i <= 31) {
did -a $dname 7 Every $ord(%i) of the month
inc %i
}
}
on *:dialog:update:sclick:8:.timer -m 1 0 update
alias -l ae {
var %i = 1, %r
while ($gettok($1-,%i,32)) {
%r = $addtok(%r,$+(Every $ifmatch,day),46)
inc %i
}
return %r
}
;
; updates.txt must contain:
;
; <ddmmyyyy>
;
; date of release
;
alias update {
; check if an update is ongoing
var %i = 1
while ($sock(*,%i)) {
if (UPDATE_* iswm $gettok($sock($ifmatch).mark,8,32)) { beep | _err Update currently in progress }
inc %i
}
if (!$isdir(temp\updates)) .mkdir temp\updates\
; remove all temporary files before downloading updates
if ($_isfile(temp\updates\updates.txt)) .remove -b $ifmatch
if ($_isfile(temp\updates\updates.zip)) .remove -b $ifmatch
dl $update.win http://www.geocities.com/basic_mirc/updates/updates.txt UPDATE_LIST
}
alias -l update.parselist {
var %f = $_isfile(temp\updates\updates.txt)
; do I need this?
if (!%f) {
window -c $update.win
err2 Unable to find updates list.
}
elseif ($read(%f,tn,1) == $basic.ver) {
if ($_isfile(temp\updates\updates.txt)) .remove -b $ifmatch
window -c $update.win
.timer 1 0 update.bleh No new updates available.
}
else update.download
}
alias -l update.win { return @Basic Update }
alias -l update.download { dl $update.win http://www.geocities.com/basic_mirc/updates/updates.zip UPDATE_FILE }
alias -l update.prompt {
window -c $update.win
munzip.check Unable to continue with the update:
if ($_connected) {
var %t = $input(You have to disconnect from all servers to continue updating the script. $&
$+ $str($crlf,2) $+ Clicking Yes will get you disconnected and update will begin immediately. $&
If you select No $+ $chr(44) the update will be done the next time you start mIRC. $&
$+ $str($crlf,2) $+ Do you want to continue?,264,Basic update)
if (!%t) { _set ScriptUpdate OnStart 1 | return }
else {
scid -a disconnect
; should I include closing all DCC chats and sends?
}
}
update.install
}
alias -l update.install {
munzip.check Unable to continue with the update:
var %zip = $shortfn( $mircdir $+ temp\updates\updates.zip )
if (!$_isfile(%zip)) { _err Error updating script: $+ $str($crlf,2) $+ Update file not found! }
; Just in case mUnzip doesn't do too well with relative paths, I'll just put the full extract dir.
var %zipfile = $+(",%zip,"), %output = $+(",$mircdir,temp\updates\")
var %extract = $dll( $munzip.dll , Unzip , -o %zipfile %output )
if (E_* iswm $gettok(%extract,1,32)) { _err Script update error: $+ $str($crlf,2) $+ $gettok(%extract,2-,32) }
; Start updating...
; I'm using /play JUST in case the misc.mrc file itself is updated
; to prevent it from being corrupted while updating.
var %pfile = temp\_updatep.txt
write -c %pfile
; the eleet progress window being /play'd ;P
; just in case the file that contains the /progress aliases are being updated,
; this should prevent things from going wrong.. yeah, doing it the hard way :/
var %w = @Basic Update, %dw = drawrect -rf %w
write %pfile window -aodhBCpk0 +nt %w 1 1 322 110 $shortfn($mircexe)
write %pfile window -a %w
write %pfile %dw $rgb(face) 1 0 0 999 999
write %pfile %dw $rgb(hilight) 1 18 50 280 20
write %pfile %dw $rgb(shadow) 1 18 50 279 19
write %pfile %dw $rgb(face) 1 19 51 278 18
write %pfile drawtext -ro %w $rgb(text) Tahoma 11 144 53 0%
write %pfile %dw $rgb(face) 1 0 25 322 18
write %pfile drawtext -r %w $rgb(text) Tahoma 11 20 25 Installing updates...
%_update.inc = 9
!.echo -q $findfile(temp\updates\,*.*,0,_update.install $1-)
.timer 1 0 .play -sc %pfile 0
; ironically enough, I'm using ON PLAYEND to trigger the end of the installation.
; but it shouldn't be a problem.
}
alias -l _update.install {
var %file = $nopath($1-), %nfile = $+(",$1-,")
if ($script(%file)) { var %s = -rs, %ofile = $ifmatch }
elseif ($alias(%file)) { var %s = -a, %ofile = $ifmatch }
elseif (%file == channel.pop ) { var %s = -pc, %ofile = sys\channel.pop }
elseif (%file == chat.pop ) { var %s = -pq, %ofile = sys\chat.pop }
elseif (%file == status.pop ) { var %s = -ps, %ofile = sys\status.pop }
elseif (%file == nicklist.pop) { var %s = -pn, %ofile = sys\nicklist.pop }
elseif (%file == menubar.pop ) { var %s = -pm, %ofile = sys\menubar.pop }
else { return }
%ofile = $+(",%ofile,")
; "be afraid.. be very afraid.." -- tabo
inc %_update.inc
var %num = $!int( $!calc( ( %_update.inc * 100 ) / $!lines(temp\_updatep.txt) ) )
var %w = $update.win, %com = write temp\_updatep.txt, %wd = $!int( $!calc( 2.76 * %num ) )
%com .copy -o %nfile %ofile $chr(124) .timer 1 0 .reload %s %ofile $&
$chr(124) if ( $!window( %w ) ) $chr(123) drawrect -rf %w 6956042 1 20 52 %wd 16 $chr(124) $&
drawtext -rco %w 16777215 Tahoma 11 144 53 $!calc( ( 20 + %wd ) - 144 ) 11 %num $!+ % $chr(125)
}
alias -l update.bleh { var %a = $input( $1- $str($crlf,2) ,68,Basic Update) }
on *:playend:{
if ($filename == $+($mircdir,temp\_updatep.txt)) {
.remove $+(",$ifmatch,")
window -c $update.win
unset %_update.inc
.alias basic.ver return $read(temp\updates\updates.txt,tn,1)
.echo -q $findfile(temp\updates\,*.*,0,.remove $+(",$1-,"))
.timer 1 0 update.bleh Script successfully updated!
}
}
on *:start:{
if ($_(ScriptUpdate,OnStart)) {
_set ScriptUpdate OnStart
.timer 1 0 update.install
}
}
;----------------
;
; mUNZIP support
;
;----------------
alias munzip.dll { return $_isfile(dll\mUnzip\mUnzip.dll) }
alias munzip.check { if (!$munzip.dll) { _err $1- $+ $str($crlf,2) $+ Required mUnzip.dll not found. } }
;
;------------------------------------------------------
;
; DOWNLOADER
;
; -----------------------------------------------------
;
; /dlwin, based on SirNo3DFx's /progress alias.
;
; dlwin [@windowname] <0-100> <info-text or c (c=clear)>
;
alias dlwin {
if (@* iswm $1) {
var %w = $1
tokenize 32 $2-
}
else var %w = @Download
var %. = drawrect -nrf %w, %wd = $int($calc(2.76 * $1))
if (!$window(%w)) {
window -aodhBCpk0 +nt %w 1 1 322 110 $shortfn($mircexe)
%. $rgb(face) 1 0 0 999 999
%. $rgb(hilight) 1 18 50 280 20
%. $rgb(shadow) 1 18 50 279 19
}
%. $rgb(face) 1 19 51 278 18
t no %w $rgb(text) 144 53 $1 $+ %
%. 6956042 1 20 52 %wd 16
t nco %w 16777215 144 53 $calc((20+%wd)-144) 11 $1 $+ %
if ($2) {
%. $rgb(face) 1 0 25 322 18
if ($2- != c) t n %w $rgb(text) 20 25 $2-
}
drawdot %w
}
alias -l t { drawtext -r $+ $1 $2 $3 Tahoma 11 $4- }
;
;--------------------------------------------------------------
;
; /dl [@windowname] <http://www.url.blah/filename.ext> [info]
;
; [@windowname] is allowed to enable Basic Update to have a different name.
; normal users shouldn't specify windownames!
;
; sockmark should be:
;
; /sockmark $dlname <@WINDOWNAME> <TYPE> <FILESIZE> <BYTES> <FILENAME> <HOST> <FULL_URL> [INFO]
;
; 1 = @window
; 2 = Type: GET or HEAD
; 3 = Size: 0 if the $1 is HEAD
; 4 = Bytes: for resume purposes, put 0 for new downloads
; 5 = Name: the .txt file to be downloaded
; 6 = Host: for the HTTP requests and maybe progress text
; 7 = Full URL to be issued in the GET command.
; 8 = Info: usually descriptive text.
; For /update, it'll tell the sockclose event what to do with the file.
;
alias dl {
var %w, %url, %s, %i = 1
while ($sock($+(dl.,%i))) { inc %i }
%s = $+(dl.,%i)
sockclose %s
; get windowname
if (@* iswm $1) { %w = $1 | tokenize 32 $2- }
else { %w = @Downloading % $+ file }
; grab the host and filename
if (http://* iswm $1) { %url = $remove($1,http://) }
var %host = $gettok(%url,1,47), %file = $gettok(%url,-1,47)
; re-evaluate the windowname
var %w = $replace($(%w,2),$chr(32),$chr(160))
sockopen %s %host 80
sockmark %s %w HEAD 0 0 %file %host $1-
dlwin %w 0 Connecting to %host $+ ...
}
;
; /sockmark $dlname <@WINDOWNAME> <TYPE> <FILESIZE> <BYTES> <FILENAME> <HOST> <URL> [INFO]
; $1 $2 $3 $4 $5 $6 $7 $8-
;
on *:sockopen:dl.*:{
tokenize 32 $sock($sockname).mark
if ($sockerr) { dl.error $1 $sockname $sock($sockname).wsmsg }
if (($8 == UPDATE_LIST) && ($_isfile(temp\updates\updates.txt))) .remove $ifmatch
sockwrite -n $sockname GET $7 HTTP/1.0
sockwrite -n $sockname Host: $6
sockwrite -n $sockname Connection: Keep-alive
sockwrite -n $sockname Accept: *.*, */*
sockwrite -n $sockname $lf
dlwin $1 1 Attempting to retrieve info for $5 ...
}
on *:sockread:dl.*:{
if ($sockerr) { dl.error $1 $sockname $sock($sockname).wsmsg }
var %a
:a
if ($gettok($sock($sockname).mark,2,32) == HEAD) { sockread %a }
else { sockread &b }
if ($sockbr) {
tokenize 32 $sock($sockname).mark
if ($2 == HEAD) {
if (%a) {
if (HTTP/* iswm $gettok(%a,1,32)) {
var %n = $gettok(%a,2,32)
if ((40? iswm %n) || (50? iswm %n)) { dl.error $1 $sockname Download error: $http.code(%n) }
; Add more response codes later
; Especially for redirected URL's and unknown Content-Lengths
}
if ($gettok(%a,1,32) == Content-Length:) { sockmark $sockname $1-2 $gettok(%a,2,32) $4- }
}
else {
sockmark $sockname $1 GET $3-
dlwin $1 2 Attempting to download $5 ...
}
}
elseif ($2 == GET) {
; extra for update feature
var %d = $getdir($5)
if (UPDATE_* iswm $8) %d = temp\updates\
; normal one
var %f = " $+ %d $+ $5 $+ "
bwrite %f -1 &b
var %cur = $lof($remove(%f,"))
dlwin $1 $int($calc((%cur * 100) / $3)) Downloading $bytes(%cur).suf of $bytes($3).suf ...
}
goto a
}
}
on *:sockclose:dl.*:{
;tokenize 32 $sock($sockname).mark
;^-- this causes the $input to pop up twice
var %s = $sock($sockname).mark
if ($sockerr) { dl.error $gettok(%s,1,32) %s $sock(%s).wsmsg }
if ($gettok(%s,8,32) == UPDATE_LIST) { update.parselist }
elseif ($gettok(%s,8,32) == UPDATE_FILE) { update.prompt }
else {
window -c $gettok(%s,1,32)
!.echo -q $input(Download of $gettok(%s,5,32) completed.,68,Download)
}
}
; /dl.error <window> <socketname> <text>
alias -l dl.error {
window -c $1
if (% [ $+ [ $1 ] ] == $null) {
.timer 1 0 err2 $3- $str($crlf,2) $+ ~Basic
set -u5 % $+ $1 blah
}
sockclose $2
halt
}
alias http.code {
var %num = $1
goto $1
:200 | return OK
:201 | return Created
:202 | return Accepted
:204 | return No Content
:301 | return Moved Permanently
:302 | return Moved Temporarily
:304 | return Not Modified
:400 | return Bad Request
:401 | return Unauthorized
:403 | return Forbidden
:404 | return File Not Found
:500 | return Internal Server Error
:501 | return Not Implemented
:502 | return Bad Gateway
:503 | return Service Unavailable
:%num | return Unknown server reply
}
;
; FEEDBACK
;
dialog feedback {
title "Feedback"
size -1 -1 157 143
option dbu
text "From:", 1, 3 4 30 8, right
edit "", 2, 36 2 118 11, autohs
text "Subject:", 3, 3 16 30 8, right
edit "", 4, 36 14 118 11, autohs
text "Mail server:", 5, 3 28 30 8, right
combo 6, 37 27 110 50, sort edit drop
button "", 7, 149 27 4 4
edit "", 8, 3 40 151 74, multi return vsbar
button "&Send", 9, 23 129 35 12
button "&Clear", 10, 61 129 35 12
button "C&ancel", 11, 99 129 35 12, cancel
edit "", 12, 3 114 151 11, read multi autohs
}
on *:dialog:feedback:init:*:{
did -a $dname 2 $email
var %i = 1
while ($_(feedback.mailservers,%i)) {
did -a $dname 6 $ifmatch
inc %i
}
did -c $dname 6 1
}
on *:dialog:feedback:sclick:7:{
_set feedback.mailservers
did -r $dname 6
}
on *:dialog:feedback:sclick:9:feedback
on *:dialog:feedback:sclick:10:did -r $dname 8,4
on *:dialog:feedback:sclick:11:sockclose $dname
alias valid_email {
var %reg = /^[0-9a-z]([-_\.0-9a-z])*@[0-9a-z]([-\.]?[0-9a-z])*\.([a-z]){2,6}$/i
return $regex($1,%reg)
}
alias feedback {
var %s = feedback
if (!$dialog(%s)) dialog -md %s %s
elseif ($dialog(%s)) {
var %d = $ifmatch, %s = _showdlg %d
if (!$valid_email($did(%d,2))) {
err2 Not a valid email address.~Feedback error
%s
halt
}
if (!$did(%d,8)) {
err2 No message body.~Feedback error
%s
halt
}
if ($did(%d,6)) storeserver $did(%d,6)
else {
err2 No mail server specified~Feedback error
%s
halt
}
did -b %d 2,4,6,7,8,9,10
sockclose %d
sockopen %d $did(%d,6) 25
sockmark %d FEEDBACK_CONNECT
fstat Attempting to connect to mail server...
}
}
alias -l fstat { if ($dialog(feedback)) did -ra $ifmatch 12 $1- }
alias -l storeserver {
if (!$1) { return }
var %i = 1
while ($_(feedback.mailservers,%i)) {
if ($1 == $ifmatch) return
inc %i
}
_set feedback.mailservers %i $1
}
alias err2 {
tokenize 126 $1-
.timer -m 1 0 !.echo -q $input($1,260,$2)
}
on *:sockopen:feedback:{
var %s = $sockname
if ($sockerr) {
fstat Unable to connect to mail server.
return
}
if (($sock(%s).mark == FEEDBACK_CONNECT) && (!$dialog(%s))) {
sockclose %s
return
}
.timer 1 1 sockwrite -n $sockname HELO $ip
sockmark %s HELO
fstat Connection established, attempting to send...
}
on *:sockread:feedback:{
var %s = $sockname, %m
if (($sock(%s).mark == HELO) && (!$dialog(%s))) {
sockclose %s
return
}
if ($sockerr) {
fstat $_iif($sock(%s).wsmsg,Connection error)
if ($dialog(%s)) did -e %s 2,4,6,7,8,9,10
return
}
:a
sockread %a
if ($sockbr) {
if (!%a) goto a
tokenize 32 %a
if ($1 isnum 400-599) {
fstat Mail server error: $2-
if ($dialog(%s)) did -e %s 2,4,6,7,8,9,10
sockclose %s
return
}
elseif ($1 == 250) {
%m = $sock(%s).mark
if (%m == HELO) {
sockwrite -tn %s MAIL FROM: $did(%s,2)
sockmark %s FROM
}
elseif (%m == FROM) {
sockwrite -tn %s RCPT TO: belf@mircscripter.com
sockmark %s TO
}
elseif (%m == TO) {
sockwrite -tn %s DATA
sockmark %s DATA
}
elseif (%m == DATA_DONE) sockwrite -tn %s QUIT
}
; send data
elseif ($1 == 354) {
fstat Sending data...
sockwrite -tn %s Subject: [Basic feedback] $did(%s,4)
sockwrite -tn %s X-Mailer: Basic feedback form
sockwrite -tn %s $lf
sockwrite -tn %s mIRC ver: $version $+ , Basic ver: $basic.ver
sockwrite -tn %s Dir: $mircdir $+ , OS: $os
sockwrite -tn %s Total script files: $script(0) $+ , Total aliases files: $alias(0)
sockwrite -tn %s Current theme setting: (MTS: $group(#display.mts) $+ ) (Basic: $group(#display.basic) $+ )
sockwrite -tn %s User: $me ( $+ $_iif($address($me,5),No address available) $+ / $&
$+ $_iif($email,No actual email available) $+ )
var %i = 1, %servers
while ($scon(%i).server) {
%servers = $addtok(%servers,$ifmatch,44)
inc %i
}
sockwrite -tn %s Servers: $_iif(%servers,Not connected)
sockwrite -tn %s $lf
var %i = 1, %a = $did(%s,8).lines
while (%i <= %a) {
if ($did(%s,8,%i)) sockwrite -tn %s $ifmatch
else sockwrite -tn %s $cr
inc %i
}
sockwrite -tn %s .
sockmark %s DATA_DONE
}
; connection closed
elseif ($1 == 221) fstat Mailserver closing connection...
; errors
elseif ($1 == 550) {
fstat Cannot send: please try another email server or send later.
if ($dialog(%s)) did -e %s 2,4,6,8,9,10
sockclose %s
return
}
goto a
}
}
on *:sockclose:feedback:{
var %s = $sockname, %d = $dialog(%s)
if ($sockerr) {
fstat $_iif($sock(%s).wsmsg,Connection error)
if (%d) did -e %s 2,4,6,8,9,10
}
else {
fstat Connection closed.
if (%d) dialog -x %s
}
}
; eof