source: oup/current/FileClasses/_FileTypes.pas@ 231

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