[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;
|
---|
| 19 | end;
|
---|
| 20 |
|
---|
[233] | 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;
|
---|
[228] | 32 |
|
---|
[229] | 33 |
|
---|
[233] | 34 |
|
---|
[228] | 35 | implementation
|
---|
| 36 |
|
---|
| 37 | uses
|
---|
[233] | 38 | Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs, DataAccess, _MetaManager;
|
---|
[228] | 39 |
|
---|
| 40 | { TExtension }
|
---|
| 41 |
|
---|
| 42 | constructor TExtension.Create(ConnectionID: Integer; Ext: String);
|
---|
[229] | 43 | begin
|
---|
| 44 | FConnectionID := ConnectionID;
|
---|
| 45 | FExt := Ext;
|
---|
| 46 | end;
|
---|
| 47 |
|
---|
[233] | 48 | function TExtension.GetCaption: String;
|
---|
[229] | 49 | begin
|
---|
[233] | 50 | Result := FExt;
|
---|
[229] | 51 | end;
|
---|
| 52 |
|
---|
[233] | 53 | function TExtension.GetChild(ID: Integer): TTreeElement;
|
---|
| 54 | var
|
---|
| 55 | Meta: TMetaManager;
|
---|
[229] | 56 | begin
|
---|
[233] | 57 | Meta := ConManager.Connection[FConnectionID].MetaData;
|
---|
| 58 | Meta.InitFile(FFiles[ID]);
|
---|
| 59 | Result := Meta.FileById[FFiles[ID]];
|
---|
| 60 | end;
|
---|
| 61 |
|
---|
| 62 | function TExtension.GetChildCount: Integer;
|
---|
| 63 | begin
|
---|
[229] | 64 | Result := Length(FFiles);
|
---|
| 65 | end;
|
---|
| 66 |
|
---|
| 67 | procedure TExtension.InitList;
|
---|
[228] | 68 | var
|
---|
| 69 | files: TStrings;
|
---|
| 70 | i: Integer;
|
---|
| 71 | fid: Integer;
|
---|
| 72 | finfo: TFileInfo;
|
---|
| 73 | begin
|
---|
| 74 | files := TStringList.Create;
|
---|
[233] | 75 | files := ConManager.Connection[FConnectionID].GetFilesList(FExt, '', False, ST_NameAsc);
|
---|
[228] | 76 | if files.Count > 0 then
|
---|
| 77 | begin
|
---|
| 78 | for i := 0 to files.Count - 1 do
|
---|
| 79 | begin
|
---|
| 80 | fid := StrToInt(MidStr(files.Strings[i], 1, 5));
|
---|
| 81 | finfo := ConManager.Connection[FConnectionID].GetFileInfo(fid);
|
---|
| 82 | if Length(finfo.Name) > 0 then
|
---|
| 83 | begin
|
---|
| 84 | SetLength(FFiles, Length(FFiles) + 1);
|
---|
| 85 | FFiles[High(FFiles)] := fid;
|
---|
| 86 | end;
|
---|
| 87 | end;
|
---|
| 88 | end;
|
---|
| 89 | files.Free;
|
---|
| 90 | end;
|
---|
| 91 |
|
---|
[233] | 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 |
|
---|
[228] | 171 | end.
|
---|