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

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