| 1 | unit _MetaManager; | 
 
 
 
 
 | 2 | interface | 
 
 
 
 
 | 3 |  | 
 
 
 
 
 | 4 | uses _FileTypes, TXAN, TXMP, _EmptyFile; | 
 
 
 
 
 | 5 |  | 
 
 
 
 
 | 6 | type | 
 
 
 
 
 | 7 | TFileType = class of TFile; | 
 
 
 
 
 | 8 | TFileDesc = record | 
 
 
 
 
 | 9 | ext: String; | 
 
 
 
 
 | 10 | ftype: TFileType; | 
 
 
 
 
 | 11 | end; | 
 
 
 
 
 | 12 |  | 
 
 
 
 
 | 13 | const | 
 
 
 
 
 | 14 | FileDescs: array[0..1] of TFileDesc = ( | 
 
 
 
 
 | 15 | (ext: 'TXAN'; ftype: TFile_TXAN), | 
 
 
 
 
 | 16 | (ext: 'TXMP'; ftype: TFile_TXMP) | 
 
 
 
 
 | 17 | ); | 
 
 
 
 
 | 18 |  | 
 
 
 
 
 | 19 | type | 
 
 
 
 
 | 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); | 
 
 
 
 
 | 31 | procedure InitFileFields(id: Integer); | 
 
 
 
 
 | 32 |  | 
 
 
 
 
 | 33 | property FileCount: Integer read GetFileCount; | 
 
 
 
 
 | 34 | property FileById[Id: Integer]: TFile read GetFileById; | 
 
 
 
 
 | 35 | end; | 
 
 
 
 
 | 36 |  | 
 
 
 
 
 | 37 | implementation | 
 
 
 
 
 | 38 |  | 
 
 
 
 
 | 39 | uses | 
 
 
 
 
 | 40 | Classes, ConnectionManager, Access_OniArchive, TypeDefs, Dialogs, SysUtils, StrUtils; | 
 
 
 
 
 | 41 |  | 
 
 
 
 
 | 42 | { TFileManager } | 
 
 
 
 
 | 43 |  | 
 
 
 
 
 | 44 | constructor TMetaManager.Create(ConnectionID: Integer); | 
 
 
 
 
 | 45 | begin | 
 
 
 
 
 | 46 | FConnectionID := ConnectionID; | 
 
 
 
 
 | 47 | InitRootFiles; | 
 
 
 
 
 | 48 | end; | 
 
 
 
 
 | 49 |  | 
 
 
 
 
 | 50 | function TMetaManager.GetFileById(Id: Integer): TFile; | 
 
 
 
 
 | 51 | begin | 
 
 
 
 
 | 52 | Result := FFiles[Id]; | 
 
 
 
 
 | 53 | end; | 
 
 
 
 
 | 54 |  | 
 
 
 
 
 | 55 | function TMetaManager.GetFileCount: Integer; | 
 
 
 
 
 | 56 | begin | 
 
 
 
 
 | 57 | Result := Length(FFiles); | 
 
 
 
 
 | 58 | end; | 
 
 
 
 
 | 59 |  | 
 
 
 
 
 | 60 | procedure TMetaManager.InitFile(id: Integer); | 
 
 
 
 
 | 61 | var | 
 
 
 
 
 | 62 | typei: Integer; | 
 
 
 
 
 | 63 | finfo: TFileInfo; | 
 
 
 
 
 | 64 | begin | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 87 | end; | 
 
 
 
 
 | 88 |  | 
 
 
 
 
 | 89 | procedure TMetaManager.InitFileFields(id: Integer); | 
 
 
 
 
 | 90 | begin | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 100 | end; | 
 
 
 
 
 | 101 |  | 
 
 
 
 
 | 102 | procedure TMetaManager.InitRootFiles; | 
 
 
 
 
 | 103 | var | 
 
 
 
 
 | 104 | files: TStrings; | 
 
 
 
 
 | 105 | i: Integer; | 
 
 
 
 
 | 106 | typei: Integer; | 
 
 
 
 
 | 107 | fid: Integer; | 
 
 
 
 
 | 108 | finfo: TFileInfo; | 
 
 
 
 
 | 109 | begin | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 144 | end; | 
 
 
 
 
 | 145 |  | 
 
 
 
 
 | 146 | end. |