Browse Source

Bug 1951: When opening or switching to a session whose local directory does not exist, open the nearest existing parent directory

https://winscp.net/tracker/1951

Source commit: d7fe161084bc09f617dc2e2fc990fd568689de80
Martin Prikryl 4 years ago
parent
commit
10aa9e9018
2 changed files with 28 additions and 0 deletions
  1. 4 0
      source/forms/ScpCommander.cpp
  2. 24 0
      source/packages/filemng/DirView.pas

+ 4 - 0
source/forms/ScpCommander.cpp

@@ -600,6 +600,10 @@ void TScpCommanderForm::RestoreSessionLocalDirView(TDirView * ALocalDirView, con
       {
         ManagedSession->ShowExtendedException(&E);
       }
+      else
+      {
+        ALocalDirView->OpenFallbackPath(LocalDirectory);
+      }
     }
   }
 }

+ 24 - 0
source/packages/filemng/DirView.pas

@@ -270,6 +270,7 @@ type
     function ItemFileName(Item: TListItem): string; override;
     function ItemFileSize(Item: TListItem): Int64; override;
     function ItemFileTime(Item: TListItem; var Precision: TDateTimePrecision): TDateTime; override;
+    procedure OpenFallbackPath(Value: string);
 
     {Thread handling: }
     procedure StartWatchThread;
@@ -969,6 +970,29 @@ begin
   end;
 end;
 
+procedure TDirView.OpenFallbackPath(Value: string);
+var
+  APath: string;
+begin
+  while True do
+  begin
+    APath := ExtractFileDir(Value);
+    if (APath = '') or (APath = Value) then
+    begin
+      Break;
+    end
+      else
+    begin
+      try
+        Path := APath;
+        Break;
+      except
+        Value := APath;
+      end;
+    end;
+  end;
+end;
+
 procedure TDirView.SetLoadEnabled(Value: Boolean);
 begin
   if Value <> LoadEnabled then