Procedure

TPatternSearcher.Search

Module

PsEngine

Last Modified

2007-05-17 15:58:28

Comments

Main search method, calls SearchWithPos or SearchWithUC

Visibility

Public

Owner

TPatternSearcher

Declaration

procedure Search;

Calls Hierarchy


TPatternSearcher.Search
 ├TPatternSearcher.SearchWithPos
 └TPatternSearcher.SearchWithUC

Called-By Hierarchy


       TPatternSearcher.Search
   TPSMainForm.GeneralSearch┘ 
TPSMainForm.CmdSearchClick┘   

Calls

Name Declaration Comments
TPatternSearcher.SearchWithPos procedure SearchWithPos(const Path : string); // searches with Pos (intf) -
TPatternSearcher.SearchWithUC procedure SearchWithUC(const Path : string); -

Called-By

Name Declaration Comments
TPSMainForm.GeneralSearch procedure GeneralSearch; -


Source

104   procedure TPatternSearcher.Search;
105   // main search method, calls SearchWithPos or SearchWithUC
106   var
107     Len, I : integer;
108     RootDir, Ext, S : string;
109     TM : TTimeMeasurer;
110     DoFile : boolean;
111   begin
112     try
113       FNumFilesSearched := 0;
114       FNumFilesMatches := 0;
115       FNumMatches := 0;
116   
117       RootDir := FStartDir;
118       Len := Length(RootDir);
119   
120       if Len > 3 then // not for "C:\"
121         if RootDir[Len] = '\' then
122           RootDir := copy(RootDir, 1, Len-1);
123   
124       if FIncludeSubFolders then
125         S := ' with subfolders'
126       else
127         S := '';
128   
129       FLog.Add('');
130       FLog.Add('--- Searching '+RootDir+S+' for pattern "'+FPattern+'" at '+DateTimeToStr(Now)+' ---');
131       FLog.Add('');
132   
133       StartTimer(TM);
134       EnumerateFiles(RootDir, FilePaths, FIncludeSubFolders, nil);
135   
136       for I := 0 to FilePaths.Count-1 do
137       begin
138         Application.ProcessMessages;
139   
140         if gStopped then
141         begin
142           FLog.Add('');
143           FLog.Add('--- Search aborted by user ---');
144           Abort;
145         end;
146   
147         if not IsDirectory(FilePaths[I]) then
148         begin
149           DoFile := false;
150   
151           if sfAll in FSearchedFiles then
152             DoFile := true
153           else
154           begin
155             Ext := JustExtensionL(FilePaths[I]);
156   
157             if (sfOnlyInc in FSearchedFiles) and SameText(Ext, 'inc') then
158               DoFile := true
159             else
160               if (sfOnlyWeb in FSearchedFiles) and (SameText(Ext, 'asp') or
161                 SameText(Ext, 'htm')) then
162                 DoFile := true
163               else
164                 if (sfOnlySql in FSearchedFiles) and SameText(Ext, 'sql') then
165                   DoFile := true
166                 else
167                   if (sfOnlyDelphi in FSearchedFiles) and (SameText(Ext, 'dfm') or
168                     SameText(Ext, 'dpk') or SameText(Ext, 'dpr') or SameText(Ext, 'pas')) then
169                     DoFile := true
170                   else
171                    if (sfOnlyVB in FSearchedFiles) and (SameText(Ext, 'bas') or
172                      SameText(Ext, 'cls') or SameText(Ext, 'frm') or
173                      SameText(Ext, 'vbp')) then
174                      DoFile := true
175                    else
176                      if (sfOnlyTxt in FSearchedFiles) and
177                        (SameText(Ext, 'txt') or SameText(Ext, 'config') or SameText(Ext, 'ini')) then
178                        DoFile := true;
179           end;
180   
181           if DoFile then
182           begin
183             inc(FNumFilesSearched);
184   
185             if FCaseSensitive then
186               SearchWithPos(FilePaths[I])
187             else
188               SearchWithUC(FilePaths[I]);
189   
190             if FEvaluation and (FNumMatches = 3) then
191               Exit;
192           end;
193         end;
194       end;
195   
196     finally
197       FLog.Add('');
198       FLog.Add('--- Searched '+IntToStr(FNumFilesSearched)+' files in '+StopTimer(TM)+' seconds ---');
199       FLog.Add('--- Found '+IntToStr(FNumMatches)+' matches in '+IntToStr(FNumFilesMatches)+' files ---');
200   
201       if FEvaluation then
202         FLog.Add('--- Unregistered evaluation version! Only 3 first matches are reported ---');
203     end;
204   end;