Răsfoiți Sursa

Factoring out IsTransfer

(cherry picked from commit ec22d33b1d052707c543542509f28367973ecba4)

Source commit: 483b83fdecf9be6861d68076d799b2d64e320c1a
Martin Prikryl 4 ani în urmă
părinte
comite
f2fd31c4a8

+ 12 - 2
source/core/FileOperationProgress.cpp

@@ -25,6 +25,11 @@ bool TFileOperationProgressType::IsIndeterminateOperation(TFileOperation Operati
   return (Operation == foCalculateSize);
 }
 //---------------------------------------------------------------------------
+bool TFileOperationProgressType::IsTransferOperation(TFileOperation Operation)
+{
+  return (Operation == foCopy) || (Operation == foMove);
+}
+//---------------------------------------------------------------------------
 void TFileOperationProgressType::TPersistence::Clear(bool Batch, bool Speed)
 {
   if (Batch)
@@ -289,7 +294,7 @@ int __fastcall TFileOperationProgressType::OverallProgress() const
 {
   if (TotalSizeSet)
   {
-    DebugAssert((Operation == foCopy) || (Operation == foMove));
+    DebugAssert(IsTransfer());
     return TotalTransferProgress();
   }
   else
@@ -329,7 +334,7 @@ void __fastcall TFileOperationProgressType::Succeeded(int Count)
 {
   if (FPersistence.Statistics != NULL)
   {
-    if ((Operation == foCopy) || (Operation == foMove))
+    if (IsTransfer())
     {
       __int64 Transferred = FTransferredSize - FSkippedSize;
       if (Side == osLocal)
@@ -989,3 +994,8 @@ bool TFileOperationProgressType::IsIndeterminate() const
     IsIndeterminateOperation(FOperation) ||
     (!TotalSizeSet && (FCount == 1));
 }
+//---------------------------------------------------------------------------
+bool TFileOperationProgressType::IsTransfer() const
+{
+  return IsTransferOperation(Operation);
+}

+ 2 - 0
source/core/FileOperationProgress.h

@@ -228,8 +228,10 @@ public:
   void __fastcall Store(TPersistence & Persistence);
   void __fastcall Restore(TPersistence & Persistence);
   bool IsIndeterminate() const;
+  bool IsTransfer() const;
 
   static bool IsIndeterminateOperation(TFileOperation Operation);
+  static bool IsTransferOperation(TFileOperation Operation);
 };
 //---------------------------------------------------------------------------
 class TSuspendFileOperationProgress

+ 2 - 2
source/core/Queue.cpp

@@ -1689,7 +1689,7 @@ void __fastcall TQueueItem::SetProgress(
 
     // do not lose CPS limit override on "calculate size" operation,
     // wait until the real transfer operation starts
-    if ((FCPSLimit >= 0) && ((ProgressData.Operation == foMove) || (ProgressData.Operation == foCopy)))
+    if ((FCPSLimit >= 0) && ProgressData.IsTransfer())
     {
       ProgressData.SetCPSLimit(static_cast<unsigned long>(FCPSLimit));
       FCPSLimit = -1;
@@ -2199,7 +2199,7 @@ void __fastcall TTransferQueueItem::ProgressUpdated()
       // We can probably move the check outside of the guard.
       if (FParallelOperation->IsInitialized())
       {
-        DebugAssert((FProgressData->Operation == foCopy) || (FProgressData->Operation == foCalculateSize));
+        DebugAssert(FProgressData->IsTransfer());
         if (FProgressData->Operation == foCopy)
         {
           Add = FParallelOperation->ShouldAddClient();

+ 2 - 3
source/core/Script.cpp

@@ -2302,8 +2302,7 @@ void __fastcall TManagementScript::ShowPendingProgress()
 void __fastcall TManagementScript::TerminalOperationProgress(
   TFileOperationProgressType & ProgressData)
 {
-  if ((ProgressData.Operation == foCopy) ||
-      (ProgressData.Operation == foMove))
+  if (ProgressData.IsTransfer())
   {
     if (ProgressData.InProgress  && ProgressData.FileInProgress &&
         !ProgressData.FileName.IsEmpty())
@@ -2412,7 +2411,7 @@ void __fastcall TManagementScript::TerminalOperationFinished(
 {
   if (Success &&
       (Operation != foCalculateSize) && (Operation != foCalculateChecksum) &&
-      (Operation != foCopy) && (Operation != foMove))
+      !TFileOperationProgressType::IsTransferOperation(Operation))
   {
     ShowPendingProgress();
     // For FKeepingUpToDate we should send events to synchronize controller eventually.

+ 1 - 1
source/core/Terminal.cpp

@@ -2015,7 +2015,7 @@ void __fastcall TTerminal::DoProgress(TFileOperationProgressType & ProgressData)
 {
 
   if ((Configuration->ActualLogProtocol >= 1) &&
-      ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)))
+      ProgressData.IsTransfer())
   {
     DWORD Now = GetTickCount();
     if (Now - FLastProgressLogged >= 1000)

+ 4 - 4
source/forms/CustomScpExplorer.cpp

@@ -1537,7 +1537,7 @@ void __fastcall TCustomScpExplorerForm::FileOperationProgress(
 
     if ((FTransferResumeList != NULL) &&
         ProgressData.InProgress &&
-        ((ProgressData.Operation == foCopy) || (ProgressData.Operation == foMove)) &&
+        ProgressData.IsTransfer() &&
         !ProgressData.FullFileName.IsEmpty())
     {
       if ((FTransferResumeList->Count == 0) ||
@@ -1627,7 +1627,7 @@ void __fastcall TCustomScpExplorerForm::DoOperationFinished(
       }
     }
 
-    if ((Operation == foCopy) || (Operation == foMove))
+    if (TFileOperationProgressType::IsTransferOperation(Operation))
     {
       DebugAssert(!IsLocalBrowserMode());
       if (Side == osLocal)
@@ -2830,7 +2830,7 @@ bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Oper
 {
   TAutoBatch AutoBatch(this);
   bool Result;
-  if ((Operation == foCopy) || (Operation == foMove))
+  if (TFileOperationProgressType::IsTransferOperation(Operation))
   {
     Result = ExecuteCopyMoveFileOperation(Operation, Side, FileList, NoConfirmation, Param);
   }
@@ -2918,7 +2918,7 @@ void __fastcall TCustomScpExplorerForm::ExecuteFileOperationCommand(
 {
   if (ExecuteFileOperation(Operation, Side, OnFocused, NoConfirmation, Param))
   {
-    if ((Operation == foCopy) || (Operation == foMove))
+    if (TFileOperationProgressType::IsTransferOperation(Operation))
     {
       DebugAssert(!IsLocalBrowserMode());
       if (GetSide(Side) == osLocal)

+ 2 - 3
source/forms/Progress.cpp

@@ -52,7 +52,7 @@ UnicodeString __fastcall TProgressForm::ProgressStr(
     PROGRESS_CALCULATE_CHECKSUM, PROGRESS_LOCK, PROGRESS_UNLOCK };
   DebugAssert((unsigned int)ProgressData->Operation >= 1 && ((unsigned int)ProgressData->Operation - 1) < LENOF(Captions));
   int Id;
-  if ((ProgressData->Operation == foCopy) || (ProgressData->Operation == foMove))
+  if (ProgressData->IsTransfer())
   {
     Id = (ProgressData->Side == osLocal) ? PROGRESS_UPLOAD : PROGRESS_DOWNLOAD;
   }
@@ -147,8 +147,7 @@ void __fastcall TProgressForm::UpdateControls()
   DebugAssert((FData.Operation >= foCopy) && (FData.Operation <= foUnlock) &&
     (FData.Operation != foRename));
 
-  bool TransferOperation =
-    ((FData.Operation == foCopy) || (FData.Operation == foMove));
+  bool TransferOperation = FData.IsTransfer();
   bool Indeterminate = IsIndeterminate(SynchronizeProgress, &FData);
 
   CancelItem->Enabled = !FReadOnly && (FCancel < csCancel);

+ 1 - 1
source/forms/ScpCommander.cpp

@@ -1085,7 +1085,7 @@ void __fastcall TScpCommanderForm::FileOperationProgress(
   // reloaded
   if (!ProgressData.InProgress && FProgressForm &&
       IsFileControl(FDDTargetControl, osLocal) &&
-      ((ProgressData.Operation == ::foCopy) || (ProgressData.Operation == ::foMove)))
+      ProgressData.IsTransfer())
   {
     ReloadLocalDirectory();
   }

+ 2 - 8
source/windows/ConsoleRunner.cpp

@@ -907,15 +907,9 @@ void __fastcall TExternalConsole::Progress(TScriptProgress & Progress)
 
     CommStruct->Event = TConsoleCommStruct::PROGRESS;
 
-    switch (Progress.Operation)
+    if (DebugAlwaysTrue(TFileOperationProgressType::IsTransferOperation(Progress.Operation)))
     {
-      case foCopy:
-      case foMove:
-        ProgressEvent.Operation = TProgressEvent::COPY;
-        break;
-
-      default:
-        DebugFail();
+      ProgressEvent.Operation = TProgressEvent::COPY;
     }
 
     switch (Progress.Side)