| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <FileInfo.h>
- #include "Exceptions.h"
- #include "Common.h"
- #include "Configuration.h"
- #include "PuttyIntf.h"
- #include "TextsCore.h"
- #include "Interface.h"
- #include "CoreMain.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- //---------------------------------------------------------------------------
- __fastcall TConfiguration::TConfiguration()
- {
- FCriticalSection = new TCriticalSection();
- FUpdating = 0;
- FStorage = stDetect;
- FDontSave = false;
- FApplicationInfo = NULL;
- FInitialized = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::Initialize()
- {
- AnsiString ARandomSeedFile = seedpath_ptr();
- FDefaultRandomSeedFile = StringReplace(ExtractFilePath(ARandomSeedFile) +
- "winscp" + ExtractFileExt(ARandomSeedFile), "\\\\", "\\",
- TReplaceFlags() << rfReplaceAll);
- FInitialized = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::Default()
- {
- TGuard Guard(FCriticalSection);
- RandomSeedFile = FDefaultRandomSeedFile;
- FConfirmOverwriting = true;
- FConfirmResume = true;
- FAutoReadDirectoryAfterOp = true;
- FSessionReopenAuto = 5000;
- FSessionReopenBackground = 2000;
- FTunnelLocalPortNumberLow = 6000;
- FTunnelLocalPortNumberHigh = 6100;
- FShowFtpWelcomeMessage = false;
- FLogging = false;
- FPermanentLogging = false;
- FLogFileName = "";
- FPermanentLogFileName = "";
- FLogFileAppend = true;
- FLogWindowLines = 100;
- FLogProtocol = 0;
- FDisablePasswordStoring = false;
- FForceBanners = false;
- FDisableAcceptingHostKeys = false;
- Changed();
- }
- //---------------------------------------------------------------------------
- __fastcall TConfiguration::~TConfiguration()
- {
- assert(!FUpdating);
- if (FApplicationInfo) FreeFileInfo(FApplicationInfo);
- delete FCriticalSection;
- }
- //---------------------------------------------------------------------------
- THierarchicalStorage * TConfiguration::CreateScpStorage(bool /*SessionList*/)
- {
- if (Storage == stRegistry)
- {
- return new TRegistryStorage(RegistryStorageKey);
- }
- else
- {
- return new TIniFileStorage(IniFileStorageName);
- }
- }
- //---------------------------------------------------------------------------
- #define LASTELEM(ELEM) \
- ELEM.SubString(ELEM.LastDelimiter(".>")+1, ELEM.Length() - ELEM.LastDelimiter(".>"))
- #define BLOCK(KEY, CANCREATE, BLOCK) \
- if (Storage->OpenSubKey(KEY, CANCREATE)) try { BLOCK } __finally { Storage->CloseSubKey(); }
- #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, VAR)
- #define REGCONFIG(CANCREATE) \
- BLOCK("Interface", CANCREATE, \
- KEY(String, RandomSeedFile); \
- KEY(Bool, ConfirmOverwriting); \
- KEY(Bool, ConfirmResume); \
- KEY(Bool, AutoReadDirectoryAfterOp); \
- KEY(Integer, SessionReopenAuto); \
- KEY(Integer, SessionReopenBackground); \
- KEY(Integer, TunnelLocalPortNumberLow); \
- KEY(Integer, TunnelLocalPortNumberHigh); \
- KEY(Bool, ShowFtpWelcomeMessage); \
- ); \
- BLOCK("Logging", CANCREATE, \
- KEYEX(Bool, PermanentLogging, Logging); \
- KEYEX(String,PermanentLogFileName, LogFileName); \
- KEY(Bool, LogFileAppend); \
- KEY(Integer, LogWindowLines); \
- KEY(Integer, LogProtocol); \
- );
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SaveData(THierarchicalStorage * Storage, bool /*All*/)
- {
- #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(LASTELEM(AnsiString(#NAME)), VAR)
- REGCONFIG(true);
- #undef KEYEX
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::Save(bool All)
- {
- if (FDontSave) return;
- if (Storage == stRegistry) CleanupIniFile();
- THierarchicalStorage * Storage = CreateScpStorage(false);
- try
- {
- Storage->AccessMode = smReadWrite;
- if (Storage->OpenSubKey(ConfigurationSubKey, true))
- {
- SaveData(Storage, All);
- }
- }
- __finally
- {
- delete Storage;
- }
- Saved();
- if (All)
- {
- StoredSessions->Save(true);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::Export(const AnsiString FileName)
- {
- THierarchicalStorage * Storage = NULL;
- THierarchicalStorage * ExportStorage = NULL;
- try
- {
- ExportStorage = new TIniFileStorage(FileName);
- ExportStorage->AccessMode = smReadWrite;
- Storage = CreateScpStorage(false);
- Storage->AccessMode = smRead;
- CopyData(Storage, ExportStorage);
- if (ExportStorage->OpenSubKey(ConfigurationSubKey, true))
- {
- SaveData(ExportStorage, true);
- }
- }
- __finally
- {
- delete ExportStorage;
- delete Storage;
- }
- StoredSessions->Export(FileName);
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::LoadData(THierarchicalStorage * Storage)
- {
- #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(LASTELEM(AnsiString(#NAME)), VAR)
- #pragma warn -eas
- REGCONFIG(false);
- #pragma warn +eas
- #undef KEYEX
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::LoadAdmin(THierarchicalStorage * Storage)
- {
- FDisablePasswordStoring = Storage->ReadBool("DisablePasswordStoring", FDisablePasswordStoring);
- FForceBanners = Storage->ReadBool("ForceBanners", FForceBanners);
- FDisableAcceptingHostKeys = Storage->ReadBool("DisableAcceptingHostKeys", FDisableAcceptingHostKeys);
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::Load()
- {
- TGuard Guard(FCriticalSection);
- THierarchicalStorage * Storage = CreateScpStorage(false);
- try
- {
- Storage->AccessMode = smRead;
- if (Storage->OpenSubKey(ConfigurationSubKey, false))
- {
- LoadData(Storage);
- }
- }
- __finally
- {
- delete Storage;
- }
- TRegistryStorage * AdminStorage;
- AdminStorage = new TRegistryStorage(RegistryStorageKey, HKEY_LOCAL_MACHINE);
- try
- {
- if (AdminStorage->OpenRootKey(false))
- {
- LoadAdmin(AdminStorage);
- AdminStorage->CloseSubKey();
- }
- }
- __finally
- {
- delete AdminStorage;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::CopyData(THierarchicalStorage * Source,
- THierarchicalStorage * Target)
- {
- TStrings * Names = new TStringList();
- try
- {
- if (Source->OpenSubKey(ConfigurationSubKey, false))
- {
- if (Target->OpenSubKey(ConfigurationSubKey, true))
- {
- if (Source->OpenSubKey("CDCache", false))
- {
- if (Target->OpenSubKey("CDCache", true))
- {
- Names->Clear();
- Source->GetValueNames(Names);
- for (int Index = 0; Index < Names->Count; Index++)
- {
- Target->WriteBinaryData(Names->Strings[Index],
- Source->ReadBinaryData(Names->Strings[Index]));
- }
- Target->CloseSubKey();
- }
- Source->CloseSubKey();
- }
- if (Source->OpenSubKey("Banners", false))
- {
- if (Target->OpenSubKey("Banners", true))
- {
- Names->Clear();
- Source->GetValueNames(Names);
- for (int Index = 0; Index < Names->Count; Index++)
- {
- Target->WriteString(Names->Strings[Index],
- Source->ReadString(Names->Strings[Index], ""));
- }
- Target->CloseSubKey();
- }
- Source->CloseSubKey();
- }
- Target->CloseSubKey();
- }
- Source->CloseSubKey();
- }
- if (Source->OpenSubKey(SshHostKeysSubKey, false))
- {
- if (Target->OpenSubKey(SshHostKeysSubKey, true))
- {
- Names->Clear();
- Source->GetValueNames(Names);
- for (int Index = 0; Index < Names->Count; Index++)
- {
- Target->WriteStringRaw(Names->Strings[Index],
- Source->ReadStringRaw(Names->Strings[Index], ""));
- }
- Target->CloseSubKey();
- }
- Source->CloseSubKey();
- }
- }
- __finally
- {
- delete Names;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::LoadDirectoryChangesCache(const AnsiString SessionKey,
- TRemoteDirectoryChangesCache * DirectoryChangesCache)
- {
- THierarchicalStorage * Storage = CreateScpStorage(false);
- try
- {
- Storage->AccessMode = smRead;
- if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
- Storage->OpenSubKey("CDCache", false) &&
- Storage->ValueExists(SessionKey))
- {
- DirectoryChangesCache->Deserialize(Storage->ReadBinaryData(SessionKey));
- }
- }
- __finally
- {
- delete Storage;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SaveDirectoryChangesCache(const AnsiString SessionKey,
- TRemoteDirectoryChangesCache * DirectoryChangesCache)
- {
- THierarchicalStorage * Storage = CreateScpStorage(false);
- try
- {
- Storage->AccessMode = smReadWrite;
- if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
- Storage->OpenSubKey("CDCache", true))
- {
- AnsiString Data;
- DirectoryChangesCache->Serialize(Data);
- Storage->WriteBinaryData(SessionKey, Data);
- }
- }
- __finally
- {
- delete Storage;
- }
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::BannerHash(const AnsiString & Banner)
- {
- AnsiString Result;
- Result.SetLength(16);
- md5checksum(Banner.c_str(), Banner.Length(), (unsigned char*)Result.c_str());
- return Result;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TConfiguration::ShowBanner(const AnsiString SessionKey,
- const AnsiString & Banner)
- {
- bool Result;
- THierarchicalStorage * Storage = CreateScpStorage(false);
- try
- {
- Storage->AccessMode = smRead;
- Result =
- !Storage->OpenSubKey(ConfigurationSubKey, false) ||
- !Storage->OpenSubKey("Banners", false) ||
- !Storage->ValueExists(SessionKey) ||
- (Storage->ReadString(SessionKey, "") != StrToHex(BannerHash(Banner)));
- }
- __finally
- {
- delete Storage;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::NeverShowBanner(const AnsiString SessionKey,
- const AnsiString & Banner)
- {
- THierarchicalStorage * Storage = CreateScpStorage(false);
- try
- {
- Storage->AccessMode = smReadWrite;
- if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
- Storage->OpenSubKey("Banners", true))
- {
- Storage->WriteString(SessionKey, StrToHex(BannerHash(Banner)));
- }
- }
- __finally
- {
- delete Storage;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::Changed()
- {
- if (FUpdating == 0)
- {
- if (OnChange)
- {
- OnChange(this);
- }
- }
- else
- {
- FChanged = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::BeginUpdate()
- {
- if (FUpdating == 0)
- {
- FChanged = false;
- }
- FUpdating++;
- // Greater value would probably indicate some nesting problem in code
- assert(FUpdating < 6);
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::EndUpdate()
- {
- assert(FUpdating > 0);
- FUpdating--;
- if ((FUpdating == 0) && FChanged)
- {
- FChanged = false;
- Changed();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::CleanupConfiguration()
- {
- try
- {
- CleanupRegistry(ConfigurationSubKey);
- if (Storage == stRegistry)
- {
- FDontSave = true;
- }
- }
- catch (Exception &E)
- {
- throw ExtException(&E, CLEANUP_CONFIG_ERROR);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::CleanupRegistry(AnsiString CleanupSubKey)
- {
- TRegistryStorage *Registry = new TRegistryStorage(RegistryStorageKey);
- try
- {
- Registry->RecursiveDeleteSubKey(CleanupSubKey);
- }
- __finally
- {
- delete Registry;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::CleanupHostKeys()
- {
- try
- {
- CleanupRegistry(SshHostKeysSubKey);
- }
- catch (Exception &E)
- {
- throw ExtException(&E, CLEANUP_HOSTKEYS_ERROR);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::CleanupRandomSeedFile()
- {
- try
- {
- DontSaveRandomSeed();
- AnsiString ExpandedRandomSeedFile = ExpandEnvironmentVariables(RandomSeedFile);
- if (FileExists(ExpandedRandomSeedFile))
- {
- if (!DeleteFile(ExpandedRandomSeedFile)) Abort();
- }
- }
- catch (Exception &E)
- {
- throw ExtException(&E, CLEANUP_SEEDFILE_ERROR);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::CleanupIniFile()
- {
- try
- {
- if (FileExists(IniFileStorageName))
- {
- if (!DeleteFile(IniFileStorageName)) Abort();
- }
- if (Storage == stIniFile)
- {
- FDontSave = true;
- }
- }
- catch (Exception &E)
- {
- throw ExtException(&E, CLEANUP_INIFILE_ERROR);
- }
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetOSVersionStr()
- {
- AnsiString Result;
- OSVERSIONINFO OSVersionInfo;
- OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVersionInfo);
- if (GetVersionEx(&OSVersionInfo) != 0)
- {
- Result = FORMAT("%d.%d.%d %s", (int(OSVersionInfo.dwMajorVersion),
- int(OSVersionInfo.dwMinorVersion), int(OSVersionInfo.dwBuildNumber),
- OSVersionInfo.szCSDVersion)).Trim();
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- TVSFixedFileInfo *__fastcall TConfiguration::GetFixedApplicationInfo()
- {
- return GetFixedFileInfo(ApplicationInfo);
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::ModuleFileName()
- {
- return ParamStr(0);
- }
- //---------------------------------------------------------------------------
- void * __fastcall TConfiguration::GetFileApplicationInfo(const AnsiString FileName)
- {
- void * Result;
- if (FileName.IsEmpty())
- {
- if (!FApplicationInfo)
- {
- FApplicationInfo = CreateFileInfo(ModuleFileName());
- }
- Result = FApplicationInfo;
- }
- else
- {
- Result = CreateFileInfo(FileName);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void * __fastcall TConfiguration::GetApplicationInfo()
- {
- return GetFileApplicationInfo("");
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetFileProductName(const AnsiString FileName)
- {
- return GetFileFileInfoString("ProductName", FileName);
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetFileCompanyName(const AnsiString FileName)
- {
- return GetFileFileInfoString("CompanyName", FileName);
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetProductName()
- {
- return GetFileProductName("");
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetCompanyName()
- {
- return GetFileCompanyName("");
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetFileProductVersion(const AnsiString FileName)
- {
- return TrimVersion(GetFileFileInfoString("ProductVersion", FileName));
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetProductVersion()
- {
- return GetFileProductVersion("");
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::TrimVersion(AnsiString Version)
- {
- while ((Version.Pos(".") != Version.LastDelimiter(".")) &&
- (Version.SubString(Version.Length() - 1, 2) == ".0"))
- {
- Version.SetLength(Version.Length() - 2);
- }
- return Version;
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetVersionStr()
- {
- TGuard Guard(FCriticalSection);
- try
- {
- return FmtLoadStr(VERSION, ARRAYOFCONST((
- HIWORD(FixedApplicationInfo->dwFileVersionMS),
- LOWORD(FixedApplicationInfo->dwFileVersionMS),
- HIWORD(FixedApplicationInfo->dwFileVersionLS),
- LOWORD(FixedApplicationInfo->dwFileVersionLS))));
- }
- catch (Exception &E)
- {
- throw ExtException(&E, "Can't get application version");
- }
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetVersion()
- {
- TGuard Guard(FCriticalSection);
- try
- {
- AnsiString Result;
- Result = TrimVersion(FORMAT("%d.%d.%d", (
- HIWORD(FixedApplicationInfo->dwFileVersionMS),
- LOWORD(FixedApplicationInfo->dwFileVersionMS),
- HIWORD(FixedApplicationInfo->dwFileVersionLS))));
- return Result;
- }
- catch (Exception &E)
- {
- throw ExtException(&E, "Can't get application version");
- }
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetFileFileInfoString(const AnsiString Key,
- const AnsiString FileName)
- {
- TGuard Guard(FCriticalSection);
- AnsiString Result;
- void * Info = GetFileApplicationInfo(FileName);
- try
- {
- if ((Info != NULL) && (GetTranslationCount(Info) > 0))
- {
- TTranslation Translation;
- Translation = GetTranslation(Info, 0);
- Result = ::GetFileInfoString(Info, Translation, Key);
- }
- else
- {
- assert(!FileName.IsEmpty());
- }
- }
- __finally
- {
- if (!FileName.IsEmpty())
- {
- FreeFileInfo(Info);
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetFileInfoString(const AnsiString Key)
- {
- return GetFileFileInfoString(Key, "");
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetRegistryStorageKey()
- {
- return GetRegistryKey();
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetIniFileStorageName(AnsiString value)
- {
- FIniFileStorageName = value;
- FStorage = stIniFile;
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetIniFileStorageName()
- {
- if (FIniFileStorageName.IsEmpty())
- {
- return ChangeFileExt(ParamStr(0), ".ini");
- }
- else
- {
- return FIniFileStorageName;
- }
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetPuttyRegistryStorageKey()
- {
- return PUTTY_REG_POS;
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetPuttySessionsKey()
- {
- return PuttyRegistryStorageKey + "\\Sessions";
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetStoredSessionsSubKey()
- {
- return "Sessions";
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetSshHostKeysSubKey()
- {
- return "SshHostKeys";
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetConfigurationSubKey()
- {
- return "Configuration";
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetRootKeyStr()
- {
- return RootKeyToStr(HKEY_CURRENT_USER);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TConfiguration::GetGSSAPIInstalled()
- {
- return HasGSSAPI();
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetStorage(TStorage value)
- {
- if (FStorage != value)
- {
- THierarchicalStorage * SourceStorage = NULL;
- THierarchicalStorage * TargetStorage = NULL;
- try
- {
- SourceStorage = CreateScpStorage(false);
- SourceStorage->AccessMode = smRead;
- FStorage = value;
- TargetStorage = CreateScpStorage(false);
- TargetStorage->AccessMode = smReadWrite;
- // copy before save as it removes the ini file,
- // when switching from ini to registry
- CopyData(SourceStorage, TargetStorage);
- }
- __finally
- {
- delete SourceStorage;
- delete TargetStorage;
- }
- Save(true);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::Saved()
- {
- // nothing
- }
- //---------------------------------------------------------------------------
- TStorage __fastcall TConfiguration::GetStorage()
- {
- if (FStorage == stDetect)
- {
- FStorage = FileExists(IniFileStorageName) ? stIniFile : stRegistry;
- }
- return FStorage;
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetRandomSeedFile(AnsiString value)
- {
- if (RandomSeedFile != value)
- {
- // never allow empty seed file to avoid Putty trying to reinitialize the path
- if (value.Trim().IsEmpty())
- {
- FRandomSeedFile = FDefaultRandomSeedFile;
- }
- else
- {
- FRandomSeedFile = value;
- }
- char *seedpath = seedpath_ptr();
- if (value.Length() >= seedpath_size())
- {
- value.SetLength(seedpath_size() - 1);
- }
- strcpy(seedpath, StripPathQuotes(ExpandEnvironmentVariables(FRandomSeedFile)).c_str());
- }
- }
- //---------------------------------------------------------------------------
- TEOLType __fastcall TConfiguration::GetLocalEOLType()
- {
- return eolCRLF;
- }
- //---------------------------------------------------------------------
- void __fastcall TConfiguration::TemporaryLogging(const AnsiString ALogFileName)
- {
- FLogging = true;
- FLogFileName = ALogFileName;
- }
- //---------------------------------------------------------------------
- void __fastcall TConfiguration::SetLogging(bool value)
- {
- if (Logging != value)
- {
- FPermanentLogging = value;
- FLogging = value;
- Changed();
- }
- }
- //---------------------------------------------------------------------
- void __fastcall TConfiguration::SetLogFileName(AnsiString value)
- {
- if (LogFileName != value)
- {
- FPermanentLogFileName = value;
- FLogFileName = value;
- Changed();
- }
- }
- //---------------------------------------------------------------------
- void __fastcall TConfiguration::SetLogToFile(bool value)
- {
- if (value != LogToFile)
- {
- LogFileName = value ? DefaultLogFileName : AnsiString("");
- Changed();
- }
- }
- //---------------------------------------------------------------------
- bool __fastcall TConfiguration::GetLogToFile()
- {
- return !LogFileName.IsEmpty();
- }
- //---------------------------------------------------------------------
- void __fastcall TConfiguration::SetLogProtocol(int value)
- {
- SET_CONFIG_PROPERTY(LogProtocol);
- }
- //---------------------------------------------------------------------
- void __fastcall TConfiguration::SetLogFileAppend(bool value)
- {
- SET_CONFIG_PROPERTY(LogFileAppend);
- }
- //---------------------------------------------------------------------
- void __fastcall TConfiguration::SetLogWindowLines(int value)
- {
- SET_CONFIG_PROPERTY(LogWindowLines);
- }
- //---------------------------------------------------------------------
- void __fastcall TConfiguration::SetLogWindowComplete(bool value)
- {
- if (value != LogWindowComplete)
- {
- LogWindowLines = value ? 0 : 50;
- Changed();
- }
- }
- //---------------------------------------------------------------------
- bool __fastcall TConfiguration::GetLogWindowComplete()
- {
- return (bool)(LogWindowLines == 0);
- }
- //---------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetDefaultLogFileName()
- {
- return IncludeTrailingBackslash(SystemTemporaryDirectory()) + "winscp.log";
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetConfirmOverwriting(bool value)
- {
- TGuard Guard(FCriticalSection);
- SET_CONFIG_PROPERTY(ConfirmOverwriting);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TConfiguration::GetConfirmOverwriting()
- {
- TGuard Guard(FCriticalSection);
- return FConfirmOverwriting;
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetConfirmResume(bool value)
- {
- TGuard Guard(FCriticalSection);
- SET_CONFIG_PROPERTY(ConfirmResume);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TConfiguration::GetConfirmResume()
- {
- TGuard Guard(FCriticalSection);
- return FConfirmResume;
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetAutoReadDirectoryAfterOp(bool value)
- {
- TGuard Guard(FCriticalSection);
- SET_CONFIG_PROPERTY(AutoReadDirectoryAfterOp);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TConfiguration::GetAutoReadDirectoryAfterOp()
- {
- TGuard Guard(FCriticalSection);
- return FAutoReadDirectoryAfterOp;
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetTimeFormat()
- {
- return "h:nn:ss";
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetPartialExt() const
- {
- return PARTIAL_EXT;
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetDefaultKeyFile()
- {
- return "";
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TConfiguration::GetLocalInvalidChars()
- {
- return "/\\:*?\"<>|";
- }
- //---------------------------------------------------------------------------
- bool __fastcall TConfiguration::GetRememberPassword()
- {
- return false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetSessionReopenAuto(int value)
- {
- SET_CONFIG_PROPERTY(SessionReopenAuto);
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetSessionReopenBackground(int value)
- {
- SET_CONFIG_PROPERTY(SessionReopenBackground);
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetTunnelLocalPortNumberLow(int value)
- {
- SET_CONFIG_PROPERTY(TunnelLocalPortNumberLow);
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetTunnelLocalPortNumberHigh(int value)
- {
- SET_CONFIG_PROPERTY(TunnelLocalPortNumberHigh);
- }
- //---------------------------------------------------------------------------
- void __fastcall TConfiguration::SetShowFtpWelcomeMessage(bool value)
- {
- SET_CONFIG_PROPERTY(ShowFtpWelcomeMessage);
- }
|