[212] | 1 | unit _MetaManager;
|
---|
| 2 | interface
|
---|
| 3 |
|
---|
| 4 | uses _FileTypes, 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..1] of TFileDesc = (
|
---|
| 15 | (ext: 'TXAN'; ftype: TFile_TXAN),
|
---|
| 16 | (ext: 'TXMP'; ftype: TFile_TXMP)
|
---|
| 17 | );
|
---|
| 18 |
|
---|
| 19 | type
|
---|
| 20 | TMetaManager = class
|
---|
| 21 | protected
|
---|
| 22 | FFiles: array of TFile;
|
---|
| 23 | FConnectionID: Integer;
|
---|
| 24 | function GetFileCount: Integer;
|
---|
| 25 | function GetFileById(Id: Integer): TFile;
|
---|
| 26 | private
|
---|
| 27 | procedure InitRootFiles;
|
---|
| 28 | public
|
---|
| 29 | constructor Create(ConnectionID: Integer);
|
---|
| 30 | procedure InitFile(id: Integer);
|
---|
| 31 |
|
---|
| 32 | property FileCount: Integer read GetFileCount;
|
---|
| 33 | property FileById[Id: Integer]: TFile read GetFileById;
|
---|
| 34 | end;
|
---|
| 35 |
|
---|
| 36 | implementation
|
---|
| 37 |
|
---|
| 38 | uses
|
---|
| 39 | Classes, ConnectionManager, Access_OniArchive, TypeDefs, Dialogs, SysUtils, StrUtils;
|
---|
| 40 |
|
---|
| 41 | { TFileManager }
|
---|
| 42 |
|
---|
| 43 | constructor TMetaManager.Create(ConnectionID: Integer);
|
---|
| 44 | begin
|
---|
| 45 | FConnectionID := ConnectionID;
|
---|
| 46 | InitRootFiles;
|
---|
| 47 | end;
|
---|
| 48 |
|
---|
| 49 | function TMetaManager.GetFileById(Id: Integer): TFile;
|
---|
| 50 | begin
|
---|
| 51 | Result := FFiles[Id];
|
---|
| 52 | end;
|
---|
| 53 |
|
---|
| 54 | function TMetaManager.GetFileCount: Integer;
|
---|
| 55 | begin
|
---|
| 56 | Result := Length(FFiles);
|
---|
| 57 | end;
|
---|
| 58 |
|
---|
| 59 | procedure TMetaManager.InitFile(id: Integer);
|
---|
| 60 | var
|
---|
| 61 | // i: Integer;
|
---|
| 62 | typei: Integer;
|
---|
| 63 | finfo: TFileInfo;
|
---|
| 64 | begin
|
---|
| 65 | if id < ConManager.Connection[FConnectionID].GetFileCount then
|
---|
| 66 | begin
|
---|
| 67 | if not Assigned(FFiles[id]) then
|
---|
| 68 | begin
|
---|
| 69 | finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
|
---|
| 70 | if finfo.Size > 0 then
|
---|
| 71 | begin
|
---|
| 72 | for typei := 0 to High(FileDescs) do
|
---|
| 73 | begin
|
---|
| 74 | if FileDescs[typei].ext = finfo.Extension then
|
---|
| 75 | begin
|
---|
| 76 | FFiles[id] := TFileType(FileDescs[typei].ftype).Create(FConnectionID, id);
|
---|
| 77 | Break;
|
---|
| 78 | end;
|
---|
| 79 | end;
|
---|
| 80 | if typei > High(FileDescs) then
|
---|
| 81 | FFiles[id] := TFile_Empty.Create(FConnectionID, id);
|
---|
| 82 | end else
|
---|
| 83 | FFiles[id] := TFile_Empty.Create(FConnectionID, id);
|
---|
| 84 | Exit;
|
---|
| 85 | end;
|
---|
| 86 | end;
|
---|
| 87 | end;
|
---|
| 88 |
|
---|
| 89 | procedure TMetaManager.InitRootFiles;
|
---|
| 90 | var
|
---|
| 91 | files: TStrings;
|
---|
| 92 | i: Integer;
|
---|
| 93 | typei: Integer;
|
---|
| 94 | fid: Integer;
|
---|
| 95 | finfo: TFileInfo;
|
---|
| 96 | begin
|
---|
| 97 | if ConManager.Connection[FConnectionID] is TAccess_OniArchive then
|
---|
| 98 | TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := False;
|
---|
| 99 | files := TStringList.Create;
|
---|
| 100 | files := ConManager.Connection[FConnectionID].GetFilesList('', '', False, ST_IDAsc);
|
---|
| 101 | SetLength(FFiles, ConManager.Connection[FConnectionID].GetFileCount);
|
---|
| 102 | for i := 0 to High(FFiles) do
|
---|
| 103 | FFiles[i] := nil;
|
---|
| 104 | if files.Count > 0 then
|
---|
| 105 | begin
|
---|
| 106 | for i := 0 to files.Count - 1 do
|
---|
| 107 | begin
|
---|
| 108 | fid := StrToInt(MidStr(files.Strings[i], 1, 5));
|
---|
| 109 | finfo := ConManager.Connection[FConnectionID].GetFileInfo(fid);
|
---|
| 110 | if Length(finfo.Name) > 0 then
|
---|
| 111 | begin
|
---|
| 112 | if finfo.Size > 0 then
|
---|
| 113 | begin
|
---|
| 114 | for typei := 0 to High(FileDescs) do
|
---|
| 115 | begin
|
---|
| 116 | if FileDescs[typei].ext = finfo.Extension then
|
---|
| 117 | begin
|
---|
| 118 | FFiles[fid] := TFileType(FileDescs[typei].ftype).Create(FConnectionID, fid);
|
---|
| 119 | Break;
|
---|
| 120 | end;
|
---|
| 121 | end;
|
---|
| 122 | end
|
---|
| 123 | else
|
---|
| 124 | FFiles[fid] := TFile_Empty.Create(FConnectionID, fid);
|
---|
| 125 | end;
|
---|
| 126 | end;
|
---|
| 127 | end;
|
---|
| 128 | files.Free;
|
---|
| 129 | if ConManager.Connection[FConnectionID] is TAccess_OniArchive then
|
---|
| 130 | TAccess_OniArchive(ConManager.Connection[FConnectionID]).UnloadWhenUnused := True;
|
---|
| 131 | end;
|
---|
| 132 |
|
---|
| 133 | end.
|
---|