Changeset 233 for oup/current/FileClasses/_MetaManager.pas
- Timestamp:
- Jun 29, 2007, 2:38:24 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/FileClasses/_MetaManager.pas
r229 r233 13 13 function GetFileCount: Integer; 14 14 function GetFileById(Id: Integer): TFile; 15 function GetExt(Ext: String): TExtension;16 procedure AddExt(Ext: String);17 15 private 18 procedure InitExts;19 16 public 20 17 constructor Create(ConnectionID: Integer; DataAccess: TObject); 21 procedure InitExtFiles(Ext: String);22 18 procedure InitFile(id: Integer); 23 19 procedure InitFileFields(id: Integer); 24 20 25 21 property Root: TExtensions read FRoot; 26 property RootExt[Ext: String]: TExtension read GetExt;27 22 property FileCount: Integer read GetFileCount; 28 23 property FileById[Id: Integer]: TFile read GetFileById; … … 33 28 uses 34 29 Classes, ConnectionManager, Access_OniArchive, TypeDefs, 35 Dialogs, SysUtils, StrUtils, DataAccess ;30 Dialogs, SysUtils, StrUtils, DataAccess, _Extensions; 36 31 37 32 { TFileManager } … … 42 37 FDataAccess := DataAccess; 43 38 SetLength(FFiles, TDataAccess(DataAccess).GetFileCount); 44 InitExts;39 FRoot := TExtensions.Create(DataAccess, ConnectionID); 45 40 end; 46 41 47 function TMetaManager.GetExt(Ext: String): TExtension;48 var49 i: Integer;50 begin51 Result := nil;52 if Length(FRoot) > 0 then53 for i := 0 to High(FRoot) do54 if FRoot[i].Ext = Ext then55 begin56 Result := FRoot[i];57 Break;58 end;59 end;60 61 procedure TMetaManager.AddExt(Ext: String);62 var63 i: Integer;64 begin65 SetLength(FRoot, Length(FRoot) + 1);66 for i := High(FRoot) downto 1 do67 begin68 if FRoot[i-1].Ext < Ext then69 begin70 FRoot[i] := TExtension.Create(FConnectionID, Ext);71 Break;72 end73 else74 FRoot[i] := FRoot[i-1];75 end;76 if i = 0 then77 FRoot[0] := TExtension.Create(FConnectionID, Ext);78 end;79 42 80 43 function TMetaManager.GetFileById(Id: Integer): TFile; 81 44 begin 45 InitFile(Id); 82 46 Result := FFiles[Id]; 83 47 end; … … 130 94 end; 131 95 132 procedure TMetaManager.InitExtFiles(Ext: String);133 var134 files: TStrings;135 i: Integer;136 typei: Integer;137 fid: Integer;138 finfo: TFileInfo;139 begin140 if ConManager.Connection[FConnectionID] is TAccess_OniArchive then141 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) do146 FFiles[i] := nil;147 if files.Count > 0 then148 begin149 for i := 0 to files.Count - 1 do150 begin151 fid := StrToInt(MidStr(files.Strings[i], 1, 5));152 finfo := ConManager.Connection[FConnectionID].GetFileInfo(fid);153 if Length(finfo.Name) > 0 then154 begin155 if finfo.Size > 0 then156 begin157 for typei := 0 to High(FileDescs) do158 begin159 if FileDescs[typei].ext = finfo.Extension then160 begin161 FFiles[fid] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, fid);162 Break;163 end;164 end;165 end166 else167 FFiles[fid] := TFile_Empty.Create(FConnectionID, fid);168 end;169 end;170 end;171 files.Free;172 if ConManager.Connection[FConnectionID] is TAccess_OniArchive then173 TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := True;174 end;175 176 procedure TMetaManager.InitExts;177 var178 files: TStrings;179 i: Integer;180 fid: Integer;181 finfo: TFileInfo;182 begin183 files := TStringList.Create;184 files := TDataAccess(FDataAccess).GetFilesList('', '', False, ST_IDAsc);185 SetLength(FRoot, 0);186 if files.Count > 0 then187 begin188 for i := 0 to files.Count - 1 do189 begin190 fid := StrToInt(MidStr(files.Strings[i], 1, 5));191 finfo := TDataAccess(FDataAccess).GetFileInfo(fid);192 if Length(finfo.Name) > 0 then193 if not Assigned(GetExt(finfo.Extension)) then194 AddExt(finfo.Extension);195 end;196 end;197 files.Free;198 end;199 200 96 end.
Note:
See TracChangeset
for help on using the changeset viewer.