瀏覽代碼

Do not collect those PuTTY settings that WinSCP sets on its own

Source commit: 02fc69d6b63ad36c00696d884085c93ffb630784
Martin Prikryl 6 年之前
父節點
當前提交
4186858f7d
共有 4 個文件被更改,包括 30 次插入10 次删除
  1. 11 5
      source/core/SessionData.cpp
  2. 2 1
      source/core/SessionData.h
  3. 3 3
      source/forms/Custom.cpp
  4. 14 1
      source/forms/SiteAdvanced.cpp

+ 11 - 5
source/core/SessionData.cpp

@@ -1206,7 +1206,7 @@ void __fastcall TSessionData::DoSave(THierarchicalStorage * Storage,
   }
 }
 //---------------------------------------------------------------------
-TStrings * __fastcall TSessionData::SaveToOptions(const TSessionData * Default, bool SaveName)
+TStrings * __fastcall TSessionData::SaveToOptions(const TSessionData * Default, bool SaveName, bool PuttyExport)
 {
   std::unique_ptr<TStringList> Options(new TStringList());
   std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Options.get(), true));
@@ -1214,7 +1214,7 @@ TStrings * __fastcall TSessionData::SaveToOptions(const TSessionData * Default,
   {
     OptionsStorage->WriteString(L"Name", Name);
   }
-  DoSave(OptionsStorage.get(), false, Default, true);
+  DoSave(OptionsStorage.get(), PuttyExport, Default, true);
   return Options.release();
 }
 //---------------------------------------------------------------------
@@ -3110,7 +3110,7 @@ TStrings * __fastcall TSessionData::GetRawSettingsForUrl()
   SessionData->CopyNonCoreData(FactoryDefaults.get());
   // Cannot be decided in SaveToOptions as it does not have HostName and UserName, so it cannot calculate DefaultSessionName.
   bool SaveName = HasSessionName() && (Name != DefaultSessionName);
-  return SessionData->SaveToOptions(FactoryDefaults.get(), SaveName);
+  return SessionData->SaveToOptions(FactoryDefaults.get(), SaveName, false);
 }
 //---------------------------------------------------------------------
 bool __fastcall TSessionData::HasRawSettingsForUrl()
@@ -3286,7 +3286,7 @@ UnicodeString __fastcall TSessionData::GenerateOpenCommandArgs(bool Rtf)
     SessionData->Timeout = FactoryDefaults->Timeout;
   }
 
