-
Notifications
You must be signed in to change notification settings - Fork 63
/
DN.ProjectGroupInfo.pas
133 lines (118 loc) · 3.28 KB
/
DN.ProjectGroupInfo.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
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.ProjectGroupInfo;
interface
uses
Classes,
Types,
SysUtils,
Generics.Collections,
DN.ProjectInfo.Intf,
DN.ProjectGroupInfo.Intf;
type
TDNProjectGroupInfo = class(TInterfacedObject, IDNProjectGroupInfo)
private
FFileName: string;
FLoadingError: string;
FProjects: TList<IDNProjectInfo>;
function GetFileName: string;
function GetProjects: TList<IDNProjectInfo>;
function GetLoadingError: string;
procedure SetError(const AError: string);
public
constructor Create();
destructor Destroy(); override;
function LoadFromFile(const AFileName: string): Boolean;
property FileName: string read GetFileName;
property Projects: TList<IDNProjectInfo> read GetProjects;
property LoadingError: string read GetLoadingError;
end;
implementation
uses
IOUtils,
DN.ProjectInfo,
XMLDoc,
XMLIntf;
{ TDNProjectGroupInfo }
constructor TDNProjectGroupInfo.Create;
begin
inherited;
FProjects := TList<IDNProjectInfo>.Create();
end;
destructor TDNProjectGroupInfo.Destroy;
begin
FProjects.Free;
inherited;
end;
function TDNProjectGroupInfo.GetFileName: string;
begin
Result := FFileName;
end;
function TDNProjectGroupInfo.GetLoadingError: string;
begin
Result := FLoadingError;
end;
function TDNProjectGroupInfo.GetProjects: TList<IDNProjectInfo>;
begin
Result := FProjects;
end;
function TDNProjectGroupInfo.LoadFromFile(const AFileName: string): Boolean;
var
LXML: IXMLDocument;
LItemGroup, LProjects, LProjectRoot: IXMLNode;
LProject: IDNProjectInfo;
LBasePath, LProjectFile: string;
begin
Result := False;
if TFile.Exists(AFileName) then
begin
FFileName := AFileName;
LBasePath := ExtractFilePath(AFileName);
LXML := TXMLDocument.Create(nil);
LXML.LoadFromFile(AFileName);
LProjectRoot := LXML.ChildNodes.FindNode('Project');
if Assigned(LProjectRoot) then
begin
LItemGroup := LProjectRoot.ChildNodes.FindNode('ItemGroup');
if Assigned(LItemGroup) then
begin
LProjects := LItemGroup.ChildNodes.FindNode('Projects');
while Assigned(LProjects) do
begin
LProject := TDNProjectInfo.Create();
LProjectFile := TPath.Combine(LBasePath, LProjects.Attributes['Include']);
if not LProject.LoadFromFile(LProjectFile) then
begin
SetError('Could not load Project ' + LProjectFile + ' Reason: ' + LProject.LoadingError);
Exit;
end;
FProjects.Add(LProject);
LProjects := LProjects.NextSibling;
end;
Result := True;
end
else
begin
SetError('ItemGroup-Node not found');
end;
end
else
begin
SetError('Project-Node not found');
end;
end
else
begin
SetError('File does not exist');
end;
end;
procedure TDNProjectGroupInfo.SetError(const AError: string);
begin
FLoadingError := AError;
end;
end.