FileOperationProgress.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 int Count = { read = FCount };
  92. __property UnicodeString FileName = { read = FFileName };
  93. __property UnicodeString FullFileName = { read = FFullFileName };
  94. __property UnicodeString Directory = { read = FDirectory };
  95. __property bool AsciiTransfer = { read = FAsciiTransfer };
  96. // Can be true with SCP protocol only
  97. __property bool TransferringFile = { read = FTransferringFile };
  98. __property bool Temp = { read = FTemp };
  99. // file size to read/write
  100. __property __int64 LocalSize = { read = FLocalSize };
  101. __property __int64 LocallyUsed = { read = FLocallyUsed };
  102. __property __int64 TransferSize = { read = FTransferSize };
  103. __property __int64 TransferredSize = { read = FTransferredSize };
  104. __property __int64 SkippedSize = { read = FSkippedSize };
  105. __property bool InProgress = { read = FInProgress };
  106. __property bool Done = { read = FDone };
  107. __property bool FileInProgress = { read = FFileInProgress };
  108. __property TCancelStatus Cancel = { read = GetCancel };
  109. // when operation started
  110. __property TDateTime StartTime = { read = FStartTime };
  111. // bytes transferred
  112. __property __int64 TotalTransferred = { read = GetTotalTransferred };
  113. __property __int64 TotalSize = { read = GetTotalSize };
  114. __property int FilesFinishedSuccessfully = { read = FFilesFinishedSuccessfully };
  115. __property TBatchOverwrite BatchOverwrite = { read = GetBatchOverwrite };
  116. __property bool SkipToAll = { read = GetSkipToAll };
  117. __property unsigned long CPSLimit = { read = GetCPSLimit };
  118. __property bool TotalSizeSet = { read = FTotalSizeSet };
  119. __property bool Suspended = { read = FSuspended };
  120. __fastcall TFileOperationProgressType();
  121. __fastcall TFileOperationProgressType(
  122. TFileOperationProgressEvent AOnProgress, TFileOperationFinished AOnFinished,
  123. TFileOperationProgressType * Parent = NULL);
  124. __fastcall ~TFileOperationProgressType();
  125. void __fastcall Assign(const TFileOperationProgressType & Other);
  126. void __fastcall AssignButKeepSuspendState(const TFileOperationProgressType & Other);
  127. void __fastcall AddLocallyUsed(__int64 ASize);
  128. void __fastcall AddTransferred(__int64 ASize, bool AddToTotals = true);
  129. void __fastcall AddResumed(__int64 ASize);
  130. void __fastcall AddSkippedFileSize(__int64 ASize);
  131. void __fastcall Clear();
  132. unsigned int __fastcall CPS();
  133. void __fastcall Finish(UnicodeString FileName, bool Success,
  134. TOnceDoneOperation & OnceDoneOperation);
  135. void __fastcall Progress();
  136. unsigned long __fastcall LocalBlockSize();
  137. bool __fastcall IsLocallyDone();
  138. bool __fastcall IsTransferDone();
  139. void __fastcall SetFile(UnicodeString AFileName, bool AFileInProgress = true);
  140. void __fastcall SetFileInProgress();
  141. unsigned long __fastcall TransferBlockSize();
  142. unsigned long __fastcall AdjustToCPSLimit(unsigned long Size);
  143. void __fastcall ThrottleToCPSLimit(unsigned long Size);
  144. static unsigned long __fastcall StaticBlockSize();
  145. void __fastcall Reset();
  146. void __fastcall Resume();
  147. void __fastcall SetLocalSize(__int64 ASize);
  148. void __fastcall SetAsciiTransfer(bool AAsciiTransfer);
  149. void __fastcall SetTransferSize(__int64 ASize);
  150. void __fastcall ChangeTransferSize(__int64 ASize);
  151. void __fastcall RollbackTransfer();
  152. void __fastcall SetTotalSize(__int64 ASize);
  153. void __fastcall Start(TFileOperation AOperation, TOperationSide ASide, int ACount);
  154. void __fastcall Start(TFileOperation AOperation,
  155. TOperationSide ASide, int ACount, bool ATemp, const UnicodeString ADirectory,
  156. unsigned long ACPSLimit);
  157. void __fastcall Stop();
  158. void __fastcall SetDone();
  159. void __fastcall Suspend();
  160. void __fastcall LockUserSelections();
  161. void __fastcall UnlockUserSelections();
  162. // whole operation
  163. TDateTime __fastcall TimeElapsed();
  164. // only current file
  165. TDateTime __fastcall TimeExpected();
  166. TDateTime __fastcall TotalTimeLeft();
  167. int __fastcall TransferProgress();
  168. int __fastcall OverallProgress();
  169. int __fastcall TotalTransferProgress();
  170. void __fastcall SetSpeedCounters();
  171. void __fastcall SetTransferringFile(bool ATransferringFile);
  172. TCancelStatus __fastcall GetCancel();
  173. void __fastcall SetCancel(TCancelStatus ACancel);
  174. void __fastcall SetCancelAtLeast(TCancelStatus ACancel);
  175. bool __fastcall ClearCancelFile();
  176. void __fastcall SetCPSLimit(unsigned long ACPSLimit);
  177. void __fastcall SetBatchOverwrite(TBatchOverwrite ABatchOverwrite);
  178. void __fastcall SetSkipToAll();
  179. UnicodeString __fastcall GetLogStr(bool Done);
  180. };
  181. //---------------------------------------------------------------------------
  182. class TSuspendFileOperationProgress
  183. {
  184. public:
  185. __fastcall TSuspendFileOperationProgress(TFileOperationProgressType * OperationProgress)
  186. {
  187. FOperationProgress = OperationProgress;
  188. if (FOperationProgress != NULL)
  189. {
  190. FOperationProgress->Suspend();
  191. }
  192. }
  193. __fastcall ~TSuspendFileOperationProgress()
  194. {
  195. if (FOperationProgress != NULL)
  196. {
  197. FOperationProgress->Resume();
  198. }
  199. }
  200. private:
  201. TFileOperationProgressType * FOperationProgress;
  202. };
  203. //---------------------------------------------------------------------------
  204. #endif