| 1 | 
 unit _MetaManager; | 
 
 
 
 
 
 | 2 | 
 interface | 
 
 
 
 
 
 | 3 | 
  | 
 
 
 
 
 
 | 4 | 
 uses _MetaTypes; | 
 
 
 
 
 
 | 5 | 
  | 
 
 
 
 
 
 | 6 | 
 type | 
 
 
 
 
 
 | 7 | 
   TMetaManager = class | 
 
 
 
 
 
 | 8 | 
     protected | 
 
 
 
 
 
 | 9 | 
       FFiles: array of TFile; | 
 
 
 
 
 
 | 10 | 
       FRoot: TExtensions; | 
 
 
 
 
 
 | 11 | 
       FConnectionID: Integer; | 
 
 
 
 
 
 | 12 | 
       FDataAccess: TObject; | 
 
 
 
 
 
 | 13 | 
       function GetFileCount: Integer; | 
 
 
 
 
 
 | 14 | 
       function GetFileById(Id: Integer): TFile; | 
 
 
 
 
 
 | 15 | 
       function GetExt(Ext: String): TExtension; | 
 
 
 
 
 
 | 16 | 
       procedure AddExt(Ext: String); | 
 
 
 
 
 
 | 17 | 
     private | 
 
 
 
 
 
 | 18 | 
       procedure InitExts; | 
 
 
 
 
 
 | 19 | 
     public | 
 
 
 
 
 
 | 20 | 
       constructor Create(ConnectionID: Integer; DataAccess: TObject); | 
 
 
 
 
 
 | 21 | 
       procedure InitExtFiles(Ext: String); | 
 
 
 
 
 
 | 22 | 
       procedure InitFile(id: Integer); | 
 
 
 
 
 
 | 23 | 
       procedure InitFileFields(id: Integer); | 
 
 
 
 
 
 | 24 | 
  | 
 
 
 
 
 
 | 25 | 
       property Root: TExtensions read FRoot; | 
 
 
 
 
 
 | 26 | 
       property RootExt[Ext: String]: TExtension read GetExt; | 
 
 
 
 
 
 | 27 | 
       property FileCount: Integer read GetFileCount; | 
 
 
 
 
 
 | 28 | 
       property FileById[Id: Integer]: TFile read GetFileById; | 
 
 
 
 
 
 | 29 | 
   end; | 
 
 
 
 
 
 | 30 | 
  | 
 
 
 
 
 
 | 31 | 
 implementation | 
 
 
 
 
 
 | 32 | 
  | 
 
 
 
 
 
 | 33 | 
 uses | 
 
 
 
 
 
 | 34 | 
   Classes, ConnectionManager, Access_OniArchive, TypeDefs, | 
 
 
 
 
 
 | 35 | 
   Dialogs, SysUtils, StrUtils, DataAccess; | 
 
 
 
 
 
 | 36 | 
  | 
 
 
 
 
 
 | 37 | 
 { TFileManager } | 
 
 
 
 
 
 | 38 | 
  | 
 
 
 
 
 
 | 39 | 
 constructor TMetaManager.Create(ConnectionID: Integer; DataAccess: TObject); | 
 
 
 
 
 
 | 40 | 
 begin | 
 
 
 
 
 
 | 41 | 
   FConnectionID := ConnectionID; | 
 
 
 
 
 
 | 42 | 
   FDataAccess := DataAccess; | 
 
 
 
 
 
 | 43 | 
   SetLength(FFiles, TDataAccess(DataAccess).GetFileCount); | 
 
 
 
 
 
 | 44 | 
   InitExts; | 
 
 
 
 
 
 | 45 | 
 end; | 
 
 
 
 
 
 | 46 | 
  | 
 
 
 
 
 
 | 47 | 
 function TMetaManager.GetExt(Ext: String): TExtension; | 
 
 
 
 
 
 | 48 | 
 var | 
 
 
 
 
 
 | 49 | 
   i: Integer; | 
 
 
 
 
 
 | 50 | 
 begin | 
 
 
 
 
 
 | 51 | 
   Result := nil; | 
 
 
 
 
 
 | 52 | 
   if Length(FRoot) > 0 then | 
 
 
 
 
 
 | 53 | 
     for i := 0 to High(FRoot) do | 
 
 
 
 
 
 | 54 | 
       if FRoot[i].Ext = Ext then | 
 
 
 
 
 
 | 55 | 
       begin | 
 
 
 
 
 
 | 56 | 
         Result := FRoot[i]; | 
 
 
 
 
 
 | 57 | 
         Break; | 
 
 
 
 
 
 | 58 | 
       end; | 
 
 
 
 
 
 | 59 | 
 end; | 
 
 
 
 
 
 | 60 | 
  | 
 
 
 
 
 
 | 61 | 
 procedure TMetaManager.AddExt(Ext: String); | 
 
 
 
 
 
 | 62 | 
 var | 
 
 
 
 
 
 | 63 | 
   i: Integer; | 
 
 
 
 
 
 | 64 | 
 begin | 
 
 
 
 
 
 | 65 | 
   SetLength(FRoot, Length(FRoot) + 1); | 
 
 
 
 
 
 | 66 | 
   for i := High(FRoot) downto 1 do | 
 
 
 
 
 
 | 67 | 
   begin | 
 
 
 
 
 
 | 68 | 
     if FRoot[i-1].Ext < Ext then | 
 
 
 
 
 
 | 69 | 
     begin | 
 
 
 
 
 
 | 70 | 
       FRoot[i] := TExtension.Create(FConnectionID, Ext); | 
 
 
 
 
 
 | 71 | 
       Break; | 
 
 
 
 
 
 | 72 | 
     end | 
 
 
 
 
 
 | 73 | 
     else | 
 
 
 
 
 
 | 74 | 
       FRoot[i] := FRoot[i-1]; | 
 
 
 
 
 
 | 75 | 
   end; | 
 
 
 
 
 
 | 76 | 
   if i = 0 then | 
 
 
 
 
 
 | 77 | 
     FRoot[0] := TExtension.Create(FConnectionID, Ext); | 
 
 
 
 
 
 | 78 | 
 end; | 
 
 
 
 
 
 | 79 | 
  | 
 
 
 
 
 
 | 80 | 
 function TMetaManager.GetFileById(Id: Integer): TFile; | 
 
 
 
 
 
 | 81 | 
 begin | 
 
 
 
 
 
 | 82 | 
   Result := FFiles[Id]; | 
 
 
 
 
 
 | 83 | 
 end; | 
 
 
 
 
 
 | 84 | 
  | 
 
 
 
 
 
 | 85 | 
 function TMetaManager.GetFileCount: Integer; | 
 
 
 
 
 
 | 86 | 
 begin | 
 
 
 
 
 
 | 87 | 
   Result := Length(FFiles); | 
 
 
 
 
 
 | 88 | 
 end; | 
 
 
 
 
 
 | 89 | 
  | 
 
 
 
 
 
 | 90 | 
 procedure TMetaManager.InitFile(id: Integer); | 
 
 
 
 
 
 | 91 | 
 var | 
 
 
 
 
 
 | 92 | 
   typei: Integer; | 
 
 
 
 
 
 | 93 | 
   finfo: TFileInfo; | 
 
 
 
 
 
 | 94 | 
 begin | 
 
 
 
 
 
 | 95 | 
   if id < ConManager.Connection[FConnectionID].GetFileCount then | 
 
 
 
 
 
 | 96 | 
   begin | 
 
 
 
 
 
 | 97 | 
     if not Assigned(FFiles[id]) then | 
 
 
 
 
 
 | 98 | 
     begin | 
 
 
 
 
 
 | 99 | 
       finfo := ConManager.Connection[FConnectionID].GetFileInfo(id); | 
 
 
 
 
 
 | 100 | 
       if finfo.Size > 0 then | 
 
 
 
 
 
 | 101 | 
       begin | 
 
 
 
 
 
 | 102 | 
         for typei := 0 to High(FileDescs) do | 
 
 
 
 
 
 | 103 | 
         begin | 
 
 
 
 
 
 | 104 | 
           if FileDescs[typei].ext = finfo.Extension then | 
 
 
 
 
 
 | 105 | 
           begin | 
 
 
 
 
 
 | 106 | 
             FFiles[id] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, id); | 
 
 
 
 
 
 | 107 | 
             Break; | 
 
 
 
 
 
 | 108 | 
           end; | 
 
 
 
 
 
 | 109 | 
         end; | 
 
 
 
 
 
 | 110 | 
         if typei > High(FileDescs) then | 
 
 
 
 
 
 | 111 | 
           FFiles[id] := TFile_Empty.Create(FConnectionID, id); | 
 
 
 
 
 
 | 112 | 
       end else | 
 
 
 
 
 
 | 113 | 
         FFiles[id] := TFile_Empty.Create(FConnectionID, id); | 
 
 
 
 
 
 | 114 | 
       Exit; | 
 
 
 
 
 
 | 115 | 
     end; | 
 
 
 
 
 
 | 116 | 
   end; | 
 
 
 
 
 
 | 117 | 
 end; | 
 
 
 
 
 
 | 118 | 
  | 
 
 
 
 
 
 | 119 | 
 procedure TMetaManager.InitFileFields(id: Integer); | 
 
 
 
 
 
 | 120 | 
 begin | 
 
 
 
 
 
 | 121 | 
   if id < ConManager.Connection[FConnectionID].GetFileCount then | 
 
 
 
 
 
 | 122 | 
   begin | 
 
 
 
 
 
 | 123 | 
     if not Assigned(FFiles[id]) then | 
 
 
 
 
 
 | 124 | 
     begin | 
 
 
 
 
 
 | 125 | 
       InitFile(id); | 
 
 
 
 
 
 | 126 | 
       if not (FFiles[id] is TFile_Empty) then | 
 
 
 
 
 
 | 127 | 
         FFiles[id].InitDataFields; | 
 
 
 
 
 
 | 128 | 
     end; | 
 
 
 
 
 
 | 129 | 
   end; | 
 
 
 
 
 
 | 130 | 
 end; | 
 
 
 
 
 
 | 131 | 
  | 
 
 
 
 
 
 | 132 | 
 procedure TMetaManager.InitExtFiles(Ext: String); | 
 
 
 
 
 
 | 133 | 
 var | 
 
 
 
 
 
 | 134 | 
   files: TStrings; | 
 
 
 
 
 
 | 135 | 
   i: Integer; | 
 
 
 
 
 
 | 136 | 
   typei: Integer; | 
 
 
 
 
 
 | 137 | 
   fid: Integer; | 
 
 
 
 
 
 | 138 | 
   finfo: TFileInfo; | 
 
 
 
 
 
 | 139 | 
 begin | 
 
 
 
 
 
 | 140 | 
   if ConManager.Connection[FConnectionID] is TAccess_OniArchive then | 
 
 
 
 
 
 | 141 | 
     TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := False; | 
 
 
 
 
 
 | 142 | 
   files := TStringList.Create; | 
 
 
 
 
 
 | 143 | 
   files := ConManager.Connection[FConnectionID].GetFilesList('', '', False, ST_IDAsc); | 
 
 
 
 
 
 | 144 | 
   SetLength(FFiles, ConManager.Connection[FConnectionID].GetFileCount); | 
 
 
 
 
 
 | 145 | 
   for i := 0 to High(FFiles) do | 
 
 
 
 
 
 | 146 | 
     FFiles[i] := nil; | 
 
 
 
 
 
 | 147 | 
   if files.Count > 0 then | 
 
 
 
 
 
 | 148 | 
   begin | 
 
 
 
 
 
 | 149 | 
     for i := 0 to files.Count - 1 do | 
 
 
 
 
 
 | 150 | 
     begin | 
 
 
 
 
 
 | 151 | 
       fid := StrToInt(MidStr(files.Strings[i], 1, 5)); | 
 
 
 
 
 
 | 152 | 
       finfo := ConManager.Connection[FConnectionID].GetFileInfo(fid); | 
 
 
 
 
 
 | 153 | 
       if Length(finfo.Name) > 0 then | 
 
 
 
 
 
 | 154 | 
       begin | 
 
 
 
 
 
 | 155 | 
         if finfo.Size > 0 then | 
 
 
 
 
 
 | 156 | 
         begin | 
 
 
 
 
 
 | 157 | 
           for typei := 0 to High(FileDescs) do | 
 
 
 
 
 
 | 158 | 
           begin | 
 
 
 
 
 
 | 159 | 
             if FileDescs[typei].ext = finfo.Extension then | 
 
 
 
 
 
 | 160 | 
             begin | 
 
 
 
 
 
 | 161 | 
               FFiles[fid] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, fid); | 
 
 
 
 
 
 | 162 | 
               Break; | 
 
 
 
 
 
 | 163 | 
             end; | 
 
 
 
 
 
 | 164 | 
           end; | 
 
 
 
 
 
 | 165 | 
         end | 
 
 
 
 
 
 | 166 | 
         else | 
 
 
 
 
 
 | 167 | 
           FFiles[fid] := TFile_Empty.Create(FConnectionID, fid); | 
 
 
 
 
 
 | 168 | 
       end; | 
 
 
 
 
 
 | 169 | 
     end; | 
 
 
 
 
 
 | 170 | 
   end; | 
 
 
 
 
 
 | 171 | 
   files.Free; | 
 
 
 
 
 
 | 172 | 
   if ConManager.Connection[FConnectionID] is TAccess_OniArchive then | 
 
 
 
 
 
 | 173 | 
     TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := True; | 
 
 
 
 
 
 | 174 | 
 end; | 
 
 
 
 
 
 | 175 | 
  | 
 
 
 
 
 
 | 176 | 
 procedure TMetaManager.InitExts; | 
 
 
 
 
 
 | 177 | 
 var | 
 
 
 
 
 
 | 178 | 
   files: TStrings; | 
 
 
 
 
 
 | 179 | 
   i: Integer; | 
 
 
 
 
 
 | 180 | 
   fid: Integer; | 
 
 
 
 
 
 | 181 | 
   finfo: TFileInfo; | 
 
 
 
 
 
 | 182 | 
 begin | 
 
 
 
 
 
 | 183 | 
   files := TStringList.Create; | 
 
 
 
 
 
 | 184 | 
   files := TDataAccess(FDataAccess).GetFilesList('', '', False, ST_IDAsc); | 
 
 
 
 
 
 | 185 | 
   SetLength(FRoot, 0); | 
 
 
 
 
 
 | 186 | 
   if files.Count > 0 then | 
 
 
 
 
 
 | 187 | 
   begin | 
 
 
 
 
 
 | 188 | 
     for i := 0 to files.Count - 1 do | 
 
 
 
 
 
 | 189 | 
     begin | 
 
 
 
 
 
 | 190 | 
       fid := StrToInt(MidStr(files.Strings[i], 1, 5)); | 
 
 
 
 
 
 | 191 | 
       finfo := TDataAccess(FDataAccess).GetFileInfo(fid); | 
 
 
 
 
 
 | 192 | 
       if Length(finfo.Name) > 0 then | 
 
 
 
 
 
 | 193 | 
         if not Assigned(GetExt(finfo.Extension)) then | 
 
 
 
 
 
 | 194 | 
           AddExt(finfo.Extension); | 
 
 
 
 
 
 | 195 | 
     end; | 
 
 
 
 
 
 | 196 | 
   end; | 
 
 
 
 
 
 | 197 | 
   files.Free; | 
 
 
 
 
 
 | 198 | 
 end; | 
 
 
 
 
 
 | 199 | 
  | 
 
 
 
 
 
 | 200 | 
 end. |