forked from Ox18/cheatmatrix-gunbound
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkyIO.pas
More file actions
284 lines (243 loc) · 5.7 KB
/
SkyIO.pas
File metadata and controls
284 lines (243 loc) · 5.7 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
unit SkyIO;
interface
uses windows, classes, sysutils, forms;
type
PFound = ^TFound;
TFound = Record
FileName: AnsiString;
FileDir: AnsiString;
FileExt: AnsiString;
Path: AnsiString;
end;
TExtension = class
constructor Create;
private
fList: TStrings;
fIndex: integer;
Function GetExtension(Index: integer): AnsiString;
Procedure SetExtension(Index: integer; Extension: AnsiString);
public
Procedure Add(Ext: AnsiString);
Function CurrentExt: AnsiString;
Property Extension[index: integer]: AnsiString read GetExtension write SetExtension;
Procedure Reset;
Function Next: boolean;
Function Prev: boolean;
Function Count: integer;
Procedure Clear;
Function Eof: boolean;
end;
TSearchResult = class
constructor Create;
private
fResults: TList;
fIndex: integer;
Function GetFound(Index: integer): TFound;
Procedure SetFound(Index: integer; Found: TFound);
public
Property Index_:integer read fIndex;
Procedure Add(Path: AnsiString);
Function CurrentResult: TFound;
Property ResultValue[index: integer]: TFound read GetFound write SetFound;
Procedure Reset;
Function Next: boolean;
Function Prev: boolean;
Function Count: integer;
Procedure Clear;
Function Eof: boolean;
end;
TSearcher = Class
constructor Create;
private
fDir: AnsiString;
fExt: TExtension;
fRes: TSearchResult;
fStop: boolean;
fSub: boolean;
procedure Search(Dir, Ext: AnsiString);
public
Property Dir: AnsiString read fDir write fDir;
Property SearchOnSubDirs: boolean read fSub write fSub;
Property Results: TSearchResult read fRes write fRes;
Property Extensions: TExtension read fExt write fExt;
Procedure StartSearch;
Procedure StopSearch;
end;
implementation
{ TExtension }
procedure TExtension.Add(Ext: AnsiString);
begin
FList.Add(ext);
end;
procedure TExtension.Clear;
begin
flist.Clear;
end;
function TExtension.Count: integer;
begin
result := flist.Count;
end;
constructor TExtension.Create;
begin
fList := TStringList.Create;
fIndex := 0;
end;
function TExtension.CurrentExt: AnsiString;
begin
result := Extension[findex];
end;
function TExtension.Eof: boolean;
begin
result := (fIndex >= fList.Count) or (fIndex<0);
end;
function TExtension.GetExtension(Index: integer): AnsiString;
begin
result := flist[index];
end;
function TExtension.Next: boolean;
begin
inc(fIndex);
result := Eof;
end;
function TExtension.Prev: boolean;
begin
dec(fIndex);
result := Eof;
end;
procedure TExtension.Reset;
begin
fIndex := 0;
end;
procedure TExtension.SetExtension(Index: integer; Extension: AnsiString);
begin
flist[index] := Extension;
end;
{ TSearchResult }
procedure TSearchResult.Add(Path: AnsiString);
var P: PFound;
S: AnsiString;
begin
P := new(PFound);
S := ExtractFileName(Path);
P^.FileName := copy( S, 1, Length(S)-Length(ExtractFileExt(Path)));
P^.FileExt := ExtractFileExt(Path);
P^.Path := Path;
P^.FileDir := ExtractFileDir(Path);
fResults.Add(P);
end;
procedure TSearchResult.Clear;
begin
fResults.Clear;
end;
function TSearchResult.Count: integer;
begin
result := fResults.Count;
end;
constructor TSearchResult.Create;
begin
fResults := TList.Create;
fIndex := 0;
end;
function TSearchResult.CurrentResult: TFound;
begin
result := ResultValue[findex];
end;
function TSearchResult.Eof: boolean;
begin
result := (fIndex >= fResults.Count) or (fIndex < 0);
end;
function TSearchResult.GetFound(Index: integer): TFound;
begin
result := TFound(fResults.Items[index]^);
end;
function TSearchResult.Next: boolean;
begin
inc(fIndex);
Result := Eof;
end;
function TSearchResult.Prev: boolean;
begin
dec(fIndex);
Result := Eof;
end;
procedure TSearchResult.Reset;
begin
fIndex := 0;
end;
procedure TSearchResult.SetFound(Index: integer; Found: TFound);
var P:PFound;
begin
P := new(PFound);
P^ := Found;
fResults.Items[index] := P;
end;
{ TSearcher }
constructor TSearcher.Create;
begin
fExt := TExtension.Create;
fRes := TSearchResult.Create;
fStop := false;
fSub := true;
end;
procedure TSearcher.Search(Dir, Ext: AnsiString);
var
Diretorio,Nome : AnsiString;
SearchRec : TSearchRec;
ListaDirs : TStringList;
Done : Integer;
i : Integer;
begin
Diretorio := Dir;
Nome := Ext;
Application.ProcessMessages;
Done := FindFirst(Dir+ext,0,SearchRec);
while Done = 0 do begin
if fStop then
exit;
Application.ProcessMessages;
Results.Add(Diretorio+SearchRec.Name);
Done := FindNext(SearchRec);
end;
FindClose(SearchRec);
ListaDirs := TStringList.Create;
if fSub then
try
Done := FindFirst(Diretorio+'*.*', faDirectory,SearchRec);
while Done = 0 do begin
if fStop then
exit;
Application.ProcessMessages;
if ((SearchRec.Attr and faDirectory) <> 0) and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
ListaDirs.Add(Diretorio+SearchRec.Name+'\');
Done := FindNext(SearchRec);
end;
FindClose(SearchRec);
// pesquisa em todos diretorios encontrados
for i := 0 to ListaDirs.Count-1 do
begin
if fStop then
exit;
Application.ProcessMessages;
Search(ListaDirs[i], Ext);
end;
finally
ListaDirs.Free;
end;
end;
procedure TSearcher.StartSearch;
begin
fStop := false;
if Dir[length(dir)] <> '\' then
Dir := Dir + '\';
Extensions.Reset;
while not Extensions.Eof do
begin
Search(dir,Extensions.CurrentExt);
Extensions.Next;
end;
end;
procedure TSearcher.StopSearch;
begin
fStop := true;
end;
end.