IdFTPListParseWinQVTNET.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.5 10/26/2004 10:03:22 PM JPMugaas
  18. Updated refs.
  19. Rev 1.4 4/19/2004 5:05:42 PM JPMugaas
  20. Class rework Kudzu wanted.
  21. Rev 1.3 2004.02.03 5:45:26 PM czhower
  22. Name changes
  23. Rev 1.2 1/22/2004 7:20:56 AM JPMugaas
  24. System.Delete changed to IdDelete so the code can work in NET.
  25. Rev 1.1 10/19/2003 3:48:20 PM DSiders
  26. Added localization comments.
  27. Rev 1.0 2/19/2003 05:49:50 PM JPMugaas
  28. Parsers ported from old framework.
  29. }
  30. unit IdFTPListParseWinQVTNET;
  31. interface
  32. {$i IdCompilerDefines.inc}
  33. uses
  34. Classes,
  35. IdFTPList, IdFTPListParseBase;
  36. {
  37. This was tested with data obtained from WinQVT/Net Version 3.98.15 running
  38. on Windows 2000.
  39. No parser is required for later versions because those use the Unix listing
  40. format.
  41. }
  42. type
  43. TIdWinQVNetFTPListItem = class(TIdFTPListItem);
  44. TIdFTPLPWinQVNet = class(TIdFTPListBase)
  45. protected
  46. class function MakeNewItem(AOwner : TIdFTPListItems) : TIdFTPListItem; override;
  47. class function ParseLine(const AItem : TIdFTPListItem; const APath : String = ''): Boolean; override;
  48. public
  49. class function GetIdent : String; override;
  50. class function CheckListing(AListing : TStrings; const ASysDescript : String = ''; const ADetails : Boolean = True): Boolean; override;
  51. end;
  52. // RLebeau 2/14/09: this forces C++Builder to link to this unit so
  53. // RegisterFTPListParser can be called correctly at program startup...
  54. {$IFDEF HAS_DIRECTIVE_HPPEMIT_LINKUNIT}
  55. {$HPPEMIT LINKUNIT}
  56. {$ELSE}
  57. {$HPPEMIT '#pragma link "IdFTPListParseWinQVTNET"'}
  58. {$ENDIF}
  59. implementation
  60. uses
  61. IdGlobal, IdFTPCommon, IdGlobalProtocols,
  62. SysUtils;
  63. { TIdFTPLPWinQVNet }
  64. class function TIdFTPLPWinQVNet.CheckListing(AListing: TStrings;
  65. const ASysDescript: String; const ADetails: Boolean): Boolean;
  66. var
  67. LData : String;
  68. begin
  69. Result := False;
  70. if AListing.Count > 0 then
  71. {
  72. test.txt 0 10-23-2003 01:01
  73. 123456789012345678901234567890123456789012345678901234567890
  74. 1 2 3 4 5 6
  75. }
  76. begin
  77. LData := AListing[0];
  78. Result := (Copy(LData, 38, 1) = '-') and {do not localize}
  79. (Copy(LData, 41, 1) = '-') and {do not localize}
  80. (Copy(LData, 49, 1) = ':') and {do not localize}
  81. IsMMDDYY(Copy(LData, 36, 10), '-') and {do not localize}
  82. (Copy(LData, 46, 1) = ' ') and {do not localize}
  83. IsHHMMSS(Copy(LData, 47, 5), ':'); {do not localize}
  84. end;
  85. end;
  86. class function TIdFTPLPWinQVNet.GetIdent: String;
  87. begin
  88. Result := 'WinQVT/NET'; {do not localize}
  89. end;
  90. class function TIdFTPLPWinQVNet.MakeNewItem(AOwner: TIdFTPListItems): TIdFTPListItem;
  91. begin
  92. Result := TIdWinQVNetFTPListItem.Create(AOwner);
  93. end;
  94. class function TIdFTPLPWinQVNet.ParseLine(const AItem: TIdFTPListItem;
  95. const APath: String): Boolean;
  96. var
  97. LBuf : String;
  98. begin
  99. //filename (note that it can contain spaces on WinNT with my test case
  100. AItem.FileName := ExtractQVNETFileName(AItem.Data);
  101. LBuf := AItem.Data;
  102. //item type
  103. if IndyPos('/', Copy(LBuf, 1, 13)) > 0 then begin {do not localize}
  104. AItem.ItemType := ditDirectory;
  105. end;
  106. IdDelete(LBuf, 1, 13);
  107. LBuf := TrimLeft(LBuf);
  108. //Size
  109. AItem.Size := IndyStrToInt64(Fetch(LBuf), 0);
  110. //Date
  111. LBuf := TrimLeft(LBuf);
  112. AItem.ModifiedDate := DateMMDDYY(Fetch(LBuf));
  113. //Time
  114. LBuf := Trim(LBuf);
  115. AItem.ModifiedDate := AItem.ModifiedDate + TimeHHMMSS(LBuf);
  116. Result := True;
  117. end;
  118. initialization
  119. RegisterFTPListParser(TIdFTPLPWinQVNet);
  120. finalization
  121. UnRegisterFTPListParser(TIdFTPLPWinQVNet);
  122. end.