-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.pas
More file actions
217 lines (189 loc) · 5.11 KB
/
Main.pas
File metadata and controls
217 lines (189 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Menus, ShellAPI, CommCtrl, CommDlg, ShlObj,
ActiveX, Engine, ExtCtrls, Types;
const
StopBtnFlag_Default = 0;
StopBtnFlag_Raised = 1;
StopBtnFlag_DefaultMessage = 'Stop';
StopBtnFlag_RaisedMessage = 'Stopping...';
type
TForm1 = class(TForm)
lvResults: TListView;
StatusBar1: TStatusBar;
MainPanel: TPanel;
lblExpression: TLabel;
lblFolders: TLabel;
ExpressionMemo: TMemo;
btnSearch: TButton;
lvFolders: TListView;
btnStop: TButton;
Folder_PopupMenu: TPopupMenu;
Menu_Add: TMenuItem;
Menu_Modify: TMenuItem;
Menu_Delete: TMenuItem;
txtMaxFileSize: TLabeledEdit;
btnAddFolder: TButton;
btnDelFolder: TButton;
procedure Menu_AddClick(Sender: TObject);
procedure Menu_ModifyClick(Sender: TObject);
procedure Menu_DeleteClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnSearchClick(Sender: TObject);
procedure lvResultsDblClick(Sender: TObject);
procedure btnStopClick(Sender: TObject);
private
{ Private declarations }
Folders: TStringList;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Settings, IOUtils;
{$R *.dfm}
function BrowseCallbackProc(HWND: HWND; uMsg: uint; lp: lParam; pData: wParam)
: integer; stdcall;
begin
if (uMsg = BFFM_INITIALIZED) then
SendMessage(HWND, BFFM_SETSELECTION, 1, pData);
result := 0;
end;
/// <returns>
/// Full path to selected folder or '' if error or user cancelled the selection
/// </returns>
function SelectFolderDialog(hwndParent: HWND; initialDir: PWideChar; Title: PChar): String;
Var
bi: TBROWSEINFO;
resultPIDL: PITEMIDLIST;
_Result: array [0 .. MAX_PATH] of Char;
begin
bi.hwndOwner := hwndParent;
bi.pidlRoot := nil;
bi.pszDisplayName := @_Result[0];
bi.lpszTitle := Title;
bi.ulFlags := BIF_STATUSTEXT or BIF_RETURNONLYFSDIRS or BIF_NEWDIALOGSTYLE;
bi.lpfn := BrowseCallbackProc;
bi.lParam := lParam(initialDir);
bi.iImage := 0;
resultPIDL := SHBrowseForFolder(bi);
try
if (resultPIDL <> nil) then
begin
if SHGetPathFromIDList(resultPIDL, @_Result[0]) then
begin
SetString(Result, PChar(@_Result[0]), StrLen(PChar(@_Result[0])));
Exit;
end;
end;
Result := '';
finally
CoTaskMemFree(resultPIDL);
end;
end;
procedure TForm1.btnSearchClick(Sender: TObject);
Var
i: integer;
TheEngine: TEngine;
begin
btnStop.Tag := StopBtnFlag_Default;
btnStop.Enabled := True;
btnSearch.Enabled := False;
lvResults.Clear;
TheEngine := TEngine.Create;
try
TheEngine.Expression := ExpressionMemo.Text;
TheEngine.MaxFileSize := StrToInt(txtMaxFileSize.Text) * 1024 * 1024;
TheEngine.Callback :=
function(State: TProcessState; _File, Dir: String): Boolean
begin
case State of
Found:
with lvResults.Items.Add do
begin
Caption := _File;
SubItems.Add(Dir);
end;
CurrentFile:
StatusBar1.Panels[0].Text := Dir;
end;
Result := (btnStop.Tag = StopBtnFlag_Default);
Application.ProcessMessages;
end;
for i := 0 to Folders.Count - 1 do
begin
TheEngine.ProcessDirectory(IncludeTrailingPathDelimiter(Folders[i]),
TSearchOption.soAllDirectories);
end;
finally
TheEngine.Destroy;
StatusBar1.Panels[0].Text := '';
btnStop.Caption := StopBtnFlag_DefaultMessage;
btnStop.Enabled := False;
btnSearch.Enabled := True;
end;
end;
procedure TForm1.btnStopClick(Sender: TObject);
begin
btnStop.Tag := StopBtnFlag_Raised;
btnStop.Caption := StopBtnFlag_RaisedMessage;
btnStop.Enabled := False;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Folders.SaveToFile(INIfile);
Folders.Destroy;
end;
procedure TForm1.FormCreate(Sender: TObject);
Var
i: integer;
begin
Folders := TStringList.Create(True);
try
Folders.LoadFromFile(INIfile);
for i := 0 to Folders.Count - 1 do
lvFolders.AddItem(Folders[i], nil);
except
end;
end;
procedure TForm1.lvResultsDblClick(Sender: TObject);
begin
with lvResults.Selected do
ShellExecute(Handle, 'open', PChar(TPath.Combine(SubItems[0], Caption)), nil,
nil, SW_SHOW);
end;
procedure TForm1.Menu_AddClick(Sender: TObject);
Var
Folder: String;
begin
Folder := SelectFolderDialog(Self.Handle, PChar(ExtractFileDir(ParamStr(0))),
'Select Dir');
if Folder = '' then
Exit;
lvFolders.AddItem(Folder, nil);
Folders.Add(Folder);
end;
procedure TForm1.Menu_DeleteClick(Sender: TObject);
begin
Folders.Delete(lvFolders.Selected.Index);
lvFolders.DeleteSelected;
end;
procedure TForm1.Menu_ModifyClick(Sender: TObject);
Var
Folder: String;
begin
Folder := SelectFolderDialog(Self.Handle, PChar(lvFolders.Selected.Caption),
'Select Dir');
if Folder = '' then
Exit;
with lvFolders.Selected do
begin
Caption := Folder;
Folders[Index] := Folder;
end;
end;
end.