FileOperationProgress.h 4.5 KB

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