|
|
@@ -153,6 +153,7 @@ class TPuttyCleanupThread : public TSimpleThread
|
|
|
{
|
|
|
public:
|
|
|
static void Schedule();
|
|
|
+ static void Finalize();
|
|
|
|
|
|
protected:
|
|
|
virtual void __fastcall Execute();
|
|
|
@@ -166,8 +167,8 @@ private:
|
|
|
static std::unique_ptr<TCriticalSection> FSection;
|
|
|
};
|
|
|
//---------------------------------------------------------------------------
|
|
|
-TPuttyCleanupThread * TPuttyCleanupThread::FInstance(NULL);
|
|
|
std::unique_ptr<TCriticalSection> TPuttyCleanupThread::FSection(TraceInitPtr(new TCriticalSection()));
|
|
|
+TPuttyCleanupThread * TPuttyCleanupThread::FInstance;
|
|
|
//---------------------------------------------------------------------------
|
|
|
void TPuttyCleanupThread::Schedule()
|
|
|
{
|
|
|
@@ -184,59 +185,85 @@ void TPuttyCleanupThread::Schedule()
|
|
|
}
|
|
|
}
|
|
|
//---------------------------------------------------------------------------
|
|
|
-void __fastcall TPuttyCleanupThread::Execute()
|
|
|
+void TPuttyCleanupThread::Finalize()
|
|
|
{
|
|
|
- std::unique_ptr<TStrings> Sessions(new TStringList());
|
|
|
-
|
|
|
- do
|
|
|
+ while (true)
|
|
|
{
|
|
|
{
|
|
|
TGuard Guard(FSection.get());
|
|
|
- std::unique_ptr<TRegistryStorage> Storage(new TRegistryStorage(Configuration->PuttySessionsKey));
|
|
|
- Storage->AccessMode = smReadWrite;
|
|
|
- Storage->ConfigureForPutty();
|
|
|
+ if (FInstance == NULL)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Sleep(100);
|
|
|
+ }
|
|
|
+}
|
|
|
+//---------------------------------------------------------------------------
|
|
|
+void __fastcall TPuttyCleanupThread::Execute()
|
|
|
+{
|
|
|
+ try
|
|
|
+ {
|
|
|
+ std::unique_ptr<TStrings> Sessions(new TStringList());
|
|
|
+ bool Continue = true;
|
|
|
|
|
|
- std::unique_ptr<TStringList> Sessions2(new TStringList());
|
|
|
- if (Storage->OpenRootKey(true))
|
|
|
+ do
|
|
|
+ {
|
|
|
{
|
|
|
- std::unique_ptr<TStrings> SubKeys(new TStringList());
|
|
|
- Storage->GetSubKeyNames(SubKeys.get());
|
|
|
- for (int Index = 0; Index < SubKeys->Count; Index++)
|
|
|
+ TGuard Guard(FSection.get());
|
|
|
+ std::unique_ptr<TRegistryStorage> Storage(new TRegistryStorage(Configuration->PuttySessionsKey));
|
|
|
+ Storage->AccessMode = smReadWrite;
|
|
|
+ Storage->ConfigureForPutty();
|
|
|
+
|
|
|
+ std::unique_ptr<TStringList> Sessions2(new TStringList());
|
|
|
+ if (Storage->OpenRootKey(true))
|
|
|
{
|
|
|
- UnicodeString SessionName = SubKeys->Strings[Index];
|
|
|
- if (StartsStr(GUIConfiguration->PuttySession, SessionName))
|
|
|
+ std::unique_ptr<TStrings> SubKeys(new TStringList());
|
|
|
+ Storage->GetSubKeyNames(SubKeys.get());
|
|
|
+ for (int Index = 0; Index < SubKeys->Count; Index++)
|
|
|
{
|
|
|
- Sessions2->Add(SessionName);
|
|
|
+ UnicodeString SessionName = SubKeys->Strings[Index];
|
|
|
+ if (StartsStr(GUIConfiguration->PuttySession, SessionName))
|
|
|
+ {
|
|
|
+ Sessions2->Add(SessionName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Sessions2->Sort();
|
|
|
+ if (!Sessions->Equals(Sessions2.get()))
|
|
|
+ {
|
|
|
+ // Just in case new sessions from another WinSCP instance are added, delay the cleanup
|
|
|
+ // (to avoid having to implement some inter-process communication).
|
|
|
+ // Both instances will attempt to do the cleanup, but that not a problem
|
|
|
+ Sessions->Assign(Sessions2.get());
|
|
|
+ DoSchedule();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Sessions2->Sort();
|
|
|
- if (!Sessions->Equals(Sessions2.get()))
|
|
|
+ if (FTimer < Now())
|
|
|
{
|
|
|
- // Just in case new sessions from another WinSCP instance are added, delay the cleanup
|
|
|
- // (to avoid having to implement some inter-process communication).
|
|
|
- // Both instances will attempt to do the cleanup, but that not a problem
|
|
|
- Sessions->Assign(Sessions2.get());
|
|
|
- DoSchedule();
|
|
|
+ for (int Index = 0; Index < Sessions->Count; Index++)
|
|
|
+ {
|
|
|
+ UnicodeString SessionName = Sessions->Strings[Index];
|
|
|
+ Storage->RecursiveDeleteSubKey(SessionName);
|
|
|
+ }
|
|
|
+
|
|
|
+ Continue = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (FTimer < Now())
|
|
|
+ if (Continue)
|
|
|
{
|
|
|
- for (int Index = 0; Index < Sessions->Count; Index++)
|
|
|
- {
|
|
|
- UnicodeString SessionName = Sessions->Strings[Index];
|
|
|
- Storage->RecursiveDeleteSubKey(SessionName);
|
|
|
- }
|
|
|
-
|
|
|
- FInstance = NULL;
|
|
|
- return;
|
|
|
+ Sleep(1000);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- Sleep(1000);
|
|
|
+ while (Continue);
|
|
|
+ }
|
|
|
+ __finally
|
|
|
+ {
|
|
|
+ TGuard Guard(FSection.get());
|
|
|
+ FInstance = NULL;
|
|
|
}
|
|
|
- while (true);
|
|
|
}
|
|
|
//---------------------------------------------------------------------------
|
|
|
void __fastcall TPuttyCleanupThread::Terminate()
|
|
|
@@ -2269,3 +2296,8 @@ bool CanShowTimeEstimate(TDateTime StartTime)
|
|
|
{
|
|
|
return (SecondsBetween(StartTime, Now()) >= 3);
|
|
|
}
|
|
|
+//---------------------------------------------------------------------------
|
|
|
+void GUIFinalize()
|
|
|
+{
|
|
|
+ TPuttyCleanupThread::Finalize();
|
|
|
+}
|