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

Last change on this file since 228 was 216, checked in by alloc, 17 years ago
File size: 5.7 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 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
74function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
75
76
77
78implementation
79
80uses
81 DatLinks, RawList, ConnectionManager, Dialogs, _EmptyFile;
82
83{ TFileType }
84
85constructor TFile.Create(ConnectionID, FileID: Integer);
86var
87 fileinfo: TFileInfo;
88begin
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 InitDatLinks();
102 InitRawList();
103 FDataFields := nil;
104 FEditor := nil;
105 end
106 else
107 begin
108 SetLength(FDatLinks, 0);
109 SetLength(FRawParts, 0);
110 FEditor := nil;
111 end;
112end;
113
114
115procedure TFile.Free;
116begin
117 FDataFields.Free;
118end;
119
120function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
121var
122 i: Integer;
123 valids: Integer;
124begin
125 if ID < GetChildCount then
126 begin
127 valids := 0;
128 i := 0;
129 repeat
130 if FDatLinks[i].DestID >= 0 then
131 begin
132 Inc(valids);
133 end;
134 Inc(i);
135 until valids > ID;
136 Result := FDatLinks[i - 1];
137 end
138 else
139 with Result do
140 begin
141 SrcOffset := -1;
142 DestID := -1;
143 PosDestExts := '';
144 end;
145end;
146
147function TFile.GetDatLinkByOffset(Offset: Integer): TDatLink;
148var
149 i: Integer;
150begin
151 Result.SrcOffset := -1;
152 Result.DestID := -1;
153 Result.PosDestExts := '';
154
155 if Length(FDatLinks) > 0 then
156 begin
157 for i := 0 to High(FDatLinks) do
158 if FDatLinks[i].SrcOffset = Offset then
159 break;
160 if i < Length(FDatLinks) then
161 Result := FDatLinks[i];
162 end;
163end;
164
165
166function TFile.GetFieldByIndex(ID: Integer): TDataField;
167begin
168 Result := FDataFields.FieldByIndex[ID];
169end;
170
171function TFile.GetFieldByOffset(Offset: Integer): TDataField;
172begin
173 Result := FDataFields.FieldByOffset[Offset];
174end;
175
176
177function TFile.GetChildCount: Integer;
178var
179 i: Integer;
180begin
181 Result := Length(FDatLinks);
182 if Result > 0 then
183 begin
184 Result := 0;
185 for i := 0 to High(FDatLinks) do
186 if FDatLinks[i].DestID >= 0 then
187 Inc(Result);
188 end;
189end;
190
191function TFile.GetRawPartByIndex(ID: Integer): TRawDataInfo;
192begin
193 if ID < Length(FRawParts) then
194 Result := FRawParts[ID]
195 else
196 with Result do
197 begin
198 SrcID := -1;
199 SrcOffset := -1;
200 RawAddr := -1;
201 RawSize := -1;
202 end;
203end;
204
205function TFile.GetRawPartByOffset(Offset: Integer): TRawDataInfo;
206var
207 i: Integer;
208begin
209 with Result do
210 begin
211 SrcID := -1;
212 SrcOffset := -1;
213 RawAddr := -1;
214 RawSize := -1;
215 end;
216
217 if Length(FRawParts) > 0 then
218 begin
219 for i := 0 to High(FRawParts) do
220 if FRawParts[i].SrcOffset = Offset then
221 break;
222 if i < Length(FRawParts) then
223 Result := FRawParts[i];
224 end;
225end;
226
227
228
229procedure TFile.InitDataFields;
230begin
231 if Assigned(FDataFields) then
232 Exit;
233end;
234
235procedure TFile.InitDatLinks;
236begin
237 FDatLinks := ConManager.Connection[FConnectionID].GetDatLinks(FFileID);
238end;
239
240procedure TFile.InitEditor;
241begin
242 Exit;
243end;
244
245procedure TFile.InitRawList;
246begin
247 FRawParts := ConManager.Connection[FConnectionID].GetRawList(FFileID);
248end;
249
250function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
251begin
252 stream.Seek(Offset, soFromBeginning);
253 stream.Read(Result, 4);
254 if Result > 0 then
255 Result := Result div 256
256 else
257 Result := -1;
258end;
259
260end.
Note: See TracBrowser for help on using the repository browser.