Peace & Protection 4.00 — File Browser
PeaceProtection4.00v4.0 / PeaceProtection4.00v4.0 / SCRIPT / upgrade.mrc
upgrade.mrc — 11.79 KB — Download this file
; #= P&P -rs
; ########################################
; Peace & Protection
; Upgrading / news / etc. from www.pairc.com
; ########################################
;
; Download and install updates
;
alias update _dialog -am ppupdate ppupdate
on *:SOCKOPEN:PNP.UPDATE:{
if ($sockerr) _ppue Could not connect to www.pairc.com
sockwrite -n PNP.UPDATE GET /pnpinfo.txt HTTP/0.9
sockwrite -n PNP.UPDATE Host: update.pairc.com
sockwrite -n PNP.UPDATE Referrer: update.pairc.com
sockwrite -n PNP.UPDATE
}
on *:SOCKREAD:PNP.UPDATE:{
if ($sockerr) _ppue Error reading data from socket
if ($window(@.update) == $null) window -hnls @.update
var %data
:again
sockread -n %data
if ($sockbr) {
if ($sock(PNP.UPDATE).mark) aline @.update %data
elseif (HTTP/* iswm $gettok(%data,1,32)) {
if ($gettok(%data,2,32) !isnum 200-299) _ppue Error from server: $gettok(%data,3-,32)
}
elseif (%data == $null) sockmark PNP.UPDATE 1
goto again
}
}
on *:SOCKCLOSE:PNP.UPDATE:{
if ($sock(PNP.UPDATE).mark) { _ppp | _ppu 1 }
else _ppue Connection was interrupted
}
dialog ppupdate {
title "P&P Updates"
size -1 -1 500 304
check "News", 1, 10 10 90 25, push disable
check "Recommended upgrades", 2, 110 10 150 25, push disable
check "All files", 3, 270 10 110 25, push disable
text "Please wait, contacting www.pairc.com for updates...", 10, 10 50 480 40
box "", 11, 10 100 480 157, hide
list 20, 20 120 350 140, hide vsbar extsel
edit "", 21, 20 120 460 123, multi read vsbar hide
list 22, 20 120 350 140, hide vsbar extsel
button "Upgrade", 100, 380 120 98 25, hide
button "Download", 101, 380 155 98 25, hide
button "Info...", 102, 380 218 98 25, hide
;;; text "If you prefer, you can visit www.pairc.com/pnp/ for files.", 150, 10 275 350 20
text "THIS STUFF IS INCOMPLETE, DO NOT EXPECT IT TO ALL WORK", 150, 10 275 350 20
button "Cancel", 200, 380 269 98 25, cancel
}
on *:DIALOG:ppupdate:init:*:{
sockopen PNP.UPDATE www.pairc.com 80
}
on *:DIALOG:ppupdate:sclick:*:{
if ($did isnum 1-3) _ppu $did
elseif ($did == 200) _ppue Cancelled
elseif (($did == 20) || ($did == 22)) _ppld $did
elseif ($did isnum 100-102) {
if ($did(2).state) var %box = 20,%win = @.update2
else var %box = 22,%win = @.update
if ($did == 102) {
if ($window(@Upgrade)) { clear @Upgrade | window -a @Upgrade }
else _window 2.1 -alkd -t11 @Upgrade $_center(450,320) @Upgrade
titlebar @Upgrade Info
var %ln = 1
:loop1
if ($line(%win,$did(%box,%ln).sel)) {
_ppin $ifmatch
inc %ln | goto loop1
}
}
else {
if ($did == 100) titlebar %win inst
else titlebar %win dl
sline -r %win
var %ln = 1
:loop2
if ($did(%box,%ln).sel) {
sline -a %win $ifmatch
inc %ln | goto loop2
}
window -c @.install
renwin %win @.install
var %ln = 1
:loop3
if (%ln <= $line(@.install,0)) {
if ($sline(@.install,%ln).ln != %ln) {
dline @.install %ln
goto loop3
}
else {
inc %ln
goto loop3
}
}
.timer -o 1 0 _ppupgrade
.timer -o 1 0 dialog -c ppupdate
}
}
}
alias -l _ppue {
sockclose PNP.UPDATE
close -@ @.update @.update2 @Upgrade
did -o ppupdate 10 1 Error getting updates: $1-
halt
}
alias -l _ppu {
did -v ppupdate 11
did -o ppupdate 200 1 Close
did -e ppupdate 1,2,3
goto $1
:1 | did -c ppupdate 1 | did -u ppupdate 2,3 | did -h ppupdate 100,101,102,20,22 | did -v ppupdate 21 | did -o ppupdate 10 1 The following is recent news on Peace && Protection. Select 'Recommended upgrades' above for recommended downloads, or 'All files' to view all downloadable files and updates. | return
:2 | did -c ppupdate 2 | did -u ppupdate 1,3 | did -vo ppupdate 100 1 Upgrade | did -h ppupdate 101,21,22 | did -v ppupdate 102,20 | _ppld 20 | did -o ppupdate 10 1 Based on your current P&&P version and installed addons, the following upgrades are recommended. Select the files you wish to install, and click Upgrade to begin. | return
:3 | did -c ppupdate 3 | did -u ppupdate 1,2 | did -vo ppupdate 100 1 Install | did -v ppupdate 101,102,22 | did -h ppupdate 20,21 | _ppld 22 | did -o ppupdate 10 1 The following Peace && Protection patches, addons, and files are available. Select one or more files and click Install to install them, or Download to just download them. | return
}
alias -l _ppld if ($did(ppupdate,$1,0).sel) did -e ppupdate 100,101,102 | else did -b ppupdate 100,101,102
alias -l _ppp {
window -hnl @.update2
filter -ww @.update @.update2 news *
var %line = $line(@.update2,0)
:loop1
if ($gettok($line(@.update2,%line),3,32) < $:bver) dline @.update2 %line
if (%line) { dec %line | goto loop1 }
%line = $line(@.update2,0)
if (%line) {
:loop2
if (%line) {
did -a ppupdate 21 $asctime($ctime($gettok($line(@.update2,%line),2,32)),mmm dd) - $gettok($line(@.update2,%line),4-,32) $+ $crlf
dec %line | goto loop2
}
}
else did -a ppupdate 21 (no news)
clear @.update2
filter -ww @.update @.update2 patch & $:bver & r *
filter -ww @.update @.update2 addon *
%line = 1
:loop3
if ($gettok($line(@.update2,%line),1,32) == patch) {
if ($gettok($line(@.update2,%line),4,32) isin $gettok($gettok($:ver,1,32),3,46)) dline @.update2 %line
else inc %line
goto loop3
}
:loop4
if ($gettok($line(@.update2,%line),1,32) == addon) {
if ($gettok($line(@.update2,%line),3,32) > $:bver) dline @.update2 %line
elseif $istok(%!addon.ids,$gettok($line(@.update2,%line),5,32),32) == $false) dline @.update2 %line
else if ($gettok($line(@.update2,%line),6,32) <= $readini -n $_cfgx(addons,$gettok($line(@.update2,%line),5,32)) addon version) dline @.update2 %line
else inc %line
goto loop4
}
%line = 1
:loop5
if ($line(@.update2,%line)) {
if ($_ppf($ifmatch)) {
did -ack ppupdate 20 $ifmatch
inc %line
}
else dline @.update2 %line
goto loop5
}
if (%line == 1) did -ab ppupdate 20 (no recommended upgrades)
%line = 1
:loop6
if ($line(@.update,%line)) {
if ($_ppf($ifmatch)) {
did -a ppupdate 22 $ifmatch
inc %line
}
else dline @.update %line
goto loop6
}
if (%line == 1) did -ab ppupdate 20 (no files available for download)
}
alias -l _ppf {
tokenize 32 $1-
var %fallout = $1
goto $1
:patch | if ($3 != $:bver) return | return Patch- $3 $+ . $+ $4 $_p2s($6) $iif($5 == r,(standard patch),(optional patch))
:addon | if ($3 > $:bver) return | return Addon- $_p2s($7) $6 by $_p2s($8) $iif($4 == c,(core addon),$iif($4 == e,(extra addon),(third-party addon)))
:%fallout | return
}
alias -l _ppin {
if ($line(@Upgrade,0) > 0) aline @Upgrade
tokenize 32 $1-
var %fallout = $1
goto $1
:patch
aline @Upgrade Patch: $+ $_p2s($6)
aline @Upgrade Patch code: $+ $:b($4) (released $asctime($ctime($2),mmm dd yyyy) $+ )
aline @Upgrade For PnP: $+ $3 $iif($3 != $:bver,(only),$iif($5 == r,(recommended patch),(optional patch)))
aline @Upgrade Size: $+ $_size($7)
aline @Upgrade File: $+ $nopath($8)
return
:addon
aline @Upgrade Addon: $+ $:h($_p2s($7))
aline @Upgrade Version: $+ $6 (released $asctime($ctime($2),mmm dd yyyy) $+ )
aline @Upgrade For PnP: $+ $3 $iif($3 < $:bver,(or later))
aline @Upgrade Author: $+ $_p2s($8)
aline @Upgrade Group: $+ $iif($4 == c,Core addon,$iif($4 == e,Extra addon,Third-party addon))
aline @Upgrade Size: $+ $_size($9)
aline @Upgrade Files: $+ $nopath($10)
var %bit = 11
:loop
if ($ [ $+ [ %bit ] ] ) {
aline @Upgrade $+ $nopath($ifmatch)
inc %bit | goto loop
}
return
:%fallout | return
}
; Actually handles downloads/upgrades based on @.install
alias -l _ppupgrade {
_progress.1 Downloading required files...
; Calculate total file size
var %total = 0,%ln = 1,%line
:loop1
tokenize 32 $sline(@.install,%ln)
if ($1) {
inc %total $iif($1 == addon,$9,$7)
inc %ln | goto loop1
}
if ($window(@.install).title == dl) {
%_install.target = $sdir="Download files to...?" $getdir
if (%_install.target == $null) { _ppdclean | return }
}
:loop2
%_install.dir = ~DL $+ $r(1000,9999)
if ($isdir(%_install.dir)) goto loop2
mkdir %_install.dir
%_install.size = %total
%_install.pos = 0
unset %_install.set
_ppnextfile
}
alias -l _ppnextfile {
if (%_install.set == $null) {
if ($sline(@.install,0)) {
tokenize 32 $sline(@.install,1)
sline -r @.install $sline(@.install,1).ln
%_install.line = $1-
if ($1 == patch) %_install.set = $8
else %_install.set = $10-
}
else { .timer -o 1 0 _ppfinishinstall | return }
}
%_install.what = $gettok(%_install.set,1,32)
%_install.filesize = $gettok(%_install.what,1,47)
%_install.get = / $+ $gettok(%_install.what,3-,47)
%_install.to = %_install.dir $+ / $+ $gettok(%_install.get,$numtok(%_install.get,47),47)
sockopen PNP.DOWNLOAD www.pairc.com 80
_progress.2 $round($calc(%_install.pos * 100 / %_install.size),0) Connecting to www.pairc.com...
}
on *:SOCKOPEN:PNP.DOWNLOAD:{
if ($sockerr) _ppde Could not connect to www.pairc.com
sockwrite -n PNP.DOWNLOAD GET %_install.get HTTP/0.9
sockwrite -n PNP.DOWNLOAD Host: $ip
sockwrite -n PNP.DOWNLOAD Referrer: pairc.update.net
sockwrite -n PNP.DOWNLOAD
_progress.2 $round($calc(%_install.pos * 100 / %_install.size),0) Requesting %_install.get $+ ...
}
on *:SOCKREAD:PNP.DOWNLOAD:{
if ($sockerr) _ppde Error reading data from socket
; (read data)
if ($sock(PNP.DOWNLOAD).mark) {
:file
sockread &data
if ($sockbr) {
bwrite %_install.to -1 $sockbr &data
inc %_install.pos $sockbr
dec %_install.filesize $sockbr
if (%_install.filesize < 0) _ppde File being received is larger than expected
goto file
}
_progress.2 $round($calc(%_install.pos * 100 / %_install.size),0) Downloading %_install.get $+ ...
}
else {
var %data
:header
sockread -n %data
if ($sockbr) {
if (%data == $null) sockmark PNP.DOWNLOAD 1
else {
if (HTTP/* iswm $gettok(%data,1,32)) {
if ($gettok(%data,2,32) !isnum 200-299) _ppde Error from server: $gettok(%data,3-,32)
}
goto header
}
}
}
}
on *:SOCKCLOSE:PNP.DOWNLOAD:{
if ($sock(PNP.DOWNLOAD).mark) {
if (%_install.filesize > 0) _ppde File received is smaller than expected
var %crcfile = $mircdir $+ %_install.to
if ($crc(%crcfile) != $gettok(%_install.what,2,47)) _ppde File received is corrupted
%_install.set = $gettok(%_install.set,2-,32)
.timer -o 1 0 _ppnextfile
}
else _ppde Connection was interrupted
}
alias -l _ppde {
sockclose PNP.DOWNLOAD
if (%_install.dir) {
_remove.all *.* $mircdir $+ %_install.dir
.rmdir " $+ $mircdir $+ %_install.dir $+ "
}
;;; better errors/restart
echo 4 -s $1-
_ppdclean
halt
}
alias -l _ppdclean {
sockclose PNP.DOWNLOAD
if (%_install.dir) {
_remove.all *.* $mircdir $+ %_install.dir
.rmdir " $+ $mircdir $+ %_install.dir $+ "
}
unset %_install.*
window -c @.install
if ($1) _progress.2 100 Done!
else window -c @Progress
halt
}
alias -l _ppfinishinstall {
var %source = $mircdir $+ %_install.dir
if ($window(@.install).title == dl) {
_progress.2 100 Copying files...
:copy
if ($findfile(%source,*.*,1)) {
var %file1 = $ifmatch,%file2 = %_install.target $+ $nopath($ifmatch)
.copy " $+ %file1 $+ " " $+ %file2 $+ "
.remove " $+ %file1 $+ "
goto copy
}
_ppdclean 1
}
;;; do install version
}
;
; Patch routines
;
; /patch [filename|drivelist]
alias patch {
}