RemoteFiles.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. //---------------------------------------------------------------------------
  2. #ifndef RemoteFilesH
  3. #define RemoteFilesH
  4. //---------------------------------------------------------------------------
  5. enum TModificationFmt { mfMDHM, mfMDY, mfFull };
  6. enum TRightsFlag {rfUserRead, rfUserWrite, rfUserExec, rfGroupRead,
  7. rfGroupWrite, rfGroupExec, rfOtherRead, rfOtherWrite, rfOtherExec};
  8. #define RightsFlagCount 9
  9. #define raUserRead 0400
  10. #define raUserWrite 0200
  11. #define raUserExec 0100
  12. #define raGroupRead 0040
  13. #define raGroupWrite 0020
  14. #define raGroupExec 0010
  15. #define raOtherRead 0004
  16. #define raOtherWrite 0002
  17. #define raOtherExec 0001
  18. #define raUser 0700
  19. #define raGroup 0070
  20. #define raOther 0007
  21. #define raRead 0444
  22. #define raWrite 0222
  23. #define raExecute 0111
  24. #define raAll 0777
  25. #define raNo 0000
  26. #define raDefault 0644
  27. #define raDirectory 0040000
  28. enum TRightState {rsNo, rsYes, rsUndef};
  29. //---------------------------------------------------------------------------
  30. #define SYMLINKSTR " -> "
  31. #define UNDEFRIGHT '$'
  32. #define NORIGHT '-'
  33. #define PARENTDIRECTORY ".."
  34. #define THISDIRECTORY "."
  35. #define FULLRIGHTS "rwxrwxrwx"
  36. #define ROOTDIRECTORY "/"
  37. #define MODEGROUPS "ugo"
  38. #define FILETYPE_SYMLINK 'L'
  39. #define FILETYPE_DIRECTORY 'D'
  40. //---------------------------------------------------------------------------
  41. class TRemoteDirectory;
  42. class TTerminal;
  43. class TRights;
  44. class TRemoteProperties;
  45. class TRemoteFileList;
  46. //---------------------------------------------------------------------------
  47. class TRemoteFile : public TPersistent
  48. {
  49. private:
  50. TRemoteFileList * FDirectory;
  51. AnsiString FOwner;
  52. TModificationFmt FModificationFmt;
  53. __int64 FSize;
  54. AnsiString FFileName;
  55. Integer FINodeBlocks;
  56. TDateTime FModification;
  57. TDateTime FLastAccess;
  58. AnsiString FGroup;
  59. Integer FIconIndex;
  60. Boolean FIsSymLink;
  61. TRemoteFile * FLinkedFile;
  62. TRemoteFile * FLinkedByFile;
  63. AnsiString FLinkTo;
  64. TRights *FRights;
  65. TTerminal *FTerminal;
  66. Char FType;
  67. bool FSelected;
  68. bool FCyclicLink;
  69. int __fastcall GetAttr();
  70. bool __fastcall GetBrokenLink();
  71. bool __fastcall GetIsDirectory() const;
  72. TRemoteFile * __fastcall GetLinkedFile();
  73. void __fastcall SetLinkedFile(TRemoteFile * value);
  74. AnsiString __fastcall GetModificationStr();
  75. void __fastcall SetModification(const TDateTime & value);
  76. void __fastcall SetListingStr(AnsiString value);
  77. AnsiString __fastcall GetListingStr();
  78. AnsiString __fastcall GetRightsStr();
  79. char __fastcall GetType() const;
  80. void __fastcall SetType(char AType);
  81. void __fastcall SetTerminal(TTerminal * value);
  82. void __fastcall SetRights(TRights * value);
  83. AnsiString __fastcall GetFullFileName();
  84. int __fastcall GetIconIndex();
  85. bool __fastcall GetIsHidden();
  86. bool __fastcall GetIsParentDirectory();
  87. bool __fastcall GetIsThisDirectory();
  88. bool __fastcall GetIsInaccesibleDirectory();
  89. AnsiString __fastcall GetExtension();
  90. AnsiString __fastcall GetUserModificationStr();
  91. protected:
  92. void __fastcall FindLinkedFile();
  93. public:
  94. __fastcall TRemoteFile(TRemoteFile * ALinkedByFile = NULL);
  95. virtual __fastcall ~TRemoteFile();
  96. TRemoteFile * __fastcall Duplicate();
  97. void __fastcall ShiftTime(const TDateTime & Difference);
  98. __property int Attr = { read = GetAttr };
  99. __property bool BrokenLink = { read = GetBrokenLink };
  100. __property TRemoteFileList * Directory = { read = FDirectory, write = FDirectory };
  101. __property AnsiString RightsStr = { read = GetRightsStr };
  102. __property __int64 Size = { read = FSize, write = FSize };
  103. __property AnsiString Owner = { read = FOwner, write = FOwner };
  104. __property AnsiString Group = { read = FGroup, write = FGroup };
  105. __property AnsiString FileName = { read = FFileName, write = FFileName };
  106. __property int INodeBlocks = { read = FINodeBlocks };
  107. __property TDateTime Modification = { read = FModification, write = SetModification };
  108. __property AnsiString ModificationStr = { read = GetModificationStr };
  109. __property AnsiString UserModificationStr = { read = GetUserModificationStr };
  110. __property TDateTime LastAccess = { read = FLastAccess, write = FLastAccess };
  111. __property bool IsSymLink = { read = FIsSymLink };
  112. __property bool IsDirectory = { read = GetIsDirectory };
  113. __property TRemoteFile * LinkedFile = { read = GetLinkedFile, write = SetLinkedFile };
  114. __property AnsiString LinkTo = { read = FLinkTo, write = FLinkTo };
  115. __property AnsiString ListingStr = { read = GetListingStr, write = SetListingStr };
  116. __property TRights * Rights = { read = FRights, write = SetRights };
  117. __property TTerminal * Terminal = { read = FTerminal, write = SetTerminal };
  118. __property Char Type = { read = GetType, write = SetType };
  119. __property bool Selected = { read=FSelected, write=FSelected };
  120. __property AnsiString FullFileName = { read=GetFullFileName };
  121. __property int IconIndex = { read = GetIconIndex };
  122. __property bool IsHidden = { read = GetIsHidden };
  123. __property bool IsParentDirectory = { read = GetIsParentDirectory };
  124. __property bool IsThisDirectory = { read = GetIsThisDirectory };
  125. __property bool IsInaccesibleDirectory = { read=GetIsInaccesibleDirectory };
  126. __property AnsiString Extension = { read=GetExtension };
  127. };
  128. //---------------------------------------------------------------------------
  129. class TRemoteParentDirectory : public TRemoteFile
  130. {
  131. public:
  132. __fastcall TRemoteParentDirectory();
  133. };
  134. //---------------------------------------------------------------------------
  135. class TRemoteFileList : public TObjectList
  136. {
  137. friend class TSCPFileSystem;
  138. friend class TSFTPFileSystem;
  139. protected:
  140. AnsiString FDirectory;
  141. TRemoteFile * __fastcall GetFiles(Integer Index);
  142. virtual void __fastcall SetDirectory(AnsiString value);
  143. AnsiString __fastcall GetFullDirectory();
  144. Boolean __fastcall GetIsRoot();
  145. TRemoteFile * __fastcall GetParentDirectory();
  146. AnsiString __fastcall GetParentPath();
  147. __int64 __fastcall GetTotalSize();
  148. virtual void __fastcall Clear();
  149. public:
  150. __fastcall TRemoteFileList();
  151. TRemoteFile * __fastcall FindFile(const AnsiString &FileName);
  152. virtual void __fastcall DuplicateTo(TRemoteFileList * Copy);
  153. virtual void __fastcall AddFile(TRemoteFile * File);
  154. __property AnsiString Directory = { read = FDirectory, write = SetDirectory };
  155. __property TRemoteFile * Files[Integer Index] = { read = GetFiles };
  156. __property AnsiString FullDirectory = { read=GetFullDirectory };
  157. __property Boolean IsRoot = { read = GetIsRoot };
  158. __property AnsiString ParentPath = { read = GetParentPath };
  159. __property __int64 TotalSize = { read = GetTotalSize };
  160. };
  161. //---------------------------------------------------------------------------
  162. class TRemoteDirectory : public TRemoteFileList
  163. {
  164. friend class TSCPFileSystem;
  165. friend class TSFTPFileSystem;
  166. private:
  167. Boolean FIncludeParentDirectory;
  168. Boolean FIncludeThisDirectory;
  169. TTerminal * FTerminal;
  170. TStrings * FSelectedFiles;
  171. TRemoteFile * FParentDirectory;
  172. TRemoteFile * FThisDirectory;
  173. virtual void __fastcall SetDirectory(AnsiString value);
  174. TStrings * __fastcall GetSelectedFiles();
  175. Boolean __fastcall GetLoaded();
  176. void __fastcall SetIncludeParentDirectory(Boolean value);
  177. void __fastcall SetIncludeThisDirectory(Boolean value);
  178. protected:
  179. virtual void __fastcall Clear();
  180. public:
  181. __fastcall TRemoteDirectory(TTerminal * aTerminal);
  182. virtual void __fastcall AddFile(TRemoteFile * File);
  183. virtual void __fastcall DuplicateTo(TRemoteFileList * Copy);
  184. __property TTerminal * Terminal = { read = FTerminal, write = FTerminal };
  185. __property TStrings * SelectedFiles = { read=GetSelectedFiles };
  186. __property Boolean IncludeParentDirectory = { read = FIncludeParentDirectory, write = SetIncludeParentDirectory };
  187. __property Boolean IncludeThisDirectory = { read = FIncludeThisDirectory, write = SetIncludeThisDirectory };
  188. __property Boolean Loaded = { read = GetLoaded };
  189. __property TRemoteFile * ParentDirectory = { read = FParentDirectory };
  190. __property TRemoteFile * ThisDirectory = { read = FThisDirectory };
  191. };
  192. //---------------------------------------------------------------------------
  193. class TRemoteDirectoryCache : private TStringList
  194. {
  195. public:
  196. __fastcall TRemoteDirectoryCache();
  197. virtual __fastcall ~TRemoteDirectoryCache();
  198. TRemoteFileList * __fastcall GetFileList(const AnsiString Directory);
  199. void __fastcall AddFileList(TRemoteFileList * FileList);
  200. void __fastcall ClearFileList(AnsiString Directory, bool SubDirs);
  201. void __fastcall Clear();
  202. __property bool IsEmpty = { read = GetIsEmpty };
  203. protected:
  204. virtual void __fastcall Delete(int Index);
  205. private:
  206. bool __fastcall GetIsEmpty() const;
  207. };
  208. //---------------------------------------------------------------------------
  209. class TRemoteDirectoryChangesCache : private TStringList
  210. {
  211. public:
  212. __fastcall TRemoteDirectoryChangesCache();
  213. void __fastcall AddDirectoryChange(const AnsiString SourceDir,
  214. const AnsiString Change, const AnsiString TargetDir);
  215. void __fastcall ClearDirectoryChange(AnsiString SourceDir);
  216. bool __fastcall GetDirectoryChange(const AnsiString SourceDir,
  217. const AnsiString Change, AnsiString & TargetDir);
  218. void __fastcall Clear();
  219. void __fastcall Serialize(AnsiString & Data);
  220. void __fastcall Deserialize(const AnsiString Data);
  221. __property bool IsEmpty = { read = GetIsEmpty };
  222. private:
  223. static bool __fastcall DirectoryChangeKey(const AnsiString SourceDir,
  224. const AnsiString Change, AnsiString & Key);
  225. bool __fastcall GetIsEmpty() const;
  226. };
  227. //---------------------------------------------------------------------------
  228. class TRights {
  229. private:
  230. Boolean FAllowUndef;
  231. AnsiString FText;
  232. AnsiString __fastcall GetFullRights() const;
  233. Boolean __fastcall GetIsUndef() const;
  234. AnsiString __fastcall GetModeStr() const;
  235. AnsiString __fastcall GetSimplestStr() const;
  236. void __fastcall SetNumber(Word value);
  237. AnsiString __fastcall GetText() const;
  238. void __fastcall SetText(AnsiString value);
  239. void __fastcall SetOctal(AnsiString value);
  240. Word __fastcall GetNumber() const;
  241. Word __fastcall GetNumberSet() const;
  242. Word __fastcall GetNumberUnset() const;
  243. AnsiString __fastcall GetOctal() const;
  244. Boolean __fastcall GetReadOnly();
  245. Boolean __fastcall GetRight(TRightsFlag Flag) const;
  246. TRightState __fastcall GetRightUndef(TRightsFlag Flag) const;
  247. void __fastcall SetAllowUndef(Boolean value);
  248. void __fastcall SetReadOnly(Boolean value);
  249. void __fastcall SetRight(TRightsFlag Flag, Boolean value);
  250. void __fastcall SetRightUndef(TRightsFlag Flag, TRightState value);
  251. protected:
  252. Word __fastcall CalcNumber(TRightState State, Boolean AllowUndef) const;
  253. public:
  254. TRights __fastcall operator &(Integer rhr) const;
  255. TRights __fastcall operator &(const TRights & rhr) const;
  256. TRights & __fastcall operator &=(Integer rhr);
  257. TRights & __fastcall operator &=(const TRights & rhr);
  258. TRights __fastcall operator |(Integer rhr) const;
  259. TRights __fastcall operator |(const TRights & rhr) const;
  260. TRights & __fastcall operator |=(Integer rhr);
  261. TRights & __fastcall operator |=(const TRights & rhr);
  262. TRights __fastcall operator ~() const;
  263. TRights & __fastcall operator =(Integer rhr);
  264. TRights & __fastcall operator =(const TRights & rhr);
  265. bool __fastcall operator ==(Integer rhr) const;
  266. bool __fastcall operator ==(const TRights & rhr) const;
  267. bool __fastcall operator !=(const TRights & rhr) const;
  268. __fastcall operator unsigned short() const;
  269. __fastcall operator unsigned long() const;
  270. void __fastcall AddExecute();
  271. void __fastcall AllUndef();
  272. virtual void __fastcall Assign(const TRights * Source);
  273. __fastcall TRights(const TRights & Source);
  274. __fastcall TRights(Word aNumber);
  275. __fastcall TRights();
  276. __property Boolean AllowUndef = { read = FAllowUndef, write = SetAllowUndef };
  277. __property AnsiString FullRights = { read = GetFullRights };
  278. __property Boolean IsUndef = { read = GetIsUndef };
  279. __property AnsiString ModeStr = { read = GetModeStr };
  280. __property AnsiString SimplestStr = { read = GetSimplestStr };
  281. __property AnsiString Octal = { read = GetOctal, write = SetOctal };
  282. __property Word Number = { read = GetNumber, write = SetNumber };
  283. __property Word NumberSet = { read = GetNumberSet };
  284. __property Word NumberUnset = { read = GetNumberUnset };
  285. __property Boolean ReadOnly = { read = GetReadOnly, write = SetReadOnly };
  286. __property Boolean Right[TRightsFlag Flag] = { read = GetRight, write = SetRight };
  287. __property TRightState RightUndef[TRightsFlag Flag] = { read = GetRightUndef, write = SetRightUndef };
  288. __property AnsiString Text = { read = GetText, write = SetText };
  289. };
  290. //---------------------------------------------------------------------------
  291. enum TValidProperty { vpRights, vpGroup, vpOwner };
  292. typedef Set<TValidProperty, vpRights, vpOwner> TValidProperties;
  293. class TRemoteProperties
  294. {
  295. public:
  296. TValidProperties Valid;
  297. bool Recursive;
  298. TRights Rights;
  299. bool AddXToDirectories;
  300. AnsiString Group;
  301. AnsiString Owner;
  302. __fastcall TRemoteProperties();
  303. bool __fastcall operator ==(const TRemoteProperties & rhp) const;
  304. bool __fastcall operator !=(const TRemoteProperties & rhp) const;
  305. static TRemoteProperties __fastcall CommonProperties(TStrings * FileList);
  306. static TRemoteProperties __fastcall ChangedProperties(
  307. const TRemoteProperties & OriginalProperties, TRemoteProperties NewProperties);
  308. };
  309. //---------------------------------------------------------------------------
  310. AnsiString __fastcall UnixIncludeTrailingBackslash(const AnsiString Path);
  311. AnsiString __fastcall UnixExcludeTrailingBackslash(const AnsiString Path);
  312. AnsiString __fastcall UnixExtractFileDir(const AnsiString Path);
  313. AnsiString __fastcall UnixExtractFilePath(const AnsiString Path);
  314. AnsiString __fastcall UnixExtractFileName(const AnsiString Path);
  315. AnsiString __fastcall UnixExtractFileExt(const AnsiString Path);
  316. Boolean __fastcall UnixComparePaths(const AnsiString Path1, const AnsiString Path2);
  317. //---------------------------------------------------------------------------
  318. #endif