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

📄 idftplistparsebase.pas

📁 photo.163.com 相册下载器 多线程下载
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  end;
end;

{ TIdFTPListBase }

{register and unreg procedures}
procedure RegisterFTPListParser(const AParser : TIdFTPListParseClass);
begin
 GParserList.Add(TObject(AParser));
end;

procedure UnregisterFTPListParser(const AParser : TIdFTPListParseClass);
begin
  if Assigned(GParserList) then
  begin
    GParserList.Remove(TObject(AParser));
  end;
end;

function ParseListing(AListing : TIdStrings; ADir : TIdFTPListItems; const AFormatID : String ) : boolean;
begin
  Result := GParserList.ParseListing(AListing,ADir,AFormatID);
end;

function CheckListParse(AListing : TIdStrings; ADir : TIdFTPListItems;var AFormat : String; const ASysDescript : String =''; const ADetails : Boolean = True) : boolean;
begin
  Result := GParserList.CheckListParse(AListing,ADir,AFormat,ASysDescript,ADetails);
end;

function CheckListing(AListing : TIdStrings; const ASysDescript : String =''; const ADetails : Boolean = True): String;
begin
  Result := GParserList.CheckListing(AListing,ASysDescript,ADetails);
end;

function CheckListParseCapa(AListing: TIdStrings;
  ADir: TIdFTPListItems; var VFormat: String;
  var VClass :  TIdFTPListParseClass; const ASysDescript: String;
  const ADetails: Boolean): boolean;
begin
  Result := GParserList.CheckListParseCapa(AListing,
    ADir, VFormat,
    VClass,
    ASysDescript,
    ADetails);
end;

{ TIdFTPListBase }

class function TIdFTPListBase.CheckListing(AListing: TIdStrings;
  const ASysDescript: String; const ADetails: Boolean): boolean;
begin
//C++Builder can not use abstract virtual class methods.
  Result := False;
end;

class function TIdFTPListBase.GetIdent: String;
begin
  Result := '';
end;

class function TIdFTPListBase.MakeNewItem(AOwner : TIdFTPListItems) : TIdFTPListItem;
begin
  Result := AOwner.Add;
end;

class function TIdFTPListBase.ParseLine(const AItem: TIdFTPListItem;
  const APath: String): Boolean;
begin
//C++Builder can not use abstract virtual class methods.
  Result := False;
end;

class function TIdFTPListBase.parselisting(AListing: TIdStrings;
  ADir: TIdFTPListItems): boolean;
var i : Integer;
  AItem : TIdFTPListItem;
begin
  Result := True;
  for i := 0 to AListing.Count -1 do
  begin
    if ( AListing[i]<>'') then
    begin
      AItem := MakeNewItem(ADir);
      AItem.Data := AListing[i];
      ParseLine(AItem,'');
    end;
  end;
end;

{ TIdFTPLPNList }

class function TIdFTPLPNList.CheckListing(AListing : TIdStrings; const ASysDescript : String =''; const ADetails : Boolean = True): boolean;
begin
  Result := (ADetails=False);
end;

class function TIdFTPLPNList.GetIdent: String;
begin
  Result := NLST;
end;

class function TIdFTPLPNList.ParseLine(const AItem: TIdFTPListItem;
  const APath: String = ''): Boolean;
begin
  AItem.FileName := AItem.Data;
  Result := True;
end;

{ TIdFTPLPMList }

class function TIdFTPLPMList.CheckListing(AListing : TIdStrings; const ASysDescript : String =''; const ADetails : Boolean = True): boolean;
begin
//user has to specifically ask for this parser
  Result := False;
end;

class function TIdFTPLPMList.GetIdent: String;
begin
  Result := MLST;
end;

class function TIdFTPLPMList.MakeNewItem(
  AOwner: TIdFTPListItems): TIdFTPListItem;
begin
  Result := TIdMLSTFTPListItem.Create(AOwner);
end;

class function TIdFTPLPMList.ParseLine(const AItem: TIdFTPListItem;
  const APath: String =''): Boolean;
var LFacts : TIdStrings;
    LBuffer : String;
    LI : TIdMLSTFTPListItem;
//based on:
//
//http://www.ietf.org/internet-drafts/draft-ietf-ftpext-mlst-15.txt
begin
  LI := AItem as TIdMLSTFTPListItem;
  LFacts := TIdStringList.Create;
  try
    LI.FileName := ParseFacts(AItem.Data,LFacts);
    LI.LocalFileName := AItem.FileName;

    LBuffer := LFacts.Values['type']; {do not localize}
