-
Notifications
You must be signed in to change notification settings - Fork 64
/
DN.EnvironmentOptions.Registry.pas
113 lines (98 loc) · 2.65 KB
/
DN.EnvironmentOptions.Registry.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
111
112
113
unit DN.EnvironmentOptions.Registry;
interface
uses
Registry,
Generics.Collections,
DN.Types,
DN.EnvironmentOptions;
type
TDNRegistryEnvironmentOptions = class(TDNEnvironmentOptions)
private
FRegistry: TRegistry;
FKey: string;
protected
function ReadString(const AName: string): string; override;
procedure WriteString(const AName: string; const AValue: string); override;
public
constructor Create(const ARegistryKey: string; APlatform: TDNCompilerPlatform); reintroduce;
destructor Destroy; override;
end;
TDNRegistryEnvironmentOptionsService = class(TDNEnvironmentOptionsService)
public
constructor Create(const ARegistryRoot: string; ASupportedPlatforms: TDNCompilerPlatforms); reintroduce;
end;
implementation
uses
Windows,
IOUtils,
DN.Utils,
DN.EnvironmentOptions.Intf;
{ TDNRegistryEnvironmentOptionsService }
constructor TDNRegistryEnvironmentOptionsService.Create(
const ARegistryRoot: string; ASupportedPlatforms: TDNCompilerPlatforms);
var
LPlatform: TDNCompilerPlatform;
LOption: IDNEnvironmentOptions;
LLibKey: string;
begin
inherited Create;
LLibKey := TPath.Combine(ARegistryRoot, 'Library');
if ASupportedPlatforms = [cpWin32] then
begin
LOption := TDNRegistryEnvironmentOptions.Create(LLibKey, cpWin32);
AddOption(LOption);
end
else
begin
for LPlatform in ASupportedPlatforms do
begin
LOption := TDNRegistryEnvironmentOptions.Create(TPath.Combine(LLibKey, TDNCompilerPlatformName[LPlatform]), LPlatform);
AddOption(LOption);
end;
end;
end;
{ TDNRegistryEnvironmentOptions }
constructor TDNRegistryEnvironmentOptions.Create(const ARegistryKey: string;
APlatform: TDNCompilerPlatform);
begin
inherited Create(APlatform);
FSearchPathName := 'Search Path';
FBPLOutputName := 'Package DPL Output';
FBrowsingPathName := 'Browsing Path';
FDCPOutputName := 'Package DCP Output';
FKey := ARegistryKey;
FRegistry := TRegistry.Create();
FRegistry.RootKey := HKEY_CURRENT_USER;
FRegistry.Access := FRegistry.Access or KEY_WOW64_64KEY;
end;
destructor TDNRegistryEnvironmentOptions.Destroy;
begin
FRegistry.Free();
inherited;
end;
function TDNRegistryEnvironmentOptions.ReadString(const AName: string): string;
begin
if FRegistry.OpenKey(FKey, False) then
begin
try
Result := FRegistry.ReadString(AName);
finally
FRegistry.CloseKey();
end
end
else
Result := '';
end;
procedure TDNRegistryEnvironmentOptions.WriteString(const AName,
AValue: string);
begin
if FRegistry.OpenKey(FKey, True) then
begin
try
FRegistry.WriteString(AName, AValue);
finally
FRegistry.CloseKey();
end;
end;
end;
end.