Преглед изворни кода

Bug 1551: Adding import from KiTTY directly to the Import dialog

+ Bug fix: When importing from FileZilla with KiTTY selected as SSH terminal, host keys were imported from KiTTY instead of FileZilla/PuTTY.

https://winscp.net/tracker/1551

Source commit: d0d428526e6a4b675e1524997f91ec654ee24973
Martin Prikryl пре 3 година
родитељ
комит
1e8d4d3a13

+ 7 - 2
source/core/Configuration.cpp

@@ -1307,9 +1307,14 @@ UnicodeString __fastcall TConfiguration::GetPuttySessionsSubKey()
   return StoredSessionsSubKey;
 }
 //---------------------------------------------------------------------------
-UnicodeString __fastcall TConfiguration::GetPuttySessionsKey()
+UnicodeString TConfiguration::GetPuttySessionsKey(const UnicodeString & RootKey)
 {
-  return PuttyRegistryStorageKey + L"\\" + PuttySessionsSubKey;
+  return RootKey + L"\\" + PuttySessionsSubKey;
+}
+//---------------------------------------------------------------------------
+UnicodeString __fastcall TConfiguration::DoGetPuttySessionsKey()
+{
+  return GetPuttySessionsKey(PuttyRegistryStorageKey);
 }
 //---------------------------------------------------------------------------
 UnicodeString __fastcall TConfiguration::GetStoredSessionsSubKey()

+ 3 - 2
source/core/Configuration.h

@@ -96,7 +96,7 @@ private:
   UnicodeString __fastcall GetCompanyName();
   UnicodeString __fastcall GetFileVersion(TVSFixedFileInfo * Info);
   UnicodeString __fastcall GetStoredSessionsSubKey();
-  UnicodeString __fastcall GetPuttySessionsKey();
+  UnicodeString __fastcall DoGetPuttySessionsKey();
   UnicodeString __fastcall GetPuttySessionsSubKey();
   void __fastcall SetRandomSeedFile(UnicodeString value);
   UnicodeString __fastcall GetRandomSeedFileName();
@@ -278,6 +278,7 @@ public:
   TStoredSessionList * __fastcall SelectKnownHostsSessionsForImport(
     TStrings * Lines, TStoredSessionList * Sessions, UnicodeString & Error);
   TStoredSessionList * SelectOpensshSessionsForImport(TStoredSessionList * Sessions, UnicodeString & Error);
+  UnicodeString GetPuttySessionsKey(const UnicodeString & RootKey);
 
   __property TVSFixedFileInfo *FixedApplicationInfo  = { read=GetFixedApplicationInfo };
   __property void * ApplicationInfo  = { read=GetApplicationInfo };
@@ -285,7 +286,7 @@ public:
   __property bool CollectUsage = { read = GetCollectUsage, write = SetCollectUsage };
   __property UnicodeString StoredSessionsSubKey = {read=GetStoredSessionsSubKey};
   __property UnicodeString PuttyRegistryStorageKey  = { read=FPuttyRegistryStorageKey, write=SetPuttyRegistryStorageKey };
-  __property UnicodeString PuttySessionsKey  = { read=GetPuttySessionsKey };
+  __property UnicodeString PuttySessionsKey  = { read=DoGetPuttySessionsKey };
   __property UnicodeString PuttySessionsSubKey  = { read=GetPuttySessionsSubKey };
   __property UnicodeString RandomSeedFile  = { read=FRandomSeedFile, write=SetRandomSeedFile };
   __property UnicodeString RandomSeedFileName  = { read=GetRandomSeedFileName };

+ 12 - 4
source/forms/ImportSessions.cpp

@@ -19,8 +19,8 @@
 //---------------------------------------------------------------------
 #pragma resource "*.dfm"
 //---------------------------------------------------------------------
-const int OpensshIndex = 2;
-const int KnownHostsIndex = 3;
+const int OpensshIndex = 3;
+const int KnownHostsIndex = 4;
 //---------------------------------------------------------------------
 bool __fastcall DoImportSessionsDialog(TList * Imported)
 {
@@ -29,10 +29,15 @@ bool __fastcall DoImportSessionsDialog(TList * Imported)
   UnicodeString Error;
 
   std::unique_ptr<TStoredSessionList> PuttyImportSessionList(
-    GUIConfiguration->SelectPuttySessionsForImport(StoredSessions, Error));
+    GUIConfiguration->SelectPuttySessionsForImport(OriginalPuttyRegistryStorageKey, L"PuTTY", StoredSessions, Error));
   SessionListsList->Add(PuttyImportSessionList.get());
   Errors->Add(Error);
 
+  std::unique_ptr<TStoredSessionList> KittyImportSessionList(
+    GUIConfiguration->SelectPuttySessionsForImport(KittyRegistryStorageKey, L"KiTTY", StoredSessions, Error));
+  SessionListsList->Add(KittyImportSessionList.get());
+  Errors->Add(Error);
+
   std::unique_ptr<TStoredSessionList> FilezillaImportSessionList(
     Configuration->SelectFilezillaSessionsForImport(StoredSessions, Error));
   SessionListsList->Add(FilezillaImportSessionList.get());
@@ -63,13 +68,16 @@ bool __fastcall DoImportSessionsDialog(TList * Imported)
     // Particularly when importing known_hosts, there is no feedback.
     TInstantOperationVisualizer Visualizer;
 
