forked from andriy-gerasika/dfm2xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfm2xml.dpr
executable file
·97 lines (92 loc) · 2.37 KB
/
dfm2xml.dpr
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
program dfm2xml;
{$APPTYPE CONSOLE}
{$IF CompilerVersion >= 21.0}
{$WEAKLINKRTTI ON}
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
{$IFEND}
uses
System.SysUtils,
System.Classes,
System.IOUtils,
Winapi.Windows,
dfm2xmlImpl in 'dfm2xmlImpl.pas';
procedure ObjectBinaryToXml(const FileName: String; OutputStream: TStream); overload;
var
InputStream: TStream;
MemoryStream: TMemoryStream;
begin
InputStream := TFileStream.Create(FileName, fmOpenRead);
try
case TestStreamFormat(InputStream) of
sofText, sofUTF8Text:
begin
MemoryStream := TMemoryStream.Create;
try
ObjectTextToBinary(InputStream, MemoryStream);
MemoryStream.Position := 0;
ObjectBinaryToXml(MemoryStream, OutputStream);
finally
MemoryStream.Free;
end;
end;
else
assert(false);
end;
finally
InputStream.Free;
end;
end;
var
OutputStream: TStream;
OutputWriter: TStreamWriter;
Param: String;
FileNames: TStringList;
FileName: String;
i: Integer;
begin
if ParamCount = 0 then
begin
Writeln('usage: dfm2xml (folder|file.dfm)+');
end else
begin
OutputStream := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));
try
OutputWriter := TStreamWriter.Create(OutputStream);
try
OutputWriter.Write('<xml>' + sLineBreak);
FileNames := TStringList.Create;
try
for i := 1 to ParamCount do
begin
Param := ParamStr(i);
if DirectoryExists(Param) then
begin
for FileName in TDirectory.GetFiles(Param, '*.dfm', TSearchOption.soAllDirectories) do
begin
FileNames.Add(FileName)
end;
end else
if FileExists(FileName) then
begin
FileNames.Add(Param);
end;
end;
FileNames.Sort;
for FileName in FileNames do
begin
OutputWriter.Write('<unit name="' + ChangeFileExt(ExtractFileName(FileName), '') + '">' + sLineBreak);
ObjectBinaryToXml(FileName, OutputStream);
OutputWriter.Write('</unit>' + sLineBreak);
end;
finally
FileNames.Sort;
end;
OutputWriter.Write('</xml>');
finally
OutputWriter.Free;
end;
finally
OutputStream.Free;
end;
end;
end.