source: oup/current/FileClasses/_DataTypes.pas@ 209

Last change on this file since 209 was 207, checked in by alloc, 18 years ago
File size: 12.8 KB
Line 
1unit _DataTypes;
2
3interface
4
5uses
6 Classes;
7
8type
9 TDataField = class
10 protected
11 FOffset: Integer;
12 FName: String;
13 FDescription: String;
14 FDataLength: Integer;
15 FParentFile: TObject;
16 FChanged: Boolean;
17 function GetValueAsString: String; virtual; abstract;
18 public
19 constructor Create(ParentFile: TObject; Offset: Integer;
20 Name, Description: String; ExtraArgs: Pointer); virtual;
21
22 procedure Update(Offset, Length: Integer); virtual; abstract;
23
24 property Offset: Integer read FOffset;
25 property Name: String read FName;
26 property Description: String read FDescription;
27 property DataLength: Integer read FDataLength;
28 property ValueAsString: String read GetValueAsString;
29 end;
30
31 TFieldType = class of TDataField;
32
33
34 TBlock = class(TDataField)
35 private
36 FDataFields: array of TDataField;
37 function GetFieldByOffset(Offset: Integer): TDataField;
38 function GetFieldByIndex(ID: Integer): TDataField;
39 function GetFieldCount: Integer;
40 public
41 // ExtraArgs: keine
42 constructor Create(ParentFile: TObject; Offset: Integer;
43 Name, Description: String; ExtraArgs: Pointer); override;
44 procedure Update(Offset, Length: Integer); override;
45 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
46 property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
47 property FieldCount: Integer read GetFieldCount;
48
49 procedure AddField(fieldtype: TFieldType; Offset: Integer;
50 Name, Description: String; ExtraArgs: Pointer);
51 end;
52
53
54 TInt = class(TDataField)
55 private
56 FInt: Integer;
57 function GetValueAsString: String; override;
58 public
59 // ExtraArgs: Pointer auf Integer: Bytes of TInt
60 constructor Create(ParentFile: TObject; Offset: Integer;
61 Name, Description: String; ExtraArgs: Pointer); override;
62 procedure Update(Offset, Length: Integer); override;
63 end;
64
65
66 TBitSet = class(TDataField)
67 private
68 FBits: Byte;
69 FNames: TStringList;
70 function GetValueAsString: String; override;
71 public
72 // ExtraArgs: Pointer auf TStringList
73 constructor Create(ParentFile: TObject; Offset: Integer;
74 Name, Description: String; ExtraArgs: Pointer); override;
75 procedure Update(Offset, Length: Integer); override;
76 end;
77
78
79 TLevelID = class(TDataField)
80 private
81 FLevelID: Integer;
82 function GetValueAsString: String; override;
83 public
84 // ExtraArgs: keine
85 constructor Create(ParentFile: TObject; Offset: Integer;
86 Name, Description: String; ExtraArgs: Pointer); override;
87 procedure Update(Offset, Length: Integer); override;
88 end;
89
90
91 TFileID = class(TDataField)
92 private
93 FFileID: Integer;
94 function GetValueAsString: String; override;
95 public
96 // ExtraArgs: keine
97 constructor Create(ParentFile: TObject; Offset: Integer;
98 Name, Description: String; ExtraArgs: Pointer); override;
99 procedure Update(Offset, Length: Integer); override;
100 end;
101
102
103 TLinkByID = class(TDataField)
104 private
105 FFileID: Integer;
106 FPosExts: String;
107 function GetValueAsString: String; override;
108 public
109 // ExtraArgs: Pointer auf String: Possible Exts
110 constructor Create(ParentFile: TObject; Offset: Integer;
111 Name, Description: String; ExtraArgs: Pointer); override;
112 procedure Update(Offset, Length: Integer); override;
113 end;
114
115
116 TString = class(TDataField)
117 private
118 FString: String;
119 function GetValueAsString: String; override;
120 public
121 // ExtraArgs: Pointer auf Integer: Length
122 constructor Create(ParentFile: TObject; Offset: Integer;
123 Name, Description: String; ExtraArgs: Pointer); override;
124 procedure Update(Offset, Length: Integer); override;
125 end;
126
127
128 TArray = class(TDataField)
129 private
130 FDataFields: array of TDataField;
131 function GetFieldByOffset(Offset: Integer): TDataField;
132 function GetFieldByIndex(ID: Integer): TDataField;
133 function GetFieldCount: Integer;
134 public
135 // ExtraArgs: Pointer auf 2 Integer: Length+Count (packed record...)
136 constructor Create(ParentFile: TObject; Offset: Integer;
137 Name, Description: String; ExtraArgs: Pointer); override;
138 procedure Update(Offset, Length: Integer); override;
139 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
140 property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
141 property FieldCount: Integer read GetFieldCount;
142
143 procedure AddField(fieldtype: TFieldType; Offset: Integer;
144 Name, Description: String; ExtraArgs: Pointer);
145 end;
146
147
148 TRawLink = class(TDataField)
149 private
150 FRawAddress: Integer;
151 function GetValueAsString: String; override;
152 public
153 // ExtraArgs: keine
154 constructor Create(ParentFile: TObject; Offset: Integer;
155 Name, Description: String; ExtraArgs: Pointer); override;
156 procedure Update(Offset, Length: Integer); override;
157 end;
158
159
160 TUnused = class(TDataField)
161 private
162 function GetValueAsString: String; override;
163 public
164 // ExtraArgs: Pointer auf Integer: Length
165 constructor Create(ParentFile: TObject; Offset: Integer;
166 Name, Description: String; ExtraArgs: Pointer); override;
167 procedure Update(Offset, Length: Integer); override;
168 end;
169
170
171
172
173implementation
174
175uses
176 SysUtils, Dialogs, _FileTypes, ConnectionManager;
177
178
179
180
181{ TDataType }
182
183constructor TDataField.Create(ParentFile: TObject; Offset: Integer;
184 Name, Description: String; ExtraArgs: Pointer);
185begin
186 FOffset := Offset;
187 FName := Name;
188 FDescription := Description;
189 FParentFile := ParentFile;
190end;
191
192
193
194{ TString }
195
196constructor TString.Create(ParentFile: TObject; Offset: Integer;
197 Name, Description: String; ExtraArgs: Pointer);
198var
199 fstream: TMemoryStream;
200 i: Integer;
201begin
202 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
203 FDataLength := Integer(ExtraArgs^);
204 fstream := TFile(ParentFile).FileStream;
205 fstream.Seek(Offset, soFromBeginning);
206 SetLength(FString, FDataLength);
207 fstream.Read(FString[1], FDataLength);
208 for i := 1 to FDataLength do
209 if FString[i] = Chr(0) then
210 begin
211 SetLength(FString, i - 1);
212 Break;
213 end;
214end;
215
216function TString.GetValueAsString: String;
217begin
218 Result := FString;
219end;
220
221procedure TString.Update(Offset, Length: Integer);
222begin
223 Exit;
224end;
225
226
227
228{ TInt }
229
230constructor TInt.Create(ParentFile: TObject; Offset: Integer;
231 Name, Description: String; ExtraArgs: Pointer);
232var
233 fstream: TMemoryStream;
234begin
235 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
236 FDataLength := Integer(ExtraArgs^);
237 FInt := 0;
238 fstream := TFile(ParentFile).FileStream;
239 fstream.Seek(Offset, soFromBeginning);
240 fstream.Read(FInt, FDataLength);
241end;
242
243function TInt.GetValueAsString: String;
244begin
245 Result := IntToStr(FInt);
246end;
247
248procedure TInt.Update(Offset, Length: Integer);
249begin
250 Exit;
251end;
252
253
254
255{ TArray }
256
257procedure TArray.AddField(fieldtype: TFieldType; Offset: Integer;
258 Name, Description: String; ExtraArgs: Pointer);
259begin
260 Exit;
261end;
262
263constructor TArray.Create(ParentFile: TObject; Offset: Integer;
264 Name, Description: String; ExtraArgs: Pointer);
265begin
266 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
267end;
268
269function TArray.GetFieldByIndex(ID: Integer): TDataField;
270begin
271 if ID < Length(FDataFields) then
272 Result := FDataFields[ID]
273 else
274 Result := nil;
275end;
276
277function TArray.GetFieldByOffset(Offset: Integer): TDataField;
278var
279 i: Integer;
280begin
281 Result := nil;
282
283 if Length(FDataFields) > 0 then
284 begin
285 for i := 0 to High(FDataFields) do
286 if FDataFields[i].Offset = Offset then
287 break;
288 if i < Length(FDataFields) then
289 Result := FDataFields[i];
290 end;
291end;
292
293function TArray.GetFieldCount: Integer;
294begin
295 Result := Length(FDataFields);
296end;
297
298procedure TArray.Update(Offset, Length: Integer);
299begin
300 Exit;
301end;
302
303
304
305{ TBlock }
306
307procedure TBlock.AddField(fieldtype: TFieldType; Offset: Integer; Name,
308 Description: String; ExtraArgs: Pointer);
309var
310 i: Integer;
311begin
312 if Length(FDataFields) > 0 then
313 begin
314 for i := 0 to High(FDataFields) do
315 if FDataFields[i].FOffset = Offset then
316 Break;
317 if i < Length(FDataFields) then
318 begin
319 ShowMessage('Field exists');
320 Exit;
321 end;
322 end;
323 SetLength(FDataFields, Length(FDataFields) + 1);
324 FDataFields[High(FDataFields)] := TFieldType(fieldtype).Create(
325 FParentFile, Offset, Name, Description, ExtraArgs);
326end;
327
328constructor TBlock.Create(ParentFile: TObject; Offset: Integer;
329 Name, Description: String; ExtraArgs: Pointer);
330begin
331 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
332end;
333
334function TBlock.GetFieldByIndex(ID: Integer): TDataField;
335begin
336 Result := FDataFields[ID];
337end;
338
339function TBlock.GetFieldByOffset(Offset: Integer): TDataField;
340begin
341 Exit;
342end;
343
344function TBlock.GetFieldCount: Integer;
345begin
346 Result := Length(FDataFields);
347end;
348
349procedure TBlock.Update(Offset, Length: Integer);
350begin
351 Exit;
352end;
353
354
355
356{ TLevelID }
357
358constructor TLevelID.Create(ParentFile: TObject; Offset: Integer;
359 Name, Description: String; ExtraArgs: Pointer);
360var
361 fstream: TMemoryStream;
362begin
363 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
364 FDataLength := 4;
365 fstream := TFile(ParentFile).FileStream;
366 fstream.Seek(Offset, soFromBeginning);
367 fstream.Read(FLevelID, 4);
368 FLevelID := FLevelID div 256 div 256 div 256 div 2;
369end;
370
371function TLevelID.GetValueAsString: String;
372begin
373 Result := IntToStr(FLevelID);
374end;
375
376procedure TLevelID.Update(Offset, Length: Integer);
377begin
378 Exit;
379end;
380
381
382
383{ TFileID }
384
385constructor TFileID.Create(ParentFile: TObject; Offset: Integer;
386 Name, Description: String; ExtraArgs: Pointer);
387var
388 fstream: TMemoryStream;
389begin
390 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
391 FDataLength := 4;
392 fstream := TFile(ParentFile).FileStream;
393 fstream.Seek(Offset, soFromBeginning);
394 fstream.Read(FFileID, 4);
395 if FFileID > 0 then
396 FFileID := FFileID div 256
397 else
398 FFileID := -1;
399end;
400
401function TFileID.GetValueAsString: String;
402begin
403 Result := IntToStr(FFileID);
404end;
405
406procedure TFileID.Update(Offset, Length: Integer);
407begin
408 Exit;
409end;
410
411
412
413{ TLinkByID }
414
415constructor TLinkByID.Create(ParentFile: TObject; Offset: Integer; Name,
416 Description: String; ExtraArgs: Pointer);
417var
418 fstream: TMemoryStream;
419begin
420 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
421 FDataLength := 4;
422 FPosExts := String(ExtraArgs^);
423 fstream := TFile(ParentFile).FileStream;
424 fstream.Seek(Offset, soFromBeginning);
425 fstream.Read(FFileID, 4);
426 if FFileID > 0 then
427 FFileID := FFileID div 256
428 else
429 FFileID := -1;
430end;
431
432function TLinkByID.GetValueAsString: String;
433begin
434 Result := IntToStr(FFileID);
435end;
436
437procedure TLinkByID.Update(Offset, Length: Integer);
438begin
439 Exit;
440end;
441
442
443
444{ TRawLink }
445
446constructor TRawLink.Create(ParentFile: TObject; Offset: Integer; Name,
447 Description: String; ExtraArgs: Pointer);
448var
449 fstream: TMemoryStream;
450begin
451 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
452 FDataLength := 4;
453 fstream := TFile(ParentFile).FileStream;
454 fstream.Seek(Offset, soFromBeginning);
455 fstream.Read(FRawAddress, 4);
456end;
457
458function TRawLink.GetValueAsString: String;
459begin
460 Result := IntToStr(FRawAddress);
461end;
462
463procedure TRawLink.Update(Offset, Length: Integer);
464begin
465 Exit;
466end;
467
468
469
470{ TUnused }
471
472constructor TUnused.Create(ParentFile: TObject; Offset: Integer; Name,
473 Description: String; ExtraArgs: Pointer);
474begin
475 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
476 FDataLength := Integer(ExtraArgs^);
477end;
478
479function TUnused.GetValueAsString: String;
480begin
481 Result := '';
482end;
483
484procedure TUnused.Update(Offset, Length: Integer);
485begin
486 Exit;
487end;
488
489
490
491{ TBitSet }
492
493constructor TBitSet.Create(ParentFile: TObject; Offset: Integer; Name,
494 Description: String; ExtraArgs: Pointer);
495var
496 fstream: TMemoryStream;
497begin
498 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
499 FNames := TStringList.Create;
500 FNames.AddStrings(TStringList(ExtraArgs^));
501 FDataLength := 1;
502 FBits := 0;
503 fstream := TFile(ParentFile).FileStream;
504 fstream.Seek(Offset, soFromBeginning);
505 fstream.Read(FBits, FDataLength);
506end;
507
508function TBitSet.GetValueAsString: String;
509begin
510 Result := IntToStr(FBits);
511end;
512
513procedure TBitSet.Update(Offset, Length: Integer);
514begin
515 Exit;
516end;
517
518end.
Note: See TracBrowser for help on using the repository browser.