Selaa lähdekoodia

Implemented ComparisonDifference.ToString

(cherry picked from commit 5adbaa938195b07d0ea8f655d8b9b24773897b59)

Source commit: 77080c12e6408ba75067272b538d01fc08990ce4
Martin Prikryl 4 vuotta sitten
vanhempi
sitoutus
10782bc71c
1 muutettua tiedostoa jossa 52 lisäystä ja 4 poistoa
  1. 52 4
      dotnet/ComparisonDifference.cs

+ 52 - 4
dotnet/ComparisonDifference.cs

@@ -51,6 +51,56 @@ namespace WinSCP
             _remotePath = remotePath;
         }
 
+        public override string ToString()
+        {
+            string buf;
+            switch (Action)
+            {
+                case SynchronizationAction.UploadNew:
+                    buf = RemotePath.Combine(TranslateLocalPathToRemote(), "*");
+                    return $"{GetLocalPathString()} ==> {buf}";
+
+                case SynchronizationAction.DownloadNew:
+                    buf = Path.Combine(TranslateRemotePathToLocal(), "*");
+                    return $"{buf} <== {GetRemotePathString()}";
+
+                case SynchronizationAction.UploadUpdate:
+                    return $"{GetLocalPathString()} ==> {GetRemotePathString()}";
+
+                case SynchronizationAction.DownloadUpdate:
+                    return $"{GetLocalPathString()} <== {GetRemotePathString()}";
+
+                case SynchronizationAction.DeleteRemote:
+                    return $"× {GetRemotePathString()}";
+
+                case SynchronizationAction.DeleteLocal:
+                    return $"× {GetLocalPathString()}";
+
+                default:
+                    throw new InvalidOperationException();
+            }
+        }
+
+        private string TranslateRemotePathToLocal()
+        {
+            return RemotePath.TranslateRemotePathToLocal(RemotePath.GetDirectoryName(Remote.FileName), _remotePath, _localPath);
+        }
+
+        private string TranslateLocalPathToRemote()
+        {
+            return RemotePath.TranslateLocalPathToRemote(Path.GetDirectoryName(Local.FileName), _localPath, _remotePath);
+        }
+
+        private string GetRemotePathString()
+        {
+            return Remote.FileName + (IsDirectory ? "/" : string.Empty);
+        }
+
+        private string GetLocalPathString()
+        {
+            return Local.FileName + (IsDirectory ? "\\" : string.Empty);
+        }
+
         public FileOperationEventArgs Resolve(Session session, TransferOptions options = null)
         {
             if (session == null)
@@ -63,8 +113,7 @@ namespace WinSCP
                 case SynchronizationAction.UploadNew:
                 case SynchronizationAction.UploadUpdate:
                     {
-                        string remoteDirectory =
-                            RemotePath.TranslateLocalPathToRemote(Path.GetDirectoryName(Local.FileName), _localPath, _remotePath);
+                        string remoteDirectory = TranslateLocalPathToRemote();
                         if (!IsDirectory)
                         {
                             return session.PutFileToDirectory(Local.FileName, remoteDirectory, options: options);
@@ -79,8 +128,7 @@ namespace WinSCP
                 case SynchronizationAction.DownloadNew:
                 case SynchronizationAction.DownloadUpdate:
                     {
-                        string localDirectory =
-                            RemotePath.TranslateRemotePathToLocal(RemotePath.GetDirectoryName(Remote.FileName), _remotePath, _localPath);
+                        string localDirectory = TranslateRemotePathToLocal();
                         if (!IsDirectory)
                         {
                             return session.GetFileToDirectory(Remote.FileName, localDirectory, options: options);