| 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 |
< |
); |
| 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 |
|
private |
| 28 |
– |
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; |
| 24 |
|
end; |
| 25 |
|
|
| 38 |
– |
var |
| 39 |
– |
Meta: TMetaManager; |
| 40 |
– |
|
| 26 |
|
implementation |
| 27 |
|
|
| 28 |
|
uses |
| 29 |
< |
Classes, ConnectionManager, Access_OniArchive, TypeDefs, Dialogs, SysUtils, StrUtils; |
| 29 |
> |
Classes, ConnectionManager, Access_OniArchive, TypeDefs, |
| 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 |
+ |
|
| 43 |
|
function TMetaManager.GetFileById(Id: Integer): TFile; |
| 44 |
|
begin |
| 45 |
+ |
InitFile(Id); |
| 46 |
|
Result := FFiles[Id]; |
| 47 |
|
end; |
| 48 |
|
|
| 67 |
|
begin |
| 68 |
|
if FileDescs[typei].ext = finfo.Extension then |
| 69 |
|
begin |
| 70 |
< |
FFiles[id] := TFileType(FileDescs[typei].ftype).Create(FConnectionID, id); |
| 70 |
> |
FFiles[id] := TFileClass(FileDescs[typei].ftype).Create(FConnectionID, id); |
| 71 |
|
Break; |
| 72 |
|
end; |
| 73 |
|
end; |
| 93 |
|
end; |
| 94 |
|
end; |
| 95 |
|
|
| 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 |
– |
|
| 96 |
|
end. |