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

Last change on this file since 211 was 210, checked in by alloc, 18 years ago
File size: 4.4 KB
Line 
1unit _FileTypes;
2
3interface
4
5uses
6 TypeDefs, _DataTypes, Classes;
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 FDatLinks: TDatLinkList;
20 FDataFields: TBlock;
21 FRawParts: TRawDataList;
22
23 procedure InitDatLinks; virtual; abstract;
24 procedure InitDataFields; virtual; abstract;
25 procedure InitRawList; virtual; abstract;
26
27 function GetDatLinkByOffset(Offset: Integer): TDatLink;
28 function GetDatLinkByIndex(ID: Integer): TDatLink;
29 function GetFieldByOffset(Offset: Integer): TDataField;
30 function GetFieldByIndex(ID: Integer): TDataField;
31 function GetRawPartByOffset(Offset: Integer): TRawDataInfo;
32 function GetRawPartByIndex(ID: Integer): TRawDataInfo;
33 public
34 constructor Create(ConnectionID, FileID: Integer); virtual;
35 procedure Free;
36
37 property FileStream: TMemoryStream read FFileStream;
38 property FileID: Integer read FFileID;
39 property FileName: String read FFileName;
40 property FileExt: String read FFileExt;
41 property FileSize: Integer read FFileSize;
42 property ConnectionID: Integer read FConnectionID;
43
44 property LinkByOffset[Offset: Integer]: TDatLink read GetDatLinkByOffset;
45 property LinkByIndex[ID: Integer]: TDatLink read GetDatLinkByIndex;
46
47 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
48 property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
49
50 property RawPartByOffset[Offset: Integer]: TRawDataInfo read GetRawPartByOffset;
51 property RawPartByIndex[ID: Integer]: TRawDataInfo read GetRawPartByIndex;
52 end;
53
54
55 TFileType = class of TFile;
56
57
58function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
59
60
61
62implementation
63
64uses
65 DatLinks, RawList, ConnectionManager, Dialogs;
66
67{ TFileType }
68
69constructor TFile.Create(ConnectionID, FileID: Integer);
70var
71 i: Integer;
72 fileinfo: TFileInfo;
73begin
74 FConnectionID := ConnectionID;
75 FFileID := FileID;
76 fileinfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
77 FFileName := fileinfo.Name;
78 FFileExt := fileinfo.Extension;
79 FFileSize := fileinfo.Size;
80
81 FFileStream := TMemoryStream.Create;
82 ConManager.Connection[ConnectionID].LoadDatFile(FileID, TStream(FFileStream));
83
84 InitDatLinks();
85 InitDataFields();
86 InitRawList();
87
88 FFileStream.Free;
89 FFileStream := nil;
90end;
91
92
93procedure TFile.Free;
94begin
95 FDataFields.Free;
96end;
97
98function TFile.GetDatLinkByIndex(ID: Integer): TDatLink;
99begin
100 if ID < Length(FDatLinks) then
101 Result := FDatLinks[ID]
102 else
103 with Result do
104 begin
105 SrcOffset := -1;
106 DestID := -1;
107 PosDestExts := '';
108 end;
109end;
110
111function TFile.GetDatLinkByOffset(Offset: Integer): TDatLink;
112var
113 i: Integer;
114begin
115 Result.SrcOffset := -1;
116 Result.DestID := -1;
117 Result.PosDestExts := '';
118
119 if Length(FDatLinks) > 0 then
120 begin
121 for i := 0 to High(FDatLinks) do
122 if FDatLinks[i].SrcOffset = Offset then
123 break;
124 if i < Length(FDatLinks) then
125 Result := FDatLinks[i];
126 end;
127end;
128
129
130function TFile.GetFieldByIndex(ID: Integer): TDataField;
131begin
132 Result := FDataFields.FieldByIndex[ID];
133end;
134
135function TFile.GetFieldByOffset(Offset: Integer): TDataField;
136var
137 i: Integer;
138begin
139 Result := FDataFields.FieldByOffset[Offset];
140end;
141
142
143function TFile.GetRawPartByIndex(ID: Integer): TRawDataInfo;
144begin
145 if ID < Length(FRawParts) then
146 Result := FRawParts[ID]
147 else
148 with Result do
149 begin
150 SrcID := -1;
151 SrcOffset := -1;
152 RawAddr := -1;
153 RawSize := -1;
154 end;
155end;
156
157function TFile.GetRawPartByOffset(Offset: Integer): TRawDataInfo;
158var
159 i: Integer;
160begin
161 with Result do
162 begin
163 SrcID := -1;
164 SrcOffset := -1;
165 RawAddr := -1;
166 RawSize := -1;
167 end;
168
169 if Length(FRawParts) > 0 then
170 begin
171 for i := 0 to High(FRawParts) do
172 if FRawParts[i].SrcOffset = Offset then
173 break;
174 if i < Length(FRawParts) then
175 Result := FRawParts[i];
176 end;
177end;
178
179
180
181function GetDatLinkValue(stream: TStream; offset: Integer): Integer;
182begin
183 stream.Seek(Offset, soFromBeginning);
184 stream.Read(Result, 4);
185 if Result > 0 then
186 Result := Result div 256
187 else
188 Result := -1;
189end;
190
191end.
Note: See TracBrowser for help on using the repository browser.