[209] | 1 | unit _FileManager;
|
---|
| 2 | interface
|
---|
| 3 |
|
---|
| 4 | uses _FileTypes, TXMP;
|
---|
| 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..0] of TFileDesc = (
|
---|
| 15 | (ext: 'TXMP'; ftype: TFile_TXMP)
|
---|
| 16 | );
|
---|
| 17 |
|
---|
| 18 | type
|
---|
| 19 | TFileManager = class
|
---|
| 20 | protected
|
---|
| 21 | FFiles: array of TFile;
|
---|
| 22 | FConnectionID: Integer;
|
---|
| 23 | function GetFileCount: Integer;
|
---|
| 24 | function GetFileById(Id: Integer): TFile;
|
---|
| 25 | public
|
---|
| 26 | constructor Create(ConnectionID: Integer);
|
---|
| 27 |
|
---|
| 28 | property FileCount: Integer read GetFileCount;
|
---|
| 29 | property FileById[Id: Integer]: TFile read GetFileById;
|
---|
| 30 | end;
|
---|
| 31 |
|
---|
| 32 | implementation
|
---|
| 33 |
|
---|
| 34 | uses
|
---|
| 35 | Classes, ConnectionManager, Access_OniArchive, TypeDefs, Dialogs, SysUtils, StrUtils;
|
---|
| 36 |
|
---|
| 37 | { TFileManager }
|
---|
| 38 |
|
---|
| 39 | constructor TFileManager.Create(ConnectionID: Integer);
|
---|
| 40 | var
|
---|
| 41 | files: TStrings;
|
---|
| 42 | i: Integer;
|
---|
| 43 | typei: Integer;
|
---|
| 44 | fid: Integer;
|
---|
| 45 | begin
|
---|
| 46 | FConnectionID := ConnectionID;
|
---|
| 47 | if ConManager.Connection[ConnectionID] is TAccess_OniArchive then
|
---|
| 48 | TAccess_OniArchive(ConManager.Connection[ConnectionID]).UnloadWhenUnused := False;
|
---|
| 49 | files := TStringList.Create;
|
---|
| 50 | files := ConManager.Connection[ConnectionID].GetFilesList('', '', False, ST_IDAsc);
|
---|
| 51 | if files.Count > 0 then
|
---|
| 52 | begin
|
---|
| 53 | for i := 0 to files.Count - 1 do
|
---|
| 54 | begin
|
---|
| 55 | for typei := 0 to High(FileDescs) do
|
---|
| 56 | begin
|
---|
| 57 | if Pos('.' + FileDescs[typei].ext, files.Strings[i]) = Length(files.Strings[i]) - 4 then
|
---|
| 58 | begin
|
---|
| 59 | SetLength(FFiles, Length(FFiles) + 1);
|
---|
| 60 | fid := StrToInt(MidStr(files.Strings[i], 1, 5));
|
---|
| 61 | FFiles[High(FFiles)] := TFileType(FileDescs[typei].ftype).Create(FConnectionID, fid);
|
---|
| 62 | end;
|
---|
| 63 | end;
|
---|
| 64 | end;
|
---|
| 65 | end;
|
---|
| 66 | files.Free;
|
---|
| 67 | if ConManager.Connection[ConnectionID] is TAccess_OniArchive then
|
---|
| 68 | TAccess_OniArchive(ConManager.Connection[ConnectionID]).UnloadWhenUnused := True;
|
---|
| 69 | end;
|
---|
| 70 |
|
---|
| 71 | function TFileManager.GetFileById(Id: Integer): TFile;
|
---|
| 72 | begin
|
---|
| 73 | Result := FFiles[Id];
|
---|
| 74 | end;
|
---|
| 75 |
|
---|
| 76 | function TFileManager.GetFileCount: Integer;
|
---|
| 77 | begin
|
---|
| 78 | Result := Length(FFiles);
|
---|
| 79 | end;
|
---|
| 80 |
|
---|
| 81 | end.
|
---|