📄 results.pas
字号:
// Find some words
end else begin
for i:=0 to Keywords.Count-1 do begin
if CaseSensitive then
keyword := Keywords.Strings[i]
else
keyword := lowercase(Keywords.Strings[i]);
if Copy(Filename, pos(keyword, Filename), Length(keyword)) = keyword then begin
// Check file extension
if FindText then begin
for k:=0 to Extensions.Count-1 do
if ExtractFileExt(Filename) = Extensions.Strings[k] then begin
CheckText(Texts, tmp);
Break;
end;
end else
if Extension <> '*.*' then begin
if ExtractFileExt(Filename) = ExtractFileExt(editExtension.Text) then
AddResult(tmp);
end else
AddResult(tmp)
end;
end;
end;
end else
// If we finished in search files in directory, finish search.
if finished then Break;
end else begin
// Line begins with '<'. Extract directory.
if (pos('<', line) = 1) and (FindText = False) then begin
path := line;
Delete(path, 1, 1);
Delete(path, Length(path), 1);
end;
// Check if dir has keywords
dirname := Copy(path, 0, Length(path)-1);
l := LastDelimiter('\', dirname);
dirname := Copy(dirname, l+1, Length(dirname)-l);
// Check for keywords
for i:=0 to Keywords.Count-1 do begin
if CaseSensitive then
keyword := Keywords.Strings[i]
else begin
keyword := lowercase(Keywords.Strings[i]);
dirname := lowercase(dirname);
end;
if Copy(dirname, pos(keyword, dirname), Length(keyword)) = keyword then AddDir(path);
end;
end;
// If search cancelled
end else Break;
end;
// Check favorites
SHGetSpecialFolderLocation(Handle, CSIDL_FAVORITES, pidl) ;
SHGetPathFromIDList(pidl, FavPath);
Favorites := TStringList.Create;
Favorites.AddStrings(GetIEFavorites(StrPas(FavPath)));
for i:=0 to Favorites.Count-1 do begin
Filename := Favorites.Strings[i];
// Find all words
if FindAll then begin
// Reset counter
j := -1;
for k:=0 to Keywords.Count-1 do begin
if CaseSensitive then
keyword := Keywords.Strings[k]
else
keyword := lowercase(Keywords.Strings[k]);
if Copy(Filename, pos(keyword, Filename), Length(keyword)) = keyword then j := j+1;
end;
// If file has all keywords
if j = Keywords.Count-1 then ShowMessage(Filename);
// Find some words
end else
for k:=0 to Keywords.Count-1 do begin
if CaseSensitive then
keyword := Keywords.Strings[k]
else
keyword := lowercase(Keywords.Strings[k]);
if Copy(Filename, pos(keyword, Filename), Length(keyword)) = keyword then ShowMessage(Filename);
end;
end;
Keywords.Free;
CloseFile(Database);
if FindText then Extensions.Free;
// Only show results if search wasn't cancelled
if btnSearch.Caption <> 'Search' then begin
// Update StatusBar text
if FormResults.listResults.Items.Count-1 <> -1 then
if FormResults.listResults.Items.Count-1 = 0 then
FormResults.StatusBar.Panels.Items[0].Text := '1 file found!'
else
FormResults.StatusBar.Panels.Items[0].Text := IntToStr(FormResults.listResults.Items.Count-1 + 1) + ' files found!'
else
FormResults.StatusBar.Panels.Items[0].Text := 'No files found!';
end;
end;
function TFormResults.GetIEFavorites(const FavPath: string): TStrings;
var
SearchRec: TSearchRec;
Buffer: array[0..2047] of Char;
str: TStrings;
path, dir, filename: string;
found: Integer;
begin
// Get all favorites name
str := TStringList.Create;
try
path := FavPath + '\*.url';
dir := ExtractFilepath(path);
found := FindFirst(path, faAnyFile, SearchRec);
while found = 0 do begin
filename := Copy(SearchRec.Name, 0, Length(SearchRec.Name)-4);
str.Add(filename);
found := FindNext(searchrec) ;
end;
found := FindFirst(dir + '\*.*', faAnyFile, SearchRec);
while found=0 do begin
if ((SearchRec.Attr and faDirectory) > 0) and (SearchRec.Name[1] <> '.') then
GetIEFavorites(dir + '\' + SearchRec.name);
found := FindNext(SearchRec);
end;
FindClose(SearchRec);
except end;
// Result of the function is the list of all favorites names
Result := Str;
end;
///////////////////////////////////////////////////////////////////////////////
// //
// END - Search functions - "The File Seeker" //
// //
///////////////////////////////////////////////////////////////////////////////
// Sort ListView by column
function SortByColumn(Item1, Item2: TListItem; Data: integer): integer; stdcall;
begin
if Data = 0 then
Result := AnsiCompareText(Item1.Caption, Item2.Caption)
else
Result := AnsiCompareText(Item1.SubItems[Data-1], Item2.SubItems[Data-1]);
if not Ascending then Result := -Result;
end;
procedure TFormResults.lblBackMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
lblBack.Font.Style := lblBack.Font.Style+[fsUnderline];
end;
procedure TFormResults.FormMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
lblBack.Font.Style := lblBack.Font.Style-[fsUnderline];
end;
procedure TFormResults.lblBackClick(Sender: TObject);
begin
// Cancel search if it's running
if btnSearch.Caption <> 'Search' then
btnSearch.Caption := 'Search';
// Move search values to main window
FormMain.editKeywords.Text := editKeywords.Text;
FormMain.editText.Text := editText.Text;
FormMain.editExtension.Text := editExtension.Text;
FormMain.cbFindAll.Checked := cbFindAll.Checked;
FormMain.cbCase.Checked := cbCase.Checked;
Hide;
FormMain.Show;
end;
procedure TFormResults.editTextChange(Sender: TObject);
begin
if editText.Text = '' then
editExtension.Enabled := True
else begin
editExtension.Enabled := False;
editExtension.Text := '*.*';
end;
end;
procedure TFormResults.btnSearchClick(Sender: TObject);
begin
if btnSearch.Caption = 'Search' then
Thread.Execute(Self)
else
btnSearch.Caption := 'Search';
end;
procedure TFormResults.Openfile1Click(Sender: TObject);
var
FileName: string;
i: integer;
begin
i := listResults.ItemIndex;
FileName := listResults.Items.Item[i].SubItems.Strings[1] + listResults.Items.Item[i].Caption;
ShellExecute(Handle, 'open', PChar(FileName), nil, nil, SW_SHOW);
end;
procedure TFormResults.Opendirectory1Click(Sender: TObject);
var
Dir: string;
i: integer;
begin
i := listResults.ItemIndex;
Dir := listResults.Items.Item[i].SubItems.Strings[1];
ShellExecute(Handle, 'open', PChar(Dir), nil, nil, SW_SHOW);
end;
procedure TFormResults.listResults1Click(Sender: TObject);
begin
if listResults.ItemIndex <> -1 then begin
Openfile1.Enabled := True;
Opendirectory1.Enabled := True;
end else begin
Openfile1.Enabled := False;
Opendirectory1.Enabled := False;
end;
end;
procedure TFormResults.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Application.Terminate;
end;
procedure TFormResults.PopupMenu1Popup(Sender: TObject);
begin
// If there's a selected item enable options
if listResults.ItemIndex <> -1 then begin
Openfile1.Enabled := True;
Opendirectory1.Enabled := True;
end else begin
Openfile1.Enabled := False;
Opendirectory1.Enabled := False;
end;
end;
procedure TFormResults.listResultsColumnClick(Sender: TObject;
Column: TListColumn);
begin
if Column.Index = LastSortedColumn then
Ascending := not Ascending
else
LastSortedColumn := Column.Index;
listResults.CustomSort(@SortByColumn, Column.Index);
end;
procedure TFormResults.FormCreate(Sender: TObject);
var
TFile: TextFile;
begin
IndexFile := FormMain.IndexFile;
ExtFile := FormMain.ExtFile;
// Check if configuration file exists and read data
if FileExists(ExtFile) then begin
AssignFile(TFile, ExtFile);
Reset(TFile);
ReadLn(TFile, Ext);
CloseFile(TFile);
end else begin
// If not exists, create new configuration file
FormResults.Ext := '.doc,.wri,.txt,.rtf';
AssignFile(TFile, ExtFile);
ReWrite(TFile);
WriteLn(TFile, Ext);
CloseFile(TFile);
end;
cbDrives.Items := FormMain.cbDrives.Items;
LastSortedColumn := -1;
Ascending := True;
end;
procedure TFormResults.imgFirefoxClick(Sender: TObject);
begin
ShellExecute(Handle, 'open', 'http://www.getfirefox.com', nil, nil, 1);
end;
procedure TFormResults.btnBrowseClick(Sender: TObject);
begin
if BrowseDir.Execute then cbDrives.Text := BrowseDir.Directory;
end;
procedure TFormResults.ThreadExecute(Sender: TObject; params: Pointer);
var
SearchPath: string;
FindText: boolean;
begin
StatusBar.Panels.Items[0].Text := 'Searching files... Please wait';
btnSearch.Caption := 'Cancel';
if editText.Text = '' then FindText := False else FindText := True;
if cbSearchAll.Checked then SearchPath := '' else SearchPath := cbDrives.Text;
FindFiles(editKeywords.Text, editText.Text, editExtension.Text, cbDrives.Text, FindText, cbFindAll.Checked, cbCase.Checked);
btnSearch.Caption := 'Search';
end;
procedure TFormResults.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then btnSearch.Click;
end;
procedure TFormResults.cbSearchAllClick(Sender: TObject);
begin
if cbSearchAll.Checked then begin
cbDrives.Enabled := False;
btnBrowse.Enabled := False;
end else begin
cbDrives.Enabled := True;
btnBrowse.Enabled := True;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -