1
0

RemoteFiles.h 26 KB

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