Terminal.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. //---------------------------------------------------------------------------
  2. #ifndef TerminalH
  3. #define TerminalH
  4. #include <Classes.hpp>
  5. #include "SessionInfo.h"
  6. #include "Interface.h"
  7. #include "FileOperationProgress.h"
  8. #include "FileMasks.h"
  9. #include "Exceptions.h"
  10. //---------------------------------------------------------------------------
  11. class TCopyParamType;
  12. class TFileOperationProgressType;
  13. class TRemoteDirectory;
  14. class TRemoteFile;
  15. class TCustomFileSystem;
  16. class TTunnelThread;
  17. class TSecureShell;
  18. struct TCalculateSizeParams;
  19. struct TOverwriteFileParams;
  20. struct TSynchronizeData;
  21. struct TSynchronizeOptions;
  22. class TSynchronizeChecklist;
  23. struct TCalculateSizeStats;
  24. struct TFileSystemInfo;
  25. struct TSpaceAvailable;
  26. struct TFilesFindParams;
  27. class TTunnelUI;
  28. class TCallbackGuard;
  29. //---------------------------------------------------------------------------
  30. typedef void __fastcall (__closure *TQueryUserEvent)
  31. (TObject * Sender, const UnicodeString Query, TStrings * MoreMessages, unsigned int Answers,
  32. const TQueryParams * Params, unsigned int & Answer, TQueryType QueryType, void * Arg);
  33. typedef void __fastcall (__closure *TPromptUserEvent)
  34. (TTerminal * Terminal, TPromptKind Kind, UnicodeString Name, UnicodeString Instructions,
  35. TStrings * Prompts, TStrings * Results, bool & Result, void * Arg);
  36. typedef void __fastcall (__closure *TDisplayBannerEvent)
  37. (TTerminal * Terminal, UnicodeString SessionName, const UnicodeString & Banner,
  38. bool & NeverShowAgain, int Options);
  39. typedef void __fastcall (__closure *TExtendedExceptionEvent)
  40. (TTerminal * Terminal, Exception * E, void * Arg);
  41. typedef void __fastcall (__closure *TReadDirectoryEvent)(System::TObject * Sender, Boolean ReloadOnly);
  42. typedef void __fastcall (__closure *TReadDirectoryProgressEvent)(
  43. System::TObject* Sender, int Progress, bool & Cancel);
  44. typedef void __fastcall (__closure *TProcessFileEvent)
  45. (const UnicodeString FileName, const TRemoteFile * File, void * Param);
  46. typedef void __fastcall (__closure *TProcessFileEventEx)
  47. (const UnicodeString FileName, const TRemoteFile * File, void * Param, int Index);
  48. typedef int __fastcall (__closure *TFileOperationEvent)
  49. (void * Param1, void * Param2);
  50. typedef void __fastcall (__closure *TSynchronizeDirectory)
  51. (const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  52. bool & Continue, bool Collect);
  53. typedef void __fastcall (__closure *TDeleteLocalFileEvent)(
  54. const UnicodeString FileName, bool Alternative);
  55. typedef int __fastcall (__closure *TDirectoryModifiedEvent)
  56. (TTerminal * Terminal, const UnicodeString Directory, bool SubDirs);
  57. typedef void __fastcall (__closure *TInformationEvent)
  58. (TTerminal * Terminal, const UnicodeString & Str, bool Status, int Phase);
  59. //---------------------------------------------------------------------------
  60. #define SUSPEND_OPERATION(Command) \
  61. { \
  62. TSuspendFileOperationProgress Suspend(OperationProgress); \
  63. Command \
  64. }
  65. #define THROW_SKIP_FILE(EXCEPTION, MESSAGE) \
  66. throw EScpSkipFile(EXCEPTION, MESSAGE)
  67. #define THROW_SKIP_FILE_NULL THROW_SKIP_FILE(NULL, L"")
  68. /* TODO : Better user interface (query to user) */
  69. #define FILE_OPERATION_LOOP_CUSTOM(TERMINAL, ALLOW_SKIP, MESSAGE, OPERATION, HELPKEYWORD) { \
  70. bool DoRepeat; \
  71. do { \
  72. DoRepeat = false; \
  73. try { \
  74. OPERATION; \
  75. } \
  76. catch (EAbort & E) \
  77. { \
  78. throw; \
  79. } \
  80. catch (EScpSkipFile & E) \
  81. { \
  82. throw; \
  83. } \
  84. catch (EFatal & E) \
  85. { \
  86. throw; \
  87. } \
  88. catch (Exception & E) \
  89. { \
  90. TERMINAL->FileOperationLoopQuery( \
  91. E, OperationProgress, MESSAGE, ALLOW_SKIP, L"", HELPKEYWORD); \
  92. DoRepeat = true; \
  93. } \
  94. } while (DoRepeat); }
  95. #define FILE_OPERATION_LOOP(MESSAGE, OPERATION) \
  96. FILE_OPERATION_LOOP_EX(True, MESSAGE, OPERATION)
  97. //---------------------------------------------------------------------------
  98. enum TCurrentFSProtocol { cfsUnknown, cfsSCP, cfsSFTP, cfsFTP, cfsWebDAV };
  99. //---------------------------------------------------------------------------
  100. const int cpDelete = 0x01;
  101. const int cpTemporary = 0x04;
  102. const int cpNoConfirmation = 0x08;
  103. const int cpAppend = 0x20;
  104. const int cpResume = 0x40;
  105. //---------------------------------------------------------------------------
  106. const int ccApplyToDirectories = 0x01;
  107. const int ccRecursive = 0x02;
  108. const int ccUser = 0x100;
  109. //---------------------------------------------------------------------------
  110. const int csIgnoreErrors = 0x01;
  111. //---------------------------------------------------------------------------
  112. const int ropNoReadDirectory = 0x02;
  113. //---------------------------------------------------------------------------
  114. const int boDisableNeverShowAgain = 0x01;
  115. //---------------------------------------------------------------------------
  116. class TTerminal : public TObject, public TSessionUI
  117. {
  118. public:
  119. // TScript::SynchronizeProc relies on the order
  120. enum TSynchronizeMode { smRemote, smLocal, smBoth };
  121. static const int spDelete = 0x01; // cannot be combined with spTimestamp
  122. static const int spNoConfirmation = 0x02; // has no effect for spTimestamp
  123. static const int spExistingOnly = 0x04; // is implicit for spTimestamp
  124. static const int spNoRecurse = 0x08;
  125. static const int spUseCache = 0x10; // cannot be combined with spTimestamp
  126. static const int spDelayProgress = 0x20; // cannot be combined with spTimestamp
  127. static const int spPreviewChanges = 0x40; // not used by core
  128. static const int spSubDirs = 0x80; // cannot be combined with spTimestamp
  129. static const int spTimestamp = 0x100;
  130. static const int spNotByTime = 0x200; // cannot be combined with spTimestamp and smBoth
  131. static const int spBySize = 0x400; // cannot be combined with smBoth, has opposite meaning for spTimestamp
  132. static const int spSelectedOnly = 0x800; // not used by core
  133. static const int spMirror = 0x1000;
  134. // for TranslateLockedPath()
  135. friend class TRemoteFile;
  136. // for ReactOnCommand()
  137. friend class TSCPFileSystem;
  138. friend class TSFTPFileSystem;
  139. friend class TFTPFileSystem;
  140. friend class TWebDAVFileSystem;
  141. friend class TTunnelUI;
  142. friend class TCallbackGuard;
  143. private:
  144. TSessionData * FSessionData;
  145. TSessionLog * FLog;
  146. TActionLog * FActionLog;
  147. TConfiguration * FConfiguration;
  148. UnicodeString FCurrentDirectory;
  149. UnicodeString FLockDirectory;
  150. Integer FExceptionOnFail;
  151. TRemoteDirectory * FFiles;
  152. int FInTransaction;
  153. bool FSuspendTransaction;
  154. TNotifyEvent FOnChangeDirectory;
  155. TReadDirectoryEvent FOnReadDirectory;
  156. TNotifyEvent FOnStartReadDirectory;
  157. TReadDirectoryProgressEvent FOnReadDirectoryProgress;
  158. TDeleteLocalFileEvent FOnDeleteLocalFile;
  159. TNotifyEvent FOnInitializeLog;
  160. TRemoteTokenList FMembership;
  161. TRemoteTokenList FGroups;
  162. TRemoteTokenList FUsers;
  163. bool FUsersGroupsLookedup;
  164. TFileOperationProgressEvent FOnProgress;
  165. TFileOperationFinished FOnFinished;
  166. TFileOperationProgressType * FOperationProgress;
  167. bool FUseBusyCursor;
  168. TRemoteDirectoryCache * FDirectoryCache;
  169. TRemoteDirectoryChangesCache * FDirectoryChangesCache;
  170. TCustomFileSystem * FFileSystem;
  171. TSecureShell * FSecureShell;
  172. UnicodeString FLastDirectoryChange;
  173. TCurrentFSProtocol FFSProtocol;
  174. TTerminal * FCommandSession;
  175. bool FAutoReadDirectory;
  176. bool FReadingCurrentDirectory;
  177. bool * FClosedOnCompletion;
  178. TSessionStatus FStatus;
  179. RawByteString FRememberedPassword;
  180. RawByteString FRememberedTunnelPassword;
  181. TTunnelThread * FTunnelThread;
  182. TSecureShell * FTunnel;
  183. TSessionData * FTunnelData;
  184. TSessionLog * FTunnelLog;
  185. TTunnelUI * FTunnelUI;
  186. int FTunnelLocalPortNumber;
  187. UnicodeString FTunnelError;
  188. TQueryUserEvent FOnQueryUser;
  189. TPromptUserEvent FOnPromptUser;
  190. TDisplayBannerEvent FOnDisplayBanner;
  191. TExtendedExceptionEvent FOnShowExtendedException;
  192. TInformationEvent FOnInformation;
  193. TNotifyEvent FOnClose;
  194. TCallbackGuard * FCallbackGuard;
  195. TFindingFileEvent FOnFindingFile;
  196. bool FEnableSecureShellUsage;
  197. bool FCollectFileSystemUsage;
  198. bool FRememberedPasswordTried;
  199. bool FRememberedTunnelPasswordTried;
  200. void __fastcall CommandError(Exception * E, const UnicodeString Msg);
  201. unsigned int __fastcall CommandError(Exception * E, const UnicodeString Msg,
  202. unsigned int Answers, const UnicodeString HelpKeyword = L"");
  203. UnicodeString __fastcall GetCurrentDirectory();
  204. bool __fastcall GetExceptionOnFail() const;
  205. const TRemoteTokenList * __fastcall GetGroups();
  206. const TRemoteTokenList * __fastcall GetUsers();
  207. const TRemoteTokenList * __fastcall GetMembership();
  208. void __fastcall SetCurrentDirectory(UnicodeString value);
  209. void __fastcall SetExceptionOnFail(bool value);
  210. void __fastcall ReactOnCommand(int /*TFSCommand*/ Cmd);
  211. UnicodeString __fastcall GetUserName() const;
  212. bool __fastcall GetAreCachesEmpty() const;
  213. void __fastcall ClearCachedFileList(const UnicodeString Path, bool SubDirs);
  214. void __fastcall AddCachedFileList(TRemoteFileList * FileList);
  215. bool __fastcall GetCommandSessionOpened();
  216. TTerminal * __fastcall GetCommandSession();
  217. bool __fastcall GetResolvingSymlinks();
  218. bool __fastcall GetActive();
  219. UnicodeString __fastcall GetPassword();
  220. UnicodeString __fastcall GetRememberedPassword();
  221. UnicodeString __fastcall GetRememberedTunnelPassword();
  222. bool __fastcall GetStoredCredentialsTried();
  223. inline bool __fastcall InTransaction();
  224. static UnicodeString __fastcall SynchronizeModeStr(TSynchronizeMode Mode);
  225. static UnicodeString __fastcall SynchronizeParamsStr(int Params);
  226. protected:
  227. bool FReadCurrentDirectoryPending;
  228. bool FReadDirectoryPending;
  229. bool FTunnelOpening;
  230. void __fastcall DoStartReadDirectory();
  231. void __fastcall DoReadDirectoryProgress(int Progress, bool & Cancel);
  232. void __fastcall DoReadDirectory(bool ReloadOnly);
  233. void __fastcall DoCreateDirectory(const UnicodeString DirName);
  234. void __fastcall DoDeleteFile(const UnicodeString FileName, const TRemoteFile * File,
  235. int Params);
  236. void __fastcall DoCustomCommandOnFile(UnicodeString FileName,
  237. const TRemoteFile * File, UnicodeString Command, int Params, TCaptureOutputEvent OutputEvent);
  238. void __fastcall DoRenameFile(const UnicodeString FileName,
  239. const UnicodeString NewName, bool Move);
  240. void __fastcall DoCopyFile(const UnicodeString FileName, const UnicodeString NewName);
  241. void __fastcall DoChangeFileProperties(const UnicodeString FileName,
  242. const TRemoteFile * File, const TRemoteProperties * Properties);
  243. void __fastcall DoChangeDirectory();
  244. void __fastcall DoInitializeLog();
  245. void __fastcall EnsureNonExistence(const UnicodeString FileName);
  246. void __fastcall LookupUsersGroups();
  247. void __fastcall FileModified(const TRemoteFile * File,
  248. const UnicodeString FileName, bool ClearDirectoryChange = false);
  249. int __fastcall FileOperationLoop(TFileOperationEvent CallBackFunc,
  250. TFileOperationProgressType * OperationProgress, bool AllowSkip,
  251. const UnicodeString Message, void * Param1 = NULL, void * Param2 = NULL);
  252. bool __fastcall GetIsCapable(TFSCapability Capability) const;
  253. bool __fastcall ProcessFiles(TStrings * FileList, TFileOperation Operation,
  254. TProcessFileEvent ProcessFile, void * Param = NULL, TOperationSide Side = osRemote,
  255. bool Ex = false);
  256. bool __fastcall ProcessFilesEx(TStrings * FileList, TFileOperation Operation,
  257. TProcessFileEventEx ProcessFile, void * Param = NULL, TOperationSide Side = osRemote);
  258. void __fastcall ProcessDirectory(const UnicodeString DirName,
  259. TProcessFileEvent CallBackFunc, void * Param = NULL, bool UseCache = false,
  260. bool IgnoreErrors = false);
  261. void __fastcall AnnounceFileListOperation();
  262. UnicodeString __fastcall TranslateLockedPath(UnicodeString Path, bool Lock);
  263. void __fastcall ReadDirectory(TRemoteFileList * FileList);
  264. void __fastcall CustomReadDirectory(TRemoteFileList * FileList);
  265. void __fastcall DoCreateLink(const UnicodeString FileName, const UnicodeString PointTo, bool Symbolic);
  266. bool __fastcall CreateLocalFile(const UnicodeString FileName,
  267. TFileOperationProgressType * OperationProgress, HANDLE * AHandle,
  268. bool NoConfirmation);
  269. void __fastcall OpenLocalFile(const UnicodeString FileName, unsigned int Access,
  270. int * Attrs, HANDLE * Handle, __int64 * ACTime, __int64 * MTime,
  271. __int64 * ATime, __int64 * Size, bool TryWriteReadOnly = true);
  272. bool __fastcall AllowLocalFileTransfer(UnicodeString FileName, const TCopyParamType * CopyParam);
  273. bool __fastcall HandleException(Exception * E);
  274. void __fastcall CalculateFileSize(UnicodeString FileName,
  275. const TRemoteFile * File, /*TCalculateSizeParams*/ void * Size);
  276. void __fastcall DoCalculateDirectorySize(const UnicodeString FileName,
  277. const TRemoteFile * File, TCalculateSizeParams * Params);
  278. void __fastcall CalculateLocalFileSize(const UnicodeString FileName,
  279. const TSearchRec Rec, /*__int64*/ void * Size);
  280. bool __fastcall CalculateLocalFilesSize(TStrings * FileList, __int64 & Size,
  281. const TCopyParamType * CopyParam, bool AllowDirs);
  282. TBatchOverwrite __fastcall EffectiveBatchOverwrite(
  283. const TCopyParamType * CopyParam, int Params,
  284. TFileOperationProgressType * OperationProgress, bool Special);
  285. bool __fastcall CheckRemoteFile(
  286. const TCopyParamType * CopyParam, int Params, TFileOperationProgressType * OperationProgress);
  287. unsigned int __fastcall ConfirmFileOverwrite(const UnicodeString FileName,
  288. const TOverwriteFileParams * FileParams, unsigned int Answers, TQueryParams * QueryParams,
  289. TOperationSide Side, const TCopyParamType * CopyParam, int Params,
  290. TFileOperationProgressType * OperationProgress, UnicodeString Message = L"");
  291. void __fastcall DoSynchronizeCollectDirectory(const UnicodeString LocalDirectory,
  292. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  293. const TCopyParamType * CopyParam, int Params,
  294. TSynchronizeDirectory OnSynchronizeDirectory,
  295. TSynchronizeOptions * Options, int Level, TSynchronizeChecklist * Checklist);
  296. void __fastcall SynchronizeCollectFile(const UnicodeString FileName,
  297. const TRemoteFile * File, /*TSynchronizeData*/ void * Param);
  298. void __fastcall SynchronizeRemoteTimestamp(const UnicodeString FileName,
  299. const TRemoteFile * File, void * Param);
  300. void __fastcall SynchronizeLocalTimestamp(const UnicodeString FileName,
  301. const TRemoteFile * File, void * Param);
  302. void __fastcall DoSynchronizeProgress(const TSynchronizeData & Data, bool Collect);
  303. void __fastcall DeleteLocalFile(UnicodeString FileName,
  304. const TRemoteFile * File, void * Param);
  305. void __fastcall RecycleFile(UnicodeString FileName, const TRemoteFile * File);
  306. TStrings * __fastcall GetFixedPaths();
  307. void __fastcall DoStartup();
  308. virtual bool __fastcall DoQueryReopen(Exception * E);
  309. virtual void __fastcall FatalError(Exception * E, UnicodeString Msg, UnicodeString HelpKeyword = L"");
  310. void __fastcall ResetConnection();
  311. virtual bool __fastcall DoPromptUser(TSessionData * Data, TPromptKind Kind,
  312. UnicodeString Name, UnicodeString Instructions, TStrings * Prompts,
  313. TStrings * Response);
  314. void __fastcall OpenTunnel();
  315. void __fastcall CloseTunnel();
  316. void __fastcall DoInformation(const UnicodeString & Str, bool Status, int Phase = -1);
  317. UnicodeString __fastcall FileUrl(const UnicodeString Protocol, const UnicodeString FileName);
  318. bool __fastcall PromptUser(TSessionData * Data, TPromptKind Kind,
  319. UnicodeString Name, UnicodeString Instructions, UnicodeString Prompt, bool Echo,
  320. int MaxLen, UnicodeString & Result);
  321. void __fastcall FileFind(UnicodeString FileName, const TRemoteFile * File, void * Param);
  322. void __fastcall DoFilesFind(UnicodeString Directory, TFilesFindParams & Params);
  323. bool __fastcall DoCreateLocalFile(const UnicodeString FileName,
  324. TFileOperationProgressType * OperationProgress, HANDLE * AHandle,
  325. bool NoConfirmation);
  326. virtual void __fastcall Information(const UnicodeString & Str, bool Status);
  327. virtual unsigned int __fastcall QueryUser(const UnicodeString Query,
  328. TStrings * MoreMessages, unsigned int Answers, const TQueryParams * Params,
  329. TQueryType QueryType = qtConfirmation);
  330. virtual unsigned int __fastcall QueryUserException(const UnicodeString Query,
  331. Exception * E, unsigned int Answers, const TQueryParams * Params,
  332. TQueryType QueryType = qtConfirmation);
  333. virtual bool __fastcall PromptUser(TSessionData * Data, TPromptKind Kind,
  334. UnicodeString Name, UnicodeString Instructions, TStrings * Prompts, TStrings * Results);
  335. virtual void __fastcall DisplayBanner(const UnicodeString & Banner);
  336. virtual void __fastcall Closed();
  337. virtual void __fastcall HandleExtendedException(Exception * E);
  338. bool __fastcall IsListenerFree(unsigned int PortNumber);
  339. void __fastcall DoProgress(TFileOperationProgressType & ProgressData, TCancelStatus & Cancel);
  340. void __fastcall DoFinished(TFileOperation Operation, TOperationSide Side, bool Temp,
  341. const UnicodeString & FileName, bool Success, TOnceDoneOperation & OnceDoneOperation);
  342. void __fastcall RollbackAction(TSessionAction & Action,
  343. TFileOperationProgressType * OperationProgress, Exception * E = NULL);
  344. void __fastcall DoAnyCommand(const UnicodeString Command, TCaptureOutputEvent OutputEvent,
  345. TCallSessionAction * Action);
  346. TRemoteFileList * __fastcall DoReadDirectoryListing(UnicodeString Directory, bool UseCache);
  347. RawByteString __fastcall EncryptPassword(const UnicodeString & Password);
  348. UnicodeString __fastcall DecryptPassword(const RawByteString & Password);
  349. void __fastcall LogRemoteFile(TRemoteFile * File);
  350. UnicodeString __fastcall FormatFileDetailsForLog(const UnicodeString & FileName, TDateTime Modification, __int64 Size);
  351. void __fastcall LogFileDetails(const UnicodeString & FileName, TDateTime Modification, __int64 Size);
  352. virtual TTerminal * __fastcall GetPasswordSource();
  353. __property TFileOperationProgressType * OperationProgress = { read=FOperationProgress };
  354. public:
  355. __fastcall TTerminal(TSessionData * SessionData, TConfiguration * Configuration);
  356. __fastcall ~TTerminal();
  357. void __fastcall Open();
  358. void __fastcall Close();
  359. void __fastcall Reopen(int Params);
  360. virtual void __fastcall DirectoryModified(const UnicodeString Path, bool SubDirs);
  361. virtual void __fastcall DirectoryLoaded(TRemoteFileList * FileList);
  362. void __fastcall ShowExtendedException(Exception * E);
  363. void __fastcall Idle();
  364. void __fastcall RecryptPasswords();
  365. bool __fastcall AllowedAnyCommand(const UnicodeString Command);
  366. void __fastcall AnyCommand(const UnicodeString Command, TCaptureOutputEvent OutputEvent);
  367. void __fastcall CloseOnCompletion(TOnceDoneOperation Operation = odoDisconnect, const UnicodeString Message = L"");
  368. UnicodeString __fastcall AbsolutePath(UnicodeString Path, bool Local);
  369. void __fastcall BeginTransaction();
  370. void __fastcall ReadCurrentDirectory();
  371. void __fastcall ReadDirectory(bool ReloadOnly, bool ForceCache = false);
  372. TRemoteFileList * __fastcall ReadDirectoryListing(UnicodeString Directory, const TFileMasks & Mask);
  373. TRemoteFileList * __fastcall CustomReadDirectoryListing(UnicodeString Directory, bool UseCache);
  374. TRemoteFile * __fastcall ReadFileListing(UnicodeString Path);
  375. void __fastcall ReadFile(const UnicodeString FileName, TRemoteFile *& File);
  376. bool __fastcall FileExists(const UnicodeString FileName, TRemoteFile ** File = NULL);
  377. void __fastcall ReadSymlink(TRemoteFile * SymlinkFile, TRemoteFile *& File);
  378. bool __fastcall CopyToLocal(TStrings * FilesToCopy,
  379. const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params);
  380. bool __fastcall CopyToRemote(TStrings * FilesToCopy,
  381. const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params);
  382. void __fastcall CreateDirectory(const UnicodeString DirName,
  383. const TRemoteProperties * Properties = NULL);
  384. void __fastcall CreateLink(const UnicodeString FileName, const UnicodeString PointTo, bool Symbolic);
  385. void __fastcall DeleteFile(UnicodeString FileName,
  386. const TRemoteFile * File = NULL, void * Params = NULL);
  387. bool __fastcall DeleteFiles(TStrings * FilesToDelete, int Params = 0);
  388. bool __fastcall DeleteLocalFiles(TStrings * FileList, int Params = 0);
  389. bool __fastcall IsRecycledFile(UnicodeString FileName);
  390. void __fastcall CustomCommandOnFile(UnicodeString FileName,
  391. const TRemoteFile * File, void * AParams);
  392. void __fastcall CustomCommandOnFiles(UnicodeString Command, int Params,
  393. TStrings * Files, TCaptureOutputEvent OutputEvent);
  394. void __fastcall ChangeDirectory(const UnicodeString Directory);
  395. void __fastcall EndTransaction();
  396. void __fastcall HomeDirectory();
  397. void __fastcall ChangeFileProperties(UnicodeString FileName,
  398. const TRemoteFile * File, /*const TRemoteProperties */ void * Properties);
  399. void __fastcall ChangeFilesProperties(TStrings * FileList,
  400. const TRemoteProperties * Properties);
  401. bool __fastcall LoadFilesProperties(TStrings * FileList);
  402. void __fastcall TerminalError(UnicodeString Msg);
  403. void __fastcall TerminalError(Exception * E, UnicodeString Msg, UnicodeString HelpKeyword = L"");
  404. void __fastcall ReloadDirectory();
  405. void __fastcall RefreshDirectory();
  406. void __fastcall RenameFile(const UnicodeString FileName, const UnicodeString NewName);
  407. void __fastcall RenameFile(const TRemoteFile * File, const UnicodeString NewName, bool CheckExistence);
  408. void __fastcall MoveFile(const UnicodeString FileName, const TRemoteFile * File,
  409. /*const TMoveFileParams*/ void * Param);
  410. bool __fastcall MoveFiles(TStrings * FileList, const UnicodeString Target,
  411. const UnicodeString FileMask);
  412. void __fastcall CopyFile(const UnicodeString FileName, const TRemoteFile * File,
  413. /*const TMoveFileParams*/ void * Param);
  414. bool __fastcall CopyFiles(TStrings * FileList, const UnicodeString Target,
  415. const UnicodeString FileMask);
  416. bool __fastcall CalculateFilesSize(TStrings * FileList, __int64 & Size,
  417. int Params, const TCopyParamType * CopyParam, bool AllowDirs,
  418. TCalculateSizeStats * Stats);
  419. void __fastcall CalculateFilesChecksum(const UnicodeString & Alg, TStrings * FileList,
  420. TStrings * Checksums, TCalculatedChecksumEvent OnCalculatedChecksum);
  421. void __fastcall ClearCaches();
  422. TSynchronizeChecklist * __fastcall SynchronizeCollect(const UnicodeString LocalDirectory,
  423. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  424. const TCopyParamType * CopyParam, int Params,
  425. TSynchronizeDirectory OnSynchronizeDirectory, TSynchronizeOptions * Options);
  426. void __fastcall SynchronizeApply(TSynchronizeChecklist * Checklist,
  427. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  428. const TCopyParamType * CopyParam, int Params,
  429. TSynchronizeDirectory OnSynchronizeDirectory);
  430. void __fastcall FilesFind(UnicodeString Directory, const TFileMasks & FileMask,
  431. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile);
  432. void __fastcall SpaceAvailable(const UnicodeString Path, TSpaceAvailable & ASpaceAvailable);
  433. bool __fastcall DirectoryFileList(const UnicodeString Path,
  434. TRemoteFileList *& FileList, bool CanLoad);
  435. void __fastcall MakeLocalFileList(const UnicodeString FileName,
  436. const TSearchRec Rec, void * Param);
  437. UnicodeString __fastcall FileUrl(const UnicodeString FileName);
  438. bool __fastcall FileOperationLoopQuery(Exception & E,
  439. TFileOperationProgressType * OperationProgress, const UnicodeString Message,
  440. bool AllowSkip, UnicodeString SpecialRetry = L"", UnicodeString HelpKeyword = L"");
  441. TUsableCopyParamAttrs __fastcall UsableCopyParamAttrs(int Params);
  442. bool __fastcall QueryReopen(Exception * E, int Params,
  443. TFileOperationProgressType * OperationProgress);
  444. UnicodeString __fastcall PeekCurrentDirectory();
  445. void __fastcall FatalAbort();
  446. void __fastcall ReflectSettings();
  447. void __fastcall CollectUsage();
  448. const TSessionInfo & __fastcall GetSessionInfo();
  449. const TFileSystemInfo & __fastcall GetFileSystemInfo(bool Retrieve = false);
  450. void __fastcall inline LogEvent(const UnicodeString & Str);
  451. static UnicodeString __fastcall ExpandFileName(UnicodeString Path,
  452. const UnicodeString BasePath);
  453. __property TSessionData * SessionData = { read = FSessionData };
  454. __property TSessionLog * Log = { read = FLog };
  455. __property TActionLog * ActionLog = { read = FActionLog };
  456. __property TConfiguration * Configuration = { read = FConfiguration };
  457. __property bool Active = { read = GetActive };
  458. __property TSessionStatus Status = { read = FStatus };
  459. __property UnicodeString CurrentDirectory = { read = GetCurrentDirectory, write = SetCurrentDirectory };
  460. __property bool ExceptionOnFail = { read = GetExceptionOnFail, write = SetExceptionOnFail };
  461. __property TRemoteDirectory * Files = { read = FFiles };
  462. __property TNotifyEvent OnChangeDirectory = { read = FOnChangeDirectory, write = FOnChangeDirectory };
  463. __property TReadDirectoryEvent OnReadDirectory = { read = FOnReadDirectory, write = FOnReadDirectory };
  464. __property TNotifyEvent OnStartReadDirectory = { read = FOnStartReadDirectory, write = FOnStartReadDirectory };
  465. __property TReadDirectoryProgressEvent OnReadDirectoryProgress = { read = FOnReadDirectoryProgress, write = FOnReadDirectoryProgress };
  466. __property TDeleteLocalFileEvent OnDeleteLocalFile = { read = FOnDeleteLocalFile, write = FOnDeleteLocalFile };
  467. __property TNotifyEvent OnInitializeLog = { read = FOnInitializeLog, write = FOnInitializeLog };
  468. __property const TRemoteTokenList * Groups = { read = GetGroups };
  469. __property const TRemoteTokenList * Users = { read = GetUsers };
  470. __property const TRemoteTokenList * Membership = { read = GetMembership };
  471. __property TFileOperationProgressEvent OnProgress = { read=FOnProgress, write=FOnProgress };
  472. __property TFileOperationFinished OnFinished = { read=FOnFinished, write=FOnFinished };
  473. __property TCurrentFSProtocol FSProtocol = { read = FFSProtocol };
  474. __property bool UseBusyCursor = { read = FUseBusyCursor, write = FUseBusyCursor };
  475. __property UnicodeString UserName = { read=GetUserName };
  476. __property bool IsCapable[TFSCapability Capability] = { read = GetIsCapable };
  477. __property bool AreCachesEmpty = { read = GetAreCachesEmpty };
  478. __property bool CommandSessionOpened = { read = GetCommandSessionOpened };
  479. __property TTerminal * CommandSession = { read = GetCommandSession };
  480. __property bool AutoReadDirectory = { read = FAutoReadDirectory, write = FAutoReadDirectory };
  481. __property TStrings * FixedPaths = { read = GetFixedPaths };
  482. __property bool ResolvingSymlinks = { read = GetResolvingSymlinks };
  483. __property UnicodeString Password = { read = GetPassword };
  484. __property UnicodeString RememberedPassword = { read = GetRememberedPassword };
  485. __property UnicodeString RememberedTunnelPassword = { read = GetRememberedTunnelPassword };
  486. __property bool StoredCredentialsTried = { read = GetStoredCredentialsTried };
  487. __property TQueryUserEvent OnQueryUser = { read = FOnQueryUser, write = FOnQueryUser };
  488. __property TPromptUserEvent OnPromptUser = { read = FOnPromptUser, write = FOnPromptUser };
  489. __property TDisplayBannerEvent OnDisplayBanner = { read = FOnDisplayBanner, write = FOnDisplayBanner };
  490. __property TExtendedExceptionEvent OnShowExtendedException = { read = FOnShowExtendedException, write = FOnShowExtendedException };
  491. __property TInformationEvent OnInformation = { read = FOnInformation, write = FOnInformation };
  492. __property TNotifyEvent OnClose = { read = FOnClose, write = FOnClose };
  493. __property int TunnelLocalPortNumber = { read = FTunnelLocalPortNumber };
  494. };
  495. //---------------------------------------------------------------------------
  496. class TSecondaryTerminal : public TTerminal
  497. {
  498. public:
  499. __fastcall TSecondaryTerminal(TTerminal * MainTerminal,
  500. TSessionData * SessionData, TConfiguration * Configuration,
  501. const UnicodeString & Name);
  502. __property TTerminal * MainTerminal = { read = FMainTerminal };
  503. protected:
  504. virtual void __fastcall DirectoryLoaded(TRemoteFileList * FileList);
  505. virtual void __fastcall DirectoryModified(const UnicodeString Path,
  506. bool SubDirs);
  507. virtual TTerminal * __fastcall GetPasswordSource();
  508. private:
  509. TTerminal * FMainTerminal;
  510. };
  511. //---------------------------------------------------------------------------
  512. class TTerminalList : public TObjectList
  513. {
  514. public:
  515. __fastcall TTerminalList(TConfiguration * AConfiguration);
  516. __fastcall ~TTerminalList();
  517. virtual TTerminal * __fastcall NewTerminal(TSessionData * Data);
  518. virtual void __fastcall FreeTerminal(TTerminal * Terminal);
  519. void __fastcall FreeAndNullTerminal(TTerminal * & Terminal);
  520. virtual void __fastcall Idle();
  521. void __fastcall RecryptPasswords();
  522. __property TTerminal * Terminals[int Index] = { read=GetTerminal };
  523. protected:
  524. virtual TTerminal * __fastcall CreateTerminal(TSessionData * Data);
  525. private:
  526. TConfiguration * FConfiguration;
  527. TTerminal * __fastcall GetTerminal(int Index);
  528. };
  529. //---------------------------------------------------------------------------
  530. struct TCustomCommandParams
  531. {
  532. UnicodeString Command;
  533. int Params;
  534. TCaptureOutputEvent OutputEvent;
  535. };
  536. //---------------------------------------------------------------------------
  537. struct TCalculateSizeStats
  538. {
  539. TCalculateSizeStats();
  540. int Files;
  541. int Directories;
  542. int SymLinks;
  543. };
  544. //---------------------------------------------------------------------------
  545. struct TCalculateSizeParams
  546. {
  547. __int64 Size;
  548. int Params;
  549. const TCopyParamType * CopyParam;
  550. TCalculateSizeStats * Stats;
  551. bool AllowDirs;
  552. bool Result;
  553. };
  554. //---------------------------------------------------------------------------
  555. struct TOverwriteFileParams
  556. {
  557. TOverwriteFileParams();
  558. __int64 SourceSize;
  559. __int64 DestSize;
  560. TDateTime SourceTimestamp;
  561. TDateTime DestTimestamp;
  562. TModificationFmt SourcePrecision;
  563. TModificationFmt DestPrecision;
  564. };
  565. //---------------------------------------------------------------------------
  566. struct TMakeLocalFileListParams
  567. {
  568. TStrings * FileList;
  569. bool IncludeDirs;
  570. bool Recursive;
  571. };
  572. //---------------------------------------------------------------------------
  573. struct TSynchronizeOptions
  574. {
  575. TSynchronizeOptions();
  576. ~TSynchronizeOptions();
  577. TStringList * Filter;
  578. bool __fastcall FilterFind(const UnicodeString & FileName);
  579. bool __fastcall MatchesFilter(const UnicodeString & FileName);
  580. };
  581. //---------------------------------------------------------------------------
  582. class TSynchronizeChecklist
  583. {
  584. friend class TTerminal;
  585. public:
  586. enum TAction { saNone, saUploadNew, saDownloadNew, saUploadUpdate,
  587. saDownloadUpdate, saDeleteRemote, saDeleteLocal };
  588. static const int ActionCount = saDeleteLocal;
  589. class TItem
  590. {
  591. friend class TTerminal;
  592. public:
  593. struct TFileInfo
  594. {
  595. UnicodeString FileName;
  596. UnicodeString Directory;
  597. TDateTime Modification;
  598. TModificationFmt ModificationFmt;
  599. __int64 Size;
  600. };
  601. TAction Action;
  602. bool IsDirectory;
  603. TFileInfo Local;
  604. TFileInfo Remote;
  605. int ImageIndex;
  606. bool Checked;
  607. TRemoteFile * RemoteFile;
  608. const UnicodeString& GetFileName() const;
  609. ~TItem();
  610. private:
  611. FILETIME FLocalLastWriteTime;
  612. TItem();
  613. };
  614. ~TSynchronizeChecklist();
  615. __property int Count = { read = GetCount };
  616. __property const TItem * Item[int Index] = { read = GetItem };
  617. protected:
  618. TSynchronizeChecklist();
  619. void Sort();
  620. void Add(TItem * Item);
  621. int GetCount() const;
  622. const TItem * GetItem(int Index) const;
  623. private:
  624. TList * FList;
  625. static int __fastcall Compare(void * Item1, void * Item2);
  626. };
  627. //---------------------------------------------------------------------------
  628. struct TSpaceAvailable
  629. {
  630. TSpaceAvailable();
  631. __int64 BytesOnDevice;
  632. __int64 UnusedBytesOnDevice;
  633. __int64 BytesAvailableToUser;
  634. __int64 UnusedBytesAvailableToUser;
  635. unsigned long BytesPerAllocationUnit;
  636. };
  637. //---------------------------------------------------------------------------
  638. #endif