Ver código fonte

Bug 1684: Failure when canceling session reconnect (3rd)

https://winscp.net/tracker/1684

Source commit: f6df652674db1237df7161192b80a12fb2fa769f
Martin Prikryl 7 anos atrás
pai
commit
37c857ad79

+ 26 - 7
source/components/UnixDirView.cpp

@@ -484,18 +484,27 @@ void __fastcall TUnixDirView::SetDriveView(TCustomUnixDriveView * Value)
 }
 //---------------------------------------------------------------------------
 #ifndef DESIGN_ONLY
-void __fastcall TUnixDirView::SetTerminal(TTerminal *value)
+void __fastcall TUnixDirView::DoSetTerminal(TTerminal * value, bool Replace)
 {
   if (FTerminal != value)
   {
     if (FTerminal)
     {
-      DebugAssert(FTerminal->OnReadDirectory == DoReadDirectory);
-      FTerminal->OnReadDirectory = NULL;
-      DebugAssert(FTerminal->OnStartReadDirectory == DoStartReadDirectory);
-      FTerminal->OnStartReadDirectory = NULL;
-      DebugAssert(FTerminal->OnChangeDirectory == DoChangeDirectory);
-      FTerminal->OnChangeDirectory = NULL;
+      DebugAssert((FTerminal->OnReadDirectory == DoReadDirectory) || Replace);
+      if (FTerminal->OnReadDirectory == DoReadDirectory)
+      {
+        FTerminal->OnReadDirectory = NULL;
+      }
+      DebugAssert((FTerminal->OnStartReadDirectory == DoStartReadDirectory) || Replace);
+      if (FTerminal->OnStartReadDirectory == DoStartReadDirectory)
+      {
+        FTerminal->OnStartReadDirectory = NULL;
+      }
+      DebugAssert((FTerminal->OnChangeDirectory == DoChangeDirectory) || Replace);
+      if (FTerminal->OnChangeDirectory == DoChangeDirectory)
+      {
+        FTerminal->OnChangeDirectory = NULL;
+      }
       if (!value || !value->Files->Loaded)
       {
         ClearItems();
@@ -523,6 +532,16 @@ void __fastcall TUnixDirView::SetTerminal(TTerminal *value)
     UpdatePathLabel();
   }
 }
+//---------------------------------------------------------------------------
+void __fastcall TUnixDirView::SetTerminal(TTerminal * value)
+{
+  DoSetTerminal(value, false);
+}
+//---------------------------------------------------------------------------
+void __fastcall TUnixDirView::ReplaceTerminal(TTerminal * value)
+{
+  DoSetTerminal(value, true);
+}
 #endif
 //---------------------------------------------------------------------------
 void __fastcall TUnixDirView::DoStartReadDirectory(TObject * /*Sender*/)

+ 2 - 0
source/components/UnixDirView.h

@@ -37,6 +37,7 @@ private:
   TNotifyEvent FOnRead;
   void __fastcall SetDDAllowMove(bool value);
   void __fastcall SetTerminal(TTerminal *value);
+  void __fastcall DoSetTerminal(TTerminal *value, bool Replace);
   void __fastcall SetShowInaccesibleDirectories(bool value);
 protected:
   virtual void __fastcall DDDragDetect(int grfKeyState, const TPoint &DetectStart,
@@ -98,6 +99,7 @@ public:
   virtual bool __fastcall PasteFromClipBoard(UnicodeString TargetPath = L"");
   void __fastcall UpdateFiles();
   void __fastcall DisplayContextMenu(const TPoint &Where);
+  void __fastcall ReplaceTerminal(TTerminal * value);
 
   __property bool Active = { read = GetActive };
   __property TTerminal *Terminal = { read = FTerminal, write = SetTerminal };

+ 34 - 17
source/forms/CustomScpExplorer.cpp

@@ -544,25 +544,35 @@ void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
   if (FTerminal != value)
   {
     TerminalChanging();
-    FTerminal = value;
-    bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
-    FAllowTransferPresetAutoSelect = false;
-    try
-    {
-      TerminalChanged();
-    }
-    __finally
-    {
-      FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
-    }
+    DoSetTerminal(value, false);
+  }
+}
+//---------------------------------------------------------------------------
+void __fastcall TCustomScpExplorerForm::DoSetTerminal(TTerminal * value, bool Replace)
+{
+  FTerminal = value;
+  bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
+  FAllowTransferPresetAutoSelect = false;
+  try
+  {
+    TerminalChanged(Replace);
+  }
+  __finally
+  {
+    FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
+  }
 
-    if (Terminal != NULL)
-    {
-      TransferPresetAutoSelect();
-    }
+  if (Terminal != NULL)
+  {
+    TransferPresetAutoSelect();
   }
 }
 //---------------------------------------------------------------------------
+void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TTerminal * value)
+{
+  DoSetTerminal(value, true);
+}
+//---------------------------------------------------------------------------
 void __fastcall TCustomScpExplorerForm::TerminalChanging()
 {
   if (FTerminal != NULL)
@@ -571,9 +581,16 @@ void __fastcall TCustomScpExplorerForm::TerminalChanging()
   }
 }
 //---------------------------------------------------------------------------
