-
Notifications
You must be signed in to change notification settings - Fork 1
/
Project.pas
155 lines (143 loc) · 4.02 KB
/
Project.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
unit Project;
interface
uses
Classes, Types, Windows, SysUtils, Generics.Collections, IDEUnit;
type
TProject = class
private
FProjectPath: string;
FProjectName: string;
FUnits: TObjectList<TIDEUnit>;
FBuildModule: Boolean;
FOptimize: Boolean;
FAssemble: Boolean;
FUseBigEndian: Boolean;
FProjectSource: TStringList;
FProjectUnit: TIDEUnit;
procedure SetProjectName(const Value: string);
public
constructor Create();
destructor Destroy(); override;
procedure SaveToFile(AFile: string);
procedure LoadFromFile(AFile: string);
function GetUnitByName(AName: string): TIDEUnit;
property ProjectName: string read FProjectName write SetProjectName;
property ProjectPath: string read FProjectPath write FProjectPath;
property Units: TObjectList<TIDEUnit> read FUnits;
property ProjectUnit: TIDEUnit read FProjectUnit;
property Optimize: Boolean read FOptimize write FOptimize;
property Assemble: Boolean read FAssemble write FAssemble;
property BuildModule: Boolean read FBuildModule write FBuildModule;
property UseBigEndian: Boolean read FUseBigEndian write FUseBigEndian;
end;
implementation
uses
xmldom, XMLIntf, msxmldom, XMLDoc, SimpleRefactor;
{ TProject }
constructor TProject.Create;
begin
FUnits := TObjectList<TIDEUnit>.Create();
FOptimize := True;
FAssemble := True;
FBuildModule := False;
FUseBigEndian := True;
FProjectSource := TStringList.Create();
FProjectUnit := TIDEUnit.Create();
end;
destructor TProject.Destroy;
begin
FUnits.Free;
FProjectUnit.Free;
FProjectSource.Free;
inherited;
end;
function TProject.GetUnitByName(AName: string): TIDEUnit;
var
LUnit: TIDEUnit;
begin
Result := nil;
if SameText(AName, FProjectUnit.Caption) then
begin
Result := FProjectUnit;
end
else
begin
for LUnit in FUnits do
begin
if SameText(AName, LUnit.Caption) then
begin
Result := LUnit;
Break;
end;
end;
end;
end;
procedure TProject.LoadFromFile(AFile: string);
var
LDoc: IXMLDocument;
LNode, LRoot: IXMLNode;
i: Integer;
LPath: string;
LUnit: TIDEUnit;
begin
FProjectUnit.FileName := ChangeFileExt(AFile, '.d16r');
LDoc := TXMLDocument.Create(nil);
LDoc.Active := True;
LDoc.LoadFromFile(AFile);
LRoot := LDoc.ChildNodes.First;
ProjectName := ChangeFileExt(LRoot.Attributes['Name'], '.d16p');
ProjectPath := ExtractFilePath(AFile);
for i := 0 to LRoot.ChildNodes.Count - 1 do
begin
LNode := LRoot.ChildNodes.Nodes[i];
LPath := ProjectPath + LNode.Attributes['Path'];
LUnit := TIDEUnit.Create();
LUnit.FileName := LPath;
FUnits.Add(LUnit);
end;
end;
procedure TProject.SaveToFile(AFile: string);
var
LDoc: IXMLDocument;
LRootNode, LSubNode: iXMLNode;
LUnit: TIDEUnit;
begin
FProjectUnit.FileName := ChangeFileExt(AFile, '.d16r');
FProjectUnit.Save;
LDoc := TXMLDocument.Create(nil);
LDoc.Active := True;
LRootNode := LDoc.AddChild('Project');
LRootNode.Attributes['Name'] := ChangeFileExt(ExtractFileName(AFile), '');
for LUnit in FUnits do
begin
LSubNode := LRootNode.AddChild('Unit');
LSubNode.Attributes['Path'] := ExtractRelativePath(FProjectPath, LUnit.FileName);
end;
LDoc.SaveToFile(AFile);
end;
procedure TProject.SetProjectName(const Value: string);
var
LRefactor: TSimpleRefactor;
begin
FProjectName := Value;
if (not FProjectUnit.IsOpen) then
begin
if FileExists(FProjectUnit.FileName) then
begin
LRefactor := TSimpleRefactor.Create(FProjectSource);
try
FProjectSource.LoadFromFile(FProjectUnit.FileName);
LRefactor.RenameHeader(ChangeFileExt(Value, ''));
FProjectUnit.Caption := ChangeFileExt(Value, '');
FProjectSource.SaveToFile(FProjectUnit.FileName);
finally
LRefactor.Free;
end;
end;
end
else
begin
FProjectUnit.Caption := ChangeFileExt(Value, '');
end;
end;
end.