1
0

Configuration.cpp 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <FileInfo.h>
  5. #include "Common.h"
  6. #include "Exceptions.h"
  7. #include "Configuration.h"
  8. #include "PuttyIntf.h"
  9. #include "TextsCore.h"
  10. #include "Interface.h"
  11. #include "CoreMain.h"
  12. #include "Security.h"
  13. #include "FileMasks.h"
  14. #include <shlobj.h>
  15. #include <System.IOUtils.hpp>
  16. #include <System.StrUtils.hpp>
  17. //---------------------------------------------------------------------------
  18. #pragma package(smart_init)
  19. //---------------------------------------------------------------------------
  20. const wchar_t * AutoSwitchNames = L"On;Off;Auto";
  21. const wchar_t * NotAutoSwitchNames = L"Off;On;Auto";
  22. //---------------------------------------------------------------------------
  23. // See https://www.iana.org/assignments/hash-function-text-names/hash-function-text-names.xhtml
  24. const UnicodeString Sha1ChecksumAlg(L"sha-1");
  25. const UnicodeString Sha224ChecksumAlg(L"sha-224");
  26. const UnicodeString Sha256ChecksumAlg(L"sha-256");
  27. const UnicodeString Sha384ChecksumAlg(L"sha-384");
  28. const UnicodeString Sha512ChecksumAlg(L"sha-512");
  29. const UnicodeString Md5ChecksumAlg(L"md5");
  30. // Not defined by IANA
  31. const UnicodeString Crc32ChecksumAlg(L"crc32");
  32. //---------------------------------------------------------------------------
  33. const UnicodeString SshFingerprintType(L"ssh");
  34. const UnicodeString TlsFingerprintType(L"tls");
  35. //---------------------------------------------------------------------------
  36. const UnicodeString HttpsCertificateStorageKey(L"HttpsCertificates");
  37. //---------------------------------------------------------------------------
  38. __fastcall TConfiguration::TConfiguration()
  39. {
  40. FCriticalSection = new TCriticalSection();
  41. FUpdating = 0;
  42. FStorage = stDetect;
  43. FDontSave = false;
  44. FApplicationInfo = NULL;
  45. FUsage = new TUsage(this);
  46. FDefaultCollectUsage = false;
  47. FScripting = false;
  48. UnicodeString RandomSeedPath;
  49. if (!GetEnvironmentVariable(L"APPDATA").IsEmpty())
  50. {
  51. RandomSeedPath = L"%APPDATA%";
  52. }
  53. else
  54. {
  55. RandomSeedPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA);
  56. if (RandomSeedPath.IsEmpty())
  57. {
  58. RandomSeedPath = GetShellFolderPath(CSIDL_APPDATA);
  59. }
  60. }
  61. FDefaultRandomSeedFile = IncludeTrailingBackslash(RandomSeedPath) + L"winscp.rnd";
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TConfiguration::Default()
  65. {
  66. TGuard Guard(FCriticalSection);
  67. FDisablePasswordStoring = false;
  68. FForceBanners = false;
  69. FDisableAcceptingHostKeys = false;
  70. TRegistryStorage * AdminStorage;
  71. AdminStorage = new TRegistryStorage(RegistryStorageKey, HKEY_LOCAL_MACHINE);
  72. try
  73. {
  74. if (AdminStorage->OpenRootKey(false))
  75. {
  76. LoadAdmin(AdminStorage);
  77. AdminStorage->CloseSubKey();
  78. }
  79. }
  80. __finally
  81. {
  82. delete AdminStorage;
  83. }
  84. RandomSeedFile = FDefaultRandomSeedFile;
  85. PuttyRegistryStorageKey = OriginalPuttyRegistryStorageKey;
  86. FConfirmOverwriting = true;
  87. FConfirmResume = true;
  88. FAutoReadDirectoryAfterOp = true;
  89. FSessionReopenAuto = 5000;
  90. FSessionReopenBackground = 2000;
  91. FSessionReopenTimeout = 0;
  92. FSessionReopenAutoStall = 60000;
  93. FTunnelLocalPortNumberLow = 50000;
  94. FTunnelLocalPortNumberHigh = 50099;
  95. FCacheDirectoryChangesMaxSize = 100;
  96. FShowFtpWelcomeMessage = false;
  97. FExternalIpAddress = L"";
  98. FTryFtpWhenSshFails = true;
  99. FParallelDurationThreshold = 10;
  100. FMimeTypes = UnicodeString();
  101. FDontReloadMoreThanSessions = 1000;
  102. CollectUsage = FDefaultCollectUsage;
  103. FLogging = false;
  104. FPermanentLogging = false;
  105. FLogFileName = DefaultLogFileName;
  106. FPermanentLogFileName = FLogFileName;
  107. FLogFileAppend = true;
  108. FLogSensitive = false;
  109. FPermanentLogSensitive = FLogSensitive;
  110. FLogMaxSize = 0;
  111. FPermanentLogMaxSize = FLogMaxSize;
  112. FLogMaxCount = 0;
  113. FPermanentLogMaxCount = FLogMaxCount;
  114. FLogProtocol = 0;
  115. FPermanentLogProtocol = FLogProtocol;
  116. UpdateActualLogProtocol();
  117. FLogActions = false;
  118. FPermanentLogActions = false;
  119. FLogActionsRequired = false;
  120. FActionsLogFileName = L"%TEMP%\\!S.xml";
  121. FPermanentActionsLogFileName = FActionsLogFileName;
  122. FProgramIniPathWrittable = -1;
  123. FCustomIniFileStorageName = LoadCustomIniFileStorageName();
  124. Changed();
  125. }
  126. //---------------------------------------------------------------------------
  127. __fastcall TConfiguration::~TConfiguration()
  128. {
  129. DebugAssert(!FUpdating);
  130. if (FApplicationInfo) FreeFileInfo(FApplicationInfo);
  131. delete FCriticalSection;
  132. delete FUsage;
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TConfiguration::UpdateStaticUsage()
  136. {
  137. Usage->Set(L"ConfigurationIniFile", (Storage == stIniFile));
  138. Usage->Set(L"ConfigurationIniFileCustom", !CustomIniFileStorageName.IsEmpty());
  139. Usage->Set("Unofficial", IsUnofficial);
  140. // this is called from here, because we are guarded from calling into
  141. // master password handler here, see TWinConfiguration::UpdateStaticUsage
  142. StoredSessions->UpdateStaticUsage();
  143. }
  144. //---------------------------------------------------------------------------
  145. THierarchicalStorage * TConfiguration::CreateConfigStorage()
  146. {
  147. bool SessionList = false;
  148. return CreateScpStorage(SessionList);
  149. }
  150. //---------------------------------------------------------------------------
  151. THierarchicalStorage * TConfiguration::CreateScpStorage(bool & SessionList)
  152. {
  153. TGuard Guard(FCriticalSection);
  154. THierarchicalStorage * Result;
  155. if (Storage == stRegistry)
  156. {
  157. Result = new TRegistryStorage(RegistryStorageKey);
  158. }
  159. else if (Storage == stNul)
  160. {
  161. Result = TIniFileStorage::CreateFromPath(INI_NUL);
  162. }
  163. else
  164. {
  165. UnicodeString StorageName = IniFileStorageName;
  166. Result = TIniFileStorage::CreateFromPath(StorageName);
  167. }
  168. if ((FOptionsStorage.get() != NULL) && (FOptionsStorage->Count > 0))
  169. {
  170. if (!SessionList)
  171. {
  172. Result = new TOptionsStorage(FOptionsStorage.get(), ConfigurationSubKey, Result);
  173. }
  174. else
  175. {
  176. // cannot reuse session list storage for configuration as for it we need
  177. // the option-override storage above
  178. }
  179. }
  180. else
  181. {
  182. // All the above stores can be reused for configuration,
  183. // if no options-overrides are set
  184. SessionList = false;
  185. }
  186. return Result;
  187. }
  188. //---------------------------------------------------------------------------
  189. UnicodeString __fastcall TConfiguration::PropertyToKey(const UnicodeString & Property)
  190. {
  191. // no longer useful
  192. int P = Property.LastDelimiter(L".>");
  193. return Property.SubString(P + 1, Property.Length() - P);
  194. }
  195. //---------------------------------------------------------------------------
  196. #define BLOCK(KEY, CANCREATE, BLOCK) \
  197. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  198. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  199. #define REGCONFIG(CANCREATE) \
  200. BLOCK(L"Interface", CANCREATE, \
  201. KEY(String, RandomSeedFile); \
  202. KEY(String, PuttyRegistryStorageKey); \
  203. KEY(Bool, ConfirmOverwriting); \
  204. KEY(Bool, ConfirmResume); \
  205. KEY(Bool, AutoReadDirectoryAfterOp); \
  206. KEY(Integer, SessionReopenAuto); \
  207. KEY(Integer, SessionReopenBackground); \
  208. KEY(Integer, SessionReopenTimeout); \
  209. KEY(Integer, SessionReopenAutoStall); \
  210. KEY(Integer, TunnelLocalPortNumberLow); \
  211. KEY(Integer, TunnelLocalPortNumberHigh); \
  212. KEY(Integer, CacheDirectoryChangesMaxSize); \
  213. KEY(Bool, ShowFtpWelcomeMessage); \
  214. KEY(String, ExternalIpAddress); \
  215. KEY(Bool, TryFtpWhenSshFails); \
  216. KEY(Integer, ParallelDurationThreshold); \
  217. KEY(String, MimeTypes); \
  218. KEY(Integer, DontReloadMoreThanSessions); \
  219. KEY(Bool, CollectUsage); \
  220. ); \
  221. BLOCK(L"Logging", CANCREATE, \
  222. KEYEX(Bool, PermanentLogging, L"Logging"); \
  223. KEYEX(String,PermanentLogFileName, L"LogFileName"); \
  224. KEY(Bool, LogFileAppend); \
  225. KEYEX(Bool, PermanentLogSensitive, L"LogSensitive"); \
  226. KEYEX(Int64, PermanentLogMaxSize, L"LogMaxSize"); \
  227. KEYEX(Integer, PermanentLogMaxCount, L"LogMaxCount"); \
  228. KEYEX(Integer,PermanentLogProtocol, L"LogProtocol"); \
  229. KEYEX(Bool, PermanentLogActions, L"LogActions"); \
  230. KEYEX(String,PermanentActionsLogFileName, L"ActionsLogFileName"); \
  231. );
  232. //---------------------------------------------------------------------------
  233. void __fastcall TConfiguration::SaveData(THierarchicalStorage * Storage, bool /*All*/)
  234. {
  235. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  236. REGCONFIG(true);
  237. #undef KEYEX
  238. if (Storage->OpenSubKey(L"Usage", true))
  239. {
  240. FUsage->Save(Storage);
  241. Storage->CloseSubKey();
  242. }
  243. }
  244. //---------------------------------------------------------------------------
  245. void __fastcall TConfiguration::Save()
  246. {
  247. // only modified, implicit
  248. DoSave(false, false);
  249. }
  250. //---------------------------------------------------------------------------
  251. void __fastcall TConfiguration::SaveExplicit()
  252. {
  253. // only modified, explicit
  254. DoSave(false, true);
  255. }
  256. //---------------------------------------------------------------------------
  257. void __fastcall TConfiguration::DoSave(bool All, bool Explicit)
  258. {
  259. if (FDontSave) return;
  260. THierarchicalStorage * AStorage = CreateConfigStorage();
  261. try
  262. {
  263. AStorage->AccessMode = smReadWrite;
  264. AStorage->Explicit = Explicit;
  265. if (AStorage->OpenSubKey(ConfigurationSubKey, true))
  266. {
  267. // if saving to TOptionsStorage, make sure we save everything so that
  268. // all configuration is properly transferred to the master storage
  269. bool ConfigAll = All || AStorage->Temporary;
  270. SaveData(AStorage, ConfigAll);
  271. }
  272. }
  273. __finally
  274. {
  275. delete AStorage;
  276. }
  277. Saved();
  278. if (All)
  279. {
  280. StoredSessions->Save(true, Explicit);
  281. }
  282. // clean up as last, so that if it fails (read only INI), the saving can proceed
  283. if (Storage == stRegistry)
  284. {
  285. CleanupIniFile();
  286. }
  287. SaveCustomIniFileStorageName();
  288. }
  289. //---------------------------------------------------------------------------
  290. void __fastcall TConfiguration::SaveCustomIniFileStorageName()
  291. {
  292. // Particularly, not to create an empty "Override" key, unless the custom INI file is ever set
  293. if (CustomIniFileStorageName != LoadCustomIniFileStorageName())
  294. {
  295. std::unique_ptr<TRegistryStorage> RegistryStorage(new TRegistryStorage(GetRegistryStorageOverrideKey()));
  296. RegistryStorage->AccessMode = smReadWrite;
  297. RegistryStorage->Explicit = true;
  298. if (RegistryStorage->OpenRootKey(true))
  299. {
  300. RegistryStorage->WriteString(L"IniFile", CustomIniFileStorageName);
  301. RegistryStorage->CloseSubKey();
  302. }
  303. }
  304. }
  305. //---------------------------------------------------------------------------
  306. void __fastcall TConfiguration::Export(const UnicodeString & FileName)
  307. {
  308. // not to "append" the export to an existing file
  309. if (FileExists(FileName))
  310. {
  311. DeleteFileChecked(FileName);
  312. }
  313. THierarchicalStorage * Storage = NULL;
  314. THierarchicalStorage * ExportStorage = NULL;
  315. try
  316. {
  317. ExportStorage = TIniFileStorage::CreateFromPath(FileName);
  318. ExportStorage->AccessMode = smReadWrite;
  319. ExportStorage->Explicit = true;
  320. Storage = CreateConfigStorage();
  321. Storage->AccessMode = smRead;
  322. CopyData(Storage, ExportStorage);
  323. if (ExportStorage->OpenSubKey(ConfigurationSubKey, true))
  324. {
  325. SaveData(ExportStorage, true);
  326. }
  327. }
  328. __finally
  329. {
  330. delete ExportStorage;
  331. delete Storage;
  332. }
  333. StoredSessions->Export(FileName);
  334. }
  335. //---------------------------------------------------------------------------
  336. void __fastcall TConfiguration::Import(const UnicodeString & FileName)
  337. {
  338. THierarchicalStorage * Storage = NULL;
  339. THierarchicalStorage * ImportStorage = NULL;
  340. try
  341. {
  342. ImportStorage = TIniFileStorage::CreateFromPath(FileName);
  343. ImportStorage->AccessMode = smRead;
  344. Storage = CreateConfigStorage();
  345. Storage->AccessMode = smReadWrite;
  346. Storage->Explicit = true;
  347. CopyData(ImportStorage, Storage);
  348. Default();
  349. LoadFrom(ImportStorage);
  350. if (ImportStorage->OpenSubKey(Configuration->StoredSessionsSubKey, false))
  351. {
  352. StoredSessions->Clear();
  353. StoredSessions->DefaultSettings->Default();
  354. StoredSessions->Load(ImportStorage);
  355. }
  356. }
  357. __finally
  358. {
  359. delete ImportStorage;
  360. delete Storage;
  361. }
  362. // save all and explicit
  363. DoSave(true, true);
  364. }
  365. //---------------------------------------------------------------------------
  366. void __fastcall TConfiguration::LoadData(THierarchicalStorage * Storage)
  367. {
  368. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  369. #pragma warn -eas
  370. REGCONFIG(false);
  371. #pragma warn +eas
  372. #undef KEYEX
  373. if (Storage->OpenSubKey(L"Usage", false))
  374. {
  375. FUsage->Load(Storage);
  376. Storage->CloseSubKey();
  377. }
  378. if (FPermanentLogActions && FPermanentActionsLogFileName.IsEmpty() &&
  379. FPermanentLogging && !FPermanentLogFileName.IsEmpty())
  380. {
  381. FPermanentActionsLogFileName = FPermanentLogFileName;
  382. FPermanentLogging = false;
  383. FPermanentLogFileName = L"";
  384. }
  385. }
  386. //---------------------------------------------------------------------------
  387. void __fastcall TConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  388. {
  389. FDisablePasswordStoring = Storage->ReadBool(L"DisablePasswordStoring", FDisablePasswordStoring);
  390. FForceBanners = Storage->ReadBool(L"ForceBanners", FForceBanners);
  391. FDisableAcceptingHostKeys = Storage->ReadBool(L"DisableAcceptingHostKeys", FDisableAcceptingHostKeys);
  392. FDefaultCollectUsage = Storage->ReadBool(L"DefaultCollectUsage", FDefaultCollectUsage);
  393. }
  394. //---------------------------------------------------------------------------
  395. void __fastcall TConfiguration::LoadFrom(THierarchicalStorage * Storage)
  396. {
  397. if (Storage->OpenSubKey(ConfigurationSubKey, false))
  398. {
  399. LoadData(Storage);
  400. Storage->CloseSubKey();
  401. }
  402. }
  403. //---------------------------------------------------------------------------
  404. UnicodeString __fastcall TConfiguration::GetRegistryStorageOverrideKey()
  405. {
  406. return GetRegistryStorageKey() + L" Override";
  407. }
  408. //---------------------------------------------------------------------------
  409. UnicodeString __fastcall TConfiguration::LoadCustomIniFileStorageName()
  410. {
  411. UnicodeString Result;
  412. std::unique_ptr<TRegistryStorage> RegistryStorage(new TRegistryStorage(GetRegistryStorageOverrideKey()));
  413. if (RegistryStorage->OpenRootKey(false))
  414. {
  415. Result = RegistryStorage->ReadString(L"IniFile", L"");
  416. RegistryStorage->CloseSubKey();
  417. }
  418. RegistryStorage.reset(NULL);
  419. return Result;
  420. }
  421. //---------------------------------------------------------------------------
  422. void __fastcall TConfiguration::Load(THierarchicalStorage * Storage)
  423. {
  424. TGuard Guard(FCriticalSection);
  425. TStorageAccessMode StorageAccessMode = Storage->AccessMode;
  426. try
  427. {
  428. Storage->AccessMode = smRead;
  429. LoadFrom(Storage);
  430. }
  431. __finally
  432. {
  433. Storage->AccessMode = StorageAccessMode;
  434. }
  435. }
  436. //---------------------------------------------------------------------------
  437. void __fastcall TConfiguration::CopyData(THierarchicalStorage * Source,
  438. THierarchicalStorage * Target)
  439. {
  440. TStrings * Names = new TStringList();
  441. try
  442. {
  443. if (Source->OpenSubKey(ConfigurationSubKey, false))
  444. {
  445. if (Target->OpenSubKey(ConfigurationSubKey, true))
  446. {
  447. if (Source->OpenSubKey(L"CDCache", false))
  448. {
  449. if (Target->OpenSubKey(L"CDCache", true))
  450. {
  451. Names->Clear();
  452. Source->GetValueNames(Names);
  453. for (int Index = 0; Index < Names->Count; Index++)
  454. {
  455. Target->WriteBinaryData(Names->Strings[Index],
  456. Source->ReadBinaryData(Names->Strings[Index]));
  457. }
  458. Target->CloseSubKey();
  459. }
  460. Source->CloseSubKey();
  461. }
  462. if (Source->OpenSubKey(L"Banners", false))
  463. {
  464. if (Target->OpenSubKey(L"Banners", true))
  465. {
  466. Names->Clear();
  467. Source->GetValueNames(Names);
  468. for (int Index = 0; Index < Names->Count; Index++)
  469. {
  470. Target->WriteString(Names->Strings[Index],
  471. Source->ReadString(Names->Strings[Index], L""));
  472. }
  473. Target->CloseSubKey();
  474. }
  475. Source->CloseSubKey();
  476. }
  477. Target->CloseSubKey();
  478. }
  479. Source->CloseSubKey();
  480. }
  481. if (Source->OpenSubKey(SshHostKeysSubKey, false))
  482. {
  483. if (Target->OpenSubKey(SshHostKeysSubKey, true))
  484. {
  485. Names->Clear();
  486. Source->GetValueNames(Names);
  487. for (int Index = 0; Index < Names->Count; Index++)
  488. {
  489. Target->WriteStringRaw(Names->Strings[Index],
  490. Source->ReadStringRaw(Names->Strings[Index], L""));
  491. }
  492. Target->CloseSubKey();
  493. }
  494. Source->CloseSubKey();
  495. }
  496. }
  497. __finally
  498. {
  499. delete Names;
  500. }
  501. }
  502. //---------------------------------------------------------------------------
  503. void __fastcall TConfiguration::LoadDirectoryChangesCache(const UnicodeString SessionKey,
  504. TRemoteDirectoryChangesCache * DirectoryChangesCache)
  505. {
  506. THierarchicalStorage * Storage = CreateConfigStorage();
  507. try
  508. {
  509. Storage->AccessMode = smRead;
  510. if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
  511. Storage->OpenSubKey(L"CDCache", false) &&
  512. Storage->ValueExists(SessionKey))
  513. {
  514. DirectoryChangesCache->Deserialize(Storage->ReadBinaryData(SessionKey));
  515. }
  516. }
  517. __finally
  518. {
  519. delete Storage;
  520. }
  521. }
  522. //---------------------------------------------------------------------------
  523. void __fastcall TConfiguration::SaveDirectoryChangesCache(const UnicodeString SessionKey,
  524. TRemoteDirectoryChangesCache * DirectoryChangesCache)
  525. {
  526. THierarchicalStorage * Storage = CreateConfigStorage();
  527. try
  528. {
  529. Storage->AccessMode = smReadWrite;
  530. if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
  531. Storage->OpenSubKey(L"CDCache", true))
  532. {
  533. UnicodeString Data;
  534. DirectoryChangesCache->Serialize(Data);
  535. Storage->WriteBinaryData(SessionKey, Data);
  536. }
  537. }
  538. __finally
  539. {
  540. delete Storage;
  541. }
  542. }
  543. //---------------------------------------------------------------------------
  544. UnicodeString __fastcall TConfiguration::BannerHash(const UnicodeString & Banner)
  545. {
  546. RawByteString Result;
  547. Result.SetLength(16);
  548. md5checksum(
  549. reinterpret_cast<const char*>(Banner.c_str()), Banner.Length() * sizeof(wchar_t),
  550. (unsigned char*)Result.c_str());
  551. return BytesToHex(Result);
  552. }
  553. //---------------------------------------------------------------------------
  554. void __fastcall TConfiguration::GetBannerData(
  555. const UnicodeString & SessionKey, UnicodeString & BannerHash, unsigned int & Params)
  556. {
  557. BannerHash = UnicodeString();
  558. Params = 0;
  559. std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
  560. Storage->AccessMode = smRead;
  561. if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
  562. Storage->OpenSubKey(L"Banners", false))
  563. {
  564. UnicodeString S = Storage->ReadString(SessionKey, L"");
  565. BannerHash = CutToChar(S, L',', true);
  566. Params = StrToIntDef(L"$" + CutToChar(S, L',', true), 0);
  567. }
  568. }
  569. //---------------------------------------------------------------------------
  570. bool __fastcall TConfiguration::ShowBanner(
  571. const UnicodeString & SessionKey, const UnicodeString & Banner, unsigned int & Params)
  572. {
  573. UnicodeString StoredBannerHash;
  574. GetBannerData(SessionKey, StoredBannerHash, Params);
  575. bool Result = (StoredBannerHash != BannerHash(Banner));
  576. return Result;
  577. }
  578. //---------------------------------------------------------------------------
  579. void __fastcall TConfiguration::SetBannerData(
  580. const UnicodeString & SessionKey, const UnicodeString & BannerHash, unsigned int Params)
  581. {
  582. std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
  583. Storage->AccessMode = smReadWrite;
  584. if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
  585. Storage->OpenSubKey(L"Banners", true))
  586. {
  587. Storage->WriteString(SessionKey, BannerHash + L"," + UIntToStr(Params));
  588. }
  589. }
  590. //---------------------------------------------------------------------------
  591. void __fastcall TConfiguration::NeverShowBanner(const UnicodeString & SessionKey, const UnicodeString & Banner)
  592. {
  593. UnicodeString DummyBannerHash;
  594. unsigned int Params;
  595. GetBannerData(SessionKey, DummyBannerHash, Params);
  596. SetBannerData(SessionKey, BannerHash(Banner), Params);
  597. }
  598. //---------------------------------------------------------------------------
  599. void __fastcall TConfiguration::SetBannerParams(const UnicodeString & SessionKey, unsigned int Params)
  600. {
  601. UnicodeString BannerHash;
  602. unsigned int DummyParams;
  603. GetBannerData(SessionKey, BannerHash, DummyParams);
  604. SetBannerData(SessionKey, BannerHash, Params);
  605. }
  606. //---------------------------------------------------------------------------
  607. UnicodeString __fastcall TConfiguration::FormatFingerprintKey(const UnicodeString & SiteKey, const UnicodeString & FingerprintType)
  608. {
  609. return FORMAT(L"%s:%s", (SiteKey, FingerprintType));
  610. }
  611. //---------------------------------------------------------------------------
  612. void __fastcall TConfiguration::RememberLastFingerprint(const UnicodeString & SiteKey, const UnicodeString & FingerprintType, const UnicodeString & Fingerprint)
  613. {
  614. std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
  615. Storage->AccessMode = smReadWrite;
  616. if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
  617. Storage->OpenSubKey(L"LastFingerprints", true))
  618. {
  619. UnicodeString FingerprintKey = FormatFingerprintKey(SiteKey, FingerprintType);
  620. Storage->WriteString(FingerprintKey, Fingerprint);
  621. }
  622. }
  623. //---------------------------------------------------------------------------
  624. UnicodeString __fastcall TConfiguration::LastFingerprint(const UnicodeString & SiteKey, const UnicodeString & FingerprintType)
  625. {
  626. UnicodeString Result;
  627. std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
  628. Storage->AccessMode = smRead;
  629. if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
  630. Storage->OpenSubKey(L"LastFingerprints", false))
  631. {
  632. UnicodeString FingerprintKey = FormatFingerprintKey(SiteKey, FingerprintType);
  633. Result = Storage->ReadString(FingerprintKey, L"");
  634. }
  635. return Result;
  636. }
  637. //---------------------------------------------------------------------------
  638. void __fastcall TConfiguration::Changed()
  639. {
  640. TNotifyEvent AOnChange = NULL;
  641. {
  642. TGuard Guard(FCriticalSection);
  643. if (FUpdating == 0)
  644. {
  645. AOnChange = OnChange;
  646. }
  647. else
  648. {
  649. FChanged = true;
  650. }
  651. }
  652. // No specific reason to call this outside of a guard, just that it is less of a change to a previous unguarded code
  653. if (AOnChange != NULL)
  654. {
  655. AOnChange(this);
  656. }
  657. }
  658. //---------------------------------------------------------------------------
  659. void __fastcall TConfiguration::BeginUpdate()
  660. {
  661. FCriticalSection->Enter();
  662. if (FUpdating == 0)
  663. {
  664. FChanged = false;
  665. }
  666. FUpdating++;
  667. // Greater value would probably indicate some nesting problem in code
  668. DebugAssert(FUpdating < 6);
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TConfiguration::EndUpdate()
  672. {
  673. DebugAssert(FUpdating > 0);
  674. FUpdating--;
  675. if ((FUpdating == 0) && FChanged)
  676. {
  677. FChanged = false;
  678. Changed();
  679. }
  680. FCriticalSection->Leave();
  681. }
  682. //---------------------------------------------------------------------------
  683. void __fastcall TConfiguration::CleanupConfiguration()
  684. {
  685. try
  686. {
  687. CleanupRegistry(ConfigurationSubKey);
  688. if (Storage == stRegistry)
  689. {
  690. FDontSave = true;
  691. }
  692. }
  693. catch (Exception &E)
  694. {
  695. throw ExtException(&E, LoadStr(CLEANUP_CONFIG_ERROR));
  696. }
  697. }
  698. //---------------------------------------------------------------------------
  699. void __fastcall TConfiguration::CleanupRegistry(UnicodeString CleanupSubKey)
  700. {
  701. TRegistryStorage *Registry = new TRegistryStorage(RegistryStorageKey);
  702. try
  703. {
  704. Registry->RecursiveDeleteSubKey(CleanupSubKey);
  705. }
  706. __finally
  707. {
  708. delete Registry;
  709. }
  710. }
  711. //---------------------------------------------------------------------------
  712. void __fastcall TConfiguration::CleanupHostKeys()
  713. {
  714. try
  715. {
  716. CleanupRegistry(SshHostKeysSubKey);
  717. }
  718. catch (Exception &E)
  719. {
  720. throw ExtException(&E, LoadStr(CLEANUP_HOSTKEYS_ERROR));
  721. }
  722. }
  723. //---------------------------------------------------------------------------
  724. void __fastcall TConfiguration::CleanupRandomSeedFile()
  725. {
  726. try
  727. {
  728. DontSaveRandomSeed();
  729. if (FileExists(ApiPath(RandomSeedFileName)))
  730. {
  731. DeleteFileChecked(RandomSeedFileName);
  732. }
  733. }
  734. catch (Exception &E)
  735. {
  736. throw ExtException(&E, LoadStr(CLEANUP_SEEDFILE_ERROR));
  737. }
  738. }
  739. //---------------------------------------------------------------------------
  740. void __fastcall TConfiguration::CleanupIniFile()
  741. {
  742. try
  743. {
  744. if (FileExists(ApiPath(IniFileStorageNameForReading)))
  745. {
  746. DeleteFileChecked(IniFileStorageNameForReading);
  747. }
  748. if (Storage == stIniFile)
  749. {
  750. FDontSave = true;
  751. }
  752. }
  753. catch (Exception &E)
  754. {
  755. throw ExtException(&E, LoadStr(CLEANUP_INIFILE_ERROR));
  756. }
  757. }
  758. //---------------------------------------------------------------------------
  759. void __fastcall TConfiguration::DontSave()
  760. {
  761. FDontSave = true;
  762. }
  763. //---------------------------------------------------------------------------
  764. RawByteString __fastcall TConfiguration::EncryptPassword(UnicodeString Password, UnicodeString Key)
  765. {
  766. if (Password.IsEmpty())
  767. {
  768. return RawByteString();
  769. }
  770. else
  771. {
  772. return ::EncryptPassword(Password, Key);
  773. }
  774. }
  775. //---------------------------------------------------------------------------
  776. UnicodeString __fastcall TConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
  777. {
  778. if (Password.IsEmpty())
  779. {
  780. return UnicodeString();
  781. }
  782. else
  783. {
  784. return ::DecryptPassword(Password, Key);
  785. }
  786. }
  787. //---------------------------------------------------------------------------
  788. RawByteString __fastcall TConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString /*Key*/)
  789. {
  790. return Password;
  791. }
  792. //---------------------------------------------------------------------------
  793. TVSFixedFileInfo *__fastcall TConfiguration::GetFixedApplicationInfo()
  794. {
  795. return GetFixedFileInfo(ApplicationInfo);
  796. }
  797. //---------------------------------------------------------------------------
  798. int __fastcall TConfiguration::GetCompoundVersion()
  799. {
  800. TVSFixedFileInfo * FileInfo = FixedApplicationInfo;
  801. return CalculateCompoundVersion(
  802. HIWORD(FileInfo->dwFileVersionMS), LOWORD(FileInfo->dwFileVersionMS),
  803. HIWORD(FileInfo->dwFileVersionLS), LOWORD(FileInfo->dwFileVersionLS));
  804. }
  805. //---------------------------------------------------------------------------
  806. UnicodeString __fastcall TConfiguration::ModuleFileName()
  807. {
  808. return ParamStr(0);
  809. }
  810. //---------------------------------------------------------------------------
  811. void * __fastcall TConfiguration::GetFileApplicationInfo(const UnicodeString FileName)
  812. {
  813. void * Result;
  814. if (FileName.IsEmpty())
  815. {
  816. if (!FApplicationInfo)
  817. {
  818. FApplicationInfo = CreateFileInfo(ModuleFileName());
  819. }
  820. Result = FApplicationInfo;
  821. }
  822. else
  823. {
  824. Result = CreateFileInfo(FileName);
  825. }
  826. return Result;
  827. }
  828. //---------------------------------------------------------------------------
  829. void * __fastcall TConfiguration::GetApplicationInfo()
  830. {
  831. return GetFileApplicationInfo("");
  832. }
  833. //---------------------------------------------------------------------------
  834. UnicodeString __fastcall TConfiguration::GetFileProductName(const UnicodeString FileName)
  835. {
  836. return GetFileFileInfoString(L"ProductName", FileName);
  837. }
  838. //---------------------------------------------------------------------------
  839. UnicodeString __fastcall TConfiguration::GetFileCompanyName(const UnicodeString FileName)
  840. {
  841. // particularly in IDE build, company name is empty
  842. return GetFileFileInfoString(L"CompanyName", FileName, true);
  843. }
  844. //---------------------------------------------------------------------------
  845. UnicodeString __fastcall TConfiguration::GetProductName()
  846. {
  847. return GetFileProductName(L"");
  848. }
  849. //---------------------------------------------------------------------------
  850. UnicodeString __fastcall TConfiguration::GetCompanyName()
  851. {
  852. return GetFileCompanyName(L"");
  853. }
  854. //---------------------------------------------------------------------------
  855. UnicodeString __fastcall TConfiguration::GetFileProductVersion(const UnicodeString FileName)
  856. {
  857. return TrimVersion(GetFileFileInfoString(L"ProductVersion", FileName));
  858. }
  859. //---------------------------------------------------------------------------
  860. UnicodeString __fastcall TConfiguration::GetFileDescription(const UnicodeString & FileName)
  861. {
  862. return GetFileFileInfoString(L"FileDescription", FileName);
  863. }
  864. //---------------------------------------------------------------------------
  865. UnicodeString __fastcall TConfiguration::GetProductVersion()
  866. {
  867. return GetFileProductVersion(L"");
  868. }
  869. //---------------------------------------------------------------------------
  870. UnicodeString __fastcall TConfiguration::GetReleaseType()
  871. {
  872. return GetFileInfoString(L"ReleaseType");
  873. }
  874. //---------------------------------------------------------------------------
  875. bool __fastcall TConfiguration::GetIsUnofficial()
  876. {
  877. #ifdef BUILD_OFFICIAL
  878. return false;
  879. #else
  880. return true;
  881. #endif
  882. }
  883. //---------------------------------------------------------------------------
  884. UnicodeString __fastcall TConfiguration::GetVersionStr()
  885. {
  886. TGuard Guard(FCriticalSection);
  887. try
  888. {
  889. UnicodeString BuildStr;
  890. if (!IsUnofficial)
  891. {
  892. BuildStr = LoadStr(VERSION_BUILD);
  893. }
  894. else
  895. {
  896. #ifdef _DEBUG
  897. BuildStr = LoadStr(VERSION_DEBUG_BUILD);
  898. #else
  899. BuildStr = LoadStr(VERSION_DEV_BUILD);
  900. #endif
  901. }
  902. int Build = LOWORD(FixedApplicationInfo->dwFileVersionLS);
  903. if (Build > 0)
  904. {
  905. BuildStr += L" " + IntToStr(Build);
  906. }
  907. #ifndef BUILD_OFFICIAL
  908. UnicodeString BuildDate = __DATE__;
  909. UnicodeString MonthStr = CutToChar(BuildDate, L' ', true);
  910. int Month = ParseShortEngMonthName(MonthStr);
  911. int Day = StrToInt(CutToChar(BuildDate, L' ', true));
  912. int Year = StrToInt(Trim(BuildDate));
  913. UnicodeString DateStr = FORMAT(L"%d-%2.2d-%2.2d", (Year, Month, Day));
  914. AddToList(BuildStr, DateStr, L" ");
  915. #endif
  916. UnicodeString FullVersion = Version;
  917. UnicodeString AReleaseType = GetReleaseType();
  918. if (DebugAlwaysTrue(!AReleaseType.IsEmpty()) &&
  919. !SameText(AReleaseType, L"stable") &&
  920. !SameText(AReleaseType, L"development"))
  921. {
  922. FullVersion += L" " + AReleaseType;
  923. }
  924. UnicodeString Result = FMTLOAD(VERSION2, (FullVersion, BuildStr));
  925. #ifndef BUILD_OFFICIAL
  926. Result += L" " + LoadStr(VERSION_DONT_DISTRIBUTE);
  927. #endif
  928. return Result;
  929. }
  930. catch (Exception &E)
  931. {
  932. throw ExtException(&E, L"Can't get application version");
  933. }
  934. }
  935. //---------------------------------------------------------------------------
  936. UnicodeString __fastcall TConfiguration::GetFileVersion(const UnicodeString & FileName)
  937. {
  938. UnicodeString Result;
  939. void * FileInfo = CreateFileInfo(FileName);
  940. try
  941. {
  942. Result = GetFileVersion(GetFixedFileInfo(FileInfo));
  943. }
  944. __finally
  945. {
  946. FreeFileInfo(FileInfo);
  947. }
  948. return Result;
  949. }
  950. //---------------------------------------------------------------------------
  951. UnicodeString __fastcall TConfiguration::GetFileVersion(TVSFixedFileInfo * Info)
  952. {
  953. TGuard Guard(FCriticalSection);
  954. try
  955. {
  956. UnicodeString Result =
  957. FormatVersion(
  958. HIWORD(Info->dwFileVersionMS),
  959. LOWORD(Info->dwFileVersionMS),
  960. HIWORD(Info->dwFileVersionLS));
  961. return Result;
  962. }
  963. catch (Exception &E)
  964. {
  965. throw ExtException(&E, L"Can't get file version");
  966. }
  967. }
  968. //---------------------------------------------------------------------------
  969. UnicodeString __fastcall TConfiguration::GetVersion()
  970. {
  971. return GetFileVersion(FixedApplicationInfo);
  972. }
  973. //---------------------------------------------------------------------------
  974. UnicodeString __fastcall TConfiguration::GetFileFileInfoString(const UnicodeString Key,
  975. const UnicodeString FileName, bool AllowEmpty)
  976. {
  977. TGuard Guard(FCriticalSection);
  978. UnicodeString Result;
  979. void * Info = GetFileApplicationInfo(FileName);
  980. try
  981. {
  982. if ((Info != NULL) && (GetTranslationCount(Info) > 0))
  983. {
  984. TTranslation Translation;
  985. Translation = GetTranslation(Info, 0);
  986. Result = ::GetFileInfoString(Info, Translation, Key, AllowEmpty);
  987. }
  988. else
  989. {
  990. DebugAssert(!FileName.IsEmpty());
  991. }
  992. }
  993. __finally
  994. {
  995. if (!FileName.IsEmpty())
  996. {
  997. FreeFileInfo(Info);
  998. }
  999. }
  1000. return Result;
  1001. }
  1002. //---------------------------------------------------------------------------
  1003. UnicodeString __fastcall TConfiguration::GetFileInfoString(const UnicodeString Key)
  1004. {
  1005. return GetFileFileInfoString(Key, L"");
  1006. }
  1007. //---------------------------------------------------------------------------
  1008. UnicodeString __fastcall TConfiguration::GetFileMimeType(const UnicodeString & FileName)
  1009. {
  1010. UnicodeString Result;
  1011. bool Found = false;
  1012. if (!MimeTypes.IsEmpty())
  1013. {
  1014. UnicodeString FileNameOnly = ExtractFileName(FileName);
  1015. UnicodeString AMimeTypes = MimeTypes;
  1016. while (!Found && !AMimeTypes.IsEmpty())
  1017. {
  1018. UnicodeString Token = CutToChar(AMimeTypes, L',', true);
  1019. UnicodeString MaskStr = CutToChar(Token, L'=', true);
  1020. TFileMasks Mask(MaskStr);
  1021. if (Mask.Matches(FileNameOnly))
  1022. {
  1023. Result = Token.Trim();
  1024. Found = true;
  1025. }
  1026. }
  1027. }
  1028. if (!Found) // allow an override to "no" Content-Type
  1029. {
  1030. Result = ::GetFileMimeType(FileName);
  1031. }
  1032. return Result;
  1033. }
  1034. //---------------------------------------------------------------------------
  1035. UnicodeString __fastcall TConfiguration::GetRegistryStorageKey()
  1036. {
  1037. return GetRegistryKey();
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. void __fastcall TConfiguration::SetNulStorage()
  1041. {
  1042. FStorage = stNul;
  1043. }
  1044. //---------------------------------------------------------------------------
  1045. void __fastcall TConfiguration::SetDefaultStorage()
  1046. {
  1047. FStorage = stDetect;
  1048. }
  1049. //---------------------------------------------------------------------------
  1050. void __fastcall TConfiguration::SetIniFileStorageName(UnicodeString value)
  1051. {
  1052. FIniFileStorageName = value;
  1053. FStorage = stIniFile;
  1054. }
  1055. //---------------------------------------------------------------------------
  1056. UnicodeString __fastcall TConfiguration::GetDefaultIniFileExportPath()
  1057. {
  1058. UnicodeString PersonalDirectory = GetPersonalFolder();
  1059. UnicodeString FileName = IncludeTrailingBackslash(PersonalDirectory) +
  1060. ExtractFileName(ExpandEnvironmentVariables(IniFileStorageName));
  1061. return FileName;
  1062. }
  1063. //---------------------------------------------------------------------------
  1064. UnicodeString __fastcall TConfiguration::GetIniFileStorageNameForReading()
  1065. {
  1066. return GetIniFileStorageName(true);
  1067. }
  1068. //---------------------------------------------------------------------------
  1069. UnicodeString __fastcall TConfiguration::GetIniFileStorageNameForReadingWriting()
  1070. {
  1071. return GetIniFileStorageName(false);
  1072. }
  1073. //---------------------------------------------------------------------------
  1074. UnicodeString __fastcall TConfiguration::GetAutomaticIniFileStorageName(bool ReadingOnly)
  1075. {
  1076. UnicodeString ProgramPath = ParamStr(0);
  1077. UnicodeString ProgramIniPath = ChangeFileExt(ProgramPath, L".ini");
  1078. UnicodeString IniPath;
  1079. if (FileExists(ApiPath(ProgramIniPath)))
  1080. {
  1081. IniPath = ProgramIniPath;
  1082. }
  1083. else
  1084. {
  1085. UnicodeString AppDataIniPath =
  1086. IncludeTrailingBackslash(GetShellFolderPath(CSIDL_APPDATA)) +
  1087. ExtractFileName(ProgramIniPath);
  1088. if (FileExists(ApiPath(AppDataIniPath)))
  1089. {
  1090. IniPath = AppDataIniPath;
  1091. }
  1092. else
  1093. {
  1094. // avoid expensive test if we are interested in existing files only
  1095. if (!ReadingOnly && (FProgramIniPathWrittable < 0))
  1096. {
  1097. UnicodeString ProgramDir = ExtractFilePath(ProgramPath);
  1098. FProgramIniPathWrittable = IsDirectoryWriteable(ProgramDir) ? 1 : 0;
  1099. }
  1100. // does not really matter what we return when < 0
  1101. IniPath = (FProgramIniPathWrittable == 0) ? AppDataIniPath : ProgramIniPath;
  1102. }
  1103. }
  1104. // BACKWARD COMPATIBILITY with 4.x
  1105. if (FVirtualIniFileStorageName.IsEmpty() &&
  1106. TPath::IsDriveRooted(IniPath))
  1107. {
  1108. UnicodeString LocalAppDataPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA);
  1109. // virtual store for non-system drives have a different virtual store,
  1110. // do not bother about them
  1111. if (TPath::IsDriveRooted(LocalAppDataPath) &&
  1112. SameText(ExtractFileDrive(IniPath), ExtractFileDrive(LocalAppDataPath)))
  1113. {
  1114. FVirtualIniFileStorageName =
  1115. IncludeTrailingBackslash(LocalAppDataPath) +
  1116. L"VirtualStore\\" +
  1117. IniPath.SubString(4, IniPath.Length() - 3);
  1118. }
  1119. }
  1120. if (!FVirtualIniFileStorageName.IsEmpty() &&
  1121. FileExists(ApiPath(FVirtualIniFileStorageName)))
  1122. {
  1123. return FVirtualIniFileStorageName;
  1124. }
  1125. else
  1126. {
  1127. return IniPath;
  1128. }
  1129. }
  1130. //---------------------------------------------------------------------------
  1131. UnicodeString __fastcall TConfiguration::GetIniFileStorageName(bool ReadingOnly)
  1132. {
  1133. UnicodeString Result;
  1134. if (!FIniFileStorageName.IsEmpty())
  1135. {
  1136. Result = FIniFileStorageName;
  1137. }
  1138. else if (!FCustomIniFileStorageName.IsEmpty())
  1139. {
  1140. Result = FCustomIniFileStorageName;
  1141. }
  1142. else
  1143. {
  1144. Result = GetAutomaticIniFileStorageName(ReadingOnly);
  1145. }
  1146. return Result;
  1147. }
  1148. //---------------------------------------------------------------------------
  1149. void __fastcall TConfiguration::SetOptionsStorage(TStrings * value)
  1150. {
  1151. TGuard Guard(FCriticalSection);
  1152. if (FOptionsStorage.get() == NULL)
  1153. {
  1154. FOptionsStorage.reset(new TStringList());
  1155. }
  1156. FOptionsStorage->AddStrings(value);
  1157. }
  1158. //---------------------------------------------------------------------------
  1159. TStrings * __fastcall TConfiguration::GetOptionsStorage()
  1160. {
  1161. return FOptionsStorage.get();
  1162. }
  1163. //---------------------------------------------------------------------------
  1164. UnicodeString __fastcall TConfiguration::GetPuttySessionsKey()
  1165. {
  1166. return PuttyRegistryStorageKey + L"\\Sessions";
  1167. }
  1168. //---------------------------------------------------------------------------
  1169. UnicodeString __fastcall TConfiguration::GetStoredSessionsSubKey()
  1170. {
  1171. return L"Sessions";
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. UnicodeString __fastcall TConfiguration::GetSshHostKeysSubKey()
  1175. {
  1176. return L"SshHostKeys";
  1177. }
  1178. //---------------------------------------------------------------------------
  1179. UnicodeString __fastcall TConfiguration::GetConfigurationSubKey()
  1180. {
  1181. return L"Configuration";
  1182. }
  1183. //---------------------------------------------------------------------------
  1184. UnicodeString __fastcall TConfiguration::GetRootKeyStr()
  1185. {
  1186. return RootKeyToStr(HKEY_CURRENT_USER);
  1187. }
  1188. //---------------------------------------------------------------------------
  1189. void __fastcall TConfiguration::MoveStorage(TStorage AStorage, const UnicodeString & ACustomIniFileStorageName)
  1190. {
  1191. if ((FStorage != AStorage) ||
  1192. !IsPathToSameFile(FCustomIniFileStorageName, ACustomIniFileStorageName))
  1193. {
  1194. TStorage StorageBak = FStorage;
  1195. UnicodeString CustomIniFileStorageNameBak = FCustomIniFileStorageName;
  1196. try
  1197. {
  1198. THierarchicalStorage * SourceStorage = NULL;
  1199. THierarchicalStorage * TargetStorage = NULL;
  1200. try
  1201. {
  1202. SourceStorage = CreateConfigStorage();
  1203. SourceStorage->AccessMode = smRead;
  1204. FStorage = AStorage;
  1205. FCustomIniFileStorageName = ACustomIniFileStorageName;
  1206. TargetStorage = CreateConfigStorage();
  1207. TargetStorage->AccessMode = smReadWrite;
  1208. TargetStorage->Explicit = true;
  1209. // copy before save as it removes the ini file,
  1210. // when switching from ini to registry
  1211. CopyData(SourceStorage, TargetStorage);
  1212. }
  1213. __finally
  1214. {
  1215. delete SourceStorage;
  1216. delete TargetStorage;
  1217. }
  1218. // save all and explicit,
  1219. // this also removes an INI file, when switching to registry storage
  1220. DoSave(true, true);
  1221. }
  1222. catch (...)
  1223. {
  1224. // If this fails, do not pretend that storage was switched.
  1225. // For instance:
  1226. // - When writing to an INI file fails (unlikely, as we fallback to user profile)
  1227. // - When removing INI file fails, when switching to registry
  1228. // (possible, when the INI file is in Program Files folder)
  1229. FStorage = StorageBak;
  1230. FCustomIniFileStorageName = CustomIniFileStorageNameBak;
  1231. throw;
  1232. }
  1233. }
  1234. }
  1235. //---------------------------------------------------------------------------
  1236. void __fastcall TConfiguration::ScheduleCustomIniFileStorageUse(const UnicodeString & ACustomIniFileStorageName)
  1237. {
  1238. FStorage = stIniFile;
  1239. FCustomIniFileStorageName = ACustomIniFileStorageName;
  1240. SaveCustomIniFileStorageName();
  1241. }
  1242. //---------------------------------------------------------------------------
  1243. void __fastcall TConfiguration::Saved()
  1244. {
  1245. // nothing
  1246. }
  1247. //---------------------------------------------------------------------------
  1248. TStorage __fastcall TConfiguration::GetStorage()
  1249. {
  1250. TGuard Guard(FCriticalSection);
  1251. if (FStorage == stDetect)
  1252. {
  1253. if (FileExists(ApiPath(IniFileStorageNameForReading)))
  1254. {
  1255. FStorage = stIniFile;
  1256. }
  1257. else
  1258. {
  1259. FStorage = stRegistry;
  1260. }
  1261. }
  1262. return FStorage;
  1263. }
  1264. //---------------------------------------------------------------------
  1265. TStoredSessionList * __fastcall TConfiguration::SelectFilezillaSessionsForImport(
  1266. TStoredSessionList * Sessions, UnicodeString & Error)
  1267. {
  1268. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1269. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1270. UnicodeString AppDataPath = GetShellFolderPath(CSIDL_APPDATA);
  1271. UnicodeString FilezillaSiteManagerFile =
  1272. IncludeTrailingBackslash(AppDataPath) + L"FileZilla\\sitemanager.xml";
  1273. UnicodeString FilezillaConfigurationFile =
  1274. IncludeTrailingBackslash(AppDataPath) + L"FileZilla\\filezilla.xml";
  1275. if (FileExists(ApiPath(FilezillaSiteManagerFile)))
  1276. {
  1277. ImportSessionList->ImportFromFilezilla(FilezillaSiteManagerFile, FilezillaConfigurationFile);
  1278. if (ImportSessionList->Count > 0)
  1279. {
  1280. ImportSessionList->SelectSessionsToImport(Sessions, true);
  1281. }
  1282. else
  1283. {
  1284. Error = FMTLOAD(FILEZILLA_NO_SITES, (FilezillaSiteManagerFile));
  1285. }
  1286. }
  1287. else
  1288. {
  1289. Error = FMTLOAD(FILEZILLA_SITE_MANAGER_NOT_FOUND, (FilezillaSiteManagerFile));
  1290. }
  1291. return ImportSessionList.release();
  1292. }
  1293. //---------------------------------------------------------------------
  1294. bool __fastcall TConfiguration::AnyFilezillaSessionForImport(TStoredSessionList * Sessions)
  1295. {
  1296. try
  1297. {
  1298. UnicodeString Error;
  1299. std::unique_ptr<TStoredSessionList> Sesssions(SelectFilezillaSessionsForImport(Sessions, Error));
  1300. return (Sesssions->Count > 0);
  1301. }
  1302. catch (...)
  1303. {
  1304. return false;
  1305. }
  1306. }
  1307. //---------------------------------------------------------------------
  1308. TStoredSessionList * __fastcall TConfiguration::SelectKnownHostsSessionsForImport(
  1309. TStoredSessionList * Sessions, UnicodeString & Error)
  1310. {
  1311. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1312. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1313. UnicodeString ProfilePath = GetShellFolderPath(CSIDL_PROFILE);
  1314. UnicodeString KnownHostsFile = IncludeTrailingBackslash(ProfilePath) + L".ssh\\known_hosts";
  1315. try
  1316. {
  1317. if (FileExists(ApiPath(KnownHostsFile)))
  1318. {
  1319. std::unique_ptr<TStrings> Lines(new TStringList());
  1320. LoadScriptFromFile(KnownHostsFile, Lines.get());
  1321. ImportSessionList->ImportFromKnownHosts(Lines.get());
  1322. }
  1323. else
  1324. {
  1325. throw Exception(LoadStr(KNOWN_HOSTS_NOT_FOUND));
  1326. }
  1327. }
  1328. catch (Exception & E)
  1329. {
  1330. Error = FORMAT(L"%s\n(%s)", (E.Message, KnownHostsFile));
  1331. }
  1332. return ImportSessionList.release();
  1333. }
  1334. //---------------------------------------------------------------------
  1335. TStoredSessionList * __fastcall TConfiguration::SelectKnownHostsSessionsForImport(
  1336. TStrings * Lines, TStoredSessionList * Sessions, UnicodeString & Error)
  1337. {
  1338. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1339. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1340. try
  1341. {
  1342. ImportSessionList->ImportFromKnownHosts(Lines);
  1343. }
  1344. catch (Exception & E)
  1345. {
  1346. Error = E.Message;
  1347. }
  1348. return ImportSessionList.release();
  1349. }
  1350. //---------------------------------------------------------------------------
  1351. void __fastcall TConfiguration::SetRandomSeedFile(UnicodeString value)
  1352. {
  1353. if (RandomSeedFile != value)
  1354. {
  1355. UnicodeString PrevRandomSeedFileName = RandomSeedFileName;
  1356. FRandomSeedFile = value;
  1357. // never allow empty seed file to avoid Putty trying to reinitialize the path
  1358. if (RandomSeedFileName.IsEmpty())
  1359. {
  1360. FRandomSeedFile = FDefaultRandomSeedFile;
  1361. }
  1362. if (!PrevRandomSeedFileName.IsEmpty() &&
  1363. (PrevRandomSeedFileName != RandomSeedFileName) &&
  1364. FileExists(ApiPath(PrevRandomSeedFileName)))
  1365. {
  1366. // ignore any error
  1367. DeleteFile(ApiPath(PrevRandomSeedFileName));
  1368. }
  1369. }
  1370. }
  1371. //---------------------------------------------------------------------
  1372. UnicodeString __fastcall TConfiguration::GetRandomSeedFileName()
  1373. {
  1374. // StripPathQuotes should not be needed as we do not feed quotes anymore
  1375. return StripPathQuotes(ExpandEnvironmentVariables(FRandomSeedFile)).Trim();
  1376. }
  1377. //---------------------------------------------------------------------
  1378. void __fastcall TConfiguration::SetExternalIpAddress(UnicodeString value)
  1379. {
  1380. SET_CONFIG_PROPERTY(ExternalIpAddress);
  1381. }
  1382. //---------------------------------------------------------------------
  1383. void __fastcall TConfiguration::SetMimeTypes(UnicodeString value)
  1384. {
  1385. SET_CONFIG_PROPERTY(MimeTypes);
  1386. }
  1387. //---------------------------------------------------------------------
  1388. void __fastcall TConfiguration::SetTryFtpWhenSshFails(bool value)
  1389. {
  1390. SET_CONFIG_PROPERTY(TryFtpWhenSshFails);
  1391. }
  1392. //---------------------------------------------------------------------
  1393. void __fastcall TConfiguration::SetParallelDurationThreshold(int value)
  1394. {
  1395. SET_CONFIG_PROPERTY(ParallelDurationThreshold);
  1396. }
  1397. //---------------------------------------------------------------------
  1398. void __fastcall TConfiguration::SetPuttyRegistryStorageKey(UnicodeString value)
  1399. {
  1400. SET_CONFIG_PROPERTY(PuttyRegistryStorageKey);
  1401. }
  1402. //---------------------------------------------------------------------------
  1403. TEOLType __fastcall TConfiguration::GetLocalEOLType()
  1404. {
  1405. return eolCRLF;
  1406. }
  1407. //---------------------------------------------------------------------
  1408. bool __fastcall TConfiguration::GetCollectUsage()
  1409. {
  1410. return FUsage->Collect;
  1411. }
  1412. //---------------------------------------------------------------------
  1413. void __fastcall TConfiguration::SetCollectUsage(bool value)
  1414. {
  1415. FUsage->Collect = value;
  1416. }
  1417. //---------------------------------------------------------------------
  1418. void __fastcall TConfiguration::TemporaryLogging(const UnicodeString ALogFileName)
  1419. {
  1420. if (SameText(ExtractFileExt(ALogFileName), L".xml"))
  1421. {
  1422. TemporaryActionsLogging(ALogFileName);
  1423. }
  1424. else
  1425. {
  1426. FLogging = true;
  1427. FLogFileName = ALogFileName;
  1428. UpdateActualLogProtocol();
  1429. }
  1430. }
  1431. //---------------------------------------------------------------------
  1432. void __fastcall TConfiguration::TemporaryActionsLogging(const UnicodeString ALogFileName)
  1433. {
  1434. FLogActions = true;
  1435. FActionsLogFileName = ALogFileName;
  1436. }
  1437. //---------------------------------------------------------------------
  1438. void __fastcall TConfiguration::TemporaryLogProtocol(int ALogProtocol)
  1439. {
  1440. FLogProtocol = ALogProtocol;
  1441. UpdateActualLogProtocol();
  1442. }
  1443. //---------------------------------------------------------------------
  1444. void __fastcall TConfiguration::TemporaryLogSensitive(bool ALogSensitive)
  1445. {
  1446. FLogSensitive = ALogSensitive;
  1447. }
  1448. //---------------------------------------------------------------------
  1449. void __fastcall TConfiguration::TemporaryLogMaxSize(__int64 ALogMaxSize)
  1450. {
  1451. FLogMaxSize = ALogMaxSize;
  1452. }
  1453. //---------------------------------------------------------------------
  1454. void __fastcall TConfiguration::TemporaryLogMaxCount(int ALogMaxCount)
  1455. {
  1456. FLogMaxCount = ALogMaxCount;
  1457. }
  1458. //---------------------------------------------------------------------
  1459. void __fastcall TConfiguration::SetLogging(bool value)
  1460. {
  1461. TGuard Guard(FCriticalSection);
  1462. if (Logging != value)
  1463. {
  1464. FPermanentLogging = value;
  1465. FLogging = value;
  1466. UpdateActualLogProtocol();
  1467. Changed();
  1468. }
  1469. }
  1470. //---------------------------------------------------------------------
  1471. bool __fastcall TConfiguration::GetLogging()
  1472. {
  1473. TGuard Guard(FCriticalSection);
  1474. return FPermanentLogging;
  1475. }
  1476. //---------------------------------------------------------------------
  1477. void __fastcall TConfiguration::SetLogFileName(UnicodeString value)
  1478. {
  1479. TGuard Guard(FCriticalSection);
  1480. if (LogFileName != value)
  1481. {
  1482. FPermanentLogFileName = value;
  1483. FLogFileName = value;
  1484. Changed();
  1485. }
  1486. }
  1487. //---------------------------------------------------------------------
  1488. UnicodeString __fastcall TConfiguration::GetLogFileName()
  1489. {
  1490. TGuard Guard(FCriticalSection);
  1491. return FPermanentLogFileName;
  1492. }
  1493. //---------------------------------------------------------------------
  1494. void __fastcall TConfiguration::SetActionsLogFileName(UnicodeString value)
  1495. {
  1496. TGuard Guard(FCriticalSection);
  1497. if (ActionsLogFileName != value)
  1498. {
  1499. FPermanentActionsLogFileName = value;
  1500. FActionsLogFileName = value;
  1501. Changed();
  1502. }
  1503. }
  1504. //---------------------------------------------------------------------
  1505. UnicodeString __fastcall TConfiguration::GetPermanentActionsLogFileName()
  1506. {
  1507. TGuard Guard(FCriticalSection);
  1508. return FPermanentActionsLogFileName;
  1509. }
  1510. //---------------------------------------------------------------------
  1511. UnicodeString __fastcall TConfiguration::GetActionsLogFileName()
  1512. {
  1513. TGuard Guard(FCriticalSection);
  1514. return FActionsLogFileName;
  1515. }
  1516. //---------------------------------------------------------------------
  1517. bool __fastcall TConfiguration::GetLogToFile()
  1518. {
  1519. // guarded within GetLogFileName
  1520. return !LogFileName.IsEmpty();
  1521. }
  1522. //---------------------------------------------------------------------
  1523. void __fastcall TConfiguration::UpdateActualLogProtocol()
  1524. {
  1525. FActualLogProtocol = FLogging ? FLogProtocol : 0;
  1526. }
  1527. //---------------------------------------------------------------------
  1528. void __fastcall TConfiguration::SetLogProtocol(int value)
  1529. {
  1530. TGuard Guard(FCriticalSection);
  1531. if (LogProtocol != value)
  1532. {
  1533. FPermanentLogProtocol = value;
  1534. FLogProtocol = value;
  1535. Changed();
  1536. UpdateActualLogProtocol();
  1537. }
  1538. }
  1539. //---------------------------------------------------------------------
  1540. void __fastcall TConfiguration::SetLogActions(bool value)
  1541. {
  1542. TGuard Guard(FCriticalSection);
  1543. if (LogActions != value)
  1544. {
  1545. FPermanentLogActions = value;
  1546. FLogActions = value;
  1547. Changed();
  1548. }
  1549. }
  1550. //---------------------------------------------------------------------
  1551. bool __fastcall TConfiguration::GetLogActions()
  1552. {
  1553. TGuard Guard(FCriticalSection);
  1554. return FPermanentLogActions;
  1555. }
  1556. //---------------------------------------------------------------------
  1557. void __fastcall TConfiguration::SetLogFileAppend(bool value)
  1558. {
  1559. SET_CONFIG_PROPERTY(LogFileAppend);
  1560. }
  1561. //---------------------------------------------------------------------
  1562. void __fastcall TConfiguration::SetLogSensitive(bool value)
  1563. {
  1564. if (LogSensitive != value)
  1565. {
  1566. FPermanentLogSensitive = value;
  1567. FLogSensitive = value;
  1568. Changed();
  1569. }
  1570. }
  1571. //---------------------------------------------------------------------
  1572. void __fastcall TConfiguration::SetLogMaxSize(__int64 value)
  1573. {
  1574. TGuard Guard(FCriticalSection);
  1575. if (LogMaxSize != value)
  1576. {
  1577. FPermanentLogMaxSize = value;
  1578. FLogMaxSize = value;
  1579. Changed();
  1580. }
  1581. }
  1582. //---------------------------------------------------------------------
  1583. __int64 __fastcall TConfiguration::GetLogMaxSize()
  1584. {
  1585. TGuard Guard(FCriticalSection);
  1586. return FPermanentLogMaxSize;
  1587. }
  1588. //---------------------------------------------------------------------
  1589. void __fastcall TConfiguration::SetLogMaxCount(int value)
  1590. {
  1591. if (LogMaxCount != value)
  1592. {
  1593. FPermanentLogMaxCount = value;
  1594. FLogMaxCount = value;
  1595. Changed();
  1596. }
  1597. }
  1598. //---------------------------------------------------------------------
  1599. int __fastcall TConfiguration::GetLogMaxCount()
  1600. {
  1601. TGuard Guard(FCriticalSection);
  1602. return FPermanentLogMaxCount;
  1603. }
  1604. //---------------------------------------------------------------------
  1605. UnicodeString __fastcall TConfiguration::GetDefaultLogFileName()
  1606. {
  1607. return L"%TEMP%\\!S.log";
  1608. }
  1609. //---------------------------------------------------------------------------
  1610. void __fastcall TConfiguration::SetConfirmOverwriting(bool value)
  1611. {
  1612. TGuard Guard(FCriticalSection);
  1613. SET_CONFIG_PROPERTY(ConfirmOverwriting);
  1614. }
  1615. //---------------------------------------------------------------------------
  1616. bool __fastcall TConfiguration::GetConfirmOverwriting()
  1617. {
  1618. TGuard Guard(FCriticalSection);
  1619. return FConfirmOverwriting;
  1620. }
  1621. //---------------------------------------------------------------------------
  1622. void __fastcall TConfiguration::SetConfirmResume(bool value)
  1623. {
  1624. TGuard Guard(FCriticalSection);
  1625. SET_CONFIG_PROPERTY(ConfirmResume);
  1626. }
  1627. //---------------------------------------------------------------------------
  1628. bool __fastcall TConfiguration::GetConfirmResume()
  1629. {
  1630. TGuard Guard(FCriticalSection);
  1631. return FConfirmResume;
  1632. }
  1633. //---------------------------------------------------------------------------
  1634. void __fastcall TConfiguration::SetAutoReadDirectoryAfterOp(bool value)
  1635. {
  1636. TGuard Guard(FCriticalSection);
  1637. SET_CONFIG_PROPERTY(AutoReadDirectoryAfterOp);
  1638. }
  1639. //---------------------------------------------------------------------------
  1640. bool __fastcall TConfiguration::GetAutoReadDirectoryAfterOp()
  1641. {
  1642. TGuard Guard(FCriticalSection);
  1643. return FAutoReadDirectoryAfterOp;
  1644. }
  1645. //---------------------------------------------------------------------------
  1646. UnicodeString __fastcall TConfiguration::GetTimeFormat()
  1647. {
  1648. return L"h:nn:ss";
  1649. }
  1650. //---------------------------------------------------------------------------
  1651. UnicodeString __fastcall TConfiguration::GetPartialExt() const
  1652. {
  1653. return PARTIAL_EXT;
  1654. }
  1655. //---------------------------------------------------------------------------
  1656. UnicodeString __fastcall TConfiguration::GetDefaultKeyFile()
  1657. {
  1658. return L"";
  1659. }
  1660. //---------------------------------------------------------------------------
  1661. bool __fastcall TConfiguration::GetRememberPassword()
  1662. {
  1663. return false;
  1664. }
  1665. //---------------------------------------------------------------------------
  1666. void __fastcall TConfiguration::SetSessionReopenAuto(int value)
  1667. {
  1668. SET_CONFIG_PROPERTY(SessionReopenAuto);
  1669. }
  1670. //---------------------------------------------------------------------------
  1671. void __fastcall TConfiguration::SetSessionReopenBackground(int value)
  1672. {
  1673. SET_CONFIG_PROPERTY(SessionReopenBackground);
  1674. }
  1675. //---------------------------------------------------------------------------
  1676. void __fastcall TConfiguration::SetSessionReopenTimeout(int value)
  1677. {
  1678. SET_CONFIG_PROPERTY(SessionReopenTimeout);
  1679. }
  1680. //---------------------------------------------------------------------------
  1681. void __fastcall TConfiguration::SetSessionReopenAutoStall(int value)
  1682. {
  1683. SET_CONFIG_PROPERTY(SessionReopenAutoStall);
  1684. }
  1685. //---------------------------------------------------------------------------
  1686. void __fastcall TConfiguration::SetTunnelLocalPortNumberLow(int value)
  1687. {
  1688. SET_CONFIG_PROPERTY(TunnelLocalPortNumberLow);
  1689. }
  1690. //---------------------------------------------------------------------------
  1691. void __fastcall TConfiguration::SetTunnelLocalPortNumberHigh(int value)
  1692. {
  1693. SET_CONFIG_PROPERTY(TunnelLocalPortNumberHigh);
  1694. }
  1695. //---------------------------------------------------------------------------
  1696. void __fastcall TConfiguration::SetCacheDirectoryChangesMaxSize(int value)
  1697. {
  1698. SET_CONFIG_PROPERTY(CacheDirectoryChangesMaxSize);
  1699. }
  1700. //---------------------------------------------------------------------------
  1701. void __fastcall TConfiguration::SetShowFtpWelcomeMessage(bool value)
  1702. {
  1703. SET_CONFIG_PROPERTY(ShowFtpWelcomeMessage);
  1704. }
  1705. //---------------------------------------------------------------------------
  1706. bool __fastcall TConfiguration::GetPersistent()
  1707. {
  1708. return (Storage != stNul);
  1709. }
  1710. //---------------------------------------------------------------------------
  1711. //---------------------------------------------------------------------------
  1712. void __fastcall TShortCuts::Add(TShortCut ShortCut)
  1713. {
  1714. FShortCuts.insert(ShortCut);
  1715. }
  1716. //---------------------------------------------------------------------------
  1717. bool __fastcall TShortCuts::Has(TShortCut ShortCut) const
  1718. {
  1719. return (FShortCuts.count(ShortCut) != 0);
  1720. }