Jump to content

Updater


XaVeR

Recommended Posts

alias [uPDATE_ALIAS] {
 if (!$sock([uPDATE_ALIAS])) {
   var %a = $findfile($mircdir,*.tmp,0,1,!.remove " $+ $1-")
   mta.log $dialog(mta).tab * Updater: Checking for [YOUR_SCRIPT_NAME] updates...
   !sockclose [uPDATE_ALIAS]
   !sockopen [uPDATE_ALIAS] [YOUR_HOST] 80
 }
}
dialog -l [uPDATE_ALIAS] {
 title "[YOUR_SCRIPT_NAME] Updater"
 size -1 -1 94 98
 option dbu
 icon [YOUR_SCRIPT_ICON], 0
 button "Yes", 1, 8 84 37 12
 button "No", 2, 52 84 37 12, ok
 edit "", 3, 2 2 90 54, multi return vsbar
 text "Status:", 4, 2 58 19 8
 text "", 5, 22 58 69 14
 box "", 6, 2 70 90 11
 text "", 7, 4 74 86 5
}
on *:sockopen:[uPDATE_ALIAS]: {
 if (!$sockerr) !sockwrite -n [uPDATE_ALIAS] GET [YOUR_FILES_DIRECTORY][YOUR_UPDATE_FILE] $+(HTTP/1.1,$crlf,Host: [YOUR_HOST],$crlf,Connection: Close,$crlf,$crlf)
 elseif ($dialog(mta)) mta.log $dialog(mta).tab * Updater: Connection problems.
}
on *:sockread:[uPDATE_ALIAS]:{ 
 !sockread &a
 while ($sockbr != 0) {
   !bwrite [YOUR_TEMPORARY_FILE] -1 &a
   !sockread &a
 }
}
on *:sockclose:[uPDATE_ALIAS]:{ 
 if ($dialog(mta)) && (!$dialog([uPDATE_ALIAS])) {
   !bread [YOUR_TEMPORARY_FILE] 1 $file([YOUR_TEMPORARY_FILE]).size &a
   !bcopy -c &a 1 &a $calc($bfind(&a,1,10 13 10)+3) -1
   !.remove [YOUR_TEMPORARY_FILE]
   !bwrite [YOUR_TEMPORARY_FILE] 0 &a
   var %a = $read([YOUR_TEMPORARY_FILE],2)
   if (%a !isnum) {
     !.remove [YOUR_TEMPORARY_FILE]
     mta.log $dialog(mta).tab * Updater: Invalid update file.
   }
   elseif ([YOUR_SCRIPT_VERSION_ALIAS] < %a) {
     mta.log $dialog(mta).tab * Updater: Version %a available.
     !dialog -v mta
     !dialog -ma [uPDATE_ALIAS] [uPDATE_ALIAS]
     !did -m [uPDATE_ALIAS] 3
     !did -a [uPDATE_ALIAS] 5 Download version %a $+ ?
     !loadbuf -o [uPDATE_ALIAS] 3 [YOUR_TEMPORARY_FILE]
   }
   else {
     !.remove [YOUR_TEMPORARY_FILE]
     mta.log $dialog(mta).tab * Updater: No updates.
   }
 }
}
on *:sockopen:[DOWNLOAD_ALIAS]:{
 if ($sockerr == 0) {
   !tokenize 32 $read([YOUR_TEMPORARY_FILE],$sock([DOWNLOAD_ALIAS]).mark)
   if ($1 == Fixes:) {
     !did -a [uPDATE_ALIAS] 5 Finished.
     !did -ea [uPDATE_ALIAS] 1 Install
   }
   else {
     !did -a [uPDATE_ALIAS] 5 Downloading " $+ $1"
     !did -r [uPDATE_ALIAS] 7
     !sockwrite -n [DOWNLOAD_ALIAS] GET [YOUR_FILES_DIRECTORY] $+ $1 $+(HTTP/1.1,$crlf,Host: [YOUR_HOST],$crlf,Connection: Close,$crlf,$crlf)
   }
 }
 else {
   !did -a [uPDATE_ALIAS] 5 Connection error.
   !did -a [uPDATE_ALIAS] 2 Close
 }
}
on *:sockread:[DOWNLOAD_ALIAS]:{ 
 !tokenize 32 $read([YOUR_TEMPORARY_FILE],$sock([DOWNLOAD_ALIAS]).mark)
 !sockread -f &a
 while ($sockbr != 0) {
   !did -a [uPDATE_ALIAS] 7 $str(l,$calc(86/ $2 * $sock([DOWNLOAD_ALIAS]).rcvd))
   !bwrite $1.tmp -1 &a
   !sockread -f &a
 }
}
on *:sockclose:[DOWNLOAD_ALIAS]:{
 !tokenize 32 $read([YOUR_TEMPORARY_FILE],$sock([DOWNLOAD_ALIAS]).mark)
 !bread $1.tmp 1 $file($1.tmp).size &a
 !bcopy -c &a 1 &a $calc($bfind(&a,1,10 13 10)+3) -1
 !.remove $1.tmp
 !bwrite $1.tmp 0 &a
 if ($crc($1.tmp) != $3) {
   !did -a [uPDATE_ALIAS] 5 CRC mismatch on " $+ $1"
   !did -a [uPDATE_ALIAS] 2 Close
 }
 else !.timer 1 0 [DOWNLOAD_ALIAS] $calc(1+$sock([DOWNLOAD_ALIAS]).mark)
}
alias [DOWNLOAD_ALIAS] {
 !sockopen [DOWNLOAD_ALIAS] [YOUR_HOST] 80
 !sockmark [DOWNLOAD_ALIAS] $1
}
on *:DIALOG:[uPDATE_ALIAS]:close:0:!sockclose [DOWNLOAD_ALIAS] $findfile($mircdir,*.tmp,0,1,!.remove " $+ $1-")
on *:DIALOG:[uPDATE_ALIAS]:sclick:1:{
 if (Yes == $did([uPDATE_ALIAS],1)) {
   !did -a [uPDATE_ALIAS] 5 Connecting...
   !did -b [uPDATE_ALIAS] 1
   !did -a [uPDATE_ALIAS] 2 Cancel
   !sockclose [DOWNLOAD_ALIAS]
   [DOWNLOAD_ALIAS] 4
 }
 if (Install == $did([uPDATE_ALIAS],1)) {
   !did -a [uPDATE_ALIAS] 5 Installing...
   !dll -u [DOWNLOAD_ALIAS]l
   var %a = 4
   while ($read([YOUR_TEMPORARY_FILE],%a) != Fixes:) {
     !tokenize 32 $read([YOUR_TEMPORARY_FILE],%a)
     !.copy -o $1.tmp $+(",$scriptdir,$1")
     !inc %a
   }
   [YOUR_SCRIPT_SHUTDOWN_ALIAS]
   !.load -rs $+(",[YOUR_MAIN_SCRIPT],")
 }
}

Replace all the [...] then create a [YOUR_UPDATE_FILE] with in:

Version:
[VERSION]
File / Size (bytes) / CRC32:
[FILE_NAME] [FILE_SIZES_IN_BYTES] [FILE_CRC32]
[FILE_NAME] [FILE_SIZES_IN_BYTES] [FILE_CRC32]
Fixes:
[FIXES]
[FIXES]
Comments:
[COMMENTS]
[COMMENTS]

If you dont understand this, or mIRC scripting at all. Please don't even try to get support on this code.

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...