Changeset 206 for oup/current/FileClasses
- Timestamp:
- May 28, 2007, 1:31:26 AM (18 years ago)
- Location:
- oup/current/FileClasses
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/FileClasses/_DataTypes.pas
r126 r206 10 10 FDescription: String; 11 11 FDataLength: Integer; 12 FParentFile: TObject; 13 FChanged: Boolean; 12 14 function GetValueAsString: String; virtual; abstract; 13 15 public 14 constructor Create(Offset: Integer; Name, Description: String); 16 constructor Create(ParentFile: TObject; Offset: Integer; 17 Name, Description: String; ExtraArgs: Pointer); virtual; 18 19 procedure Update(Offset, Length: Integer); virtual; abstract; 15 20 16 21 property Offset: Integer read FOffset; … … 21 26 end; 22 27 23 TDataFields = array of TDataField; 24 25 26 TInt32 = class(TDataField) 27 private 28 FInt: LongWord; 29 function GetValueAsString: String; override; 30 public 31 constructor Create(Offset: Integer; Name, Description: String); 32 end; 33 34 35 TString = class(TDataField) 36 private 37 FString: String; 38 function GetValueAsString: String; override; 39 public 40 constructor Create(Offset: Integer; Name, Description: String; Length: Integer); 41 end; 42 43 44 45 TArray = class(TDataField) 46 private 47 FDataFields: TDataFields; 28 TFieldType = class of TDataField; 29 30 TBlock = class(TDataField) 31 private 32 FDataFields: array of TDataField; 48 33 function GetFieldByOffset(Offset: Integer): TDataField; 49 34 function GetFieldByIndex(ID: Integer): TDataField; 50 public 51 constructor Create(Offset: Integer; Name, Description: String; Length, Count: Integer); 35 function GetFieldCount: Integer; 36 public 37 // ExtraArgs: Pointer auf 2 Integer: Length+Count 38 constructor Create(ParentFile: TObject; Offset: Integer; 39 Name, Description: String; ExtraArgs: Pointer); override; 40 procedure Update(Offset, Length: Integer); override; 52 41 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset; 53 42 property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex; 54 end; 43 property FieldCount: Integer read GetFieldCount; 44 45 procedure AddField(fieldtype: TFieldType; Offset: Integer; 46 Name, Description: String; ExtraArgs: Pointer); 47 end; 48 49 50 TInt = class(TDataField) 51 private 52 FInt: Integer; 53 function GetValueAsString: String; override; 54 public 55 // ExtraArgs: Pointer auf Integer: Bytes of TInt 56 constructor Create(ParentFile: TObject; Offset: Integer; 57 Name, Description: String; ExtraArgs: Pointer); override; 58 procedure Update(Offset, Length: Integer); override; 59 end; 60 61 62 TLevelID = class(TDataField) 63 private 64 FLevelID: Integer; 65 function GetValueAsString: String; override; 66 public 67 // ExtraArgs: keine 68 constructor Create(ParentFile: TObject; Offset: Integer; 69 Name, Description: String; ExtraArgs: Pointer); override; 70 procedure Update(Offset, Length: Integer); override; 71 end; 72 73 74 TFileID = class(TDataField) 75 private 76 FFileID: Integer; 77 function GetValueAsString: String; override; 78 public 79 // ExtraArgs: keine 80 constructor Create(ParentFile: TObject; Offset: Integer; 81 Name, Description: String; ExtraArgs: Pointer); override; 82 procedure Update(Offset, Length: Integer); override; 83 end; 84 85 86 TLinkByID = class(TDataField) 87 private 88 FFileID: Integer; 89 FPosExts: String; 90 function GetValueAsString: String; override; 91 public 92 // ExtraArgs: Pointer auf String: Possible Exts 93 constructor Create(ParentFile: TObject; Offset: Integer; 94 Name, Description: String; ExtraArgs: Pointer); override; 95 procedure Update(Offset, Length: Integer); override; 96 end; 97 98 99 TString = class(TDataField) 100 private 101 FString: String; 102 function GetValueAsString: String; override; 103 public 104 // ExtraArgs: Pointer auf Integer: Length 105 constructor Create(ParentFile: TObject; Offset: Integer; 106 Name, Description: String; ExtraArgs: Pointer); override; 107 procedure Update(Offset, Length: Integer); override; 108 end; 109 110 111 TArray = class(TDataField) 112 private 113 FDataFields: array of TDataField; 114 function GetFieldByOffset(Offset: Integer): TDataField; 115 function GetFieldByIndex(ID: Integer): TDataField; 116 function GetFieldCount: Integer; 117 public 118 // ExtraArgs: Pointer auf 2 Integer: Length+Count 119 constructor Create(ParentFile: TObject; Offset: Integer; 120 Name, Description: String; ExtraArgs: Pointer); override; 121 procedure Update(Offset, Length: Integer); override; 122 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset; 123 property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex; 124 property FieldCount: Integer read GetFieldCount; 125 126 procedure AddField(fieldtype: TFieldType; Offset: Integer; 127 Name, Description: String; ExtraArgs: Pointer); 128 end; 129 130 131 TRawLink = class(TDataField) 132 private 133 FRawAddress: Integer; 134 function GetValueAsString: String; override; 135 public 136 // ExtraArgs: keine 137 constructor Create(ParentFile: TObject; Offset: Integer; 138 Name, Description: String; ExtraArgs: Pointer); override; 139 procedure Update(Offset, Length: Integer); override; 140 end; 141 142 143 TUnused = class(TDataField) 144 private 145 function GetValueAsString: String; override; 146 public 147 // ExtraArgs: Pointer auf Integer: Length 148 constructor Create(ParentFile: TObject; Offset: Integer; 149 Name, Description: String; ExtraArgs: Pointer); override; 150 procedure Update(Offset, Length: Integer); override; 151 end; 152 55 153 56 154 implementation 57 155 58 156 uses 59 SysUtils ;157 SysUtils, Dialogs, _FileTypes, Classes, ConnectionManager; 60 158 61 159 62 160 { TDataType } 63 161 64 constructor TDataField.Create(Offset: Integer; Name, Description: String); 162 constructor TDataField.Create(ParentFile: TObject; Offset: Integer; 163 Name, Description: String; ExtraArgs: Pointer); 65 164 begin 66 165 FOffset := Offset; 67 166 FName := Name; 68 FDescription := Description; 167 FDescription := Description; 168 FParentFile := ParentFile; 69 169 end; 70 170 … … 73 173 { TInt32 } 74 174 75 constructor TInt32.Create(Offset: Integer; Name, Description: String); 76 begin 77 inherited Create(Offset, Name, Description); 78 end; 79 80 function TInt32.GetValueAsString: String; 175 constructor TInt.Create(ParentFile: TObject; Offset: Integer; 176 Name, Description: String; ExtraArgs: Pointer); 177 var 178 fstream: TMemoryStream; 179 begin 180 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs); 181 FDataLength := Integer(ExtraArgs^); 182 FInt := 0; 183 fstream := TFile(ParentFile).FileStream; 184 fstream.Seek(Offset, soFromBeginning); 185 fstream.Read(FInt, FDataLength); 186 end; 187 188 function TInt.GetValueAsString: String; 81 189 begin 82 190 Result := IntToStr(FInt); 83 191 end; 84 192 193 procedure TInt.Update(Offset, Length: Integer); 194 begin 195 Exit; 196 end; 197 85 198 86 199 87 200 { TString } 88 201 89 constructor TString.Create(Offset: Integer; Name, Description: String; 90 Length: Integer); 91 begin 92 inherited Create(Offset, Name, Description); 93 202 constructor TString.Create(ParentFile: TObject; Offset: Integer; 203 Name, Description: String; ExtraArgs: Pointer); 204 var 205 fstream: TMemoryStream; 206 i: Integer; 207 begin 208 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs); 209 FDataLength := Integer(ExtraArgs^); 210 fstream := TFile(ParentFile).FileStream; 211 fstream.Seek(Offset, soFromBeginning); 212 SetLength(FString, FDataLength); 213 fstream.Read(FString[1], FDataLength); 214 for i := 1 to FDataLength do 215 if FString[i] = Chr(0) then 216 begin 217 SetLength(FString, i - 1); 218 Break; 219 end; 94 220 end; 95 221 … … 99 225 end; 100 226 227 procedure TString.Update(Offset, Length: Integer); 228 begin 229 Exit; 230 end; 231 101 232 102 233 103 234 { TArray } 104 235 105 constructor TArray.Create(Offset: Integer; Name, Description: String; 106 Length, Count: Integer); 107 begin 108 Exit; 236 procedure TArray.AddField(fieldtype: TFieldType; Offset: Integer; 237 Name, Description: String; ExtraArgs: Pointer); 238 begin 239 Exit; 240 end; 241 242 constructor TArray.Create(ParentFile: TObject; Offset: Integer; 243 Name, Description: String; ExtraArgs: Pointer); 244 begin 245 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs); 109 246 end; 110 247 … … 133 270 end; 134 271 272 function TArray.GetFieldCount: Integer; 273 begin 274 Result := Length(FDataFields); 275 end; 276 277 procedure TArray.Update(Offset, Length: Integer); 278 begin 279 Exit; 280 end; 281 282 283 284 { TBlock } 285 286 procedure TBlock.AddField(fieldtype: TFieldType; Offset: Integer; Name, 287 Description: String; ExtraArgs: Pointer); 288 var 289 i: Integer; 290 begin 291 if Length(FDataFields) > 0 then 292 begin 293 for i := 0 to High(FDataFields) do 294 if FDataFields[i].FOffset = Offset then 295 Break; 296 if i < Length(FDataFields) then 297 begin 298 ShowMessage('Field exists'); 299 Exit; 300 end; 301 end; 302 SetLength(FDataFields, Length(FDataFields) + 1); 303 FDataFields[High(FDataFields)] := TFieldType(fieldtype).Create( 304 FParentFile, Offset, Name, Description, ExtraArgs); 305 end; 306 307 constructor TBlock.Create(ParentFile: TObject; Offset: Integer; 308 Name, Description: String; ExtraArgs: Pointer); 309 begin 310 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs); 311 end; 312 313 function TBlock.GetFieldByIndex(ID: Integer): TDataField; 314 begin 315 Result := FDataFields[ID]; 316 end; 317 318 function TBlock.GetFieldByOffset(Offset: Integer): TDataField; 319 begin 320 Exit; 321 end; 322 323 function TBlock.GetFieldCount: Integer; 324 begin 325 Result := Length(FDataFields); 326 end; 327 328 procedure TBlock.Update(Offset, Length: Integer); 329 begin 330 Exit; 331 end; 332 333 334 335 { TLevelID } 336 337 constructor TLevelID.Create(ParentFile: TObject; Offset: Integer; 338 Name, Description: String; ExtraArgs: Pointer); 339 var 340 fstream: TMemoryStream; 341 begin 342 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs); 343 FDataLength := 4; 344 fstream := TFile(ParentFile).FileStream; 345 fstream.Seek(Offset, soFromBeginning); 346 fstream.Read(FLevelID, 4); 347 FLevelID := FLevelID div 256 div 256 div 256 div 2; 348 end; 349 350 function TLevelID.GetValueAsString: String; 351 begin 352 Result := IntToStr(FLevelID); 353 end; 354 355 procedure TLevelID.Update(Offset, Length: Integer); 356 begin 357 Exit; 358 end; 359 360 361 362 { TFileID } 363 364 constructor TFileID.Create(ParentFile: TObject; Offset: Integer; 365 Name, Description: String; ExtraArgs: Pointer); 366 var 367 fstream: TMemoryStream; 368 begin 369 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs); 370 FDataLength := 4; 371 fstream := TFile(ParentFile).FileStream; 372 fstream.Seek(Offset, soFromBeginning); 373 fstream.Read(FFileID, 4); 374 if FFileID > 0 then 375 FFileID := FFileID div 256 376 else 377 FFileID := -1; 378 end; 379 380 function TFileID.GetValueAsString: String; 381 begin 382 Result := IntToStr(FFileID); 383 end; 384 385 procedure TFileID.Update(Offset, Length: Integer); 386 begin 387 Exit; 388 end; 389 390 391 392 { TLinkByID } 393 394 constructor TLinkByID.Create(ParentFile: TObject; Offset: Integer; Name, 395 Description: String; ExtraArgs: Pointer); 396 var 397 fstream: TMemoryStream; 398 begin 399 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs); 400 FDataLength := 4; 401 FPosExts := String(ExtraArgs^); 402 fstream := TFile(ParentFile).FileStream; 403 fstream.Seek(Offset, soFromBeginning); 404 fstream.Read(FFileID, 4); 405 if FFileID > 0 then 406 FFileID := FFileID div 256 407 else 408 FFileID := -1; 409 end; 410 411 function TLinkByID.GetValueAsString: String; 412 begin 413 Result := IntToStr(FFileID); 414 end; 415 416 procedure TLinkByID.Update(Offset, Length: Integer); 417 begin 418 Exit; 419 end; 420 421 422 423 { TRawLink } 424 425 constructor TRawLink.Create(ParentFile: TObject; Offset: Integer; Name, 426 Description: String; ExtraArgs: Pointer); 427 var 428 fstream: TMemoryStream; 429 begin 430 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs); 431 FDataLength := 4; 432 fstream := TFile(ParentFile).FileStream; 433 fstream.Seek(Offset, soFromBeginning); 434 fstream.Read(FRawAddress, 4); 435 end; 436 437 function TRawLink.GetValueAsString: String; 438 begin 439 Result := IntToStr(FRawAddress); 440 end; 441 442 procedure TRawLink.Update(Offset, Length: Integer); 443 begin 444 Exit; 445 end; 446 447 448 449 { TUnused } 450 451 constructor TUnused.Create(ParentFile: TObject; Offset: Integer; Name, 452 Description: String; ExtraArgs: Pointer); 453 begin 454 inherited Create(ParentFile, Offset, Name, Description, ExtraArgs); 455 FDataLength := Integer(ExtraArgs^); 456 end; 457 458 function TUnused.GetValueAsString: String; 459 begin 460 Result := ''; 461 end; 462 463 procedure TUnused.Update(Offset, Length: Integer); 464 begin 465 Exit; 466 end; 135 467 136 468 end. -
oup/current/FileClasses/_FileTypes.pas
r126 r206 4 4 5 5 uses 6 TypeDefs, _DataTypes ;6 TypeDefs, _DataTypes, Classes; 7 7 8 8 9 9 type 10 10 TFile = class 11 pr ivate11 protected 12 12 FConnectionID: Integer; 13 13 FFileID: Integer; 14 FFile: TMemoryStream; 14 15 15 16 FDatLinks: TDatLinkList; 16 FDataFields: T DataFields;17 FDataFields: TBlock; 17 18 FRawParts: TRawDataList; 19 20 procedure InitDatLinks; virtual; abstract; 21 procedure InitDataFields; virtual; abstract; 22 procedure InitRawList; virtual; abstract; 18 23 19 24 function GetDatLinkByOffset(Offset: Integer): TDatLink; … … 24 29 function GetRawPartByIndex(ID: Integer): TRawDataInfo; 25 30 public 26 constructor Create(ConnectionID, FileID: Integer); 27 31 constructor Create(ConnectionID, FileID: Integer); virtual; 32 procedure Free; 33 34 property FileStream: TMemoryStream read FFile; 35 property FileID: Integer read FFileID; 36 property ConnectionID: Integer read FConnectionID; 37 28 38 property LinkByOffset[Offset: Integer]: TDatLink read GetDatLinkByOffset; 29 39 property LinkByIndex[ID: Integer]: TDatLink read GetDatLinkByIndex; … … 40 50 41 51 uses 42 DatLinks, RawList ;52 DatLinks, RawList, ConnectionManager, Dialogs; 43 53 44 54 { TFileType } 45 55 46 56 constructor TFile.Create(ConnectionID, FileID: Integer); 57 var 58 i: Integer; 47 59 begin 48 60 FConnectionID := ConnectionID; 49 61 FFileID := FileID; 62 FFile := nil; 50 63 51 FDatLinks := DatLinksManager.GetDatLinks(ConnectionID, FileID); 52 FRawParts := RawLists.GetRawList(ConnectionID, FileID); 64 FFile := TMemoryStream.Create; 65 ConManager.Connection[ConnectionID].LoadDatFile(FileID, TStream(FFile)); 66 67 InitDatLinks(); 68 InitDataFields(); 69 InitRawList(); 70 71 if FDataFields.FieldCount > 0 then 72 begin 73 for i := 0 to FDataFields.FieldCount - 1 do 74 begin 75 ShowMessage(FDataFields.FieldByIndex[i].ValueAsString); 76 end; 77 end; 78 79 FFile.Free; 80 FFile := nil; 81 82 // FDatLinks := DatLinksManager.GetDatLinks(ConnectionID, FileID); 83 // FRawParts := RawLists.GetRawList(ConnectionID, FileID); 53 84 end; 54 85 86 87 procedure TFile.Free; 88 begin 89 FDataFields.Free; 90 end; 55 91 56 92 function TFile.GetDatLinkByIndex(ID: Integer): TDatLink; … … 88 124 function TFile.GetFieldByIndex(ID: Integer): TDataField; 89 125 begin 90 if ID < Length(FDataFields) then 91 Result := FDataFields[ID] 92 else 93 Result := nil; 126 Result := FDataFields.FieldByIndex[ID]; 94 127 end; 95 128 … … 98 131 i: Integer; 99 132 begin 100 Result := nil; 101 102 if Length(FDataFields) > 0 then 103 begin 104 for i := 0 to High(FDataFields) do 105 if FDataFields[i].Offset = Offset then 106 break; 107 if i < Length(FDataFields) then 108 Result := FDataFields[i]; 109 end; 133 Result := FDataFields.FieldByOffset[Offset]; 110 134 end; 111 135
Note:
See TracChangeset
for help on using the changeset viewer.