1 | unit _DataTypes;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, _TreeElement;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TContainer = class;
|
---|
10 |
|
---|
11 | TDataField = class(TTreeElement)
|
---|
12 | protected
|
---|
13 | FOffset: Integer;
|
---|
14 | FName: String;
|
---|
15 | FType: String;
|
---|
16 | FDescription: String;
|
---|
17 | FDataLength: Integer;
|
---|
18 | FParentFile: TObject;
|
---|
19 | FParentBlock: TContainer;
|
---|
20 | FChanged: Boolean;
|
---|
21 | FExtraArgs: array of TVarRec;
|
---|
22 | function GetChildCount: Integer; override;
|
---|
23 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
24 | function GetCaption: String; override;
|
---|
25 | function GetType: String; override;
|
---|
26 | function GetValueAsString: String; virtual;
|
---|
27 | public
|
---|
28 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
29 | Name, Description: String; ExtraArgs: array of const); virtual;
|
---|
30 |
|
---|
31 | procedure Update(Offset, Length: Integer); virtual; abstract;
|
---|
32 | procedure WriteData(stream: TStream); virtual; abstract;
|
---|
33 |
|
---|
34 | property Offset: Integer read FOffset;
|
---|
35 | property Name: String read FName;
|
---|
36 | property Description: String read FDescription;
|
---|
37 | property DataLength: Integer read FDataLength;
|
---|
38 | property ValueAsString: String read GetValueAsString;
|
---|
39 | end;
|
---|
40 |
|
---|
41 | TFieldType = class of TDataField;
|
---|
42 |
|
---|
43 | TContainer = class(TDataField)
|
---|
44 | public
|
---|
45 | function AddField(fieldtype: TFieldType; Name, Description: String;
|
---|
46 | ExtraArgs: array of const): TDataField; virtual; abstract;
|
---|
47 | procedure UpdateSize; virtual; abstract;
|
---|
48 | end;
|
---|
49 |
|
---|
50 | TBlock = class(TContainer)
|
---|
51 | protected
|
---|
52 | FDataFields: array of TDataField;
|
---|
53 | function GetChildCount: Integer; override;
|
---|
54 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
55 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
56 | public
|
---|
57 | // ExtraArgs: Pointer auf Integer: BlockLength <- no longer
|
---|
58 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
59 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
60 | procedure Update(Offset, Length: Integer); override;
|
---|
61 | procedure WriteData(stream: TStream); override;
|
---|
62 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
---|
63 |
|
---|
64 | function AddField(fieldtype: TFieldType; Name, Description: String;
|
---|
65 | ExtraArgs: array of const): TDataField; override;
|
---|
66 | procedure UpdateSize; override;
|
---|
67 | end;
|
---|
68 |
|
---|
69 |
|
---|
70 | TInt = class(TDataField)
|
---|
71 | protected
|
---|
72 | FInt: Integer;
|
---|
73 | function GetValueAsString: String; override;
|
---|
74 | public
|
---|
75 | // ExtraArgs: Pointer auf Integer: Bytes of TInt
|
---|
76 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
77 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
78 | procedure Update(Offset, Length: Integer); override;
|
---|
79 | procedure WriteData(stream: TStream); override;
|
---|
80 | end;
|
---|
81 |
|
---|
82 |
|
---|
83 | TFloat = class(TDataField)
|
---|
84 | protected
|
---|
85 | FFloat: Single;
|
---|
86 | function GetValueAsString: String; override;
|
---|
87 | public
|
---|
88 | // ExtraArgs: none
|
---|
89 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
90 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
91 | procedure Update(Offset, Length: Integer); override;
|
---|
92 | procedure WriteData(stream: TStream); override;
|
---|
93 | end;
|
---|
94 |
|
---|
95 |
|
---|
96 | TBitSet = class(TDataField)
|
---|
97 | protected
|
---|
98 | FBits: Byte;
|
---|
99 | FNames: TStringList;
|
---|
100 | function GetValueAsString: String; override;
|
---|
101 | public
|
---|
102 | // ExtraArgs: Pointer auf TStringList
|
---|
103 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
104 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
105 | procedure Update(Offset, Length: Integer); override;
|
---|
106 | procedure WriteData(stream: TStream); override;
|
---|
107 | end;
|
---|
108 |
|
---|
109 |
|
---|
110 | TLevelID = class(TDataField)
|
---|
111 | protected
|
---|
112 | FLevelID: Integer;
|
---|
113 | function GetValueAsString: String; override;
|
---|
114 | public
|
---|
115 | // ExtraArgs: keine
|
---|
116 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
117 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
118 | procedure Update(Offset, Length: Integer); override;
|
---|
119 | procedure WriteData(stream: TStream); override;
|
---|
120 | end;
|
---|
121 |
|
---|
122 |
|
---|
123 | TFileID = class(TDataField)
|
---|
124 | protected
|
---|
125 | FFileID: Integer;
|
---|
126 | function GetValueAsString: String; override;
|
---|
127 | public
|
---|
128 | // ExtraArgs: keine
|
---|
129 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
130 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
131 | procedure Update(Offset, Length: Integer); override;
|
---|
132 | procedure WriteData(stream: TStream); override;
|
---|
133 | end;
|
---|
134 |
|
---|
135 |
|
---|
136 | TDatLink = class(TDataField)
|
---|
137 | protected
|
---|
138 | FPosExts: String;
|
---|
139 | function GetTarget: TObject; virtual; abstract;
|
---|
140 | public
|
---|
141 | property PosExts: String read FPosExts;
|
---|
142 | property TargetFile: TObject read GetTarget;
|
---|
143 | end;
|
---|
144 |
|
---|
145 |
|
---|
146 | TLinkByID = class(TDatLink)
|
---|
147 | protected
|
---|
148 | FFileID: Integer;
|
---|
149 | function GetChildCount: Integer; override;
|
---|
150 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
151 | function GetValueAsString: String; override;
|
---|
152 | function GetTarget: TObject; override;
|
---|
153 | public
|
---|
154 | // ExtraArgs: Pointer auf String: Possible Exts
|
---|
155 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
156 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
157 | procedure Update(Offset, Length: Integer); override;
|
---|
158 | procedure WriteData(stream: TStream); override;
|
---|
159 | end;
|
---|
160 |
|
---|
161 |
|
---|
162 | TString = class(TDataField)
|
---|
163 | protected
|
---|
164 | FString: String;
|
---|
165 | function GetValueAsString: String; override;
|
---|
166 | public
|
---|
167 | // ExtraArgs: Pointer auf Integer: Length
|
---|
168 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
169 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
170 | procedure Update(Offset, Length: Integer); override;
|
---|
171 | procedure WriteData(stream: TStream); override;
|
---|
172 | end;
|
---|
173 |
|
---|
174 |
|
---|
175 | TArray = class(TContainer)
|
---|
176 | protected
|
---|
177 | FDataFields: array of TBlock;
|
---|
178 | FTemplate: TBlock;
|
---|
179 | FCounterSize: Integer;
|
---|
180 | FBlockCount: Integer;
|
---|
181 | function GetChildCount: Integer; override;
|
---|
182 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
183 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
184 | public
|
---|
185 | // ExtraArgs:
|
---|
186 | // 1. Integer: CounterSize (if 0 then 2. integer is required)
|
---|
187 | // 2. Integer: BlockCount (for fixed-size arrays)
|
---|
188 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
189 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
190 | procedure Update(Offset, Length: Integer); override;
|
---|
191 | procedure WriteData(stream: TStream); override;
|
---|
192 |
|
---|
193 | function AddField(fieldtype: TFieldType; Name, Description: String;
|
---|
194 | ExtraArgs: array of const): TDataField; override;
|
---|
195 | procedure SetCount; overload;
|
---|
196 | procedure SetCount(n: Integer); overload;
|
---|
197 | procedure UpdateSize; override;
|
---|
198 | end;
|
---|
199 |
|
---|
200 |
|
---|
201 | TRawLink = class(TDataField)
|
---|
202 | protected
|
---|
203 | FRawAddress: Integer;
|
---|
204 | FRawType: String;
|
---|
205 | FSep: Boolean;
|
---|
206 | function GetValueAsString: String; override;
|
---|
207 | public
|
---|
208 | // ExtraArgs: String: RawType; Bool: Sep
|
---|
209 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
210 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
211 | procedure Update(Offset, Length: Integer); override;
|
---|
212 | procedure WriteData(stream: TStream); override;
|
---|
213 |
|
---|
214 | property RawType: String read FRawType;
|
---|
215 | end;
|
---|
216 |
|
---|
217 |
|
---|
218 | TUnused = class(TDataField)
|
---|
219 | protected
|
---|
220 | function GetValueAsString: String; override;
|
---|
221 | public
|
---|
222 | // ExtraArgs: Pointer auf Integer: Length
|
---|
223 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
224 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
225 | procedure Update(Offset, Length: Integer); override;
|
---|
226 | procedure WriteData(stream: TStream); override;
|
---|
227 | end;
|
---|
228 |
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|
232 | implementation
|
---|
233 |
|
---|
234 | uses
|
---|
235 | SysUtils, Dialogs, _FileTypes, ConnectionManager, StrUtils;
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 |
|
---|
240 | { TDataType }
|
---|
241 |
|
---|
242 | constructor TDataField.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
243 | Name, Description: String; ExtraArgs: array of const);
|
---|
244 | var
|
---|
245 | i: Integer;
|
---|
246 | begin
|
---|
247 | if Assigned(ParentBlock) then
|
---|
248 | FOffset := ParentBlock.Offset + ParentBlock.DataLength
|
---|
249 | else
|
---|
250 | FOffset := 0;
|
---|
251 | FName := Name;
|
---|
252 | FDescription := Description;
|
---|
253 | FParentFile := ParentFile;
|
---|
254 | FParentBlock := ParentBlock;
|
---|
255 | SetLength(FExtraArgs, Length(ExtraArgs));
|
---|
256 | if Length(ExtraArgs) > 0 then
|
---|
257 | for i := 0 to High(ExtraArgs) do
|
---|
258 | FExtraArgs[i] := ExtraArgs[i];
|
---|
259 | FConnectionID := TFile(ParentFile).ConnectionID;
|
---|
260 | end;
|
---|
261 |
|
---|
262 | function TDataField.GetCaption: String;
|
---|
263 | begin
|
---|
264 | Result := FName;
|
---|
265 | end;
|
---|
266 |
|
---|
267 | function TDataField.GetChild(ID: Integer): TTreeElement;
|
---|
268 | begin
|
---|
269 | Result := nil;
|
---|
270 | end;
|
---|
271 |
|
---|
272 | function TDataField.GetChildCount: Integer;
|
---|
273 | begin
|
---|
274 | Result := 0;
|
---|
275 | end;
|
---|
276 |
|
---|
277 | function TDataField.GetType: String;
|
---|
278 | begin
|
---|
279 | Result := FType;
|
---|
280 | end;
|
---|
281 |
|
---|
282 | function TDataField.GetValueAsString: String;
|
---|
283 | begin
|
---|
284 | Result := '';
|
---|
285 | end;
|
---|
286 |
|
---|
287 | { TString }
|
---|
288 |
|
---|
289 | constructor TString.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
290 | Name, Description: String; ExtraArgs: array of const);
|
---|
291 | begin
|
---|
292 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
293 | FDataLength := ExtraArgs[0].VInteger;
|
---|
294 | FType := 'String[' + IntToStr(FDataLength) + ']';
|
---|
295 | end;
|
---|
296 |
|
---|
297 | function TString.GetValueAsString: String;
|
---|
298 | begin
|
---|
299 | Result := FString;
|
---|
300 | end;
|
---|
301 |
|
---|
302 | procedure TString.Update(Offset, Length: Integer);
|
---|
303 | var
|
---|
304 | fstream: TMemoryStream;
|
---|
305 | i: Integer;
|
---|
306 | begin
|
---|
307 | fstream := TFile(FParentFile).FileStream;
|
---|
308 | fstream.Seek(FOffset, soFromBeginning);
|
---|
309 | SetLength(FString, FDataLength);
|
---|
310 | fstream.Read(FString[1], FDataLength);
|
---|
311 | for i := 1 to FDataLength do
|
---|
312 | if FString[i] = Chr(0) then
|
---|
313 | begin
|
---|
314 | SetLength(FString, i - 1);
|
---|
315 | Break;
|
---|
316 | end;
|
---|
317 | end;
|
---|
318 |
|
---|
319 | procedure TString.WriteData(stream: TStream);
|
---|
320 | var
|
---|
321 | temps: String;
|
---|
322 | i: Integer;
|
---|
323 | begin
|
---|
324 | temps := FString;
|
---|
325 | SetLength(temps, FDataLength);
|
---|
326 | for i := Length(FString) + 1 to FDataLength do
|
---|
327 | temps[i] := #0;
|
---|
328 | stream.Write(temps[1], FDataLength);
|
---|
329 | end;
|
---|
330 |
|
---|
331 |
|
---|
332 |
|
---|
333 | { TInt }
|
---|
334 |
|
---|
335 | constructor TInt.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
336 | Name, Description: String; ExtraArgs: array of const);
|
---|
337 | begin
|
---|
338 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
339 | FDataLength := ExtraArgs[0].VInteger;
|
---|
340 | FType := 'Int' + IntToStr(FDataLength * 8);
|
---|
341 | FInt := 0;
|
---|
342 | end;
|
---|
343 |
|
---|
344 | function TInt.GetValueAsString: String;
|
---|
345 | begin
|
---|
346 | Result := IntToStr(FInt);
|
---|
347 | end;
|
---|
348 |
|
---|
349 | procedure TInt.Update(Offset, Length: Integer);
|
---|
350 | var
|
---|
351 | fstream: TMemoryStream;
|
---|
352 | begin
|
---|
353 | fstream := TFile(FParentFile).FileStream;
|
---|
354 | fstream.Seek(FOffset, soFromBeginning);
|
---|
355 | fstream.Read(FInt, FDataLength);
|
---|
356 | end;
|
---|
357 |
|
---|
358 | procedure TInt.WriteData(stream: TStream);
|
---|
359 | begin
|
---|
360 | stream.Write(FInt, FDataLength);
|
---|
361 | end;
|
---|
362 |
|
---|
363 |
|
---|
364 |
|
---|
365 | { TArray }
|
---|
366 |
|
---|
367 | function TArray.AddField(fieldtype: TFieldType;
|
---|
368 | Name, Description: String; ExtraArgs: array of const): TDataField;
|
---|
369 | var
|
---|
370 | i: Integer;
|
---|
371 | begin
|
---|
372 | Result := FTemplate.AddField(fieldtype, Name, Description, ExtraArgs);
|
---|
373 | end;
|
---|
374 |
|
---|
375 | constructor TArray.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
376 | Name, Description: String; ExtraArgs: array of const);
|
---|
377 | begin
|
---|
378 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
379 | FCounterSize := ExtraArgs[0].VInteger;
|
---|
380 | FType := '';
|
---|
381 | if Length(ExtraArgs) = 2 then
|
---|
382 | FBlockCount := ExtraArgs[1].VInteger
|
---|
383 | else
|
---|
384 | FBlockCount := 0;
|
---|
385 | FTemplate := TBlock.Create(ParentFile, Self, '', '', []);
|
---|
386 | end;
|
---|
387 |
|
---|
388 | function TArray.GetChildCount: Integer;
|
---|
389 | begin
|
---|
390 | Result := Length(FDataFields);
|
---|
391 | end;
|
---|
392 |
|
---|
393 | function TArray.GetChild(ID: Integer): TTreeElement;
|
---|
394 | begin
|
---|
395 | Result := FDataFields[ID];
|
---|
396 | end;
|
---|
397 |
|
---|
398 | function TArray.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
399 | begin
|
---|
400 | Exit;
|
---|
401 | end;
|
---|
402 |
|
---|
403 | procedure TArray.SetCount;
|
---|
404 | var
|
---|
405 | fstream: TMemoryStream;
|
---|
406 | arr_index: Integer;
|
---|
407 | i: Integer;
|
---|
408 |
|
---|
409 | procedure Add(DestBlock, SrcBlock: TBlock);
|
---|
410 | var
|
---|
411 | fid: Integer;
|
---|
412 | field: TDataField;
|
---|
413 | result: TDataField;
|
---|
414 | begin
|
---|
415 | if Length(SrcBlock.FDataFields) > 0 then
|
---|
416 | begin
|
---|
417 | for fid := 0 to High(SrcBlock.FDataFields) do
|
---|
418 | begin
|
---|
419 | field := SrcBlock.FDataFields[fid];
|
---|
420 | result := DestBlock.AddField(TFieldType(field.ClassType), field.Name, field.Description, field.FExtraArgs);
|
---|
421 | if result is TBlock then
|
---|
422 | Add(TBlock(result), TBlock(field));
|
---|
423 | end;
|
---|
424 | end;
|
---|
425 | end;
|
---|
426 |
|
---|
427 | begin
|
---|
428 | if FCounterSize > 0 then
|
---|
429 | begin
|
---|
430 | fstream := TFile(FParentFile).FileStream;
|
---|
431 | fstream.Seek(Offset, soFromBeginning);
|
---|
432 | FBlockCount := 0;
|
---|
433 | fstream.Read(FBlockCount, FCounterSize);
|
---|
434 | end;
|
---|
435 | FDataLength := FCounterSize;
|
---|
436 | if FBlockCount > 0 then
|
---|
437 | begin
|
---|
438 | for arr_index := 0 to FBlockCount - 1 do
|
---|
439 | begin
|
---|
440 | SetLength(FDataFields, arr_index + 1);
|
---|
441 | FDataFields[arr_index] := TBlock.Create(FParentFile, Self,
|
---|
442 | '[' + IntToStr(arr_index) + ']', '', []);
|
---|
443 | Add(FDataFields[arr_index], FTemplate);
|
---|
444 | end;
|
---|
445 | end;
|
---|
446 | if Pos('[', FName) > 0 then
|
---|
447 | begin
|
---|
448 | if Pos(']', FName) = Length(FName) then
|
---|
449 | begin
|
---|
450 | i := Pos('[', ReverseString(FName));
|
---|
451 | FName := MidStr(FName, 1, Length(FName) - i);
|
---|
452 | end;
|
---|
453 | end;
|
---|
454 | FName := FName + '[' + IntToStr(FBlockCount) + ']';
|
---|
455 | FParentBlock.UpdateSize;
|
---|
456 | end;
|
---|
457 |
|
---|
458 | procedure TArray.SetCount(n: Integer);
|
---|
459 | var
|
---|
460 | fstream: TMemoryStream;
|
---|
461 | begin
|
---|
462 | FBlockCount := n;
|
---|
463 | if FCounterSize > 0 then
|
---|
464 | begin
|
---|
465 | fstream := TFile(FParentFile).FileStream;
|
---|
466 | fstream.Seek(Offset, soFromBeginning);
|
---|
467 | fstream.Write(FBlockCount, FCounterSize);
|
---|
468 | end;
|
---|
469 | SetCount;
|
---|
470 | end;
|
---|
471 |
|
---|
472 | procedure TArray.Update(Offset, Length: Integer);
|
---|
473 | var
|
---|
474 | i: Integer;
|
---|
475 | field: TDataField;
|
---|
476 | begin
|
---|
477 | if System.Length(FDataFields) > 0 then
|
---|
478 | begin
|
---|
479 | if Length > 0 then
|
---|
480 | begin
|
---|
481 | for i := 0 to High(FDataFields) do
|
---|
482 | begin
|
---|
483 | field := FDataFields[i];
|
---|
484 | if ((field.Offset < Offset) and (field.Offset + field.DataLength > Offset + Length)) or
|
---|
485 | ((field.Offset > Offset) and (field.Offset < Offset + Length)) or
|
---|
486 | ((field.Offset + field.DataLength > Offset) and (field.Offset+field.DataLength < Offset + Length)) then
|
---|
487 | field.Update(Offset, Length);
|
---|
488 | end;
|
---|
489 | end else begin
|
---|
490 | for i := 0 to High(FDataFields) do
|
---|
491 | FDataFields[i].Update(Offset, Length);
|
---|
492 | end;
|
---|
493 | end;
|
---|
494 | end;
|
---|
495 |
|
---|
496 | procedure TArray.UpdateSize;
|
---|
497 | var
|
---|
498 | i: Integer;
|
---|
499 | begin
|
---|
500 | FDataLength := FCounterSize;
|
---|
501 | if Length(FDataFields) > 0 then
|
---|
502 | for i := 0 to High(FDataFields) do
|
---|
503 | FDataLength := FDataLength + FDataFields[i].DataLength;
|
---|
504 | FParentBlock.UpdateSize;
|
---|
505 | end;
|
---|
506 |
|
---|
507 | procedure TArray.WriteData(stream: TStream);
|
---|
508 | var
|
---|
509 | i: Integer;
|
---|
510 | begin
|
---|
511 | if FCounterSize > 0 then
|
---|
512 | stream.Write(FBlockCount, FCounterSize);
|
---|
513 | if Length(FDataFields) > 0 then
|
---|
514 | for i := 0 to High(FDataFields) do
|
---|
515 | FDataFields[i].WriteData(stream);
|
---|
516 | end;
|
---|
517 |
|
---|
518 |
|
---|
519 |
|
---|
520 | { TBlock }
|
---|
521 |
|
---|
522 | function TBlock.AddField(fieldtype: TFieldType; Name,
|
---|
523 | Description: String; ExtraArgs: array of const): TDataField;
|
---|
524 | begin
|
---|
525 | SetLength(FDataFields, Length(FDataFields) + 1);
|
---|
526 | FDataFields[High(FDataFields)] := TFieldType(fieldtype).Create(
|
---|
527 | FParentFile, Self, Name, Description, ExtraArgs);
|
---|
528 | Result := FDataFields[High(FDataFields)];
|
---|
529 | FDataLength := FDataLength + Result.DataLength;
|
---|
530 | if Assigned(FParentBlock) then
|
---|
531 | FParentBlock.UpdateSize;
|
---|
532 | end;
|
---|
533 |
|
---|
534 | constructor TBlock.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
535 | Name, Description: String; ExtraArgs: array of const);
|
---|
536 | begin
|
---|
537 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
538 | FType := '';
|
---|
539 | end;
|
---|
540 |
|
---|
541 | function TBlock.GetChild(ID: Integer): TTreeElement;
|
---|
542 | begin
|
---|
543 | Result := FDataFields[ID];
|
---|
544 | end;
|
---|
545 |
|
---|
546 | function TBlock.GetChildCount: Integer;
|
---|
547 | begin
|
---|
548 | Result := Length(FDataFields);
|
---|
549 | end;
|
---|
550 |
|
---|
551 | function TBlock.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
552 | begin
|
---|
553 | Exit;
|
---|
554 | end;
|
---|
555 |
|
---|
556 | procedure TBlock.Update(Offset, Length: Integer);
|
---|
557 | var
|
---|
558 | i: Integer;
|
---|
559 | field: TDataField;
|
---|
560 | begin
|
---|
561 | if System.Length(FDataFields) > 0 then
|
---|
562 | begin
|
---|
563 | if Length > 0 then
|
---|
564 | begin
|
---|
565 | for i := 0 to High(FDataFields) do
|
---|
566 | begin
|
---|
567 | field := FDataFields[i];
|
---|
568 | if ((field.Offset < Offset) and (field.Offset + field.DataLength > Offset + Length)) or
|
---|
569 | ((field.Offset > Offset) and (field.Offset < Offset + Length)) or
|
---|
570 | ((field.Offset + field.DataLength > Offset) and (field.Offset+field.DataLength < Offset + Length)) then
|
---|
571 | field.Update(Offset, Length);
|
---|
572 | end;
|
---|
573 | end else begin
|
---|
574 | for i := 0 to High(FDataFields) do
|
---|
575 | begin
|
---|
576 | FDataFields[i].Update(Offset, Length);
|
---|
577 | end;
|
---|
578 | end;
|
---|
579 | end;
|
---|
580 | end;
|
---|
581 |
|
---|
582 | procedure TBlock.UpdateSize;
|
---|
583 | var
|
---|
584 | i: Integer;
|
---|
585 | begin
|
---|
586 | FDataLength := 0;
|
---|
587 | if Length(FDataFields) > 0 then
|
---|
588 | for i := 0 to High(FDataFields) do
|
---|
589 | FDataLength := FDataLength + FDataFields[i].FDataLength;
|
---|
590 | if Assigned(FParentBlock) then
|
---|
591 | FParentBlock.UpdateSize;
|
---|
592 | end;
|
---|
593 |
|
---|
594 | procedure TBlock.WriteData(stream: TStream);
|
---|
595 | var
|
---|
596 | i: Integer;
|
---|
597 | begin
|
---|
598 | if Length(FDataFields) > 0 then
|
---|
599 | for i := 0 to High(FDataFields) do
|
---|
600 | FDataFields[i].WriteData(stream);
|
---|
601 | end;
|
---|
602 |
|
---|
603 |
|
---|
604 | { TLevelID }
|
---|
605 |
|
---|
606 | constructor TLevelID.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
607 | Name, Description: String; ExtraArgs: array of const);
|
---|
608 | begin
|
---|
609 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
610 | FDataLength := 4;
|
---|
611 | FType := 'LevelID';
|
---|
612 | FLevelID := 0;
|
---|
613 | end;
|
---|
614 |
|
---|
615 | function TLevelID.GetValueAsString: String;
|
---|
616 | begin
|
---|
617 | Result := IntToStr(FLevelID);
|
---|
618 | end;
|
---|
619 |
|
---|
620 | procedure TLevelID.Update(Offset, Length: Integer);
|
---|
621 | var
|
---|
622 | fstream: TMemoryStream;
|
---|
623 | begin
|
---|
624 | fstream := TFile(FParentFile).FileStream;
|
---|
625 | fstream.Seek(FOffset, soFromBeginning);
|
---|
626 | fstream.Read(FLevelID, 4);
|
---|
627 | FLevelID := FLevelID div 256 div 256 div 256 div 2;
|
---|
628 | end;
|
---|
629 |
|
---|
630 | procedure TLevelID.WriteData(stream: TStream);
|
---|
631 | var
|
---|
632 | tempi: Integer;
|
---|
633 | begin
|
---|
634 | tempi := FLevelID * 256 * 256 * 256 * 2 + 1;
|
---|
635 | stream.Write(tempi, 4);
|
---|
636 | end;
|
---|
637 |
|
---|
638 |
|
---|
639 |
|
---|
640 | { TFileID }
|
---|
641 |
|
---|
642 | constructor TFileID.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
643 | Name, Description: String; ExtraArgs: array of const);
|
---|
644 | begin
|
---|
645 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
646 | FDataLength := 4;
|
---|
647 | FType := 'FileID';
|
---|
648 | FFileID := -1;
|
---|
649 | end;
|
---|
650 |
|
---|
651 | function TFileID.GetValueAsString: String;
|
---|
652 | begin
|
---|
653 | Result := IntToStr(FFileID);
|
---|
654 | end;
|
---|
655 |
|
---|
656 | procedure TFileID.Update(Offset, Length: Integer);
|
---|
657 | var
|
---|
658 | fstream: TMemoryStream;
|
---|
659 | begin
|
---|
660 | fstream := TFile(FParentFile).FileStream;
|
---|
661 | fstream.Seek(FOffset, soFromBeginning);
|
---|
662 | fstream.Read(FFileID, 4);
|
---|
663 | if FFileID > 0 then
|
---|
664 | FFileID := FFileID div 256
|
---|
665 | else
|
---|
666 | FFileID := -1;
|
---|
667 | end;
|
---|
668 |
|
---|
669 | procedure TFileID.WriteData(stream: TStream);
|
---|
670 | var
|
---|
671 | tempi: Integer;
|
---|
672 | begin
|
---|
673 | if FFileID >= 0 then
|
---|
674 | tempi := FFileID * 256 + 1
|
---|
675 | else
|
---|
676 | tempi := 0;
|
---|
677 | stream.Write(tempi, 4);
|
---|
678 | end;
|
---|
679 |
|
---|
680 |
|
---|
681 |
|
---|
682 | { TLinkByID }
|
---|
683 |
|
---|
684 | constructor TLinkByID.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
685 | Name, Description: String; ExtraArgs: array of const);
|
---|
686 | begin
|
---|
687 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
688 | FDataLength := 4;
|
---|
689 | case ExtraArgs[0].VType of
|
---|
690 | vtChar: FPosExts := ExtraArgs[0].VChar;
|
---|
691 | vtAnsiString: FPosExts := String(ExtraArgs[0].VAnsiString);
|
---|
692 | end;
|
---|
693 | FType := 'LinkByID(' + FPosExts + ')';
|
---|
694 | FFileID := -1;
|
---|
695 | end;
|
---|
696 |
|
---|
697 | function TLinkByID.GetChild(ID: Integer): TTreeElement;
|
---|
698 | begin
|
---|
699 | if FFileID > 0 then
|
---|
700 | Result := ConManager.Connection[FConnectionID].MetaData.FileById[FFileID].Child[ID]
|
---|
701 | else
|
---|
702 | Result := nil;
|
---|
703 | end;
|
---|
704 |
|
---|
705 | function TLinkByID.GetChildCount: Integer;
|
---|
706 | begin
|
---|
707 | if FFileID > 0 then
|
---|
708 | Result := ConManager.Connection[FConnectionID].MetaData.FileById[FFileID].ChildCount
|
---|
709 | else
|
---|
710 | Result := 0;
|
---|
711 | end;
|
---|
712 |
|
---|
713 | function TLinkByID.GetTarget: TObject;
|
---|
714 | begin
|
---|
715 | if FFileID > 0 then
|
---|
716 | Result := ConManager.Connection[FConnectionID].MetaData.FileById[FFileID]
|
---|
717 | else
|
---|
718 | Result := nil;
|
---|
719 | end;
|
---|
720 |
|
---|
721 | function TLinkByID.GetValueAsString: String;
|
---|
722 | begin
|
---|
723 | if FFileID >= 0 then
|
---|
724 | Result := IntToStr(FFileID)
|
---|
725 | else
|
---|
726 | Result := 'unused';
|
---|
727 | end;
|
---|
728 |
|
---|
729 | procedure TLinkByID.Update(Offset, Length: Integer);
|
---|
730 | var
|
---|
731 | fstream: TMemoryStream;
|
---|
732 | begin
|
---|
733 | fstream := TFile(FParentFile).FileStream;
|
---|
734 | fstream.Seek(FOffset, soFromBeginning);
|
---|
735 | fstream.Read(FFileID, 4);
|
---|
736 | if FFileID > 0 then
|
---|
737 | FFileID := FFileID div 256
|
---|
738 | else
|
---|
739 | FFileID := -1;
|
---|
740 | end;
|
---|
741 |
|
---|
742 | procedure TLinkByID.WriteData(stream: TStream);
|
---|
743 | var
|
---|
744 | tempi: Integer;
|
---|
745 | begin
|
---|
746 | if FFileID >= 0 then
|
---|
747 | tempi := FFileID * 256 + 1
|
---|
748 | else
|
---|
749 | tempi := 0;
|
---|
750 | stream.Write(tempi, 4);
|
---|
751 | end;
|
---|
752 |
|
---|
753 |
|
---|
754 |
|
---|
755 | { TRawLink }
|
---|
756 |
|
---|
757 | constructor TRawLink.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
758 | Name, Description: String; ExtraArgs: array of const);
|
---|
759 | begin
|
---|
760 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
761 | case ExtraArgs[0].VType of
|
---|
762 | vtChar: FRawType := ExtraArgs[0].VChar;
|
---|
763 | vtAnsiString: FRawType := String(ExtraArgs[0].VAnsiString);
|
---|
764 | end;
|
---|
765 | if Length(ExtraArgs) > 1 then
|
---|
766 | FSep := ExtraArgs[1].VBoolean;
|
---|
767 | FType := 'RawLink(' + FRawType + ')';
|
---|
768 | FDataLength := 4;
|
---|
769 | end;
|
---|
770 |
|
---|
771 | function TRawLink.GetValueAsString: String;
|
---|
772 | begin
|
---|
773 | if FRawAddress > 0 then
|
---|
774 | Result := '0x' + IntToHex(FRawAddress, 8)
|
---|
775 | else
|
---|
776 | Result := 'unused';
|
---|
777 | end;
|
---|
778 |
|
---|
779 | procedure TRawLink.Update(Offset, Length: Integer);
|
---|
780 | var
|
---|
781 | fstream: TMemoryStream;
|
---|
782 | begin
|
---|
783 | fstream := TFile(FParentFile).FileStream;
|
---|
784 | fstream.Seek(FOffset, soFromBeginning);
|
---|
785 | fstream.Read(FRawAddress, 4);
|
---|
786 | end;
|
---|
787 |
|
---|
788 | procedure TRawLink.WriteData(stream: TStream);
|
---|
789 | begin
|
---|
790 | stream.Write(FRawAddress, 4);
|
---|
791 | end;
|
---|
792 |
|
---|
793 |
|
---|
794 |
|
---|
795 | { TUnused }
|
---|
796 |
|
---|
797 | constructor TUnused.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
798 | Name, Description: String; ExtraArgs: array of const);
|
---|
799 | begin
|
---|
800 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
801 | FDataLength := ExtraArgs[0].VInteger;
|
---|
802 | FType := 'Unused';
|
---|
803 | end;
|
---|
804 |
|
---|
805 | function TUnused.GetValueAsString: String;
|
---|
806 | begin
|
---|
807 | Result := '';
|
---|
808 | end;
|
---|
809 |
|
---|
810 | procedure TUnused.Update(Offset, Length: Integer);
|
---|
811 | begin
|
---|
812 | Exit;
|
---|
813 | end;
|
---|
814 |
|
---|
815 | procedure TUnused.WriteData(stream: TStream);
|
---|
816 | var
|
---|
817 | i: Integer;
|
---|
818 | tempb: Byte;
|
---|
819 | begin
|
---|
820 | tempb := 0;
|
---|
821 | for i := 1 to FDataLength do
|
---|
822 | stream.Write(tempb, 1);
|
---|
823 | end;
|
---|
824 |
|
---|
825 |
|
---|
826 |
|
---|
827 | { TBitSet }
|
---|
828 |
|
---|
829 | constructor TBitSet.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
830 | Name, Description: String; ExtraArgs: array of const);
|
---|
831 | var
|
---|
832 | i: Integer;
|
---|
833 | begin
|
---|
834 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
835 | FNames := TStringList.Create;
|
---|
836 | for i := 0 to High(ExtraArgs) do
|
---|
837 | case ExtraArgs[i].VType of
|
---|
838 | vtChar: FNames.Add(ExtraArgs[0].VChar);
|
---|
839 | vtAnsiString: FNames.Add(String(ExtraArgs[0].VAnsiString));
|
---|
840 | end;
|
---|
841 | FDataLength := 1;
|
---|
842 | FType := 'BitSet';
|
---|
843 | FBits := 0;
|
---|
844 | end;
|
---|
845 |
|
---|
846 | function TBitSet.GetValueAsString: String;
|
---|
847 | function IntToBits(Int: Integer): String;
|
---|
848 | var
|
---|
849 | i: Integer;
|
---|
850 | begin
|
---|
851 | Result := '';
|
---|
852 | for i := 0 to 7 do
|
---|
853 | begin
|
---|
854 | Result := IntToStr(FBits and (1 shl i) shr i) + Result;
|
---|
855 | end;
|
---|
856 | end;
|
---|
857 | begin
|
---|
858 | Result := IntToBits(FBits);
|
---|
859 | end;
|
---|
860 |
|
---|
861 | procedure TBitSet.Update(Offset, Length: Integer);
|
---|
862 | var
|
---|
863 | fstream: TMemoryStream;
|
---|
864 | begin
|
---|
865 | fstream := TFile(FParentFile).FileStream;
|
---|
866 | fstream.Seek(FOffset, soFromBeginning);
|
---|
867 | fstream.Read(FBits, FDataLength);
|
---|
868 | end;
|
---|
869 |
|
---|
870 | procedure TBitSet.WriteData(stream: TStream);
|
---|
871 | begin
|
---|
872 | stream.Write(FBits, FDataLength);
|
---|
873 | end;
|
---|
874 |
|
---|
875 |
|
---|
876 |
|
---|
877 | { TFloat }
|
---|
878 |
|
---|
879 | constructor TFloat.Create(ParentFile: TObject; ParentBlock: TContainer; Name,
|
---|
880 | Description: String; ExtraArgs: array of const);
|
---|
881 | begin
|
---|
882 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
883 | FDataLength := 4;
|
---|
884 | FType := 'Float';
|
---|
885 | FFloat := 0;
|
---|
886 | end;
|
---|
887 |
|
---|
888 | function TFloat.GetValueAsString: String;
|
---|
889 | begin
|
---|
890 | Result := FloatToStr(FFloat);
|
---|
891 | end;
|
---|
892 |
|
---|
893 | procedure TFloat.Update(Offset, Length: Integer);
|
---|
894 | var
|
---|
895 | fstream: TMemoryStream;
|
---|
896 | begin
|
---|
897 | fstream := TFile(FParentFile).FileStream;
|
---|
898 | fstream.Seek(FOffset, soFromBeginning);
|
---|
899 | fstream.Read(FFloat, FDataLength);
|
---|
900 | end;
|
---|
901 |
|
---|
902 | procedure TFloat.WriteData(stream: TStream);
|
---|
903 | begin
|
---|
904 | stream.Write(FFloat, 4);
|
---|
905 | end;
|
---|
906 |
|
---|
907 |
|
---|
908 | end.
|
---|