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

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