Browse Source

App logging for Open in PuTTY

Source commit: 874547a2c32c07ae82a8df65d63d3cceae03a4e4
Martin Prikryl 2 years ago
parent
commit
deb89bf039
3 changed files with 20 additions and 4 deletions
  1. 4 1
      source/core/SessionData.cpp
  2. 1 1
      source/core/SessionData.h
  3. 15 2
      source/windows/GUITools.cpp

+ 4 - 1
source/core/SessionData.cpp

@@ -5354,9 +5354,10 @@ THierarchicalStorage * __fastcall TStoredSessionList::CreateHostKeysStorageForWr
   return Storage.release();
 }
 //---------------------------------------------------------------------------
-void __fastcall TStoredSessionList::ImportHostKeys(
+int __fastcall TStoredSessionList::ImportHostKeys(
   THierarchicalStorage * SourceStorage, THierarchicalStorage * TargetStorage, TStoredSessionList * Sessions, bool OnlySelected)
 {
+  int Result = 0;
   if (OpenHostKeysSubKey(SourceStorage, false) &&
       OpenHostKeysSubKey(TargetStorage, true))
   {
@@ -5376,11 +5377,13 @@ void __fastcall TStoredSessionList::ImportHostKeys(
           if (EndsText(HostKeyName, KeyName))
           {
             TargetStorage->WriteStringRaw(KeyName, SourceStorage->ReadStringRaw(KeyName, L""));
+            Result++;
           }
         }
       }
     }
   }
+  return Result;
 }
 //---------------------------------------------------------------------------
 void __fastcall TStoredSessionList::ImportHostKeys(

+ 1 - 1
source/core/SessionData.h

@@ -767,7 +767,7 @@ public:
   __property TSessionData * Sessions[int Index]  = { read=AtSession };
   __property TSessionData * DefaultSettings  = { read=FDefaultSettings, write=SetDefaultSettings };
 
-  static void __fastcall ImportHostKeys(
+  static int __fastcall ImportHostKeys(
     THierarchicalStorage * SourceStorage, THierarchicalStorage * TargetStorage, TStoredSessionList * Sessions, bool OnlySelected);
   static void __fastcall ImportHostKeys(
     const UnicodeString & SourceKey, TStoredSessionList * Sessions, bool OnlySelected);

+ 15 - 2
source/windows/GUITools.cpp

@@ -111,7 +111,11 @@ bool __fastcall ExportSessionToPutty(TSessionData * SessionData, bool ReuseExist
   if (Storage->OpenRootKey(true))
   {
     Result = ReuseExisting && Storage->KeyExists(SessionData->StorageKey);
-    if (!Result)
+    if (Result)
+    {
+      AppLogFmt(L"Reusing existing PuTTY session: %s", (SessionData->StorageKey));
+    }
+    else
     {
       std::unique_ptr<TRegistryStorage> SourceStorage(new TRegistryStorage(Configuration->PuttySessionsKey));
       SourceStorage->ConfigureForPutty();
@@ -144,6 +148,7 @@ bool __fastcall ExportSessionToPutty(TSessionData * SessionData, bool ReuseExist
       }
 
       ExportData->Save(Storage.get(), true);
+      AppLogFmt(L"Exported site settings to PuTTY session: %s", (SessionName));
     }
   }
   return Result;
@@ -290,6 +295,8 @@ void OpenSessionInPutty(TSessionData * SessionData)
   UnicodeString Program, AParams, Dir;
   SplitCommand(GUIConfiguration->PuttyPath, Program, AParams, Dir);
   Program = ExpandEnvironmentVariables(Program);
+  AppLogFmt(L"PuTTY program: %s", (Program));
+  AppLogFmt(L"Params: %s", (AParams));
   if (FindFile(Program))
   {
 
@@ -315,6 +322,7 @@ void OpenSessionInPutty(TSessionData * SessionData)
     UnicodeString Params =
       LocalCustomCommand.Complete(InteractiveCustomCommand.Complete(AParams, false), true);
     UnicodeString PuttyParams;
+    AppLogFmt(L"Expanded params: %s", (Params));
 
     if (!LocalCustomCommand.IsSiteCommand(AParams))
     {
@@ -327,7 +335,8 @@ void OpenSessionInPutty(TSessionData * SessionData)
         std::unique_ptr<TStoredSessionList> HostKeySessionList(new TStoredSessionList());
         HostKeySessionList->OwnsObjects = false;
         HostKeySessionList->Add(SessionData);
-        TStoredSessionList::ImportHostKeys(SourceHostKeyStorage.get(), TargetHostKeyStorage.get(), HostKeySessionList.get(), false);
+        int Imported = TStoredSessionList::ImportHostKeys(SourceHostKeyStorage.get(), TargetHostKeyStorage.get(), HostKeySessionList.get(), false);
+        AppLogFmt(L"Imported host keys: %d", (Imported));
       }
 
       if (IsUWP())
@@ -380,6 +389,8 @@ void OpenSessionInPutty(TSessionData * SessionData)
         {
           AddToList(PuttyParams, L"-6", L" ");
         }
+
+        AppLogFmt(L"Using command-line instead of stored session in UWP: %s", (PuttyParams));
       }
       else
       {
@@ -537,6 +548,7 @@ bool __fastcall CopyCommandToClipboard(const UnicodeString & Command)
   if (Result)
   {
     TInstantOperationVisualizer Visualizer;
+    AppLogFmt(L"Copied command to the clipboard: %s", (Command));
     CopyToClipboard(Command);
   }
   return Result;
@@ -570,6 +582,7 @@ static bool __fastcall DoExecuteShell(const UnicodeString Path, const UnicodeStr
     ExecuteInfo.lpDirectory = (ChangeWorkingDirectory ? Directory.c_str() : NULL);
     ExecuteInfo.nShow = SW_SHOW;
 
+    AppLogFmt(L"Executing program \"%s\" with params: %s", (Path, Params));
     Result = (ShellExecuteEx(&ExecuteInfo) != 0);
     if (Result)
     {