| 1 | unit _MetaManager; | 
 
 
 
 
 | 2 | interface | 
 
 
 
 
 | 3 |  | 
 
 
 
 
 | 4 | uses _FileTypes, SUBT, 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..2] of TFileDesc = ( | 
 
 
 
 
 | 15 | (ext: 'SUBT'; ftype: TFile_SUBT), | 
 
 
 
 
 | 16 | (ext: 'TXAN'; ftype: TFile_TXAN), | 
 
 
 
 
 | 17 | (ext: 'TXMP'; ftype: TFile_TXMP) | 
 
 
 
 
 | 18 | ); | 
 
 
 
 
 | 19 |  | 
 
 
 
 
 | 20 | type | 
 
 
 
 
 | 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 |  | 
 
 
 
 
 | 38 | var | 
 
 
 
 
 | 39 | Meta: TMetaManager; | 
 
 
 
 
 | 40 |  | 
 
 
 
 
 | 41 | implementation | 
 
 
 
 
 | 42 |  | 
 
 
 
 
 | 43 | uses | 
 
 
 
 
 | 44 | Classes, ConnectionManager, Access_OniArchive, TypeDefs, Dialogs, SysUtils, StrUtils; | 
 
 
 
 
 | 45 |  | 
 
 
 
 
 | 46 | { TFileManager } | 
 
 
 
 
 | 47 |  | 
 
 
 
 
 | 48 | constructor TMetaManager.Create(ConnectionID: Integer); | 
 
 
 
 
 | 49 | begin | 
 
 
 
 
 | 50 | FConnectionID := ConnectionID; | 
 
 
 
 
 | 51 | InitRootFiles; | 
 
 
 
 
 | 52 | end; | 
 
 
 
 
 | 53 |  | 
 
 
 
 
 | 54 | function TMetaManager.GetFileById(Id: Integer): TFile; | 
 
 
 
 
 | 55 | begin | 
 
 
 
 
 | 56 | Result := FFiles[Id]; | 
 
 
 
 
 | 57 | end; | 
 
 
 
 
 | 58 |  | 
 
 
 
 
 | 59 | function TMetaManager.GetFileCount: Integer; | 
 
 
 
 
 | 60 | begin | 
 
 
 
 
 | 61 | Result := Length(FFiles); | 
 
 
 
 
 | 62 | end; | 
 
 
 
 
 | 63 |  | 
 
 
 
 
 | 64 | procedure TMetaManager.InitFile(id: Integer); | 
 
 
 
 
 | 65 | var | 
 
 
 
 
 | 66 | typei: Integer; | 
 
 
 
 
 | 67 | finfo: TFileInfo; | 
 
 
 
 
 | 68 | begin | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 91 | end; | 
 
 
 
 
 | 92 |  | 
 
 
 
 
 | 93 | procedure TMetaManager.InitFileFields(id: Integer); | 
 
 
 
 
 | 94 | begin | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 104 | end; | 
 
 
 
 
 | 105 |  | 
 
 
 
 
 | 106 | procedure TMetaManager.InitRootFiles; | 
 
 
 
 
 | 107 | var | 
 
 
 
 
 | 108 | files: TStrings; | 
 
 
 
 
 | 109 | i: Integer; | 
 
 
 
 
 | 110 | typei: Integer; | 
 
 
 
 
 | 111 | fid: Integer; | 
 
 
 
 
 | 112 | finfo: TFileInfo; | 
 
 
 
 
 | 113 | begin | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 148 | end; | 
 
 
 
 
 | 149 |  | 
 
 
 
 
 | 150 | end. |