[124] | 1 | unit _DataTypes;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
[207] | 5 | uses
|
---|
[233] | 6 | Classes, _TreeElement;
|
---|
[207] | 7 |
|
---|
[124] | 8 | type
|
---|
[236] | 9 | TContainer = class;
|
---|
| 10 |
|
---|
[233] | 11 | TDataField = class(TTreeElement)
|
---|
[207] | 12 | protected
|
---|
[126] | 13 | FOffset: Integer;
|
---|
| 14 | FName: String;
|
---|
[241] | 15 | FType: String;
|
---|
[126] | 16 | FDescription: String;
|
---|
| 17 | FDataLength: Integer;
|
---|
[206] | 18 | FParentFile: TObject;
|
---|
[236] | 19 | FParentBlock: TContainer;
|
---|
[206] | 20 | FChanged: Boolean;
|
---|
[237] | 21 | FExtraArgs: array of TVarRec;
|
---|
[241] | 22 | function GetChildCount: Integer; override;
|
---|
| 23 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
| 24 | function GetCaption: String; override;
|
---|
| 25 | function GetType: String; override;
|
---|
[236] | 26 | function GetValueAsString: String; virtual;
|
---|
[126] | 27 | public
|
---|
[236] | 28 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 29 | Name, Description: String; ExtraArgs: array of const); virtual;
|
---|
[126] | 30 |
|
---|
[206] | 31 | procedure Update(Offset, Length: Integer); virtual; abstract;
|
---|
[240] | 32 | procedure WriteData(stream: TStream); virtual; abstract;
|
---|
[206] | 33 |
|
---|
[126] | 34 | property Offset: Integer read FOffset;
|
---|
| 35 | property Name: String read FName;
|
---|
| 36 | property Description: String read FDescription;
|
---|
| 37 | property DataLength: Integer read FDataLength;
|
---|
[124] | 38 | property ValueAsString: String read GetValueAsString;
|
---|
| 39 | end;
|
---|
| 40 |
|
---|
[206] | 41 | TFieldType = class of TDataField;
|
---|
[124] | 42 |
|
---|
[236] | 43 | TContainer = class(TDataField)
|
---|
| 44 | public
|
---|
[237] | 45 | function AddField(fieldtype: TFieldType; Name, Description: String;
|
---|
| 46 | ExtraArgs: array of const): TDataField; virtual; abstract;
|
---|
[236] | 47 | procedure UpdateSize; virtual; abstract;
|
---|
| 48 | end;
|
---|
[207] | 49 |
|
---|
[236] | 50 | TBlock = class(TContainer)
|
---|
[241] | 51 | protected
|
---|
[206] | 52 | FDataFields: array of TDataField;
|
---|
[233] | 53 | function GetChildCount: Integer; override;
|
---|
| 54 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
[206] | 55 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
| 56 | public
|
---|
[236] | 57 | // ExtraArgs: Pointer auf Integer: BlockLength <- no longer
|
---|
| 58 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 59 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[206] | 60 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 61 | procedure WriteData(stream: TStream); override;
|
---|
[206] | 62 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
---|
[124] | 63 |
|
---|
[236] | 64 | function AddField(fieldtype: TFieldType; Name, Description: String;
|
---|
[237] | 65 | ExtraArgs: array of const): TDataField; override;
|
---|
[236] | 66 | procedure UpdateSize; override;
|
---|
[206] | 67 | end;
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | TInt = class(TDataField)
|
---|
[241] | 71 | protected
|
---|
[206] | 72 | FInt: Integer;
|
---|
[124] | 73 | function GetValueAsString: String; override;
|
---|
[126] | 74 | public
|
---|
[206] | 75 | // ExtraArgs: Pointer auf Integer: Bytes of TInt
|
---|
[236] | 76 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 77 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[206] | 78 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 79 | procedure WriteData(stream: TStream); override;
|
---|
[124] | 80 | end;
|
---|
| 81 |
|
---|
[126] | 82 |
|
---|
[237] | 83 | TFloat = class(TDataField)
|
---|
[241] | 84 | protected
|
---|
[237] | 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;
|
---|
[240] | 92 | procedure WriteData(stream: TStream); override;
|
---|
[237] | 93 | end;
|
---|
| 94 |
|
---|
| 95 |
|
---|
[207] | 96 | TBitSet = class(TDataField)
|
---|
[241] | 97 | protected
|
---|
[207] | 98 | FBits: Byte;
|
---|
| 99 | FNames: TStringList;
|
---|
| 100 | function GetValueAsString: String; override;
|
---|
| 101 | public
|
---|
| 102 | // ExtraArgs: Pointer auf TStringList
|
---|
[236] | 103 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 104 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[207] | 105 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 106 | procedure WriteData(stream: TStream); override;
|
---|
[207] | 107 | end;
|
---|
| 108 |
|
---|
| 109 |
|
---|
[206] | 110 | TLevelID = class(TDataField)
|
---|
[241] | 111 | protected
|
---|
[206] | 112 | FLevelID: Integer;
|
---|
| 113 | function GetValueAsString: String; override;
|
---|
| 114 | public
|
---|
| 115 | // ExtraArgs: keine
|
---|
[236] | 116 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 117 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[206] | 118 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 119 | procedure WriteData(stream: TStream); override;
|
---|
[206] | 120 | end;
|
---|
| 121 |
|
---|
| 122 |
|
---|
[248] | 123 | TResourceID = class(TDataField)
|
---|
[241] | 124 | protected
|
---|
[206] | 125 | FFileID: Integer;
|
---|
| 126 | function GetValueAsString: String; override;
|
---|
| 127 | public
|
---|
| 128 | // ExtraArgs: keine
|
---|
[236] | 129 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 130 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[206] | 131 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 132 | procedure WriteData(stream: TStream); override;
|
---|
[206] | 133 | end;
|
---|
| 134 |
|
---|
| 135 |
|
---|
[240] | 136 | TDatLink = class(TDataField)
|
---|
[241] | 137 | protected
|
---|
| 138 | FPosExts: String;
|
---|
[240] | 139 | function GetTarget: TObject; virtual; abstract;
|
---|
| 140 | public
|
---|
[241] | 141 | property PosExts: String read FPosExts;
|
---|
[240] | 142 | property TargetFile: TObject read GetTarget;
|
---|
| 143 | end;
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | TLinkByID = class(TDatLink)
|
---|
[241] | 147 | protected
|
---|
| 148 | FFileID: Integer;
|
---|
[233] | 149 | function GetChildCount: Integer; override;
|
---|
| 150 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
[206] | 151 | function GetValueAsString: String; override;
|
---|
[240] | 152 | function GetTarget: TObject; override;
|
---|
[206] | 153 | public
|
---|
| 154 | // ExtraArgs: Pointer auf String: Possible Exts
|
---|
[236] | 155 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 156 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[206] | 157 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 158 | procedure WriteData(stream: TStream); override;
|
---|
[206] | 159 | end;
|
---|
| 160 |
|
---|
| 161 |
|
---|
[126] | 162 | TString = class(TDataField)
|
---|
[241] | 163 | protected
|
---|
[124] | 164 | FString: String;
|
---|
| 165 | function GetValueAsString: String; override;
|
---|
[126] | 166 | public
|
---|
[206] | 167 | // ExtraArgs: Pointer auf Integer: Length
|
---|
[236] | 168 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 169 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[206] | 170 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 171 | procedure WriteData(stream: TStream); override;
|
---|
[124] | 172 | end;
|
---|
| 173 |
|
---|
[126] | 174 |
|
---|
[236] | 175 | TArray = class(TContainer)
|
---|
[241] | 176 | protected
|
---|
[233] | 177 | FDataFields: array of TBlock;
|
---|
[236] | 178 | FTemplate: TBlock;
|
---|
| 179 | FCounterSize: Integer;
|
---|
| 180 | FBlockCount: Integer;
|
---|
[233] | 181 | function GetChildCount: Integer; override;
|
---|
| 182 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
[126] | 183 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
| 184 | public
|
---|
[237] | 185 | // ExtraArgs:
|
---|
| 186 | // 1. Integer: CounterSize (if 0 then 2. integer is required)
|
---|
| 187 | // 2. Integer: BlockCount (for fixed-size arrays)
|
---|
[236] | 188 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 189 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[206] | 190 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 191 | procedure WriteData(stream: TStream); override;
|
---|
[206] | 192 |
|
---|
[236] | 193 | function AddField(fieldtype: TFieldType; Name, Description: String;
|
---|
[237] | 194 | ExtraArgs: array of const): TDataField; override;
|
---|
[236] | 195 | procedure SetCount; overload;
|
---|
| 196 | procedure SetCount(n: Integer); overload;
|
---|
| 197 | procedure UpdateSize; override;
|
---|
[126] | 198 | end;
|
---|
| 199 |
|
---|
[206] | 200 |
|
---|
| 201 | TRawLink = class(TDataField)
|
---|
[241] | 202 | protected
|
---|
[206] | 203 | FRawAddress: Integer;
|
---|
[241] | 204 | FRawType: String;
|
---|
| 205 | FSep: Boolean;
|
---|
[206] | 206 | function GetValueAsString: String; override;
|
---|
| 207 | public
|
---|
[241] | 208 | // ExtraArgs: String: RawType; Bool: Sep
|
---|
[236] | 209 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 210 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[206] | 211 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 212 | procedure WriteData(stream: TStream); override;
|
---|
[241] | 213 |
|
---|
| 214 | property RawType: String read FRawType;
|
---|
[206] | 215 | end;
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | TUnused = class(TDataField)
|
---|
[241] | 219 | protected
|
---|
[206] | 220 | function GetValueAsString: String; override;
|
---|
| 221 | public
|
---|
| 222 | // ExtraArgs: Pointer auf Integer: Length
|
---|
[236] | 223 | constructor Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 224 | Name, Description: String; ExtraArgs: array of const); override;
|
---|
[206] | 225 | procedure Update(Offset, Length: Integer); override;
|
---|
[240] | 226 | procedure WriteData(stream: TStream); override;
|
---|
[206] | 227 | end;
|
---|
| 228 |
|
---|
| 229 |
|
---|
[207] | 230 |
|
---|
| 231 |
|
---|
[124] | 232 | implementation
|
---|
| 233 |
|
---|
| 234 | uses
|
---|
[237] | 235 | SysUtils, Dialogs, _FileTypes, ConnectionManager, StrUtils;
|
---|
[124] | 236 |
|
---|
[126] | 237 |
|
---|
[207] | 238 |
|
---|
| 239 |
|
---|
[126] | 240 | { TDataType }
|
---|
| 241 |
|
---|
[236] | 242 | constructor TDataField.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 243 | Name, Description: String; ExtraArgs: array of const);
|
---|
[237] | 244 | var
|
---|
| 245 | i: Integer;
|
---|
[126] | 246 | begin
|
---|
[236] | 247 | if Assigned(ParentBlock) then
|
---|
| 248 | FOffset := ParentBlock.Offset + ParentBlock.DataLength
|
---|
| 249 | else
|
---|
| 250 | FOffset := 0;
|
---|
[126] | 251 | FName := Name;
|
---|
[206] | 252 | FDescription := Description;
|
---|
[212] | 253 | FParentFile := ParentFile;
|
---|
[236] | 254 | FParentBlock := ParentBlock;
|
---|
[237] | 255 | SetLength(FExtraArgs, Length(ExtraArgs));
|
---|
| 256 | if Length(ExtraArgs) > 0 then
|
---|
| 257 | for i := 0 to High(ExtraArgs) do
|
---|
| 258 | FExtraArgs[i] := ExtraArgs[i];
|
---|
[248] | 259 | FConnectionID := TResource(ParentFile).ConnectionID;
|
---|
[126] | 260 | end;
|
---|
| 261 |
|
---|
[233] | 262 | function TDataField.GetCaption: String;
|
---|
| 263 | begin
|
---|
| 264 | Result := FName;
|
---|
| 265 | end;
|
---|
[126] | 266 |
|
---|
[233] | 267 | function TDataField.GetChild(ID: Integer): TTreeElement;
|
---|
| 268 | begin
|
---|
| 269 | Result := nil;
|
---|
| 270 | end;
|
---|
[126] | 271 |
|
---|
[233] | 272 | function TDataField.GetChildCount: Integer;
|
---|
| 273 | begin
|
---|
| 274 | Result := 0;
|
---|
| 275 | end;
|
---|
| 276 |
|
---|
[241] | 277 | function TDataField.GetType: String;
|
---|
| 278 | begin
|
---|
| 279 | Result := FType;
|
---|
| 280 | end;
|
---|
| 281 |
|
---|
[236] | 282 | function TDataField.GetValueAsString: String;
|
---|
| 283 | begin
|
---|
| 284 | Result := '';
|
---|
| 285 | end;
|
---|
[233] | 286 |
|
---|
[207] | 287 | { TString }
|
---|
[124] | 288 |
|
---|
[236] | 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;
|
---|
[241] | 294 | FType := 'String[' + IntToStr(FDataLength) + ']';
|
---|
[236] | 295 | end;
|
---|
| 296 |
|
---|
| 297 | function TString.GetValueAsString: String;
|
---|
| 298 | begin
|
---|
| 299 | Result := FString;
|
---|
| 300 | end;
|
---|
| 301 |
|
---|
| 302 | procedure TString.Update(Offset, Length: Integer);
|
---|
[206] | 303 | var
|
---|
| 304 | fstream: TMemoryStream;
|
---|
[207] | 305 | i: Integer;
|
---|
[124] | 306 | begin
|
---|
[248] | 307 | fstream := TResource(FParentFile).FileStream;
|
---|
[236] | 308 | fstream.Seek(FOffset, soFromBeginning);
|
---|
[207] | 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;
|
---|
[124] | 317 | end;
|
---|
| 318 |
|
---|
[240] | 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;
|
---|
[124] | 330 |
|
---|
[126] | 331 |
|
---|
[240] | 332 |
|
---|
[207] | 333 | { TInt }
|
---|
[124] | 334 |
|
---|
[236] | 335 | constructor TInt.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 336 | Name, Description: String; ExtraArgs: array of const);
|
---|
[124] | 337 | begin
|
---|
[236] | 338 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
| 339 | FDataLength := ExtraArgs[0].VInteger;
|
---|
[241] | 340 | FType := 'Int' + IntToStr(FDataLength * 8);
|
---|
[207] | 341 | FInt := 0;
|
---|
[124] | 342 | end;
|
---|
| 343 |
|
---|
[207] | 344 | function TInt.GetValueAsString: String;
|
---|
[124] | 345 | begin
|
---|
[207] | 346 | Result := IntToStr(FInt);
|
---|
[124] | 347 | end;
|
---|
| 348 |
|
---|
[207] | 349 | procedure TInt.Update(Offset, Length: Integer);
|
---|
[236] | 350 | var
|
---|
| 351 | fstream: TMemoryStream;
|
---|
[206] | 352 | begin
|
---|
[248] | 353 | fstream := TResource(FParentFile).FileStream;
|
---|
[236] | 354 | fstream.Seek(FOffset, soFromBeginning);
|
---|
| 355 | fstream.Read(FInt, FDataLength);
|
---|
[206] | 356 | end;
|
---|
[126] | 357 |
|
---|
[240] | 358 | procedure TInt.WriteData(stream: TStream);
|
---|
| 359 | begin
|
---|
| 360 | stream.Write(FInt, FDataLength);
|
---|
| 361 | end;
|
---|
[126] | 362 |
|
---|
[206] | 363 |
|
---|
[240] | 364 |
|
---|
[126] | 365 | { TArray }
|
---|
| 366 |
|
---|
[236] | 367 | function TArray.AddField(fieldtype: TFieldType;
|
---|
| 368 | Name, Description: String; ExtraArgs: array of const): TDataField;
|
---|
[234] | 369 | var
|
---|
| 370 | i: Integer;
|
---|
[126] | 371 | begin
|
---|
[236] | 372 | Result := FTemplate.AddField(fieldtype, Name, Description, ExtraArgs);
|
---|
[126] | 373 | end;
|
---|
| 374 |
|
---|
[236] | 375 | constructor TArray.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 376 | Name, Description: String; ExtraArgs: array of const);
|
---|
[126] | 377 | begin
|
---|
[236] | 378 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
| 379 | FCounterSize := ExtraArgs[0].VInteger;
|
---|
[241] | 380 | FType := '';
|
---|
[237] | 381 | if Length(ExtraArgs) = 2 then
|
---|
| 382 | FBlockCount := ExtraArgs[1].VInteger
|
---|
| 383 | else
|
---|
[236] | 384 | FBlockCount := 0;
|
---|
| 385 | FTemplate := TBlock.Create(ParentFile, Self, '', '', []);
|
---|
[126] | 386 | end;
|
---|
| 387 |
|
---|
[233] | 388 | function TArray.GetChildCount: Integer;
|
---|
[206] | 389 | begin
|
---|
| 390 | Result := Length(FDataFields);
|
---|
| 391 | end;
|
---|
[126] | 392 |
|
---|
[233] | 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 |
|
---|
[236] | 403 | procedure TArray.SetCount;
|
---|
| 404 | var
|
---|
[237] | 405 | fstream: TMemoryStream;
|
---|
[236] | 406 | arr_index: Integer;
|
---|
[237] | 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 |
|
---|
[206] | 427 | begin
|
---|
[237] | 428 | if FCounterSize > 0 then
|
---|
| 429 | begin
|
---|
[248] | 430 | fstream := TResource(FParentFile).FileStream;
|
---|
[237] | 431 | fstream.Seek(Offset, soFromBeginning);
|
---|
| 432 | FBlockCount := 0;
|
---|
| 433 | fstream.Read(FBlockCount, FCounterSize);
|
---|
| 434 | end;
|
---|
[236] | 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,
|
---|
[237] | 442 | '[' + IntToStr(arr_index) + ']', '', []);
|
---|
| 443 | Add(FDataFields[arr_index], FTemplate);
|
---|
[236] | 444 | end;
|
---|
| 445 | end;
|
---|
[237] | 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;
|
---|
[236] | 454 | FName := FName + '[' + IntToStr(FBlockCount) + ']';
|
---|
| 455 | FParentBlock.UpdateSize;
|
---|
[206] | 456 | end;
|
---|
| 457 |
|
---|
[236] | 458 | procedure TArray.SetCount(n: Integer);
|
---|
[237] | 459 | var
|
---|
| 460 | fstream: TMemoryStream;
|
---|
[236] | 461 | begin
|
---|
[237] | 462 | FBlockCount := n;
|
---|
| 463 | if FCounterSize > 0 then
|
---|
| 464 | begin
|
---|
[248] | 465 | fstream := TResource(FParentFile).FileStream;
|
---|
[237] | 466 | fstream.Seek(Offset, soFromBeginning);
|
---|
| 467 | fstream.Write(FBlockCount, FCounterSize);
|
---|
| 468 | end;
|
---|
| 469 | SetCount;
|
---|
[236] | 470 | end;
|
---|
[206] | 471 |
|
---|
[236] | 472 | procedure TArray.Update(Offset, Length: Integer);
|
---|
[206] | 473 | var
|
---|
| 474 | i: Integer;
|
---|
[236] | 475 | field: TDataField;
|
---|
[206] | 476 | begin
|
---|
[236] | 477 | if System.Length(FDataFields) > 0 then
|
---|
[206] | 478 | begin
|
---|
[236] | 479 | if Length > 0 then
|
---|
[206] | 480 | begin
|
---|
[236] | 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);
|
---|
[206] | 492 | end;
|
---|
| 493 | end;
|
---|
[236] | 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 |
|
---|
[240] | 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;
|
---|
[236] | 517 |
|
---|
| 518 |
|
---|
[240] | 519 |
|
---|
[236] | 520 | { TBlock }
|
---|
| 521 |
|
---|
| 522 | function TBlock.AddField(fieldtype: TFieldType; Name,
|
---|
| 523 | Description: String; ExtraArgs: array of const): TDataField;
|
---|
| 524 | begin
|
---|
[206] | 525 | SetLength(FDataFields, Length(FDataFields) + 1);
|
---|
| 526 | FDataFields[High(FDataFields)] := TFieldType(fieldtype).Create(
|
---|
[236] | 527 | FParentFile, Self, Name, Description, ExtraArgs);
|
---|
[212] | 528 | Result := FDataFields[High(FDataFields)];
|
---|
[236] | 529 | FDataLength := FDataLength + Result.DataLength;
|
---|
| 530 | if Assigned(FParentBlock) then
|
---|
| 531 | FParentBlock.UpdateSize;
|
---|
[206] | 532 | end;
|
---|
| 533 |
|
---|
[236] | 534 | constructor TBlock.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 535 | Name, Description: String; ExtraArgs: array of const);
|
---|
[206] | 536 | begin
|
---|
[236] | 537 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
[241] | 538 | FType := '';
|
---|
[206] | 539 | end;
|
---|
| 540 |
|
---|
[233] | 541 | function TBlock.GetChild(ID: Integer): TTreeElement;
|
---|
[206] | 542 | begin
|
---|
| 543 | Result := FDataFields[ID];
|
---|
| 544 | end;
|
---|
| 545 |
|
---|
[233] | 546 | function TBlock.GetChildCount: Integer;
|
---|
[206] | 547 | begin
|
---|
[233] | 548 | Result := Length(FDataFields);
|
---|
[206] | 549 | end;
|
---|
| 550 |
|
---|
[233] | 551 | function TBlock.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
[206] | 552 | begin
|
---|
[233] | 553 | Exit;
|
---|
[206] | 554 | end;
|
---|
| 555 |
|
---|
| 556 | procedure TBlock.Update(Offset, Length: Integer);
|
---|
[236] | 557 | var
|
---|
| 558 | i: Integer;
|
---|
| 559 | field: TDataField;
|
---|
[206] | 560 | begin
|
---|
[236] | 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;
|
---|
[206] | 580 | end;
|
---|
| 581 |
|
---|
[236] | 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;
|
---|
[206] | 593 |
|
---|
[240] | 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;
|
---|
[206] | 602 |
|
---|
[236] | 603 |
|
---|
[206] | 604 | { TLevelID }
|
---|
| 605 |
|
---|
[236] | 606 | constructor TLevelID.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 607 | Name, Description: String; ExtraArgs: array of const);
|
---|
[206] | 608 | begin
|
---|
[236] | 609 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
[206] | 610 | FDataLength := 4;
|
---|
[241] | 611 | FType := 'LevelID';
|
---|
[236] | 612 | FLevelID := 0;
|
---|
[206] | 613 | end;
|
---|
| 614 |
|
---|
| 615 | function TLevelID.GetValueAsString: String;
|
---|
| 616 | begin
|
---|
| 617 | Result := IntToStr(FLevelID);
|
---|
| 618 | end;
|
---|
| 619 |
|
---|
| 620 | procedure TLevelID.Update(Offset, Length: Integer);
|
---|
[236] | 621 | var
|
---|
| 622 | fstream: TMemoryStream;
|
---|
[206] | 623 | begin
|
---|
[248] | 624 | fstream := TResource(FParentFile).FileStream;
|
---|
[236] | 625 | fstream.Seek(FOffset, soFromBeginning);
|
---|
| 626 | fstream.Read(FLevelID, 4);
|
---|
| 627 | FLevelID := FLevelID div 256 div 256 div 256 div 2;
|
---|
[206] | 628 | end;
|
---|
| 629 |
|
---|
[240] | 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;
|
---|
[206] | 637 |
|
---|
| 638 |
|
---|
[240] | 639 |
|
---|
[206] | 640 | { TFileID }
|
---|
| 641 |
|
---|
[248] | 642 | constructor TResourceID.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
[236] | 643 | Name, Description: String; ExtraArgs: array of const);
|
---|
[206] | 644 | begin
|
---|
[236] | 645 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
[206] | 646 | FDataLength := 4;
|
---|
[241] | 647 | FType := 'FileID';
|
---|
[236] | 648 | FFileID := -1;
|
---|
[206] | 649 | end;
|
---|
| 650 |
|
---|
[248] | 651 | function TResourceID.GetValueAsString: String;
|
---|
[206] | 652 | begin
|
---|
| 653 | Result := IntToStr(FFileID);
|
---|
| 654 | end;
|
---|
| 655 |
|
---|
[248] | 656 | procedure TResourceID.Update(Offset, Length: Integer);
|
---|
[236] | 657 | var
|
---|
| 658 | fstream: TMemoryStream;
|
---|
[206] | 659 | begin
|
---|
[248] | 660 | fstream := TResource(FParentFile).FileStream;
|
---|
[236] | 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;
|
---|
[206] | 667 | end;
|
---|
| 668 |
|
---|
[248] | 669 | procedure TResourceID.WriteData(stream: TStream);
|
---|
[240] | 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;
|
---|
[206] | 679 |
|
---|
| 680 |
|
---|
[240] | 681 |
|
---|
[206] | 682 | { TLinkByID }
|
---|
| 683 |
|
---|
[236] | 684 | constructor TLinkByID.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 685 | Name, Description: String; ExtraArgs: array of const);
|
---|
[206] | 686 | begin
|
---|
[236] | 687 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
[206] | 688 | FDataLength := 4;
|
---|
[236] | 689 | case ExtraArgs[0].VType of
|
---|
| 690 | vtChar: FPosExts := ExtraArgs[0].VChar;
|
---|
| 691 | vtAnsiString: FPosExts := String(ExtraArgs[0].VAnsiString);
|
---|
| 692 | end;
|
---|
[241] | 693 | FType := 'LinkByID(' + FPosExts + ')';
|
---|
[236] | 694 | FFileID := -1;
|
---|
[206] | 695 | end;
|
---|
| 696 |
|
---|
[233] | 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 |
|
---|
[240] | 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 |
|
---|
[206] | 721 | function TLinkByID.GetValueAsString: String;
|
---|
| 722 | begin
|
---|
[236] | 723 | if FFileID >= 0 then
|
---|
| 724 | Result := IntToStr(FFileID)
|
---|
| 725 | else
|
---|
| 726 | Result := 'unused';
|
---|
[206] | 727 | end;
|
---|
| 728 |
|
---|
| 729 | procedure TLinkByID.Update(Offset, Length: Integer);
|
---|
[236] | 730 | var
|
---|
| 731 | fstream: TMemoryStream;
|
---|
[206] | 732 | begin
|
---|
[248] | 733 | fstream := TResource(FParentFile).FileStream;
|
---|
[236] | 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;
|
---|
[206] | 740 | end;
|
---|
| 741 |
|
---|
[240] | 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;
|
---|
[206] | 752 |
|
---|
| 753 |
|
---|
[240] | 754 |
|
---|
[206] | 755 | { TRawLink }
|
---|
| 756 |
|
---|
[236] | 757 | constructor TRawLink.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 758 | Name, Description: String; ExtraArgs: array of const);
|
---|
[206] | 759 | begin
|
---|
[236] | 760 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
[241] | 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 + ')';
|
---|
[206] | 768 | FDataLength := 4;
|
---|
| 769 | end;
|
---|
| 770 |
|
---|
| 771 | function TRawLink.GetValueAsString: String;
|
---|
| 772 | begin
|
---|
[236] | 773 | if FRawAddress > 0 then
|
---|
| 774 | Result := '0x' + IntToHex(FRawAddress, 8)
|
---|
| 775 | else
|
---|
| 776 | Result := 'unused';
|
---|
[206] | 777 | end;
|
---|
| 778 |
|
---|
| 779 | procedure TRawLink.Update(Offset, Length: Integer);
|
---|
[236] | 780 | var
|
---|
| 781 | fstream: TMemoryStream;
|
---|
[206] | 782 | begin
|
---|
[248] | 783 | fstream := TResource(FParentFile).FileStream;
|
---|
[236] | 784 | fstream.Seek(FOffset, soFromBeginning);
|
---|
| 785 | fstream.Read(FRawAddress, 4);
|
---|
[206] | 786 | end;
|
---|
| 787 |
|
---|
[240] | 788 | procedure TRawLink.WriteData(stream: TStream);
|
---|
| 789 | begin
|
---|
| 790 | stream.Write(FRawAddress, 4);
|
---|
| 791 | end;
|
---|
[206] | 792 |
|
---|
| 793 |
|
---|
[240] | 794 |
|
---|
[206] | 795 | { TUnused }
|
---|
| 796 |
|
---|
[236] | 797 | constructor TUnused.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 798 | Name, Description: String; ExtraArgs: array of const);
|
---|
[206] | 799 | begin
|
---|
[236] | 800 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
| 801 | FDataLength := ExtraArgs[0].VInteger;
|
---|
[241] | 802 | FType := 'Unused';
|
---|
[206] | 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 |
|
---|
[240] | 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;
|
---|
[207] | 824 |
|
---|
| 825 |
|
---|
[240] | 826 |
|
---|
[207] | 827 | { TBitSet }
|
---|
| 828 |
|
---|
[236] | 829 | constructor TBitSet.Create(ParentFile: TObject; ParentBlock: TContainer;
|
---|
| 830 | Name, Description: String; ExtraArgs: array of const);
|
---|
[207] | 831 | var
|
---|
[236] | 832 | i: Integer;
|
---|
[207] | 833 | begin
|
---|
[236] | 834 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
[207] | 835 | FNames := TStringList.Create;
|
---|
[236] | 836 | for i := 0 to High(ExtraArgs) do
|
---|
[243] | 837 | begin
|
---|
[236] | 838 | case ExtraArgs[i].VType of
|
---|
[243] | 839 | vtChar: FNames.Add(ExtraArgs[i].VChar);
|
---|
| 840 | vtAnsiString: FNames.Add(String(ExtraArgs[i].VAnsiString));
|
---|
[236] | 841 | end;
|
---|
[243] | 842 | if Length(FDescription) > 0 then
|
---|
| 843 | FDescription := FDescription + #13#10;
|
---|
| 844 | FDescription := FDescription + '$' + IntToHex(1 shl i,2) + ': ' + FNames.Strings[FNames.Count - 1];
|
---|
| 845 | end;
|
---|
[207] | 846 | FDataLength := 1;
|
---|
[241] | 847 | FType := 'BitSet';
|
---|
[207] | 848 | FBits := 0;
|
---|
| 849 | end;
|
---|
| 850 |
|
---|
| 851 | function TBitSet.GetValueAsString: String;
|
---|
[236] | 852 | function IntToBits(Int: Integer): String;
|
---|
| 853 | var
|
---|
| 854 | i: Integer;
|
---|
| 855 | begin
|
---|
| 856 | Result := '';
|
---|
| 857 | for i := 0 to 7 do
|
---|
| 858 | begin
|
---|
| 859 | Result := IntToStr(FBits and (1 shl i) shr i) + Result;
|
---|
| 860 | end;
|
---|
| 861 | end;
|
---|
[207] | 862 | begin
|
---|
[236] | 863 | Result := IntToBits(FBits);
|
---|
[207] | 864 | end;
|
---|
| 865 |
|
---|
| 866 | procedure TBitSet.Update(Offset, Length: Integer);
|
---|
[236] | 867 | var
|
---|
| 868 | fstream: TMemoryStream;
|
---|
[207] | 869 | begin
|
---|
[248] | 870 | fstream := TResource(FParentFile).FileStream;
|
---|
[236] | 871 | fstream.Seek(FOffset, soFromBeginning);
|
---|
| 872 | fstream.Read(FBits, FDataLength);
|
---|
[207] | 873 | end;
|
---|
| 874 |
|
---|
[240] | 875 | procedure TBitSet.WriteData(stream: TStream);
|
---|
| 876 | begin
|
---|
| 877 | stream.Write(FBits, FDataLength);
|
---|
| 878 | end;
|
---|
[237] | 879 |
|
---|
| 880 |
|
---|
[240] | 881 |
|
---|
[237] | 882 | { TFloat }
|
---|
| 883 |
|
---|
| 884 | constructor TFloat.Create(ParentFile: TObject; ParentBlock: TContainer; Name,
|
---|
| 885 | Description: String; ExtraArgs: array of const);
|
---|
| 886 | begin
|
---|
| 887 | inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
|
---|
| 888 | FDataLength := 4;
|
---|
[241] | 889 | FType := 'Float';
|
---|
[237] | 890 | FFloat := 0;
|
---|
| 891 | end;
|
---|
| 892 |
|
---|
| 893 | function TFloat.GetValueAsString: String;
|
---|
| 894 | begin
|
---|
| 895 | Result := FloatToStr(FFloat);
|
---|
| 896 | end;
|
---|
| 897 |
|
---|
| 898 | procedure TFloat.Update(Offset, Length: Integer);
|
---|
| 899 | var
|
---|
| 900 | fstream: TMemoryStream;
|
---|
| 901 | begin
|
---|
[248] | 902 | fstream := TResource(FParentFile).FileStream;
|
---|
[237] | 903 | fstream.Seek(FOffset, soFromBeginning);
|
---|
| 904 | fstream.Read(FFloat, FDataLength);
|
---|
| 905 | end;
|
---|
| 906 |
|
---|
[240] | 907 | procedure TFloat.WriteData(stream: TStream);
|
---|
| 908 | begin
|
---|
| 909 | stream.Write(FFloat, 4);
|
---|
| 910 | end;
|
---|
[237] | 911 |
|
---|
[240] | 912 |
|
---|
[124] | 913 | end.
|
---|