Jump to content

/monitorfile


tidy trax

Recommended Posts

There isn't a section for just mIRC snippets/addons so i'll post this here.

 

This snippet will monitor files for changes and tell you when they're changed or deleted.

 

Note: this snippet will only work on mIRC 6.16, if you want to use it in older versions of mIRC then you can simply change '$v1' to '$ifmatch' on line 52.

 

/*

What does /monitorfile do?

/monitorfile will watch a file and tell you when the file is modified or deleted, it will send a 'monitorfile' signal with either 
'FILE_DELETE' or 'FILE_CHANGE' as the first parameter followed by the file that was being watched.
If you don't use a . with the /monitorfile command (/.monitorfile) then you will also see some information in the active window when files
are changed or deleted.
All error/information messages should replicate mIRCs own messages.
/monitorfile uses a 5 second interval to check for changes in files.

How do I use /monitorfile?

The syntax is: /monitorfile [off] <file>
If you specify [off] then the specified file will no longer be monitored.
Otherwise, the specified file will start being monitored.

How does /monitorfile work? (For scripters)

/monitorfile will store the crc value of a file when you start monitoring a file and check the current crc value against the stored one 
every 5 seconds.
If the value doesn't match then the FILE_CHANGE signal will be sent and the new crc value will be stored.
If the file no longer exists when /monitorfile goes to check the current crc value then the FIlE_DELETE signal will be sent and the timer
will be stopped. 

Can you give me an example of using this?

on *:start:{ .monitorfile $mircini }
on *:signal:monitorfile:{
 if ($1 == FILE_CHANGE) && ($2- == $mircini) { echo $color(info) -afilr Hi $+($me,!) mIRC will just revert all changes to mirc.ini so $&
   there's no point in changing it unless you used the options dialog. :) }
}

How can I contact you?

You can email me at [email protected] or [email protected]
You can also find me in #mIRC or #mirc.net on IRC at irc.undernet.org but I am not always there.

*/

alias checkfile {
 if (!$isfile($1-)) {
   .signal -n monitorfile FILE_DELETE $1-
   hdel monitorfile $replace($1-,$chr(32),\s)
   if (!$hget(monitorfile,0).item) { hfree monitorfile }
   $+(.timermonitorfile,$replace($1-,$chr(32),\s)) off
   echo $color(info) -afilqr * /monitorfile: No longer monitoring $+(',$1-') for changes (File was deleted).
   linesep -a
   return
 }
 if ($crc($1-) != $hget(monitorfile,$replace($1-,$chr(32),\s))) {
   hadd -m monitorfile $replace($1-,$chr(32),\s) $v1
   .signal -n monitorfile FILE_CHANGE $1-
   echo $color(info) -afilqr * /monitorfile: File $+(',$1-') has changed. 
   linesep -a
 }
}
alias monitorfile {
 if ($1 == off) && ($hget(monitorfile,$replace($2-,$chr(32),\s))) {
   hdel monitorfile $replace($2-,$chr(32),\s)
   if (!$hget(monitorfile,0).item) { hfree monitorfile }
   $+(.timermonitorfile,$replace($2-,$chr(32),\s)) off
   echo $color(info) -afilqr * /monitorfile: No longer monitoring $+(',$1-') for changes (Stopped by user).
   linesep -a
   return
 }
 if (!$isfile($1-)) {
   if (!$line($active,0)) { linesep -a }
   echo $color(info) -abfilr * /monitorfile: No such file $+(',$1-')
   linesep -a
   return
 }
 hadd -m monitorfile $replace($1-,$chr(32),\s) $crc($1-)
 $+(.timermonitorfile,$replace($1-,$chr(32),\s)) 0 5 $+($iif(!$show,.),checkfile) $1-
 echo $color(info) -afilqr * /monitorfile: Now monitoring $+(',$1-') for changes. 
}

Link to comment
Share on other sites

Updated:

 

