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

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