1 | unit _FileTypes;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | TypeDefs, _DataTypes, Classes, Forms;
|
---|
7 |
|
---|
8 |
|
---|
9 | type
|
---|
10 | TFile = class
|
---|
11 | protected
|
---|
12 | FConnectionID: Integer;
|
---|
13 | FFileID: Integer;
|
---|
14 | FFileName: String;
|
---|
15 | FFileExt: String;
|
---|
16 | FFileSize: Integer;
|
---|
17 | FFileStream: TMemoryStream;
|
---|
18 |
|
---|
19 | FCached: Boolean;
|
---|
20 | FChanged: Boolean;
|
---|
21 |
|
---|
22 | FDatLinks: TDatLinkList;
|
---|
23 | FDataFields: TBlock;
|
---|
24 | FRawParts: TRawDataList;
|
---|
25 |
|
---|
26 | FEditor: TFrame;
|
---|
27 | FOpened: Boolean;
|
---|
28 |
|
---|
29 | procedure InitDatLinks;
|
---|
30 | procedure InitRawList;
|
---|
31 |
|
---|
32 | function GetDatLinkByOffset(Offset: Integer): TDatLink;
|
---|
33 | function GetDatLinkByIndex(ID: Integer): TDatLink;
|
---|
34 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
35 | function GetFieldByIndex(ID: Integer): TDataField;
|
---|
36 | function GetRawPartByOffset(Offset: Integer): TRawDataInfo;
|
---|
37 | function GetRawPartByIndex(ID: Integer): TRawDataInfo;
|
---|
38 | function GetChildCount: Integer;
|
---|
39 | public
|
---|
40 | constructor Create(ConnectionID, FileID: Integer); virtual;
|
---|
41 | procedure Free;
|
---|
42 |
|
---|
43 | procedure InitDataFields; virtual;
|
---|
44 | procedure InitEditor; virtual;
|
---|
45 |
|
---|
46 | property FileStream: TMemoryStream read FFileStream;
|
---|
47 | property FileID: Integer read FFileID;
|
---|
48 | property FileName: String read FFileName;
|
---|
49 | property FileExt: String read FFileExt;
|
---|
50 | property FileSize: Integer read FFileSize;
|
---|
51 | property ConnectionID: Integer read FConnectionID;
|
---|
52 |
|
---|
53 | property Cached: Boolean read FCached;
|
---|
54 | property Changed: Boolean read FChanged write FChanged;
|
---|
55 |
|
---|
56 | property Editor: TFrame read FEditor;
|
---|
57 | property Opened: Boolean read FOpened write FOpened;
|
---|
58 |
|
---|
59 | property ChildCount: Integer read GetChildCount;
|
---|
60 | property LinkByOffset[Offset: Integer]: TDatLink read GetDatLinkByOffset;
|
---|
61 | property LinkByIndex[ID: Integer]: TDatLink read GetDatLinkByIndex;
|
---|
62 |
|
---|
63 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
---|
64 | property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
|
---|
65 |
|
---|
66 | property RawPartByOffset[Offset: Integer]: TRawDataInfo read GetRawPartByOffset;
|
---|
67 | property RawPartByIndex[ID: Integer]: TRawDataInfo read GetRawPartByIndex;
|
---|
68 | end;
|
---|
69 |
|
---|
70 |
|
---|
71 | TFileType = class of TFile;
|
---|
72 |
|
---|
73 |
|
---|
74 | function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 | implementation
|
---|
79 |
|
---|
80 | uses
|
---|
81 | DatLinks, RawList, ConnectionManager, Dialogs, _EmptyFile;
|
---|
82 |
|
---|
83 | { TFileType }
|
---|
84 |
|
---|
85 | constructor TFile.Create(ConnectionID, FileID: Integer);
|
---|
86 | var
|
---|
87 | fileinfo: TFileInfo;
|
---|
88 | begin
|
---|
89 | FConnectionID := ConnectionID;
|
---|
90 | FFileID := FileID;
|
---|
91 | fileinfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
|
---|
92 | FFileName := fileinfo.Name;
|
---|
93 | FFileExt := fileinfo.Extension;
|
---|
94 | FFileSize := fileinfo.Size;
|
---|
95 |
|
---|
96 | FCached := False;
|
---|
97 | FChanged := False;
|
---|
98 |
|
---|
99 | if not (Self is TFile_Empty) then
|
---|
100 | begin
|
---|
101 | FFileStream := TMemoryStream.Create;
|
---|
102 | ConManager.Connection[ConnectionID].LoadDatFile(FileID, TStream(FFileStream));
|
---|
103 |
|
---|
104 | InitDatLinks();
|
---|
105 | InitRawList();
|
---|
106 | FDataFields := nil;
|
---|
107 | FEditor := nil;
|
---|
108 |
|
---|
109 | FFileStream.Free;
|
---|
110 | FFileStream := nil;
|
---|
111 | end
|
---|
112 | else
|
---|
113 | begin
|
---|
114 | SetLength(FDatLinks, 0);
|
---|
115 | SetLength(FRawParts, 0);
|
---|
116 | FEditor := nil;
|
---|
117 | end;
|
---|
118 | end;
|
---|
119 |
|
---|
120 |
|
---|
121 | procedure TFile.Free;
|
---|
122 | begin
|
---|
123 | FDataFields.Free;
|
---|
124 | end;
|
---|
125 |
|
---|
126 | function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
|
---|
127 | var
|
---|
128 | i: Integer;
|
---|
129 | valids: Integer;
|
---|
130 | begin
|
---|
131 | if ID < GetChildCount then
|
---|
132 | begin
|
---|
133 | valids := 0;
|
---|
134 | i := 0;
|
---|
135 | repeat
|
---|
136 | if FDatLinks[i].DestID >= 0 then
|
---|
137 | begin
|
---|
138 | Inc(valids);
|
---|
139 | end;
|
---|
140 | Inc(i);
|
---|
141 | until valids > ID;
|
---|
142 | Result := FDatLinks[i - 1];
|
---|
143 | end
|
---|
144 | else
|
---|
145 | with Result do
|
---|
146 | begin
|
---|
147 | SrcOffset := -1;
|
---|
148 | DestID := -1;
|
---|
149 | PosDestExts := '';
|
---|
150 | end;
|
---|
151 | end;
|
---|
152 |
|
---|
153 | function TFile.GetDatLinkByOffset(Offset: Integer): TDatLink;
|
---|
154 | var
|
---|
155 | i: Integer;
|
---|
156 | begin
|
---|
157 | Result.SrcOffset := -1;
|
---|
158 | Result.DestID := -1;
|
---|
159 | Result.PosDestExts := '';
|
---|
160 |
|
---|
161 | if Length(FDatLinks) > 0 then
|
---|
162 | begin
|
---|
163 | for i := 0 to High(FDatLinks) do
|
---|
164 | if FDatLinks[i].SrcOffset = Offset then
|
---|
165 | break;
|
---|
166 | if i < Length(FDatLinks) then
|
---|
167 | Result := FDatLinks[i];
|
---|
168 | end;
|
---|
169 | end;
|
---|
170 |
|
---|
171 |
|
---|
172 | function TFile.GetFieldByIndex(ID: Integer): TDataField;
|
---|
173 | begin
|
---|
174 | Result := FDataFields.FieldByIndex[ID];
|
---|
175 | end;
|
---|
176 |
|
---|
177 | function TFile.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
178 | begin
|
---|
179 | Result := FDataFields.FieldByOffset[Offset];
|
---|
180 | end;
|
---|
181 |
|
---|
182 |
|
---|
183 | function TFile.GetChildCount: Integer;
|
---|
184 | var
|
---|
185 | i: Integer;
|
---|
186 | begin
|
---|
187 | Result := Length(FDatLinks);
|
---|
188 | if Result > 0 then
|
---|
189 | begin
|
---|
190 | Result := 0;
|
---|
191 | for i := 0 to High(FDatLinks) do
|
---|
192 | if FDatLinks[i].DestID >= 0 then
|
---|
193 | Inc(Result);
|
---|
194 | end;
|
---|
195 | end;
|
---|
196 |
|
---|
197 | function TFile.GetRawPartByIndex(ID: Integer): TRawDataInfo;
|
---|
198 | begin
|
---|
199 | if ID < Length(FRawParts) then
|
---|
200 | Result := FRawParts[ID]
|
---|
201 | else
|
---|
202 | with Result do
|
---|
203 | begin
|
---|
204 | SrcID := -1;
|
---|
205 | SrcOffset := -1;
|
---|
206 | RawAddr := -1;
|
---|
207 | RawSize := -1;
|
---|
208 | end;
|
---|
209 | end;
|
---|
210 |
|
---|
211 | function TFile.GetRawPartByOffset(Offset: Integer): TRawDataInfo;
|
---|
212 | var
|
---|
213 | i: Integer;
|
---|
214 | begin
|
---|
215 | with Result do
|
---|
216 | begin
|
---|
217 | SrcID := -1;
|
---|
218 | SrcOffset := -1;
|
---|
219 | RawAddr := -1;
|
---|
220 | RawSize := -1;
|
---|
221 | end;
|
---|
222 |
|
---|
223 | if Length(FRawParts) > 0 then
|
---|
224 | begin
|
---|
225 | for i := 0 to High(FRawParts) do
|
---|
226 | if FRawParts[i].SrcOffset = Offset then
|
---|
227 | break;
|
---|
228 | if i < Length(FRawParts) then
|
---|
229 | Result := FRawParts[i];
|
---|
230 | end;
|
---|
231 | end;
|
---|
232 |
|
---|
233 |
|
---|
234 |
|
---|
235 | procedure TFile.InitDataFields;
|
---|
236 | begin
|
---|
237 | if Assigned(FDataFields) then
|
---|
238 | Exit;
|
---|
239 | end;
|
---|
240 |
|
---|
241 | procedure TFile.InitDatLinks;
|
---|
242 | begin
|
---|
243 | FDatLinks := ConManager.Connection[FConnectionID].GetDatLinks(FFileID);
|
---|
244 | end;
|
---|
245 |
|
---|
246 | procedure TFile.InitEditor;
|
---|
247 | begin
|
---|
248 | Exit;
|
---|
249 | end;
|
---|
250 |
|
---|
251 | procedure TFile.InitRawList;
|
---|
252 | begin
|
---|
253 | FRawParts := ConManager.Connection[FConnectionID].GetRawList(FFileID);
|
---|
254 | end;
|
---|
255 |
|
---|
256 | function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
|
---|
257 | begin
|
---|
258 | stream.Seek(Offset, soFromBeginning);
|
---|
259 | stream.Read(Result, 4);
|
---|
260 | if Result > 0 then
|
---|
261 | Result := Result div 256
|
---|
262 | else
|
---|
263 | Result := -1;
|
---|
264 | end;
|
---|
265 |
|
---|
266 | end.
|
---|