FileOperationProgress.h 4.8 KB

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