updateMirc — File Browser
updateMircv1.0 / updateMircv1.0 / updatemirc.mrc
updatemirc.mrc — 20.33 KB — Download this file
;/////////////////////////////////////////////////////////////////
; update mIRC v1.0
; Author: Smay
; Last Modified: 10/08/05, 07:57pm
;
; This script will connect to www.mirc.com and check the version
; number of the latest release of mIRC. If a new version is
; available, it will prompt the user to download it.
;
; If the user choses to download mIRC, a screen will pop up showing
; a list of servers, their locations, and their ping. The user
; selects from this list, and clicks "Download" to download from
; that server. Until the download succeeds or the user closes the
; window, the server list will remain on the screen.
;
; Servers that do not respond to ping requests, or that a download
; fails from are marked with a *
;
; Please see readme.txt for more information, as well as a list of
; known bugs
;
; Credits:
; *Download socket script borrowed from ^Andy, and modified for
; this projet.
; *Ping alias borrowed from Sephiroth and modified for this
; project
;/////////////////////////////////////////////////////////////////
;An easier to remember alias to get the current version
alias updatemIRC { updMirc.getCurrentVersion }
;Check for a new version on load. Also make sure this can actually run
;on the user's current version
on 1:load: {
if ($version < 5.91) { echo 4 -a This script requires mIRC 5.91 or later. You can download the latest version at www.mirc.com | halt }
echo 7 -a updatemIRC was successfully loaded. Please see readme.txt for more information about this script.
updatemIRC
}
;On connect check to see if a new version of mIRC exists
on 1:connect: { updatemIRC }
;On Screen menus
menu status,nicklist,channel,query {
-
Update mIRC: { updatemIRC }
}
;================================================================================
;Get the latest version number of mIRC
;================================================================================
;Check www.mirc.com to get the latest version
alias updMirc.getCurrentVersion {
if ($sock(updMirc.getCurrVer)) {
echo 4 -a Socket is already in use!
return
}
sockopen updMirc.getCurrVer www.mirc.com 80
}
on 1:sockopen:updMirc.getCurrVer: {
if ($sockerr) {
echo 4 -a Error! ( $+ $sockerr $+ )
return
}
;Send header information
sockwrite -n $sockname GET http://www.mirc.com/index.html HTTP/1.0
sockwrite -n $sockname Accept: */*
sockwrite -n $sockname Host: www.mirc.com
sockwrite -n $sockname
}
;Scan index.html for the words "released". If the version released is > current version, ask
;User if they want to update
on 1:sockread:updMirc.getCurrVer: {
var %updMirc.htmlinfo
sockread %updMirc.htmlinfo
while ($sockbr) {
if (*has been released* iswm %updMirc.htmlinfo) {
var %updMirc.latestversion $updMirc.striphtml(%updMirc.htmlinfo)
sockclose updMirc.getCurrVer
if (%updMirc.latestversion) {
var %updMirc.version $wildtok(%updMirc.latestversion,*.*,1,32)
if (%updMirc.version > $version) {
.timer -m 1 100 updMirc.askForUpdate
}
}
}
else {
sockread %updMirc.htmlinfo
}
}
}
on 1:sockclose:updMirc.getCurrVer: {
echo 4 -a Connection closed by host!
}
;================================================================================
;Get the server list for download sites
;================================================================================
;Download the latest version of mIRC
alias updMirc.GetServers {
if ($sock(updMirc.GetServers)) {
echo 4 -a Socket is already in use!
return
}
sockopen updMirc.GetServers www.mirc.com 80
}
on 1:sockopen:updMirc.GetServers: {
if ($sockerr) {
echo 4 -a Error! ( $+ $sockerr $+ )
return
}
sockwrite -n $sockname GET http://www.mirc.com/get.html HTTP/1.0
sockwrite -n $sockname Accept: */*
sockwrite -n $sockname Host: www.mirc.com
sockwrite -n $sockname
}
on 1:sockread:updMirc.GetServers: {
window -h @Servers
var %updMirc.htmlinfo
sockread %updMirc.htmlinfo
while ($sockbr) {
if (American and Canadian isin %updMirc.htmlinfo) {
set %updMirc.getURL 1
}
if ((*<b>*</b>*<br>* iswm %updMirc.htmlinfo) && (%updMirc.getURL == 1)) {
aline @Servers -- $+ $updMirc.striphtml(%updMirc.htmlinfo)
}
if (</table> isin %updMirc.htmlinfo) {
unset %updMirc.getURL
sockclose updMirc.GetServers
.timer -m 1 100 dialog -ma updMirc.ServerList updMirc.ServerList
break
}
if (%updMirc.getURL == 1) {
if ((href isin %updMirc.htmlinfo) && ($(< $+ $chr(33)) !isin %updMirc.htmlinfo)) {
if (ftp:// !isin %updMirc.htmlinfo) {
var %updMirc.server $gettok($remove(%updMirc.htmlinfo,<A href="),1,34)
if ($chr(61) !isin %updMirc.server) {
var %updMirc.state $gettok(%updMirc.htmlinfo,5-,32)
aline @Servers $gettok(%updMirc.state,1,60)
aline @Servers $gettok($remove(%updMirc.htmlinfo,<A href="),1,34)
}
}
}
}
sockread %updMirc.htmlinfo
}
}
on 1:sockclose:updMirc.GetServers: {
echo 4 -a Connection closed by host!
unset %updMirc.getURL
}
;================================================================================
;Download the latest version of mIRC
;================================================================================
alias updMirc.DownloadMirc {
if ($sock(updMirc.DownloadMirc)) {
echo 4 -a Socket is already in use!
return
}
set %updMirc.file $3-
sockopen updMirc.DownloadMirc $gettok($3-,2,47) 80
}
on *:sockopen:updMirc.DownloadMirc:{
if ($sockerr) {
echo 4 -a Error! $sockerr when downloading
return
}
write -c " $+ %updMirc.saveDir $+ $nopath(%updMirc.file) $+ "
unset %updMirc.downloadlength %updMirc.downloadready
sockwrite -n $sockname GET %updMirc.file HTTP/1.0
sockwrite -n $sockname Accept: */*
sockwrite -n $sockname Host: $gettok(%updMirc.file,2,47)
sockwrite -n $sockname
}
on *:sockread:updMirc.DownloadMirc:{
if ($sockerr) { return }
if (%updMirc.downloadready != 1) {
var %updMirc.header
sockread %updMirc.header
while ($sockbr) {
if (Content-length: * iswm %updMirc.header) {
%updMirc.downloadlength = $gettok(%updMirc.header,2,32)
}
elseif (* !iswm %updMirc.header) {
%updMirc.downloadready = 1
%updMirc.downloadoffset = $sock($sockname).rcvd
break
}
sockread %updMirc.header
}
}
if (%updMirc.firsttime != $false) {
updMirc.dlwindow $nopath(%updMirc.file) $gettok(%updMirc.file,2,47)
set %updMirc.oldbr $sock(updMirc.DownloadMirc).rcvd
.timerCPS -m 0 200 updMirc.UpdateCPS
set %updMirc.firsttime $false
set %updMirc.starttime $ticks
}
sockread 4096 &d
while ($sockbr) {
updMirc.UpdateProgress $round($calc(100 * ($sock(updMirc.DownloadMirc).rcvd - %updMirc.downloadoffset) / %updMirc.downloadlength),1)
bwrite " $+ %updMirc.saveDir $+ $nopath(%updMirc.file) $+ " -1 -1 &d
sockread 4096 &d
}
}
on *:sockclose:updMirc.DownloadMirc:{
if ($file(" $+ %updMirc.saveDir $+ $nopath(%updMirc.file) $+ ").size <= 500000) {
.timer -m 1 100 updMirc.ShowError
}
.timerCPS off
drawrect -nrf @Downloading $rgb(face) 1 120 100 80 20
updMirc.drawbutton 120 100 80 20 Open File
drawrect -nrf @Downloading $rgb(face) 1 3 80 283 14
drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 3 80 Transfer Rate: $round($calc(($file(" $+ %updMirc.saveDir $+ $nopath(%updMirc.file) $+ ") / (($ticks - %updMirc.starttime) / 1000)) / 1024),2) $+ k/s
drawdot @Downloading
set %updMirc.open $true
}
;================================================================================
;Aliases
;================================================================================
;Strip all HTML codes from lines read in (or most, at least). ReExp would be better here
alias updMirc.striphtml {
if ($1-) {
var %updMirc.codeline $replace($1-,$chr(44),$chr(189))
while ($chr(60) isin %updMirc.codeline) {
var %updMirc.codeline $remove(%updMirc.codeline,$mid(%updMirc.codeline,$pos(%updMirc.codeline,$chr(60),1),$calc($pos(%updMirc.codeline,$chr(62),1) - $pos(%updMirc.codeline,$chr(60),1) + 1)))
}
return $replace(%updMirc.codeline,$chr(189),$chr(44))
}
}
;Since $input can't be used in events, an alias to check if the user wants to update
;Ask if they want to update
alias -l updMirc.askForUpdate {
if ($input(There is a new version of mIRC available! Would you like to download it?,104,New mIRC Version Available) == $yes) {
.timer -m 1 100 updMirc.GetServers
}
}
alias updMirc.Ping {
var %x = $ticks
var %p = $gettok($1,2,47)
var %f = c:\ $+ %p $+ .txt
var %r = $iif($2 isnum,$2,1),%r = %r * 1000
if ($com(ping $+ %x)) { .comclose ping $+ %x }
.comopen ping $+ %x WScript.Shell
if !$comerr { .comclose ping $+ %x $com(ping $+ %x,Run,3,bstr,$iif($istok(95 98 ME,$os,32),command.com,cmd.exe) /c ping %p -n 1 -w %r > %f,uint,0,bool,true) }
%p = $read(%f,n,4)
if (: isin %p) { .remove %f | return $gettok($gettok($gettok(%p,2-,58),2,32),2,61) }
else { .remove %f | return $false }
}
alias updMirc.ShowError {
var %updMirc.useless $input(Sorry $+ $chr(44) there appears to have been an error in the file transfer. Please try a different server.,ow,Error!)
unset %updMirc.down*
window -c @Downloading
var %updMirc.sel $did(updMirc.ServerList,5).sel
did -c updMirc.ServerList 5 %updMirc.sel
did -e updMirc.ServerList 5
did -e updMirc.ServerList 1
}
;================================================================================
;Update screens
;================================================================================
;/updMirc.UpdateCPS bytes read
alias updMirc.UpdateCPS {
var %updMirc.cps $round($calc((($sock(updMirc.DownloadMirc).rcvd / 1024) - (%updMirc.oldbr / 1024)) * 5),2)
set %updMirc.oldbr $sock(updMirc.DownloadMirc).rcvd
drawrect -nrf @Downloading $rgb(face) 1 3 80 283 14
drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 3 80 Transfer Rate: %updMirc.cps $+ k/s
drawdot @Downloading
}
alias updMirc.dlwindow {
window -Cdpk0 @Downloading -1 -1 300 160
titlebar @Downloading $1
drawrect -nrf @Downloading $rgb(face) 1 0 0 300 155
drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 3 7 Downloading $1 from $2
drawline -nr @Downloading $rgb(shadow) 1 3 40 3 30 285 30
drawline -nr @Downloading $rgb(hilight) 1 285 31 285 40 3 40
drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 3 50 Transfer Status:
drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 3 65 Saving to: $mircdir $+ $1
drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 3 80 Transfer Rate: Unknown
updMirc.drawbuttondis 120 100 80 20 Open File
updMirc.drawbutton 205 100 80 20 Close
updMirc.updateprogress 0
set %updMirc.open $false
drawdot @Downloading
window -a @Downloading
}
;/updMirc.drawbutton x y w h text
alias -l updMirc.drawbutton {
drawrect -nrf @Downloading $rgb(face) 1 $1 $2 $3 $4
drawline -nr @Downloading $rgb(hilight) 1 $1 $calc($2 + $4) $1 $2 $calc($1 + $3) $2
drawline -nr @Downloading $rgb(shadow) 1 $1 $calc($2 + $4) $calc($1 + $3) $calc($2 + $4) $calc($1 + $3) $calc($2 - 1)
drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 $calc($1 + ($3 / 2) - ($width($5-,Veranda,10,0,0) / 2) - 3) $calc($2 + ($4 / 2) - ($height($5-,Veranda,10) / 2)) $5-
}
alias -l updMirc.drawbuttondis {
drawrect -nrf @Downloading $rgb(face) 1 $1 $2 $3 $4
drawline -nr @Downloading $rgb(hilight) 1 $1 $calc($2 + $4) $1 $2 $calc($1 + $3) $2
drawline -nr @Downloading $rgb(shadow) 1 $1 $calc($2 + $4) $calc($1 + $3) $calc($2 + $4) $calc($1 + $3) $calc($2 - 1)
drawtext -nr @Downloading $rgb(hilight) "Veranda" 12 $calc($1 + ($3 / 2) - ($width($5-,Veranda,10,0,0) / 2) - 3 + 1) $calc($2 + ($4 / 2) - ($height($5-,Veranda,10) / 2) + 1) $5-
drawtext -nr @Downloading $rgb(shadow) "Veranda" 12 $calc($1 + ($3 / 2) - ($width($5-,Veranda,10,0,0) / 2) - 3) $calc($2 + ($4 / 2) - ($height($5-,Veranda,10) / 2)) $5-
}
alias -l updMirc.drawbuttondown {
drawrect -nrf @Downloading $rgb(face) 1 $1 $2 $3 $4
drawline -nr @Downloading $rgb(shadow) 1 $1 $calc($2 + $4) $1 $2 $calc($1 + $3) $2
drawline -nr @Downloading $rgb(hilight) 1 $1 $calc($2 + $4) $calc($1 + $3) $calc($2 + $4) $calc($1 + $3) $calc($2 - 1)
drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 $calc($1 + ($3 / 2) - ($width($5-,Veranda,10,0,0) / 2) - 3) $calc($2 + ($4 / 2) - ($height($5-,Veranda,10) / 2)) $5-
}
;/updMirc.updateprogress <%complete>
alias updMirc.updateprogress {
drawrect -nrf @Downloading $rgb(0,0,192) 1 4 31 $calc($1 * (280 / 100)) 9
drawrect -nrf @Downloading $rgb(face) 1 3 50 283 14
$iif($calc($sock(updMirc.DownloadMirc).rcvd - %updMirc.downloadoffset) < %updMirc.downloadlength,drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 3 50 Transfer Status: $round($calc(($sock(updMirc.DownloadMirc).rcvd - %updMirc.downloadoffset) / 1024),2) $+ KB of $round($calc(%updMirc.downloadlength / (1024 * 1024)),2) $+ mb ( $+ $1 $+ % $+ ),drawtext -nr @Downloading $rgb(0,0,0) "Veranda" 12 3 50 Transfer Status: $round($calc(($sock(updMirc.DownloadMirc).rcvd - %updMirc.downloadoffset) / (1024 * 1024)),2) $+ mb of $round($calc(%updMirc.downloadlength / (1024 * 1024)),2) $+ mb ( $+ $1 $+ % $+ ))
drawdot @Downloading
}
menu @Downloading {
sclick: {
if ($inrect($mouse.x,$mouse.y,120,100,80,20)) {
if (%updMirc.open == $true) {
if ($window(@Downloading)) { updMirc.drawbuttondown 120 100 80 20 Open File }
}
}
if ($inrect($mouse.x,$mouse.y,205,100,80,20)) {
if ($window(@Downloading)) { updMirc.drawbuttondown 205 100 80 20 Close }
}
drawdot @Downloading
}
uclick: {
$iif(%updMirc.open == $true,updMirc.drawbutton 120 100 80 20 Open File,updMirc.drawbuttondis 120 100 80 20 Open File)
updMirc.drawbutton 205 100 80 20 Close
drawdot @Downloading
if ($inrect($mouse.x,$mouse.y,120,100,80,20)) {
if (%updMirc.open == $true) {
run " $+ %updMirc.saveDir $+ $nopath(%updMirc.file) $+ "
.timerCPS off
if ($sock(updMirc.DownloadMirc)) {
sockclose updMirc.DownloadMirc
}
.timer -m 1 100 window -c @Downloading
window -c @Servers
unset %updMirc.*
dialog -x updMirc.ServerList
}
}
if ($inrect($mouse.x,$mouse.y,205,100,80,20)) {
.timerCPS off
if ($sock(updMirc.DownloadMirc)) {
sockclose updMirc.DownloadMirc
}
if ($file(" $+ %updMirc.saveDir $+ $nopath(%updMirc.file) $+ ").size > 500000) {
window -c @Servers
unset %updMirc.*
dialog -x updMirc.ServerList
}
else {
var %updMirc.sel $did(updMirc.ServerList,5).sel
did -c updMirc.ServerList 5 %updMirc.sel
did -e updMirc.ServerList 5
did -e updMirc.ServerList 1
}
window -c @Downloading
}
}
}
on 1:close:@Downloading: {
.timerCPS off
if ($sock(updMirc.DownloadMirc)) {
sockclose updMirc.DownloadMirc
}
if ($file(" $+ %updMirc.saveDir $+ $nopath(%updMirc.file) $+ ").size > 500000) {
window -c @Servers
unset %updMirc.*
dialog -x updMirc.ServerList
}
else {
var %updMirc.sel $did(updMirc.ServerList,5).sel
did -c updMirc.ServerList 5 %updMirc.sel
did -e updMirc.ServerList 5
did -e updMirc.ServerList 1
}
}
;================================================================================
;Server list
;================================================================================
dialog updMirc.ServerList {
title "Select Download Server"
size -1 -1 174 138
option dbu
text "Please select a server to download from",89,3 3 168 12, center
text "Region:", 95, 3 15 50 12
combo 200, 30 13 142 50, drop
text "Location and Server URL",90,3 33 100 12
list 5,2 40 170 65, vsbar hsbar
box "Server Information",80,3 98 70 25
text "Location: ",91, 8 106 30 8
text "Unknown",92, 35 106 36 8
text "Ping:",93, 8 113 30 8
text "Unknown",94, 35 113 36 8
box "Select Download Folder",81,78 98 93 25
edit "C:\",10,83 108 58 10, autohs
button "Browse",3,143 108 25 10
button "Download",1,30 125 55 10, default
button "Cancel",2,90 125 55 10, cancel
}
on 1:dialog:updMirc.ServerList:init:0: {
var %updMirc.counter 2
var %updMirc.AddToServerList $true
did -a updMirc.ServerList 200 $right($line(@Servers,1),-2)
while (%updMirc.counter <= $line(@Servers,0)) {
if ($left($line(@Servers,%updMirc.counter),2) == --) {
did -a updMirc.ServerList 200 $right($line(@Servers,%updMirc.counter),-2)
var %updMirc.AddToServerList $false
inc %updMirc.counter 1
}
else {
if (%updMirc.AddToServerList == $true) {
did -a updMirc.ServerList 5 $line(@Servers,%updMirc.counter) - $line(@Servers,$calc(%updMirc.counter + 1))
}
inc %updMirc.counter 2
}
}
;Select the first region
did -c updMirc.ServerList 200 1
;Select the first line
did -c updMirc.ServerList 5 1
;Set Editbox
set %updMirc.saveDir $mircdir
did -o updMirc.ServerList 10 1 %updMirc.saveDir
;Get Information for the selected line, and update it
did -o updMirc.ServerList 92 1 $gettok($remove($did(updMirc.ServerList,5,$did(updMirc.ServerList,5).sel).text,*),1,32)
var %updMirc.ping $updMirc.Ping($gettok($remove($did(updMirc.ServerList,5,$did(updMirc.ServerList,5).sel).text,*),3,32))
if ( [ %updMirc.ping ] == $false) {
did -o updMirc.ServerList 94 1 Unknown
}
else {
did -o updMirc.ServerList 94 1 %updMirc.ping
}
}
;Region list
on 1:dialog:updMirc.ServerList:sclick:200: {
var %updMirc.region $did(updMirc.Serverlist,200).text
var %updMirc.linenum $fline(@Servers,* $+ %updMirc.region $+ *, 1)
if (%updMirc.linenum != $null) {
did -r updMirc.ServerList 5
inc %updMirc.linenum
while (%updMirc.linenum <= $line(@Servers,0)) {
if ($left($line(@Servers,%updMirc.linenum),2) == --) { break }
did -a updMirc.ServerList 5 $line(@Servers,%updMirc.linenum) - $line(@Servers,$calc(%updMirc.linenum + 1))
inc %updMirc.linenum 2
}
did -c updMirc.ServerList 5 1
}
}
;Server list
on 1:dialog:updMirc.ServerList:sclick:5: {
;Get Information for the selected line, and update it
did -o updMirc.ServerList 92 1 $left($gettok($remove($did(updMirc.ServerList,5,$did(updMirc.ServerList,5).sel).text,*),1,45),-1)
var %updMirc.ping $updMirc.Ping($right($gettok($remove($did(updMirc.ServerList,5,$did(updMirc.ServerList,5).sel).text,*),2-,45),-1))
if (%updMirc.ping == $false) {
;Cannot ping server. Mark with a * to indicate timeout
did -o updMirc.ServerList 94 1 Unknown
var %updMirc.sel $did(updMirc.ServerList,5).sel
did -c updMirc.ServerList 5 %updMirc.sel
}
else {
did -o updMirc.ServerList 94 1 %updMirc.ping
var %updMirc.sel $did(updMirc.ServerList,5).sel
did -c updMirc.ServerList 5 %updMirc.sel
}
}
;Browse button
on 1:dialog:updMirc.ServerList:sclick:3: {
if ($exists(" $+ $did(updMirc.ServerList,10).text $+ ")) {
set %updMirc.saveDir $sdir(" $+ $did(updMirc.ServerList,10).text $+ ",Select Download Folder)
}
else {
set %updMirc.saveDir $sdir(" $+ $mircdir $+ ",Select Download Folder)
}
did -o updMirc.ServerList 10 1 %updMirc.saveDir
}
;Editbox
on 1:dialog:updMirc.ServerList:edit:10: {
set %updMirc.saveDir $did(updMirc.ServerList,10).text
}
;OK Button
on 1:dialog:updMirc.ServerList:sclick:1: {
;Check download dir
if ($exists(" $+ $did(updMirc.ServerList,10).text $+ ")) {
unset %updMirc.firsttime
;Start downloading from current server and disable IDs until download window is closed
did -b updMirc.ServerList 5
did -b updMirc.ServerList 1
.timer -m 1 100 updMirc.DownloadMirc $remove($did(updMirc.ServerList,5,$did(updMirc.ServerList,5).sel).text,*)
}
else {
var %updMirc.useless $input(Sorry $+ $chr(44) the directory: %updMirc.saveDir does not exist. Please use the create new directory button when clicking browse to create this directory first,ow,Directory does not exist)
}
}
;Cancel Button
on 1:dialog:updMirc.ServerList:sclick:2: {
window -c @Servers
unset %updMirc.*
}