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

Last change on this file since 228 was 228, checked in by alloc, 17 years ago
File size: 3.6 KB
Line 
1unit _MetaManager;
2interface
3
4uses _MetaTypes;
5
6type
7 TMetaManager = class
8 protected
9 FFiles: array of TFile;
10 FRoot: array of TExtension;
11 FConnectionID: Integer;
12 function GetFileCount: Integer;
13 function GetFileById(Id: Integer): TFile;
14 private
15 procedure InitRootFiles;
16 public
17 constructor Create(ConnectionID: Integer);
18 procedure InitFile(id: Integer);
19 procedure InitFileFields(id: Integer);
20
21 property FileCount: Integer read GetFileCount;
22 property FileById[Id: Integer]: TFile read GetFileById;
23 end;
24
25var
26 Meta: TMetaManager;
27
28implementation
29
30uses
31 Classes, ConnectionManager, Access_OniArchive, TypeDefs,
32 Dialogs, SysUtils, StrUtils;
33
34{ TFileManager }
35
36constructor TMetaManager.Create(ConnectionID: Integer);
37begin
38 FConnectionID := ConnectionID;
39 InitRootFiles;
40end;
41
42function TMetaManager.GetFileById(Id: Integer): TFile;
43begin
44 Result := FFiles[Id];
45end;
46
47function TMetaManager.GetFileCount: Integer;
48begin
49 Result := Length(FFiles);
50end;
51
52procedure TMetaManager.InitFile(id: Integer);
53var
54 typei: Integer;
55 finfo: TFileInfo;
56begin
57 if id < ConManager.Connection[FConnectionID].GetFileCount then
58 begin
59 if not Assigned(FFiles[id]) then
60 begin
61 finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
62 if finfo.Size > 0 then
63 begin
64 for typei := 0 to High(FileDescs) do
65 begin
66 if FileDescs[typei].ext = finfo.Extension then
67 begin
68 FFiles[id] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, id);
69 Break;
70 end;
71 end;
72 if typei > High(FileDescs) then
73 FFiles[id] := TFile_Empty.Create(FConnectionID, id);
74 end else
75 FFiles[id] := TFile_Empty.Create(FConnectionID, id);
76 Exit;
77 end;
78 end;
79end;
80
81procedure TMetaManager.InitFileFields(id: Integer);
82begin
83 if id < ConManager.Connection[FConnectionID].GetFileCount then
84 begin
85 if not Assigned(FFiles[id]) then
86 begin
87 InitFile(id);
88 if not (FFiles[id] is TFile_Empty) then
89 FFiles[id].InitDataFields;
90 end;
91 end;
92end;
93
94procedure TMetaManager.InitRootFiles;
95var
96 files: TStrings;
97 i: Integer;
98 typei: Integer;
99 fid: Integer;
100 finfo: TFileInfo;
101begin
102 if ConManager.Connection[FConnectionID] is TAccess_OniArchive then
103 TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := False;
104 files := TStringList.Create;
105 files := ConManager.Connection[FConnectionID].GetFilesList('', '', False, ST_IDAsc);
106 SetLength(FFiles, ConManager.Connection[FConnectionID].GetFileCount);
107 for i := 0 to High(FFiles) do
108 FFiles[i] := nil;
109 if files.Count > 0 then
110 begin
111 for i := 0 to files.Count - 1 do
112 begin
113 fid := StrToInt(MidStr(files.Strings[i], 1, 5));
114 finfo := ConManager.Connection[FConnectionID].GetFileInfo(fid);
115 if Length(finfo.Name) > 0 then
116 begin
117 if finfo.Size > 0 then
118 begin
119 for typei := 0 to High(FileDescs) do
120 begin
121 if FileDescs[typei].ext = finfo.Extension then
122 begin
123 FFiles[fid] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, fid);
124 Break;
125 end;
126 end;
127 end
128 else
129 FFiles[fid] := TFile_Empty.Create(FConnectionID, fid);
130 end;
131 end;
132 end;
133 files.Free;
134 if ConManager.Connection[FConnectionID] is TAccess_OniArchive then
135 TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := True;
136end;
137
138end.
Note: See TracBrowser for help on using the repository browser.