| 1 | unit _FileTypes;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | TypeDefs, _DataTypes, Classes;
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 | TFile = class
|
|---|
| 11 | protected
|
|---|
| 12 | FConnectionID: Integer;
|
|---|
| 13 | FFileID: Integer;
|
|---|
| 14 | FFile: TMemoryStream;
|
|---|
| 15 |
|
|---|
| 16 | FDatLinks: TDatLinkList;
|
|---|
| 17 | FDataFields: TBlock;
|
|---|
| 18 | FRawParts: TRawDataList;
|
|---|
| 19 |
|
|---|
| 20 | procedure InitDatLinks; virtual; abstract;
|
|---|
| 21 | procedure InitDataFields; virtual; abstract;
|
|---|
| 22 | procedure InitRawList; virtual; abstract;
|
|---|
| 23 |
|
|---|
| 24 | function GetDatLinkByOffset(Offset: Integer): TDatLink;
|
|---|
| 25 | function GetDatLinkByIndex(ID: Integer): TDatLink;
|
|---|
| 26 | function GetFieldByOffset(Offset: Integer): TDataField;
|
|---|
| 27 | function GetFieldByIndex(ID: Integer): TDataField;
|
|---|
| 28 | function GetRawPartByOffset(Offset: Integer): TRawDataInfo;
|
|---|
| 29 | function GetRawPartByIndex(ID: Integer): TRawDataInfo;
|
|---|
| 30 | public
|
|---|
| 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 |
|
|---|
| 38 | property LinkByOffset[Offset: Integer]: TDatLink read GetDatLinkByOffset;
|
|---|
| 39 | property LinkByIndex[ID: Integer]: TDatLink read GetDatLinkByIndex;
|
|---|
| 40 |
|
|---|
| 41 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
|---|
| 42 | property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
|
|---|
| 43 |
|
|---|
| 44 | property RawPartByOffset[Offset: Integer]: TRawDataInfo read GetRawPartByOffset;
|
|---|
| 45 | property RawPartByIndex[ID: Integer]: TRawDataInfo read GetRawPartByIndex;
|
|---|
| 46 | end;
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | TFileType = class of TFile;
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | implementation
|
|---|
| 53 |
|
|---|
| 54 | uses
|
|---|
| 55 | DatLinks, RawList, ConnectionManager, Dialogs;
|
|---|
| 56 |
|
|---|
| 57 | { TFileType }
|
|---|
| 58 |
|
|---|
| 59 | constructor TFile.Create(ConnectionID, FileID: Integer);
|
|---|
| 60 | var
|
|---|
| 61 | i: Integer;
|
|---|
| 62 | begin
|
|---|
| 63 | FConnectionID := ConnectionID;
|
|---|
| 64 | FFileID := FileID;
|
|---|
| 65 | FFile := nil;
|
|---|
| 66 |
|
|---|
| 67 | FFile := TMemoryStream.Create;
|
|---|
| 68 | ConManager.Connection[ConnectionID].LoadDatFile(FileID, TStream(FFile));
|
|---|
| 69 |
|
|---|
| 70 | InitDatLinks();
|
|---|
| 71 | InitDataFields();
|
|---|
| 72 | InitRawList();
|
|---|
| 73 |
|
|---|
| 74 | if FDataFields.FieldCount > 0 then
|
|---|
| 75 | begin
|
|---|
| 76 | for i := 0 to FDataFields.FieldCount - 1 do
|
|---|
| 77 | begin
|
|---|
| 78 | ShowMessage(FDataFields.FieldByIndex[i].ValueAsString);
|
|---|
| 79 | end;
|
|---|
| 80 | end;
|
|---|
| 81 |
|
|---|
| 82 | FFile.Free;
|
|---|
| 83 | FFile := nil;
|
|---|
| 84 | end;
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | procedure TFile.Free;
|
|---|
| 88 | begin
|
|---|
| 89 | FDataFields.Free;
|
|---|
| 90 | end;
|
|---|
| 91 |
|
|---|
| 92 | function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
|
|---|
| 93 | begin
|
|---|
| 94 | if ID < Length(FDatLinks) then
|
|---|
| 95 | Result := FDatLinks[ID]
|
|---|
| 96 | else
|
|---|
| 97 | with Result do
|
|---|
| 98 | begin
|
|---|
| 99 | SrcOffset := -1;
|
|---|
| 100 | DestID := -1;
|
|---|
| 101 | PosDestExts := '';
|
|---|
| 102 | end;
|
|---|
| 103 | end;
|
|---|
| 104 |
|
|---|
| 105 | function TFile.GetDatLinkByOffset(Offset: Integer): TDatLink;
|
|---|
| 106 | var
|
|---|
| 107 | i: Integer;
|
|---|
| 108 | begin
|
|---|
| 109 | Result.SrcOffset := -1;
|
|---|
| 110 | Result.DestID := -1;
|
|---|
| 111 | Result.PosDestExts := '';
|
|---|
| 112 |
|
|---|
| 113 | if Length(FDatLinks) > 0 then
|
|---|
| 114 | begin
|
|---|
| 115 | for i := 0 to High(FDatLinks) do
|
|---|
| 116 | if FDatLinks[i].SrcOffset = Offset then
|
|---|
| 117 | break;
|
|---|
| 118 | if i < Length(FDatLinks) then
|
|---|
| 119 | Result := FDatLinks[i];
|
|---|
| 120 | end;
|
|---|
| 121 | end;
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | function TFile.GetFieldByIndex(ID: Integer): TDataField;
|
|---|
| 125 | begin
|
|---|
| 126 | Result := FDataFields.FieldByIndex[ID];
|
|---|
| 127 | end;
|
|---|
| 128 |
|
|---|
| 129 | function TFile.GetFieldByOffset(Offset: Integer): TDataField;
|
|---|
| 130 | var
|
|---|
| 131 | i: Integer;
|
|---|
| 132 | begin
|
|---|
| 133 | Result := FDataFields.FieldByOffset[Offset];
|
|---|
| 134 | end;
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 | function TFile.GetRawPartByIndex(ID: Integer): TRawDataInfo;
|
|---|
| 138 | begin
|
|---|
| 139 | if ID < Length(FRawParts) then
|
|---|
| 140 | Result := FRawParts[ID]
|
|---|
| 141 | else
|
|---|
| 142 | with Result do
|
|---|
| 143 | begin
|
|---|
| 144 | SrcID := -1;
|
|---|
| 145 | SrcOffset := -1;
|
|---|
| 146 | RawAddr := -1;
|
|---|
| 147 | RawSize := -1;
|
|---|
| 148 | end;
|
|---|
| 149 | end;
|
|---|
| 150 |
|
|---|
| 151 | function TFile.GetRawPartByOffset(Offset: Integer): TRawDataInfo;
|
|---|
| 152 | var
|
|---|
| 153 | i: Integer;
|
|---|
| 154 | begin
|
|---|
| 155 | with Result do
|
|---|
| 156 | begin
|
|---|
| 157 | SrcID := -1;
|
|---|
| 158 | SrcOffset := -1;
|
|---|
| 159 | RawAddr := -1;
|
|---|
| 160 | RawSize := -1;
|
|---|
| 161 | end;
|
|---|
| 162 |
|
|---|
| 163 | if Length(FRawParts) > 0 then
|
|---|
| 164 | begin
|
|---|
| 165 | for i := 0 to High(FRawParts) do
|
|---|
| 166 | if FRawParts[i].SrcOffset = Offset then
|
|---|
| 167 | break;
|
|---|
| 168 | if i < Length(FRawParts) then
|
|---|
| 169 | Result := FRawParts[i];
|
|---|
| 170 | end;
|
|---|
| 171 | end;
|
|---|
| 172 |
|
|---|
| 173 | end.
|
|---|