📄 idftplistoutput.pas
字号:
function TIdFTPListOutput.UnixGetOutputGroup(
AItem: TIdFTPListOutputItem): String;
begin
if AItem.GroupName = '' then
begin
Result := UnixGetOutputOwner(AItem);
end
else
begin
Result := AItem.GroupName;
end;
end;
function TIdFTPListOutput.UnixGetOutputGroupPerms(
AItem: TIdFTPListOutputItem): String;
begin
if AItem.UnixOtherPermissions = '' then
begin
if AItem.ItemType in [ditSymbolicLink, ditSymbolicLinkDir] then
begin
Result := DEF_DIR_GRP_PERM;
end
else
begin
Result := DEF_FILE_GRP_PERM;
end;
end
else
begin
Result := AItem.UnixOtherPermissions;
end;
end;
function TIdFTPListOutput.UnixGetOutputOtherPerms(
AItem: TIdFTPListOutputItem): String;
begin
if AItem.UnixOtherPermissions = '' then
begin
if AItem.ItemType in [ditSymbolicLink, ditSymbolicLinkDir] then
begin
Result := DEF_DIR_OTHER_PERM;
end
else
begin
Result := DEF_FILE_OTHER_PERM
end;
end
else
begin
Result := AItem.UnixOtherPermissions;
end;
end;
function TIdFTPListOutput.UnixGetOutputOwner(
AItem: TIdFTPListOutputItem): String;
begin
if AItem.OwnerName = '' then
begin
Result := DEF_OWNER;
end
else
begin
Result := AItem.OwnerName;
end;
end;
function TIdFTPListOutput.UnixGetOutputOwnerPerms(
AItem: TIdFTPListOutputItem): String;
begin
if AItem.UnixOwnerPermissions = '' then
begin
if AItem.ItemType in [ditSymbolicLink, ditSymbolicLinkDir] then
begin
Result := DEF_DIR_OWN_PERM
end
else
begin
Result := DEF_FILE_OWN_PERM;
end;
end
else
begin
Result := AItem.UnixOwnerPermissions;
end;
end;
function TIdFTPListOutput.UnixINodeOutput(AItem: TIdFTPListOutputItem): String;
var LInode : String;
begin
Result := '';
if IndyPos(SWITCH_PRINT_INODE,Switches)>0 then
begin
LInode := IntToStr(Abs(AItem.Inode));
//should be no more than 10 digits
LInode := Copy(LInode,1,10);
Result := Result + Format('%10s ',[ LInode ]);
end;
end;
function TIdFTPListOutput.UnixItem(AItem: TIdFTPListOutputItem): String;
var
LSize, LTime: string;
l, month: Word;
LLinkNum : Integer;
LFileName : String;
LFormat : String;
LMTime : TDateTime;
begin
LFileName := IndyGetFileName(AItem.FileName);
Result := '';
Result := Result + UnixINodeOutput(AItem);
Result := Result + UnixBlocksOutput(AItem);
LSize := '-'; {Do not Localize}
case AItem.ItemType of
ditDirectory: begin
AItem.Size := UNIX_DIR_SIZE;
LSize := 'd'; {Do not Localize}
end;
ditSymbolicLink: LSize := 'l'; {Do not Localize}
end;
if AItem.LinkCount = 0 then
begin
LLinkNum := 1;
end
else
begin
LLinkNum := AItem.LinkCount;
end;
LFormat := '%3:3s%4:3s%5:3s %6:3d '; {Do not localize}
//g - surpress owner
//lrwxrwxrwx 1 other 7 Nov 16 2001 bin -> usr/bin
//where it would normally print
//lrwxrwxrwx 1 root other 7 Nov 16 2001 bin -> usr/bin
if (IndyPos('g',Switches)=0) then
begin
LFormat := LFormat + '%1:-8s '; {Do not localize}
end;
//o - surpress group
//lrwxrwxrwx 1 root 7 Nov 16 2001 bin -> usr/bin
//where it would normally print
//lrwxrwxrwx 1 root other 7 Nov 16 2001 bin -> usr/bin
if (IndyPos('o',Switches)=0) then
begin
LFormat := LFormat + '%2:-8s '; {Do not localize}
end;
LFormat := LFormat + '%0:8d'; {Do not localize}
LSize := LSize + Format(LFormat
, [AItem.Size, UnixGetOutputOwner(AItem), UnixGetOutputGroup(AItem), UnixGetOutputOwnerPerms(AItem), UnixGetOutputGroupPerms(AItem), UnixGetOutputOtherPerms(AItem),LLinkNum]);
LMTime := GetLocalModTime(AItem);
DecodeDate(LMTime, l, month, l);
LTime := MonthNames[month] + FormatDateTime(' dd', LMTime); {Do not Localize}
if (IndyPos(SWITCH_BOTH_TIME_YEAR,Switches)>0) then
begin
LTime := LTime + FormatDateTime(' hh:mm:ss yyyy', AItem.ModifiedDate); {Do not Localize}
end
else
begin
if IsIn6MonthWindow(LMTime) then begin {Do not Localize}
LTime := LTime + FormatDateTime(' hh:mm', LMTime); {Do not Localize}
end else begin
LTime := LTime + FormatDateTime(' yyyy', LMTime); {Do not Localize}
end;
end;
// A.Neillans, 20 Apr 2002, Fixed glitch, extra space in front of names.
// Result := LSize + ' ' + LTime + ' ' + FileName; {Do not Localize}
Result := Result + LSize + ' ' + LTime + ' ';
if (IndyPos(SWITCH_QUOTEDNAME,Switches)>0) then
begin
Result := Result + '"'+LFileName+'"';
end
else
begin
Result := Result + LFileName; {Do not Localize}
end;
if AItem.ItemType in [ditSymbolicLink, ditSymbolicLinkDir] then
begin
if (IndyPos(SWITCH_QUOTEDNAME,Switches)>0) then
begin
Result := Result + UNIX_LINKTO_SYM + '"'+AItem.LinkedItemName+'"';
end
else
begin
Result := Result + UNIX_LINKTO_SYM + AItem.LinkedItemName;
end;
end;
if ((IndyPos(SWITCH_CLASSIFY,Switches)>0) or (IndyPos(SWITCH_SLASHDIR,Switches)>0)) and {Do not translate}
(AItem.ItemType in [ditDirectory, ditSymbolicLinkDir]) then
begin
Result := Result + PATH_SUBDIR_SEP_UNIX;
end;
if (IndyPos(SWITCH_CLASSIFY,Switches)>0) and {Do not translate}
(AItem.ItemType = ditFile) and
IsUnixExec( UnixGetOutputOwnerPerms(AItem), UnixGetOutputGroupPerms(AItem), UnixGetOutputOtherPerms(AItem)) then
begin
//star is placed at the end of a file name
//like this:
//-r-xr-xr-x 1 0 1 17440 Aug 8 2000 ls*
Result := Result + '*';
end;
end;
function TIdFTPListOutput.Win32Item(AItem: TIdFTPListOutputItem): String;
var LSize, LFileName : String;
begin
LFileName := IndyGetFileName(AItem.FileName);
if AItem.ItemType = ditDirectory then begin
LSize := ' ' + '<DIR>' + StringOfChar(' ', 9); {Do not Localize}
end else begin
LSize := StringOfChar(' ', 20 - Length(IntToStr(AItem.Size))) + IntToStr(AItem.Size); {Do not Localize}
end;
Result := FormatDateTime('mm-dd-yy hh:mmAM/PM', GetLocalModTime( AItem) ) + ' ' + LSize {Do not Localize}
+ ' ' + LFileName; {Do not Localize}
end;
{ TDirEntry }
function TDirEntry.AddFileName(const APathName: String;
ADirEnt: TIdFTPListOutputItem) : Boolean;
var i : Integer;
LParentPart : String;
LDirEnt : TDirEntry;
begin
Result := False;
LParentPart := StripInitPathDelin(IndyGetFilePath(APathName));
// LParentPart := IndyGetFileName(LParentPart);
if LParentPart = PathName then
begin
if FFileList.IndexOf(APathName)=-1 then
begin
FFileList.AddObject(APathName,ADirEnt);
end;
Result := True;
end
else
begin
if Assigned( SubDirs) then
begin
for i := 0 to SubDirs.Count -1 do
begin
LDirEnt := TDirEntry(SubDirs[i]);
LParentPart := StripInitPathDelin( IndyGetFilePath(LDirEnt.FDirListItem.FileName));
if Copy(APathName,1, Length(LParentPart))=
LParentPart then
begin
if TDirEntry(SubDirs[i]).AddFileName(APathName,ADirEnt) then
begin
Result := True;
Break;
end;
end;
end;
end;
end;
end;
function TDirEntry.AddSubDir(const APathName: String;
ADirEnt: TIdFTPListOutputItem) : Boolean;
var LDirEnt : TDirEntry;
i : Integer;
LParentPart : String;
begin
Result := False;
LParentPart := StripInitPathDelin(IndyGetFilePath(APathName));
if LParentPart = PathName then
begin
if Assigned(FSubDirs)=False then
begin
FSubDirs := TIdObjectList.Create;
end;
LParentPart := StripInitPathDelin( IndyGetFilePath(APathName));
LParentPart := IndyGetFileName(LParentPart);
LDirEnt := TDirEntry.Create(APathName,ADirEnt);
FSubDirs.Add(LDirEnt);
AddFileName(APathName, ADirEnt);
Result := True;
end
else
begin
if Assigned(SubDirs) then
begin
for i := 0 to SubDirs.Count -1 do
begin
LDirEnt := TDirEntry(SubDirs[i]);
LParentPart := StripInitPathDelin( IndyGetFilePath(LDirEnt.FDirListItem.FileName));
// if Copy(APathName,1, Length(LParentPart))=
// LParentPart then
if Copy(APathName,1, Length(LParentPart))=
LParentPart then
begin
if LDirEnt.AddSubDir(APathName,ADirEnt) then
begin
Result := True;
Break;
end;
end;
end;
end;
end;
end;
constructor TDirEntry.Create(const APathName : String; ADirListItem : TIdFTPListOutputItem);
begin
inherited Create;
FPathName := APathName;
FFileList := TIdBubbleSortStringList.Create;
FDirListItem := ADirListItem;
//create that only when necessary;
FSubDirs := TIdObjectList.Create;
end;
destructor TDirEntry.Destroy;
begin
FreeAndNil( FFileList );
FreeAndNil( FSubDirs );
inherited;
end;
procedure TDirEntry.SortAscendFName;
var i : Integer;
begin
if Assigned(FFileList) then
begin
FFileList.BubbleSort(StrSortAscFName);
end;
if Assigned(FSubDirs) then
begin
FSubDirs.BubbleSort(DESortAscFName);
for i := 0 to FSubDirs.Count -1 do
begin
TDirEntry(FSubDirs[i]).SortAscendFName;
end;
end;
end;
procedure TDirEntry.SortAscendMTime;
var i : Integer;
begin
FFileList.BubbleSort(StrSortAscMTime);
if Assigned(FSubDirs) then
begin
FSubDirs.BubbleSort(DESortAscMTime);
for i := 0 to FSubDirs.Count -1 do
begin
TDirEntry(FSubDirs[i]).SortAscendMTime;
end;
end;
end;
procedure TDirEntry.SortDescendMTime;
var i : Integer;
begin
FFileList.BubbleSort(StrSortDescMTime);
if Assigned(FSubDirs) then
begin
FSubDirs.BubbleSort(DESortDescMTime);
for i := 0 to FSubDirs.Count -1 do
begin
TDirEntry(FSubDirs[i]).SortDescendMTime;
end;
end;
end;
procedure TDirEntry.SortDescendFName;
var i : Integer;
begin
if Assigned(FSubDirs) then
begin
FSubDirs.BubbleSort(DESortDescFName);
for i := 0 to FSubDirs.Count -1 do
begin
TDirEntry(FSubDirs[i]).SortDescendFName;
end;
end;
FFileList.BubbleSort(StrSortDescFName);
end;
procedure TDirEntry.SortAscendFNameExt;
var i : Integer;
begin
if Assigned(FFileList) then
begin
FFileList.BubbleSort(StrSortAscFNameExt);
end;
if Assigned(FSubDirs) then
begin
FSubDirs.BubbleSort(DESortAscFName);
for i := 0 to FSubDirs.Count -1 do
begin
TDirEntry(FSubDirs[i]).SortAscendFNameExt;
end;
end;
end;
procedure TDirEntry.SortDescendFNameExt;
var i : Integer;
begin
if Assigned(FFileList) then
begin
FFileList.BubbleSort(StrSortDescFNameExt);
end;
if Assigned(FSubDirs) then
begin
FSubDirs.BubbleSort(DESortAscFName);
for i := 0 to FSubDirs.Count -1 do
begin
TDirEntry(FSubDirs[i]).SortDescendFNameExt;
end;
end;
end;
procedure TDirEntry.SortAscendSize;
var i : Integer;
begin
FFileList.BubbleSort(StrSortAscSize);
if Assigned(FSubDirs) then
begin
FSubDirs.BubbleSort(DESortAscMTime);
for i := 0 to FSubDirs.Count -1 do
begin
TDirEntry(FSubDirs[i]).SortAscendSize;
end;
end;
end;
procedure TDirEntry.SortDescendSize;
var i : Integer;
begin
FFileList.BubbleSort(StrSortDescSize);
if Assigned(FSubDirs) then
begin
FSubDirs.BubbleSort(DESortDescFName);
for i := 0 to FSubDirs.Count -1 do
begin
TDirEntry(FSubDirs[i]).SortDescendSize ;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -