RemoteFiles.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. virtual void ExtractFile(TRemoteFile * File);
  214. static TStrings * __fastcall CloneStrings(TStrings * List);
  215. static bool AnyDirectory(TStrings * List);
  216. __property UnicodeString Directory = { read = FDirectory, write = SetDirectory };
  217. __property TRemoteFile * Files[Integer Index] = { read = GetFiles };
  218. __property UnicodeString FullDirectory = { read=GetFullDirectory };
  219. __property Boolean IsRoot = { read = GetIsRoot };
  220. __property UnicodeString ParentPath = { read = GetParentPath };
  221. __property __int64 TotalSize = { read = GetTotalSize };
  222. __property TDateTime Timestamp = { read = FTimestamp };
  223. };
  224. //---------------------------------------------------------------------------
  225. class TRemoteDirectory : public TRemoteFileList
  226. {
  227. friend class TSCPFileSystem;
  228. friend class TSFTPFileSystem;
  229. private:
  230. Boolean FIncludeParentDirectory;
  231. Boolean FIncludeThisDirectory;
  232. TTerminal * FTerminal;
  233. TRemoteFile * FParentDirectory;
  234. TRemoteFile * FThisDirectory;
  235. virtual void __fastcall SetDirectory(UnicodeString value);
  236. Boolean __fastcall GetLoaded();
  237. void __fastcall SetIncludeParentDirectory(Boolean value);
  238. void __fastcall SetIncludeThisDirectory(Boolean value);
  239. void __fastcall ReleaseRelativeDirectories();
  240. public:
  241. __fastcall TRemoteDirectory(TTerminal * aTerminal, TRemoteDirectory * Template = NULL);
  242. virtual __fastcall ~TRemoteDirectory();
  243. virtual void __fastcall AddFile(TRemoteFile * File);
  244. virtual void __fastcall DuplicateTo(TRemoteFileList * Copy);
  245. virtual void __fastcall Reset();
  246. __property TTerminal * Terminal = { read = FTerminal, write = FTerminal };
  247. __property Boolean IncludeParentDirectory = { read = FIncludeParentDirectory, write = SetIncludeParentDirectory };
  248. __property Boolean IncludeThisDirectory = { read = FIncludeThisDirectory, write = SetIncludeThisDirectory };
  249. __property Boolean Loaded = { read = GetLoaded };
  250. __property TRemoteFile * ParentDirectory = { read = FParentDirectory };
  251. __property TRemoteFile * ThisDirectory = { read = FThisDirectory };
  252. };
  253. //---------------------------------------------------------------------------
  254. class TRemoteDirectoryCache : private TStringList
  255. {
  256. public:
  257. __fastcall TRemoteDirectoryCache();
  258. virtual __fastcall ~TRemoteDirectoryCache();
  259. bool __fastcall HasFileList(const UnicodeString Directory);
  260. bool __fastcall HasNewerFileList(const UnicodeString Directory, TDateTime Timestamp);
  261. bool __fastcall GetFileList(const UnicodeString Directory,
  262. TRemoteFileList * FileList);
  263. void __fastcall AddFileList(TRemoteFileList * FileList);
  264. void __fastcall ClearFileList(UnicodeString Directory, bool SubDirs);
  265. void __fastcall Clear();
  266. __property bool IsEmpty = { read = GetIsEmpty };
  267. protected:
  268. virtual void __fastcall Delete(int Index);
  269. private:
  270. TCriticalSection * FSection;
  271. bool __fastcall GetIsEmpty() const;
  272. void __fastcall DoClearFileList(UnicodeString Directory, bool SubDirs);
  273. };
  274. //---------------------------------------------------------------------------
  275. class TRemoteDirectoryChangesCache : private TStringList
  276. {
  277. public:
  278. __fastcall TRemoteDirectoryChangesCache(int MaxSize);
  279. void __fastcall AddDirectoryChange(const UnicodeString SourceDir,
  280. const UnicodeString Change, const UnicodeString TargetDir);
  281. void __fastcall ClearDirectoryChange(UnicodeString SourceDir);
  282. void __fastcall ClearDirectoryChangeTarget(UnicodeString TargetDir);
  283. bool __fastcall GetDirectoryChange(const UnicodeString SourceDir,
  284. const UnicodeString Change, UnicodeString & TargetDir);
  285. void __fastcall Clear();
  286. void __fastcall Serialize(UnicodeString & Data);
  287. void __fastcall Deserialize(const UnicodeString Data);
  288. __property bool IsEmpty = { read = GetIsEmpty };
  289. private:
  290. static bool __fastcall DirectoryChangeKey(const UnicodeString SourceDir,
  291. const UnicodeString Change, UnicodeString & Key);
  292. bool __fastcall GetIsEmpty() const;
  293. void __fastcall SetValue(const UnicodeString & Name, const UnicodeString & Value);
  294. UnicodeString __fastcall GetValue(const UnicodeString & Name);
  295. int FMaxSize;
  296. };
  297. //---------------------------------------------------------------------------
  298. class TRights
  299. {
  300. public:
  301. static const int TextLen = 9;
  302. static const wchar_t UndefSymbol = L'$';
  303. static const wchar_t UnsetSymbol = L'-';
  304. // Used by Win32-OpenSSH for permissions that are not applicable on Windows.
  305. // See strmode() in contrib\win32\win32compat\misc.c
  306. static const wchar_t UnsetSymbolWin = L'*';
  307. static const wchar_t BasicSymbols[];
  308. static const wchar_t CombinedSymbols[];
  309. static const wchar_t ExtendedSymbols[];
  310. static const wchar_t ModeGroups[];
  311. enum TRightLevel {
  312. rlNone = -1,
  313. rlRead, rlWrite, rlExec, rlSpecial,
  314. rlFirst = rlRead, rlLastNormal = rlExec, rlLastWithSpecial = rlSpecial,
  315. rlS3Read = rlRead, rlS3Write = rlWrite, rlS3ReadACP = rlExec, rlS3WriteACP = rlSpecial, rlLastAcl = rlLastWithSpecial,
  316. };
  317. enum TRightGroup {
  318. rgUser, rgGroup, rgOther,
  319. rgFirst = rgUser, rgLast = rgOther,
  320. rgS3AllAwsUsers = rgGroup, rgS3AllUsers = rgOther,
  321. };
  322. enum TRight {
  323. rrUserIDExec, rrGroupIDExec, rrStickyBit,
  324. rrUserRead, rrUserWrite, rrUserExec,
  325. rrGroupRead, rrGroupWrite, rrGroupExec,
  326. rrOtherRead, rrOtherWrite, rrOtherExec,
  327. rrFirst = rrUserIDExec, rrLast = rrOtherExec };
  328. enum TFlag {
  329. rfSetUID = 04000, rfSetGID = 02000, rfStickyBit = 01000,
  330. rfUserRead = 00400, rfUserWrite = 00200, rfUserExec = 00100,
  331. rfGroupRead = 00040, rfGroupWrite = 00020, rfGroupExec = 00010,
  332. rfOtherRead = 00004, rfOtherWrite = 00002, rfOtherExec = 00001,
  333. rfRead = 00444, rfWrite = 00222, rfExec = 00111,
  334. rfNo = 00000, rfDefault = 00644, rfAll = 00777,
  335. rfSpecials = 07000, rfAllSpecials = 07777,
  336. rfS3Read = rfOtherRead, rfS3Write = rfOtherWrite, rfS3ReadACP = rfOtherExec, rfS3WriteACP = rfStickyBit,
  337. };
  338. enum TUnsupportedFlag {
  339. rfDirectory = 040000 };
  340. enum TState { rsNo, rsYes, rsUndef };
  341. public:
  342. static TFlag __fastcall RightToFlag(TRight Right);
  343. static TRight CalculateRight(TRightGroup Group, TRightLevel Level);
  344. static TFlag CalculateFlag(TRightGroup Group, TRightLevel Level);
  345. static unsigned short CalculatePermissions(TRightGroup Group, TRightLevel Level, TRightLevel Level2 = rlNone, TRightLevel Level3 = rlNone);
  346. __fastcall TRights();
  347. __fastcall TRights(const TRights & Source);
  348. __fastcall TRights(unsigned short Number);
  349. void __fastcall Assign(const TRights * Source);
  350. void __fastcall AddExecute();
  351. void __fastcall AllUndef();
  352. TRights Combine(const TRights & Other) const;
  353. void SetTextOverride(const UnicodeString & value);
  354. bool __fastcall operator ==(const TRights & rhr) const;
  355. bool __fastcall operator ==(unsigned short rhr) const;
  356. bool __fastcall operator !=(const TRights & rhr) const;
  357. TRights & __fastcall operator =(const TRights & rhr);
  358. TRights & __fastcall operator =(unsigned short rhr);
  359. TRights __fastcall operator ~() const;
  360. TRights __fastcall operator &(unsigned short rhr) const;
  361. TRights __fastcall operator &(const TRights & rhr) const;
  362. TRights & __fastcall operator &=(unsigned short rhr);
  363. TRights & __fastcall operator &=(const TRights & rhr);
  364. TRights __fastcall operator |(unsigned short rhr) const;
  365. TRights __fastcall operator |(const TRights & rhr) const;
  366. TRights & __fastcall operator |=(unsigned short rhr);
  367. TRights & __fastcall operator |=(const TRights & rhr);
  368. __fastcall operator unsigned short() const;
  369. __fastcall operator unsigned long() const;
  370. UnicodeString __fastcall GetChmodStr(int Directory) const;
  371. __property bool AllowUndef = { read = FAllowUndef, write = SetAllowUndef };
  372. __property bool IsUndef = { read = GetIsUndef };
  373. __property UnicodeString ModeStr = { read = GetModeStr };
  374. __property UnicodeString Octal = { read = GetOctal, write = SetOctal };
  375. __property unsigned short Number = { read = GetNumber, write = SetNumber };
  376. __property unsigned short NumberSet = { read = FSet };
  377. __property unsigned short NumberUnset = { read = FUnset };
  378. __property unsigned long NumberDecadic = { read = GetNumberDecadic };
  379. __property bool ReadOnly = { read = GetReadOnly, write = SetReadOnly };
  380. __property bool Right[TRight Right] = { read = GetRight, write = SetRight };
  381. __property TState RightUndef[TRight Right] = { read = GetRightUndef, write = SetRightUndef };
  382. __property UnicodeString Text = { read = GetText, write = SetText };
  383. __property bool Unknown = { read = FUnknown };
  384. private:
  385. bool FAllowUndef;
  386. unsigned short FSet;
  387. unsigned short FUnset;
  388. UnicodeString FText;
  389. bool FUnknown;
  390. bool __fastcall GetIsUndef() const;
  391. UnicodeString __fastcall GetModeStr() const;
  392. void __fastcall SetNumber(unsigned short value);
  393. UnicodeString __fastcall GetText() const;
  394. void __fastcall SetText(const UnicodeString & value);
  395. void __fastcall SetOctal(UnicodeString value);
  396. unsigned short __fastcall GetNumber() const;
  397. unsigned short __fastcall GetNumberSet() const;
  398. unsigned short __fastcall GetNumberUnset() const;
  399. unsigned long __fastcall GetNumberDecadic() const;
  400. UnicodeString __fastcall GetOctal() const;
  401. bool __fastcall GetReadOnly();
  402. bool __fastcall GetRight(TRight Right) const;
  403. TState __fastcall GetRightUndef(TRight Right) const;
  404. void __fastcall SetAllowUndef(bool value);
  405. void __fastcall SetReadOnly(bool value);
  406. void __fastcall SetRight(TRight Right, bool value);
  407. void __fastcall SetRightUndef(TRight Right, TState value);
  408. };
  409. //---------------------------------------------------------------------------
  410. enum TValidProperty { vpRights, vpGroup, vpOwner, vpModification, vpLastAccess, vpEncrypt, vpTags };
  411. typedef Set<TValidProperty, vpRights, vpTags> TValidProperties;
  412. class TRemoteProperties
  413. {
  414. public:
  415. TValidProperties Valid;
  416. bool Recursive;
  417. TRights Rights;
  418. bool AddXToDirectories;
  419. TRemoteToken Group;
  420. TRemoteToken Owner;
  421. __int64 Modification; // unix time
  422. __int64 LastAccess; // unix time
  423. bool Encrypt;
  424. UnicodeString Tags;
  425. __fastcall TRemoteProperties();
  426. __fastcall TRemoteProperties(const TRemoteProperties & rhp);
  427. bool __fastcall operator ==(const TRemoteProperties & rhp) const;
  428. bool __fastcall operator !=(const TRemoteProperties & rhp) const;
  429. void __fastcall Default();
  430. void __fastcall Load(THierarchicalStorage * Storage);
  431. void __fastcall Save(THierarchicalStorage * Storage) const;
  432. static TRemoteProperties __fastcall CommonProperties(TStrings * FileList);
  433. static TRemoteProperties __fastcall ChangedProperties(
  434. const TRemoteProperties & OriginalProperties, TRemoteProperties NewProperties);
  435. };
  436. //---------------------------------------------------------------------------
  437. class TSynchronizeChecklist
  438. {
  439. friend class TTerminal;
  440. public:
  441. enum TAction {
  442. saNone, saUploadNew, saDownloadNew, saUploadUpdate, saDownloadUpdate, saDeleteRemote, saDeleteLocal };
  443. static const int ActionCount = saDeleteLocal;
  444. class TItem
  445. {
  446. friend class TTerminal;
  447. friend class TSynchronizeChecklist;
  448. public:
  449. struct TFileInfo
  450. {
  451. UnicodeString FileName;
  452. UnicodeString Directory;
  453. TDateTime Modification;
  454. TModificationFmt ModificationFmt;
  455. __int64 Size;
  456. };
  457. TAction Action;
  458. bool IsDirectory;
  459. TFileInfo Local;
  460. TFileInfo Remote;
  461. int ImageIndex;
  462. bool Checked;
  463. TRemoteFile * RemoteFile;
  464. const UnicodeString& GetFileName() const;
  465. bool IsRemoteOnly() const { return (Action == saDownloadNew) || (Action == saDeleteRemote); }
  466. bool IsLocalOnly() const { return (Action == saUploadNew) || (Action == saDeleteLocal); }
  467. bool HasSize() const { return !IsDirectory || FDirectoryHasSize; }
  468. __int64 __fastcall GetBaseSize() const;
  469. __int64 __fastcall GetSize() const;
  470. __int64 __fastcall GetSize(TAction AAction) const;
  471. UnicodeString GetLocalPath() const;
  472. // Contrary to RemoteFile->FullFileName, this does not include trailing slash for directories
  473. UnicodeString GetRemotePath() const;
  474. UnicodeString GetLocalTarget() const;
  475. UnicodeString GetRemoteTarget() const;
  476. TStrings * GetFileList() const;
  477. ~TItem();
  478. private:
  479. FILETIME FLocalLastWriteTime;
  480. bool FDirectoryHasSize;
  481. TItem();
  482. __int64 __fastcall GetBaseSize(TAction AAction) const;
  483. };
  484. typedef std::vector<const TSynchronizeChecklist::TItem *> TItemList;
  485. ~TSynchronizeChecklist();
  486. void __fastcall Update(const TItem * Item, bool Check, TAction Action);
  487. void __fastcall UpdateDirectorySize(const TItem * Item, __int64 Size);
  488. void Delete(const TItem * Item);
  489. static TAction __fastcall Reverse(TAction Action);
  490. static bool __fastcall IsItemSizeIrrelevant(TAction Action);
  491. bool GetNextChecked(int & Index, const TItem *& Item) const;
  492. __property int Count = { read = GetCount };
  493. __property int CheckedCount = { read = GetCheckedCount };
  494. __property const TItem * Item[int Index] = { read = GetItem };
  495. static int Compare(const TItem * Item1, const TItem * Item2);
  496. protected:
  497. TSynchronizeChecklist();
  498. void Sort();
  499. void Add(TItem * Item);
  500. int GetCount() const;
  501. int GetCheckedCount() const;
  502. const TItem * GetItem(int Index) const;
  503. private:
  504. TList * FList;
  505. static int __fastcall Compare(void * Item1, void * Item2);
  506. };
  507. //---------------------------------------------------------------------------
  508. class TFileOperationProgressType;
  509. //---------------------------------------------------------------------------
  510. class TSynchronizeProgress
  511. {
  512. public:
  513. TSynchronizeProgress(const TSynchronizeChecklist * Checklist);
  514. void ItemProcessed(const TSynchronizeChecklist::TItem * ChecklistItem);
  515. int Progress(const TFileOperationProgressType * CurrentItemOperationProgress) const;
  516. TDateTime TimeLeft(const TFileOperationProgressType * CurrentItemOperationProgress) const;
  517. private:
  518. const TSynchronizeChecklist * FChecklist;
  519. mutable __int64 FTotalSize;
  520. __int64 FProcessedSize;
  521. __int64 ItemSize(const TSynchronizeChecklist::TItem * ChecklistItem) const;
  522. __int64 GetProcessed(const TFileOperationProgressType * CurrentItemOperationProgress) const;
  523. };
  524. //---------------------------------------------------------------------------
  525. bool __fastcall IsUnixStyleWindowsPath(const UnicodeString & Path);
  526. bool __fastcall UnixIsAbsolutePath(const UnicodeString & Path);
  527. UnicodeString __fastcall UnixIncludeTrailingBackslash(const UnicodeString & Path);
  528. UnicodeString __fastcall UnixExcludeTrailingBackslash(const UnicodeString & Path, bool Simple = false);
  529. UnicodeString __fastcall SimpleUnixExcludeTrailingBackslash(const UnicodeString & Path);
  530. UnicodeString __fastcall UnixCombinePaths(const UnicodeString & Path1, const UnicodeString & Path2);
  531. UnicodeString __fastcall UnixExtractFileDir(const UnicodeString & Path);
  532. UnicodeString __fastcall UnixExtractFilePath(const UnicodeString & Path);
  533. UnicodeString __fastcall UnixExtractFileName(const UnicodeString & Path);
  534. UnicodeString ExtractShortName(const UnicodeString & Path, bool Unix);
  535. UnicodeString __fastcall UnixExtractFileExt(const UnicodeString & Path);
  536. Boolean __fastcall UnixSamePath(const UnicodeString & Path1, const UnicodeString & Path2);
  537. bool __fastcall UnixIsChildPath(const UnicodeString & Parent, const UnicodeString & Child);
  538. bool __fastcall ExtractCommonPath(TStrings * Files, UnicodeString & Path);
  539. bool __fastcall UnixExtractCommonPath(TStrings * Files, UnicodeString & Path);
  540. UnicodeString __fastcall ExtractFileName(const UnicodeString & Path, bool Unix);
  541. bool __fastcall IsUnixRootPath(const UnicodeString & Path);
  542. bool __fastcall IsUnixHiddenFile(const UnicodeString & Path);
  543. UnicodeString __fastcall AbsolutePath(const UnicodeString & Base, const UnicodeString & Path);
  544. UnicodeString __fastcall FromUnixPath(const UnicodeString & Path);
  545. UnicodeString __fastcall ToUnixPath(const UnicodeString & Path);
  546. UnicodeString __fastcall MinimizeName(const UnicodeString & FileName, int MaxLen, bool Unix);
  547. UnicodeString __fastcall MakeFileList(TStrings * FileList);
  548. TDateTime __fastcall ReduceDateTimePrecision(TDateTime DateTime,
  549. TModificationFmt Precision);
  550. TModificationFmt __fastcall LessDateTimePrecision(
  551. TModificationFmt Precision1, TModificationFmt Precision2);
  552. UnicodeString __fastcall UserModificationStr(TDateTime DateTime,
  553. TModificationFmt Precision);
  554. UnicodeString __fastcall ModificationStr(TDateTime DateTime,
  555. TModificationFmt Precision);
  556. int GetPartialFileExtLen(const UnicodeString & FileName);
  557. int __fastcall FakeFileImageIndex(UnicodeString FileName, unsigned long Attrs = 0,
  558. UnicodeString * TypeName = NULL);
  559. bool __fastcall SameUserName(const UnicodeString & UserName1, const UnicodeString & UserName2);
  560. UnicodeString __fastcall FormatMultiFilesToOneConfirmation(const UnicodeString & Target, bool Unix);
  561. //---------------------------------------------------------------------------
  562. #endif