| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 | //---------------------------------------------------------------------------#ifndef FileOperationProgressH#define FileOperationProgressH//---------------------------------------------------------------------------#include "Configuration.h"#include "CopyParam.h"#include "Exceptions.h"#include <vector>//---------------------------------------------------------------------------class TFileOperationProgressType;enum TFileOperation { foNone, foCopy, foMove, foDelete, foSetProperties,  foRename, foCustomCommand, foCalculateSize, foRemoteMove, foRemoteCopy,  foGetProperties, foCalculateChecksum, foLock, foUnlock };// csCancelTransfer and csRemoteAbort are used with SCP onlyenum TCancelStatus { csContinue = 0, csCancelFile, csCancel, csCancelTransfer, csRemoteAbort };enum TBatchOverwrite { boNo, boAll, boNone, boOlder, boAlternateResume, boAppend, boResume };typedef void __fastcall (__closure *TFileOperationProgressEvent)  (TFileOperationProgressType & ProgressData);typedef void __fastcall (__closure *TFileOperationFinished)  (TFileOperation Operation, TOperationSide Side, bool Temp,    const UnicodeString & FileName, bool Success, TOnceDoneOperation & OnceDoneOperation);//---------------------------------------------------------------------------class TFileOperationProgressType{private:  TFileOperation FOperation;  TOperationSide FSide;  UnicodeString FFileName;  UnicodeString FFullFileName;  UnicodeString FDirectory;  bool FAsciiTransfer;  bool FTransferringFile;  bool FTemp;  __int64 FLocalSize;  __int64 FLocallyUsed;  __int64 FTransferSize;  __int64 FTransferredSize;  __int64 FSkippedSize;  bool FInProgress;  bool FDone;  bool FFileInProgress;  TCancelStatus FCancel;  int FCount;  TDateTime FStartTime;  __int64 FTotalTransferred;  __int64 FTotalSkipped;  __int64 FTotalSize;  TBatchOverwrite FBatchOverwrite;  bool FSkipToAll;  unsigned long FCPSLimit;  bool FTotalSizeSet;  bool FSuspended;  TFileOperationProgressType * FParent;  // when it was last time suspended (to calculate suspend time in Resume())  unsigned int FSuspendTime;  // when current file was started being transferred  TDateTime FFileStartTime;  int FFilesFinished;  int FFilesFinishedSuccessfully;  TFileOperationProgressEvent FOnProgress;  TFileOperationFinished FOnFinished;  bool FReset;  unsigned int FLastSecond;  unsigned long FRemainingCPS;  bool FCounterSet;  std::vector<unsigned long> FTicks;  std::vector<__int64> FTotalTransferredThen;  TCriticalSection * FSection;  TCriticalSection * FUserSelectionsSection;  __int64 __fastcall GetTotalTransferred();  __int64 __fastcall GetTotalSize();  unsigned long __fastcall GetCPSLimit();  TBatchOverwrite __fastcall GetBatchOverwrite();  bool __fastcall GetSkipToAll();protected:  void __fastcall ClearTransfer();  inline void __fastcall DoProgress();  int __fastcall OperationProgress();  void __fastcall AddTransferredToTotals(__int64 ASize);  void __fastcall AddSkipped(__int64 ASize);  void __fastcall AddTotalSize(__int64 ASize);  void __fastcall RollbackTransferFromTotals(__int64 ATransferredSize, __int64 ASkippedSize);  unsigned int __fastcall GetCPS();  void __fastcall Init();  static bool __fastcall PassCancelToParent(TCancelStatus ACancel);public:  // common data  __property TFileOperation Operation = { read = FOperation };  // on what side if operation being processed (local/remote), source of copy  __property TOperationSide Side = { read = FSide };  __property int Count =  { read = FCount };  __property UnicodeString FileName =  { read = FFileName };  __property UnicodeString FullFileName = { read = FFullFileName };  __property UnicodeString Directory = { read = FDirectory };  __property bool AsciiTransfer = { read = FAsciiTransfer };  // Can be true with SCP protocol only  __property bool TransferringFile = { read = FTransferringFile };  __property bool Temp = { read = FTemp };  // file size to read/write  __property __int64 LocalSize = { read = FLocalSize };  __property __int64 LocallyUsed = { read = FLocallyUsed };  __property __int64 TransferSize = { read = FTransferSize };  __property __int64 TransferredSize = { read = FTransferredSize };  __property __int64 SkippedSize = { read = FSkippedSize };  __property bool InProgress = { read = FInProgress };  __property bool Done = { read = FDone };  __property bool FileInProgress = { read = FFileInProgress };  __property TCancelStatus Cancel = { read = GetCancel };  // when operation started  __property TDateTime StartTime = { read = FStartTime };  // bytes transferred  __property __int64 TotalTransferred = { read = GetTotalTransferred };  __property __int64 TotalSize = { read = GetTotalSize };  __property int FilesFinishedSuccessfully = { read = FFilesFinishedSuccessfully };  __property TBatchOverwrite BatchOverwrite = { read = GetBatchOverwrite };  __property bool SkipToAll = { read = GetSkipToAll };  __property unsigned long CPSLimit = { read = GetCPSLimit };  __property bool TotalSizeSet = { read = FTotalSizeSet };  __property bool Suspended = { read = FSuspended };  __fastcall TFileOperationProgressType();  __fastcall TFileOperationProgressType(    TFileOperationProgressEvent AOnProgress, TFileOperationFinished AOnFinished,    TFileOperationProgressType * Parent = NULL);  __fastcall ~TFileOperationProgressType();  void __fastcall Assign(const TFileOperationProgressType & Other);  void __fastcall AssignButKeepSuspendState(const TFileOperationProgressType & Other);  void __fastcall AddLocallyUsed(__int64 ASize);  void __fastcall AddTransferred(__int64 ASize, bool AddToTotals = true);  void __fastcall AddResumed(__int64 ASize);  void __fastcall AddSkippedFileSize(__int64 ASize);  void __fastcall Clear();  unsigned int __fastcall CPS();  void __fastcall Finish(UnicodeString FileName, bool Success,    TOnceDoneOperation & OnceDoneOperation);  void __fastcall Progress();  unsigned long __fastcall LocalBlockSize();  bool __fastcall IsLocallyDone();  bool __fastcall IsTransferDone();  void __fastcall SetFile(UnicodeString AFileName, bool AFileInProgress = true);  void __fastcall SetFileInProgress();  unsigned long __fastcall TransferBlockSize();  unsigned long __fastcall AdjustToCPSLimit(unsigned long Size);  void __fastcall ThrottleToCPSLimit(unsigned long Size);  static unsigned long __fastcall StaticBlockSize();  void __fastcall Reset();  void __fastcall Resume();  void __fastcall SetLocalSize(__int64 ASize);  void __fastcall SetAsciiTransfer(bool AAsciiTransfer);  void __fastcall SetTransferSize(__int64 ASize);  void __fastcall ChangeTransferSize(__int64 ASize);  void __fastcall RollbackTransfer();  void __fastcall SetTotalSize(__int64 ASize);  void __fastcall Start(TFileOperation AOperation, TOperationSide ASide, int ACount);  void __fastcall Start(TFileOperation AOperation,    TOperationSide ASide, int ACount, bool ATemp, const UnicodeString ADirectory,    unsigned long ACPSLimit);  void __fastcall Stop();  void __fastcall SetDone();  void __fastcall Suspend();  void __fastcall LockUserSelections();  void __fastcall UnlockUserSelections();  // whole operation  TDateTime __fastcall TimeElapsed();  // only current file  TDateTime __fastcall TimeExpected();  TDateTime __fastcall TotalTimeLeft();  int __fastcall TransferProgress();  int __fastcall OverallProgress();  int __fastcall TotalTransferProgress();  void __fastcall SetSpeedCounters();  void __fastcall SetTransferringFile(bool ATransferringFile);  TCancelStatus __fastcall GetCancel();  void __fastcall SetCancel(TCancelStatus ACancel);  void __fastcall SetCancelAtLeast(TCancelStatus ACancel);  bool __fastcall ClearCancelFile();  void __fastcall SetCPSLimit(unsigned long ACPSLimit);  void __fastcall SetBatchOverwrite(TBatchOverwrite ABatchOverwrite);  void __fastcall SetSkipToAll();  UnicodeString __fastcall GetLogStr(bool Done);};//---------------------------------------------------------------------------class TSuspendFileOperationProgress{public:  __fastcall TSuspendFileOperationProgress(TFileOperationProgressType * OperationProgress)  {    FOperationProgress = OperationProgress;    if (FOperationProgress != NULL)    {      FOperationProgress->Suspend();    }  }  __fastcall ~TSuspendFileOperationProgress()  {    if (FOperationProgress != NULL)    {      FOperationProgress->Resume();    }  }private:  TFileOperationProgressType * FOperationProgress;};//---------------------------------------------------------------------------#endif
 |