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

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