1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00

Option to cleanup Cached host keys removes all other kinds of caches as well (the next major version will even say so)

Source commit: 99b731ed399220748631039a373037a216fd59ba
This commit is contained in:
Martin Prikryl
2019-11-13 15:30:49 +00:00
parent 8c646ce6af
commit 31bb835842
4 changed files with 30 additions and 23 deletions

View File

@@ -39,6 +39,9 @@ const UnicodeString TlsFingerprintType(L"tls");
const UnicodeString FtpsCertificateStorageKey(L"FtpsCertificates");
const UnicodeString HttpsCertificateStorageKey(L"HttpsCertificates");
const UnicodeString LastFingerprintsStorageKey(L"LastFingerprints");
const UnicodeString DirectoryStatisticsCacheKey(L"DirectoryStatisticsCache");
const UnicodeString CDCacheKey(L"CDCache");
const UnicodeString BannersKey(L"Banners");
//---------------------------------------------------------------------------
__fastcall TConfiguration::TConfiguration()
{
@@ -515,7 +518,7 @@ void __fastcall TConfiguration::CopyData(THierarchicalStorage * Source,
{
if (CopySubKey(Source, Target, ConfigurationSubKey))
{
if (CopySubKey(Source, Target, L"CDCache"))
if (CopySubKey(Source, Target, CDCacheKey))
{
std::unique_ptr<TStrings> Names(new TStringList());
Source->GetValueNames(Names.get());
@@ -529,7 +532,7 @@ void __fastcall TConfiguration::CopyData(THierarchicalStorage * Source,
Source->CloseSubKey();
}
CopyAllStringsInSubKey(Source, Target, L"Banners");
CopyAllStringsInSubKey(Source, Target, BannersKey);
CopyAllStringsInSubKey(Source, Target, LastFingerprintsStorageKey);
Target->CloseSubKey();
@@ -549,7 +552,7 @@ void __fastcall TConfiguration::LoadDirectoryChangesCache(const UnicodeString Se
{
Storage->AccessMode = smRead;
if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
Storage->OpenSubKey(L"CDCache", false) &&
Storage->OpenSubKey(CDCacheKey, false) &&
Storage->ValueExists(SessionKey))
{
DirectoryChangesCache->Deserialize(Storage->ReadBinaryData(SessionKey));
@@ -569,7 +572,7 @@ void __fastcall TConfiguration::SaveDirectoryChangesCache(const UnicodeString Se
{
Storage->AccessMode = smReadWrite;
if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
Storage->OpenSubKey(L"CDCache", true))
Storage->OpenSubKey(CDCacheKey, true))
{
UnicodeString Data;
DirectoryChangesCache->Serialize(Data);
@@ -601,7 +604,7 @@ void __fastcall TConfiguration::GetBannerData(
std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
Storage->AccessMode = smRead;
if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
Storage->OpenSubKey(L"Banners", false))
Storage->OpenSubKey(BannersKey, false))
{
UnicodeString S = Storage->ReadString(SessionKey, L"");
BannerHash = CutToChar(S, L',', true);
@@ -625,7 +628,7 @@ void __fastcall TConfiguration::SetBannerData(
Storage->AccessMode = smReadWrite;
if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
Storage->OpenSubKey(L"Banners", true))
Storage->OpenSubKey(BannersKey, true))
{
Storage->WriteString(SessionKey, BannerHash + L"," + UIntToStr(Params));
}
@@ -744,26 +747,30 @@ void __fastcall TConfiguration::CleanupConfiguration()
}
}
//---------------------------------------------------------------------------
void __fastcall TConfiguration::CleanupRegistry(UnicodeString CleanupSubKey)
void __fastcall TConfiguration::CleanupRegistry(const UnicodeString & CleanupSubKey, const UnicodeString & ParentKey)
{
TRegistryStorage *Registry = new TRegistryStorage(RegistryStorageKey);
try
std::unique_ptr<TRegistryStorage> Registry(new TRegistryStorage(RegistryStorageKey));
if (ParentKey.IsEmpty() ||
Registry->OpenSubKeyPath(ParentKey, false))
{
Registry->RecursiveDeleteSubKey(CleanupSubKey);
}
__finally
{
delete Registry;
}
}
//---------------------------------------------------------------------------
void __fastcall TConfiguration::CleanupHostKeys()
void __fastcall TConfiguration::CleanupCaches()
{
try
{
CleanupRegistry(SshHostKeysSubKey);
CleanupRegistry(FtpsCertificateStorageKey);
CleanupRegistry(HttpsCertificateStorageKey);
CleanupRegistry(DirectoryStatisticsCacheKey);
CleanupRegistry(CDCacheKey, ConfigurationSubKey);
CleanupRegistry(BannersKey, ConfigurationSubKey);
CleanupRegistry(LastFingerprintsStorageKey, ConfigurationSubKey);
}
catch (Exception &E)
catch (Exception & E)
{
throw ExtException(&E, LoadStr(CLEANUP_HOSTKEYS_ERROR));
}
@@ -1480,7 +1487,7 @@ THierarchicalStorage * TConfiguration::OpenDirectoryStatisticsCache(bool CanCrea
{
std::unique_ptr<THierarchicalStorage> Storage(Configuration->CreateConfigStorage());
Storage->AccessMode = CanCreate ? smReadWrite : smRead;
if (!Storage->OpenSubKey(L"DirectoryStatisticsCache", CanCreate))
if (!Storage->OpenSubKey(DirectoryStatisticsCacheKey, CanCreate))
{
Storage.reset(NULL);
}

View File

@@ -161,7 +161,7 @@ protected:
virtual void __fastcall LoadAdmin(THierarchicalStorage * Storage);
virtual UnicodeString __fastcall GetDefaultKeyFile();
virtual void __fastcall Saved();
void __fastcall CleanupRegistry(UnicodeString CleanupSubKey);
void __fastcall CleanupRegistry(const UnicodeString & CleanupSubKey, const UnicodeString & ParentKey = UnicodeString());
void __fastcall CopyAllStringsInSubKey(
THierarchicalStorage * Source, THierarchicalStorage * Target, const UnicodeString & Name);
bool __fastcall CopySubKey(THierarchicalStorage * Source, THierarchicalStorage * Target, const UnicodeString & Name);
@@ -223,7 +223,7 @@ public:
void __fastcall Import(const UnicodeString & FileName);
void __fastcall CleanupConfiguration();
void __fastcall CleanupIniFile();
void __fastcall CleanupHostKeys();
void __fastcall CleanupCaches();
void __fastcall CleanupRandomSeedFile();
void __fastcall BeginUpdate();
void __fastcall EndUpdate();

View File

@@ -44,8 +44,8 @@ Boolean __fastcall DoCleanupDialog(TStoredSessionList *SessionList,
SessionList->Cleanup();
break;
case wdHostKeys:
Configuration->CleanupHostKeys();
case wdCaches:
Configuration->CleanupCaches();
break;
case wdConfigurationIniFile:
@@ -102,9 +102,9 @@ void __fastcall TCleanupDialog::InitControls()
Location = Configuration->StoredSessionsSubKey;
break;
case wdHostKeys:
case wdCaches:
Caption = LoadStr(CLEANUP_HOSTKEYS);
Location = Configuration->SshHostKeysSubKey;
Location = L"...";
break;
case wdConfigurationIniFile:

View File

@@ -12,7 +12,7 @@
#include <WinInterface.h>
#include <GUITools.h>
//---------------------------------------------------------------------
enum TWinSCPData {wdConfiguration = 1, wdStoredSessions, wdHostKeys,
enum TWinSCPData {wdConfiguration = 1, wdStoredSessions, wdCaches,
wdConfigurationIniFile, wdRandomSeedFile, wdTemporaryFolders };
//---------------------------------------------------------------------
class TCleanupDialog : public TForm