; Filefinder for mIRC
; Description	: Taken from Basic script. It allows you to find files.
; Usage 	: Can be done via menubar or by typing /find <keyword>
; Requirements	: mIRC v5.61 or higher.
; Author	: blue-elf
; Email 	: belf@null.net

menu menubar {
  Find...:find
}
alias find {
  if ($1-) set %.lostfile $1-
  dialog -dm ffind ffind
}
dialog ffind {
  size -3 -3 300 70
  title "Find"
  button "",1, 1 1 1 1, cancel hide
  text "Filename:", 2, 5 15 50 14
  text "Find in:", 3, 5 38 50 14
  combo 4, 55 10 160 200, drop edit autohs autovs
  edit "",5, 55 35 160 22, drop sort autovs
  button "&Find", 6, 220 8 75 22, default
  button "&Browse", 7, 220 33 75 22
  list 8, 5 90 290 117, sort hsbar vsbar
  text "Found:", 9, 5 70 300 14
  button "&Open selected", 10, 5 200 90 22
  button "Open &with...", 11, 100 200 90 22
  button "View in &notepad",12, 195 200 90 22
}
on *:dialog:ffind:init:*:{
  if ((%.lostfile) && ($isrecf(%.lostfile) == $false)) addrecf %.lostfile
  var %x = 0, %o = $_recf
  :loop
  inc %x
  if ($gettok(%o,%x,32)) {
    did -a $dname 4 $ifmatch
    if ($ifmatch == %.lostfile) did -c $dname 4 %x
    goto loop
  }
  did -a $dname 5 $left($mircdir,3)
}
on *:dialog:ffind:sclick:1:unset %.lostfile
on *:dialog:ffind:sclick:6:{
  set -u %.lostfile $did(4)
  if (%.lostfile) {
    did -o $dname 9 1 Searching for %.lostfile ... please wait.
    if ($isrecf(%.lostfile) == $false) addrecf %.lostfile
    did -r $dname 8
    dialog -s $dname $cwin(300,230) 300 230
    set -u %tmp_path $iif($did(5),$did(5),$left($mircdir,3))
    window -hl @find_it
    if ((* !isin %.lostfile) && (. !isin %.lostfile)) %.lostfile = * $+ %.lostfile $+ *
    set -u %.ffind $findfile(%tmp_path,%.lostfile,@find_it)
    set -u %.ffind $finddir(%tmp_path,%.lostfile,@find_it) 
    if ($line(@find_it,0)) {
      filter -wo @find_it $dname 8 *
      did -o $dname 9 1 Found: $line(@find_it,0) file(s) - Double click to open.
    }
    else did -o $dname 9 1 Found: 0 files
    .timer 1 0 window -c @find_it $chr(124) did -z $dname 8
  }
}
on *:dialog:ffind:sclick:7:.timer 1 0 _fsdir
on *:dialog:ffind:dclick:8:_ffind runfile
on *:dialog:ffind:sclick:10:_ffind runfile
on *:dialog:ffind:sclick:11:_ffind runfile2
on *:dialog:ffind:sclick:12:_ffind runfile3
alias -l _ffind {
  if ($did(ffind,8,$did(ffind,8).sel)) .timer 1 0 $1 $ifmatch
  dialog -v ffind
}
alias -l isrecf return $istok($_recf,$1,32)
alias -l _recf return %recent.findfile
alias -l addrecf if ($len($_recf) < 900) set %recent.findfile $addtok($_recf,$1-,32)
alias -l runfile {
  if (((*.exe iswm $1-) || (*.com iswm $1-) || (*.bat iswm $1-)) && ($?!=" $rmsg($1-) " == $false)) {
    dialog -v ffind
    halt
  }
  run $lfnfix($1-)
}
alias -l runfile2 {
  if ($_isfile($1-)) {
    var %.2view = $ifmatch
    var %.sel.exe = $dir="Select an application to open $nopath($remove(%.2view,")) " \*.exe
    if ($_isfile(%.sel.exe)) run $ifmatch %.2view
  }
  dialog -v ffind
}
alias -l runfile3 if ($_isfile($1-)) run notepad $ifmatch
alias -l rmsg return WARNING: $crlf This is a $_ext($1-) file. Running this could be dangerous! Are you sure you want to run this?
alias -l _ext return . $+ $upper($gettok($1-,$numtok($1-,46),46))
alias -l lfnfix {
  if (" isin $1-) return $1-
  if ($chr(32) isin $1-) return " $+ $1- $+ "
  return $1-
}
alias -l _isdir if (($exists($1)) && ($isdir($1))) return $lfnfix($1)
alias -l _isfile if (($exists($1)) && ($isfile($1))) return $lfnfix($1)
alias -l cwin return $int($calc(( [ $window(-1).w ] - $1) / 2)) $int($calc(( [ $window(-1).h ] - $2) / 2))
alias _fsdir {
  var %.fd = $sdir="Select starting directory"
  if (%.fd) did -o ffind 5 1 $ifmatch
  dialog -v ffind
}
on *:start:unset %recent.findfile
on *:load:{
  if ($version < 5.61) {
    echo 4 -a *** Unable to load find.mrc This requires mIRC v5.61 or later.
    unload -rs $script
    halt
  }
}
; EOF

