FileOperationProgress.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. enum TCancelStatus { csContinue = 0, csCancel, csCancelTransfer, csRemoteAbort };
  15. enum TResumeStatus { rsNotAvailable, rsEnabled, rsDisabled };
  16. enum TBatchOverwrite { boNo, boAll, boNone, boOlder, boAlternateResume, boAppend, boResume };
  17. typedef void __fastcall (__closure *TFileOperationProgressEvent)
  18. (TFileOperationProgressType & ProgressData, TCancelStatus & Cancel);
  19. typedef void __fastcall (__closure *TFileOperationFinished)
  20. (TFileOperation Operation, TOperationSide Side, bool Temp,
  21. const AnsiString & 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. std::vector<unsigned long> FTicks;
  37. std::vector<__int64> FTotalTransferredThen;
  38. protected:
  39. void __fastcall ClearTransfer();
  40. inline void __fastcall DoProgress();
  41. public:
  42. // common data
  43. TFileOperation Operation;
  44. // on what side if operation being processed (local/remote), source of copy
  45. TOperationSide Side;
  46. AnsiString FileName;
  47. AnsiString Directory;
  48. bool AsciiTransfer;
  49. bool TransferingFile;
  50. bool Temp;
  51. // file size to read/write
  52. __int64 LocalSize;
  53. __int64 LocalyUsed;
  54. __int64 TransferSize;
  55. __int64 TransferedSize;
  56. __int64 SkippedSize;
  57. TResumeStatus ResumeStatus;
  58. bool InProgress;
  59. TCancelStatus Cancel;
  60. int Count;
  61. // when operation started
  62. TDateTime StartTime;
  63. // bytes transfered
  64. __int64 TotalTransfered;
  65. __int64 TotalSkipped;
  66. __int64 TotalSize;
  67. TBatchOverwrite BatchOverwrite;
  68. bool SkipToAll;
  69. unsigned long CPSLimit;
  70. bool TotalSizeSet;
  71. bool Suspended;
  72. __fastcall TFileOperationProgressType();
  73. __fastcall TFileOperationProgressType(
  74. TFileOperationProgressEvent AOnProgress, TFileOperationFinished AOnFinished);
  75. __fastcall ~TFileOperationProgressType();
  76. void __fastcall AddLocalyUsed(__int64 ASize);
  77. void __fastcall AddTransfered(__int64 ASize, bool AddToTotals = true);
  78. void __fastcall AddResumed(__int64 ASize);
  79. void __fastcall Clear();
  80. unsigned int __fastcall CPS();
  81. void __fastcall Finish(AnsiString FileName, bool Success,
  82. TOnceDoneOperation & OnceDoneOperation);
  83. unsigned long __fastcall LocalBlockSize();
  84. bool __fastcall IsLocalyDone();
  85. bool __fastcall IsTransferDone();
  86. void __fastcall SetFile(AnsiString AFileName);
  87. int __fastcall OperationProgress();
  88. unsigned long __fastcall TransferBlockSize();
  89. unsigned long __fastcall AdjustToCPSLimit(unsigned long Size);
  90. static unsigned long __fastcall StaticBlockSize();
  91. void __fastcall Reset();
  92. void __fastcall Resume();
  93. void __fastcall SetLocalSize(__int64 ASize);
  94. void __fastcall SetAsciiTransfer(bool AAsciiTransfer);
  95. void __fastcall SetResumeStatus(TResumeStatus AResumeStatus);
  96. void __fastcall SetTransferSize(__int64 ASize);
  97. void __fastcall ChangeTransferSize(__int64 ASize);
  98. void __fastcall RollbackTransfer();
  99. void __fastcall SetTotalSize(__int64 ASize);
  100. void __fastcall Start(TFileOperation AOperation, TOperationSide ASide, int ACount);
  101. void __fastcall Start(TFileOperation AOperation,
  102. TOperationSide ASide, int ACount, bool ATemp, const AnsiString ADirectory,
  103. unsigned long ACPSLimit);
  104. void __fastcall Stop();
  105. void __fastcall Suspend();
  106. // whole operation
  107. TDateTime __fastcall TimeElapsed();
  108. // only current file
  109. TDateTime __fastcall TimeExpected();
  110. TDateTime __fastcall TotalTimeExpected();
  111. TDateTime __fastcall TotalTimeLeft();
  112. int __fastcall TransferProgress();
  113. int __fastcall OverallProgress();
  114. int __fastcall TotalTransferProgress();
  115. };
  116. //---------------------------------------------------------------------------
  117. class TSuspendFileOperationProgress
  118. {
  119. public:
  120. __fastcall TSuspendFileOperationProgress(TFileOperationProgressType * OperationProgress)
  121. {
  122. FOperationProgress = OperationProgress;
  123. FOperationProgress->Suspend();
  124. }
  125. __fastcall ~TSuspendFileOperationProgress()
  126. {
  127. FOperationProgress->Resume();
  128. }
  129. private:
  130. TFileOperationProgressType * FOperationProgress;
  131. };
  132. //---------------------------------------------------------------------------
  133. #endif