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