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

Last change on this file since 901 was 248, checked in by alloc, 17 years ago
File size: 2.4 KB
Line 
1unit _MetaManager;
2interface
3
4uses _MetaTypes;
5
6type
7 TMetaManager = class
8 protected
9 FFiles: array of TResource;
10 FRoot: TExtensions;
11 FConnectionID: Integer;
12 FDataAccess: TObject;
13 function GetFileCount: Integer;
14 function GetFileById(Id: Integer): TResource;
15 private
16 public
17 constructor Create(ConnectionID: Integer; DataAccess: TObject);
18 procedure InitFile(id: Integer);
19 procedure InitFileFields(id: Integer);
20
21 property Root: TExtensions read FRoot;
22 property FileCount: Integer read GetFileCount;
23 property FileById[Id: Integer]: TResource read GetFileById;
24 end;
25
26implementation
27
28uses
29 Classes, ConnectionManager, Access_OniArchive, TypeDefs,
30 Dialogs, SysUtils, StrUtils, DataAccess, _Extensions;
31
32{ TFileManager }
33
34constructor TMetaManager.Create(ConnectionID: Integer; DataAccess: TObject);
35begin
36 FConnectionID := ConnectionID;
37 FDataAccess := DataAccess;
38 SetLength(FFiles, TDataAccess(DataAccess).GetFileCount);
39 FRoot := TExtensions.Create(DataAccess, ConnectionID);
40end;
41
42
43function TMetaManager.GetFileById(Id: Integer): TResource;
44begin
45 InitFile(Id);
46 Result := FFiles[Id];
47end;
48
49function TMetaManager.GetFileCount: Integer;
50begin
51 Result := Length(FFiles);
52end;
53
54procedure TMetaManager.InitFile(id: Integer);
55var
56 typei: Integer;
57 finfo: TFileInfo;
58begin
59 if id < ConManager.Connection[FConnectionID].GetFileCount then
60 begin
61 if not Assigned(FFiles[id]) then
62 begin
63 finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
64 if finfo.Size > 0 then
65 begin
66 for typei := 0 to High(ResourceDescs) do
67 begin
68 if ResourceDescs[typei].ext = finfo.Extension then
69 begin
70 FFiles[id] := TResourceClass(ResourceDescs[typei].ftype).Create(FConnectionID, id);
71 Break;
72 end;
73 end;
74 if typei > High(ResourceDescs) then
75 FFiles[id] := TFile_Empty.Create(FConnectionID, id);
76 end else
77 FFiles[id] := TFile_Empty.Create(FConnectionID, id);
78 Exit;
79 end;
80 end;
81end;
82
83procedure TMetaManager.InitFileFields(id: Integer);
84begin
85 if id < ConManager.Connection[FConnectionID].GetFileCount then
86 begin
87 if not Assigned(FFiles[id]) then
88 begin
89 InitFile(id);
90 if not (FFiles[id] is TFile_Empty) then
91 FFiles[id].InitDataFields;
92 end;
93 end;
94end;
95
96end.
Note: See TracBrowser for help on using the repository browser.