1 | unit _Extensions;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | _FileTypes, _TreeElement;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TExtension = class(TTreeElement)
|
---|
10 | protected
|
---|
11 | function GetChildCount: Integer; override;
|
---|
12 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
13 | function GetCaption: String; override;
|
---|
14 | function GetType: String; override;
|
---|
15 | private
|
---|
16 | FExt: String;
|
---|
17 | FFiles: array of Integer;
|
---|
18 | public
|
---|
19 | constructor Create(ConnectionID: Integer; Ext: String); virtual;
|
---|
20 | procedure InitList;
|
---|
21 | property Ext: String read FExt;
|
---|
22 | end;
|
---|
23 |
|
---|
24 | TExtensions = class(TTreeElement)
|
---|
25 | function GetChildCount: Integer; override;
|
---|
26 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
27 | function GetCaption: String; override;
|
---|
28 | function GetType: String; override;
|
---|
29 | private
|
---|
30 | FExtensions: array of TExtension;
|
---|
31 | public
|
---|
32 | constructor Create(DataAccess: TObject; ConnectionID: Integer);
|
---|
33 | function GetExt(Ext: String): TExtension;
|
---|
34 | procedure AddExt(Ext: String);
|
---|
35 | end;
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 | implementation
|
---|
40 |
|
---|
41 | uses
|
---|
42 | Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs, DataAccess, _MetaManager;
|
---|
43 |
|
---|
44 | { TExtension }
|
---|
45 |
|
---|
46 | constructor TExtension.Create(ConnectionID: Integer; Ext: String);
|
---|
47 | begin
|
---|
48 | FConnectionID := ConnectionID;
|
---|
49 | FExt := Ext;
|
---|
50 | end;
|
---|
51 |
|
---|
52 | function TExtension.GetCaption: String;
|
---|
53 | begin
|
---|
54 | Result := FExt + '[' + IntToStr(GetChildCount) + ']';
|
---|
55 | end;
|
---|
56 |
|
---|
57 | function TExtension.GetChild(ID: Integer): TTreeElement;
|
---|
58 | var
|
---|
59 | Meta: TMetaManager;
|
---|
60 | begin
|
---|
61 | Meta := ConManager.Connection[FConnectionID].MetaData;
|
---|
62 | Meta.InitFile(FFiles[ID]);
|
---|
63 | Result := Meta.FileById[FFiles[ID]];
|
---|
64 | end;
|
---|
65 |
|
---|
66 | function TExtension.GetChildCount: Integer;
|
---|
67 | begin
|
---|
68 | Result := Length(FFiles);
|
---|
69 | end;
|
---|
70 |
|
---|
71 | function TExtension.GetType: String;
|
---|
72 | begin
|
---|
73 | Result := '';
|
---|
74 | end;
|
---|
75 |
|
---|
76 | procedure TExtension.InitList;
|
---|
77 | var
|
---|
78 | files: TStrings;
|
---|
79 | i: Integer;
|
---|
80 | fid: Integer;
|
---|
81 | finfo: TFileInfo;
|
---|
82 | begin
|
---|
83 | files := TStringList.Create;
|
---|
84 | files := ConManager.Connection[FConnectionID].GetFilesList(FExt, '', False, ST_NameAsc);
|
---|
85 | if files.Count > 0 then
|
---|
86 | begin
|
---|
87 | for i := 0 to files.Count - 1 do
|
---|
88 | begin
|
---|
89 | fid := StrToInt(MidStr(files.Strings[i], 1, 5));
|
---|
90 | finfo := ConManager.Connection[FConnectionID].GetFileInfo(fid);
|
---|
91 | if Length(finfo.Name) > 0 then
|
---|
92 | begin
|
---|
93 | SetLength(FFiles, Length(FFiles) + 1);
|
---|
94 | FFiles[High(FFiles)] := fid;
|
---|
95 | end;
|
---|
96 | end;
|
---|
97 | end;
|
---|
98 | files.Free;
|
---|
99 | end;
|
---|
100 |
|
---|
101 |
|
---|
102 | { TExtensions }
|
---|
103 |
|
---|
104 | function TExtensions.GetCaption: String;
|
---|
105 | begin
|
---|
106 | Result := 'Extensions';
|
---|
107 | end;
|
---|
108 |
|
---|
109 | function TExtensions.GetChild(ID: Integer): TTreeElement;
|
---|
110 | begin
|
---|
111 | FExtensions[ID].InitList;
|
---|
112 | Result := FExtensions[ID];
|
---|
113 | end;
|
---|
114 |
|
---|
115 | function TExtensions.GetChildCount: Integer;
|
---|
116 | begin
|
---|
117 | Result := Length(FExtensions);
|
---|
118 | end;
|
---|
119 |
|
---|
120 | constructor TExtensions.Create(DataAccess: TObject; ConnectionID: Integer);
|
---|
121 | var
|
---|
122 | files: TStrings;
|
---|
123 | i: Integer;
|
---|
124 | fid: Integer;
|
---|
125 | finfo: TFileInfo;
|
---|
126 | begin
|
---|
127 | FConnectionID := ConnectionID;
|
---|
128 | files := TStringList.Create;
|
---|
129 | files := TDataAccess(DataAccess).GetFilesList('', '', False, ST_IDAsc);
|
---|
130 | SetLength(FExtensions, 0);
|
---|
131 | if files.Count > 0 then
|
---|
132 | begin
|
---|
133 | for i := 0 to files.Count - 1 do
|
---|
134 | begin
|
---|
135 | fid := StrToInt(MidStr(files.Strings[i], 1, 5));
|
---|
136 | finfo := TDataAccess(DataAccess).GetFileInfo(fid);
|
---|
137 | if Length(finfo.Name) > 0 then
|
---|
138 | if not Assigned(GetExt(finfo.Extension)) then
|
---|
139 | AddExt(finfo.Extension);
|
---|
140 | end;
|
---|
141 | end;
|
---|
142 | files.Free;
|
---|
143 | end;
|
---|
144 |
|
---|
145 |
|
---|
146 | function TExtensions.GetExt(Ext: String): TExtension;
|
---|
147 | var
|
---|
148 | i: Integer;
|
---|
149 | begin
|
---|
150 | Result := nil;
|
---|
151 | if Length(FExtensions) > 0 then
|
---|
152 | for i := 0 to High(FExtensions) do
|
---|
153 | if FExtensions[i].Ext = Ext then
|
---|
154 | begin
|
---|
155 | Result := FExtensions[i];
|
---|
156 | Break;
|
---|
157 | end;
|
---|
158 | end;
|
---|
159 |
|
---|
160 | function TExtensions.GetType: String;
|
---|
161 | begin
|
---|
162 | Result := '';
|
---|
163 | end;
|
---|
164 |
|
---|
165 | procedure TExtensions.AddExt(Ext: String);
|
---|
166 | var
|
---|
167 | i: Integer;
|
---|
168 | begin
|
---|
169 | SetLength(FExtensions, Length(FExtensions) + 1);
|
---|
170 | for i := High(FExtensions) downto 1 do
|
---|
171 | begin
|
---|
172 | if FExtensions[i-1].GetCaption < Ext then
|
---|
173 | begin
|
---|
174 | FExtensions[i] := TExtension.Create(FConnectionID, Ext);
|
---|
175 | Break;
|
---|
176 | end
|
---|
177 | else
|
---|
178 | FExtensions[i] := FExtensions[i-1];
|
---|
179 | end;
|
---|
180 | if i = 0 then
|
---|
181 | FExtensions[0] := TExtension.Create(FConnectionID, Ext);
|
---|
182 | end;
|
---|
183 |
|
---|
184 |
|
---|
185 |
|
---|
186 | end.
|
---|