⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idftplistoutput.pas

📁 photo.163.com 相册下载器 多线程下载
💻 PAS
📖 第 1 页 / 共 4 页
字号:
      //just treat as one column
      if (LMaxLen > 39) then
      begin
        ProcessOnePathCol(ARoot, ACurDir, AOutput, Recurse);
        Exit;
      end;
      if Recurse and Assigned(ACurDir.SubDirs) then
      begin
        if Recurse then
        begin
          PrintSubDirHeader(ARoot,ACurDir,AOutput,Recurse);
        end;
      end;
      LCols := 79 div (LMaxLen + 2);//2 spaces between columns
      LLines := ACurDir.FileList.COunt div LCols;
      LFrm := '%'+IntToStr(LMaxLen+2)+'s';
      if (ACurDir.FileList.COunt mod LCols >0) then
      begin
        Inc(LLines);
      end;
      for i := 1 to LLines do
      begin
        j := 0;
        LTmp := '';
        repeat
          if (i-1)+(LLInes*j) < ACurDir.FileList.Count then
          begin
            LTmp := LTmp + PadSpaces(NListItem(TIdFTPListOutputItem(ACurDir.FileList.Objects[(i-1)+(LLInes*j)])),LMaxLen)+ '  ';
          end;
          Inc(j);
        until (j > LCols);
        AOutput.Add(TrimRight(LTmp));
      end;
      if Recurse and Assigned(ACurDir.SubDirs) then
      begin
        for i := 0 to ACurDir.SubDirs.Count -1 do
        begin
          LCurItem := TDirEntry(ACurDir.SubDirs[i]).DirListItem;
          if LCurItem.DirError then
          begin
            if i = 0 then
            begin
              AOutput.Add('');
            end;
            AOutput.Add(Format('/bin/ls: %s: Permission denied', [LCurItem.FileName])); {do not localize}
          end
          else
          begin
            ProcessPathAccross(ARoot, TDirEntry(ACurDir.SubDirs[i]), AOutput, Recurse);
          end;
        end;
      end;
    end;

    procedure ProcessPathComma(ARoot, ACurDir : TDirEntry; AOutput : TIdStrings; const Recurse : Boolean = False);
    var i : Integer;
      LTmp : String;
      LCurItem : TIdFTPListOutputItem;
    begin
      if Recurse then
      begin
        PrintSubDirHeader(ARoot,ACurDir,AOutput,Recurse);
      end;
      LTmp := '';
      for i := 0 to ACurDir.FileList.Count -1 do
      begin
          LTmp := LTmp + NListItem(TIdFTPListOutputItem(ACurDir.FileList.Objects[i])) +
            ', ';
      end;
      IdDelete(LTmp,Length(LTmp)-1,2);
      AOutput.Text := AOutput.Text + WrapText(LTmp);
      if Recurse and Assigned(ACurDir.SubDirs) then
      begin
        for i := 0 to ACurDir.SubDirs.Count -1 do
        begin
          LCurItem := TDirEntry(ACurDir.SubDirs[i]).DirListItem;
          if LCurItem.DirError then
          begin
            if i = 0 then
            begin
              AOutput.Add('');
            end;
            AOutput.Add(Format('/bin/ls: %s: Permission denied', [LCurItem.FileName])); {do not localize}
          end
          else
          begin
            ProcessPathComma(ARoot, TDirEntry(ACurDir.SubDirs[i]), AOutput, Recurse);
          end;
        end;
      end;
    end;

    procedure ProcessPathLong(ARoot, ACurDir : TDirEntry; AOutput : TIdStrings; const Recurse : Boolean = False);
    var i : Integer;
      LBlockCount : Integer;
      LCurItem : TIdFTPListOutputItem;
    begin
      if Recurse then
      begin
        PrintSubDirHeader(ARoot,ACurDir,AOutput,Recurse);
      end;
        if (DirFormat = doUnix) and ExportTotalLine then
        begin
          LBlockCount := 0;
          for i := 0 to ACurDir.FileList.Count -1 do
          begin
            LBlockCount := LBlockCount +
              TIdFTPListOutputItem(ACurDir.FileList.Objects[i]).NumberBlocks;
          end;
          AOutput.Add(Format('total %d',[LBlockCount]));  {Do not translate}
        end;

        for i := 0 to ACurDir.FileList.Count -1 do
        begin
          LCurItem := TIdFTPListOutputItem(ACurDir.FileList.Objects[i]);
          case DirFormat of
            doEPLF : AOutput.Add(Self.EPLFItem(LCurItem));
            doWin32 : AOutput.Add(Self.Win32Item (LCurItem));
          else
            AOutput.Add(Self.UnixItem (LCurItem));
          end;
        end;

      if Recurse and Assigned(ACurDir.SubDirs) then
      begin
        for i := 0 to ACurDir.SubDirs.Count -1 do
        begin
          LCurItem := TDirEntry(ACurDir.SubDirs[i]).DirListItem;
          if LCurItem.DirError then
          begin
            if DirFormat = doUnix then
            begin
              if i = 0 then
              begin
                AOutput.Add('');
              end;
              AOutput.Add(Format('/bin/ls: %s: Permission denied', [LCurItem.FileName])); {do not localize}
            end;
          end
          else
          begin
            ProcessPathLong(ARoot, TDirEntry(ACurDir.SubDirs[i]), AOutput, Recurse);
          end;
        end;
      end;
    end;

    procedure DoUnixfParam(ARoot : TDirEntry; AOutput : TIdStrings);
    var i : Integer;
        LI : TIdFTPListItem;
    begin
      for i := 0 to ARoot.FileList.Count -1 do
      begin
        LI := TIdFTPListItem(ARoot.FileList.Objects[i]);
        if LI.ItemType = ditDirectory then
        begin
          AOutput.Add( IndyGetFileName(LI.FileName));
        end;
      end;
    end;

