mirror of
https://github.com/winscp/winscp.git
synced 2026-10-24 02:28:55 +03:00
Bug 2066: In .NET assembly or scripting with "nul" configuration, when WinSCP registry key does not exist, do not write statistics to INI file
https://winscp.net/tracker/2066 Source commit: 51f067850f46e2ad633d336b20183fa0955b33e0
This commit is contained in:
@@ -1169,11 +1169,6 @@ void __fastcall TConfiguration::SetNulStorage()
|
||||
FStorage = stNul;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TConfiguration::SetDefaultStorage()
|
||||
{
|
||||
FStorage = stDetect;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TConfiguration::SetExplicitIniFileStorageName(const UnicodeString & FileName)
|
||||
{
|
||||
FIniFileStorageName = FileName;
|
||||
|
||||
@@ -225,7 +225,6 @@ public:
|
||||
void __fastcall ScheduleCustomIniFileStorageUse(const UnicodeString & ACustomIniFileStorageName);
|
||||
void __fastcall SetExplicitIniFileStorageName(const UnicodeString & FileName);
|
||||
void __fastcall SetNulStorage();
|
||||
void __fastcall SetDefaultStorage();
|
||||
UnicodeString __fastcall GetAutomaticIniFileStorageName(bool ReadingOnly);
|
||||
UnicodeString __fastcall GetDefaultIniFileExportPath();
|
||||
UnicodeString __fastcall GetIniFileParamValue();
|
||||
|
||||
@@ -841,6 +841,49 @@ bool __fastcall TWinConfiguration::CanWriteToStorage()
|
||||
return Result;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
bool TWinConfiguration::DetectStorage(bool SafeOnly)
|
||||
{
|
||||
bool Result;
|
||||
FStorage = stIniFile;
|
||||
if (FileExists(ApiPath(IniFileStorageNameForReading)))
|
||||
{
|
||||
Result = !SafeOnly;
|
||||
if (Result)
|
||||
{
|
||||
FStorage = stIniFile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DetectRegistryStorage(HKEY_CURRENT_USER) ||
|
||||
DetectRegistryStorage(HKEY_LOCAL_MACHINE))
|
||||
{
|
||||
FStorage = stRegistry;
|
||||
Result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SafeOnly)
|
||||
{
|
||||
Result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
FStorage = stIniFile;
|
||||
// As we fall back to user profile folder, when application folder
|
||||
// is not writtable, it is actually unlikely that the below test ever fails.
|
||||
if (!CanWriteToStorage())
|
||||
{
|
||||
FStorage = stRegistry;
|
||||
}
|
||||
// With !SafeOnly we always return true, so this result is actually never considered
|
||||
Result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
TStorage __fastcall TWinConfiguration::GetStorage()
|
||||
{
|
||||
if (FStorage == stDetect)
|
||||
@@ -860,24 +903,19 @@ TStorage __fastcall TWinConfiguration::GetStorage()
|
||||
}
|
||||
}
|
||||
|
||||
FStorage = stIniFile;
|
||||
if (!FileExists(ApiPath(IniFileStorageNameForReading)))
|
||||
{
|
||||
if (DetectRegistryStorage(HKEY_CURRENT_USER) ||
|
||||
DetectRegistryStorage(HKEY_LOCAL_MACHINE) ||
|
||||
// FStorage is now stIniFile, so this tests writing to an INI file.
|
||||
// As we fall back to user profile folder, when application folder
|
||||
// is not writtable, it is actually unlikely that the below test ever fails.
|
||||
!CanWriteToStorage())
|
||||
{
|
||||
FStorage = stRegistry;
|
||||
}
|
||||
}
|
||||
DebugCheck(DetectStorage(false));
|
||||
}
|
||||
// Meaning any inherited autodetection basically does not happen, so the below call returns FStorage
|
||||
DebugAssert(FStorage != stDetect);
|
||||
TStorage Result = TCustomWinConfiguration::GetStorage();
|
||||
return Result;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
bool TWinConfiguration::TrySetSafeStorage()
|
||||
{
|
||||
return DetectStorage(true);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TWinConfiguration::Saved()
|
||||
{
|
||||
TCustomWinConfiguration::Saved();
|
||||
|
||||
@@ -593,6 +593,7 @@ private:
|
||||
|
||||
protected:
|
||||
virtual TStorage __fastcall GetStorage();
|
||||
bool DetectStorage(bool SafeOnly);
|
||||
virtual void __fastcall SaveData(THierarchicalStorage * Storage, bool All);
|
||||
virtual void __fastcall LoadData(THierarchicalStorage * Storage);
|
||||
virtual void __fastcall LoadFrom(THierarchicalStorage * Storage);
|
||||
@@ -660,6 +661,7 @@ public:
|
||||
bool __fastcall IsDDExtRunning();
|
||||
bool __fastcall IsDDExtBroken();
|
||||
bool __fastcall UseDarkTheme();
|
||||
bool TrySetSafeStorage();
|
||||
|
||||
static void __fastcall RestoreFont(const TFontConfiguration & Configuration, TFont * Font);
|
||||
static void __fastcall StoreFont(TFont * Font, TFontConfiguration & Configuration);
|
||||
|
||||
@@ -371,12 +371,12 @@ void __fastcall RecordWrapperVersions(UnicodeString ConsoleVersion, UnicodeStrin
|
||||
}
|
||||
WinConfiguration->Updates = Updates;
|
||||
|
||||
if (Configuration->Storage == stNul)
|
||||
if ((WinConfiguration->Storage == stNul) &&
|
||||
WinConfiguration->TrySetSafeStorage())
|
||||
{
|
||||
Configuration->SetDefaultStorage();
|
||||
try
|
||||
{
|
||||
THierarchicalStorage * Storage = Configuration->CreateConfigStorage();
|
||||
THierarchicalStorage * Storage = WinConfiguration->CreateConfigStorage();
|
||||
try
|
||||
{
|
||||
Storage->AccessMode = smReadWrite;
|
||||
|
||||
Reference in New Issue
Block a user