mIRC Home    About    Download    Register    News    Help

Print Thread
update script #52998 08/10/03 10:16 PM
Joined: Dec 2002
Posts: 397
A
ATMA Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: Dec 2002
Posts: 397
how can i make an update script useing sockets like have it find a file and inside the .txt file it says like the new updated files like:
fsetup.mrc
core.mrc
and so on like that and then grab those files and have it connect to
http://www.matrixn3t.net/file/location/filename.mrc
and down load the files


Need amazing web design for low price: http://www.matrixn3t.net
Re: update script #52999 09/10/03 12:12 AM
Joined: Oct 2003
Posts: 8
A
Aazn Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
A
Joined: Oct 2003
Posts: 8
In hope to simplify that and make it easier to read for me, are you saying:

You need a socket script that will check for updates on a file(s) that you have, and if the filesize is differant, it will download and rehash without desturbing you?

If that's what you want, that'll be easier to follow, because I can read my answer easier. I'll try to figure out a way to do the above/


( www.nnscript.de )
Re: update script #53000 09/10/03 01:31 AM
Joined: Dec 2002
Posts: 397
A
ATMA Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: Dec 2002
Posts: 397
yea thats basicly what im going for =p


Need amazing web design for low price: http://www.matrixn3t.net
Re: update script #53001 09/10/03 02:41 AM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
here is a download script i made a while ago that includes signals so you know when the file is complete.. Myabe you can play with it a lil laugh

