FileOperationProgress.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //---------------------------------------------------------------------------
  2. #ifndef FileOperationProgressH
  3. #define FileOperationProgressH
  4. //---------------------------------------------------------------------------
  5. #include "Configuration.h"
  6. #include "CopyParam.h"
  7. #include "Exceptions.h"
  8. #include <vector>
  9. //---------------------------------------------------------------------------
  10. class TFileOperationProgressType;
  11. enum TFileOperation { foNone, foCopy, foMove, foDelete, foSetProperties,
  12. foRename, foCustomCommand, foCalculateSize, foRemoteMove, foRemoteCopy,
  13. foGetProperties, foCalculateChecksum, foLock, foUnlock };
  14. // csCancelTransfer and csRemoteAbort are used with SCP only
  15. enum TCancelStatus { csContinue = 0, csCancelFile, csCancel, csCancelTransfer, csRemoteAbort };
  16. enum TBatchOverwrite { boNo, boAll, boNone, boOlder, boAlternateResume, boAppend, boResume };
  17. typedef void __fastcall (__closure *TFileOperationProgressEvent)
  18. (TFileOperationProgressType & ProgressData);
  19. typedef void __fastcall (__closure *TFileOperationFinished)
  20. (TFileOperation Operation, TOperationSide Side, bool Temp,
  21. const UnicodeString & FileName, bool Success, TOnceDoneOperation & OnceDoneOperation);
  22. //---------------------------------------------------------------------------
  23. class TFileOperationProgressType
  24. {
  25. private:
  26. TFileOperation FOperation;
  27. TOperationSide FSide;
  28. UnicodeString FFileName;
  29. UnicodeString FFullFileName;
  30. UnicodeString FDirectory;
  31. bool FAsciiTransfer;
  32. bool FTransferringFile;
  33. bool FTemp;
  34. __int64 FLocalSize;
  35. __int64 FLocallyUsed;
  36. __int64 FTransferSize;
  37. __int64 FTransferredSize;
  38. __int64 FSkippedSize;
  39. bool FInProgress;
  40. bool FDone;
  41. bool FFileInProgress;
  42. TCancelStatus FCancel;
  43. int FCount;
  44. TDateTime FStartTime;
  45. __int64 FTotalTransferred;
  46. __int64 FTotalSkipped;
  47. __int64 FTotalSize;
  48. TBatchOverwrite FBatchOverwrite;
  49. bool FSkipToAll;
  50. unsigned long FCPSLimit;
  51. bool FTotalSizeSet;
  52. bool FSuspended;
  53. TFileOperationProgressType * FParent;
  54. // when it was last time suspended (to calculate suspend time in Resume())
  55. unsigned int FSuspendTime;
  56. // when current file was started being transferred
  57. TDateTime FFileStartTime;
  58. int FFilesFinished;
  59. int FFilesFinishedSuccessfully;
  60. TFileOperationProgressEvent FOnProgress;
  61. TFileOperationFinished FOnFinished;
  62. bool FReset;
  63. unsigned int FLastSecond;
  64. unsigned long FRemainingCPS;
  65. bool FCounterSet;
  66. std::vector<unsigned long> FTicks;
  67. std::vector<__int64> FTotalTransferredThen;
  68. TCriticalSection * FSection;
  69. TCriticalSection * FUserSelectionsSection;
  70. __int64 __fastcall GetTotalTransferred();
  71. __int64 __fastcall GetTotalSize();
  72. unsigned long __fastcall GetCPSLimit();
  73. TBatchOverwrite __fastcall GetBatchOverwrite();
  74. bool __fastcall GetSkipToAll();
  75. protected:
  76. void __fastcall ClearTransfer();
  77. inline void __fastcall DoProgress();
  78. int __fastcall OperationProgress();
  79. void __fastcall AddTransferredToTotals(__int64 ASize);
  80. void __fastcall AddSkipped(__int64 ASize);
  81. void __fastcall AddTotalSize(__int64 ASize);
  82. void __fastcall RollbackTransferFromTotals(__int64 ATransferredSize, __int64 ASkippedSize);
  83. unsigned int __fastcall GetCPS();
  84. void __fastcall Init();
  85. static bool __fastcall PassCancelToParent(TCancelStatus ACancel);
  86. public:
  87. // common data
  88. __property TFileOperation Operation = { read = FOperation };
  89. // on what side if operation being processed (local/remote), source of copy
  90. __property TOperationSide Side = { read = FSide };
  91. __property UnicodeString FileName = { read = FFileName };
  92. __property UnicodeString FullFileName = { read = FFullFileName };
  93. __property UnicodeString Directory = { read = FDirectory };
  94. __property bool AsciiTransfer = { read = FAsciiTransfer };
  95. // Can be true with SCP protocol only
  96. __property bool TransferringFile = { read = FTransferringFile };
  97. __property bool Temp = { read = FTemp };
  98. // file size to read/write
  99. __property __int64 LocalSize = { read = FLocalSize };
  100. __property __int64 LocallyUsed = { read = FLocallyUsed };
  101. __property __int64 TransferSize = { read = FTransferSize };
  102. __property __int64 TransferredSize = { read = FTransferredSize };
  103. __property __int64 SkippedSize = { read = FSkippedSize };
  104. __property bool InProgress = { read = FInProgress };
  105. __property bool Done = { read = FDone };
  106. __property bool FileInProgress = { read = FFileInProgress };
  107. __property TCancelStatus Cancel = { read = GetCancel };
  108. // when operation started
  109. __property TDateTime StartTime = { read = FStartTime };
  110. // bytes transferred
  111. __property __int64 TotalTransferred = { read = GetTotalTransferred };
  112. __property __int64 TotalSize = { read = GetTotalSize };
  113. __property int FilesFinishedSuccessfully = { read = FFilesFinishedSuccessfully };
  114. __property TBatchOverwrite BatchOverwrite = { read = GetBatchOverwrite };
  115. __property bool SkipToAll = { read = GetSkipToAll };
  116. __property unsigned long CPSLimit = { read = GetCPSLimit };
  117. __property bool TotalSizeSet = { read = FTotalSizeSet };
  118. __property bool Suspended = { read = FSuspended };
  119. __fastcall TFileOperationProgressType();
  120. __fastcall TFileOperationProgressType(
  121. TFileOperationProgressEvent AOnProgress, TFileOperationFinished AOnFinished,
  122. TFileOperationProgressType * Parent = NULL);
  123. __fastcall ~TFileOperationProgressType();
  124. void __fastcall Assign(const TFileOperationProgressType & Other);
  125. void __fastcall AssignButKeepSuspendState(const TFileOperationProgressType & Other);
  126. void __fastcall AddLocallyUsed(__int64 ASize);
  127. void __fastcall AddTransferred(__int64 ASize, bool AddToTotals = true);
  128. void __fastcall AddResumed(__int64 ASize);
  129. void __fastcall AddSkippedFileSize(__int64 ASize);
  130. void __fastcall Clear();
  131. unsigned int __fastcall CPS();
  132. void __fastcall Finish(UnicodeString FileName, bool Success,
  133. TOnceDoneOperation & OnceDoneOperation);
  134. void __fastcall Progress();
  135. unsigned long __fastcall LocalBlockSize();
  136. bool __fastcall IsLocallyDone();
  137. bool __fastcall IsTransferDone();
  138. void __fastcall SetFile(UnicodeString AFileName, bool AFileInProgress = true);
  139. void __fastcall SetFileInProgress();
  140. unsigned long __fastcall TransferBlockSize();
  141. unsigned long __fastcall AdjustToCPSLimit(unsigned long Size);
  142. void __fastcall ThrottleToCPSLimit(unsigned long Size);
  143. static unsigned long __fastcall StaticBlockSize();
  144. void __fastcall Reset();
  145. void __fastcall Resume();
  146. void __fastcall SetLocalSize(__int64 ASize);
  147. void __fastcall SetAsciiTransfer(bool AAsciiTransfer);
  148. void __fastcall SetTransferSize(__int64 ASize);
  149. void __fastcall ChangeTransferSize(__int64 ASize);
  150. void __fastcall RollbackTransfer();
  151. void __fastcall SetTotalSize(__int64 ASize);
  152. void __fastcall Start(TFileOperation AOperation, TOperationSide ASide, int ACount);
  153. void __fastcall Start(TFileOperation AOperation,
  154. TOperationSide ASide, int ACount, bool ATemp, const UnicodeString ADirectory,
  155. unsigned long ACPSLimit);
  156. void __fastcall Stop();
  157. void __fastcall SetDone();
  158. void __fastcall Suspend();
  159. void __fastcall LockUserSelections();
  160. void __fastcall UnlockUserSelections();
  161. // whole operation
  162. TDateTime __fastcall TimeElapsed();
  163. // only current file
  164. TDateTime __fastcall TimeExpected();
  165. TDateTime __fastcall TotalTimeLeft();
  166. int __fastcall TransferProgress();
  167. int __fastcall OverallProgress();
  168. int __fastcall TotalTransferProgress();
  169. void __fastcall SetSpeedCounters();
  170. void __fastcall SetTransferringFile(bool ATransferringFile);
  171. TCancelStatus __fastcall GetCancel();
  172. void __fastcall SetCancel(TCancelStatus ACancel);
  173. void __fastcall SetCancelAtLeast(TCancelStatus ACancel);
  174. bool __fastcall ClearCancelFile();
  175. void __fastcall SetCPSLimit(unsigned long ACPSLimit);
  176. void __fastcall SetBatchOverwrite(TBatchOverwrite ABatchOverwrite);
  177. void __fastcall SetSkipToAll();
  178. };
  179. //---------------------------------------------------------------------------
  180. class TSuspendFileOperationProgress
  181. {
  182. public:
  183. __fastcall TSuspendFileOperationProgress(TFileOperationProgressType * OperationProgress)
  184. {
  185. FOperationProgress = OperationProgress;
  186. if (FOperationProgress != NULL)
  187. {
  188. FOperationProgress->Suspend();
  189. }
  190. }
  191. __fastcall ~TSuspendFileOperationProgress()
  192. {
  193. if (FOperationProgress != NULL)
  194. {
  195. FOperationProgress->Resume();
  196. }
  197. }
  198. private:
  199. TFileOperationProgressType * FOperationProgress;
  200. };
  201. //---------------------------------------------------------------------------
  202. #endif