浏览代码

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
Martin Prikryl 6 年之前
父节点
当前提交
31bb835842
共有 4 个文件被更改,包括 30 次插入23 次删除
  1. 23 16
      source/core/Configuration.cpp
  2. 2 2
      source/core/Configuration.h
  3. 4 4
      source/forms/Cleanup.cpp
  4. 1 1
      source/forms/Cleanup.h

+ 23 - 16
source/core/Configuration.cpp

@@ -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);
   }

+ 2 - 2
source/core/Configuration.h

@@ -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();

+ 4 - 4
source/forms/Cleanup.cpp

@@ -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:

+ 1 - 1
source/forms/Cleanup.h

@@ -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