FileOperationProgress.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //---------------------------------------------------------------------------
  2. #ifndef FileOperationProgressH
  3. #define FileOperationProgressH
  4. //---------------------------------------------------------------------------
  5. #include "Configuration.h"
  6. #include "CopyParam.h"
  7. #include <vector>
  8. //---------------------------------------------------------------------------
  9. class TFileOperationProgressType;
  10. enum TFileOperation { foNone, foCopy, foMove, foDelete, foSetProperties,
  11. foRename, foCustomCommand, foCalculateSize, foRemoteMove, foRemoteCopy,
  12. foGetProperties, foCalculateChecksum };
  13. enum TCancelStatus { csContinue = 0, csCancel, csCancelTransfer, csRemoteAbort };
  14. enum TResumeStatus { rsNotAvailable, rsEnabled, rsDisabled };
  15. typedef void __fastcall (__closure *TFileOperationProgressEvent)
  16. (TFileOperationProgressType & ProgressData, TCancelStatus & Cancel);
  17. typedef void __fastcall (__closure *TFileOperationFinished)
  18. (TFileOperation Operation, TOperationSide Side, bool Temp,
  19. const AnsiString FileName, bool Success, bool & DisconnectWhenComplete);
  20. //---------------------------------------------------------------------------
  21. class TFileOperationProgressType
  22. {
  23. private:
  24. // when it was last time suspended (to calculate suspend time in Resume())
  25. unsigned int FSuspendTime;
  26. // when current file was started being transfered
  27. TDateTime FFileStartTime;
  28. int FFilesFinished;
  29. TFileOperationProgressEvent FOnProgress;
  30. TFileOperationFinished FOnFinished;
  31. bool FReset;
  32. unsigned int FLastSecond;
  33. unsigned long FRemainingCPS;
  34. std::vector<unsigned long> FTicks;
  35. std::vector<__int64> FTotalTransferredThen;
  36. protected:
  37. void __fastcall ClearTransfer();
  38. void __fastcall DoProgress();
  39. public:
  40. // common data
  41. TFileOperation Operation;
  42. // on what side if operation being processed (local/remote), source of copy
  43. TOperationSide Side;
  44. AnsiString FileName;
  45. AnsiString Directory;
  46. bool AsciiTransfer;
  47. bool TransferingFile;
  48. bool Temp;
  49. // file size to read/write
  50. __int64 LocalSize;
  51. __int64 LocalyUsed;
  52. __int64 TransferSize;
  53. __int64 TransferedSize;
  54. __int64 SkippedSize;
  55. TResumeStatus ResumeStatus;
  56. bool InProgress;
  57. TCancelStatus Cancel;
  58. int Count;
  59. // when operation started
  60. TDateTime StartTime;
  61. // bytes transfered
  62. __int64 TotalTransfered;
  63. __int64 TotalSkipped;
  64. __int64 TotalSize;
  65. bool YesToAll;
  66. bool YesToNewer;
  67. bool NoToAll;
  68. bool SkipToAll;
  69. bool AlternateResumeAlways;
  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 AddLocalyUsed(__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(AnsiString FileName, bool Success,
  83. bool & DisconnectWhenComplete);
  84. unsigned long __fastcall LocalBlockSize();
  85. bool __fastcall IsLocalyDone();
  86. bool __fastcall IsTransferDone();
  87. void __fastcall SetFile(AnsiString AFileName);
  88. int __fastcall OperationProgress();
  89. unsigned long __fastcall TransferBlockSize();
  90. unsigned long __fastcall AdjustToCPSLimit(unsigned long Size);
  91. static unsigned long __fastcall StaticBlockSize();
  92. void __fastcall Reset();
  93. void __fastcall Resume();
  94. void __fastcall SetLocalSize(__int64 ASize);
  95. void __fastcall SetAsciiTransfer(bool AAsciiTransfer);
  96. void __fastcall SetResumeStatus(TResumeStatus AResumeStatus);
  97. void __fastcall SetTransferSize(__int64 ASize);
  98. void __fastcall ChangeTransferSize(__int64 ASize);
  99. void __fastcall RollbackTransfer();
  100. void __fastcall SetTotalSize(__int64 ASize);
  101. void __fastcall Start(TFileOperation AOperation, TOperationSide ASide, int ACount);
  102. void __fastcall Start(TFileOperation AOperation,
  103. TOperationSide ASide, int ACount, bool ATemp, const AnsiString ADirectory,
  104. unsigned long ACPSLimit);
  105. void __fastcall Stop();
  106. void __fastcall Suspend();
  107. // whole operation
  108. TDateTime __fastcall TimeElapsed();
  109. // only current file
  110. TDateTime __fastcall TimeExpected();
  111. TDateTime __fastcall TotalTimeExpected();
  112. TDateTime __fastcall TotalTimeLeft();
  113. int __fastcall TransferProgress();
  114. int __fastcall OverallProgress();
  115. int __fastcall TotalTransferProgress();
  116. };
  117. //---------------------------------------------------------------------------
  118. class TSuspendFileOperationProgress
  119. {
  120. public:
  121. __fastcall TSuspendFileOperationProgress(TFileOperationProgressType * OperationProgress)
  122. {
  123. FOperationProgress = OperationProgress;
  124. FOperationProgress->Suspend();
  125. }
  126. __fastcall ~TSuspendFileOperationProgress()
  127. {
  128. FOperationProgress->Resume();
  129. }
  130. private:
  131. TFileOperationProgressType * FOperationProgress;
  132. };
  133. //---------------------------------------------------------------------------
  134. #endif