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