This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
PackageLoadThread.pas
110 lines (100 loc) · 2.72 KB
/
PackageLoadThread.pas
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
{ **
DelphiPI (Delphi Package Installer)
Author : ibrahim dursun (ibrahimdursun gmail)
License : GNU General Public License 2.0
** }
unit PackageLoadThread;
interface
uses Classes, SysUtils, Generics.Collections, PackageInfo, TreeNodes, PackageInfoFactory;
type
TPackageLoadThread = class(TThread)
private
fPackageInfoFactory: TPackageInfoFactory;
fActive: Boolean;
fList: TList<TTreeNode>;
fDirectory: string;
fPattern: string;
procedure LoadPackageInformations(const directory: string);
protected
procedure Execute; override;
procedure Search(const folder: String);
public
constructor Create(directory: string; pattern: string; list: TList<TTreeNode>);
destructor Destroy; override;
property Active: Boolean read fActive write fActive;
end;
implementation
uses Dialogs, JclFileUtils;
{ TPackageLoadThread }
constructor TPackageLoadThread.Create(directory: string; pattern: string; list: TList<TTreeNode>);
begin
inherited Create(true);
Assert(Assigned(list), 'List cannot be null');
fList := list;
fPackageInfoFactory := TPackageInfoFactory.Create;
fDirectory := directory;
fPattern := pattern;
end;
destructor TPackageLoadThread.Destroy;
begin
fPackageInfoFactory.Free;
inherited;
end;
procedure TPackageLoadThread.Execute;
begin
inherited;
fActive := true;
try
try
Search(fDirectory);
except
on e: Exception do
ShowMessage(e.Message);
end;
finally
fActive := false;
end;
end;
procedure TPackageLoadThread.LoadPackageInformations(const directory: string);
var
sr: TSearchRec;
packageNode: TPackageTreeNode;
begin
if FindFirst(PathAppend(directory, fPattern), faAnyFile, sr) = 0 then
begin
try
repeat
if UpperCase(ExtractFileExt(sr.Name)) = '.DPK' then
begin
packageNode := TPackageTreeNode.Create(fPackageInfoFactory.CreatePackageInfo(PathAppend(directory, sr.Name)));
if not fList.Contains(packageNode) then
fList.Add(packageNode);
end;
until (FindNext(sr) <> 0) and Active;
finally
FindClose(sr);
end;
end;
end;
procedure TPackageLoadThread.Search(const folder: String);
var
directoryList: TStringList;
directory, dir: string;
begin
directoryList := TStringList.Create;
try
BuildFileList(PathAppend(folder, '*.*'), faAnyFile, directoryList);
for directory in directoryList do
begin
if not Active then
Break;
dir := PathAppend(folder, directory);
if IsDirectory(dir) then
Search(dir);
end;
LoadPackageInformations(folder);
finally
directoryList.Free;
end;
end;
end.