Skip to content

Commit 58efc4e

Browse files
Merge remote-tracking branch 'ssvine/fix-recursive-sessions'
2 parents e603231 + f9762cd commit 58efc4e

8 files changed

+29
-10
lines changed

src/NetBox/FarPlugin.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,21 @@ TCustomFarFileSystem * TCustomFarPlugin::GetPanelFileSystem(bool Another,
320320
{
321321
TCustomFarFileSystem * Result{nullptr};
322322
const RECT ActivePanelBounds = GetPanelBounds(PANEL_ACTIVE);
323+
const bool IsEmptyActiveRect = IsRectEmpty(&ActivePanelBounds);
323324
const RECT PassivePanelBounds = GetPanelBounds(PANEL_PASSIVE);
325+
const bool IsEmptyPassiveRect = IsRectEmpty(&PassivePanelBounds);
324326

325327
int32_t Index{0};
326328
while (!Result && (Index < FOpenedPlugins->GetCount()))
327329
{
328330
TCustomFarFileSystem * FarFileSystem = FOpenedPlugins->GetAs<TCustomFarFileSystem>(Index);
329331
DebugAssert(FarFileSystem);
330332
const RECT Bounds = GetPanelBounds(FarFileSystem);
331-
if (Another && CompareRects(Bounds, PassivePanelBounds))
333+
if (Another && !IsEmptyPassiveRect && CompareRects(Bounds, PassivePanelBounds))
332334
{
333335
Result = FarFileSystem;
334336
}
335-
else if (!Another && CompareRects(Bounds, ActivePanelBounds))
337+
else if (!Another && !IsEmptyActiveRect && CompareRects(Bounds, ActivePanelBounds))
336338
{
337339
Result = FarFileSystem;
338340
}
@@ -444,7 +446,6 @@ void TCustomFarPlugin::CloseFileSystem(TCustomFarFileSystem * FileSystem)
444446
__finally
445447
{
446448
FOpenedPlugins->Remove(FileSystem);
447-
CloseFileSystem(FileSystem->GetOwnerFileSystem());
448449
SAFE_DESTROY(FileSystem);
449450
} end_try__finally
450451
#ifdef USE_DLMALLOC

src/NetBox/FarPlugin.h

+3
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ class TCustomFarFileSystem : public TObject
349349
void SetOwnerFileSystem(TCustomFarFileSystem * Value) { FOwnerFileSystem = Value; }
350350
bool GetClosed() const { return FClosed; }
351351
TCustomFarPlugin * GetPlugin() const { return FPlugin; }
352+
bool IsConnectedDirectly() const { return FConnectedDirectly; };
353+
void SetConnectedDirectly(bool Value = true) { FConnectedDirectly = Value; }
352354

353355
private:
354356
TCriticalSection FCriticalSection;
@@ -361,6 +363,7 @@ class TCustomFarFileSystem : public TObject
361363
gsl::not_null<TCustomFarPlugin *> FPlugin;
362364
bool FClosed{false};
363365
static uint32_t FInstances;
366+
bool FConnectedDirectly{false};
364367

365368
void ClearOpenPanelInfo(OpenPanelInfo & Info);
366369
TObjectList * CreatePanelItemList(struct PluginPanelItem * PanelItem, int32_t ItemsNumber);

src/NetBox/NetBox.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ HANDLE WINAPI OpenW(const struct OpenInfo * Info)
225225
DebugAssert(FarPlugin);
226226
const TFarPluginGuard Guard;
227227
const HANDLE Handle = static_cast<HANDLE>(FarPlugin->OpenPlugin(Info));
228+
if (!Handle && Info->OpenFrom == OPEN_ANALYSE)
229+
{
230+
return PANEL_STOP;
231+
}
228232
return Handle;
229233
}
230234

src/NetBox/WinSCPFileSystem.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,8 @@ bool TWinSCPFileSystem::ProcessKeyEx(int32_t Key, uint32_t ControlState)
10701070
}
10711071

10721072
// Return to session panel
1073-
if (Focused && !Handled && ((Key == VK_RETURN) && (Focused->GetFileName() == PARENTDIRECTORY) ||
1073+
if (Focused && !Handled && !IsConnectedDirectly() &&
1074+
((Key == VK_RETURN) && (Focused->GetFileName() == PARENTDIRECTORY) ||
10741075
(Key == VK_PRIOR) && (ControlState & CTRLMASK)) && FLastPath == ROOTDIRECTORY)
10751076
{
10761077
SetDirectoryEx(PARENTDIRECTORY, 0);

src/NetBox/WinSCPPlugin.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ int32_t TWinSCPPlugin::ProcessEditorInputEx(const INPUT_RECORD * Rec)
275275
TCustomFarFileSystem * TWinSCPPlugin::OpenPluginEx(OPENFROM OpenFrom, intptr_t Item)
276276
{
277277
std::unique_ptr<TWinSCPFileSystem> FileSystem;
278+
bool Success = true;
278279
CoreInitializeOnce();
279280
// DEBUG_PRINTF("OpenFrom: %d", (int)OpenFrom);
280281

@@ -351,8 +352,9 @@ TCustomFarFileSystem * TWinSCPPlugin::OpenPluginEx(OPENFROM OpenFrom, intptr_t I
351352
DebugAssert(false);
352353
Abort();
353354
}
354-
FileSystem->Connect(Session.get());
355-
if (!Directory.IsEmpty())
355+
FileSystem->SetConnectedDirectly();
356+
Success = FileSystem->Connect(Session.get());
357+
if (Success && !Directory.IsEmpty())
356358
{
357359
FileSystem->SetDirectoryEx(Directory, OPM_SILENT);
358360
}
@@ -381,14 +383,18 @@ TCustomFarFileSystem * TWinSCPPlugin::OpenPluginEx(OPENFROM OpenFrom, intptr_t I
381383
DebugAssert(false);
382384
Abort();
383385
}
384-
FileSystem->Connect(Session.get());
386+
FileSystem->SetConnectedDirectly();
387+
Success = FileSystem->Connect(Session.get());
385388
}
386389
else
387390
{
388391
DebugAssert(false);
389392
}
390393
}
391-
394+
if (!Success)
395+
{
396+
FileSystem.reset(nullptr);
397+
}
392398
return FileSystem.release();
393399
}
394400

src/core/FtpFileSystem.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,8 @@ void TFTPFileSystem::DoStartup()
19941994
// retrieve initialize working directory to save it as home directory
19951995
ReadCurrentDirectory();
19961996
FHomeDirectory = FCurrentDirectory;
1997+
// clear FCurrentDirectory (it will be set later during TTerminal::DoStartup execution)
1998+
FCurrentDirectory.Clear();
19971999
}
19982000

19992001
void TFTPFileSystem::HomeDirectory()

src/core/S3FileSystem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ void TS3FileSystem::ReadCurrentDirectory()
10451045
{
10461046
if (FCachedDirectoryChange.IsEmpty())
10471047
{
1048-
FCurrentDirectory = FCurrentDirectory.IsEmpty() ? UnicodeString(L"/") : FCurrentDirectory;
1048+
// FCurrentDirectory is set later during TTerminal::DoStartup execution
10491049
}
10501050
else
10511051
{

src/core/WebDAVFileSystem.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,14 @@ void TWebDAVFileSystem::OpenUrl(const UnicodeString & Url)
273273
CorrectedUrl = Url;
274274
}
275275
const UnicodeString ParsedPath = ParsePathFromUrl(CorrectedUrl);
276+
#if defined(__BORLANDC__)
276277
if (!ParsedPath.IsEmpty())
277278
{
278279
// this is most likely pointless as it get overwritten by
279280
// call to ChangeDirectory() from TTerminal::DoStartup
280281
FCurrentDirectory = ParsedPath;
281282
}
283+
#endif // defined(__BORLANDC__)
282284
}
283285

284286
void TWebDAVFileSystem::NeonClientOpenSessionInternal(UnicodeString & CorrectedUrl, const UnicodeString & AUrl)
@@ -736,7 +738,7 @@ void TWebDAVFileSystem::ReadCurrentDirectory()
736738
{
737739
if (FCachedDirectoryChange.IsEmpty())
738740
{
739-
FCurrentDirectory = FCurrentDirectory.IsEmpty() ? UnicodeString(ROOTDIRECTORY) : FCurrentDirectory;
741+
// FCurrentDirectory is set later during TTerminal::DoStartup execution
740742
}
741743
else
742744
{

0 commit comments

Comments
 (0)