/*

What does /monitorfile do?

/monitorfile will watch a file and tell you when the file is modified or deleted, it will send a 'monitorfile' signal with either 
'FILE_DELETE' or 'FILE_CHANGE' as the first parameter followed by the file that was being watched.
If you don't use a . with the /monitorfile command (/.monitorfile) then you will also see some information in the active window when files
are changed or deleted.
All error/information messages should replicate mIRCs own messages.
/monitorfile uses a 5 second interval to check for changes in files.

How do I use /monitorfile?

The syntax is: /monitorfile [-l|-s] <file>
If you specify -l then the files matching the wildcard string in <file> will be listed.
If you specify -s then the files matching the wildcard string in <file> will stop being monitored.
Otherwise, the specified file will start being monitored.

How do I use $monitorfile?

The syntax is: $monitorfile(<file>,<N>)
This identifier will return the Nth monitored file matching the wildcard string in <file>, if you specify 0 as <N> then the amount of
matching files will be returned.

How does /monitorfile work? (For scripters)

/monitorfile will store the crc value of a file when you start monitoring a file and check the current crc value against the stored one 
every 5 seconds.
If the value doesn't match then the FILE_CHANGE signal will be sent and the new crc value will be stored.
If the file no longer exists when /monitorfile goes to check the current crc value then the FIlE_DELETE signal will be sent and the timer
will be stopped. 

Can you give me an example of using this?

on *:start:{ .monitorfile $mircini }
on *:signal:monitorfile:{
 if ($1 == FILE_CHANGE) && ($2- == $mircini) { echo $color(info) -afilr Hi $+($me,!) mIRC will just revert all changes to mirc.ini so $&
   there's no point in changing it unless you used the options dialog. :) }
}

How can I contact you?

You can email me at [email protected] or [email protected]
You can also find me in #mIRC or #mirc.net on IRC at irc.undernet.org but I am not always there.

*/

alias checkfile {
 if (!$isfile($1-)) {
   .signal -n monitorfile FILE_DELETE $1-
   hdel monitorfile $replace($1-,$chr(32),\s)
   if (!$hget(monitorfile,0).item) { hfree monitorfile }
   $+(.timermonitorfile,$replace($1-,$chr(32),\s)) off
   if (!$line($active,0)) { linesep -a }
   echo $color(info) -afilqr * /monitorfile: No longer monitoring $+(',$1-') for changes (File was deleted).
   linesep -a
   return
 }
 if ($crc($1-) != $hget(monitorfile,$replace($1-,$chr(32),\s))) {
   hadd -m monitorfile $replace($1-,$chr(32),\s) $v1
   .signal -n monitorfile FILE_CHANGE $1-
   if (!$line($active,0)) { linesep -a }
   echo $color(info) -afilqr * /monitorfile: File $+(',$1-') has changed. 
   linesep -a
 }
}
alias monitorfile {
 if (!$isid) {
   if ($istok(-l -s,$1,32)) {
     var %i = 1
     if ($1 == -l) {  
       if ($2 == $null) { tokenize 32 -l * }
       if (!$line($active,0)) { linesep -a }
       echo $color(info) -afilr * Monitoring files:
     }
     tokenize 32 $1 $replace($2,$chr(32),\s)
     while ($hfind(monitorfile,$2,%i,w)) {
       if ($1 == -s) { 
         if (!$line($active,0)) { linesep -a }
         echo $color(info) -afilqr * /monitorfile: No longer monitoring $+(',$replace($hfind(monitorfile,$2,%i,w),\s,$chr(32)),') $&
           for changes (Stopped by user).
         linesep -a
         $+(.timermonitorfile,$hfind(monitorfile,$2,%i,w)) off
         hdel monitorfile $hfind(monitorfile,$2,%i,w)
       }
       else { echo $color(info) -afilr * $hfind(monitorfile,$2,%i,w) }
       inc %i
     }
     if (!$hget(monitorfile,0).item) { hfree monitorfile }
     linesep -a
     return
   }
   if (!$isfile($1-)) {
     if (!$line($active,0)) { linesep -a }
     echo $color(info) -abfilr * /monitorfile: No such file $+(',$1-')
     linesep -a
     return
   }
   hadd -m monitorfile $replace($1-,$chr(32),\s) $crc($1-)
   $+(.timermonitorfile,$replace($1-,$chr(32),\s)) 0 5 $+($iif(!$show,.),checkfile) $1-
   if (!$line($active,0)) { linesep -a }
   echo $color(info) -afilqr * /monitorfile: Now monitoring $+(',$1-') for changes. 
   linesep -a
 }
 else { return $hfind(monitorfile,$1,$iif($2 != $null,$v1,1),w) }
}

Link to comment
Share on other sites

Updated again:

 

