| [212] | 1 | unit _MetaManager; | 
|---|
|  | 2 | interface | 
|---|
|  | 3 |  | 
|---|
| [228] | 4 | uses _MetaTypes; | 
|---|
| [212] | 5 |  | 
|---|
|  | 6 | type | 
|---|
|  | 7 | TMetaManager = class | 
|---|
|  | 8 | protected | 
|---|
| [248] | 9 | FFiles: array of TResource; | 
|---|
| [229] | 10 | FRoot: TExtensions; | 
|---|
| [212] | 11 | FConnectionID: Integer; | 
|---|
| [229] | 12 | FDataAccess: TObject; | 
|---|
| [212] | 13 | function GetFileCount: Integer; | 
|---|
| [248] | 14 | function GetFileById(Id: Integer): TResource; | 
|---|
| [212] | 15 | private | 
|---|
|  | 16 | public | 
|---|
| [229] | 17 | constructor Create(ConnectionID: Integer; DataAccess: TObject); | 
|---|
| [212] | 18 | procedure InitFile(id: Integer); | 
|---|
| [213] | 19 | procedure InitFileFields(id: Integer); | 
|---|
| [212] | 20 |  | 
|---|
| [229] | 21 | property Root: TExtensions read FRoot; | 
|---|
| [212] | 22 | property FileCount: Integer read GetFileCount; | 
|---|
| [248] | 23 | property FileById[Id: Integer]: TResource read GetFileById; | 
|---|
| [212] | 24 | end; | 
|---|
|  | 25 |  | 
|---|
|  | 26 | implementation | 
|---|
|  | 27 |  | 
|---|
|  | 28 | uses | 
|---|
| [228] | 29 | Classes, ConnectionManager, Access_OniArchive, TypeDefs, | 
|---|
| [233] | 30 | Dialogs, SysUtils, StrUtils, DataAccess, _Extensions; | 
|---|
| [212] | 31 |  | 
|---|
|  | 32 | { TFileManager } | 
|---|
|  | 33 |  | 
|---|
| [229] | 34 | constructor TMetaManager.Create(ConnectionID: Integer; DataAccess: TObject); | 
|---|
| [212] | 35 | begin | 
|---|
|  | 36 | FConnectionID := ConnectionID; | 
|---|
| [229] | 37 | FDataAccess := DataAccess; | 
|---|
|  | 38 | SetLength(FFiles, TDataAccess(DataAccess).GetFileCount); | 
|---|
| [233] | 39 | FRoot := TExtensions.Create(DataAccess, ConnectionID); | 
|---|
| [212] | 40 | end; | 
|---|
|  | 41 |  | 
|---|
| [229] | 42 |  | 
|---|
| [248] | 43 | function TMetaManager.GetFileById(Id: Integer): TResource; | 
|---|
| [212] | 44 | begin | 
|---|
| [233] | 45 | InitFile(Id); | 
|---|
| [212] | 46 | Result := FFiles[Id]; | 
|---|
|  | 47 | end; | 
|---|
|  | 48 |  | 
|---|
|  | 49 | function TMetaManager.GetFileCount: Integer; | 
|---|
|  | 50 | begin | 
|---|
|  | 51 | Result := Length(FFiles); | 
|---|
|  | 52 | end; | 
|---|
|  | 53 |  | 
|---|
|  | 54 | procedure TMetaManager.InitFile(id: Integer); | 
|---|
|  | 55 | var | 
|---|
|  | 56 | typei: Integer; | 
|---|
|  | 57 | finfo: TFileInfo; | 
|---|
|  | 58 | begin | 
|---|
|  | 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 | 
|---|
| [248] | 66 | for typei := 0 to High(ResourceDescs) do | 
|---|
| [212] | 67 | begin | 
|---|
| [248] | 68 | if ResourceDescs[typei].ext = finfo.Extension then | 
|---|
| [212] | 69 | begin | 
|---|
| [248] | 70 | FFiles[id] := TResourceClass(ResourceDescs[typei].ftype).Create(FConnectionID, id); | 
|---|
| [212] | 71 | Break; | 
|---|
|  | 72 | end; | 
|---|
|  | 73 | end; | 
|---|
| [248] | 74 | if typei > High(ResourceDescs) then | 
|---|
| [212] | 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; | 
|---|
|  | 81 | end; | 
|---|
|  | 82 |  | 
|---|
| [213] | 83 | procedure TMetaManager.InitFileFields(id: Integer); | 
|---|
|  | 84 | begin | 
|---|
|  | 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; | 
|---|
|  | 94 | end; | 
|---|
|  | 95 |  | 
|---|
| [212] | 96 | end. | 
|---|