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

Last change on this file since 216 was 215, checked in by alloc, 17 years ago
File size: 8.7 KB
RevLine 
[212]1unit _MetaManager;
2interface
3
[215]4uses _FileTypes,
5 ABNA, AGDB, AGQC, AGQG, AGQM, AGQR, AISA, AITR, AIWA, AKAA, AKBA, AKBP, AKDA,
6 AKEV, AKOT, AKVA, BINA, CBPI, CBPM, CONS, CRSA, DOOR, DPge, EDIA, ENVP, FILM,
7 FXLR, GMAN, HPge, IDXA, IGHH, IGPA, IGPG, IGSA, IGSt, Impt, IPge, KeyI, M3GA,
8 M3GM, M3TA, Mtrl, NMSA, OBAN, OBDC, OBLS, OBOA, OFGA, ONCC, ONCP, ONCV, ONFA,
9 ONGS, ONIA, ONLD, ONLV, ONMA, ONOA, ONSA, ONSK, ONTA, ONVL, ONWC, OPge, OSBD,
10 OTIT, OTLF, PLEA, PNTA, PSpc, PSpL, PSUI, QTNA, QUDA, SNDD, StNA, SUBT, TMFA,
11 TMRA, TRAC, TRAM, TRAS, TRBS, TRCM, TRFT, TRGA, TRGE, TRIA, TRIG, TRMA, TRSC,
12 TRTA, TSFF, TSFL, TSFT, TSGA, TStr, TURR, TXAN, TXCA, TXMA, TXMB, TXMP, TXPC,
13 TxtC, UUEA, UVDL, VCRA, WMCL, WMDD, WMM_, WMMB, WPge,
14 _EmptyFile;
[212]15
16type
17 TFileType = class of TFile;
18 TFileDesc = record
19 ext: String;
20 ftype: TFileType;
21 end;
22
23const
[215]24 FileDescs: array[0..112] of TFileDesc = (
25 (ext: 'ABNA'; ftype: TFile_ABNA),
26 (ext: 'AGDB'; ftype: TFile_AGDB),
27 (ext: 'AGQC'; ftype: TFile_AGQC),
28 (ext: 'AGQG'; ftype: TFile_AGQG),
29 (ext: 'AGQM'; ftype: TFile_AGQM),
30 (ext: 'AGQR'; ftype: TFile_AGQR),
31 (ext: 'AISA'; ftype: TFile_AISA),
32 (ext: 'AITR'; ftype: TFile_AITR),
33 (ext: 'AIWA'; ftype: TFile_AIWA),
34 (ext: 'AKAA'; ftype: TFile_AKAA),
35 (ext: 'AKBA'; ftype: TFile_AKBA),
36 (ext: 'AKBP'; ftype: TFile_AKBP),
37 (ext: 'AKDA'; ftype: TFile_AKDA),
38 (ext: 'AKEV'; ftype: TFile_AKEV),
39 (ext: 'AKOT'; ftype: TFile_AKOT),
40 (ext: 'AKVA'; ftype: TFile_AKVA),
41 (ext: 'BINA'; ftype: TFile_BINA),
42 (ext: 'CBPI'; ftype: TFile_CBPI),
43 (ext: 'CBPM'; ftype: TFile_CBPM),
44 (ext: 'CONS'; ftype: TFile_CONS),
45 (ext: 'CRSA'; ftype: TFile_CRSA),
46 (ext: 'DOOR'; ftype: TFile_DOOR),
47 (ext: 'DPge'; ftype: TFile_DPge),
48 (ext: 'EDIA'; ftype: TFile_EDIA),
49 (ext: 'ENVP'; ftype: TFile_ENVP),
50 (ext: 'FILM'; ftype: TFile_FILM),
51 (ext: 'FXLR'; ftype: TFile_FXLR),
52 (ext: 'GMAN'; ftype: TFile_GMAN),
53 (ext: 'HPge'; ftype: TFile_HPge),
54 (ext: 'IDXA'; ftype: TFile_IDXA),
55 (ext: 'IGHH'; ftype: TFile_IGHH),
56 (ext: 'IGPA'; ftype: TFile_IGPA),
57 (ext: 'IGPG'; ftype: TFile_IGPG),
58 (ext: 'IGSA'; ftype: TFile_IGSA),
59 (ext: 'IGSt'; ftype: TFile_IGSt),
60 (ext: 'Impt'; ftype: TFile_Impt),
61 (ext: 'IPge'; ftype: TFile_IPge),
62 (ext: 'KeyI'; ftype: TFile_KeyI),
63 (ext: 'M3GA'; ftype: TFile_M3GA),
64 (ext: 'M3GM'; ftype: TFile_M3GM),
65 (ext: 'M3TA'; ftype: TFile_M3TA),
66 (ext: 'Mtrl'; ftype: TFile_Mtrl),
67 (ext: 'NMSA'; ftype: TFile_NMSA),
68 (ext: 'OBAN'; ftype: TFile_OBAN),
69 (ext: 'OBDC'; ftype: TFile_OBDC),
70 (ext: 'OBLS'; ftype: TFile_OBLS),
71 (ext: 'OBOA'; ftype: TFile_OBOA),
72 (ext: 'OFGA'; ftype: TFile_OFGA),
73 (ext: 'ONCC'; ftype: TFile_ONCC),
74 (ext: 'ONCP'; ftype: TFile_ONCP),
75 (ext: 'ONCV'; ftype: TFile_ONCV),
76 (ext: 'ONFA'; ftype: TFile_ONFA),
77 (ext: 'ONGS'; ftype: TFile_ONGS),
78 (ext: 'ONIA'; ftype: TFile_ONIA),
79 (ext: 'ONLD'; ftype: TFile_ONLD),
80 (ext: 'ONLV'; ftype: TFile_ONLV),
81 (ext: 'ONMA'; ftype: TFile_ONMA),
82 (ext: 'ONOA'; ftype: TFile_ONOA),
83 (ext: 'ONSA'; ftype: TFile_ONSA),
84 (ext: 'ONSK'; ftype: TFile_ONSK),
85 (ext: 'ONTA'; ftype: TFile_ONTA),
86 (ext: 'ONVL'; ftype: TFile_ONVL),
87 (ext: 'ONWC'; ftype: TFile_ONWC),
88 (ext: 'OPge'; ftype: TFile_OPge),
89 (ext: 'OSBD'; ftype: TFile_OSBD),
90 (ext: 'OTIT'; ftype: TFile_OTIT),
91 (ext: 'OTLF'; ftype: TFile_OTLF),
92 (ext: 'PLEA'; ftype: TFile_PLEA),
93 (ext: 'PNTA'; ftype: TFile_PNTA),
94 (ext: 'PSpc'; ftype: TFile_PSpc),
95 (ext: 'PSpL'; ftype: TFile_PSpL),
96 (ext: 'PSUI'; ftype: TFile_PSUI),
97 (ext: 'QTNA'; ftype: TFile_QTNA),
98 (ext: 'QUDA'; ftype: TFile_QUDA),
99 (ext: 'SNDD'; ftype: TFile_SNDD),
100 (ext: 'StNA'; ftype: TFile_StNA),
[214]101 (ext: 'SUBT'; ftype: TFile_SUBT),
[215]102 (ext: 'TMFA'; ftype: TFile_TMFA),
103 (ext: 'TMRA'; ftype: TFile_TMRA),
104 (ext: 'TRAC'; ftype: TFile_TRAC),
105 (ext: 'TRAM'; ftype: TFile_TRAM),
106 (ext: 'TRAS'; ftype: TFile_TRAS),
107 (ext: 'TRBS'; ftype: TFile_TRBS),
108 (ext: 'TRCM'; ftype: TFile_TRCM),
109 (ext: 'TRFT'; ftype: TFile_TRFT),
110 (ext: 'TRGA'; ftype: TFile_TRGA),
111 (ext: 'TRGE'; ftype: TFile_TRGE),
112 (ext: 'TRIA'; ftype: TFile_TRIA),
113 (ext: 'TRIG'; ftype: TFile_TRIG),
114 (ext: 'TRMA'; ftype: TFile_TRMA),
115 (ext: 'TRSC'; ftype: TFile_TRSC),
116 (ext: 'TRTA'; ftype: TFile_TRTA),
117 (ext: 'TSFF'; ftype: TFile_TSFF),
118 (ext: 'TSFL'; ftype: TFile_TSFL),
119 (ext: 'TSFT'; ftype: TFile_TSFT),
120 (ext: 'TSGA'; ftype: TFile_TSGA),
121 (ext: 'TStr'; ftype: TFile_TStr),
122 (ext: 'TURR'; ftype: TFile_TURR),
[212]123 (ext: 'TXAN'; ftype: TFile_TXAN),
[215]124 (ext: 'TXCA'; ftype: TFile_TXCA),
125 (ext: 'TXMA'; ftype: TFile_TXMA),
126 (ext: 'TXMB'; ftype: TFile_TXMB),
127 (ext: 'TXMP'; ftype: TFile_TXMP),
128 (ext: 'TXPC'; ftype: TFile_TXPC),
129 (ext: 'TxtC'; ftype: TFile_TxtC),
130 (ext: 'UUEA'; ftype: TFile_UUEA),
131 (ext: 'UVDL'; ftype: TFile_UVDL),
132 (ext: 'VCRA'; ftype: TFile_VCRA),
133 (ext: 'WMCL'; ftype: TFile_WMCL),
134 (ext: 'WMDD'; ftype: TFile_WMDD),
135 (ext: 'WMM_'; ftype: TFile_WMM_),
136 (ext: 'WMMB'; ftype: TFile_WMMB),
137 (ext: 'WPge'; ftype: TFile_WPge)
[212]138 );
139
140type
141 TMetaManager = class
142 protected
143 FFiles: array of TFile;
144 FConnectionID: Integer;
145 function GetFileCount: Integer;
146 function GetFileById(Id: Integer): TFile;
147 private
148 procedure InitRootFiles;
149 public
150 constructor Create(ConnectionID: Integer);
151 procedure InitFile(id: Integer);
[213]152 procedure InitFileFields(id: Integer);
[212]153
154 property FileCount: Integer read GetFileCount;
155 property FileById[Id: Integer]: TFile read GetFileById;
156 end;
157
[214]158var
159 Meta: TMetaManager;
160
[212]161implementation
162
163uses
164 Classes, ConnectionManager, Access_OniArchive, TypeDefs, Dialogs, SysUtils, StrUtils;
165
166{ TFileManager }
167
168constructor TMetaManager.Create(ConnectionID: Integer);
169begin
170 FConnectionID := ConnectionID;
171 InitRootFiles;
172end;
173
174function TMetaManager.GetFileById(Id: Integer): TFile;
175begin
176 Result := FFiles[Id];
177end;
178
179function TMetaManager.GetFileCount: Integer;
180begin
181 Result := Length(FFiles);
182end;
183
184procedure TMetaManager.InitFile(id: Integer);
185var
186 typei: Integer;
187 finfo: TFileInfo;
188begin
189 if id < ConManager.Connection[FConnectionID].GetFileCount then
190 begin
191 if not Assigned(FFiles[id]) then
192 begin
193 finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
194 if finfo.Size > 0 then
195 begin
196 for typei := 0 to High(FileDescs) do
197 begin
198 if FileDescs[typei].ext = finfo.Extension then
199 begin
200 FFiles[id] := TFileType(FileDescs[typei].ftype).Create(FConnectionID, id);
201 Break;
202 end;
203 end;
204 if typei > High(FileDescs) then
205 FFiles[id] := TFile_Empty.Create(FConnectionID, id);
206 end else
207 FFiles[id] := TFile_Empty.Create(FConnectionID, id);
208 Exit;
209 end;
210 end;
211end;
212
[213]213procedure TMetaManager.InitFileFields(id: Integer);
214begin
215 if id < ConManager.Connection[FConnectionID].GetFileCount then
216 begin
217 if not Assigned(FFiles[id]) then
218 begin
219 InitFile(id);
220 if not (FFiles[id] is TFile_Empty) then
221 FFiles[id].InitDataFields;
222 end;
223 end;
224end;
225
[212]226procedure TMetaManager.InitRootFiles;
227var
228 files: TStrings;
229 i: Integer;
230 typei: Integer;
231 fid: Integer;
232 finfo: TFileInfo;
233begin
234 if ConManager.Connection[FConnectionID] is TAccess_OniArchive then
235 TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := False;
236 files := TStringList.Create;
237 files := ConManager.Connection[FConnectionID].GetFilesList('', '', False, ST_IDAsc);
238 SetLength(FFiles, ConManager.Connection[FConnectionID].GetFileCount);
239 for i := 0 to High(FFiles) do
240 FFiles[i] := nil;
241 if files.Count > 0 then
242 begin
243 for i := 0 to files.Count - 1 do
244 begin
245 fid := StrToInt(MidStr(files.Strings[i], 1, 5));
246 finfo := ConManager.Connection[FConnectionID].GetFileInfo(fid);
247 if Length(finfo.Name) > 0 then
248 begin
249 if finfo.Size > 0 then
250 begin
251 for typei := 0 to High(FileDescs) do
252 begin
253 if FileDescs[typei].ext = finfo.Extension then
254 begin
255 FFiles[fid] := TFileType(FileDescs[typei].ftype).Create(FConnectionID, fid);
256 Break;
257 end;
258 end;
259 end
260 else
261 FFiles[fid] := TFile_Empty.Create(FConnectionID, fid);
262 end;
263 end;
264 end;
265 files.Free;
266 if ConManager.Connection[FConnectionID] is TAccess_OniArchive then
267 TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := True;
268end;
269
270end.
Note: See TracBrowser for help on using the repository browser.