Terminal.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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 FPassword;
  180. RawByteString FTunnelPassword;
  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. void __fastcall CommandError(Exception * E, const UnicodeString Msg);
  199. unsigned int __fastcall CommandError(Exception * E, const UnicodeString Msg,
  200. unsigned int Answers, const UnicodeString HelpKeyword = L"");
  201. UnicodeString __fastcall GetCurrentDirectory();
  202. bool __fastcall GetExceptionOnFail() const;
  203. const TRemoteTokenList * __fastcall GetGroups();
  204. const TRemoteTokenList * __fastcall GetUsers();
  205. const TRemoteTokenList * __fastcall GetMembership();
  206. void __fastcall SetCurrentDirectory(UnicodeString value);
  207. void __fastcall SetExceptionOnFail(bool value);
  208. void __fastcall ReactOnCommand(int /*TFSCommand*/ Cmd);
  209. UnicodeString __fastcall GetUserName() const;
  210. bool __fastcall GetAreCachesEmpty() const;
  211. void __fastcall ClearCachedFileList(const UnicodeString Path, bool SubDirs);
  212. void __fastcall AddCachedFileList(TRemoteFileList * FileList);
  213. bool __fastcall GetCommandSessionOpened();
  214. TTerminal * __fastcall GetCommandSession();
  215. bool __fastcall GetResolvingSymlinks();
  216. bool __fastcall GetActive();
  217. UnicodeString __fastcall GetPassword();
  218. UnicodeString __fastcall GetTunnelPassword();
  219. bool __fastcall GetStoredCredentialsTried();
  220. inline bool __fastcall InTransaction();
  221. static UnicodeString __fastcall SynchronizeModeStr(TSynchronizeMode Mode);
  222. static UnicodeString __fastcall SynchronizeParamsStr(int Params);
  223. protected:
  224. bool FReadCurrentDirectoryPending;
  225. bool FReadDirectoryPending;
  226. bool FTunnelOpening;
  227. void __fastcall DoStartReadDirectory();
  228. void __fastcall DoReadDirectoryProgress(int Progress, bool & Cancel);
  229. void __fastcall DoReadDirectory(bool ReloadOnly);
  230. void __fastcall DoCreateDirectory(const UnicodeString DirName);
  231. void __fastcall DoDeleteFile(const UnicodeString FileName, const TRemoteFile * File,
  232. int Params);
  233. void __fastcall DoCustomCommandOnFile(UnicodeString FileName,
  234. const TRemoteFile * File, UnicodeString Command, int Params, TCaptureOutputEvent OutputEvent);
  235. void __fastcall DoRenameFile(const UnicodeString FileName,
  236. const UnicodeString NewName, bool Move);
  237. void __fastcall DoCopyFile(const UnicodeString FileName, const UnicodeString NewName);
  238. void __fastcall DoChangeFileProperties(const UnicodeString FileName,
  239. const TRemoteFile * File, const TRemoteProperties * Properties);
  240. void __fastcall DoChangeDirectory();
  241. void __fastcall DoInitializeLog();
  242. void __fastcall EnsureNonExistence(const UnicodeString FileName);
  243. void __fastcall LookupUsersGroups();
  244. void __fastcall FileModified(const TRemoteFile * File,
  245. const UnicodeString FileName, bool ClearDirectoryChange = false);
  246. int __fastcall FileOperationLoop(TFileOperationEvent CallBackFunc,
  247. TFileOperationProgressType * OperationProgress, bool AllowSkip,
  248. const UnicodeString Message, void * Param1 = NULL, void * Param2 = NULL);
  249. bool __fastcall GetIsCapable(TFSCapability Capability) const;
  250. bool __fastcall ProcessFiles(TStrings * FileList, TFileOperation Operation,
  251. TProcessFileEvent ProcessFile, void * Param = NULL, TOperationSide Side = osRemote,
  252. bool Ex = false);
  253. bool __fastcall ProcessFilesEx(TStrings * FileList, TFileOperation Operation,
  254. TProcessFileEventEx ProcessFile, void * Param = NULL, TOperationSide Side = osRemote);
  255. void __fastcall ProcessDirectory(const UnicodeString DirName,
  256. TProcessFileEvent CallBackFunc, void * Param = NULL, bool UseCache = false,
  257. bool IgnoreErrors = false);
  258. void __fastcall AnnounceFileListOperation();
  259. UnicodeString __fastcall TranslateLockedPath(UnicodeString Path, bool Lock);
  260. void __fastcall ReadDirectory(TRemoteFileList * FileList);
  261. void __fastcall CustomReadDirectory(TRemoteFileList * FileList);
  262. void __fastcall DoCreateLink(const UnicodeString FileName, const UnicodeString PointTo, bool Symbolic);
  263. bool __fastcall CreateLocalFile(const UnicodeString FileName,
  264. TFileOperationProgressType * OperationProgress, HANDLE * AHandle,
  265. bool NoConfirmation);
  266. void __fastcall OpenLocalFile(const UnicodeString FileName, unsigned int Access,
  267. int * Attrs, HANDLE * Handle, __int64 * ACTime, __int64 * MTime,
  268. __int64 * ATime, __int64 * Size, bool TryWriteReadOnly = true);
  269. bool __fastcall AllowLocalFileTransfer(UnicodeString FileName, const TCopyParamType * CopyParam);
  270. bool __fastcall HandleException(Exception * E);
  271. void __fastcall CalculateFileSize(UnicodeString FileName,
  272. const TRemoteFile * File, /*TCalculateSizeParams*/ void * Size);
  273. void __fastcall DoCalculateDirectorySize(const UnicodeString FileName,
  274. const TRemoteFile * File, TCalculateSizeParams * Params);
  275. void __fastcall CalculateLocalFileSize(const UnicodeString FileName,
  276. const TSearchRec Rec, /*__int64*/ void * Size);
  277. bool __fastcall CalculateLocalFilesSize(TStrings * FileList, __int64 & Size,
  278. const TCopyParamType * CopyParam, bool AllowDirs);
  279. TBatchOverwrite __fastcall EffectiveBatchOverwrite(
  280. const TCopyParamType * CopyParam, int Params,
  281. TFileOperationProgressType * OperationProgress, bool Special);
  282. bool __fastcall CheckRemoteFile(
  283. const TCopyParamType * CopyParam, int Params, TFileOperationProgressType * OperationProgress);
  284. unsigned int __fastcall ConfirmFileOverwrite(const UnicodeString FileName,
  285. const TOverwriteFileParams * FileParams, unsigned int Answers, TQueryParams * QueryParams,
  286. TOperationSide Side, const TCopyParamType * CopyParam, int Params,
  287. TFileOperationProgressType * OperationProgress, UnicodeString Message = L"");
  288. void __fastcall DoSynchronizeCollectDirectory(const UnicodeString LocalDirectory,
  289. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  290. const TCopyParamType * CopyParam, int Params,
  291. TSynchronizeDirectory OnSynchronizeDirectory,
  292. TSynchronizeOptions * Options, int Level, TSynchronizeChecklist * Checklist);
  293. void __fastcall SynchronizeCollectFile(const UnicodeString FileName,
  294. const TRemoteFile * File, /*TSynchronizeData*/ void * Param);
  295. void __fastcall SynchronizeRemoteTimestamp(const UnicodeString FileName,
  296. const TRemoteFile * File, void * Param);
  297. void __fastcall SynchronizeLocalTimestamp(const UnicodeString FileName,
  298. const TRemoteFile * File, void * Param);
  299. void __fastcall DoSynchronizeProgress(const TSynchronizeData & Data, bool Collect);
  300. void __fastcall DeleteLocalFile(UnicodeString FileName,
  301. const TRemoteFile * File, void * Param);
  302. void __fastcall RecycleFile(UnicodeString FileName, const TRemoteFile * File);
  303. TStrings * __fastcall GetFixedPaths();
  304. void __fastcall DoStartup();
  305. virtual bool __fastcall DoQueryReopen(Exception * E);
  306. virtual void __fastcall FatalError(Exception * E, UnicodeString Msg, UnicodeString HelpKeyword = L"");
  307. void __fastcall ResetConnection();
  308. virtual bool __fastcall DoPromptUser(TSessionData * Data, TPromptKind Kind,
  309. UnicodeString Name, UnicodeString Instructions, TStrings * Prompts,
  310. TStrings * Response);
  311. void __fastcall OpenTunnel();
  312. void __fastcall CloseTunnel();
  313. void __fastcall DoInformation(const UnicodeString & Str, bool Status, int Phase = -1);
  314. UnicodeString __fastcall FileUrl(const UnicodeString Protocol, const UnicodeString FileName);
  315. bool __fastcall PromptUser(TSessionData * Data, TPromptKind Kind,
  316. UnicodeString Name, UnicodeString Instructions, UnicodeString Prompt, bool Echo,
  317. int MaxLen, UnicodeString & Result);
  318. void __fastcall FileFind(UnicodeString FileName, const TRemoteFile * File, void * Param);
  319. void __fastcall DoFilesFind(UnicodeString Directory, TFilesFindParams & Params);
  320. bool __fastcall DoCreateLocalFile(const UnicodeString FileName,
  321. TFileOperationProgressType * OperationProgress, HANDLE * AHandle,
  322. bool NoConfirmation);
  323. virtual void __fastcall Information(const UnicodeString & Str, bool Status);
  324. virtual unsigned int __fastcall QueryUser(const UnicodeString Query,
  325. TStrings * MoreMessages, unsigned int Answers, const TQueryParams * Params,
  326. TQueryType QueryType = qtConfirmation);
  327. virtual unsigned int __fastcall QueryUserException(const UnicodeString Query,
  328. Exception * E, unsigned int Answers, const TQueryParams * Params,
  329. TQueryType QueryType = qtConfirmation);
  330. virtual bool __fastcall PromptUser(TSessionData * Data, TPromptKind Kind,
  331. UnicodeString Name, UnicodeString Instructions, TStrings * Prompts, TStrings * Results);
  332. virtual void __fastcall DisplayBanner(const UnicodeString & Banner);
  333. virtual void __fastcall Closed();
  334. virtual void __fastcall HandleExtendedException(Exception * E);
  335. bool __fastcall IsListenerFree(unsigned int PortNumber);
  336. void __fastcall DoProgress(TFileOperationProgressType & ProgressData, TCancelStatus & Cancel);
  337. void __fastcall DoFinished(TFileOperation Operation, TOperationSide Side, bool Temp,
  338. const UnicodeString & FileName, bool Success, TOnceDoneOperation & OnceDoneOperation);
  339. void __fastcall RollbackAction(TSessionAction & Action,
  340. TFileOperationProgressType * OperationProgress, Exception * E = NULL);
  341. void __fastcall DoAnyCommand(const UnicodeString Command, TCaptureOutputEvent OutputEvent,
  342. TCallSessionAction * Action);
  343. TRemoteFileList * __fastcall DoReadDirectoryListing(UnicodeString Directory, bool UseCache);
  344. RawByteString __fastcall EncryptPassword(const UnicodeString & Password);
  345. UnicodeString __fastcall DecryptPassword(const RawByteString & Password);
  346. void __fastcall LogFile(TRemoteFile * File);
  347. __property TFileOperationProgressType * OperationProgress = { read=FOperationProgress };
  348. public:
  349. __fastcall TTerminal(TSessionData * SessionData, TConfiguration * Configuration);
  350. __fastcall ~TTerminal();
  351. void __fastcall Open();
  352. void __fastcall Close();
  353. void __fastcall Reopen(int Params);
  354. virtual void __fastcall DirectoryModified(const UnicodeString Path, bool SubDirs);
  355. virtual void __fastcall DirectoryLoaded(TRemoteFileList * FileList);
  356. void __fastcall ShowExtendedException(Exception * E);
  357. void __fastcall Idle();
  358. void __fastcall RecryptPasswords();
  359. bool __fastcall AllowedAnyCommand(const UnicodeString Command);
  360. void __fastcall AnyCommand(const UnicodeString Command, TCaptureOutputEvent OutputEvent);
  361. void __fastcall CloseOnCompletion(TOnceDoneOperation Operation = odoDisconnect, const UnicodeString Message = L"");
  362. UnicodeString __fastcall AbsolutePath(UnicodeString Path, bool Local);
  363. void __fastcall BeginTransaction();
  364. void __fastcall ReadCurrentDirectory();
  365. void __fastcall ReadDirectory(bool ReloadOnly, bool ForceCache = false);
  366. TRemoteFileList * __fastcall ReadDirectoryListing(UnicodeString Directory, const TFileMasks & Mask);
  367. TRemoteFileList * __fastcall CustomReadDirectoryListing(UnicodeString Directory, bool UseCache);
  368. TRemoteFile * __fastcall ReadFileListing(UnicodeString Path);
  369. void __fastcall ReadFile(const UnicodeString FileName, TRemoteFile *& File);
  370. bool __fastcall FileExists(const UnicodeString FileName, TRemoteFile ** File = NULL);
  371. void __fastcall ReadSymlink(TRemoteFile * SymlinkFile, TRemoteFile *& File);
  372. bool __fastcall CopyToLocal(TStrings * FilesToCopy,
  373. const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params);
  374. bool __fastcall CopyToRemote(TStrings * FilesToCopy,
  375. const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params);
  376. void __fastcall CreateDirectory(const UnicodeString DirName,
  377. const TRemoteProperties * Properties = NULL);
  378. void __fastcall CreateLink(const UnicodeString FileName, const UnicodeString PointTo, bool Symbolic);
  379. void __fastcall DeleteFile(UnicodeString FileName,
  380. const TRemoteFile * File = NULL, void * Params = NULL);
  381. bool __fastcall DeleteFiles(TStrings * FilesToDelete, int Params = 0);
  382. bool __fastcall DeleteLocalFiles(TStrings * FileList, int Params = 0);
  383. bool __fastcall IsRecycledFile(UnicodeString FileName);
  384. void __fastcall CustomCommandOnFile(UnicodeString FileName,
  385. const TRemoteFile * File, void * AParams);
  386. void __fastcall CustomCommandOnFiles(UnicodeString Command, int Params,
  387. TStrings * Files, TCaptureOutputEvent OutputEvent);
  388. void __fastcall ChangeDirectory(const UnicodeString Directory);
  389. void __fastcall EndTransaction();
  390. void __fastcall HomeDirectory();
  391. void __fastcall ChangeFileProperties(UnicodeString FileName,
  392. const TRemoteFile * File, /*const TRemoteProperties */ void * Properties);
  393. void __fastcall ChangeFilesProperties(TStrings * FileList,
  394. const TRemoteProperties * Properties);
  395. bool __fastcall LoadFilesProperties(TStrings * FileList);
  396. void __fastcall TerminalError(UnicodeString Msg);
  397. void __fastcall TerminalError(Exception * E, UnicodeString Msg, UnicodeString HelpKeyword = L"");
  398. void __fastcall ReloadDirectory();
  399. void __fastcall RefreshDirectory();
  400. void __fastcall RenameFile(const UnicodeString FileName, const UnicodeString NewName);
  401. void __fastcall RenameFile(const TRemoteFile * File, const UnicodeString NewName, bool CheckExistence);
  402. void __fastcall MoveFile(const UnicodeString FileName, const TRemoteFile * File,
  403. /*const TMoveFileParams*/ void * Param);
  404. bool __fastcall MoveFiles(TStrings * FileList, const UnicodeString Target,
  405. const UnicodeString FileMask);
  406. void __fastcall CopyFile(const UnicodeString FileName, const TRemoteFile * File,
  407. /*const TMoveFileParams*/ void * Param);
  408. bool __fastcall CopyFiles(TStrings * FileList, const UnicodeString Target,
  409. const UnicodeString FileMask);
  410. bool __fastcall CalculateFilesSize(TStrings * FileList, __int64 & Size,
  411. int Params, const TCopyParamType * CopyParam, bool AllowDirs,
  412. TCalculateSizeStats * Stats);
  413. void __fastcall CalculateFilesChecksum(const UnicodeString & Alg, TStrings * FileList,
  414. TStrings * Checksums, TCalculatedChecksumEvent OnCalculatedChecksum);
  415. void __fastcall ClearCaches();
  416. TSynchronizeChecklist * __fastcall SynchronizeCollect(const UnicodeString LocalDirectory,
  417. const UnicodeString RemoteDirectory, TSynchronizeMode Mode,
  418. const TCopyParamType * CopyParam, int Params,
  419. TSynchronizeDirectory OnSynchronizeDirectory, TSynchronizeOptions * Options);
  420. void __fastcall SynchronizeApply(TSynchronizeChecklist * Checklist,
  421. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  422. const TCopyParamType * CopyParam, int Params,
  423. TSynchronizeDirectory OnSynchronizeDirectory);
  424. void __fastcall FilesFind(UnicodeString Directory, const TFileMasks & FileMask,
  425. TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile);
  426. void __fastcall SpaceAvailable(const UnicodeString Path, TSpaceAvailable & ASpaceAvailable);
  427. bool __fastcall DirectoryFileList(const UnicodeString Path,
  428. TRemoteFileList *& FileList, bool CanLoad);
  429. void __fastcall MakeLocalFileList(const UnicodeString FileName,
  430. const TSearchRec Rec, void * Param);
  431. UnicodeString __fastcall FileUrl(const UnicodeString FileName);
  432. bool __fastcall FileOperationLoopQuery(Exception & E,
  433. TFileOperationProgressType * OperationProgress, const UnicodeString Message,
  434. bool AllowSkip, UnicodeString SpecialRetry = L"", UnicodeString HelpKeyword = L"");
  435. TUsableCopyParamAttrs __fastcall UsableCopyParamAttrs(int Params);
  436. bool __fastcall QueryReopen(Exception * E, int Params,
  437. TFileOperationProgressType * OperationProgress);
  438. UnicodeString __fastcall PeekCurrentDirectory();
  439. void __fastcall FatalAbort();
  440. void __fastcall ReflectSettings();
  441. void __fastcall CollectUsage();
  442. const TSessionInfo & __fastcall GetSessionInfo();
  443. const TFileSystemInfo & __fastcall GetFileSystemInfo(bool Retrieve = false);
  444. void __fastcall inline LogEvent(const UnicodeString & Str);
  445. static UnicodeString __fastcall ExpandFileName(UnicodeString Path,
  446. const UnicodeString BasePath);
  447. __property TSessionData * SessionData = { read = FSessionData };
  448. __property TSessionLog * Log = { read = FLog };
  449. __property TActionLog * ActionLog = { read = FActionLog };
  450. __property TConfiguration * Configuration = { read = FConfiguration };
  451. __property bool Active = { read = GetActive };
  452. __property TSessionStatus Status = { read = FStatus };
  453. __property UnicodeString CurrentDirectory = { read = GetCurrentDirectory, write = SetCurrentDirectory };
  454. __property bool ExceptionOnFail = { read = GetExceptionOnFail, write = SetExceptionOnFail };
  455. __property TRemoteDirectory * Files = { read = FFiles };
  456. __property TNotifyEvent OnChangeDirectory = { read = FOnChangeDirectory, write = FOnChangeDirectory };
  457. __property TReadDirectoryEvent OnReadDirectory = { read = FOnReadDirectory, write = FOnReadDirectory };
  458. __property TNotifyEvent OnStartReadDirectory = { read = FOnStartReadDirectory, write = FOnStartReadDirectory };
  459. __property TReadDirectoryProgressEvent OnReadDirectoryProgress = { read = FOnReadDirectoryProgress, write = FOnReadDirectoryProgress };
  460. __property TDeleteLocalFileEvent OnDeleteLocalFile = { read = FOnDeleteLocalFile, write = FOnDeleteLocalFile };
  461. __property TNotifyEvent OnInitializeLog = { read = FOnInitializeLog, write = FOnInitializeLog };
  462. __property const TRemoteTokenList * Groups = { read = GetGroups };
  463. __property const TRemoteTokenList * Users = { read = GetUsers };
  464. __property const TRemoteTokenList * Membership = { read = GetMembership };
  465. __property TFileOperationProgressEvent OnProgress = { read=FOnProgress, write=FOnProgress };
  466. __property TFileOperationFinished OnFinished = { read=FOnFinished, write=FOnFinished };
  467. __property TCurrentFSProtocol FSProtocol = { read = FFSProtocol };
  468. __property bool UseBusyCursor = { read = FUseBusyCursor, write = FUseBusyCursor };
  469. __property UnicodeString UserName = { read=GetUserName };
  470. __property bool IsCapable[TFSCapability Capability] = { read = GetIsCapable };
  471. __property bool AreCachesEmpty = { read = GetAreCachesEmpty };
  472. __property bool CommandSessionOpened = { read = GetCommandSessionOpened };
  473. __property TTerminal * CommandSession = { read = GetCommandSession };
  474. __property bool AutoReadDirectory = { read = FAutoReadDirectory, write = FAutoReadDirectory };
  475. __property TStrings * FixedPaths = { read = GetFixedPaths };
  476. __property bool ResolvingSymlinks = { read = GetResolvingSymlinks };
  477. __property UnicodeString Password = { read = GetPassword };
  478. __property UnicodeString TunnelPassword = { read = GetTunnelPassword };
  479. __property bool StoredCredentialsTried = { read = GetStoredCredentialsTried };
  480. __property TQueryUserEvent OnQueryUser = { read = FOnQueryUser, write = FOnQueryUser };
  481. __property TPromptUserEvent OnPromptUser = { read = FOnPromptUser, write = FOnPromptUser };
  482. __property TDisplayBannerEvent OnDisplayBanner = { read = FOnDisplayBanner, write = FOnDisplayBanner };
  483. __property TExtendedExceptionEvent OnShowExtendedException = { read = FOnShowExtendedException, write = FOnShowExtendedException };
  484. __property TInformationEvent OnInformation = { read = FOnInformation, write = FOnInformation };
  485. __property TNotifyEvent OnClose = { read = FOnClose, write = FOnClose };
  486. __property int TunnelLocalPortNumber = { read = FTunnelLocalPortNumber };
  487. };
  488. //---------------------------------------------------------------------------
  489. class TSecondaryTerminal : public TTerminal
  490. {
  491. public:
  492. __fastcall TSecondaryTerminal(TTerminal * MainTerminal,
  493. TSessionData * SessionData, TConfiguration * Configuration,
  494. const UnicodeString & Name);
  495. __property TTerminal * MainTerminal = { read = FMainTerminal };
  496. protected:
  497. virtual void __fastcall DirectoryLoaded(TRemoteFileList * FileList);
  498. virtual void __fastcall DirectoryModified(const UnicodeString Path,
  499. bool SubDirs);
  500. virtual bool __fastcall DoPromptUser(TSessionData * Data, TPromptKind Kind,
  501. UnicodeString Name, UnicodeString Instructions, TStrings * Prompts, TStrings * Results);
  502. private:
  503. bool FMasterPasswordTried;
  504. bool FMasterTunnelPasswordTried;
  505. TTerminal * FMainTerminal;
  506. };
  507. //---------------------------------------------------------------------------
  508. class TTerminalList : public TObjectList
  509. {
  510. public:
  511. __fastcall TTerminalList(TConfiguration * AConfiguration);
  512. __fastcall ~TTerminalList();
  513. virtual TTerminal * __fastcall NewTerminal(TSessionData * Data);
  514. virtual void __fastcall FreeTerminal(TTerminal * Terminal);
  515. void __fastcall FreeAndNullTerminal(TTerminal * & Terminal);
  516. virtual void __fastcall Idle();
  517. void __fastcall RecryptPasswords();
  518. __property TTerminal * Terminals[int Index] = { read=GetTerminal };
  519. protected:
  520. virtual TTerminal * __fastcall CreateTerminal(TSessionData * Data);
  521. private:
  522. TConfiguration * FConfiguration;
  523. TTerminal * __fastcall GetTerminal(int Index);
  524. };
  525. //---------------------------------------------------------------------------
  526. struct TCustomCommandParams
  527. {
  528. UnicodeString Command;
  529. int Params;
  530. TCaptureOutputEvent OutputEvent;
  531. };
  532. //---------------------------------------------------------------------------
  533. struct TCalculateSizeStats
  534. {
  535. TCalculateSizeStats();
  536. int Files;
  537. int Directories;
  538. int SymLinks;
  539. };
  540. //---------------------------------------------------------------------------
  541. struct TCalculateSizeParams
  542. {
  543. __int64 Size;
  544. int Params;
  545. const TCopyParamType * CopyParam;
  546. TCalculateSizeStats * Stats;
  547. bool AllowDirs;
  548. bool Result;
  549. };
  550. //---------------------------------------------------------------------------
  551. struct TOverwriteFileParams
  552. {
  553. TOverwriteFileParams();
  554. __int64 SourceSize;
  555. __int64 DestSize;
  556. TDateTime SourceTimestamp;
  557. TDateTime DestTimestamp;
  558. TModificationFmt SourcePrecision;
  559. TModificationFmt DestPrecision;
  560. };
  561. //---------------------------------------------------------------------------
  562. struct TMakeLocalFileListParams
  563. {
  564. TStrings * FileList;
  565. bool IncludeDirs;
  566. bool Recursive;
  567. };
  568. //---------------------------------------------------------------------------
  569. struct TSynchronizeOptions
  570. {
  571. TSynchronizeOptions();
  572. ~TSynchronizeOptions();
  573. TStringList * Filter;
  574. bool __fastcall FilterFind(const UnicodeString & FileName);
  575. bool __fastcall MatchesFilter(const UnicodeString & FileName);
  576. };
  577. //---------------------------------------------------------------------------
  578. class TSynchronizeChecklist
  579. {
  580. friend class TTerminal;
  581. public:
  582. enum TAction { saNone, saUploadNew, saDownloadNew, saUploadUpdate,
  583. saDownloadUpdate, saDeleteRemote, saDeleteLocal };
  584. static const int ActionCount = saDeleteLocal;
  585. class TItem
  586. {
  587. friend class TTerminal;
  588. public:
  589. struct TFileInfo
  590. {
  591. UnicodeString FileName;
  592. UnicodeString Directory;
  593. TDateTime Modification;
  594. TModificationFmt ModificationFmt;
  595. __int64 Size;
  596. };
  597. TAction Action;
  598. bool IsDirectory;
  599. TFileInfo Local;
  600. TFileInfo Remote;
  601. int ImageIndex;
  602. bool Checked;
  603. TRemoteFile * RemoteFile;
  604. const UnicodeString& GetFileName() const;
  605. ~TItem();
  606. private:
  607. FILETIME FLocalLastWriteTime;
  608. TItem();
  609. };
  610. ~TSynchronizeChecklist();
  611. __property int Count = { read = GetCount };
  612. __property const TItem * Item[int Index] = { read = GetItem };
  613. protected:
  614. TSynchronizeChecklist();
  615. void Sort();
  616. void Add(TItem * Item);
  617. int GetCount() const;
  618. const TItem * GetItem(int Index) const;
  619. private:
  620. TList * FList;
  621. static int __fastcall Compare(void * Item1, void * Item2);
  622. };
  623. //---------------------------------------------------------------------------
  624. struct TSpaceAvailable
  625. {
  626. TSpaceAvailable();
  627. __int64 BytesOnDevice;
  628. __int64 UnusedBytesOnDevice;
  629. __int64 BytesAvailableToUser;
  630. __int64 UnusedBytesAvailableToUser;
  631. unsigned long BytesPerAllocationUnit;
  632. };
  633. //---------------------------------------------------------------------------
  634. #endif