source: oup/current/FileClasses/_FileManager.pas@ 211

Last change on this file since 211 was 209, checked in by alloc, 17 years ago
File size: 2.1 KB
RevLine 
[209]1unit _FileManager;
2interface
3
4uses _FileTypes, TXMP;
5
6type
7 TFileType = class of TFile;
8 TFileDesc = record
9 ext: String;
10 ftype: TFileType;
11 end;
12
13const
14 FileDescs: array[0..0] of TFileDesc = (
15 (ext: 'TXMP'; ftype: TFile_TXMP)
16 );
17
18type
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
32implementation
33
34uses
35 Classes, ConnectionManager, Access_OniArchive, TypeDefs, Dialogs, SysUtils, StrUtils;
36
37{ TFileManager }
38
39constructor TFileManager.Create(ConnectionID: Integer);
40var
41 files: TStrings;
42 i: Integer;
43 typei: Integer;
44 fid: Integer;
45begin
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;
69end;
70
71function TFileManager.GetFileById(Id: Integer): TFile;
72begin
73 Result := FFiles[Id];
74end;
75
76function TFileManager.GetFileCount: Integer;
77begin
78 Result := Length(FFiles);
79end;
80
81end.
Note: See TracBrowser for help on using the repository browser.