forked from Memnarch/Delphinus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDN.ToolsApi.Extension.pas
More file actions
355 lines (310 loc) · 9.86 KB
/
DN.ToolsApi.Extension.pas
File metadata and controls
355 lines (310 loc) · 9.86 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.ToolsApi.Extension;
interface
uses
Classes,
Windows,
Registry,
IniFiles,
Generics.Collections,
ToolsApi,
DN.Compiler.Intf,
DN.ToolsApi.Extension.Intf;
type
TDNEnvironmentOptions = class(TInterfacedObject, IDNEnvironmentOptions)
private
FPlatform: TDNCompilerPlatform;
FUpdateLevel: Integer;
FOnChanged: TNotifyEvent;
function GetPlatform: TDNCompilerPlatform;
function GetBPLOutput: string;
function GetBrowsingPath: string;
function GetDCPOutput: string;
function GetSearchPath: string;
procedure SetBPLOutput(const Value: string);
procedure SetBrowsingPath(const Value: string);
procedure SetDCPOutput(const Value: string);
procedure SetSearchPath(const Value: string);
protected
FBrowsingPathName: string;
FSearchPathName: string;
FBPLOutputName: string;
FDCPOutputName: string;
function ReadString(const AName: string): string; virtual; abstract;
procedure WriteString(const AName, AValue: string); virtual; abstract;
procedure Changed(); virtual;
public
constructor Create(APlatform: TDNCompilerPlatform);
procedure BeginUpdate();
procedure EndUpdate();
property Platform: TDNCompilerPlatform read GetPlatform;
property BrowingPath: string read GetBrowsingPath write SetBrowsingPath;
property SearchPath: string read GetSearchPath write SetSearchPath;
property BPLOutput: string read GetBPLOutput write SetBPLOutput;
property DCPOutput: string read GetDCPOutput write SetDCPOutput;
property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
end;
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;
TDNEnvironmentOptionsService = class(TInterfacedObject, IDNEnvironmentOptionsService)
private
FSupportedPlatforms: TDNCompilerPlatforms;
FOptions: TList<IDNEnvironmentOptions>;
FUpdateLevel: Integer;
FChanges: Integer;
function GetOptions(
const APlatform: TDNCompilerPlatform): IDNEnvironmentOptions;
function GetSupportedPlatforms: TDNCompilerPlatforms;
procedure LoadPlatforms();
procedure HandleChanged(Sender: TObject);
public
constructor Create();
destructor Destroy(); override;
procedure BeginUpdate();
procedure EndUpdate();
property Options[const APlatform: TDNCompilerPlatform]: IDNEnvironmentOptions read GetOptions;
property SupportedPlatforms: TDNCompilerPlatforms read GetSupportedPlatforms;
end;
implementation
uses
IOUtils,
DN.ToolsApi,
RTTI;
const
CLibraryKey = 'Library';
CPlatformKeys: array[cpWin32..cpOSX32] of string = ('Win32', 'Win64', 'OSX32');
{ TDNEnvironmentOptionsService }
procedure TDNEnvironmentOptionsService.BeginUpdate;
begin
Inc(FUpdateLevel);
end;
constructor TDNEnvironmentOptionsService.Create;
begin
inherited;
FOptions := TList<IDNEnvironmentOptions>.Create();
LoadPlatforms();
end;
destructor TDNEnvironmentOptionsService.Destroy;
begin
FOptions.Free;
inherited;
end;
procedure TDNEnvironmentOptionsService.EndUpdate;
begin
if FUpdateLevel > 0 then
begin
Dec(FUpdateLevel);
if (FUpdateLevel = 0) and (FChanges > 0) then
begin
FChanges := 0;
end;
end;
end;
function TDNEnvironmentOptionsService.GetOptions(
const APlatform: TDNCompilerPlatform): IDNEnvironmentOptions;
var
LOption: IDNEnvironmentOptions;
begin
Result := nil;
for LOption in FOptions do
begin
if LOption.Platform = APlatform then
Exit(LOption);
end;
end;
function TDNEnvironmentOptionsService.GetSupportedPlatforms: TDNCompilerPlatforms;
begin
Result := FSupportedPlatforms;
end;
procedure TDNEnvironmentOptionsService.HandleChanged(Sender: TObject);
begin
Inc(FChanges);
end;
procedure TDNEnvironmentOptionsService.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);
LOptions.OnChanged := HandleChanged;
FOptions.Add(LOptions);
FSupportedPlatforms := [cpWin32];
end
else
begin
//we are on a multiplatform Delphi
FSupportedPlatforms := [];
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);
LOptions.OnChanged := HandleChanged;
FOptions.Add(LOptions);
FSupportedPlatforms := FSupportedPlatforms + [LPlatform];
end;
end;
end;
end;
end;
finally
LReg.Free;
end;
end;
{ TDNEnvironmentOptions }
procedure TDNEnvironmentOptions.BeginUpdate;
begin
Inc(FUpdateLevel);
end;
procedure TDNRegistryEnvironmentOptions.Changed;
var
LContext: TRttiContext;
LType: TRttiType;
begin
LType := LContext.GetType(FRegistryOptions.ClassType);
LType.GetMethod('SavePropValues').Invoke(FRegistryOptions, []);
inherited;
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;
procedure TDNEnvironmentOptions.Changed;
begin
if Assigned(FOnChanged) then
FOnChanged(Self);
end;
constructor TDNEnvironmentOptions.Create(APlatform: TDNCompilerPlatform);
begin
inherited Create();
FPlatform := APlatform;
end;
procedure TDNEnvironmentOptions.EndUpdate;
begin
if FUpdateLevel > 0 then
begin
Dec(FUpdateLevel);
if FUpdateLevel = 0 then
Changed();
end;
end;
function TDNEnvironmentOptions.GetBPLOutput: string;
begin
Result := ReadString(FBPLOutputName);
end;
function TDNEnvironmentOptions.GetBrowsingPath: string;
begin
Result := ReadString(FBrowsingPathName);
end;
function TDNEnvironmentOptions.GetDCPOutput: string;
begin
Result := ReadString(FDCPOutputName);
end;
function TDNEnvironmentOptions.GetPlatform: TDNCompilerPlatform;
begin
Result := FPlatform;
end;
function TDNEnvironmentOptions.GetSearchPath: string;
begin
Result := ReadString(FSearchPathName);
end;
function TDNRegistryEnvironmentOptions.ReadString(const AName: string): string;
begin
Result := FRegistry.ReadString(FRegstryKey, AName, '');
end;
procedure TDNEnvironmentOptions.SetBPLOutput(const Value: string);
begin
WriteString(FBPLOutputName, Value);
end;
procedure TDNEnvironmentOptions.SetBrowsingPath(const Value: string);
begin
WriteString(FBrowsingPathName, Value);
end;
procedure TDNEnvironmentOptions.SetDCPOutput(const Value: string);
begin
WriteString(FDCPOutputName, Value);
end;
procedure TDNEnvironmentOptions.SetSearchPath(const Value: string);
begin
WriteString(FSearchPathName, Value);
end;
procedure TDNRegistryEnvironmentOptions.WriteString(const AName, AValue: string);
begin
FRegistry.WriteString(FRegstryKey, AName, AValue);
if FUpdateLevel = 0 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;
initialization
GDelphinusIDEServices := TDNEnvironmentOptionsService.Create();
finalization
GDelphinusIDEServices := nil;
end.