FileOperationProgress.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 FTransferingFile;
  33. bool FTemp;
  34. __int64 FLocalSize;
  35. __int64 FLocallyUsed;
  36. __int64 FTransferSize;
  37. __int64 FTransferedSize;
  38. __int64 FSkippedSize;
  39. bool FInProgress;
  40. bool FFileInProgress;
  41. TCancelStatus FCancel;
  42. int FCount;
  43. TDateTime FStartTime;
  44. __int64 FTotalTransfered;
  45. __int64 FTotalSkipped;
  46. __int64 FTotalSize;
  47. TBatchOverwrite FBatchOverwrite;
  48. bool FSkipToAll;
  49. unsigned long FCPSLimit;
  50. bool FTotalSizeSet;
  51. bool FSuspended;
  52. // when it was last time suspended (to calculate suspend time in Resume())
  53. unsigned int FSuspendTime;
  54. // when current file was started being transfered
  55. TDateTime FFileStartTime;
  56. int FFilesFinished;
  57. TFileOperationProgressEvent FOnProgress;
  58. TFileOperationFinished FOnFinished;
  59. bool FReset;
  60. unsigned int FLastSecond;
  61. unsigned long FRemainingCPS;
  62. bool FCounterSet;
  63. std::vector<unsigned long> FTicks;
  64. std::vector<__int64> FTotalTransferredThen;
  65. protected:
  66. void __fastcall ClearTransfer();
  67. inline void __fastcall DoProgress();
  68. int __fastcall OperationProgress();
  69. public:
  70. // common data
  71. __property TFileOperation Operation = { read = FOperation };
  72. // on what side if operation being processed (local/remote), source of copy
  73. __property TOperationSide Side = { read = FSide };
  74. __property UnicodeString FileName = { read = FFileName };
  75. __property UnicodeString FullFileName = { read = FFullFileName };
  76. __property UnicodeString Directory = { read = FDirectory };
  77. __property bool AsciiTransfer = { read = FAsciiTransfer };
  78. // Can be true with SCP protocol only
  79. __property bool TransferingFile = { read = FTransferingFile };
  80. __property bool Temp = { read = FTemp };
  81. // file size to read/write
  82. __property __int64 LocalSize = { read = FLocalSize };
  83. __property __int64 LocallyUsed = { read = FLocallyUsed };
  84. __property __int64 TransferSize = { read = FTransferSize };
  85. __property __int64 TransferedSize = { read = FTransferedSize };
  86. __property __int64 SkippedSize = { read = FSkippedSize };
  87. __property bool InProgress = { read = FInProgress };
  88. __property bool FileInProgress = { read = FFileInProgress };
  89. __property TCancelStatus Cancel = { read = FCancel };
  90. __property int Count = { read = FCount };
  91. // when operation started
  92. __property TDateTime StartTime = { read = FStartTime };
  93. // bytes transfered
  94. __property __int64 TotalTransfered = { read = FTotalTransfered };
  95. __property __int64 TotalSkipped = { read = FTotalSkipped };
  96. __property __int64 TotalSize = { read = FTotalSize };
  97. __property TBatchOverwrite BatchOverwrite = { read = FBatchOverwrite };
  98. __property bool SkipToAll = { read = FSkipToAll };
  99. __property unsigned long CPSLimit = { read = FCPSLimit };
  100. __property bool TotalSizeSet = { read = FTotalSizeSet };
  101. __property bool Suspended = { read = FSuspended };
  102. __fastcall TFileOperationProgressType();
  103. __fastcall TFileOperationProgressType(
  104. TFileOperationProgressEvent AOnProgress, TFileOperationFinished AOnFinished);
  105. __fastcall ~TFileOperationProgressType();
  106. void __fastcall AssignButKeepSuspendState(const TFileOperationProgressType & Other);
  107. void __fastcall AddLocallyUsed(__int64 ASize);
  108. void __fastcall AddTransfered(__int64 ASize, bool AddToTotals = true);
  109. void __fastcall AddResumed(__int64 ASize);
  110. void __fastcall AddSkippedFileSize(__int64 ASize);
  111. void __fastcall Clear();
  112. unsigned int __fastcall CPS();
  113. void __fastcall Finish(UnicodeString FileName, bool Success,
  114. TOnceDoneOperation & OnceDoneOperation);
  115. void __fastcall Progress();
  116. unsigned long __fastcall LocalBlockSize();
  117. bool __fastcall IsLocallyDone();
  118. bool __fastcall IsTransferDone();
  119. void __fastcall SetFile(UnicodeString AFileName, bool AFileInProgress = true);
  120. void __fastcall SetFileInProgress();
  121. unsigned long __fastcall TransferBlockSize();
  122. unsigned long __fastcall AdjustToCPSLimit(unsigned long Size);
  123. void __fastcall ThrottleToCPSLimit(unsigned long Size);
  124. static unsigned long __fastcall StaticBlockSize();
  125. void __fastcall Reset();
  126. void __fastcall Resume();
  127. void __fastcall SetLocalSize(__int64 ASize);
  128. void __fastcall SetAsciiTransfer(bool AAsciiTransfer);
  129. void __fastcall SetTransferSize(__int64 ASize);
  130. void __fastcall ChangeTransferSize(__int64 ASize);
  131. void __fastcall RollbackTransfer();
  132. void __fastcall SetTotalSize(__int64 ASize);
  133. void __fastcall Start(TFileOperation AOperation, TOperationSide ASide, int ACount);
  134. void __fastcall Start(TFileOperation AOperation,
  135. TOperationSide ASide, int ACount, bool ATemp, const UnicodeString ADirectory,
  136. unsigned long ACPSLimit);
  137. void __fastcall Stop();
  138. void __fastcall Suspend();
  139. // whole operation
  140. TDateTime __fastcall TimeElapsed();
  141. // only current file
  142. TDateTime __fastcall TimeExpected();
  143. TDateTime __fastcall TotalTimeExpected();
  144. TDateTime __fastcall TotalTimeLeft();
  145. int __fastcall TransferProgress();
  146. int __fastcall OverallProgress();
  147. int __fastcall TotalTransferProgress();
  148. void __fastcall SetSpeedCounters();
  149. void __fastcall SetTransferingFile(bool ATransferingFile);
  150. void __fastcall SetCancel(TCancelStatus ACancel);
  151. void __fastcall SetCancelAtLeast(TCancelStatus ACancel);
  152. bool __fastcall ClearCancelFile();
  153. void __fastcall SetCPSLimit(unsigned long ACPSLimit);
  154. void __fastcall SetBatchOverwrite(TBatchOverwrite ABatchOverwrite);
  155. void __fastcall SetSkipToAll();
  156. };
  157. //---------------------------------------------------------------------------
  158. class TSuspendFileOperationProgress
  159. {
  160. public:
  161. __fastcall TSuspendFileOperationProgress(TFileOperationProgressType * OperationProgress)
  162. {
  163. FOperationProgress = OperationProgress;
  164. if (FOperationProgress != NULL)
  165. {
  166. FOperationProgress->Suspend();
  167. }
  168. }
  169. __fastcall ~TSuspendFileOperationProgress()
  170. {
  171. if (FOperationProgress != NULL)
  172. {
  173. FOperationProgress->Resume();
  174. }
  175. }
  176. private:
  177. TFileOperationProgressType * FOperationProgress;
  178. };
  179. //---------------------------------------------------------------------------
  180. #endif