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