-void __fastcall TCustomScpExplorerForm::TerminalChanged()
+void __fastcall TCustomScpExplorerForm::TerminalChanged(bool Replaced)
 {
-  RemoteDirView->Terminal = Terminal;
+  if (Replaced)
+  {
+    RemoteDirView->ReplaceTerminal(Terminal);
+  }
+  else
+  {
+    RemoteDirView->Terminal = Terminal;
+  }
   NonVisualDataModule->ResetQueueOnceEmptyOperation();
 
   TManagedTerminal * ManagedTerminal = NULL;

+ 3 - 1
source/forms/CustomScpExplorer.h

@@ -267,6 +267,7 @@ private:
   bool __fastcall GetEnableFocusedOperation(TOperationSide Side, int FilesOnly);
   bool __fastcall GetEnableSelectedOperation(TOperationSide Side, int FilesOnly);
   void __fastcall SetTerminal(TTerminal * value);
+  void __fastcall DoSetTerminal(TTerminal * value, bool Replace);
   void __fastcall SetQueue(TTerminalQueue * value);
   void __fastcall TransferListChange(TObject * Sender);
   void __fastcall TransferListDrawItem(TTBXCustomList * Sender, TCanvas * ACanvas,
@@ -380,7 +381,7 @@ protected:
     const TCustomCommandType & ACommand, TStrings * ALocalFileList,
     const TCustomCommandData & Data, const UnicodeString & CommandCommand);
   virtual void __fastcall TerminalChanging();
-  virtual void __fastcall TerminalChanged();
+  virtual void __fastcall TerminalChanged(bool Replaced);
   virtual void __fastcall QueueChanged();
   void __fastcall InitStatusBar();
   void __fastcall UpdateStatusBar();
@@ -761,6 +762,7 @@ public:
   bool __fastcall CanPrivateKeyUpload();
   void __fastcall PrivateKeyUpload();
   bool __fastcall IsComponentPossible(Byte Component);
+  void __fastcall ReplaceTerminal(TTerminal * value);
 
   __property bool ComponentVisible[Byte Component] = { read = GetComponentVisible, write = SetComponentVisible };
   __property bool EnableFocusedOperation[TOperationSide Side] = { read = GetEnableFocusedOperation, index = 0 };

+ 2 - 2
source/forms/ScpCommander.cpp

@@ -466,11 +466,11 @@ void __fastcall TScpCommanderForm::StartingDisconnected()
   LocalDefaultDirectory();
 }
 //---------------------------------------------------------------------------
-void __fastcall TScpCommanderForm::TerminalChanged()
+void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
 {
   NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
 
-  TCustomScpExplorerForm::TerminalChanged();
+  TCustomScpExplorerForm::TerminalChanged(Replaced);
 
   if (Terminal)
   {

+ 1 - 1
source/forms/ScpCommander.h

@@ -533,7 +533,7 @@ protected:
   virtual void __fastcall RestoreFormParams();
   virtual void __fastcall RestoreParams();
   virtual void __fastcall FixControlsPlacement();
-  virtual void __fastcall TerminalChanged();
+  virtual void __fastcall TerminalChanged(bool Replaced);
   virtual void __fastcall ConfigurationChanged();
   virtual bool __fastcall GetHasDirView(TOperationSide Side);
   virtual void __fastcall UpdateControls();

+ 1 - 1
source/windows/TerminalManager.cpp

@@ -279,7 +279,7 @@ void __fastcall TTerminalManager::DoConnectTerminal(TTerminal * Terminal, bool R
           Items[ActiveTerminalIndex] = Terminal;
           OwnsObjects = true;
           FActiveTerminal = Terminal;
-          TerminalReady();
+          FScpExplorer->ReplaceTerminal(Terminal);
         }
         // Now we do not have any reference to an abandoned terminal, so we can safely allow the thread
         // to complete its task and destroy the terminal afterwards.