Code:
; ------------------------------------------------------------------------------------------------------
; usage: $download(<link>)
; --
; properties:
;   .owrite - When specified, if a file already exists with the same name as that of ebign downloaded,
;             it is overwritten.  When not specified, the user will be faces with a popup asking if they
;             would like to overwrite the file.
; ------------------------------------------------------------------------------------------------------
alias download {
  if (!$isid) || (!$1) {
    /echo -s Invalid Usage: $ $+ download(link)[.owrite]
    return
  }
  else {
    var %link = $remove($$1, http://) $+ /
    var %host = $gettok(%link, 1, $asc(/))
    var %get = $iif($left($remove(%link, %host), -1), $ifmatch, /)
    /inc %download.header
    if ($sock(download)) /download.close
    /sockopen download %host 80
    /sockmark download %host %get
    /set %download.info $rand(1,9999) $+ $chr(44) $+ $iif($prop && $prop == owrite, 1, 0)
    return $gettok(%download.info, 1, 44)
  }
}

alias download.close {
  if ($sock(download)) /sockclose download
  /unset %download.*
  if ($isFile(download.dat)) .remove download.dat
}

on 1:SOCKOPEN:download: {
  if ($sockerr) {
    /echo -a Error: Could not connect to $gettok($sock($sockname).mark, 1, 32)
    /download.close
  }
  else {
    /sockwrite -n $sockname GET $gettok($sock($sockname).mark, 2-, 32) HTTP/1.1
    /sockwrite -n $sockname Host: $gettok($sock($sockname).mark, 1, 32)
    /sockwrite -n $sockname $crlf
  }
}

on 1:SOCKREAD:download: {
  /sockread 0f &data
  if (%downlaod.header) {
    var %data = $bvar(&data, 1, 100).text
    if (%data == $null) /unset %download.header
  }
  else {
    /bwrite download.dat -1 -1 &data
  }
}

on 1:SOCKCLOSE:download: {
  var %file = $gettok($nopath($gettok($sock($sockname).mark, 2-, 32)) $+ ?, 1, $asc(?))
  if (%file == $null) %file = index.htm
  var %owrite = $gettok(%download.info, 2, 44)
  /echo -s File: %file
  if ($isFile(%file)) {
    if (%owrite) || ($$?!="Would you like to overwrite the previous file ( $+ %file $+ )?") .remove %file
  }
  .rename download.dat %file
  .signal DOWNLOAD $gettok(%download.info, 1, 44) %file
  /download.close
}

; ------------------------------------------------------------------------------------------------------
; example code
alias dlGoogle {
  /echo -a Downloading File...
  /set %dl.id $download(www.google.com)
}

on *:SIGNAL:DOWNLOAD: {
  var %id = $1, %file = $2
  ; ----------------------
  if (%id == %dl.id) {
    /echo -a File Downloaded ( $+ %file $+ )
    /run %file
  }
}

; EOF
; ------------------------------------------------------------------------------------------------------


-KingTomato
Re: update script #53002 09/10/03 10:40 AM
Joined: Dec 2002
Posts: 397
A
ATMA Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: Dec 2002
Posts: 397
thx im not going to bother with it atm but i will look at it later today the day is saved once again by a tomato?


Need amazing web design for low price: http://www.matrixn3t.net
Re: update script #53003 09/10/03 01:25 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline
Hoopy frood
Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
that failed on a .zip, .jpeg, .bmp and .exe frown


new username: tidy_trax
Re: update script #53004 09/10/03 09:02 PM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
My mistake, I forgot I was playing with http:/1.1 and 1.0 and never put a connection tyoe, as well as had a type on the sockread.

Please do note you can only do one download at a time, and I have tested this.

Code:
; ------------------------------------------------------------------------------------------------------
; usage: $download(<link>)
; --
; properties:
;   .owrite - When specified, if a file already exists with the same name as that of ebign downloaded,
;             it is overwritten.  When not specified, the user will be faces with a popup asking if they
;             would like to overwrite the file.
; ------------------------------------------------------------------------------------------------------
alias download {
  if (!$isid) || (!$1) {
    /echo -s Invalid Usage: $ $+ download(link)[.owrite]
    return
  }
  else {
    var %link = $remove($$1, http://) $+ /
    var %host = $gettok(%link, 1, $asc(/))
    var %get = $iif($left($remove(%link, %host), -1), $ifmatch, /)
    if ($sock(download)) /download.close
    /sockopen download %host 80
    /sockmark download %host %get
    /set %download.info $rand(1,9999) $+ $chr(44) $+ $iif($prop && $prop == owrite, 1, 0) $+ ,1
    return $gettok(%download.info, 1, 44)
  }
}

alias download.close {
  if ($sock(download)) /sockclose download
  /unset %download.*
  if ($isFile(download.dat)) .remove download.dat
}

on 1:SOCKOPEN:download: {
  if ($sockerr) {
    /echo -a Error: Could not connect to $gettok($sock($sockname).mark, 1, 32)
    /download.close
  }
  else {
    /sockwrite -n $sockname GET $gettok($sock($sockname).mark, 2-, 32) HTTP/1.0
    /sockwrite -n $sockname Host: $gettok($sock($sockname).mark, 1, 32)
    /sockwrite -n $sockname $crlf
  }
}

on 1:SOCKREAD:download: {
  var %download.header = $gettok(%download.info, 3, 44)
  if (%download.header) {
    /sockread %data
    if (%data == $null) /set %download.info $puttok(%download.info, 0, 3, 44)
  }
  else {
    /sockread -f &data
    /bwrite download.dat -1 -1 &data
  }
}

on 1:SOCKCLOSE:download: {
  .timerdownload -m 1 250 /download.done $sock($sockname).mark
}

alias download.done {
  var %mark = $1-
  var %file = $gettok($nopath($gettok(%mark, 2-, 32)) $+ ?, 1, $asc(?))
  if (%file == $null) %file = index.htm
  var %owrite = $gettok(%download.info, 2, 44)
  if ($isFile(%file)) {
    if (%owrite) || ($$?!="Would you like to overwrite the previous file ( $+ %file $+ )?") .remove %file
  }
  .rename download.dat %file
  .signal DOWNLOAD $gettok(%download.info, 1, 44) %file
  /download.close
}

; ------------------------------------------------------------------------------------------------------
; example code
alias dlTest {
  /echo -a Downloading File...
  /set %dl.id $download($1-)
}

on *:SIGNAL:DOWNLOAD: {
  var %id = $1, %file = $2-
  ; ----------------------
  if (%id == %dl.id) {
    /echo -a File Downloaded ( $+ %file $+ )
    /run %file
  }
}

; EOF
; ------------------------------------------------------------------------------------------------------


works:

/dlText http://www.google.com
/dlTest http://www.google.com/images/logo.gif
/dlText http://home.ceinetworks.com/~hawk/mirc61.exe

I can only assume the others work, but let me know if they dont.


-KingTomato
Re: update script #53005 09/10/03 09:14 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline
Hoopy frood
Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
ive been looking for a tutorial on auto-updaters or downloaders, but a working example is better ty smile


new username: tidy_trax
Re: update script #53006 09/10/03 09:32 PM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Im working on a version to run multiple file dl's at once atm, if anyone is interested in it--please pm me. I dont feel like spamming the board one more time


-KingTomato
Re: update script #53007 09/10/03 09:43 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline
Hoopy frood
Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
you could just use:
sockopen download. $+ <url>
although im guessing you knew that :tongue:, thats how i'd do it.


new username: tidy_trax
Re: update script #53008 09/10/03 09:50 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
I gotta remember to create a curlmirc.dll one day. Curl is a fantastic tool, it allows you to download multiple files at once and it supports numerous protocols, http (1.0 and 1.1), https, ftp, ftps, gopher, etc.

Re: update script #53009 09/10/03 09:54 PM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
yea, I was fooling wiht making a cURL facsimile one day in mirc--then i got into how much stuff there is and how many protocols to cover--i just said forget it.


-KingTomato
Re: update script #53010 10/10/03 12:08 AM
Joined: May 2003
Posts: 2,265
P
pheonix Offline
Hoopy frood
Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
Code:
alias download {
  if ($isid) || (!$2) { 
    if ($show) { echo -s $+(,$colour(info),*) /download $+ : correct format is /download &lt;url&gt; &lt;directory&gt; }
    return 
  }
  elseif (!$isdir($+(",$remove($2-,"),"))) { 
    if ($input($+(",$remove($2-,"),") directory does not exist $+ $chr(44) do you want to create it?,ohd,error) == $true) { mkdir $+(",$remove($2-,"),") }
  }
  hadd -m $remove($gettok($$1,1,47),http://,www.) path $$2-
  tokenize 47 $remove($$1,http://,www.)
  if ($isfile($+(",$hget($1,path),$ [ $+ [ $0 ] ],"))) &amp;&amp; ($input($ [ $+ [ $0 ] ] exists $+ $chr(44) overwrite?,owd,exists) != $true) { return }
  elseif ($isfile($+(",$remove($ [ $+ [ $0 ] ],"),"))) { .remove $+(",$remove($ [ $+ [ $0 ] ],"),") }
  hadd -m $1 url $1
  hadd -m $1 file $iif($left($ [ $+ [ $0 ] ],1) != /,/) $+ $ [ $+ [ $0 ] ] 
  sockopen download. [ $+ [ $1 ] ] $1 80
}
on *:sockopen:download.*:{
  if ($sockerr) { return }
  tokenize 46 $sockname
  sockwrite -n $sockname GET $hget($replace($2-,$chr(32),$chr(46)),file) HTTP/1.1
  sockwrite -n $sockname Accept: */*
  sockwrite -n $sockname Host: www. [ $+ [ $replace($2-,$chr(32),$chr(46)) ] ]
  sockwrite -n $sockname $crlf
}
on *:sockread:download.*:{
  if ($sockerr) { return }
  tokenize 46 $sockname
  sockread -f &amp;file
  bwrite $+(",$iif($right($hget($replace($2-,$chr(32),$chr(46)),path),1) == \,$hget($replace($2-,$chr(32),$chr(46)),path),$hget($replace($2-,$chr(32),$chr(46)),path) $+ \),dlfile. [ $+ [ $right($hget($replace($2-,$chr(32),$chr(46)),file),-1) $+ .dat ] ],") -1 -1 &amp;file
}
on *:sockclose:download.*:{
  tokenize 46 $sockname
  echo -a $right($hget($replace($2-,$chr(32),$chr(46)),file),-1) finished downloading.
  .rename $+(",$iif($right($hget($replace($2-,$chr(32),$chr(46)),path),1) == \,$hget($replace($2-,$chr(32),$chr(46)),path),$hget($replace($2-,$chr(32),$chr(46)),path) $+ \),dlfile. [ $+ [ $right($hget($replace($2-,$chr(32),$chr(46)),file),-1) $+ .dat ] ],") $+(",$iif($right($hget($replace($2-,$chr(32),$chr(46)),path),1) == \,$hget($replace($2-,$chr(32),$chr(46)),path),$hget($replace($2-,$chr(32),$chr(46)),path) $+ \),$right($hget($replace($2-,$chr(32),$chr(46)),file),-1),")
  if (!$isfile($+(",$hget($replace($2-,$chr(32),$chr(46)),path),$right($hget($replace($2-,$chr(32),$chr(46)),file),-1),"))) { echo -s $+(,$colour(info),*) /download: there was an error in the download. }
  elseif (!$file($+(",$hget($replace($2-,$chr(32),$chr(46)),path),$right($hget($replace($2-,$chr(32),$chr(46)),file),-1),")).size) { 
    echo -s $+(,$colour(info),*) /download: there was an error in the download.
    .remove $+(",$hget($replace($2-,$chr(32),$chr(46)),path),$right($hget($replace($2-,$chr(32),$chr(46)),file),-1),") 
  }
  .hfree $replace($2-,$chr(32),$chr(46))
}


this writes to dlfile.<downloading filename>.dat, but when it renames the file, the data is lost, do you know why frown?


new username: tidy_trax
Re: update script #53011 10/10/03 01:20 AM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
eww, sloppy. A hash table for each download? hmm I got mine working, so maybe you can look at it and see what's going on?

Code:
; ------------------------------------------------------------------------------------------------------
; usage: $download(&lt;link&gt;, option)
; --
; Options:
;   Excluded or run [Default Option]
;     Will download and run program apon completion of download
;   norun
;     Will not run the program after download completion
;   opendir
;     Will open the mirc directory to which i was downloaded to apon completion
;
; Properties:
;   .owrite - When specified, if a file already exists with the same name as that of ebign downloaded,
;             it is overwritten.  When not specified, the user will be faces with a popup asking if they
;             would like to overwrite the file.
; ------------------------------------------------------------------------------------------------------
alias download {
  if (!$isid) || (!$1) {
    /echo -s Invalid Usage: $ $+ download(link, option)[.owrite]
    /echo -s Options:
    /echo -s  $null   - [Default Option] Will download and run program apon completion of download
    /echo -s  norun   - Will not run the program after download completion
    /echo -s  opendir - Will open the mirc directory to which i was downloaded to apon completion
    return
  }
  else {
    var %link = $remove($$1, http://) $+ /
    var %host = $gettok(%link, 1, $asc(/))
    var %get = $iif($left($remove(%link, %host), -1), $ifmatch, /)
    if ($sock(download)) /download.close
    var %download.info $+($rand(1,9999),$chr(44),$iif($prop &amp;&amp; $prop == owrite, 1, 0),$chr(44),1,$chr(44),$iif($2, $2, run))
    var %id = $gettok(%download.info, 1, 44)
    /sockopen download $+ %id %host 80
    /sockmark download $+ %id %host %get
    /set %download. [ $+ [ %id ] ] %download.info
    return %id
  }
}

alias download.close {
  if ($sock(download $+ $1)) /sockclose download $+ $1
  /unset %download. $+ $1
  if ($isFile(download $+ $1 $+ .dat)) .remove download $+ $$1 $+ .dat
}

on 1:SOCKOPEN:download*: {
  var %id = $remove($sockname, download)
  if ($sockerr) {
    /echo -a Error: Could not connect to $gettok($sock($sockname).mark, 1, 32)
    .signal download %id $false Could not connect to host " $+ $gettok($sock($sockname).mark, 1, 32) $+ "
    /download.close %id
  }
  else {
    /sockwrite -n $sockname GET $gettok($sock($sockname).mark, 2-, 32) HTTP/1.0
    /sockwrite -n $sockname Host: $gettok($sock($sockname).mark, 1, 32)
    /sockwrite -n $sockname $crlf
  }
}

on 1:SOCKREAD:download*: {
  var %id = $remove($sockname, download)
  var %download.header = $gettok(%download. [ $+ [ %id ] ], 3, 44)
  if (%download.header) {
    /sockread %data
    if (%data == $null) /set %download. $+ %id $puttok(%download.info, 0, 3, 44)
  }
  else {
    /sockread -f &amp;data
    /bwrite download $+ %id $+ .dat -1 -1 &amp;data
  }
}

on 1:SOCKCLOSE:download*: {
  var %id = $remove($sockname, download)
  .timerdownload -m 1 250 /download.done %id $sock($sockname).mark
}

alias download.done {
  var %id = $1, %mark = $2-
  var %file = $gettok($nopath($gettok(%mark, 2-, 32)) $+ ?, 1, $asc(?))
  if (%file == $null) %file = index.htm
  var %owrite = $gettok(%download. [ $+ [ %id ] ], 2, 44)

  if ($isFile(download $+ %id $+ .dat)) {
    if ($isFile(%file)) {
      if (%owrite) || ($$?!="Would you like to overwrite the previous file ( $+ %file $+ )?") .remove %file
    }
    .rename download $+ %id $+ .dat %file
    .signal DOWNLOAD %id $true %file

    var %option = $gettok(%download. [ $+ [ %id ] ], 4, 44)
    else if (%option == opendir) /run .
    else if (%option != norun) /run %file
  }
  else .signal download %id $false Could not find downloaded file "download $+ %id $+ .dat"

  /download.close %id
}

; ------------------------------------------------------------------------------------------------------
; example code
alias dlTest {
  /inc %files
  /echo -a Downloading File... (With opendir option)
  /set %dl.id $download($1-, opendir).owrite
}

on *:SIGNAL:DOWNLOAD: {
  var %id = $1, %sOK = $2
  if (%sOK) var %file = $3-
  else var %error = $3-
  ; ----------------------
  if (%id == %dl.id) {
    if (%sOk) /echo -a File Downloaded ( $+ %file $+ )
    else /echo -a Error Occured! ( $+ %error $+ )
  }
}

; EOF
; ------------------------------------------------------------------------------------------------------


Few additions:

/dlText <path> to run a demonstration download. It is called as an ID, and passed back a numeric value identifying that file. From there, a download.<id>.dat file is created (less the header information). Once the download has completed, the file is saved as its name from the path (Defaults to paths like www.somesite.com/ with no name) On completion, the signal "download" is called with three parameters.

.signal download <id> <sok> <info>
id - the id of the download that was either completed, or performed an error
sOk - states if the download was successful (returns tru on success, and false on fail)
info - depending on an sok value of true or false, this could be either the filename of the downloaded file, or the error message that occured respectivly.

I also added an option prperty to the $download call as the second parameter ($download(path, option)) The option can be any of the following settings:

If the option parameter is excluded or is filled with run, it will execute the just-downloaded program on completition.
If the option is filled with norun, the file will not be executed when the download is complete
If the option opendir is included, the mirc directory to which it was downloaded will open apon completion.

Hope that helps you, and homefully others. the idea is basically you can do somethign like the following:

Code:
alias versionCheck {
  /set %verFile $download(http://mywebsite.com/vers.txt, noopen)
}

on *:SIGNAL:DOWNLOAD: {
  var %id = $1, %sOK = $2, %file = $3-
  if (%id == %verFile) {
    if (%sOK) {
      var %content = $read(%file, 1)
      if (%content = %vers) var %a = $input(No new versions are currently available for download, o)
      else var %a = $input(A new version has become available for download!, o)
    }
    else var %a = $input(An error occured while checking the verion: $crlf %file, o)
  }
}


Assuming vers.txt on ur website contained just one line, and that was the version--this would work


-KingTomato