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