| 6 |
|
type |
| 7 |
|
TMetaManager = class |
| 8 |
|
protected |
| 9 |
< |
FFiles: array of TFile; |
| 10 |
< |
FRoot: array of TExtension; |
| 9 |
> |
FFiles: array of TResource; |
| 10 |
> |
FRoot: TExtensions; |
| 11 |
|
FConnectionID: Integer; |
| 12 |
+ |
FDataAccess: TObject; |
| 13 |
|
function GetFileCount: Integer; |
| 14 |
< |
function GetFileById(Id: Integer): TFile; |
| 14 |
> |
function GetFileById(Id: Integer): TResource; |
| 15 |
|
private |
| 15 |
– |
procedure InitRootFiles; |
| 16 |
|
public |
| 17 |
< |
constructor Create(ConnectionID: Integer); |
| 17 |
> |
constructor Create(ConnectionID: Integer; DataAccess: TObject); |
| 18 |
|
procedure InitFile(id: Integer); |
| 19 |
|
procedure InitFileFields(id: Integer); |
| 20 |
|
|
| 21 |
+ |
property Root: TExtensions read FRoot; |
| 22 |
|
property FileCount: Integer read GetFileCount; |
| 23 |
< |
property FileById[Id: Integer]: TFile read GetFileById; |
| 23 |
> |
property FileById[Id: Integer]: TResource read GetFileById; |
| 24 |
|
end; |
| 25 |
|
|
| 25 |
– |
var |
| 26 |
– |
Meta: TMetaManager; |
| 27 |
– |
|
| 26 |
|
implementation |
| 27 |
|
|
| 28 |
|
uses |
| 29 |
|
Classes, ConnectionManager, Access_OniArchive, TypeDefs, |
| 30 |
< |
Dialogs, SysUtils, StrUtils; |
| 30 |
> |
Dialogs, SysUtils, StrUtils, DataAccess, _Extensions; |
| 31 |
|
|
| 32 |
|
{ TFileManager } |
| 33 |
|
|
| 34 |
< |
constructor TMetaManager.Create(ConnectionID: Integer); |
| 34 |
> |
constructor TMetaManager.Create(ConnectionID: Integer; DataAccess: TObject); |
| 35 |
|
begin |
| 36 |
|
FConnectionID := ConnectionID; |
| 37 |
< |
InitRootFiles; |
| 37 |
> |
FDataAccess := DataAccess; |
| 38 |
> |
SetLength(FFiles, TDataAccess(DataAccess).GetFileCount); |
| 39 |
> |
FRoot := TExtensions.Create(DataAccess, ConnectionID); |
| 40 |
|
end; |
| 41 |
|
|
| 42 |
< |
function TMetaManager.GetFileById(Id: Integer): TFile; |
| 42 |
> |
|
| 43 |
> |
function TMetaManager.GetFileById(Id: Integer): TResource; |
| 44 |
|
begin |
| 45 |
+ |
InitFile(Id); |
| 46 |
|
Result := FFiles[Id]; |
| 47 |
|
end; |
| 48 |
|
|
| 63 |
|
finfo := ConManager.Connection[FConnectionID].GetFileInfo(id); |
| 64 |
|
if finfo.Size > 0 then |
| 65 |
|
begin |
| 66 |
< |
for typei := 0 to High(FileDescs) do |
| 66 |
> |
for typei := 0 to High(ResourceDescs) do |
| 67 |
|
begin |
| 68 |
< |
if FileDescs[typei].ext = finfo.Extension then |
| 68 |
> |
if ResourceDescs[typei].ext = finfo.Extension then |
| 69 |
|
begin |
| 70 |
< |
FFiles[id] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, id); |
| 70 |
> |
FFiles[id] := TResourceClass(ResourceDescs[typei].ftype).Create(FConnectionID, id); |
| 71 |
|
Break; |
| 72 |
|
end; |
| 73 |
|
end; |
| 74 |
< |
if typei > High(FileDescs) then |
| 74 |
> |
if typei > High(ResourceDescs) then |
| 75 |
|
FFiles[id] := TFile_Empty.Create(FConnectionID, id); |
| 76 |
|
end else |
| 77 |
|
FFiles[id] := TFile_Empty.Create(FConnectionID, id); |
| 93 |
|
end; |
| 94 |
|
end; |
| 95 |
|
|
| 94 |
– |
procedure TMetaManager.InitRootFiles; |
| 95 |
– |
var |
| 96 |
– |
files: TStrings; |
| 97 |
– |
i: Integer; |
| 98 |
– |
typei: Integer; |
| 99 |
– |
fid: Integer; |
| 100 |
– |
finfo: TFileInfo; |
| 101 |
– |
begin |
| 102 |
– |
if ConManager.Connection[FConnectionID] is TAccess_OniArchive then |
| 103 |
– |
TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := False; |
| 104 |
– |
files := TStringList.Create; |
| 105 |
– |
files := ConManager.Connection[FConnectionID].GetFilesList('', '', False, ST_IDAsc); |
| 106 |
– |
SetLength(FFiles, ConManager.Connection[FConnectionID].GetFileCount); |
| 107 |
– |
for i := 0 to High(FFiles) do |
| 108 |
– |
FFiles[i] := nil; |
| 109 |
– |
if files.Count > 0 then |
| 110 |
– |
begin |
| 111 |
– |
for i := 0 to files.Count - 1 do |
| 112 |
– |
begin |
| 113 |
– |
fid := StrToInt(MidStr(files.Strings[i], 1, 5)); |
| 114 |
– |
finfo := ConManager.Connection[FConnectionID].GetFileInfo(fid); |
| 115 |
– |
if Length(finfo.Name) > 0 then |
| 116 |
– |
begin |
| 117 |
– |
if finfo.Size > 0 then |
| 118 |
– |
begin |
| 119 |
– |
for typei := 0 to High(FileDescs) do |
| 120 |
– |
begin |
| 121 |
– |
if FileDescs[typei].ext = finfo.Extension then |
| 122 |
– |
begin |
| 123 |
– |
FFiles[fid] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, fid); |
| 124 |
– |
Break; |
| 125 |
– |
end; |
| 126 |
– |
end; |
| 127 |
– |
end |
| 128 |
– |
else |
| 129 |
– |
FFiles[fid] := TFile_Empty.Create(FConnectionID, fid); |
| 130 |
– |
end; |
| 131 |
– |
end; |
| 132 |
– |
end; |
| 133 |
– |
files.Free; |
| 134 |
– |
if ConManager.Connection[FConnectionID] is TAccess_OniArchive then |
| 135 |
– |
TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := True; |
| 136 |
– |
end; |
| 137 |
– |
|
| 96 |
|
end. |