//   file         -- a file entry
//   cdir         -- the listed directory
//   pdir         -- a parent directory
//   dir          -- a directory or sub-directory
//   OS.name=type -- an OS or file system dependent file type

    if (LBuffer = 'cdir') or (LBuffer='pdir') or  {do not localize}
      (LBuffer = 'dir') then  {do not localize}
    begin
      LI.ItemType := ditDirectory;
    end
    else
    begin
      LI.ItemType := ditFile;
    end;
    LBuffer := LFacts.Values['modify']; {do not localize}
    if LBuffer <> '' then
    begin
      LI.ModifiedDate := FTPMLSToLocalDateTime(LBuffer);
      LI.ModifiedDateGMT := FTPMLSToGMTDateTime(LBuffer);
    end
    else
    begin
      LI.ModifiedAvail := False;
    end;
    //create
    LBuffer := LFacts.Values['create']; {do not localize}
    if LBuffer <> '' then
    begin
      LI.CreationDate := FTPMLSToLocalDateTime(LBuffer);
      LI.CreationDateGMT := FTPMLSToGMTDateTime(LBuffer);
    end;
    //last access time
    LBuffer := LFacts.Values['windows.lastaccesstime']; {do not localize}
    if LBuffer <> '' then
    begin
      LI.LastAccessDate := FTPMLSToLocalDateTime(LBuffer);
      LI.LastAccessDateGMT := FTPMLSToGMTDateTime(LBuffer);
    end;
    LBuffer := LFacts.Values['size']; {do not localize}
    if LBuffer<>'' then
    begin
      LI.Size := StrToIntDef(LBuffer, 0);

    end
    else
    begin
      LI.SizeAvail := False;
    end;
    if LI.SizeAvail = False and (LI.ItemType=ditDirectory) then
    begin
      {PureFTPD uses a sizd fact for directories instead of the size fact}
      LBuffer := LFacts.Values['sizd']; {Do not localize}
      if LBuffer<>'' then
      begin
        LI.Size := StrToIntDef(LBuffer, 0);
        LI.SizeAvail := True;
      end
      else
      begin
        LI.SizeAvail := False;
      end;
    end;
    LI.MLISTPermissions := LFacts.Values['perm'];  {do not localize}
    LI.UniqueID := LFacts.Values['unique']; {do not localize}
    Result := True;
  finally
    FreeAndNil(LFacts);
  end;
end;

{ TIdFTPListBaseHeader }


class function TIdFTPListBaseHeader.CheckListing(AListing: TIdStrings;
  const ASysDescript: String; const ADetails: Boolean): boolean;
var i : Integer;
begin
  Result := False;
  for i := 0 to AListing.Count -1 do
  begin
    if IsWhiteString(AListing[i])
       or IsLineStr(AListing[i]) then
    begin
    end
    else
    begin
      Result := IsHeader(AListing[i]);
      break;
    end;
  end;
end;

class function TIdFTPListBaseHeader.IsFooter(const AData: String): Boolean;
begin
  Result := False;
end;

class function TIdFTPListBaseHeader.IsHeader(const AData: String): Boolean;
begin
  Result := False;
end;

class function TIdFTPListBaseHeader.ParseListing(AListing: TIdStrings;
  ADir: TIdFTPListItems): boolean;
var LStart : Integer;
   i : Integer;
   LItem : TIdFTPListItem;
begin
  if AListing.Count >0 then
  begin
    //find the entries below the header
    LStart := 0;
    for i := 0 to AListing.Count -1 do
    begin
      if IsHeader(AListing[i]) or IsWhiteString(AListing[i])
       or IsLineStr(AListing[i]) then
      begin
        LStart := i+1;
      end
      else
      begin
        //we found where the header ends
        break;
      end;
    end;
    for i := LStart to AListing.Count -1 do
    begin
      if (IsWhiteString(AListing[i])=False) and
        (IsLineStr(AListing[i])=False)
        and (IsFooter(AListing[i])=False) then
      begin
        LItem := MakeNewItem(ADir);
        LItem.Data := AListing[i];
        ParseLine(LItem);
      end;
    end;
  end;
  Result := True;
end;

{ TIdFTPLineOwnedList }

class function TIdFTPLineOwnedList.MakeNewItem(
  AOwner: TIdFTPListItems): TIdFTPListItem;
begin
  Result := TIdOwnerFTPListItem.Create(AOwner);
end;

initialization
  GParserList := TIdFTPRegParseList.Create;

  //Register the manditory parsers
  RegisterFTPListParser(TIdFTPLPNList);
  RegisterFTPListParser(TIdFTPLPMList);

finalization
  FreeAndNil(GParserList);
end.

⌨️ 快捷键说明

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