-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathDN.Installer.pas
927 lines (851 loc) · 30.4 KB
/
DN.Installer.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
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.Installer;
interface
uses
Classes,
Types,
SysUtils,
Generics.Collections,
DN.Types,
DN.Installer.Intf,
DN.Compiler.Intf,
DN.ProjectInfo.Intf,
DN.ProjectGroupInfo.Intf,
DN.JSonFile.Installation,
DN.JSonFile.Uninstallation,
DN.JSonFile.Info,
DN.Progress.Intf,
DN.ExpertService.Intf,
DN.VariableResolver.Compiler.Factory;
type
TDNInstaller = class(TInterfacedObject, IDNInstaller, IDNProgress)
private
FCompiler: IDNCompiler;
FExpertService: IDNExpertService;
FOnMessage: TMessageEvent;
FProgress: IDNProgress;
FTargetDirectory: string;
FHasPendingChanges: Boolean;
procedure ProcessPathes(const APathes: TArray<TSearchPath>; const ARootDirectory: string; APathType: TPathType);
procedure ProcessSourceFolders(const ASourceFolders: TArray<TFolder>; const ASourceDirectory, ATargetDirectory: string);
function ProcessProjects(const AProjects: TArray<TProject>; const ATargetDirectory: string): Boolean;
function ProcessProject(const AProject: IDNProjectInfo): Boolean;
function ProcessExperts(const AExperts: TArray<TExpert>): Boolean;
function ProcessRawFolders(const ARawFolders: TArray<TRawFolder>; const ASourceDirectory: string): Boolean;
function ProcessRawFolder(const ARawFolder, ASourceDirectory: string): Boolean;
function RegisterRawDesignBPLs(const ADesignBPLs: TArray<string>): Boolean;
function IsSupported(ACompiler_Min, ACompiler_Max: Integer): Boolean;
function FileMatchesFilter(const AFile: string; const AFilter: TStringDynArray): Boolean;
procedure ProcessLibPathes;
procedure Reset();
function GetOnMessage: TMessageEvent;
procedure SetOnMessage(const Value: TMessageEvent);
function GetSourceFolder(const ADirectory: string): string;
function UndecoratePath(const APath: string): string;
function LoadSupportedProjects(const ABaseDirectory: string; const AProjects: TArray<TProject>; ASupportedProjects: TList<IDNProjectInfo>): Boolean;
protected
FSearchPathes: string;
FBrowsingPathes: string;
FPackages: TList<TPackage>;
FExperts: TList<TInstalledExpert>;
FRawFiles: TStringList;
FVariableResolverFactory: TDNCompilerVariableResolverFacory;
procedure DoMessage(AType: TMessageType; const AMessage: string); virtual;
procedure CopyDirectory(const ASource, ATarget: string; AFileFilters: TStringDynArray; ARecursive: Boolean = False; ACopiedFiles: TStringList = nil); virtual;
procedure AddSearchPath(const ASearchPath: string; const APlatforms: TDNCompilerPlatforms); virtual;
procedure AddBrowsingPath(const ABrowsingPath: string; const APlatforms: TDNCompilerPlatforms); virtual;
procedure BeforeCompile(const AProjectFile: string); virtual;
procedure AfterCompile(const AProjectFile: string; const ALog: TStrings; ASuccessFull: Boolean); virtual;
function InstallBPL(const ABPL: string): Boolean; virtual;
function InstallExpert(const AExpert: string; AHotReload: Boolean): Boolean; virtual;
function CopyMetaData(const ASourceDirectory, ATargetDirectory: string): Boolean; virtual;
procedure CopyLicense(const ASourceDirectory, ATargetDirectory, ALicense: string); virtual;
function GetSupportedPlatforms: TDNCompilerPlatforms; virtual; abstract;
procedure ConfigureCompiler(const ACompiler: IDNCompiler); virtual;
function GetTargetDirectory: string; virtual;
function GetLibBaseDir: string; virtual;
function GetBinBaseDir: string; virtual;
function GetBPLDir(APlatform: TDNCompilerPlatform): string; virtual; abstract;
function GetDCPDir(APlatform: TDNCompilerPlatform): string; virtual; abstract;
function GetHasPendingChanges: Boolean; virtual;
function PrepareInstallationDirectory(const ATargetDirectory: string): Boolean; virtual;
function LoadInfo(const ADirectory: string; AInfo: TInfoFile): Boolean; virtual;
function ValidateInfoAndGetLicenceFiles(const ADirectory: string; out ALicenceFiles: TArray<string>): Boolean; virtual;
function LoadInstallation(const ADirectory: string; AInstallation: TInstallationFile): Boolean; virtual;
function ProcessInstallation(AInstallation: TInstallationFile;
const ASourceDirectory, ATargetDirectory: string; const ALicenceFiles: TArray<string>): Boolean; virtual;
procedure SaveUninstall(const ATargetDirectory: string); virtual;
function LoadProject(const AProjectFile: string; out AProject: IDNProjectInfo): Boolean; virtual;
function LoadProjectGroup(const AGroupFile: string; out AGroup: IDNProjectGroupInfo): Boolean; virtual;
//properties for interface redirection
property Progress: IDNProgress read FProgress implements IDNProgress;
public
constructor Create(const ACompiler: IDNCompiler;
const AVariableResolverFactory: TDNCompilerVariableResolverFacory;
const AExpertService: IDNExpertService = nil);
destructor Destroy(); override;
function Install(const ASourceDirectory, ATargetDirectory: string): Boolean; virtual;
property OnMessage: TMessageEvent read GetOnMessage write SetOnMessage;
property HasPendingChanges: Boolean read GetHasPendingChanges;
end;
implementation
uses
IOUtils,
StrUtils,
Masks,
DN.Utils,
DN.ProjectInfo,
DN.ProjectGroupInfo,
DN.Uninstaller.Intf,
DN.Progress,
DN.VariableResolver.Intf;
const
CLibDir = 'lib';
CBinDir = 'bin';
CBPLDir = 'bpl';
CDCPDir = 'dcp';
CDesignBPL = 'DesignBPL';
CSourceDir = 'source';
{ TDNInstaller }
procedure TDNInstaller.AddBrowsingPath(const ABrowsingPath: string;
const APlatforms: TDNCompilerPlatforms);
begin
if FBrowsingPathes = '' then
FBrowsingPathes := ABrowsingPath
else
FBrowsingPathes := FBrowsingPathes + ';' + ABrowsingPath;
end;
procedure TDNInstaller.AddSearchPath(const ASearchPath: string; const APlatforms: TDNCompilerPlatforms);
begin
if FSearchPathes = '' then
FSearchPathes := ASearchPath
else
FSearchPathes := FSearchPathes + ';' + ASearchPath;
end;
procedure TDNInstaller.AfterCompile(const AProjectFile: string;
const ALog: TStrings; ASuccessFull: Boolean);
begin
if ASuccessFull then
begin
DoMessage(mtNotification, 'Success');
end
else
begin
DoMessage(mtNotification, ALog.Text);
DoMessage(mtError, 'Failed');
end;
end;
procedure TDNInstaller.BeforeCompile(const AProjectFile: string);
begin
DoMessage(mtNotification, 'Compiling ' + ExtractFileName(AProjectFile));
end;
procedure TDNInstaller.ConfigureCompiler(const ACompiler: IDNCompiler);
begin
ACompiler.DCUOutput := TPath.Combine(GetLibBaseDir(), '$(Platform)\$(Config)');
ACompiler.ExeOutput := TPath.Combine(GetBinBaseDir(), '$(Platform)\$(Config)');
ACompiler.BPLOutput := GetBPLDir(ACompiler.Platform);
ACompiler.DCPOutput := GetDCPDir(ACompiler.Platform);
end;
procedure TDNInstaller.CopyDirectory(const ASource, ATarget: string; AFileFilters: TStringDynArray; ARecursive: Boolean = False; ACopiedFiles: TStringList = nil);
var
LDirectories, LFiles: TStringDynArray;
LDirectory, LFile, LFileName, LTargetFile: string;
LForcedDirectory: Boolean;
begin
LForcedDirectory := False;
if ARecursive then
begin
LDirectories := TDirectory.GetDirectories(ASource);
for LDirectory in LDirectories do
begin
CopyDirectory(LDirectory, TPath.Combine(ATarget, ExtractFileName(LDirectory)), AFileFilters, ARecursive, ACopiedFiles);
end;
end;
LFiles := TDirectory.GetFiles(ASource);
for LFile in LFiles do
begin
LFileName := ExtractFileName(LFile);
if FileMatchesFilter(LFileName, AFileFilters) then
begin
//lazy directory creation, so directories with no matching files are not created in the target path!
if not LForcedDirectory then
begin
LForcedDirectory := True;
ForceDirectories(ATarget);
end;
LTargetFile := TPath.Combine(ATarget, LFileName);
TFile.Copy(LFile, LTargetFile, True);
if Assigned(ACopiedFiles) then
ACopiedFiles.Add(LTargetFile);
end;
end;
end;
procedure TDNInstaller.CopyLicense(const ASourceDirectory,
ATargetDirectory, ALicense: string);
var
LSource, LTarget: string;
begin
LSource := TPath.Combine(ASourceDirectory, ALicense);
LTarget := TPath.Combine(ATargetDirectory, ExtractFileName(ALicense));
if TFile.Exists(LSource) then
TFile.Copy(LSource, LTarget, True);
end;
function TDNInstaller.CopyMetaData(const ASourceDirectory,
ATargetDirectory: string): Boolean;
var
LSourceInfo, LTargetInfo, LSourcePic, LTargetPic: string;
LSourceInstall, LTargetInstall: string;
LInfo: TInfoFile;
begin
Result := True;
LSourceInfo := TPath.Combine(ASourceDirectory, CInfoFile);
LTargetInfo := TPath.Combine(ATargetDirectory, CInfoFile);
if TFile.Exists(LSourceInfo) then
begin
TFile.Copy(LSourceInfo, LTargetInfo, True);
LInfo := TInfoFile.Create();
try
if LInfo.LoadFromFile(LSourceInfo) then
begin
if LInfo.Picture <> '' then
begin
LSourcePic := TPath.Combine(ASourceDirectory, LInfo.Picture);
LTargetPic := TPath.Combine(ATargetDirectory, LInfo.Picture);
if TFile.Exists(LSourcePic) then
begin
ForceDirectories(ExtractFilePath(LTargetPic));
TFile.Copy(LSourcePic, LTargetPic, True);
end;
end;
end;
finally
LInfo.Free;
end;
end;
LSourceInstall := TPath.Combine(ASourceDirectory, CInstallFile);
LTargetInstall := TPath.Combine(ATargetDirectory, CInstallFile);
TFile.Copy(LSourceInstall, LTargetInstall, True);
end;
constructor TDNInstaller.Create(const ACompiler: IDNCompiler;
const AVariableResolverFactory: TDNCompilerVariableResolverFacory;
const AExpertService: IDNExpertService);
begin
inherited Create();
FCompiler := ACompiler;
FVariableResolverFactory := AVariableResolverFactory;
FExpertService := AExpertService;
FPackages := TList<TPackage>.Create();
FProgress := TDNProgress.Create();
FRawFiles := TStringList.Create();
FExperts := TList<TInstalledExpert>.Create();
end;
destructor TDNInstaller.Destroy;
begin
FPackages.Free();
FRawFiles.Free();
FExperts.Free();
FProgress := nil;
inherited;
end;
procedure TDNInstaller.DoMessage(AType: TMessageType; const AMessage: string);
begin
if Assigned(FOnMessage) then
FOnMessage(AType, AMessage);
end;
function TDNInstaller.FileMatchesFilter(const AFile: string;
const AFilter: TStringDynArray): Boolean;
var
LFilter: string;
begin
Result := Length(AFilter) = 0;
if not Result then
begin
for LFilter in AFilter do
begin
Result := MatchesMask(AFile, LFilter);
if Result then
Break;
end;
end;
end;
function TDNInstaller.GetBinBaseDir: string;
begin
Result := TPath.Combine(GetTargetDirectory, CBinDir);
end;
function TDNInstaller.GetHasPendingChanges: Boolean;
begin
Result := FHasPendingChanges;
end;
function TDNInstaller.GetLibBaseDir: string;
begin
Result := TPath.Combine(GetTargetDirectory, CLibDir);
end;
function TDNInstaller.GetOnMessage: TMessageEvent;
begin
Result := FOnMessage;
end;
function TDNInstaller.GetSourceFolder(const ADirectory: string): string;
begin
Result := TPath.Combine(ADirectory, CSourceDir);
end;
function TDNInstaller.GetTargetDirectory: string;
begin
Result := FTargetDirectory;
end;
function TDNInstaller.LoadInfo(const ADirectory: string;
AInfo: TInfoFile): Boolean;
var
LInfoFile: string;
begin
LInfoFile := TPath.Combine(ADirectory, CInfoFile);
if TFile.Exists(LInfoFile) then
begin
Result := AInfo.LoadFromFile(LInfoFile);
if not Result then
begin
DoMessage(mtError, CInfoFile + ' seems to be corrupt');
Exit(False);
end;
end
else
begin
DoMessage(mtError, 'no info-file provided');
Exit(False);
end;
end;
function TDNInstaller.LoadInstallation(const ADirectory: string;
AInstallation: TInstallationFile): Boolean;
var
LInstallerFile: string;
begin
Result := False;
LInstallerFile := TPath.Combine(ADirectory, CInstallFile);
if TFile.Exists(LInstallerFile) then
begin
Result := AInstallation.LoadFromFile(LInstallerFile);
if not Result then
begin
DoMessage(mtError, CInstallFile + ' seems to be invalid json');
end;
end
else
begin
DoMessage(mtError, 'No installation file');
end;
end;
function TDNInstaller.LoadProject(const AProjectFile: string;
out AProject: IDNProjectInfo): Boolean;
begin
AProject := TDNProjectInfo.Create();
Result := AProject.LoadFromFile(AProjectFile);
if not Result then
begin
DoMessage(mtError, 'Failed to load project ' + AProjectFile);
DoMessage(mtError, AProject.LoadingError);
end;
end;
function TDNInstaller.LoadProjectGroup(const AGroupFile: string;
out AGroup: IDNProjectGroupInfo): Boolean;
begin
AGroup := TDNProjectGroupInfo.Create();
Result := AGroup.LoadFromFile(AGroupFile);
if not Result then
begin
DoMessage(mtError, 'Failed to load group ' + AGroupFile);
DoMessage(mtError, AGroup.LoadingError);
end;
end;
function TDNInstaller.LoadSupportedProjects(const ABaseDirectory: string; const AProjects: TArray<TProject>; ASupportedProjects: TList<IDNProjectInfo>): Boolean;
var
LProject: TProject;
LInfo: IDNProjectInfo;
LGroup: IDNProjectGroupInfo;
const
CGroup = '.groupproj';
CProject = '.dproj';
begin
Result := True;
for LProject in AProjects do
begin
if IsSupported(LProject.CompilerMin, LProject.CompilerMax) then
begin
case AnsiIndexText(ExtractFileExt(LProject.Project), [CProject, CGroup]) of
0:
begin
if LoadProject(TPath.Combine(ABaseDirectory, LProject.Project), LInfo) then
begin
if ((GetSupportedPlatforms * LInfo.SupportedPlatforms) <> []) then
ASupportedProjects.Add(LInfo);
end
else
Exit(False);
end;
1:
begin
if LoadProjectGroup(TPath.Combine(ABaseDirectory, LProject.Project), LGroup) then
begin
for LInfo in LGroup.Projects do
begin
if ((GetSupportedPlatforms * LInfo.SupportedPlatforms) <> []) then
ASupportedProjects.Add(LInfo);
end;
end
else
Exit(False)
end
else
begin
DoMessage(mtError, 'Unknown fileextension for project ' + LProject.Project);
end;
end;
end;
end;
end;
function TDNInstaller.Install(const ASourceDirectory,
ATargetDirectory: string): Boolean;
var
LInstallInfo: TInstallationFile;
LLicenseFiles: TArray<string>;
begin
Reset();
Result := False;
if not PrepareInstallationDirectory(ATargetDirectory) then
Exit;
try
FTargetDirectory := ATargetDirectory;
if not ValidateInfoAndGetLicenceFiles(ASourceDirectory, LLicenseFiles) then
Exit;
LInstallInfo := TInstallationFile.Create();
try
if LoadInstallation(ASourceDirectory, LInstallInfo) then
Result := ProcessInstallation(LInstallInfo, ASourceDirectory, ATargetDirectory, LLicenseFiles);
finally
LInstallInfo.Free;
end;
finally
SaveUninstall(ATargetDirectory);
end;
end;
function TDNInstaller.InstallBPL(const ABPL: string): Boolean;
begin
Result := True;
end;
function TDNInstaller.InstallExpert(const AExpert: string;
AHotReload: Boolean): Boolean;
var
LResult: Boolean;
begin
Result := TFile.Exists(AExpert);
if Result then
begin
DoMessage(mtNotification, AExpert);
if Assigned(FExpertService) then
begin
TThread.Synchronize(nil,
procedure
begin
LResult := FExpertService.RegisterExpert(AExpert, AHotReload);
end);
Result := LResult;
FHasPendingChanges := FHasPendingChanges or not AHotReload;
end;
end
else
begin
DoMessage(mtError, 'File not found: ' + AExpert);
end;
end;
function TDNInstaller.IsSupported(ACompiler_Min, ACompiler_Max: Integer): Boolean;
begin
Result := True;
if ACompiler_Min > 0 then
Result := Result and (Trunc(FCompiler.Version) >= ACompiler_Min);
if ACompiler_Max > 0 then
Result := Result and (Trunc(FCompiler.Version) <= ACompiler_Max);
end;
function TDNInstaller.ProcessProject(const AProject: IDNProjectInfo): Boolean;
var
LCompiledPackage: TPackage;
LPlatform: TDNCompilerPlatform;
LResolver: IVariableResolver;
begin
Result := False;
BeforeCompile(AProject.FileName);
for LPlatform in AProject.SupportedPlatforms do
begin
if LPlatform in GetSupportedPlatforms() then
begin
DoMessage(mtNotification, TDNCompilerPlatformName[LPlatform]);
FCompiler.Platform := LPlatform;
ConfigureCompiler(FCompiler);
LResolver := FVariableResolverFactory(FCompiler.Platform, FCompiler.Config);
Result := FCompiler.Compile(AProject.FileName);
if Result and AProject.IsPackage then
begin
if (not AProject.IsRuntimeOnlyPackage) and (LPlatform = cpWin32) then
begin
Result := InstallBPL(TPath.Combine(LResolver.Resolve(FCompiler.BPLOutput), AProject.BinaryName));
if Result then
DoMessage(mtNotification, 'installed')
else
DoMessage(mtError, 'failed to install');
end;
if LPlatform = cpOSX32 then
begin
LCompiledPackage.BPLFile := TPath.Combine(LResolver.Resolve(FCompiler.BPLOutput), CMacPackagePrefix + AProject.BinaryName);
LCompiledPackage.BPLFile := ChangeFileExt(LCompiledPackage.BPLFile, CMacPackageExtension);
end
else
begin
LCompiledPackage.BPLFile := TPath.Combine(LResolver.Resolve(FCompiler.BPLOutput), AProject.BinaryName);
end;
LCompiledPackage.DCPFile := TPath.Combine(LResolver.Resolve(FCompiler.DCPOutput), AProject.DCPName);
LCompiledPackage.Installed := (not AProject.IsRuntimeOnlyPackage) and (LPlatform = cpWin32);
FPackages.Add(LCompiledPackage);
end;
if not Result then
Break;
end
else
begin
DoMessage(mtWarning, 'Platform ' + TDNCompilerPlatformName[LPlatform] + ' not supported, skipping');
end;
end;
AfterCompile(AProject.FileName, FCompiler.Log, Result);
end;
function TDNInstaller.ProcessProjects(const AProjects: TArray<TProject>; const ATargetDirectory: string): Boolean;
var
LProject: IDNProjectInfo;
LProjects: TList<IDNProjectInfo>;
i: Integer;
begin
LProjects := TList<IDNProjectInfo>.Create();
try
Result := LoadSupportedProjects(GetSourceFolder(ATargetDirectory), AProjects, LProjects);
if Result then
begin
for i := 0 to LProjects.Count - 1 do
begin
LProject := LProjects[i];
FProgress.SetTaskProgress(ExtractFileName(LProject.FileName), i, LProjects.Count);
Result := ProcessProject(LProject);
if not Result then
Break;
end;
end;
finally
LProjects.Free;
end;
end;
function TDNInstaller.ProcessRawFolder(const ARawFolder, ASourceDirectory: string): Boolean;
var
LRawFolder, LSourceFolder: string;
LSourceLib, LSourceBin, LSourceDCP, LSourceBPL, LSourceDesignBPL: string;
LPlatformName, LConfig, LPlatformConfig: string;
LPlatform: TDNCompilerPlatform;
LDesignBPLs: TStringList;
LBPLFilter: TStringDynArray;
LResolver: IVariableResolver;
begin
Result := True;
DoMessage(mtNotification, ARawFolder);
LRawFolder := TPath.Combine(ASourceDirectory, ARawFolder);
LSourceLib := TPath.Combine(LRawFolder, CLibDir);
LSourceBin := TPath.Combine(LRawFolder, CBinDir);
LSourceDCP := TPath.Combine(LRawFolder, CDCPDir);
LSourceBPL := TPath.Combine(LRawFolder, CBPLDir);
LSourceDesignBPL := TPath.Combine(LRawFolder, CDesignBPL);
LConfig := TDNCompilerConfigName[ccRelease];
for LPlatform in GetSupportedPlatforms() do
begin
LPlatformName := TDNCompilerPlatformName[LPlatform];
LPlatformConfig := IncludeTrailingPathDelimiter(LPlatformName) + LConfig;
LResolver := FVariableResolverFactory(LPlatform, ccRelease);
LSourceFolder := TPath.Combine(LSourceLib, LPlatformName);
if TDirectory.Exists(LSourceFolder) then
CopyDirectory(LSourceFolder, TPath.Combine(GetLibBaseDir(), LPlatformConfig), nil, True);
LSourceFolder := TPath.Combine(LSourceBin, LPlatformName);
if TDirectory.Exists(LSourceFolder) then
CopyDirectory(LSourceFolder, TPath.Combine(GetBinBaseDir(), LPlatformConfig), nil, True);
LSourceFolder := TPath.Combine(LSourceDCP, LPlatformName);
if TDirectory.Exists(LSourceFolder) then
CopyDirectory(LSourceFolder, LResolver.Resolve(GetDCPDir(LPlatform)), nil, False, FRawFiles);
LSourceFolder := TPath.Combine(LSourceBPL, LPlatformName);
if TDirectory.Exists(LSourceFolder) then
CopyDirectory(LSourceFolder, LResolver.Resolve(GetBPLDir(LPlatform)), nil, False, FRawFiles);
if LPlatform = cpWin32 then
begin
LDesignBPLs := TStringList.Create();
try
SetLength(LBPLFilter, 1);
LBPLFilter[0] := '*.bpl';
LSourceFolder := TPath.Combine(LSourceDesignBPL, LPlatformName);
if TDirectory.Exists(LSourceFolder) then
begin
CopyDirectory(LSourceFolder, LResolver.Resolve(GetBPLDir(LPlatform)), LBPLFilter, False, LDesignBPLs);
Result := RegisterRawDesignBPLs(LDesignBPLs.ToStringArray);
if not Result then
Break;
end;
finally
LDesignBPLs.Free;
end;
end;
end;
end;
function TDNInstaller.ProcessRawFolders(const ARawFolders: TArray<TRawFolder>;
const ASourceDirectory: string): Boolean;
var
LFolder: TRawFolder;
begin
Result := True;
if Length(ARawFolders) > 0 then
DoMessage(mtNotification, 'copying rawfolders:');
for LFolder in ARawFolders do
begin
if IsSupported(LFolder.CompilerMin, LFolder.CompilerMax) then
Result := Result and ProcessRawFolder(LFolder.Folder, ASourceDirectory);
if not Result then
Break;
end;
end;
function TDNInstaller.PrepareInstallationDirectory(
const ATargetDirectory: string): Boolean;
begin
Result := ForceDirectories(ATargetDirectory);
if not Result then
DoMessage(mtError, 'Failed to create directory ' + QuotedStr(ATargetDirectory));
end;
function TDNInstaller.ProcessExperts(const AExperts: TArray<TExpert>): Boolean;
var
LExpert: TExpert;
LBaseDir, LExpertFile: string;
LInstalledExpert: TInstalledExpert;
begin
Result := True;
if Length(AExperts) > 0 then
DoMessage(mtNotification, 'Installing Experts:');
LBaseDir := TPath.Combine(TPath.Combine(GetBinBaseDir, TDNCompilerPlatformName[cpWin32]), TDNCompilerConfigName[ccRelease]);
for LExpert in AExperts do
begin
if IsSupported(LExpert.CompilerMin, LExpert.CompilerMax) then
begin
LExpertFile := TPath.Combine(LBaseDir, LExpert.Expert);
LInstalledExpert.Expert := LExpertFile;
LInstalledExpert.HotReload := LExpert.HotReload;
FExperts.Add(LInstalledExpert);
Result := InstallExpert(LExpertFile, LExpert.HotReload);
end;
if not Result then
Break;
end;
end;
function TDNInstaller.ProcessInstallation(AInstallation: TInstallationFile;
const ASourceDirectory, ATargetDirectory: string; const ALicenceFiles: TArray<string>): Boolean;
var
LLicense: string;
begin
FProgress.SetTasks(['Copy Raw', 'Copy Source', 'Compile Projects', 'Adding Experts', 'Adding Pathes']);
ProcessRawFolders(AInstallation.RawFolders, ASourceDirectory);
FProgress.NextTask();
ProcessSourceFolders(AInstallation.SourceFolders, ASourceDirectory, GetSourceFolder(ATargetDirectory));
CopyMetaData(ASourceDirectory, ATargetDirectory);
for LLicense in ALicenceFiles do
CopyLicense(ASourceDirectory, ATargetDirectory, LLicense);
FProgress.NextTask();
Result := ProcessProjects(AInstallation.Projects, ATargetDirectory);
FProgress.NextTask();
Result := Result and ProcessExperts(AInstallation.Experts);
FProgress.NextTask();
FProgress.SetTaskProgress('Libpath', 0, 2);
ProcessLibPathes();
FProgress.SetTaskProgress('SearchPath', 1, 2);
ProcessPathes(AInstallation.SearchPathes, ATargetDirectory, tpSearchPath);
FProgress.SetTaskProgress('BrowsingPath', 2, 2);
ProcessPathes(AInstallation.BrowsingPathes, ATargetDirectory, tpBrowsingPath);
FProgress.Completed();
end;
procedure TDNInstaller.ProcessLibPathes;
var
LPlatform: TDNCompilerPlatform;
LSubDirs: TStringDynArray;
LPlatformDir, LSubDir: string;
begin
DoMessage(mtNotification, 'Adding Libpathes:');
for LPlatform in GetSupportedPlatforms() do
begin
LPlatformDir := TPath.Combine(GetLibBaseDir(), TDNCompilerPlatformName[LPlatform]);
if TDirectory.Exists(LPlatformDir) then
begin
LSubDirs := TDirectory.GetDirectories(LPlatformDir, TSEarchOption.soAllDirectories, nil);
for LSubDir in LSubDirs do
if Length(TDirectory.GetFiles(LSubDir)) > 0 then
begin
DoMessage(mtNotification, LSubDir);
AddSearchPath(LSubDir, [LPlatform]);
end;
end;
end;
end;
procedure TDNInstaller.ProcessPathes(const APathes: TArray<TSearchPath>; const ARootDirectory: string; APathType: TPathType);
var
LPathes: TStringDynArray;
LPath: TSearchPath;
LRelPath, LBasePath, LFullPath: string;
LPlatforms: TDNCompilerPlatforms;
begin
if Length(APathes) > 0 then
begin
case APathType of
tpSearchPath: DoMessage(mtNotification, 'Adding Searchpathes:');
tpBrowsingPath: DoMessage(mtNotification, 'Adding Browsingpathes:');
else
DoMessage(mtError, 'Unknown PathType');
Exit;
end;
LBasePath := TPath.Combine(ARootDirectory, CSourceDir);
for LPath in APathes do
begin
LPlatforms := LPath.Platforms * GetSupportedPlatforms();
if IsSupported(LPath.CompilerMin, LPath.CompilerMax) and (LPlatforms <> []) then
begin
LPathes := SplitString(LPath.Path, ';');
for LRelPath in LPathes do
begin
DoMessage(mtNotification, LRelPath);
LFullPath := TPath.Combine(LBasePath, UndecoratePath(LRelPath));
case APathType of
tpSearchPath: AddSearchPath(LFullPath, LPlatforms);
tpBrowsingPath: AddBrowsingPath(LFullPath, LPlatforms);
end;
end;
end;
end;
end;
end;
procedure TDNInstaller.ProcessSourceFolders(const ASourceFolders: TArray<TFolder>; const ASourceDirectory, ATargetDirectory: string);
var
LFolder: TFolder;
LFilter: TStringDynArray;
LRelTargetPath, LBase: string;
begin
if Length(ASourceFolders) > 0 then
begin
DoMessage(mtNotification, 'Copying sourcefolders:');
for LFolder in ASourceFolders do
begin
if IsSupported(LFolder.CompilerMin, LFolder.CompilerMax) then
begin
if not TPath.IsRelativePath(LFolder.Folder) then
begin
DoMessage(mtWarning, 'Path is not relative ' + LFolder.Folder);
end;
LRelTargetPath := LFolder.Folder;
if LFolder.Base <> '' then
begin
LBase := IncludeTrailingPathDelimiter(LFolder.Base);
LRelTargetPath := IncludeTrailingPathDelimiter(LFolder.Folder);
if StartsText(LBase, LRelTargetPath) then
begin
LRelTargetPath := Copy(LRelTargetPath, Length(LBase) + 1, Length(LRelTargetPath));
LRelTargetPath := ExcludeTrailingPathDelimiter(LRelTargetPath);
end
else
DoMessage(mtError, 'base must be exactly overlapping with folder string to remove it');
end;
LFilter := SplitString(LFolder.Filter, ';');
DoMessage(mtNotification, LFolder.Folder);
CopyDirectory(
TPath.Combine(ASourceDirectory, UndecoratePath(LFolder.Folder)),
TPath.Combine(ATargetDirectory, UndecoratePath(LRelTargetPath)), LFilter, LFolder.Recursive);
end;
end;
end;
end;
function TDNInstaller.RegisterRawDesignBPLs(
const ADesignBPLs: TArray<string>): Boolean;
var
LBPL: string;
LPackage: TPackage;
begin
Result := True;
for LBPL in ADesignBPLs do
begin
LPackage.BPLFile := LBPL;
LPackage.Installed := True;
FPackages.Add(LPackage);
Result := InstallBPL(LBPL);
if not Result then
Break;
end;
end;
procedure TDNInstaller.Reset;
begin
FSearchPathes := '';
FBrowsingPathes := '';
FPackages.Clear();
FRawFiles.Clear;
FExperts.Clear();
end;
procedure TDNInstaller.SaveUninstall(const ATargetDirectory: string);
var
LUninstall: TUninstallationFile;
begin
LUninstall := TUninstallationFile.Create();
try
LUninstall.SearchPathes := FSearchPathes;
LUninstall.BrowsingPathes := FBrowsingPathes;
LUninstall.Packages := FPackages.ToArray;
LUninstall.RawFiles := FRawFiles.ToStringArray;
LUninstall.Experts := FExperts.ToArray;
LUninstall.SaveToFile(TPath.Combine(ATargetDirectory, CUninstallFile));
finally
LUninstall.Free;
end;
end;
procedure TDNInstaller.SetOnMessage(const Value: TMessageEvent);
begin
FOnMessage := Value;
end;
function TDNInstaller.UndecoratePath(const APath: string): string;
begin
if StartsStr('..', APath) then
Result := Copy(APath, 3, Length(APath))
else if StartsStr('.', APath) then
Result := Copy(APath, 2, Length(APath))
else
Result := APath;
if StartsStr('\', Result) then
Result := Copy(Result, 2, Length(Result));
end;
function TDNInstaller.ValidateInfoAndGetLicenceFiles(const ADirectory: string;
out ALicenceFiles: TArray<string>): Boolean;
var
LInfo: TInfoFile;
i: Integer;
begin
LInfo := TInfoFile.Create();
try
Result := LoadInfo(ADirectory, LInfo);
if Result then
begin
if LInfo.ID = TGuid.Empty then
begin
DoMessage(mtError, 'no ID provided');
Exit(False);
end;
SetLength(ALicenceFiles, Length(LInfo.Licenses));
for i := Low(ALicenceFiles) to High(ALicenceFiles) do
ALicenceFiles[i] := LInfo.Licenses[i].LicenseFile;
end;
finally
LInfo.Free;
end;
end;
end.