[228] | 1 | unit _Extensions;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
[231] | 5 | uses
|
---|
[233] | 6 | _FileTypes, _TreeElement;
|
---|
[231] | 7 |
|
---|
[228] | 8 | type
|
---|
[233] | 9 | TExtension = class(TTreeElement)
|
---|
[241] | 10 | protected
|
---|
[233] | 11 | function GetChildCount: Integer; override;
|
---|
| 12 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
| 13 | function GetCaption: String; override;
|
---|
[241] | 14 | function GetType: String; override;
|
---|
[228] | 15 | private
|
---|
[229] | 16 | FExt: String;
|
---|
[228] | 17 | FFiles: array of Integer;
|
---|
| 18 | public
|
---|
| 19 | constructor Create(ConnectionID: Integer; Ext: String); virtual;
|
---|
| 20 | procedure InitList;
|
---|
[237] | 21 | property Ext: String read FExt;
|
---|
[228] | 22 | end;
|
---|
| 23 |
|
---|
[233] | 24 | TExtensions = class(TTreeElement)
|
---|
| 25 | function GetChildCount: Integer; override;
|
---|
| 26 | function GetChild(ID: Integer): TTreeElement; override;
|
---|
| 27 | function GetCaption: String; override;
|
---|
[244] | 28 | function GetType: String; override;
|
---|
[233] | 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;
|
---|
[228] | 36 |
|
---|
[229] | 37 |
|
---|
[233] | 38 |
|
---|
[228] | 39 | implementation
|
---|
| 40 |
|
---|
| 41 | uses
|
---|
[233] | 42 | Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs, DataAccess, _MetaManager;
|
---|
[228] | 43 |
|
---|
| 44 | { TExtension }
|
---|
| 45 |
|
---|
| 46 | constructor TExtension.Create(ConnectionID: Integer; Ext: String);
|
---|
[229] | 47 | begin
|
---|
| 48 | FConnectionID := ConnectionID;
|
---|
| 49 | FExt := Ext;
|
---|
| 50 | end;
|
---|
| 51 |
|
---|
[233] | 52 | function TExtension.GetCaption: String;
|
---|
[229] | 53 | begin
|
---|
[237] | 54 | Result := FExt + '[' + IntToStr(GetChildCount) + ']';
|
---|
[229] | 55 | end;
|
---|
| 56 |
|
---|
[233] | 57 | function TExtension.GetChild(ID: Integer): TTreeElement;
|
---|
| 58 | var
|
---|
| 59 | Meta: TMetaManager;
|
---|
[229] | 60 | begin
|
---|
[233] | 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
|
---|
[229] | 68 | Result := Length(FFiles);
|
---|
| 69 | end;
|
---|
| 70 |
|
---|
[241] | 71 | function TExtension.GetType: String;
|
---|
| 72 | begin
|
---|
| 73 | Result := '';
|
---|
| 74 | end;
|
---|
| 75 |
|
---|
[229] | 76 | procedure TExtension.InitList;
|
---|
[228] | 77 | var
|
---|
| 78 | files: TStrings;
|
---|
| 79 | i: Integer;
|
---|
| 80 | fid: Integer;
|
---|
| 81 | finfo: TFileInfo;
|
---|
| 82 | begin
|
---|
| 83 | files := TStringList.Create;
|
---|
[233] | 84 | files := ConManager.Connection[FConnectionID].GetFilesList(FExt, '', False, ST_NameAsc);
|
---|
[228] | 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 |
|
---|
[233] | 101 |
|
---|
| 102 | { TExtensions }
|
---|
| 103 |
|
---|
| 104 | function TExtensions.GetCaption: String;
|
---|
| 105 | begin
|
---|
[244] | 106 | Result := 'Extensions';
|
---|
[233] | 107 | end;
|
---|
| 108 |
|
---|
| 109 | function TExtensions.GetChild(ID: Integer): TTreeElement;
|
---|
| 110 | begin
|
---|
[237] | 111 | FExtensions[ID].InitList;
|
---|
[233] | 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
|
---|
[237] | 153 | if FExtensions[i].Ext = Ext then
|
---|
[233] | 154 | begin
|
---|
| 155 | Result := FExtensions[i];
|
---|
| 156 | Break;
|
---|
| 157 | end;
|
---|
| 158 | end;
|
---|
| 159 |
|
---|
[244] | 160 | function TExtensions.GetType: String;
|
---|
| 161 | begin
|
---|
| 162 | Result := '';
|
---|
| 163 | end;
|
---|
| 164 |
|
---|
[233] | 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 |
|
---|
[228] | 186 | end.
|
---|