FileOperationProgress.h 4.9 KB

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