-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathDN.EnvironmentOptions.IDE.pas
178 lines (156 loc) · 4.91 KB
/
DN.EnvironmentOptions.IDE.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
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
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.EnvironmentOptions.IDE;
interface
uses
Classes,
Windows,
Registry,
IniFiles,
Generics.Collections,
ToolsApi,
DN.Types,
DN.EnvironmentOptions;
type
TDNRegistryEnvironmentOptions = class(TDNEnvironmentOptions)
private
FRegstryKey: string;
FRegistryOptions: TObject;
FRegistry: TMemIniFile;
protected
function ReadString(const AName: string): string; override;
procedure WriteString(const AName, AValue: string); override;
procedure Changed; override;
public
constructor Create(APlatform: TDNCompilerPlatform; const ARegistryKey: string; const ARegistryOptions : TObject);
end;
TDNOTAEnvironmentOptions = class(TDNEnvironmentOptions)
private
FOptions: IOTAOptions;
protected
function ReadString(const AName: string): string; override;
procedure WriteString(const AName: string; const AValue: string); override;
public
constructor Create(APlatform: TDNCompilerPlatform);
end;
TDNIDEEnvironmentOptionsService = class(TDNEnvironmentOptionsService)
private
procedure LoadPlatforms();
public
constructor Create();
end;
implementation
uses
IOUtils,
DN.ToolsApi,
RTTI;
const
CLibraryKey = 'Library';
//these maybe different than the names used by the Compiler.
//for example it is Android for the compiler, but Android32 for the registry
CPlatformKeys: array[cpWin32..cpLinux64] of string = ('Win32', 'Win64', 'OSX32', 'Android32', 'iOSDevice32', 'iOSDevice64', 'Linux64');
{ TDNIDEEnvironmentOptionsService }
constructor TDNIDEEnvironmentOptionsService.Create;
begin
inherited;
LoadPlatforms();
end;
procedure TDNIDEEnvironmentOptionsService.LoadPlatforms;
var
LService: IOTAServices;
LReg: TRegistry;
LBase, LLibraryKey, LPlatformKey: string;
LOptions: TDNEnvironmentOptions;
LPlatform: TDNCompilerPlatform;
LRegistryOptions: TObject;
begin
LService := BorlandIDEservices as IOTAServices;
LBase := LService.GetBaseRegistryKey();
LReg := TRegistry.Create();
try
LReg.RootKey := HKEY_CURRENT_USER;
LLibraryKey := TPath.Combine(LBase ,CLibraryKey);
if LReg.OpenKey(LLibraryKey, False) then
begin
//we are on a Win32-Only Delphi
if CompilerVersion <= 22 then
begin
LOptions := TDNOTAEnvironmentOptions.Create(cpWin32);
AddOption(LOptions);
end
else
begin
//we are on a multiplatform Delphi
for LPlatform := Low(CPlatformKeys) to High(CPlatformKeys) do
begin
if LReg.KeyExists(CPlatformKeys[LPlatform]) then
begin
LPlatformKey := TPath.Combine(LLibraryKey, CPlatformKeys[LPlatform]);
LRegistryOptions := GetRegistryOptionsObject(GetEnvironmentOptionObject(), LPlatformKey);
if Assigned(LRegistryOptions) then
begin
LOptions := TDNRegistryEnvironmentOptions.Create(LPlatform, LPlatformKey, LRegistryOptions);
AddOption(LOptions);
end;
end;
end;
end;
end;
finally
LReg.Free;
end;
end;
constructor TDNRegistryEnvironmentOptions.Create(APlatform: TDNCompilerPlatform; const ARegistryKey: string; const ARegistryOptions : TObject);
begin
inherited Create(APlatform);
FSearchPathName := 'Search Path';
FBPLOutputName := 'Package DPL Output';
FBrowsingPathName := 'Browsing Path';
FDCPOutputName := 'Package DCP Output';
FRegstryKey := ARegistryKey;
FRegistryOptions := ARegistryOptions;
FRegistry := GetRegistryOptionsMemIni(FRegistryOptions);
end;
function TDNRegistryEnvironmentOptions.ReadString(const AName: string): string;
begin
Result := FRegistry.ReadString(FRegstryKey, AName, '');
end;
procedure TDNRegistryEnvironmentOptions.Changed;
var
LContext: TRttiContext;
LType: TRttiType;
begin
LType := LContext.GetType(FRegistryOptions.ClassType);
LType.GetMethod('SavePropValues').Invoke(FRegistryOptions, []);
inherited;
end;
procedure TDNRegistryEnvironmentOptions.WriteString(const AName, AValue: string);
begin
FRegistry.WriteString(FRegstryKey, AName, AValue);
if not IsUpdating then
Changed();
end;
{ TDNOTAEnvironmentOptions }
constructor TDNOTAEnvironmentOptions.Create(APlatform: TDNCompilerPlatform);
begin
inherited;
FSearchPathName := 'LibraryPath';
FBPLOutputName := 'PackageDPLOutput';
FBrowsingPathName := 'BrowsingPath';
FDCPOutputName := 'PackageDCPOutput';
FOptions := (BorlandIDEServices as IOTAServices).GetEnvironmentOptions;
end;
function TDNOTAEnvironmentOptions.ReadString(const AName: string): string;
begin
Result := FOptions.Values[AName];
end;
procedure TDNOTAEnvironmentOptions.WriteString(const AName, AValue: string);
begin
FOptions.Values[AName] := AValue;
end;
end.