-  std::unique_ptr<TStrings> RawSettings(SessionData->SaveToOptions(FactoryDefaults.get(), false));
+  std::unique_ptr<TStrings> RawSettings(SessionData->SaveToOptions(FactoryDefaults.get(), false, false));
 
   if (RawSettings->Count > 0)
   {
@@ -3500,7 +3500,7 @@ void __fastcall TSessionData::GenerateAssemblyCode(
 
   Head += AssemblyNewClassInstanceEnd(Language, false);
 
-  std::unique_ptr<TStrings> RawSettings(SessionData->SaveToOptions(FactoryDefaults.get(), false));
+  std::unique_ptr<TStrings> RawSettings(SessionData->SaveToOptions(FactoryDefaults.get(), false, false));
 
   UnicodeString SessionOptionsVariableName = AssemblyVariableName(Language, SessionOptionsClassName);
 
@@ -4129,6 +4129,12 @@ void __fastcall TSessionData::DisableAuthentationsExceptPassword()
   Passphrase = L"";
   TryAgent = false;
 }
+//---------------------------------------------------------------------
+TStrings * TSessionData::GetAllOptionNames(bool PuttyExport)
+{
+  std::unique_ptr<TSessionData> FactoryDefaults(new TSessionData(L""));
+  return FactoryDefaults->SaveToOptions(NULL, false, PuttyExport);
+}
 //=== TStoredSessionList ----------------------------------------------
 __fastcall TStoredSessionList::TStoredSessionList(bool aReadOnly):
   TNamedObjectList(), FReadOnly(aReadOnly)

+ 2 - 1
source/core/SessionData.h

@@ -490,7 +490,7 @@ public:
   bool __fastcall ParseUrl(UnicodeString Url, TOptions * Options,
     TStoredSessionList * StoredSessions, bool & DefaultsOnly,
     UnicodeString * FileName, bool * AProtocolDefined, UnicodeString * MaskedUrl, int Flags);
-  TStrings * __fastcall SaveToOptions(const TSessionData * Default, bool SaveName);
+  TStrings * __fastcall SaveToOptions(const TSessionData * Default, bool SaveName, bool PuttyExport);
   void __fastcall ConfigureTunnel(int PortNumber);
   void __fastcall RollbackTunnel();
   void __fastcall ExpandEnvironmentVariables();
@@ -517,6 +517,7 @@ public:
   static bool __fastcall IsOptionWithParameters(const UnicodeString & Option);
   static bool __fastcall MaskPasswordInOptionParameter(const UnicodeString & Option, UnicodeString & Param);
   static UnicodeString __fastcall FormatSiteKey(const UnicodeString & HostName, int PortNumber);
+  static TStrings * GetAllOptionNames(bool PuttyExport);
 
   __property UnicodeString HostName  = { read=FHostName, write=SetHostName };
   __property UnicodeString HostNameExpanded  = { read=GetHostNameExpanded };

+ 3 - 3
source/forms/Custom.cpp

@@ -1482,7 +1482,7 @@ bool __fastcall TSiteRawDialog::Execute(TSessionData * Data)
   RawData->Password = FactoryDefaults->Password;
   RawData->Ftps = FactoryDefaults->Ftps;
 
-  std::unique_ptr<TStrings> Options(RawData->SaveToOptions(FactoryDefaults.get(), false));
+  std::unique_ptr<TStrings> Options(RawData->SaveToOptions(FactoryDefaults.get(), false, false));
 
   SettingsMemo->Lines = Options.get();
 
@@ -1522,9 +1522,9 @@ void __fastcall TSiteRawDialog::AddButtonClick(TObject *)
   BasicData->UserName = FactoryDefaults->UserName + RandomAppendix;
   BasicData->Password = FactoryDefaults->Password + RandomAppendix;
 
-  std::unique_ptr<TStrings> BasicOptions(BasicData->SaveToOptions(FactoryDefaults.get(), false));
+  std::unique_ptr<TStrings> BasicOptions(BasicData->SaveToOptions(FactoryDefaults.get(), false, false));
 
-  std::unique_ptr<TStrings> AllOptions(FactoryDefaults->SaveToOptions(NULL, false));
+  std::unique_ptr<TStrings> AllOptions(TSessionData::GetAllOptionNames(false));
 
   std::unique_ptr<TStrings> Names(CreateSortedStringList());
   for (int Index = 0; Index < AllOptions->Count; Index++)

+ 14 - 1
source/forms/SiteAdvanced.cpp

@@ -1726,7 +1726,10 @@ void __fastcall TSiteAdvancedDialog::PuttySettingsTimer(TObject *)
       UnicodeString NewValue = NewPuttyRegSettings->ValueFromIndex[NewIndex];
       int Index = FPuttyRegSettings->IndexOfName(Name);
       // Ignoring values we do not know (from future versions of PuTTY),
-      // as we cannot tell if they are modified or not
+      // as we cannot tell if they are modified or not.
+      // Ignoring also all value that we export outselves from WinSCP settings
+      // (primarily to avoid collecting all those values, when the user forgets to load the temporary site in PuTTY,
+      // and only saves the changed terminal settings with the basic session settings set to empty values)
       if ((Index >= 0) &&
           (FPuttyRegSettings->ValueFromIndex[Index] != NewValue))
       {
@@ -1777,6 +1780,16 @@ void __fastcall TSiteAdvancedDialog::PuttySettingsButtonClick(TObject *)
   FPuttyRegSettings.reset(new TStringList());
   SerializePuttyRegistry(PuttySiteKey, FPuttyRegSettings.get());
 
+  std::unique_ptr<TStrings> AllOptions(TSessionData::GetAllOptionNames(true));
+  for (int Index = 0; Index < AllOptions->Count; Index++)
+  {
+    int I = FPuttyRegSettings->IndexOfName(AllOptions->Names[Index]);
+    if (I >= 0)
+    {
+      FPuttyRegSettings->Delete(I);
+    }
+  }
+
   SessionData->PuttySettings = PuttySettings;
   ExportSessionToPutty(SessionData.get(), false, SiteName);