瀏覽代碼

Factoring out CopyToParallel

Source commit: 51d5f21e4b9d7bf2d05307edab1cba8e17f73f68
Martin Prikryl 8 年之前
父節點
當前提交
6e01b5ba12
共有 3 個文件被更改,包括 45 次插入31 次删除
  1. 1 1
      source/core/Queue.cpp
  2. 41 29
      source/core/Terminal.cpp
  3. 3 1
      source/core/Terminal.h

+ 1 - 1
source/core/Queue.cpp

@@ -2199,7 +2199,7 @@ void __fastcall TParallelUploadQueueItem::DoExecute(TTerminal * Terminal)
     bool Continue = true;
     do
     {
-      int GotNext = Terminal->CopyToRemoteParallel(FParallelOperation, &OperationProgress);
+      int GotNext = Terminal->CopyToParallel(FParallelOperation, &OperationProgress);
       if (GotNext < 0)
       {
         Continue = false;

+ 41 - 29
source/core/Terminal.cpp

@@ -6204,7 +6204,7 @@ bool __fastcall TTerminal::GetStoredCredentialsTried()
   return Result;
 }
 //---------------------------------------------------------------------------
-int __fastcall TTerminal::CopyToRemoteParallel(TParallelOperation * ParallelOperation, TFileOperationProgressType * OperationProgress)
+int __fastcall TTerminal::CopyToParallel(TParallelOperation * ParallelOperation, TFileOperationProgressType * OperationProgress)
 {
   UnicodeString FileName;
   UnicodeString TargetDir;
@@ -6217,7 +6217,10 @@ int __fastcall TTerminal::CopyToRemoteParallel(TParallelOperation * ParallelOper
     std::unique_ptr<TStrings> FilesToCopy(new TStringList());
     FilesToCopy->Add(FileName);
 
-    UnicodeString UnlockedTargetDir = TranslateLockedPath(TargetDir, false);
+    if (ParallelOperation->Side == osLocal)
+    {
+      TargetDir = TranslateLockedPath(TargetDir, false);
+    }
     // OnceDoneOperation is not supported
     TOnceDoneOperation OnceDoneOperation = odoIdle;
 
@@ -6231,8 +6234,15 @@ int __fastcall TTerminal::CopyToRemoteParallel(TParallelOperation * ParallelOper
     int Prev = OperationProgress->FilesFinishedSuccessfully;
     try
     {
-      FFileSystem->CopyToRemote(
-        FilesToCopy.get(), UnlockedTargetDir, ParallelOperation->CopyParam, Params, OperationProgress, OnceDoneOperation);
+      if (ParallelOperation->Side == osLocal)
+      {
+        FFileSystem->CopyToRemote(
+          FilesToCopy.get(), TargetDir, ParallelOperation->CopyParam, Params, OperationProgress, OnceDoneOperation);
+      }
+      else
+      {
+        DebugFail();
+      }
     }
     __finally
     {
@@ -6256,6 +6266,32 @@ bool __fastcall TTerminal::CanParallel(
     (!CopyParam->PreserveTime || !CopyParam->PreserveTimeDirs);
 }
 //---------------------------------------------------------------------------
+void __fastcall TTerminal::CopyParallel(TParallelOperation * ParallelOperation, TFileOperationProgressType * OperationProgress)
+{
+  try
+  {
+    bool Continue = true;
+    do
+    {
+      int GotNext = CopyToParallel(ParallelOperation, OperationProgress);
+      if (GotNext < 0)
+      {
+        Continue = false;
+      }
+      else if (GotNext == 0)
+      {
+        Sleep(100);
+      }
+    }
+    while (Continue && !OperationProgress->Cancel);
+  }
+  __finally
+  {
+    OperationProgress->SetDone();
+    ParallelOperation->WaitFor();
+  }
+}
+//---------------------------------------------------------------------------
 bool __fastcall TTerminal::CopyToRemote(TStrings * FilesToCopy,
   const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params, TParallelOperation * ParallelOperation)
 {
@@ -6321,31 +6357,7 @@ bool __fastcall TTerminal::CopyToRemote(TStrings * FilesToCopy,
         {
           // OnceDoneOperation is not supported
           ParallelOperation->Init(Files.release(), UnlockedTargetDir, CopyParam, Params, &OperationProgress);
-
-          try
-          {
-            bool Continue = true;
-            do
-            {
-              int GotNext = CopyToRemoteParallel(ParallelOperation, &OperationProgress);
-              if (GotNext < 0)
-              {
-                Continue = false;
-              }
-              else if (GotNext == 0)
-              {
-                Sleep(100);
-              }
-            }
-            while (Continue && !OperationProgress.Cancel);
-
-            Result = true;
-          }
-          __finally
-          {
-            OperationProgress.SetDone();
-            ParallelOperation->WaitFor();
-          }
+          CopyParallel(ParallelOperation, &OperationProgress);
         }
         else
         {

+ 3 - 1
source/core/Terminal.h

@@ -400,6 +400,7 @@ protected:
   bool __fastcall CanRecurseToDirectory(const TRemoteFile * File);
   bool __fastcall DoOnCustomCommand(const UnicodeString & Command);
   bool __fastcall CanParallel(const TCopyParamType * CopyParam, int Params, TParallelOperation * ParallelOperation);
+  void __fastcall CopyParallel(TParallelOperation * ParallelOperation, TFileOperationProgressType * OperationProgress);
 
   __property TFileOperationProgressType * OperationProgress = { read=FOperationProgress };
 
@@ -432,7 +433,7 @@ public:
     const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params);
   bool __fastcall CopyToRemote(TStrings * FilesToCopy,
     const UnicodeString TargetDir, const TCopyParamType * CopyParam, int Params, TParallelOperation * ParallelOperation);
-  int __fastcall CopyToRemoteParallel(TParallelOperation * ParallelOperation, TFileOperationProgressType * OperationProgress);
+  int __fastcall CopyToParallel(TParallelOperation * ParallelOperation, TFileOperationProgressType * OperationProgress);
   void __fastcall CreateDirectory(const UnicodeString DirName,
     const TRemoteProperties * Properties = NULL);
   void __fastcall CreateLink(const UnicodeString FileName, const UnicodeString PointTo, bool Symbolic);
@@ -798,6 +799,7 @@ public:
   int GetNext(TTerminal * Terminal, UnicodeString & FileName, UnicodeString & TargetDir, bool & Dir, bool & Recursed);
   void Done(const UnicodeString & FileName, bool Dir, bool Success);
 
+  __property TOperationSide Side = { read = FSide };
   __property const TCopyParamType * CopyParam = { read = FCopyParam };
   __property int Params = { read = FParams };
   __property UnicodeString TargetDir = { read = FTargetDir };