begin
  LShowNavSym := (DirFormat=doUnix) and
    (IndyPos(SWITCH_SHOW_ALLPERIOD,Switches)>0);
  if LShowNavSym then
  begin
    LShowNavSym := (IndyPos(SWITCH_HIDE_DIRPOINT,Switches)=0);
  end;
  LRootPath := TDirEntry.Create('',nil);
  try
    for i := 0 to Count -1 do
    begin
      if (Items[i].ItemType in [ditDirectory,ditSymbolicLinkDir])  then
      begin
        if IsNavPath(StripInitPathDelin(IndyGetFileName( Items[i].FileName)))=False then
        begin
          LRootPath.AddSubDir(StripInitPathDelin(Items[i].FileName),Items[i]);
        end
        else
        begin
          //if it's a "." or "..", we show it only in Unix mode and only with eht -a switch
          if LShowNavSym then
          begin
            LRootPath.AddFileName(StripInitPathDelin(Items[i].FileName),Items[i]);
          end;
        end;
      end;
    end;
    //add the file names
    for i := 0 to Count -1 do
    begin
      if (Items[i].ItemType in [ditFile, ditSymbolicLink]) then
      begin
        if IsNavPath(StripInitPathDelin(IndyGetFileName( Items[i].FileName))) then
        begin
          if LShowNavSym then
          begin
            LRootPath.AddFileName(StripInitPathDelin(Items[i].FileName),Items[i]);
          end;
        end
        else
        begin
          LRootPath.AddFileName(StripInitPathDelin(Items[i].FileName),Items[i]);
        end;
      end;
    end;
    //Note that Indy does not support a Last Access time in some file systems
    //so we use the u parameter to mean the same as the t parameter
    if IndyPos(SWITCH_SORT_REVERSE,Switches)>0 then
    begin
      if (IndyPos(SWITCH_SORTBY_MTIME,Switches)>0) or (IndyPos(SWITCH_SORTBY_CTIME,Switches)>0) then
      begin
        LRootPath.SortDescendMTime;
      end
      else
      begin
        if (IndyPos(SWITCH_SORTBY_EXT, Switches)>0) then
        begin
          LRootPath.SortDescendFNameExt;
        end
        else
        begin
          if (IndyPos(SWITCH_SORTBY_SIZE, Switches)>0) then
          begin
            LRootPath.SortDescendSize;
          end
          else
          begin
            LRootPath.SortDescendFName;
          end;
        end;
      end;
    end
    else
    begin
      if (IndyPos(SWITCH_SORTBY_MTIME,Switches)>0) or (IndyPos(SWITCH_SORTBY_CTIME,Switches)>0) then
      begin
        LRootPath.SortAscendMTime;
      end
      else
      begin
        if (IndyPos(SWITCH_SORTBY_EXT, Switches)>0) then
        begin
          LRootPath.SortAscendFNameExt;
        end
        else
        begin
          if (IndyPos(SWITCH_SORTBY_SIZE, Switches)>0) then
          begin
            LRootPath.SortAscendSize;
          end
          else
          begin
            LRootPath.SortAscendFName;
          end;
        end;
      end;
    end;
    //select the operation
    // do the selected output operation
    case DetermineOp of
      doColsAccross : ProcessPathAccross(LRootPath,LRootPath,AOutput, IndyPos(SWITCH_RECURSIVE,Switches)>0 );
      doColsDown : ProcessPathDown(LRootPath,LRootPath,AOutput, IndyPos(SWITCH_RECURSIVE,Switches)>0 );
      doOneCol   : ProcessOnePathCol(LRootPath,LRootPath,AOutput, IndyPos(SWITCH_RECURSIVE,Switches)>0 );
      doOnlyDirs : DoUnixfParam(LRootPath,AOutput);
      doComma :  ProcessPathComma(LRootPath,LRootPath,AOutput, IndyPos(SWITCH_RECURSIVE,Switches)>0 );
    else
      ProcessPathLong(LRootPath,LRootPath,AOutput, IndyPos(SWITCH_RECURSIVE,Switches)>0 );
    end;
  finally
    FreeAndNil(LRootPath);
  end;
