-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUDLPorts.pas
206 lines (179 loc) · 4.54 KB
/
UDLPorts.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
unit UDLPorts;
interface
uses
Windows, StreamedObjects, CheckLst, TypedStream;
type
TPWADsList = class;
TDoomPortType = (ptUnknown, ptGZDoom);
TDoomPortTypeSet = set of TDoomPortType;
TPWADsList = class(TStreamedObjectList)
public
procedure InsertPWAD(const Index: Integer; const FileName: string);
procedure ToListBox(const LB: TCheckListBox);
end;
TDoomPort = class(TStreamedObject)
private
FDescr: string;
FFileName: string;
FPortType: TDoomPortType;
FVer: string;
procedure SetFileName(const Value: string);
protected
procedure LoadFromTypedStream(const Stream: TTypedStream); override;
procedure SaveToTypedStream(const Stream: TTypedStream); override;
public
constructor Create; override;
function CmdParams(const GameType: Integer): string;
function PortName: string;
property Descr: string read FDescr;
property FileName: string read FFileName write SetFileName;
property PortType: TDoomPortType read FPortType;
property Ver: string read FVer;
end;
TIWAD = class(TStreamedObject)
private
FPWADsList: TPWADsList;
protected
procedure LoadFromTypedStream(const Stream: TTypedStream); override;
procedure SaveToTypedStream(const Stream: TTypedStream); override;
public
Descr: string;
FileName: string;
constructor Create; override;
destructor Destroy; override;
property PWADsList: TPWADsList read FPWADsList;
end;
TPWAD = class(TStreamedObject)
protected
procedure LoadFromTypedStream(const Stream: TTypedStream); override;
procedure SaveToTypedStream(const Stream: TTypedStream); override;
public
Checked: Boolean;
FileName: string;
end;
TWADVersion = record
Hash: string;
Version: string;
end;
implementation
uses
SysUtils, JvVersionInfo, System.Character;
procedure TPWAD.LoadFromTypedStream(const Stream: TTypedStream);
begin
inherited;
FileName := Stream.ReadString;
Checked := Stream.ReadBoolean;
end;
procedure TPWAD.SaveToTypedStream(const Stream: TTypedStream);
begin
inherited;
Stream.WriteString(FileName);
Stream.WriteBoolean(Checked);
end;
constructor TIWAD.Create;
begin
inherited;
FPWADsList := TPWADsList.Create;
FVersion := 2;
end;
destructor TIWAD.Destroy;
begin
FreeAndNil(FPWADsList);
inherited;
end;
procedure TIWAD.LoadFromTypedStream(const Stream: TTypedStream);
begin
inherited;
FileName := Stream.ReadString;
Descr := Stream.ReadString;
if FSavedVersion >= 2 then
PWADsList.LoadFromStream(Stream);
end;
procedure TIWAD.SaveToTypedStream(const Stream: TTypedStream);
begin
inherited;
Stream.WriteString(FileName);
Stream.WriteString(Descr);
PWADsList.SaveToStream(Stream);
end;
constructor TDoomPort.Create;
begin
inherited Create;
FVersion := 2;
end;
function TDoomPort.CmdParams(const GameType: Integer): string;
begin
Result := '';
end;
procedure TDoomPort.LoadFromTypedStream(const Stream: TTypedStream);
begin
inherited;
FileName := Stream.ReadString;
if FSavedVersion < 2 then
begin
FDescr := Stream.ReadString;
FVer := Stream.ReadString;
FPortType := TDoomPortType(Stream.ReadInteger);
end;
end;
function TDoomPort.PortName: string;
begin
Result := FDescr + ' ' + FVer + ' (' + FFileName + ')';
end;
procedure TDoomPort.SaveToTypedStream(const Stream: TTypedStream);
begin
inherited;
Stream.WriteString(FFileName);
if FVersion < 2 then
begin
Stream.WriteString(FDescr);
Stream.WriteString(FVer);
Stream.WriteInteger(Ord(FPortType));
end;
end;
procedure TDoomPort.SetFileName(const Value: string);
var
VersionInfo: TJvVersionInfo;
begin
FFileName := Value;
VersionInfo := TJvVersionInfo.Create(FFileName);
try
FDescr := VersionInfo.ProductName;
FVer := VersionInfo.FileVersion;
if AnsiPos('GZDoom', FDescr) = 1 then
FPortType := ptGZDoom
else
begin
FPortType := ptUnknown;
if FDescr = '' then
FDescr := ChangeFileExt(ExtractFileName(FFileName), '');
if FDescr.Length > 0 then
FDescr[1] := FDescr[1].ToUpper;
end;
finally
VersionInfo.Free;
end;
end;
procedure TPWADsList.InsertPWAD(const Index: Integer; const FileName: string);
var
PWAD: TPWAD;
begin
PWAD := TPWAD.Create;
PWAD.FileName := FileName;
PWAD.Checked := True;
List.Insert(Index, PWAD);
end;
procedure TPWADsList.ToListBox(const LB: TCheckListBox);
var
i, k: Integer;
PWAD: TPWAD;
begin
LB.Items.Clear;
for i := 0 to List.Count - 1 do
begin
PWAD := TPWAD(List[i]);
k := LB.Items.Add(PWAD.FileName);
LB.Checked[k] := PWAD.Checked;
end;
end;
end.