Browse Source

Generalizing TParallelOperation for any direction

Source commit: dad0d39e41d1e371f54702496ca7049aee85833c
Martin Prikryl 8 years ago
parent
commit
181116ebef
3 changed files with 49 additions and 11 deletions
  1. 1 1
      source/core/Queue.cpp
  2. 45 8
      source/core/Terminal.cpp
  3. 3 2
      source/core/Terminal.h

+ 1 - 1
source/core/Queue.cpp

@@ -2108,7 +2108,7 @@ void __fastcall TUploadQueueItem::DoExecute(TTerminal * Terminal)
   TTransferQueueItem::DoExecute(Terminal);
 
   DebugAssert(Terminal != NULL);
-  TParallelOperation ParallelOperation;
+  TParallelOperation ParallelOperation(osLocal);
   FParallelOperation = &ParallelOperation;
   try
   {

+ 45 - 8
source/core/Terminal.cpp

@@ -7,6 +7,7 @@
 #include <SysUtils.hpp>
 #include <FileCtrl.hpp>
 #include <StrUtils.hpp>
+#include <System.IOUtils.hpp>
 
 #include "Common.h"
 #include "PuttyTools.h"
@@ -681,13 +682,15 @@ bool TRetryOperationLoop::Retry()
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
-TParallelOperation::TParallelOperation()
+TParallelOperation::TParallelOperation(TOperationSide Side)
 {
   FCopyParam = NULL;
   FParams = 0;
   FProbablyEmpty = false;
   FClients = 0;
   FMainOperationProgress = NULL;
+  DebugAssert((Side == osLocal) || (Side == osRemote));
+  FSide = Side;
 }
 //---------------------------------------------------------------------------
 void TParallelOperation::Init(
@@ -783,7 +786,15 @@ void TParallelOperation::Done(const UnicodeString & FileName, bool Dir, bool Suc
         FDirectories.erase(DirectoryIterator);
         if (FFileList->Count > 0)
         {
-          UnicodeString FileNameWithSlash = IncludeTrailingBackslash(FileName);
+          UnicodeString FileNameWithSlash;
+          if (FSide == osLocal)
+          {
+            FileNameWithSlash = IncludeTrailingBackslash(FileName);
+          }
+          else
+          {
+            FileNameWithSlash = UnixIncludeTrailingBackslash(FileName);
+          }
 
           // It can actually be a different list than the one the directory was taken from,
           // but that does not matter that much. It should not happen anyway, as more lists should be in scripting only.
@@ -832,14 +843,25 @@ int TParallelOperation::GetNext(TTerminal * Terminal, UnicodeString & FileName,
     UnicodeString RootPath = FFileList->Strings[0];
 
     FileName = Files->Strings[0];
-    Dir = (FileName[FileName.Length()] == L'\\');
+    wchar_t Slash = ((FSide == osLocal) ? L'\\' : L'/');
+    Dir = (FileName[FileName.Length()] == Slash);
     if (Dir)
     {
       FileName.SetLength(FileName.Length() - 1);
     }
-    UnicodeString DirPath = ExtractFileDir(FileName);
+    UnicodeString DirPath;
+    bool FirstLevel;
+    if (FSide == osLocal)
+    {
+      DirPath = ExtractFileDir(FileName);
+      FirstLevel = SamePaths(DirPath, RootPath);
+    }
+    else
+    {
+      DirPath = UnixExtractFileDir(FileName);
+      FirstLevel = UnixSamePath(DirPath, RootPath);
+    }
 
-    bool FirstLevel = SamePaths(DirPath, RootPath);
     if (FirstLevel)
     {
       TargetDir = FTargetDir;
@@ -858,7 +880,7 @@ int TParallelOperation::GetNext(TTerminal * Terminal, UnicodeString & FileName,
       }
       else
       {
-        TargetDir = DirectoryData.RemotePath;
+        TargetDir = DirectoryData.OppositePath;
       }
     }
 
@@ -868,9 +890,24 @@ int TParallelOperation::GetNext(TTerminal * Terminal, UnicodeString & FileName,
       {
         TDirectoryData DirectoryData;
 
-        UnicodeString OnlyFileName = ExtractFileName(FileName);
+        UnicodeString OnlyFileName;
+        if (FSide == osLocal)
+        {
+          OnlyFileName = ExtractFileName(FileName);
+        }
+        else
+        {
+          OnlyFileName = UnixExtractFileName(FileName);
+        }
         OnlyFileName = Terminal->ChangeFileName(FCopyParam, OnlyFileName, osRemote, FirstLevel);
-        DirectoryData.RemotePath = UnixCombinePaths(TargetDir, OnlyFileName);
+        if (FSide == osLocal)
+        {
+          DirectoryData.OppositePath = UnixCombinePaths(TargetDir, OnlyFileName);
+        }
+        else
+        {
+          DirectoryData.OppositePath = TPath::Combine(TargetDir, OnlyFileName);
+        }
 
         DirectoryData.Exists = false;
 

+ 3 - 2
source/core/Terminal.h

@@ -758,7 +758,7 @@ private:
 class TParallelOperation
 {
 public:
-  TParallelOperation();
+  TParallelOperation(TOperationSide Side);
   ~TParallelOperation();
 
   void Init(
@@ -780,7 +780,7 @@ public:
 private:
   struct TDirectoryData
   {
-    UnicodeString RemotePath;
+    UnicodeString OppositePath;
     bool Exists;
   };
 
@@ -794,6 +794,7 @@ private:
   int FClients;
   std::unique_ptr<TCriticalSection> FSection;
   TFileOperationProgressType * FMainOperationProgress;
+  TOperationSide FSide;
 };
 //---------------------------------------------------------------------------
 #endif