FileOperationProgress.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 };
  14. // csCancelTransfer and csRemoteAbort are used with SCP only
  15. enum TCancelStatus { csContinue = 0, 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. // when it was last time suspended (to calculate suspend time in Resume())
  27. unsigned int FSuspendTime;
  28. // when current file was started being transfered
  29. TDateTime FFileStartTime;
  30. int FFilesFinished;
  31. TFileOperationProgressEvent FOnProgress;
  32. TFileOperationFinished FOnFinished;
  33. bool FReset;
  34. unsigned int FLastSecond;
  35. unsigned long FRemainingCPS;
  36. bool FCounterSet;
  37. std::vector<unsigned long> FTicks;
  38. std::vector<__int64> FTotalTransferredThen;
  39. protected:
  40. void __fastcall ClearTransfer();
  41. inline void __fastcall DoProgress();
  42. public:
  43. // common data
  44. TFileOperation Operation;
  45. // on what side if operation being processed (local/remote), source of copy
  46. TOperationSide Side;
  47. UnicodeString FileName;
  48. UnicodeString FullFileName;
  49. UnicodeString Directory;
  50. bool AsciiTransfer;
  51. // Can be true with SCP protocol only
  52. bool TransferingFile;
  53. bool Temp;
  54. // file size to read/write
  55. __int64 LocalSize;
  56. __int64 LocallyUsed;
  57. __int64 TransferSize;
  58. __int64 TransferedSize;
  59. __int64 SkippedSize;
  60. bool InProgress;
  61. bool FileInProgress;
  62. TCancelStatus Cancel;
  63. int Count;
  64. // when operation started
  65. TDateTime StartTime;
  66. // bytes transfered
  67. __int64 TotalTransfered;
  68. __int64 TotalSkipped;
  69. __int64 TotalSize;
  70. TBatchOverwrite BatchOverwrite;
  71. bool SkipToAll;
  72. unsigned long CPSLimit;
  73. bool TotalSizeSet;
  74. bool Suspended;
  75. __fastcall TFileOperationProgressType();
  76. __fastcall TFileOperationProgressType(
  77. TFileOperationProgressEvent AOnProgress, TFileOperationFinished AOnFinished);
  78. __fastcall ~TFileOperationProgressType();
  79. void __fastcall AssignButKeepSuspendState(const TFileOperationProgressType & Other);
  80. void __fastcall AddLocallyUsed(__int64 ASize);
  81. void __fastcall AddTransfered(__int64 ASize, bool AddToTotals = true);
  82. void __fastcall AddResumed(__int64 ASize);
  83. void __fastcall AddSkippedFileSize(__int64 ASize);
  84. void __fastcall Clear();
  85. unsigned int __fastcall CPS();
  86. void __fastcall Finish(UnicodeString FileName, bool Success,
  87. TOnceDoneOperation & OnceDoneOperation);
  88. void __fastcall Progress();
  89. unsigned long __fastcall LocalBlockSize();
  90. bool __fastcall IsLocallyDone();
  91. bool __fastcall IsTransferDone();
  92. void __fastcall SetFile(UnicodeString AFileName, bool AFileInProgress = true);
  93. void __fastcall SetFileInProgress();
  94. int __fastcall OperationProgress();
  95. unsigned long __fastcall TransferBlockSize();
  96. unsigned long __fastcall AdjustToCPSLimit(unsigned long Size);
  97. void __fastcall ThrottleToCPSLimit(unsigned long Size);
  98. static unsigned long __fastcall StaticBlockSize();
  99. void __fastcall Reset();
  100. void __fastcall Resume();
  101. void __fastcall SetLocalSize(__int64 ASize);
  102. void __fastcall SetAsciiTransfer(bool AAsciiTransfer);
  103. void __fastcall SetTransferSize(__int64 ASize);
  104. void __fastcall ChangeTransferSize(__int64 ASize);
  105. void __fastcall RollbackTransfer();
  106. void __fastcall SetTotalSize(__int64 ASize);
  107. void __fastcall Start(TFileOperation AOperation, TOperationSide ASide, int ACount);
  108. void __fastcall Start(TFileOperation AOperation,
  109. TOperationSide ASide, int ACount, bool ATemp, const UnicodeString ADirectory,
  110. unsigned long ACPSLimit);
  111. void __fastcall Stop();
  112. void __fastcall Suspend();
  113. // whole operation
  114. TDateTime __fastcall TimeElapsed();
  115. // only current file
  116. TDateTime __fastcall TimeExpected();
  117. TDateTime __fastcall TotalTimeExpected();
  118. TDateTime __fastcall TotalTimeLeft();
  119. int __fastcall TransferProgress();
  120. int __fastcall OverallProgress();
  121. int __fastcall TotalTransferProgress();
  122. void __fastcall SetSpeedCounters();
  123. };
  124. //---------------------------------------------------------------------------
  125. class TSuspendFileOperationProgress
  126. {
  127. public:
  128. __fastcall TSuspendFileOperationProgress(TFileOperationProgressType * OperationProgress)
  129. {
  130. FOperationProgress = OperationProgress;
  131. if (FOperationProgress != NULL)
  132. {
  133. FOperationProgress->Suspend();
  134. }
  135. }
  136. __fastcall ~TSuspendFileOperationProgress()
  137. {
  138. if (FOperationProgress != NULL)
  139. {
  140. FOperationProgress->Resume();
  141. }
  142. }
  143. private:
  144. TFileOperationProgressType * FOperationProgress;
  145. };
  146. //---------------------------------------------------------------------------
  147. #endif