--- oup/current/FileClasses/_MetaManager.pas 2007/06/20 09:51:38 228 +++ oup/current/FileClasses/_MetaManager.pas 2007/06/20 10:57:51 229 @@ -7,36 +7,74 @@ type TMetaManager = class protected FFiles: array of TFile; - FRoot: array of TExtension; + FRoot: TExtensions; FConnectionID: Integer; + FDataAccess: TObject; function GetFileCount: Integer; function GetFileById(Id: Integer): TFile; + function GetExt(Ext: String): TExtension; + procedure AddExt(Ext: String); private - procedure InitRootFiles; + procedure InitExts; public - constructor Create(ConnectionID: Integer); + constructor Create(ConnectionID: Integer; DataAccess: TObject); + procedure InitExtFiles(Ext: String); procedure InitFile(id: Integer); procedure InitFileFields(id: Integer); + property Root: TExtensions read FRoot; + property RootExt[Ext: String]: TExtension read GetExt; property FileCount: Integer read GetFileCount; property FileById[Id: Integer]: TFile read GetFileById; end; -var - Meta: TMetaManager; - implementation uses Classes, ConnectionManager, Access_OniArchive, TypeDefs, - Dialogs, SysUtils, StrUtils; + Dialogs, SysUtils, StrUtils, DataAccess; { TFileManager } -constructor TMetaManager.Create(ConnectionID: Integer); +constructor TMetaManager.Create(ConnectionID: Integer; DataAccess: TObject); begin FConnectionID := ConnectionID; - InitRootFiles; + FDataAccess := DataAccess; + SetLength(FFiles, TDataAccess(DataAccess).GetFileCount); + InitExts; +end; + +function TMetaManager.GetExt(Ext: String): TExtension; +var + i: Integer; +begin + Result := nil; + if Length(FRoot) > 0 then + for i := 0 to High(FRoot) do + if FRoot[i].Ext = Ext then + begin + Result := FRoot[i]; + Break; + end; +end; + +procedure TMetaManager.AddExt(Ext: String); +var + i: Integer; +begin + SetLength(FRoot, Length(FRoot) + 1); + for i := High(FRoot) downto 1 do + begin + if FRoot[i-1].Ext < Ext then + begin + FRoot[i] := TExtension.Create(FConnectionID, Ext); + Break; + end + else + FRoot[i] := FRoot[i-1]; + end; + if i = 0 then + FRoot[0] := TExtension.Create(FConnectionID, Ext); end; function TMetaManager.GetFileById(Id: Integer): TFile; @@ -91,7 +129,7 @@ begin end; end; -procedure TMetaManager.InitRootFiles; +procedure TMetaManager.InitExtFiles(Ext: String); var files: TStrings; i: Integer; @@ -135,4 +173,28 @@ begin TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := True; end; +procedure TMetaManager.InitExts; +var + files: TStrings; + i: Integer; + fid: Integer; + finfo: TFileInfo; +begin + files := TStringList.Create; + files := TDataAccess(FDataAccess).GetFilesList('', '', False, ST_IDAsc); + SetLength(FRoot, 0); + if files.Count > 0 then + begin + for i := 0 to files.Count - 1 do + begin + fid := StrToInt(MidStr(files.Strings[i], 1, 5)); + finfo := TDataAccess(FDataAccess).GetFileInfo(fid); + if Length(finfo.Name) > 0 then + if not Assigned(GetExt(finfo.Extension)) then + AddExt(finfo.Extension); + end; + end; + files.Free; +end; + end.