FileOperationProgress.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 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. 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. UnicodeString FileName;
  47. UnicodeString Directory;
  48. bool AsciiTransfer;
  49. bool TransferingFile;
  50. bool Temp;
  51. // file size to read/write
  52. __int64 LocalSize;
  53. __int64 LocallyUsed;
  54. __int64 TransferSize;
  55. __int64 TransferedSize;
  56. __int64 SkippedSize;
  57. TResumeStatus ResumeStatus;
  58. bool InProgress;
  59. bool FileInProgress;
  60. TCancelStatus Cancel;
  61. int Count;
  62. // when operation started
  63. TDateTime StartTime;
  64. // bytes transfered
  65. __int64 TotalTransfered;
  66. __int64 TotalSkipped;
  67. __int64 TotalSize;
  68. TBatchOverwrite BatchOverwrite;
  69. bool SkipToAll;
  70. unsigned long CPSLimit;
  71. bool TotalSizeSet;
  72. bool Suspended;
  73. __fastcall TFileOperationProgressType();
  74. __fastcall TFileOperationProgressType(
  75. TFileOperationProgressEvent AOnProgress, TFileOperationFinished AOnFinished);
  76. __fastcall ~TFileOperationProgressType();
  77. void __fastcall AddLocallyUsed(__int64 ASize);
  78. void __fastcall AddTransfered(__int64 ASize, bool AddToTotals = true);
  79. void __fastcall AddResumed(__int64 ASize);
  80. void __fastcall Clear();
  81. unsigned int __fastcall CPS();
  82. void __fastcall Finish(UnicodeString FileName, bool Success,
  83. TOnceDoneOperation & OnceDoneOperation);
  84. unsigned long __fastcall LocalBlockSize();
  85. bool __fastcall IsLocallyDone();
  86. bool __fastcall IsTransferDone();
  87. void __fastcall SetFile(UnicodeString AFileName, bool AFileInProgress = true);
  88. void __fastcall SetFileInProgress();
  89. int __fastcall OperationProgress();
  90. unsigned long __fastcall TransferBlockSize();
  91. unsigned long __fastcall AdjustToCPSLimit(unsigned long Size);
  92. static unsigned long __fastcall StaticBlockSize();
  93. void __fastcall Reset();
  94. void __fastcall Resume();
  95. void __fastcall SetLocalSize(__int64 ASize);
  96. void __fastcall SetAsciiTransfer(bool AAsciiTransfer);
  97. void __fastcall SetResumeStatus(TResumeStatus AResumeStatus);
  98. void __fastcall SetTransferSize(__int64 ASize);
  99. void __fastcall ChangeTransferSize(__int64 ASize);
  100. void __fastcall RollbackTransfer();
  101. void __fastcall SetTotalSize(__int64 ASize);
  102. void __fastcall Start(TFileOperation AOperation, TOperationSide ASide, int ACount);
  103. void __fastcall Start(TFileOperation AOperation,
  104. TOperationSide ASide, int ACount, bool ATemp, const UnicodeString ADirectory,
  105. unsigned long ACPSLimit);
  106. void __fastcall Stop();
  107. void __fastcall Suspend();
  108. // whole operation
  109. TDateTime __fastcall TimeElapsed();
  110. // only current file
  111. TDateTime __fastcall TimeExpected();
  112. TDateTime __fastcall TotalTimeExpected();
  113. TDateTime __fastcall TotalTimeLeft();
  114. int __fastcall TransferProgress();
  115. int __fastcall OverallProgress();
  116. int __fastcall TotalTransferProgress();
  117. };
  118. //---------------------------------------------------------------------------
  119. class TSuspendFileOperationProgress
  120. {
  121. public:
  122. __fastcall TSuspendFileOperationProgress(TFileOperationProgressType * OperationProgress)
  123. {
  124. FOperationProgress = OperationProgress;
  125. if (FOperationProgress != NULL)
  126. {
  127. FOperationProgress->Suspend();
  128. }
  129. }
  130. __fastcall ~TSuspendFileOperationProgress()
  131. {
  132. if (FOperationProgress != NULL)
  133. {
  134. FOperationProgress->Resume();
  135. }
  136. }
  137. private:
  138. TFileOperationProgressType * FOperationProgress;
  139. };
  140. //---------------------------------------------------------------------------
  141. #endif