-
Notifications
You must be signed in to change notification settings - Fork 1
/
sm_srv_base.pas
238 lines (191 loc) · 7.26 KB
/
sm_srv_base.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
unit sm_srv_base;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Variants, DateUtils, XMLRead,XMLWrite,Dom,sm_types,sm_utils;
type
//-------------------------------------------------------------------
{ TScriptStorage }
{ TServerStorage }
TServerStorage = class(TPackageList)
public
procedure LoadFromXmlStream(aFileName: TStream);
procedure LoadFromXmlFile(aFileName: string);
procedure SaveLocalXMLRegistry(aFileName: string);
end;
implementation
//-------------------------------------------------------------------
procedure TServerStorage.LoadFromXmlStream(aFileName: TStream);
//-------------------------------------------------------------------
procedure DoLoadFiles(aParentNode: TDOMNode; aPackageItem: TPackageItem);
var
I: Integer;
j: Integer;
oFileItem: TFileItem;
oNode,oNode1: TDOMNode;
s,p: string;
sItem: TSubitem;
begin
for I := 0 to aParentNode.ChildNodes.Count - 1 do
begin
oFileItem:=aPackageItem.Files.AddItem;
oNode:=aParentNode.ChildNodes[i];
oFileItem.FileName:= VarToStr(oNode.Attributes.GetNamedItem('filename').NodeValue);
oFileItem.Author := VarToStr(oNode.Attributes.GetNamedItem('author').NodeValue);
oFileItem.EMail := VarToStr(oNode.Attributes.GetNamedItem('email').NodeValue);
oFileItem.Version := StrToFloat(VarToStr(oNode.Attributes.GetNamedItem('version').NodeValue));
s:=VarToStr(oNode.Attributes.GetNamedItem('date_modify').NodeValue);
//oFileItem.DateModify := StrToDateTime(s);
oFileItem.DateModify := SM_StrToDate(s);
for j := 0 to oNode.ChildNodes.Count - 1 do
begin
oNode1:=oNode.ChildNodes[j];
if LowerCase(oNode1.NodeName)='subfile' then
begin
sItem:=oFileItem.SubFiles.AddItem;
sItem.FileName:=oNode1.Attributes.GetNamedItem('filename').NodeValue;
sItem.UnpPath:=oNode1.Attributes.GetNamedItem('filepath').NodeValue;
end else
if LowerCase(oNode1.NodeName)='description' then
begin
oFileItem.Description:=oNode1.TextContent;
end;
end;
end;
end;
procedure DoLoadPackages(aParentNode: TDOMNode);
var
I: Integer;
oNode: TDOMNode;
oPackageItem: TPackageItem;
begin
for I := 0 to aParentNode.ChildNodes.Count - 1 do
begin
oPackageItem:=AddItem;
oNode:=aParentNode.ChildNodes[i];
oPackageItem.Name:= oNode.Attributes.GetNamedItem('name').NodeValue;
DoLoadFiles(oNode, oPackageItem);
end;
end;
var
oXmlDocument: TXmlDocument;
begin
oXMLDocument:=TXMLDocument.Create;
ReadXMLFile(oXmlDocument,aFileName);
DoLoadPackages (oXmlDocument.DocumentElement);
FreeAndNil(oXmlDocument);
end;
procedure TServerStorage.LoadFromXmlFile(aFileName: string);
procedure DoLoadFiles(aParentNode: TDOMNode; aPackageItem: TPackageItem);
var
I: Integer;
j: Integer;
oFileItem: TFileItem;
oNode,oNode1: TDOMNode;
s,p: string;
sItem: TSubitem;
begin
for I := 0 to aParentNode.ChildNodes.Count - 1 do
begin
oFileItem:=aPackageItem.Files.AddItem;
oNode:=aParentNode.ChildNodes[i];
oFileItem.FileName:= VarToStr(oNode.Attributes.GetNamedItem('filename').NodeValue);
oFileItem.Author := VarToStr(oNode.Attributes.GetNamedItem('author').NodeValue);
oFileItem.EMail := VarToStr(oNode.Attributes.GetNamedItem('email').NodeValue);
oFileItem.Version := StrToFloat(VarToStr(oNode.Attributes.GetNamedItem('version').NodeValue));
s:=VarToStr(oNode.Attributes.GetNamedItem('date_modify').NodeValue);
//oFileItem.DateModify := StrToDateTime(s);
oFileItem.DateModify := SM_StrToDate(s);
for j := 0 to oNode.ChildNodes.Count - 1 do
begin
oNode1:=oNode.ChildNodes[j];
if LowerCase(oNode1.NodeName)='subfile' then
begin
sItem:=oFileItem.SubFiles.AddItem;
sItem.FileName:=oNode1.Attributes.GetNamedItem('filename').NodeValue;
sItem.UnpPath:=oNode1.Attributes.GetNamedItem('filepath').NodeValue;
end else
if LowerCase(oNode1.NodeName)='description' then
begin
oFileItem.Description:=oNode1.TextContent;
end;
end;
end;
end;
procedure DoLoadPackages(aParentNode: TDOMNode);
var
I: Integer;
oNode: TDOMNode;
oPackageItem: TPackageItem;
begin
for I := 0 to aParentNode.ChildNodes.Count - 1 do
begin
oPackageItem:=AddItem;
oNode:=aParentNode.ChildNodes[i];
oPackageItem.Name:= oNode.Attributes.GetNamedItem('name').NodeValue;
DoLoadFiles(oNode, oPackageItem);
end;
end;
var
oXmlDocument: TXmlDocument;
begin
oXMLDocument:=TXMLDocument.Create;
ReadXMLFile(oXmlDocument,aFileName);
DoLoadPackages (oXmlDocument.DocumentElement);
FreeAndNil(oXmlDocument);
end;
procedure TServerStorage.SaveLocalXMLRegistry(aFileName: string);
var
oXmlDocument: TXmlDocument;
vRoot,ParentNode,PackageNode,TempNode,Description,FileItemNode,SubFileNode: TDOMNode;
i,d,j: integer;
s: string;
oFileItem: TFileItem;
begin
oXmlDocument:=TXmlDocument.Create;
oXmlDocument.Encoding:='UTF-8';
vRoot:=oXmlDocument.CreateElement('Document');
oXmlDocument.AppendChild(vroot);
vRoot:=oXMLDocument.DocumentElement;
for i:=0 to count -1 do
begin
PackageNode:=oXmlDocument.CreateElement('structure');
TDOMElement(PackageNode).SetAttribute('name',Items[i].Name);
for d:=0 to Items[i].Files.Count - 1 do
begin
oFileItem:=Items[i].Files.Items[d];
FileItemNode:=oXMLDocument.CreateElement('file');
TDOMElement(FileItemNode).SetAttribute('filename',oFileItem.FileName);
TDOMElement(FileItemNode).SetAttribute('author',oFileItem.Author);
TDOMElement(FileItemNode).SetAttribute('email',oFileItem.EMail);
TDOMElement(FileItemNode).SetAttribute('version',FloatToStr(oFileItem.Version));
TDOMElement(FileItemNode).SetAttribute('installed',IntToStr(0));
TDOMElement(FileItemNode).SetAttribute('update',IntToStr(0));
s:=DateTimeToStr(oFileItem.DateModify);
TDOMElement(FileItemNode).SetAttribute('date_modify',s);
if oFileItem.description<>'' then
begin
TempNode:=oXMLDocument.CreateElement('description');
Description:=oXMLDocument.CreateTextNode(oFileItem.description);
TempNode.AppendChild(Description);
FileItemNode.AppendChild(TempNode);
end;
{ for j := 0 to oFileItem.SubFiles.Count - 1 do
begin
SubFileNode:=oXMLDocument.CreateElement('subfile');
TDOMElement(SubFileNode).SetAttribute('filename',oFileItem.SubFiles[j].FileName);
TDOMElement(SubFileNode).SetAttribute('filepath',oFileItem.SubFiles[j].UnpPath);
FileItemNode.AppendChild(SubFileNode);
end; }
PackageNode.AppendChild(FileItemNode);
end;
vRoot.AppendChild(PackageNode);
end;
WriteXMLFile (oXmlDocument,aFileName);
FreeAndNil(oXmlDocument);
end;
begin
ShortDateFormat:='dd.mm.yyyy';
ShortTimeFormat:='h:mm';
{Test; }
end.