forked from Memnarch/Delphinus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DN.DelphiInstallation.Provider.pas
104 lines (92 loc) · 2.44 KB
/
DN.DelphiInstallation.Provider.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
unit DN.DelphiInstallation.Provider;
interface
uses
DN.DelphiInstallation.Provider.Intf,
DN.DelphiInstallation.Intf,
Generics.Collections;
type
TDNDelphiInstallationProvider = class(TInterfacedObject, IDNDelphiInstallationProvider)
private
FInstallations: TList<IDNDelphiInstallation>;
FIgnoredEditions: TArray<string>;
function GetInstallations: TList<IDNDelphiInstallation>;
procedure LoadInstallations;
procedure RemoveIgnoredInstallations;
public
constructor Create(const AIgnoredEditions: array of string);
destructor Destroy; override;
property Installations: TList<IDNDelphiInstallation> read GetInstallations;
end;
implementation
uses
Classes,
Registry,
IOUtils,
StrUtils,
DN.DelphiInstallation;
{ TDNDelphiInstallationInfo }
constructor TDNDelphiInstallationProvider.Create(
const AIgnoredEditions: array of string);
var
i: Integer;
begin
inherited Create();
SetLength(FIgnoredEditions, Length(AIgnoredEditions));
for i := 0 to Length(FIgnoredEditions) - 1 do
FIgnoredEditions[i] := AIgnoredEditions[i];
end;
destructor TDNDelphiInstallationProvider.Destroy;
begin
FInstallations.Free;
inherited;
end;
function TDNDelphiInstallationProvider.GetInstallations: TList<IDNDelphiInstallation>;
begin
if not Assigned(FInstallations) then
begin
FInstallations := TList<IDNDelphiInstallation>.Create();
LoadInstallations();
end;
Result := FInstallations;
end;
procedure TDNDelphiInstallationProvider.LoadInstallations;
var
LRegistry: TRegistry;
LInstallation: IDNDelphiInstallation;
LKeyNames: TStringList;
LKey: string;
const
CRootKey = 'Software\Embarcadero\BDS';
begin
LRegistry := TRegistry.Create();
LKeyNames := TStringList.Create();
try
if LRegistry.OpenKeyReadOnly(CRootKey) then
begin
LRegistry.GetKeyNames(LKeyNames);
for LKey in LKeyNames do
begin
LInstallation := TDNDelphInstallation.Create(TPath.Combine(CRootKey, LKey));
if LInstallation.Application <> '' then
begin
FInstallations.Add(LInstallation);
end;
end;
RemoveIgnoredInstallations();
end;
finally
LKeyNames.Free;
LRegistry.Free;
end;
end;
procedure TDNDelphiInstallationProvider.RemoveIgnoredInstallations;
var
i: Integer;
begin
for i := FInstallations.Count - 1 downto 0 do
begin
if AnsiIndexText(FInstallations[i].Edition, FIgnoredEditions) > -1 then
FInstallations.Delete(i);
end;
end;
end.