/*

What does /monitorfile do?

/monitorfile will watch a file and tell you when the file is modified or deleted, it will send a 'monitorfile' signal with either 
'FILE_DELETE' or 'FILE_CHANGE' as the first parameter followed by the file that was being watched.
If you don't use a . with the /monitorfile command (/.monitorfile) then you will also see some information in the active window when files
are changed or deleted.
All error/information messages should replicate mIRCs own messages.
/monitorfile uses a 5 second interval to check for changes in files.

How do I use /monitorfile?

The syntax is: /monitorfile [-l|-s] <file>
If you specify -l then the files matching the wildcard string in <file> will be listed.
If you specify -s then the files matching the wildcard string in <file> will stop being monitored.
Otherwise, the specified file will start being monitored.

How do I use $monitorfile?

The syntax is: $monitorfile(<file>,<N>)
This identifier will return the Nth monitored file matching the wildcard string in <file>, if you specify 0 as <N> then the amount of
matching files will be returned.

How does /monitorfile work? (For scripters)

/monitorfile will store the crc value of a file when you start monitoring a file and check the current crc value against the stored one 
every 5 seconds.
If the value doesn't match then the FILE_CHANGE signal will be sent and the new crc value will be stored.
If the file no longer exists when /monitorfile goes to check the current crc value then the FIlE_DELETE signal will be sent and the timer
will be stopped. 

Can you give me an example of using this?

on *:start:{ .monitorfile $mircini }
on *:signal:monitorfile:{
 if ($1 == FILE_CHANGE) && ($2- == $mircini) { echo $color(info) -afilr Hi $+($me,!) mIRC will just revert all changes to mirc.ini so $&
   there's no point in changing it unless you used the options dialog. :) }
}

How can I contact you?

You can email me at [email protected] or [email protected]
You can also find me in #mIRC or #mirc.net on IRC at irc.undernet.org but I am not always there.

Have you made any changes to this snippet since it was first made?

v2:
Added -s and -l switches.

v3:
Fixed -s not stopping all matching files from being monitored.
Fixed hfree bug when table didn't exist.
Now uses '<' to replace spaces instead of '\s'

*/

alias checkfile {
 if (!$isfile($1-)) {
   .signal -n monitorfile FILE_DELETE $1-
   if ($hget(monitorfile)) {
     hdel monitorfile $replace($1-,$chr(32),<)
     if (!$hget(monitorfile,0).item) { hfree monitorfile }
   }
   $+(.timermonitorfile,$replace($1-,$chr(32),<)) off
   if (!$line($active,0)) { linesep -a }
   echo $color(info) -afilqr * /monitorfile: No longer monitoring $+(',$1-') for changes (File was deleted).
   linesep -a
   return
 }
 if ($crc($1-) != $hget(monitorfile,$replace($1-,$chr(32),<))) {
   hadd -m monitorfile $replace($1-,$chr(32),<) $v1
   .signal -n monitorfile FILE_CHANGE $1-
   if (!$line($active,0)) { linesep -a }
   echo $color(info) -afilqr * /monitorfile: File $+(',$1-') has changed. 
   linesep -a
 }
}
alias monitorfile {
 if (!$isid) {
   if ($istok(-l -s,$1,32)) {
     if ($hget(monitorfile)) {
       var %i = 1
       tokenize 32 $1 $replace($2,$chr(32),<)
       if ($1 == -s) {
         while ($hfind(monitorfile,$2,1,w)) {
           echo $color(info) -afilqr * /monitorfile: No longer monitoring $+(',$replace($hfind(monitorfile,$2,1,w),<,$chr(32)),') $&
             for changes (Stopped by user).
           linesep -a
           $+(.timermonitorfile,$hfind(monitorfile,$2,1,w)) off
           hdel monitorfile $hfind(monitorfile,$2,1,w)
         }
       }
       else {
         if ($2 == $null) { tokenize 32 -l * }
         if (!$line($active,0)) { linesep -a }
         echo $color(info) -afilr * Monitoring files:
         var %i = 1 
         while ($hfind(monitorfile,$2,%i,w)) {
           echo $color(info2) -afilr $hfind(monitorfile,$2,%i,w)
           inc %i
         }
       }
       if (!$hget(monitorfile,0).item) { hfree monitorfile }
       linesep -a
     }
     return
   }
   if (!$isfile($1-)) {
     if (!$line($active,0)) { linesep -a }
     echo $color(info) -abfilr * /monitorfile: No such file $+(',$1-')
     linesep -a
     return
   }
   hadd -m monitorfile $replace($1-,$chr(32),<) $crc($1-)
   $+(.timermonitorfile,$replace($1-,$chr(32),<)) 0 5 $+($iif(!$show,.),checkfile) $1-
   if (!$line($active,0)) { linesep -a }
   echo $color(info) -afilqr * /monitorfile: Now monitoring $+(',$1-') for changes. 
   linesep -a
 }
 else { return $hfind(monitorfile,$1,$iif($2 != $null,$v1,1),w) }
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...