-    UnicodeString PuttyHostKeysSourceKey = Configuration->PuttyRegistryStorageKey;
+    UnicodeString PuttyHostKeysSourceKey = OriginalPuttyRegistryStorageKey;
     TStoredSessionList * AKnownHostsImportSessionList =
       static_cast<TStoredSessionList *>(SessionListsList->Items[KnownHostsIndex]);
 
     StoredSessions->Import(PuttyImportSessionList.get(), true, Imported);
     TStoredSessionList::ImportHostKeys(PuttyHostKeysSourceKey, PuttyImportSessionList.get(), true);
 
+    StoredSessions->Import(KittyImportSessionList.get(), true, Imported);
+    TStoredSessionList::ImportHostKeys(KittyRegistryStorageKey, KittyImportSessionList.get(), true);
+
     StoredSessions->Import(FilezillaImportSessionList.get(), true, Imported);
     // FileZilla uses PuTTY's host key store
     TStoredSessionList::ImportHostKeys(PuttyHostKeysSourceKey, FilezillaImportSessionList.get(), true);

+ 1 - 0
source/forms/ImportSessions.dfm

@@ -103,6 +103,7 @@ object ImportSessionsDialog: TImportSessionsDialog
     OnSelect = SourceComboBoxSelect
     Items.Strings = (
       'PuTTY'
+      'KiTTY'
       'FileZilla'
       'OpenSSH'
       'known_hosts')

+ 1 - 1
source/resource/TextsWin.h

@@ -59,7 +59,7 @@
 #define SHELL_PATTERN_ERROR     1175
 #define PATH_ENV_TOO_LONG       1176
 #define STACK_TRACE             1177
-#define PUTTY_NO_SITES          1180
+#define PUTTY_NO_SITES2         1180
 #define BATCH_SET_NO_MASK       1181
 #define BATCH_SET_NO_SETTINGS   1182
 #define BATCH_SET_NOT_CHANGED   1183

+ 1 - 1
source/resource/TextsWin1.rc

@@ -67,7 +67,7 @@ BEGIN
         SHELL_PATTERN_ERROR, "Error executing command \"%s\" (%s)."
         PATH_ENV_TOO_LONG, "Cannot add new path to %PATH%, %PATH% is already too long."
         STACK_TRACE, "Stack trace:"
-        PUTTY_NO_SITES, "No sites found in PuTTY sites registry key (%s)."
+        PUTTY_NO_SITES2, "No sites found in %s sites registry key (%s)."
         BATCH_SET_NO_MASK, "No site mask specified."
         BATCH_SET_NO_SETTINGS, "No site settings specified."
         BATCH_SET_NOT_CHANGED, "Not changed"

+ 6 - 4
source/windows/GUIConfiguration.cpp

@@ -1371,12 +1371,13 @@ void __fastcall TGUIConfiguration::SetQueueKeepDoneItemsFor(int value)
 }
 //---------------------------------------------------------------------
 TStoredSessionList * __fastcall TGUIConfiguration::SelectPuttySessionsForImport(
-  TStoredSessionList * Sessions, UnicodeString & Error)
+  const UnicodeString & RootKey, const UnicodeString & Source, TStoredSessionList * Sessions, UnicodeString & Error)
 {
   std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
   ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
 
-  std::unique_ptr<TRegistryStorage> Storage(new TRegistryStorage(PuttySessionsKey));
+  UnicodeString SessionsKey = GetPuttySessionsKey(RootKey);
+  std::unique_ptr<TRegistryStorage> Storage(new TRegistryStorage(SessionsKey));
   Storage->ConfigureForPutty();
   if (Storage->OpenRootKey(false))
   {
@@ -1395,7 +1396,7 @@ TStoredSessionList * __fastcall TGUIConfiguration::SelectPuttySessionsForImport(
   }
   else
   {
-    Error = FMTLOAD(PUTTY_NO_SITES, (PuttySessionsKey));
+    Error = FMTLOAD(PUTTY_NO_SITES2, (Source, SessionsKey));
   }
 
   return ImportSessionList.release();
@@ -1406,7 +1407,8 @@ bool __fastcall TGUIConfiguration::AnyPuttySessionForImport(TStoredSessionList *
   try
   {
     UnicodeString Error;
-    std::unique_ptr<TStoredSessionList> SessionsForImport(SelectPuttySessionsForImport(Sessions, Error));
+    std::unique_ptr<TStoredSessionList> SessionsForImport(
+      SelectPuttySessionsForImport(OriginalPuttyRegistryStorageKey, L"PuTTY", Sessions, Error));
     return (SessionsForImport->Count > 0);
   }
   catch (...)

+ 2 - 1
source/windows/GUIConfiguration.h

@@ -249,7 +249,8 @@ public:
   bool __fastcall UsingInternalTranslation();
   UnicodeString __fastcall AppliedLocaleCopyright();
   UnicodeString __fastcall AppliedLocaleVersion();
-  TStoredSessionList * __fastcall SelectPuttySessionsForImport(TStoredSessionList * Sessions, UnicodeString & Error);
+  TStoredSessionList * __fastcall SelectPuttySessionsForImport(
+    const UnicodeString & RootKey, const UnicodeString & Source, TStoredSessionList * Sessions, UnicodeString & Error);
   bool __fastcall AnyPuttySessionForImport(TStoredSessionList * Sessions);
 
   __property bool ContinueOnError = { read = FContinueOnError, write = FContinueOnError };