RemoteFiles.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. //---------------------------------------------------------------------------
  2. #ifndef RemoteFilesH
  3. #define RemoteFilesH
  4. //---------------------------------------------------------------------------
  5. #include <vector>
  6. #include <map>
  7. //---------------------------------------------------------------------------
  8. enum TModificationFmt { mfNone, mfMDHM, mfYMDHM, mfMDY, mfFull };
  9. //---------------------------------------------------------------------------
  10. #define SYMLINKSTR L" -> "
  11. #define ROOTDIRECTORY L"/"
  12. #define FILETYPE_DEFAULT L'-'
  13. #define FILETYPE_SYMLINK L'L'
  14. #define FILETYPE_DIRECTORY L'D'
  15. extern const UnicodeString PartialExt;
  16. //---------------------------------------------------------------------------
  17. class TTerminal;
  18. class TRights;
  19. class TRemoteFileList;
  20. class THierarchicalStorage;
  21. //---------------------------------------------------------------------------
  22. class TRemoteToken
  23. {
  24. public:
  25. __fastcall TRemoteToken();
  26. TRemoteToken(const TRemoteToken &) = default;
  27. explicit __fastcall TRemoteToken(const UnicodeString & Name);
  28. void __fastcall Clear();
  29. bool __fastcall operator ==(const TRemoteToken & rht) const;
  30. bool __fastcall operator !=(const TRemoteToken & rht) const;
  31. TRemoteToken & __fastcall operator =(const TRemoteToken & rht);
  32. int __fastcall Compare(const TRemoteToken & rht) const;
  33. __property UnicodeString Name = { read = FName, write = FName };
  34. __property bool NameValid = { read = GetNameValid };
  35. __property unsigned int ID = { read = FID, write = SetID };
  36. __property bool IDValid = { read = FIDValid };
  37. __property bool IsSet = { read = GetIsSet };
  38. __property UnicodeString LogText = { read = GetLogText };
  39. __property UnicodeString DisplayText = { read = GetDisplayText };
  40. private:
  41. UnicodeString FName;
  42. unsigned int FID;
  43. bool FIDValid;
  44. void __fastcall SetID(unsigned int value);
  45. bool __fastcall GetNameValid() const;
  46. bool __fastcall GetIsSet() const;
  47. UnicodeString __fastcall GetDisplayText() const;
  48. UnicodeString __fastcall GetLogText() const;
  49. };
  50. //---------------------------------------------------------------------------
  51. class TRemoteTokenList
  52. {
  53. public:
  54. TRemoteTokenList * __fastcall Duplicate() const;
  55. void __fastcall Clear();
  56. void __fastcall Add(const TRemoteToken & Token);
  57. void __fastcall AddUnique(const TRemoteToken & Token);
  58. bool __fastcall Exists(const UnicodeString & Name) const;
  59. const TRemoteToken * Find(unsigned int ID) const;
  60. const TRemoteToken * Find(const UnicodeString & Name) const;
  61. void __fastcall Log(TTerminal * Terminal, const wchar_t * Title);
  62. int __fastcall Count() const;
  63. const TRemoteToken * __fastcall Token(int Index) const;
  64. private:
  65. typedef std::vector<TRemoteToken> TTokens;
  66. typedef std::map<UnicodeString, size_t> TNameMap;
  67. typedef std::map<unsigned int, size_t> TIDMap;
  68. TTokens FTokens;
  69. TNameMap FNameMap;
  70. TIDMap FIDMap;
  71. };
  72. //---------------------------------------------------------------------------
  73. class TRemoteFile : public TPersistent
  74. {
  75. private:
  76. TRemoteFileList * FDirectory;
  77. TRemoteToken FOwner;
  78. TModificationFmt FModificationFmt;
  79. __int64 FSize;
  80. __int64 FCalculatedSize;
  81. UnicodeString FFileName;
  82. UnicodeString FDisplayName;
  83. Integer FINodeBlocks;
  84. TDateTime FModification;
  85. TDateTime FLastAccess;
  86. TRemoteToken FGroup;
  87. Integer FIconIndex;
  88. Boolean FIsSymLink;
  89. TRemoteFile * FLinkedFile;
  90. TRemoteFile * FLinkedByFile;
  91. UnicodeString FLinkTo;
  92. TRights *FRights;
  93. UnicodeString FHumanRights;
  94. TTerminal *FTerminal;
  95. wchar_t FType;
  96. UnicodeString FTags;
  97. bool FCyclicLink;
  98. UnicodeString FFullFileName;
  99. int FIsHidden;
  100. UnicodeString FTypeName;
  101. bool FIsEncrypted;
  102. int __fastcall GetAttr();
  103. bool __fastcall GetBrokenLink();
  104. bool __fastcall GetIsDirectory() const;
  105. const TRemoteFile * __fastcall GetLinkedFile() const;
  106. UnicodeString __fastcall GetModificationStr();
  107. void __fastcall SetModification(const TDateTime & value);
  108. void __fastcall SetListingStr(UnicodeString value);
  109. UnicodeString __fastcall GetListingStr();
  110. UnicodeString __fastcall GetRightsStr();
  111. wchar_t __fastcall GetType() const;
  112. void __fastcall SetType(wchar_t AType);
  113. void __fastcall SetTerminal(TTerminal * value);
  114. void __fastcall SetRights(TRights * value);
  115. UnicodeString __fastcall GetFullFileName() const;
  116. bool __fastcall GetHaveFullFileName() const;
  117. int __fastcall GetIconIndex() const;
  118. UnicodeString __fastcall GetTypeName();
  119. bool __fastcall GetIsHidden() const;
  120. void __fastcall SetIsHidden(bool value);
  121. bool __fastcall GetIsParentDirectory() const;
  122. bool __fastcall GetIsThisDirectory() const;
  123. bool __fastcall GetIsInaccessibleDirectory() const;
  124. UnicodeString __fastcall GetExtension();
  125. UnicodeString __fastcall GetUserModificationStr();
  126. void __fastcall LoadTypeInfo();
  127. __int64 __fastcall GetSize() const;
  128. protected:
  129. void __fastcall FindLinkedFile();
  130. public:
  131. __fastcall TRemoteFile(TRemoteFile * ALinkedByFile = NULL);
  132. virtual __fastcall ~TRemoteFile();
  133. TRemoteFile * __fastcall Duplicate(bool Standalone = true) const;
  134. void __fastcall ShiftTimeInSeconds(__int64 Seconds);
  135. bool __fastcall IsTimeShiftingApplicable();
  136. void __fastcall Complete();
  137. void __fastcall SetEncrypted();
  138. const TRemoteFile * __fastcall Resolve() const;
  139. static bool __fastcall IsTimeShiftingApplicable(TModificationFmt ModificationFmt);
  140. static void __fastcall ShiftTimeInSeconds(TDateTime & DateTime, TModificationFmt ModificationFmt, __int64 Seconds);
  141. __property int Attr = { read = GetAttr };
  142. __property bool BrokenLink = { read = GetBrokenLink };
  143. __property TRemoteFileList * Directory = { read = FDirectory, write = FDirectory };
  144. __property UnicodeString RightsStr = { read = GetRightsStr };
  145. __property __int64 Size = { read = GetSize, write = FSize };
  146. __property __int64 CalculatedSize = { read = FCalculatedSize, write = FCalculatedSize };
  147. __property TRemoteToken Owner = { read = FOwner, write = FOwner };
  148. __property TRemoteToken Group = { read = FGroup, write = FGroup };
  149. __property UnicodeString FileName = { read = FFileName, write = FFileName };
  150. __property UnicodeString DisplayName = { read = FDisplayName, write = FDisplayName };
  151. __property int INodeBlocks = { read = FINodeBlocks };
  152. __property TDateTime Modification = { read = FModification, write = SetModification };
  153. __property UnicodeString ModificationStr = { read = GetModificationStr };
  154. __property UnicodeString UserModificationStr = { read = GetUserModificationStr };
  155. __property TModificationFmt ModificationFmt = { read = FModificationFmt, write = FModificationFmt };
  156. __property TDateTime LastAccess = { read = FLastAccess, write = FLastAccess };
  157. __property bool IsSymLink = { read = FIsSymLink };
  158. __property bool IsDirectory = { read = GetIsDirectory };
  159. __property const TRemoteFile * LinkedFile = { read = GetLinkedFile };
  160. __property UnicodeString LinkTo = { read = FLinkTo, write = FLinkTo };
  161. __property UnicodeString ListingStr = { read = GetListingStr, write = SetListingStr };
  162. __property TRights * Rights = { read = FRights, write = SetRights };
  163. __property UnicodeString HumanRights = { read = FHumanRights, write = FHumanRights };
  164. __property TTerminal * Terminal = { read = FTerminal, write = SetTerminal };
  165. __property wchar_t Type = { read = GetType, write = SetType };
  166. __property UnicodeString FullFileName = { read = GetFullFileName, write = FFullFileName };
  167. __property bool HaveFullFileName = { read = GetHaveFullFileName };
  168. __property int IconIndex = { read = GetIconIndex };
  169. __property UnicodeString TypeName = { read = GetTypeName };
  170. __property UnicodeString Tags = { read = FTags, write = FTags };
  171. __property bool IsHidden = { read = GetIsHidden, write = SetIsHidden };
  172. __property bool IsParentDirectory = { read = GetIsParentDirectory };
  173. __property bool IsThisDirectory = { read = GetIsThisDirectory };
  174. __property bool IsInaccesibleDirectory = { read=GetIsInaccessibleDirectory };
  175. __property UnicodeString Extension = { read=GetExtension };
  176. __property bool IsEncrypted = { read = FIsEncrypted };
  177. };
  178. //---------------------------------------------------------------------------
  179. class TRemoteDirectoryFile : public TRemoteFile
  180. {
  181. public:
  182. __fastcall TRemoteDirectoryFile();
  183. };
  184. //---------------------------------------------------------------------------
  185. class TRemoteParentDirectory : public TRemoteDirectoryFile
  186. {
  187. public:
  188. __fastcall TRemoteParentDirectory(TTerminal * Terminal);
  189. };
  190. //---------------------------------------------------------------------------
  191. class TRemoteFileList : public TObjectList
  192. {
  193. friend class TSCPFileSystem;
  194. friend class TSFTPFileSystem;
  195. friend class TFTPFileSystem;
  196. friend class TWebDAVFileSystem;
  197. friend class TS3FileSystem;
  198. protected:
  199. UnicodeString FDirectory;
  200. TDateTime FTimestamp;
  201. TRemoteFile * __fastcall GetFiles(Integer Index);
  202. void SetDirectory(const UnicodeString & value);
  203. UnicodeString __fastcall GetFullDirectory();
  204. Boolean __fastcall GetIsRoot();
  205. TRemoteFile * __fastcall GetParentDirectory();
  206. UnicodeString __fastcall GetParentPath();
  207. __int64 __fastcall GetTotalSize();
  208. public:
  209. __fastcall TRemoteFileList();
  210. virtual void __fastcall Reset();
  211. TRemoteFile * __fastcall FindFile(const UnicodeString &FileName);
  212. virtual void __fastcall DuplicateTo(TRemoteFileList * Copy);
  213. virtual bool AddFile(TRemoteFile * File);
  214. virtual void ExtractFile(TRemoteFile * File);
  215. static TStrings * __fastcall CloneStrings(TStrings * List);
  216. static bool AnyDirectory(TStrings * List);
  217. __property UnicodeString Directory = { read = FDirectory, write = SetDirectory };
  218. __property TRemoteFile * Files[Integer Index] = { read = GetFiles };
  219. __property UnicodeString FullDirectory = { read=GetFullDirectory };
  220. __property Boolean IsRoot = { read = GetIsRoot };
  221. __property UnicodeString ParentPath = { read = GetParentPath };
  222. __property __int64 TotalSize = { read = GetTotalSize };
  223. __property TDateTime Timestamp = { read = FTimestamp };
  224. };
  225. //---------------------------------------------------------------------------
  226. class TRemoteDirectory : public TRemoteFileList
  227. {
  228. private:
  229. Boolean FIncludeParentDirectory;
  230. TTerminal * FTerminal;
  231. TRemoteFile * FParentDirectory;
  232. Boolean __fastcall GetLoaded();
  233. void __fastcall SetIncludeParentDirectory(Boolean value);
  234. void __fastcall ReleaseRelativeDirectories();
  235. public:
  236. __fastcall TRemoteDirectory(TTerminal * aTerminal, TRemoteDirectory * Template = NULL);
  237. virtual __fastcall ~TRemoteDirectory();
  238. virtual bool AddFile(TRemoteFile * File);
  239. virtual void __fastcall DuplicateTo(TRemoteFileList * Copy);
  240. virtual void __fastcall Reset();
  241. __property TTerminal * Terminal = { read = FTerminal };
  242. __property Boolean IncludeParentDirectory = { read = FIncludeParentDirectory, write = SetIncludeParentDirectory };
  243. __property Boolean Loaded = { read = GetLoaded };
  244. };
  245. //---------------------------------------------------------------------------
  246. class TRemoteDirectoryCache : private TStringList
  247. {
  248. public:
  249. __fastcall TRemoteDirectoryCache();
  250. virtual __fastcall ~TRemoteDirectoryCache();
  251. bool __fastcall HasFileList(const UnicodeString Directory);
  252. bool __fastcall HasNewerFileList(const UnicodeString Directory, TDateTime Timestamp);
  253. bool __fastcall GetFileList(const UnicodeString Directory,
  254. TRemoteFileList * FileList);
  255. void __fastcall AddFileList(TRemoteFileList * FileList);
  256. void __fastcall ClearFileList(UnicodeString Directory, bool SubDirs);
  257. void __fastcall Clear();
  258. __property bool IsEmpty = { read = GetIsEmpty };
  259. protected:
  260. virtual void __fastcall Delete(int Index);
  261. private:
  262. TCriticalSection * FSection;
  263. bool __fastcall GetIsEmpty() const;
  264. void __fastcall DoClearFileList(UnicodeString Directory, bool SubDirs);
  265. };
  266. //---------------------------------------------------------------------------
  267. class TRemoteDirectoryChangesCache : private TStringList
  268. {
  269. public:
  270. __fastcall TRemoteDirectoryChangesCache(int MaxSize);
  271. void __fastcall AddDirectoryChange(const UnicodeString SourceDir,
  272. const UnicodeString Change, const UnicodeString TargetDir);
  273. void __fastcall ClearDirectoryChange(UnicodeString SourceDir);
  274. void __fastcall ClearDirectoryChangeTarget(UnicodeString TargetDir);
  275. bool __fastcall GetDirectoryChange(const UnicodeString SourceDir,
  276. const UnicodeString Change, UnicodeString & TargetDir);
  277. void __fastcall Clear();
  278. void __fastcall Serialize(UnicodeString & Data);
  279. void __fastcall Deserialize(const UnicodeString Data);
  280. __property bool IsEmpty = { read = GetIsEmpty };
  281. private:
  282. static bool __fastcall DirectoryChangeKey(const UnicodeString SourceDir,
  283. const UnicodeString Change, UnicodeString & Key);
  284. bool __fastcall GetIsEmpty() const;
  285. void __fastcall SetValue(const UnicodeString & Name, const UnicodeString & Value);
  286. UnicodeString __fastcall GetValue(const UnicodeString & Name);
  287. int FMaxSize;
  288. };
  289. //---------------------------------------------------------------------------
  290. class TRights
  291. {
  292. public:
  293. static const int TextLen = 9;
  294. static const wchar_t UndefSymbol = L'$';
  295. static const wchar_t UnsetSymbol = L'-';
  296. // Used by Win32-OpenSSH for permissions that are not applicable on Windows.
  297. // See strmode() in contrib\win32\win32compat\misc.c
  298. static const wchar_t UnsetSymbolWin = L'*';
  299. static const wchar_t BasicSymbols[];
  300. static const wchar_t CombinedSymbols[];
  301. static const wchar_t ExtendedSymbols[];
  302. static const wchar_t ModeGroups[];
  303. enum TRightLevel {
  304. rlNone = -1,
  305. rlRead, rlWrite, rlExec, rlSpecial,
  306. rlFirst = rlRead, rlLastNormal = rlExec, rlLastWithSpecial = rlSpecial,
  307. rlS3Read = rlRead, rlS3Write = rlWrite, rlS3ReadACP = rlExec, rlS3WriteACP = rlSpecial, rlLastAcl = rlLastWithSpecial,
  308. };
  309. enum TRightGroup {
  310. rgUser, rgGroup, rgOther,
  311. rgFirst = rgUser, rgLast = rgOther,
  312. rgS3AllAwsUsers = rgGroup, rgS3AllUsers = rgOther,
  313. };
  314. enum TRight {
  315. rrUserIDExec, rrGroupIDExec, rrStickyBit,
  316. rrUserRead, rrUserWrite, rrUserExec,
  317. rrGroupRead, rrGroupWrite, rrGroupExec,
  318. rrOtherRead, rrOtherWrite, rrOtherExec,
  319. rrFirst = rrUserIDExec, rrLast = rrOtherExec };
  320. enum TFlag {
  321. rfSetUID = 04000, rfSetGID = 02000, rfStickyBit = 01000,
  322. rfUserRead = 00400, rfUserWrite = 00200, rfUserExec = 00100,
  323. rfGroupRead = 00040, rfGroupWrite = 00020, rfGroupExec = 00010,
  324. rfOtherRead = 00004, rfOtherWrite = 00002, rfOtherExec = 00001,
  325. rfRead = 00444, rfWrite = 00222, rfExec = 00111,
  326. rfNo = 00000, rfDefault = 00644, rfAll = 00777,
  327. rfSpecials = 07000, rfAllSpecials = 07777,
  328. rfS3Read = rfOtherRead, rfS3Write = rfOtherWrite, rfS3ReadACP = rfOtherExec, rfS3WriteACP = rfStickyBit,
  329. };
  330. enum TUnsupportedFlag {
  331. rfDirectory = 040000 };
  332. enum TState { rsNo, rsYes, rsUndef };
  333. public:
  334. static TFlag __fastcall RightToFlag(TRight Right);
  335. static TRight CalculateRight(TRightGroup Group, TRightLevel Level);
  336. static TFlag CalculateFlag(TRightGroup Group, TRightLevel Level);
  337. static unsigned short CalculatePermissions(TRightGroup Group, TRightLevel Level, TRightLevel Level2 = rlNone, TRightLevel Level3 = rlNone);
  338. __fastcall TRights();
  339. __fastcall TRights(const TRights & Source);
  340. __fastcall TRights(unsigned short Number);
  341. void __fastcall Assign(const TRights * Source);
  342. void __fastcall AddExecute();
  343. void __fastcall AllUndef();
  344. TRights Combine(const TRights & Other) const;
  345. void SetTextOverride(const UnicodeString & value);
  346. bool __fastcall operator ==(const TRights & rhr) const;
  347. bool __fastcall operator ==(unsigned short rhr) const;
  348. bool __fastcall operator !=(const TRights & rhr) const;
  349. TRights & __fastcall operator =(const TRights & rhr);
  350. TRights & __fastcall operator =(unsigned short rhr);
  351. TRights __fastcall operator ~() const;
  352. TRights __fastcall operator &(unsigned short rhr) const;
  353. TRights __fastcall operator &(const TRights & rhr) const;
  354. TRights & __fastcall operator &=(unsigned short rhr);
  355. TRights & __fastcall operator &=(const TRights & rhr);
  356. TRights __fastcall operator |(unsigned short rhr) const;
  357. TRights __fastcall operator |(const TRights & rhr) const;
  358. TRights & __fastcall operator |=(unsigned short rhr);
  359. TRights & __fastcall operator |=(const TRights & rhr);
  360. __fastcall operator unsigned short() const;
  361. __fastcall operator unsigned long() const;
  362. UnicodeString __fastcall GetChmodStr(int Directory) const;
  363. __property bool AllowUndef = { read = FAllowUndef, write = SetAllowUndef };
  364. __property bool IsUndef = { read = GetIsUndef };
  365. __property UnicodeString ModeStr = { read = GetModeStr };
  366. __property UnicodeString Octal = { read = GetOctal, write = SetOctal };
  367. __property unsigned short Number = { read = GetNumber, write = SetNumber };
  368. __property unsigned short NumberSet = { read = FSet };
  369. __property unsigned short NumberUnset = { read = FUnset };
  370. __property unsigned long NumberDecadic = { read = GetNumberDecadic };
  371. __property bool ReadOnly = { read = GetReadOnly, write = SetReadOnly };
  372. __property bool Right[TRight Right] = { read = GetRight, write = SetRight };
  373. __property TState RightUndef[TRight Right] = { read = GetRightUndef, write = SetRightUndef };
  374. __property UnicodeString Text = { read = GetText, write = SetText };
  375. __property bool Unknown = { read = FUnknown };
  376. private:
  377. bool FAllowUndef;
  378. unsigned short FSet;
  379. unsigned short FUnset;
  380. UnicodeString FText;
  381. bool FUnknown;
  382. bool __fastcall GetIsUndef() const;
  383. UnicodeString __fastcall GetModeStr() const;
  384. void __fastcall SetNumber(unsigned short value);
  385. UnicodeString __fastcall GetText() const;
  386. void __fastcall SetText(const UnicodeString & value);
  387. void __fastcall SetOctal(UnicodeString value);
  388. unsigned short __fastcall GetNumber() const;
  389. unsigned short __fastcall GetNumberSet() const;
  390. unsigned short __fastcall GetNumberUnset() const;
  391. unsigned long __fastcall GetNumberDecadic() const;
  392. UnicodeString __fastcall GetOctal() const;
  393. bool __fastcall GetReadOnly();
  394. bool __fastcall GetRight(TRight Right) const;
  395. TState __fastcall GetRightUndef(TRight Right) const;
  396. void __fastcall SetAllowUndef(bool value);
  397. void __fastcall SetReadOnly(bool value);
  398. void __fastcall SetRight(TRight Right, bool value);
  399. void __fastcall SetRightUndef(TRight Right, TState value);
  400. };
  401. //---------------------------------------------------------------------------
  402. enum TValidProperty { vpRights, vpGroup, vpOwner, vpModification, vpLastAccess, vpEncrypt, vpTags };
  403. typedef Set<TValidProperty, vpRights, vpTags> TValidProperties;
  404. class TRemoteProperties
  405. {
  406. public:
  407. TValidProperties Valid;
  408. bool Recursive;
  409. TRights Rights;
  410. bool AddXToDirectories;
  411. TRemoteToken Group;
  412. TRemoteToken Owner;
  413. __int64 Modification; // unix time
  414. __int64 LastAccess; // unix time
  415. bool Encrypt;
  416. UnicodeString Tags;
  417. __fastcall TRemoteProperties();
  418. __fastcall TRemoteProperties(const TRemoteProperties & rhp);
  419. TRemoteProperties & operator =(const TRemoteProperties &) = default;
  420. bool __fastcall operator ==(const TRemoteProperties & rhp) const;
  421. bool __fastcall operator !=(const TRemoteProperties & rhp) const;
  422. void __fastcall Default();
  423. void __fastcall Load(THierarchicalStorage * Storage);
  424. void __fastcall Save(THierarchicalStorage * Storage) const;
  425. static TRemoteProperties __fastcall CommonProperties(TStrings * FileList);
  426. static TRemoteProperties __fastcall ChangedProperties(
  427. const TRemoteProperties & OriginalProperties, TRemoteProperties NewProperties);
  428. };
  429. //---------------------------------------------------------------------------
  430. class TSynchronizeChecklist
  431. {
  432. friend class TTerminal;
  433. public:
  434. enum TAction {
  435. saNone, saUploadNew, saDownloadNew, saUploadUpdate, saDownloadUpdate, saDeleteRemote, saDeleteLocal };
  436. static const int ActionCount = saDeleteLocal;
  437. class TItem
  438. {
  439. friend class TTerminal;
  440. friend class TSynchronizeChecklist;
  441. public:
  442. struct TFileInfo
  443. {
  444. UnicodeString FileName;
  445. UnicodeString Directory;
  446. TDateTime Modification;
  447. TModificationFmt ModificationFmt;
  448. __int64 Size;
  449. };
  450. TAction Action;
  451. bool IsDirectory;
  452. TFileInfo Local;
  453. TFileInfo Remote;
  454. int ImageIndex;
  455. bool Checked;
  456. TRemoteFile * RemoteFile;
  457. const UnicodeString& GetFileName() const;
  458. bool IsRemoteOnly() const { return (Action == saDownloadNew) || (Action == saDeleteRemote); }
  459. bool IsLocalOnly() const { return (Action == saUploadNew) || (Action == saDeleteLocal); }
  460. bool HasSize() const { return !IsDirectory || FDirectoryHasSize; }
  461. __int64 __fastcall GetBaseSize() const;
  462. __int64 __fastcall GetSize() const;
  463. __int64 __fastcall GetSize(TAction AAction) const;
  464. UnicodeString GetLocalPath() const;
  465. UnicodeString ForceGetLocalPath() const;
  466. // Contrary to RemoteFile->FullFileName, this does not include trailing slash for directories
  467. UnicodeString GetRemotePath() const;
  468. UnicodeString ForceGetRemotePath() const;
  469. UnicodeString GetLocalTarget() const;
  470. UnicodeString GetRemoteTarget() const;
  471. TStrings * GetFileList() const;
  472. ~TItem();
  473. private:
  474. FILETIME FLocalLastWriteTime;
  475. bool FDirectoryHasSize;
  476. TItem();
  477. __int64 __fastcall GetBaseSize(TAction AAction) const;
  478. };
  479. typedef std::vector<const TSynchronizeChecklist::TItem *> TItemList;
  480. ~TSynchronizeChecklist();
  481. void __fastcall Update(const TItem * Item, bool Check, TAction Action);
  482. void __fastcall UpdateDirectorySize(const TItem * Item, __int64 Size);
  483. void Delete(const TItem * Item);
  484. static TAction __fastcall Reverse(TAction Action);
  485. static bool __fastcall IsItemSizeIrrelevant(TAction Action);
  486. bool GetNextChecked(int & Index, const TItem *& Item) const;
  487. __property int Count = { read = GetCount };
  488. __property int CheckedCount = { read = GetCheckedCount };
  489. __property const TItem * Item[int Index] = { read = GetItem };
  490. static int Compare(const TItem * Item1, const TItem * Item2);
  491. protected:
  492. TSynchronizeChecklist();
  493. void Sort();
  494. void Add(TItem * Item);
  495. int GetCount() const;
  496. int GetCheckedCount() const;
  497. const TItem * GetItem(int Index) const;
  498. private:
  499. TList * FList;
  500. static int __fastcall Compare(void * Item1, void * Item2);
  501. };
  502. //---------------------------------------------------------------------------
  503. class TFileOperationProgressType;
  504. //---------------------------------------------------------------------------
  505. class TSynchronizeProgress
  506. {
  507. public:
  508. TSynchronizeProgress(const TSynchronizeChecklist * Checklist);
  509. void ItemProcessed(const TSynchronizeChecklist::TItem * ChecklistItem);
  510. int Progress(const TFileOperationProgressType * CurrentItemOperationProgress) const;
  511. TDateTime TimeLeft(const TFileOperationProgressType * CurrentItemOperationProgress) const;
  512. private:
  513. const TSynchronizeChecklist * FChecklist;
  514. mutable __int64 FTotalSize;
  515. __int64 FProcessedSize;
  516. __int64 ItemSize(const TSynchronizeChecklist::TItem * ChecklistItem) const;
  517. __int64 GetProcessed(const TFileOperationProgressType * CurrentItemOperationProgress) const;
  518. };
  519. //---------------------------------------------------------------------------
  520. bool __fastcall IsUnixStyleWindowsPath(const UnicodeString & Path);
  521. bool __fastcall UnixIsAbsolutePath(const UnicodeString & Path);
  522. UnicodeString __fastcall UnixIncludeTrailingBackslash(const UnicodeString & Path);
  523. UnicodeString __fastcall UnixExcludeTrailingBackslash(const UnicodeString & Path, bool Simple = false);
  524. UnicodeString __fastcall SimpleUnixExcludeTrailingBackslash(const UnicodeString & Path);
  525. UnicodeString __fastcall UnixCombinePaths(const UnicodeString & Path1, const UnicodeString & Path2);
  526. UnicodeString UnixCombinePathsForce(const UnicodeString & Path1, const UnicodeString & Path2);
  527. UnicodeString UnixCombinePathsSmart(const UnicodeString & Path1, const UnicodeString & Path2);
  528. UnicodeString __fastcall UnixExtractFileDir(const UnicodeString & Path);
  529. UnicodeString __fastcall UnixExtractFilePath(const UnicodeString & Path);
  530. UnicodeString __fastcall UnixExtractFileName(const UnicodeString & Path);
  531. UnicodeString ExtractShortName(const UnicodeString & Path, bool Unix);
  532. UnicodeString __fastcall UnixExtractFileExt(const UnicodeString & Path);
  533. Boolean __fastcall UnixSamePath(const UnicodeString & Path1, const UnicodeString & Path2);
  534. bool __fastcall UnixIsChildPath(const UnicodeString & Parent, const UnicodeString & Child);
  535. bool __fastcall ExtractCommonPath(TStrings * Files, UnicodeString & Path);
  536. bool __fastcall UnixExtractCommonPath(TStrings * Files, UnicodeString & Path);
  537. UnicodeString __fastcall ExtractFileName(const UnicodeString & Path, bool Unix);
  538. bool __fastcall IsUnixRootPath(const UnicodeString & Path);
  539. bool __fastcall IsUnixHiddenFile(const UnicodeString & Path);
  540. UnicodeString __fastcall AbsolutePath(const UnicodeString & Base, const UnicodeString & Path);
  541. UnicodeString __fastcall FromUnixPath(const UnicodeString & Path);
  542. UnicodeString __fastcall ToUnixPath(const UnicodeString & Path);
  543. UnicodeString __fastcall MinimizeName(const UnicodeString & FileName, int MaxLen, bool Unix);
  544. UnicodeString __fastcall MakeFileList(TStrings * FileList);
  545. TDateTime __fastcall ReduceDateTimePrecision(TDateTime DateTime,
  546. TModificationFmt Precision);
  547. TModificationFmt __fastcall LessDateTimePrecision(
  548. TModificationFmt Precision1, TModificationFmt Precision2);
  549. UnicodeString __fastcall UserModificationStr(TDateTime DateTime,
  550. TModificationFmt Precision);
  551. UnicodeString __fastcall ModificationStr(TDateTime DateTime,
  552. TModificationFmt Precision);
  553. int GetPartialFileExtLen(const UnicodeString & FileName);
  554. int __fastcall FakeFileImageIndex(UnicodeString FileName, unsigned long Attrs = 0,
  555. UnicodeString * TypeName = NULL);
  556. bool __fastcall SameUserName(const UnicodeString & UserName1, const UnicodeString & UserName2);
  557. UnicodeString __fastcall FormatMultiFilesToOneConfirmation(const UnicodeString & Target, bool Unix);
  558. //---------------------------------------------------------------------------
  559. #endif