end;

procedure TIdFTPListOutput.LISTOutputDir(AOutput: TIdStrings);
begin
  InternelOutputDir(AOutput,True);
end;

function TIdFTPListOutput.MListItem(AItem: TIdFTPListOutputItem;
  AMLstOpts: TIdFTPFactOutputs): String;
begin
  if AMLstOpts <> [] then
  begin
    if Size in AMLstOpts then  {do not localize}
    begin
      Result := 'size=' + IntToStr(AItem.Size) + ';'; {do not localize}
    end;

    if ItemType in AMLstOpts then  {do not localize}
    begin
      Result := Result + 'type='; {do not localize}
      case AItem.ItemType of
        ditFile : Result := Result + 'file;'; {do not localize}
        ditDirectory :
        begin
          if (AItem.FileName = '..') then {do not localize}
          begin
            Result := Result + 'pdir;'; {do not localize}
          end
          else
          begin
            if (AItem.FileName = '.') then
            begin
              Result := Result + 'cdir;'; {do not localize}
            end
            else
            begin
            Result := Result + 'dir;';  {do not localize}
            end;
          end;
        end;
        ditSymbolicLink :
          Result := Result + 'OS.unix=slink:' + AItem.FileName + ';';  {do not localize}
      end;
    end;

    if Perm in AMLstOpts then  {do not localize}
    begin
      Result := Result + 'perm=' + AItem.MLISTPermissions + ';';  {do not localize}
    end;

    if CreateTime in AMLstOpts then  {do not localize}
    begin
      if AItem.CreationDateGMT<>0 then
      begin
        Result := Result + 'create='+ FTPGMTDateTimeToMLS(AItem.CreationDateGMT ) + ';';  {do not localize}
      end
      else
      begin
        if AItem.CreationDate<>0 then
        begin
          Result := Result + 'create='+ FTPLocalDateTimeToMLS(AItem.CreationDate ) + ';';  {do not localize}
        end;
      end;
    end;

    if Modify in AMLstOpts then  {do not localize}
    begin
      if AItem.ModifiedDateGMT<>0 then
      begin
        Result := Result + 'modify='+  FTPGMTDateTimeToMLS(AItem.ModifiedDateGMT ) + ';';  {do not localize}
      end
      else
      begin
        if AItem.ModifiedDate<>0 then
        begin
          Result := Result + 'modify='+ FTPLocalDateTimeToMLS(AItem.ModifiedDate) + ';';  {do not localize}
        end;
      end;
    end;
    if UnixMODE in AMLstOpts then {do not localize}
    begin
      Result := Result + 'UNIX.mode='+ Format('%.4d', [PermsToChmodNo(UnixGetOutputOwnerPerms(AItem), UnixGetOutputGroupPerms(AItem), UnixGetOutputOtherPerms(AItem) )] ) + ';';  {do not localize}
    end;
    if UnixOwner in AMLstOpts then  {do not localize}
    begin
      Result := Result + 'UNIX.owner=' + UnixGetOutputOwner(AItem) + ';'; {do not localize}
    end;
    if UnixGroup in AMLstOpts then  {do not localize}
    begin
      Result := Result + 'UNIX.group=' + UnixGetOutputGroup(AItem) + ';'; {do not localize}
    end;
    if Unique in AMLstOpts then
    begin
      if AItem.UniqueID <> '' then
      begin
        Result := Result + 'unique=' + AItem.UniqueID+';'; {do not localize}
      end;
    end;

    if LastAccessTime in AMLstOpts then  {do not localize}
    begin
      if AItem.ModifiedDateGMT<>0 then
      begin
        Result := Result + 'windows.lastaccesstime='+  FTPGMTDateTimeToMLS(AItem.ModifiedDateGMT ) + ';';  {do not localize}
      end
      else
      begin
        if AItem.ModifiedDate<>0 then
        begin
          Result := Result + 'windows.lastaccesstime='+ FTPLocalDateTimeToMLS(AItem.ModifiedDate) + ';';  {do not localize}
        end;
      end;
    end;
    Result := Result + ' ' + AItem.FileName;
  end
  else
  begin
    Result := AItem.FileName;
  end;
