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

Last change on this file since 216 was 216, checked in by alloc, 18 years ago
File size: 5.7 KB
RevLine 
[124]1unit _FileTypes;
2
3interface
4
5uses
[214]6 TypeDefs, _DataTypes, Classes, Forms;
[124]7
8
9type
[126]10 TFile = class
[206]11 protected
[126]12 FConnectionID: Integer;
13 FFileID: Integer;
[209]14 FFileName: String;
[210]15 FFileExt: String;
16 FFileSize: Integer;
17 FFileStream: TMemoryStream;
[126]18
[212]19 FCached: Boolean;
20 FChanged: Boolean;
21
[124]22 FDatLinks: TDatLinkList;
[206]23 FDataFields: TBlock;
[126]24 FRawParts: TRawDataList;
25
[214]26 FEditor: TFrame;
27 FOpened: Boolean;
28
[215]29 procedure InitDatLinks;
30 procedure InitRawList;
[206]31
[126]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;
[212]38 function GetChildCount: Integer;
[124]39 public
[206]40 constructor Create(ConnectionID, FileID: Integer); virtual;
41 procedure Free;
42
[213]43 procedure InitDataFields; virtual;
[214]44 procedure InitEditor; virtual;
[213]45
[210]46 property FileStream: TMemoryStream read FFileStream;
[206]47 property FileID: Integer read FFileID;
[209]48 property FileName: String read FFileName;
[210]49 property FileExt: String read FFileExt;
50 property FileSize: Integer read FFileSize;
[206]51 property ConnectionID: Integer read FConnectionID;
52
[212]53 property Cached: Boolean read FCached;
54 property Changed: Boolean read FChanged write FChanged;
55
[214]56 property Editor: TFrame read FEditor;
57 property Opened: Boolean read FOpened write FOpened;
58
[212]59 property ChildCount: Integer read GetChildCount;
[126]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;
[124]68 end;
69
70
[207]71 TFileType = class of TFile;
72
73
[209]74function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
75
76
77
[124]78implementation
79
[126]80uses
[212]81 DatLinks, RawList, ConnectionManager, Dialogs, _EmptyFile;
[126]82
[124]83{ TFileType }
84
[126]85constructor TFile.Create(ConnectionID, FileID: Integer);
[206]86var
[210]87 fileinfo: TFileInfo;
[126]88begin
89 FConnectionID := ConnectionID;
90 FFileID := FileID;
[210]91 fileinfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
92 FFileName := fileinfo.Name;
93 FFileExt := fileinfo.Extension;
94 FFileSize := fileinfo.Size;
[126]95
[212]96 FCached := False;
97 FChanged := False;
[206]98
[212]99 if not (Self is TFile_Empty) then
100 begin
[215]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;
[126]112end;
113
114
[206]115procedure TFile.Free;
116begin
117 FDataFields.Free;
118end;
119
[126]120function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
[212]121var
122 i: Integer;
123 valids: Integer;
[126]124begin
[212]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
[126]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;
[124]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
[126]165
166function TFile.GetFieldByIndex(ID: Integer): TDataField;
167begin
[206]168 Result := FDataFields.FieldByIndex[ID];
[126]169end;
170
171function TFile.GetFieldByOffset(Offset: Integer): TDataField;
[124]172begin
[206]173 Result := FDataFields.FieldByOffset[Offset];
[124]174end;
175
[126]176
[212]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
[126]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
[209]227
228
[213]229procedure TFile.InitDataFields;
230begin
231 if Assigned(FDataFields) then
232 Exit;
233end;
234
[215]235procedure TFile.InitDatLinks;
236begin
237 FDatLinks := ConManager.Connection[FConnectionID].GetDatLinks(FFileID);
238end;
239
[214]240procedure TFile.InitEditor;
241begin
242 Exit;
243end;
244
[215]245procedure TFile.InitRawList;
246begin
247 FRawParts := ConManager.Connection[FConnectionID].GetRawList(FFileID);
248end;
249
[209]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
[124]260end.
Note: See TracBrowser for help on using the repository browser.