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; virtual; abstract;
|
---|
30 | procedure InitRawList; virtual; abstract;
|
---|
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 | end;
|
---|
104 |
|
---|
105 | InitDatLinks();
|
---|
106 | InitRawList();
|
---|
107 | FDataFields := nil;
|
---|
108 | FEditor := nil;
|
---|
109 |
|
---|
110 | if not (Self is TFile_Empty) then
|
---|
111 | FFileStream.Free;
|
---|
112 | FFileStream := nil;
|
---|
113 | end;
|
---|
114 |
|
---|
115 |
|
---|
116 | procedure TFile.Free;
|
---|
117 | begin
|
---|
118 | FDataFields.Free;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
|
---|
122 | var
|
---|
123 | i: Integer;
|
---|
124 | valids: Integer;
|
---|
125 | begin
|
---|
126 | if ID < GetChildCount then
|
---|
127 | begin
|
---|
128 | valids := 0;
|
---|
129 | i := 0;
|
---|
130 | repeat
|
---|
131 | if FDatLinks[i].DestID >= 0 then
|
---|
132 | begin
|
---|
133 | Inc(valids);
|
---|
134 | end;
|
---|
135 | Inc(i);
|
---|
136 | until valids > ID;
|
---|
137 | Result := FDatLinks[i - 1];
|
---|
138 | end
|
---|
139 | else
|
---|
140 | with Result do
|
---|
141 | begin
|
---|
142 | SrcOffset := -1;
|
---|
143 | DestID := -1;
|
---|
144 | PosDestExts := '';
|
---|
145 | end;
|
---|
146 | end;
|
---|
147 |
|
---|
148 | function TFile.GetDatLinkByOffset(Offset: Integer): TDatLink;
|
---|
149 | var
|
---|
150 | i: Integer;
|
---|
151 | begin
|
---|
152 | Result.SrcOffset := -1;
|
---|
153 | Result.DestID := -1;
|
---|
154 | Result.PosDestExts := '';
|
---|
155 |
|
---|
156 | if Length(FDatLinks) > 0 then
|
---|
157 | begin
|
---|
158 | for i := 0 to High(FDatLinks) do
|
---|
159 | if FDatLinks[i].SrcOffset = Offset then
|
---|
160 | break;
|
---|
161 | if i < Length(FDatLinks) then
|
---|
162 | Result := FDatLinks[i];
|
---|
163 | end;
|
---|
164 | end;
|
---|
165 |
|
---|
166 |
|
---|
167 | function TFile.GetFieldByIndex(ID: Integer): TDataField;
|
---|
168 | begin
|
---|
169 | Result := FDataFields.FieldByIndex[ID];
|
---|
170 | end;
|
---|
171 |
|
---|
172 | function TFile.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
173 | begin
|
---|
174 | Result := FDataFields.FieldByOffset[Offset];
|
---|
175 | end;
|
---|
176 |
|
---|
177 |
|
---|
178 | function TFile.GetChildCount: Integer;
|
---|
179 | var
|
---|
180 | i: Integer;
|
---|
181 | begin
|
---|
182 | Result := Length(FDatLinks);
|
---|
183 | if Result > 0 then
|
---|
184 | begin
|
---|
185 | Result := 0;
|
---|
186 | for i := 0 to High(FDatLinks) do
|
---|
187 | if FDatLinks[i].DestID >= 0 then
|
---|
188 | Inc(Result);
|
---|
189 | end;
|
---|
190 | end;
|
---|
191 |
|
---|
192 | function TFile.GetRawPartByIndex(ID: Integer): TRawDataInfo;
|
---|
193 | begin
|
---|
194 | if ID < Length(FRawParts) then
|
---|
195 | Result := FRawParts[ID]
|
---|
196 | else
|
---|
197 | with Result do
|
---|
198 | begin
|
---|
199 | SrcID := -1;
|
---|
200 | SrcOffset := -1;
|
---|
201 | RawAddr := -1;
|
---|
202 | RawSize := -1;
|
---|
203 | end;
|
---|
204 | end;
|
---|
205 |
|
---|
206 | function TFile.GetRawPartByOffset(Offset: Integer): TRawDataInfo;
|
---|
207 | var
|
---|
208 | i: Integer;
|
---|
209 | begin
|
---|
210 | with Result do
|
---|
211 | begin
|
---|
212 | SrcID := -1;
|
---|
213 | SrcOffset := -1;
|
---|
214 | RawAddr := -1;
|
---|
215 | RawSize := -1;
|
---|
216 | end;
|
---|
217 |
|
---|
218 | if Length(FRawParts) > 0 then
|
---|
219 | begin
|
---|
220 | for i := 0 to High(FRawParts) do
|
---|
221 | if FRawParts[i].SrcOffset = Offset then
|
---|
222 | break;
|
---|
223 | if i < Length(FRawParts) then
|
---|
224 | Result := FRawParts[i];
|
---|
225 | end;
|
---|
226 | end;
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 | procedure TFile.InitDataFields;
|
---|
231 | begin
|
---|
232 | if Assigned(FDataFields) then
|
---|
233 | Exit;
|
---|
234 | end;
|
---|
235 |
|
---|
236 | procedure TFile.InitEditor;
|
---|
237 | begin
|
---|
238 | Exit;
|
---|
239 | end;
|
---|
240 |
|
---|
241 | function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
|
---|
242 | begin
|
---|
243 | stream.Seek(Offset, soFromBeginning);
|
---|
244 | stream.Read(Result, 4);
|
---|
245 | if Result > 0 then
|
---|
246 | Result := Result div 256
|
---|
247 | else
|
---|
248 | Result := -1;
|
---|
249 | end;
|
---|
250 |
|
---|
251 | end.
|
---|