end;

procedure TIdFTPListOutput.MLISTOutputDir(AOutput : TIdStrings; AMLstOpts: TIdFTPFactOutputs);
var i : Integer;
begin
  AOutput.Clear;
  for i := 0 to Count -1 do
  begin
    AOutput.Add(MListItem(Items[i],AMLstOpts));
  end;
end;

function TIdFTPListOutput.NListItem(AItem: TIdFTPListOutputItem): String;
begin
  Result := IndyGetFileName(AItem.FileName);
  case Self.DirFormat of

    doUnix : begin
      if (IndyPos(SWITCH_QUOTEDNAME,Switches) >0) then
      begin
        Result := '"'+Result+'"';
      end;
      if (IndyPos(SWITCH_CLASSIFY,Switches)>0) or (IndyPos(SWITCH_SLASHDIR,Switches)>0) then
      begin
        case AItem.ItemType of
        ditDirectory : Result := Result + PATH_SUBDIR_SEP_UNIX;
        ditSymbolicLink, ditSymbolicLinkDir : Result := Result + '@';
        else
          if IsUnixExec(AItem.UnixOwnerPermissions, AItem.UnixGroupPermissions , AItem.UnixOtherPermissions) then
          begin
            Result := Result + '*';
          end;
        end;
      end;
      Result := UnixinodeOutput(AItem)+ UnixBlocksOutput(AItem)+ Result;
    end;
  end;
end;

procedure TIdFTPListOutput.NLISTOutputDir(AOutput: TIdStrings);
begin
  InternelOutputDir(AOutput,False);
end;

procedure TIdFTPListOutput.SetItems(AIndex: Integer;
  const AValue: TIdFTPListOutputItem);
begin
  inherited Items[AIndex] := AValue;
end;

function TIdFTPListOutput.UnixBlocksOutput(AItem: TIdFTPListOutputItem): String;
begin
  Result := '';
  if IndyPos(SWITCH_PRINT_BLOCKS,Switches)>0 then
  begin
    Result := Result + Format('%4d ',[ AItem.NumberBlocks ]);
  end;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -