Najeebsk

Everything.ahk

Feb 24th, 2023 (edited)
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ____________________________________________
  2. ; \____ NajeebSK - EverythingFindStrGui _____/
  3.  
  4. ; Coded by Najeeb Shah Khan .                              Last Edit:- 02/25/2023
  5.  
  6. ; Based on "Everything FindStr 1.41" by NSK
  7.  
  8. ; Frontend for "Everything" search engine and "FindStr" (finds strings of text in files) apps.
  9.  
  10. ; Everything/Es:  http://www.voidtools.com/
  11. ; Download page:  http://www.voidtools.com/download.php
  12. ; Direct download:
  13. ;     Everything: http://www.voidtools.com/Everything-1.2.1.371.exe
  14. ;     Es:         http://www.voidtools.com/es.exe
  15.  
  16. ; FindStr:        C:\Windows\system32
  17.  
  18.  
  19. #SingleInstance Force
  20. SetBatchLines -1
  21. SetWorkingDir %A_ScriptDir%
  22. FileCreateDir,%A_ScriptDir%\Everything
  23. FileInstall , Everything.ahk, %A_ScriptDir%\Everything.ahk, 1
  24. FileInstall , Everything\Everything.exe, %A_ScriptDir%\Everything\Everything.exe, 1
  25. FileInstall , Everything\cli.c, %A_ScriptDir%\Everything\cli.c, 1
  26. FileInstall , Everything\es.exe, %A_ScriptDir%\Everything\es.exe, 1
  27. FileInstall , Everything\Everything.lng, %A_ScriptDir%\Everything\Everything.lng, 1
  28. FileInstall , Everything\findstr.exe, %A_ScriptDir%\Everything\findstr.exe, 1
  29. FileSetAttrib +HS, %A_ScriptDir%\Everything, 2
  30. FileSetAttrib +HS, %A_ScriptDir%\Everything.ahk, 2
  31. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  32. If !A_IsAdmin
  33. {
  34.    DllCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str, A_AhkPath
  35.       , str, """" . A_ScriptFullPath . """", str, A_WorkingDir, int, 1)
  36.    ExitApp
  37.    }
  38.  
  39. DriveGet allDrives, list, fixed                                      ; Get drive list
  40. Loop Parse, allDrives                                                ; Extract all NTFS drives
  41. {
  42.    l := A_LoopField
  43.    DriveGet thisDrive, FS, %l%:
  44.    If thisDrive = ntfs
  45.    {
  46.       If !firstDrive                                                 ; First drive found (usually C:)
  47.          firstDrive := l
  48.       ntfsDrives = %ntfsDrives%  %l%
  49.       }
  50.    }
  51.  
  52. app_name          = NajeebSK - EverythingFindStrGui
  53. driveShow         = Available NTFS drives: %ntfsDrives%
  54. GUI_name          = %app_name% - %driveShow%
  55.  
  56. helpFile          = Operators.txt
  57. result_filename   = output_everything.txt
  58. result_filename2  = output_findstr.txt
  59. iniPath           = %app_name%.ini
  60.  
  61. progNameSB        = %app_name% - Select a file then click status bar to copy full path.
  62. sbDisplay         = Select a file then click status bar to copy full path.
  63.  
  64. fileSearchStrings = *.mp3|*.wma¦*.jpg|*.jpeg|*.gif|*.png¦*.ahk
  65.  
  66. Gosub cfgLoad
  67.  
  68. If savedFileSearchQuery = ERROR
  69.    savedFileSearchQuery=
  70. If savedStringSearchQuery = ERROR
  71.    savedStringSearchQuery=
  72.  
  73. guiNewChoice      = %guiChoice%
  74. esSortPath        = %esSortByPath%
  75.  
  76. Gosub exeCheck
  77.  
  78. If !appNotFound
  79.    Run %everything_app%,, hide, everythingPID
  80.  
  81. Gosub doGui
  82.  
  83. ;OnMessage(0x200, "WM_MOUSEMOVE")
  84. Return
  85.  
  86. exeCheck:
  87. IfNotExist %A_ScriptDir%\Everything\Everything.exe
  88.    appNotFound = Everything: %A_ScriptDir%\Everything\Everything.exe`n
  89. IfNotExist %A_ScriptDir%\Everything\es.exe
  90.    appNotFound = %appNotfound%Es: %A_ScriptDir%\Everything\es.exe`n
  91. IfNotExist %A_ScriptDir%\Everything\findstr.exe
  92.    appNotFound = %appNotFound%FindStr: %A_ScriptDir%\Everything\findstr.exe
  93. If appNotFound
  94.    MsgBox The following`n`n%appNotFound%`n`nare needed for this program to work and they cannot be found in their default installation location. Please check that you have them installed then set the paths in this programs Options.
  95. Return
  96.  
  97. doGui:
  98. If guiNewChoice = 0
  99.    Gosub Gui1
  100. Else
  101.    Gosub Gui2
  102. winID := WinExist("A")
  103. GuiControl focus, command_search
  104. Gosub loadOptions
  105. Sleep 500
  106. WinActivate ahk_ID %winID%
  107. Return
  108.  
  109. ; ****************** WIDE GUI ******************
  110. Gui1:
  111. Gui 1:Margin, 5, 5
  112. Gui 1:+MinSize  +LastFound
  113. Gui 1:+Delimiter¦                                                 ; Pipe is used in searches, use alernate field separator.
  114.  
  115. Gui 1:Add, GroupBox, x5 y10 w390 h80 section, Find File
  116. Gui 1:Add, CheckBox, xs+10 ys+25 vesWW gesOptions, Whole Word
  117. Gui 1:Add, CheckBox, x+5 vesCase gesOptions, Case
  118. Gui 1:Add, CheckBox, x+5 vesPath gesOptions, Path
  119. Gui 1:Add, CheckBox, x+20 vesSortPath gesOptions checked%esSortPath%, Path sort
  120. Gui 1:Add, CheckBox, x+20 vesRegEx gesOptions, Enable RegEx
  121.  
  122. Gui 1:Add, ComboBox, xs+10 yp+25 w247 vcommand_search gsearch , %savedFileSearchQuery%%fileSearchStrings%
  123. Gui 1:Add, Button, x+1 yp-1 w12 vsaveFileSearchString gsaveFileSearchQuery disabled, +
  124. Gui 1:Add, Button, x+3 vaddPathButton gaddPathToSearch disabled, +path
  125. Gui 1:Add, Button, x+10 vshowFileSize gshowFileSize disabled, Show size
  126.  
  127. Gui 1:Add, GroupBox, x398 y10 w320 h80 section, Find String
  128. Gui 1:Add, CheckBox, xs+10 ys+25 vfindLiteral gfindOptions, Literal
  129. Gui 1:Add, CheckBox, x+5 vfindCase gfindOptions, Case
  130. Gui 1:Add, CheckBox, x+20 vfindRegEx gfindOptions, Enable RegEx
  131. Gui 1:Add, Button, x+39 yp-5 vpreviewButton gpreviewResults disabled, Preview
  132. Gui 1:Add, ComboBox, xs+10 yp+30 w287 vsearch_inside gsearch disabled, %parameter%
  133. Gui 1:Add, Button, x+1 yp-1 w12 vsaveStringSearchString gsaveStringSearchQuery disabled, +
  134.  
  135. Gui 1:Add, GroupBox, x+15 y10 w66 h80 section
  136. Gui 1:Add, Button, xs+8 ys+13 w50 h20 gswapGui , Gui
  137. Gui 1:Add, Button, xs+8 yp+20 w50 h20 gapp_options, Options
  138. Gui 1:Add, Button, xs+8 yp+20 w50 h20 gprogHelp disabled, Help
  139.  
  140. GUI 1:Add, ListView, x5 r20 w785 vhitlist glistviewEvent AltSubmit -multi count%max_results% , result¦name¦ext¦size¦path
  141. LV_ModifyCol(1, 0)                                                   ; Hide column 1 (contains files FULL path).
  142. LV_ModifyCol(2, 300)                                                 ; Set "name" column size.
  143. LV_ModifyCol(3, 45)                                                  ; Set "ext" column size.
  144. LV_ModifyCol(4, 60)                                                  ; Set "size" column size.
  145. LV_ModifyCol(5, 464)                                                 ; Set "path" column size.
  146.  
  147. Gui 1:Add, StatusBar, gsbCopyFullPath, %progNameSB%                  ; Clicking SB copies files full path to clipboard.
  148.  
  149. GUI 1:Show,, %GUI_name%
  150. Return
  151.  
  152. ; ****************** TABBED GUI ******************
  153. Gui2:
  154. Gui 1:Margin, 5, 5
  155. GUI 1:+MinSize  +LastFound
  156. Gui 1:+Delimiter¦                                                 ; Pipe is used in searches, use alternate field separator.
  157.  
  158. Gui 1:Add, Button, x266 w50 h20 gapp_options, Options
  159. Gui 1:Add, Button, x+0 w50 h20 gprogHelp disabled, Help
  160. Gui 1:Add, Button, x+0 w50 h20 gswapGui, Gui
  161.  
  162. Gui 1:Add, Tab2, x5 y10 w410 h140 vtabVar gwhichTab -wrap -Background, File Search¦String Search
  163.  
  164. Gui 1:Tab, File Search
  165.  
  166. Gui 1:Add, Text, x10 y38 h20 disabled, Operators:
  167. Gui 1:Add, Button, x+1 yp-3 w15 h20 disabled, ?
  168. Gui 1:Add, Button, x+0 w15 h20 disabled, *
  169. Gui 1:Add, Button, x+0 h20 w20 disabled, ""
  170. Gui 1:Add, Button, x+0 h20 w15 disabled, |
  171. Gui 1:Add, Button, x+0 h20 w15 disabled, !
  172. Gui 1:Add, Button, x+0 h20 w15 disabled, \
  173.  
  174. Gui 1:Add, Text, x+9 y38 h20 disabled, RegEx:
  175. Gui 1:Add, Button, x+1 yp-3 w15 h20 disabled, |
  176. Gui 1:Add, Button, x+0 h20 w20 disabled, ( )
  177. Gui 1:Add, Button, x+0 h20 w15 disabled, ?
  178. Gui 1:Add, Button, x+0 h20 w15 disabled, *
  179. Gui 1:Add, Button, x+0 h20 w15 disabled, +
  180. Gui 1:Add, Button, x+0 h20 w15 disabled, .
  181. Gui 1:Add, Button, x+0 h20 w20 disabled, [ ]
  182. Gui 1:Add, Button, x+0 h20 w25 disabled, [^ ]
  183. Gui 1:Add, Button, x+0 h20 w15 disabled, ^
  184. Gui 1:Add, Button, x+0 h20 w15 disabled, $
  185. Gui 1:Add, Button, x+0 h20 w35 disabled, {m,n}
  186.  
  187. Gui 1:Add, GroupBox, x10 yp+17 w395 h80 section
  188. Gui 1:Add, CheckBox, xs+10 ys+25 vesWW gesOptions, Whole Word
  189. Gui 1:Add, CheckBox, x+5 vesCase gesOptions, Case
  190. Gui 1:Add, CheckBox, x+5 vesPath gesOptions, Path
  191.  
  192. Gui 1:Add, CheckBox, x+25 vesSortPath gesOptions checked%esSortPath%, Path sort
  193.  
  194. Gui 1:Add, CheckBox, x+20 vesRegEx gesOptions, Enable RegEx
  195.  
  196. Gui 1:Add, ComboBox, xs+10 yp+25 w259 vcommand_search gsearch , %savedFileSearchQuery%%fileSearchStrings%
  197. Gui 1:Add, Button, x+1 yp-1 w12 vsaveFileSearchString gsaveFileSearchQuery disabled, +
  198. Gui 1:Add, Button, x+3 vaddPathButton gaddPathToSearch disabled, +path
  199.  
  200. Gui 1:Add, Button, x+5 vshowFileSize gshowFileSize disabled, Show size
  201.  
  202. Gui 1:Tab, String Search
  203.  
  204. Gui 1:Add, Text, x10 y38 h20 disabled, RegEx:
  205. Gui 1:Add, Button, x+15 yp-3 w20 h20 disabled, .
  206. Gui 1:Add, Button, x+0 h20 w20 disabled, *
  207. Gui 1:Add, Button, x+0 h20 w20 disabled, ^
  208. Gui 1:Add, Button, x+0 h20 w20 disabled, $
  209. Gui 1:Add, Button, x+0 h20 w50 disabled, [class]
  210. Gui 1:Add, Button, x+0 h20 w55 disabled, [^class]
  211. Gui 1:Add, Button, x+0 h20 w40 disabled, [x-y]
  212. Gui 1:Add, Button, x+0 h20 w30 disabled, \x
  213. Gui 1:Add, Button, x+0 h20 w45 disabled, \<xyz
  214. Gui 1:Add, Button, x+0 h20 w45 disabled, xyz\>
  215. Gui 1:Add, GroupBox, x10 yp+17 w395 h80 section
  216. Gui 1:Add, CheckBox, xs+10 ys+25 vfindLiteral gfindOptions, Literal
  217. Gui 1:Add, CheckBox, x+5 vfindCase gfindOptions, Case
  218. Gui 1:Add, CheckBox, x+30 vfindRegEx gfindOptions, Enable RegEx
  219. Gui 1:Add, Button, x+104 yp-5 vpreviewButton gpreviewResults disabled, Preview
  220. Gui 1:Add, ComboBox, xs+10 yp+30 w362 section vsearch_inside gsearch disabled, %parameter%
  221. Gui 1:Add, Button, x+1 yp-1 w12 vsaveStringSearchString gsaveStringSearchQuery disabled, +
  222.  
  223. Gui 1:Tab
  224.  
  225. GUI 1:Add, ListView, x5 w410 r20 vhitlist glistviewEvent AltSubmit -multi count%max_results% , result¦name¦ext¦size¦path
  226. LV_ModifyCol(1, 0)                                                   ; Hide column 1 (contains files FULL path).
  227. LV_ModifyCol(2, 200)                                                 ; Set "name" column size.
  228. LV_ModifyCol(3, 45)                                                  ; Set "ext" column size.
  229. LV_ModifyCol(4, 60)                                                  ; Set "size" column size.
  230. LV_ModifyCol(5, 464)                                                 ; Set "path" column size.
  231.  
  232. Gui 1:Add, StatusBar, gsbCopyFullPath, %progNameSB%                  ; Clicking SB copies files full path to clipboard.
  233.  
  234. GUI 1:Show,, %GUI_name%
  235. Return
  236.  
  237.  
  238. saveFileSearchQuery:
  239. Gui Submit, Nohide
  240. IfNotInString savedFileSearchQuery, %command_search%
  241. {
  242.    savedFileSearchQuery = %savedFileSearchQuery%¦%command_search%
  243.    GuiControl,, command_search, ¦%savedFileSearchQuery%%fileSearchStrings%
  244.    GuiControl focus, command_search
  245.    SendInput {Raw} %command_search%
  246.    Gosub cfgSave
  247.    }
  248. Return
  249.  
  250. saveStringSearchQuery:
  251. Gui Submit, Nohide
  252. IfNotInString savedStringSearchQuery, %search_inside%
  253. {
  254.    savedStringSearchQuery = %savedStringSearchQuery%¦%search_inside%
  255.    GuiControl,, search_inside, ¦%savedStringSearchQuery%
  256.    GuiControl focus, search_inside
  257.    SendInput {Raw} %search_inside%
  258.    Gosub cfgSave
  259.    }
  260. Return
  261.  
  262. whichTab:                                                           ; Select the correct control when selecting
  263. Gui Submit, Nohide                                                   ; different tabs.
  264. If (tabVar = "File Search")
  265.    GuiControl focus, command_search
  266. Else
  267.    GuiControl focus, search_inside
  268. SendInput {End}
  269. Return
  270.  
  271. progHelp:
  272. Run %helpFile%
  273. Return
  274.  
  275. saveSearchString:
  276.  
  277. Return
  278.  
  279. showFileSize:                                                       ; Showing file size is disabled by default due to
  280. showSize = 1                                                         ; the excesive time taken to retrieve info from
  281. Gosub esOptions                                                      ; large numbers of files while typing the query.
  282. showSize=                                                            ; Clicking the "show size" button once the search
  283. Return                                                               ; is done runs this routine and fills the size column.
  284.  
  285. swapGui:                                                            ; Changes from one gui layout to the other.
  286. If (guiNewChoice = 0)
  287.    guiNewChoice = 1
  288. Else
  289.    guiNewChoice = 0
  290.  
  291. If esWW                                                              ; Save all wanted control data ready for new gui.
  292.    esWW = 1
  293. If esCase
  294.    esCase = 1
  295. If esPath
  296.    esPath = 1
  297. If esRegex
  298.    esRegex = 1
  299.  
  300. If findLiteral
  301.    findLiteral = 1
  302. If findCase
  303.    findCase = 1  
  304. If findRegEx
  305.    findRegEx = 1
  306.  
  307. If esSortPath
  308.    esSortPath = 1
  309.  
  310. If (command_search) {
  311.    IfInString command_search, "|"
  312.       StringReplace command_search, command_search, "|", |, A
  313.    command_search1 = %command_search%
  314.    }
  315. If search_inside
  316.    search_inside1 = %search_inside%
  317. Gui 1:Destroy                                                        ; Bye-bye old gui.
  318.  
  319. Gosub doGui                                                          ; Hello new gui.
  320.  
  321. If esWW                                                              ; Update new gui's controls with saved data.
  322.    GuiControl,, esWW, 1
  323. If esCase
  324.    GuiControl,, esCase, 1
  325. If esPath
  326.    GuiControl,, esPath, 1
  327. If esRegex
  328.    GuiControl,, esRegex, 1
  329.    
  330. If findLiteral
  331.    GuiControl,, findLiteral, 1
  332. If findCase
  333.    GuiControl,, findCase, 1
  334. If findRegEx
  335.    GuiControl,, findRegEx, 1
  336.  
  337. swap = 1
  338. Gosub esOptions                                                      ; Get Es.exe command line options.
  339. Gosub findOptions                                                    ; Get FindStr.exe command line options.
  340. swap=
  341.  
  342. If (command_search1) {                                               ; If there was text in the previous gui's find file
  343.    GuiControl focus, command_search                                  ; search box, place it in the new gui's search box
  344.    SendInput {Raw} %command_search1%                                 ; and do search using the above command line options.
  345.    }
  346. If search_inside1                                                    ; Same as above but search file's for strings of text.
  347.    GuiControl Text, search_inside, %search_inside1%
  348.    
  349. command_search1=
  350. search_inside1=
  351. Return
  352.  
  353. loadOptions:                                                        ; Sets variables for initial search on app start.
  354. findSearchOptions := "/S /M "
  355. If (esSortPath)
  356.    esSortPath = -s
  357. Else
  358.    esSortPath=
  359. esSearchOptions = %esSortPath%
  360. Return
  361.  
  362. esOptions:                                                          ; Sets command line options for es.exe.
  363. Gui Submit, NoHide
  364. If (esWW)                                                            ; Whole word search.
  365.    esWW = -w
  366. Else
  367.    esWW=
  368. If (esCase)                                                          ; Case sensitive search.
  369.    esCase = -i
  370. Else
  371.    esCase=
  372. If (esPath)                                                          ; Search the path.
  373.    esPath = -p
  374. Else
  375.    esPath=
  376. If (esRegex) {                                                       ; Enable regex search strings.
  377.    esRegex = -r
  378.    GuiControl Disable, esWW
  379.    }
  380. Else {
  381.    esRegEx=
  382.    GuiControl Enable, esWW
  383.    }
  384. If (esSortPath)                                                      ; Sort the results by path (rather than by name).
  385.    esSortPath = -s
  386. Else
  387.    esSortPath=
  388. esSearchOptions = %esSortPath% %esWW% %esCase% %esPath% %esRegEx%    ; Completed options string ready to pass on to es.exe.
  389. If swap                                                              ; Gui is being swapped so don't perform search (yet!).
  390.    Return
  391. Gosub execute_search
  392. Return
  393.  
  394. findOptions:                                                        ; Sets command line options for EveryStr.exe.
  395. Gui Submit, NoHide
  396. If (findLiteral)                                                     ; Search string is literal, eg. "good dog" rather than
  397.    findLiteral := "/C:"                                              ; "good" AND "dog".
  398. Else
  399.    findLiteral=
  400. If (findCase) || (findLiteral)                                       ; Default condition is "case sensitive" for the search
  401.    findCase=                                                         ; query.  Adding /I make the query NOT case sensitive.
  402. Else
  403.    findCase := "/I "
  404.  
  405. If (findRegEx) {                                                     ; RegEx.
  406.    findRegex := "/R "
  407.    GuiControl Disable, findLiteral                                   ; These aren't needed if regex is enabled ... I think!
  408.    GuiControl Disable, findCase
  409.    }
  410. Else {
  411.    findRegEx=
  412.    GuiControl Enable, findLiteral
  413.    GuiControl Enable, findCase
  414.    }
  415. findSearchOptions :=  "/S /M " . findCase . findRegEx . findLiteral  ; The completed  options string.
  416.  
  417. If swap
  418.    Return
  419. Gosub execute_search
  420. Return
  421.  
  422. previewResults:
  423. Gui Submit, Nohide
  424. If (search_inside) {
  425.    IfExist %result_filename%
  426.    {
  427.       StringReplace pOpts, findSearchOptions, /M, /N
  428.       FileDelete preview.txt
  429.       ;msgbox "%pOpts%"
  430.       Runwait %comspec% /c ""%findstr_app%" /F:"%result_filename%" %pOpts%"%search_inside%" > "preview.txt"", %A_ScriptDir%, hide
  431.       FileRead result, preview.txt
  432.       Run preview.txt
  433.       }
  434.    result=
  435.    }
  436. Return
  437.  
  438. search:
  439.   SetTimer execute_search, -%update_speed%                          ;Wait xxx milliseconds after typing stops.
  440. Return
  441.  
  442. execute_search:
  443. Gui Submit, NoHide                                                   ; Retrieve the variables from the GUI
  444. If (!command_search) {                                               ; Search box is empty so clear the listview
  445.    LV_Delete()                                                       ; and, a few controls and vars.
  446.    SB_SetText(progNameSB)
  447.    GuiControl disable, addPathButton
  448.    Guicontrol disable, search_inside
  449.    GuiControl disable, showFileSize
  450.    GuiControl disable, saveFileSearchString  
  451.    lvFullPath = Result
  452.    hitCnt=
  453.    Return
  454.    }
  455. IfInString command_search, |
  456.    StringReplace command_search, command_search, |, "|", all
  457. IfExist %result_filename%                                            ; Check if the temporary output file exists,
  458.    FileDelete %result_filename%                                      ; if so, delete it.
  459. Runwait %comspec% /c ""%find_app%" %command_search% %esSearchOptions% -n %max_results% > "%result_filename%"", %A_ScriptDir%, hide
  460. IfExist %result_filename2%                                           ; Check if the temporary (filtered) output file exists,
  461.    FileDelete %result_filename2%                                     ; if so, delete it.
  462.  
  463. If (search_inside) {                                                 ; Search retrieved file list for specified text.
  464.    Runwait %comspec% /c ""%findstr_app%" /F:"%result_filename%" %findSearchOptions%"%search_inside%" > "%result_filename2%"", %A_ScriptDir%, hide
  465.    FileDelete %result_filename%
  466.    FileMove %result_filename2%, %result_filename%  
  467.    }
  468.  
  469. IfExist %result_filename%                                            ; Read the (filtered) outputfile to a variable
  470. {
  471.    LV_Delete()                                                       ; Empty the list ready it for updated/new results
  472.    FileRead , results, %result_filename%
  473.    StringReplace , results , results , `r`n, `n, A                   ; Needed for the listview.
  474.    GuiControl, -Redraw, Hitlist
  475.    hitCnt = -1
  476.    Loop parse, results, `n
  477.    {
  478.       hitCnt++                                                       ; Start counting the hits.
  479.       SplitPath A_LoopField , OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
  480.       If (showSize) {                                                ; Get files size. This is done manually by the user.
  481.          FileGetSize, fileSize, %A_LoopField%, B
  482.          If fileSize = 0
  483.             fileSize=
  484.       FileGetAttrib isFolder, %A_LoopField%
  485.       IfInString isFolder, D
  486.       {
  487.          OutExtension = !Folder
  488.          fileSize=
  489.          }
  490.       }
  491.       If (outfilename)
  492.          LV_Add("", A_LoopField, OutFileName, OutExtension, fileSize, OutDir)        
  493.       }
  494.    GuiControl +Redraw, Hitlist
  495.    If hitCnt = -1
  496.       hitCnt = 0
  497.    SB_SetText(hitCnt " hits. - "sbDisplay)
  498.    
  499.    If (search_inside) && (hitCnt > 0) {                              ; Enable/disable some controls dependent on hits.
  500.       GuiControl enable, saveStringSearchString
  501.       Guicontrol enable, previewButton
  502.       GuiControl disable, command_search                             ; Disable file search input box when text search box
  503.       }                                                              ; has content.
  504.    Else {
  505.       GuiControl disable, saveStringSearchString
  506.       GuiControl disable, previewButton
  507.       GuiControl enable, command_search
  508.       }
  509.    }
  510.    Guicontrol enable, search_inside
  511.    GuiControl enable, showFileSize
  512.    GuiControl enable, saveFileSearchString  
  513.    GuiControl disable, addPathButton
  514. LV_ModifyCol(4, "Integer")                                           ; Size column
  515. results=                                                             ; Empty the variables to free up memory
  516. hitCnt=
  517. Return
  518.  
  519. listviewEvent:
  520. If (A_GuiEvent = "DoubleClick") {                                    ; Listview was double clicked.
  521.    Gosub listviewInfo
  522.    If (lvFullPath <> "Result")
  523.       Gosub command_run
  524.    }
  525. If (A_GuiEvent = "Normal" || A_GuiEvent = "I") {                     ; Single click or selection changed.
  526.    Gosub listviewInfo
  527.    If (lvFullPath <> "Result") {
  528.       ;msgbox %lvFullPath%`n%search_inside%
  529.       If (!search_inside) {
  530.          SB_SetText("Click to copy: " lvFullPath)
  531.          GuiControl enable, addPathButton
  532.          }
  533.       }
  534.    }
  535. Return
  536.  
  537. addPathToSearch:                                                    ; Add selected files path to the search box
  538. GuiControl Focus, command_search                                     ; (shows files in that folder) and do search.
  539. SendInput %lvDirName%
  540. Return
  541.  
  542.  
  543. listviewInfo:
  544. LV_GetText(lvFullPath, A_EventInfo, 1)
  545. LV_GetText(lvFileName, A_EventInfo, 2)
  546. LV_GetText(lvDirName, A_EventInfo, 5)
  547. Return
  548.  
  549. GuiContextMenu:
  550. If (A_GuiControl = "hitlist" && A_GuiControlEvent = "RightClick")    ; Only show menu when listview is right clicked.
  551. {
  552.    Gosub listviewInfo
  553.    
  554.    Menu Context, Add, Open &directory, menuEvent
  555.    Menu Context, Add
  556.    Menu Context, Add, Open &with %textEditorName%, menuEvent
  557.    Menu Context, Add, &Edit, menuEvent
  558.    Menu Context, Add, &Properties, menuEvent
  559.    Menu Context, Add
  560.    Menu Context, Add, Save &list, menuEvent
  561.    Menu Context, Add
  562.    Menu Context, Add, &Options, menuEvent
  563.    
  564.    Menu ContextHelp, Add, RegEx Reference, menuEvent
  565.    Menu ContextHelp, Add
  566.    
  567.    Menu ContextHelp, Add, Everything, menuEvent
  568.    Menu ContextHelp, disable, Everything
  569.    Menu ContextHelp, Add, Home, menuEvent
  570.    Menu ContextHelp, Add, FAQ Searching, menuEvent
  571.    Menu ContextHelp, Add, Wiki Searching, menuEvent
  572.    Menu ContextHelp, Add
  573.    Menu ContextHelp, Add, FindStr Reference, menuEvent
  574.    Menu Context, Add, Help, :ContextHelp
  575.    
  576.    Menu Context, Show, %A_GuiX%, %A_GuiY%
  577.    Menu Context, Delete
  578.    }
  579. Return
  580.  
  581. menuEvent:
  582. If ( !ThisMenuItem )
  583.     ThisMenuItem = %A_ThisMenuItem%
  584. If (ThisMenuItem = "Open &directory")
  585.    Gosub openDirectory
  586. If (ThisMenuItem = "Open &with "textEditorName)
  587.    Gosub openInTextEditor
  588. If (ThisMenuItem = "&Edit")
  589.    Gosub editFile
  590. If (ThisMenuItem = "&Properties")
  591.    Run properties "%lvFullPath%",, UseErrorLevel
  592. If (ThisMenuItem = "Save &list")
  593.    Gosub saveList
  594. If (ThisMenuItem = "&Options")
  595.    Gosub app_options
  596. If (ThisMenuItem = "RegEx Reference")
  597.    Run http://www.regular-expressions.info/
  598. If (ThisMenuItem = "Home")
  599.    Run http://www.voidtools.com
  600. If (ThisMenuItem = "FAQ Searching")
  601.    Run http://www.voidtools.com/faq.php#Searching
  602. If (ThisMenuItem = "Wiki Searching")
  603.    Run http://support.voidtools.com/everything/Searching
  604. If (ThisMenuItem = "FindStr Reference")
  605. Run http://technet.microsoft.com/en-us/library/bb490907.aspx
  606. ThisMenuItem=
  607. Return
  608.  
  609. sbCopyFullPath:                                                     ; Sets the timer on for clicking the status bar
  610. SetTimer copyPath, on                                                ; to copy the selected files full path to clipboard.
  611. Return
  612.  
  613. copyPath:
  614. If (lvFullPath = "Result") {                                         ; No file selected.
  615.    SB_SetText("Please make a selection first or try again!")
  616.    Sleep 3000
  617.    SB_SetText(progNameSB)
  618.    SetTimer copyPath, off
  619.    Return
  620.    }
  621. Clipboard = %lvFullPath%                                             ; Path copied.
  622. SB_SetText("COPIED - - " lvFullPath " - - COPIED")                   ; Show confirmation.
  623. Sleep 5000
  624. SB_SetText("Click to copy: " lvFullPath)
  625. SetTimer copyPath, off
  626. Return
  627.  
  628. saveList:                                                           ; Save the current list of file paths.
  629. IfNotExist %result_filename%                                         ; No list to save.
  630. {
  631.    MsgBox Nothing to save!
  632.    Return
  633.    }
  634. FileSelectFile  saveListPath, 16, %A_ScriptDir%\%app_name% - Saved List.txt,, txt   ; Select file name and path to save to.
  635. If (!saveListPath)                                                   ; File save cancelled.
  636.    Return
  637. FileCopy %result_filename%, %saveListPath%
  638. If ErrorLevel <> 0
  639.    Msgbox There was a problem, list not saved.
  640. Return
  641.  
  642. openDirectory:                                                      ; Open selected files folder.
  643. IfExist %lvDirName%
  644.    Run %fileMan_app% %fileManArgs%"%lvFullPath%", %lvDirName%, UseErrorLevel
  645. Gosub error_check
  646. Return
  647.  
  648. command_run:                                                        ; Run the selected file.
  649. Run %lvFullPath%, %lvDirName%, UseErrorLevel
  650. Gosub error_check
  651. Return
  652.  
  653. editFile:                                                           ; Edit the file with it's registered program.
  654. Run Edit %lvFullPath%, %lvDirName%, UseErrorLevel
  655. Gosub error_check
  656. Return
  657.  
  658. openInTextEditor:                                                   ; Open file in a text editor.
  659. Run %textEditor_app% %lvFullPath%, %lvDirName%, UseErrorLevel
  660. Gosub error_check
  661. Return
  662.  
  663. error_check:                                                        ; If there's an error opening a file, show the reason.
  664. If (A_LastError <> 0) {
  665.     thisError := returnLastError()
  666.     MsgBox,, %app_name% - Oops ..., %thisError%`nFile: %lvFullPath%
  667.    }
  668. Return
  669.  
  670. app_options:                                                        ; Options gui.
  671. Gui 2:Default
  672. Gui 2:+Owner +AlwaysOnTop
  673. Gui 2:Margin, 10, 10
  674.  
  675. Gui 2:Add, GroupBox, w400 h90 y+10 section, General
  676. Gui 2:Add, CheckBox, xs+40 ys+25 vguiChoice checked%guiChoice%, Start with "tabbed" Gui
  677. Gui 2:Add, CheckBox, xs+240 ys+25 vesSortByPath checked%esSortByPath%, Sort results by full path
  678. Gui 2:Add, Text, xs+40 yp+35, Maximum results:
  679. Gui 2:Add, Edit, x+5 w50 r1 vmax_results, %max_results%
  680. Gui 2:Add, Text, xs+240 yp, Update speed:
  681. Gui 2:Add, Edit, x+5 w40 r1 vupdate_speed, %update_speed%
  682.  
  683. Gui 2:Add, Groupbox, x5 yp+50 w400 h110 section, App Paths
  684. Gui 2:Add, Text, xs+10 ys+25 w70, Everything:
  685. Gui 2:Add, Edit, x+5 w300 r1 veverything_app, %everything_app%
  686. Gui 2:Add, Text, xs+10 yp+25 w70, Es:
  687. Gui 2:Add, Edit, x+5 w300 r1 vfind_app, %find_app%
  688. Gui 2:Add, Text, xs+10 yp+25 w70, Findstr:
  689. Gui 2:Add, Edit, x+5 w300 r1 vfindstr_app, %findstr_app%
  690.  
  691. Gui 2:Add, Groupbox, x5 yp+50 w400 h85 section, File Manager
  692. Gui 2:Add, Text, xs+10 ys+25 w70, Path:
  693. Gui 2:Add, Edit, x+5 w300 r1 vfileMan_app, %fileMan_app%
  694. Gui 2:Add, Text, xs+10 yp+25 w70, Arguments:
  695. Gui 2:Add, Edit, x+5 w100 r1 vfileManArgs, %fileManArgs%
  696.  
  697. Gui 2:Add, Groupbox, x5 yp+50 w400 h85 section, Text Editor
  698. Gui 2:Add, Text, xs+10 ys+25 w70, Path:
  699. Gui 2:Add, Edit, x+5 w300 r1 vtextEditor_app, %textEditor_app%
  700. Gui 2:Add, Text,  xs+10 yp+25 w70, Editor name:
  701. Gui 2:Add, Edit,  x+5 w300 r1 vtextEditorName, %textEditorName%
  702.  
  703. Gui 2:Add, Button, x10 gGui2OK, &Ok
  704. Gui 2:Add, Button, x+5 gGui2Cancel, &Cancel
  705.  
  706. Gui 2:Show,, %app_name% - Options
  707. Return
  708.  
  709. cfgLoad:
  710. IniRead max_results,             %iniPath%, General,  MaximumResults, 10000
  711. IniRead update_speed,            %iniPath%, General,  UpdateSpeed, 250
  712. IniRead esSortByPath,            %iniPath%, General,  SortByPath, 0
  713. IniRead guiChoice,               %iniPath%, General,  TabbedGui, 0
  714. IniRead everything_app,          %iniPath%, Paths,    EverythingPath, %ProgramFiles%\Everything\Everything.exe
  715. IniRead find_app,                %iniPath%, Paths,    EsPath, %ProgramFiles%\Everything\es.exe
  716. IniRead findstr_app,             %iniPath%, Paths,    FindStrPath, %A_WinDir%\system32\findstr.exe
  717. IniRead fileMan_app,             %iniPath%, Paths,    FileManagerPath, %A_WinDir%\explorer.exe
  718. IniRead fileManArgs,             %iniPath%, Paths,    FileManagerPathArgs, `/select`,
  719. IniRead textEditor_app,          %iniPath%, Paths,    TextEditorPath, %A_WinDir%\notepad.exe
  720. IniRead textEditorName,          %iniPath%, Paths,    TextEditorName, Notepad
  721. IniRead savedFileSearchQuery,    %iniPath%, Strings,  FileSearchStrings,
  722. IniRead savedStringSearchQuery,  %iniPath%, Strings,  StringSearchStrings,
  723.  
  724. Return
  725. ; C:\Program Files\FreeCommander\FreeCommander.exe /c /l=
  726. cfgSave:
  727. IniWrite %max_results%,             %iniPath%, General,  MaximumResults
  728. IniWrite %update_speed%,            %iniPath%, General,  UpdateSpeed
  729. IniWrite %esSortByPath%,            %iniPath%, General,  SortByPath
  730. IniWrite %guiChoice%,               %iniPath%, General,  TabbedGui
  731. IniWrite %everything_app%,          %iniPath%, Paths,    EverythingPath
  732. IniWrite %find_app%,                %iniPath%, Paths,    EsPath
  733. IniWrite %findstr_app%,             %iniPath%, Paths,    FindStrPath
  734. IniWrite %fileMan_app%,             %iniPath%, Paths,    FileManagerPath
  735. IniWrite %fileManArgs%,             %iniPath%, Paths,    FileManagerPathArgs
  736. IniWrite %textEditor_app%,          %iniPath%, Paths,    TextEditorPath
  737. IniWrite %textEditorName%,          %iniPath%, Paths,    TextEditorName
  738. IniWrite %savedFileSearchQuery%,    %iniPath%, Strings,  FileSearchStrings
  739. IniWrite %savedStringSearchQuery%,  %iniPath%, Strings,  StringSearchStrings
  740. Return
  741.  
  742. Gui2Cancel:                                                         ; Close/cancel Options gui.
  743. 2GuiEscape:
  744. 2GuiClose:
  745. Gui 2:Destroy
  746. Gui 1:Default
  747. Return
  748.  
  749. Gui2OK:                                                             ; Save Options
  750. Gui 2:Submit, Nohide
  751. Gosub cfgSave
  752. Gosub Gui2Cancel                                                     ; and close gui
  753. Return
  754.  
  755. GuiEscape:                                                           ; Close app and delete any temporary files generated.
  756. GuiClose:
  757. IfExist %result_filename%
  758.    FileDelete %result_filename%
  759. IfExist %result_filename2%
  760.    FileDelete %result_filename2%
  761. IfExist preview.txt
  762.    FileDelete preview.txt
  763. ExitApp
  764. Return
  765.  
  766. RemoveToolTip:
  767. ToolTip
  768. Return
  769.  
  770. WM_MOUSEMOVE() {
  771.   static CurrControl, PrevControl, _TT
  772.   CurrControl := A_GuiControl
  773.   If (CurrControl <> PrevControl and not InStr(CurrControl, " ")) {
  774.     ToolTip % %CurrControl%_TT
  775.     SetTimer, RemoveToolTip, 7000
  776.     PrevControl := CurrControl      
  777.   }
  778. }
  779.  
  780. returnLastError() {
  781. Global
  782. IfEqual A_LastError, 2, Return, "Error " %A_LastError% ": The system cannot find the file specified."
  783. IfEqual A_LastError, 3, Return, "Error " %A_LastError% ": The system cannot find the path specified."
  784. IfEqual A_LastError, 4, Return, "Error " %A_LastError% ": The system cannot open the file."
  785. IfEqual A_LastError, 5, Return, "Error " %A_LastError% ": Access is denied."
  786. IfEqual A_LastError, 15, Return, "Error " %A_LastError% ": The system cannot find the drive specified."
  787. IfEqual A_LastError, 21, Return, "Error " %A_LastError% ": The device is not ready."
  788. IfEqual A_LastError, 25, Return, "Error " %A_LastError% ": Windows cannot find the network path.`nVerify that the network path is correct and the destination computer is not busy or turned off.`nIf Windows still cannot find the network path, contact your network administrator."
  789. IfEqual A_LastError, 1155, Return, "Error " %A_LastError% ": No application is associated with the specified file for this operation."
  790. }
  791.  
  792.  
  793. /*
  794. Everything:
  795. -r Search the database using a basic POSIX regular expression.
  796. -i Does a case sensitive search.
  797. -w Does a whole word search.
  798. -p Does a full path search.
  799. -h --help Display this help.
  800. -n <num> Limit the amount of results shown to <num>.
  801. -s Sort by full path.
  802. */
  803.  
  804. /*
  805. Info: http://technet.microsoft.com/en-us/library/bb490907.aspx
  806.  
  807. Findstr:
  808. Searches for strings in files.
  809.  
  810. FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F]
  811.         [/C] [/G] [/D] [/A] [/OFF[LINE]]
  812.         strings [[drive][path]filename[ ...]]
  813.  
  814.   /B         Matches pattern if at the beginning of a line.
  815.   /E         Matches pattern if at the end of a line.
  816.   /L         Uses search strings literally.
  817.   /R         Uses search strings as regular expressions.
  818.   /S         Searches for matching files in the current directory and all subdirectories.
  819.   /I         Specifies that the search is not to be case-sensitive.
  820.   /X         Prints lines that match exactly.
  821.   /V         Prints only lines that do not contain a match.
  822.   /N         Prints the line number before each line that matches.
  823.   /M         Prints only the filename if a file contains a match.
  824.   /O         Prints character offset before each matching line.
  825.   /P         Skip files with non-printable characters.
  826.   /OFF[LINE] Do not skip files with offline attribute set.
  827.   /A:attr    Specifies color attribute with two hex digits. See "color /?"
  828.   /F:file    Reads file list from the specified file(/ stands for console).
  829.   /C:string  Uses specified string as a literal search string.
  830.   /G:file    Gets search strings from the specified file(/ stands for console).
  831.   /D:dir     Search a semicolon delimited list of directories
  832.   strings    Text to be searched for.
  833.   [drive][path]filename     Specifies a file or files to search.
  834.  
  835. Use spaces to separate multiple search strings unless the argument is prefixed
  836. with /C.  For example, 'FINDSTR "hello there" x.y' searches for "hello" or
  837. "there" in file x.y.  'FINDSTR /C:"hello there" x.y' searches for
  838. "hello there" in file x.y.
  839.  
  840.  
  841. The special characters in regular expression syntax are most powerful when you use them together. For example, the following combination of the wildcard character (.) and repeat (*) character match any string of characters:
  842.  
  843. .*
  844.  
  845. Use the following expression as part of a larger expression that matches any string beginning with "b" and ending with "ing":
  846.  
  847. b.*ing
  848. For full information on FINDSTR regular expressions refer to the online Command
  849. Reference.
  850. */
  851. /*
  852. http://www.regular-expressions.info/
  853.  
  854.  
  855. */
Add Comment
Please, Sign In to add comment