Configuration.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <FileInfo.h>
  5. #include "Exceptions.h"
  6. #include "Common.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 <shlobj.h>
  14. #include <System.IOUtils.hpp>
  15. //---------------------------------------------------------------------------
  16. #pragma package(smart_init)
  17. //---------------------------------------------------------------------------
  18. __fastcall TConfiguration::TConfiguration()
  19. {
  20. FCriticalSection = new TCriticalSection();
  21. FUpdating = 0;
  22. FStorage = stDetect;
  23. FDontSave = false;
  24. FApplicationInfo = NULL;
  25. FUsage = new TUsage(this);
  26. FDefaultCollectUsage = false;
  27. wchar_t Buf[10];
  28. UnicodeString RandomSeedPath;
  29. if (GetEnvironmentVariable(L"APPDATA", Buf, LENOF(Buf)) > 0)
  30. {
  31. RandomSeedPath = L"%APPDATA%";
  32. }
  33. else
  34. {
  35. RandomSeedPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA);
  36. if (RandomSeedPath.IsEmpty())
  37. {
  38. RandomSeedPath = GetShellFolderPath(CSIDL_APPDATA);
  39. }
  40. }
  41. FDefaultRandomSeedFile = IncludeTrailingBackslash(RandomSeedPath) + L"winscp.rnd";
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TConfiguration::Default()
  45. {
  46. TGuard Guard(FCriticalSection);
  47. FDisablePasswordStoring = false;
  48. FForceBanners = false;
  49. FDisableAcceptingHostKeys = false;
  50. TRegistryStorage * AdminStorage;
  51. AdminStorage = new TRegistryStorage(RegistryStorageKey, HKEY_LOCAL_MACHINE);
  52. try
  53. {
  54. if (AdminStorage->OpenRootKey(false))
  55. {
  56. LoadAdmin(AdminStorage);
  57. AdminStorage->CloseSubKey();
  58. }
  59. }
  60. __finally
  61. {
  62. delete AdminStorage;
  63. }
  64. RandomSeedFile = FDefaultRandomSeedFile;
  65. PuttyRegistryStorageKey = OriginalPuttyRegistryStorageKey;
  66. FConfirmOverwriting = true;
  67. FConfirmResume = true;
  68. FAutoReadDirectoryAfterOp = true;
  69. FSessionReopenAuto = 5000;
  70. FSessionReopenBackground = 2000;
  71. FSessionReopenTimeout = 0;
  72. FSessionReopenAutoStall = 60000;
  73. FTunnelLocalPortNumberLow = 50000;
  74. FTunnelLocalPortNumberHigh = 50099;
  75. FCacheDirectoryChangesMaxSize = 100;
  76. FShowFtpWelcomeMessage = false;
  77. FExternalIpAddress = L"";
  78. FTryFtpWhenSshFails = true;
  79. CollectUsage = FDefaultCollectUsage;
  80. FLogging = false;
  81. FPermanentLogging = false;
  82. FLogFileName = DefaultLogFileName;
  83. FPermanentLogFileName = FLogFileName;
  84. FLogFileAppend = true;
  85. FLogWindowLines = 100;
  86. FLogProtocol = 0;
  87. UpdateActualLogProtocol();
  88. FLogActions = false;
  89. FPermanentLogActions = false;
  90. FActionsLogFileName = L"%TEMP%\\!S.xml";
  91. FPermanentActionsLogFileName = FActionsLogFileName;
  92. FProgramIniPathWrittable = -1;
  93. Changed();
  94. }
  95. //---------------------------------------------------------------------------
  96. __fastcall TConfiguration::~TConfiguration()
  97. {
  98. assert(!FUpdating);
  99. if (FApplicationInfo) FreeFileInfo(FApplicationInfo);
  100. delete FCriticalSection;
  101. delete FUsage;
  102. }
  103. //---------------------------------------------------------------------------
  104. THierarchicalStorage * TConfiguration::CreateScpStorage(bool /*SessionList*/)
  105. {
  106. if (Storage == stRegistry)
  107. {
  108. return new TRegistryStorage(RegistryStorageKey);
  109. }
  110. else if (Storage == stNul)
  111. {
  112. return new TIniFileStorage(L"nul");
  113. }
  114. else
  115. {
  116. return new TIniFileStorage(IniFileStorageName);
  117. }
  118. }
  119. //---------------------------------------------------------------------------
  120. UnicodeString __fastcall TConfiguration::PropertyToKey(const UnicodeString & Property)
  121. {
  122. // no longer useful
  123. int P = Property.LastDelimiter(L".>");
  124. return Property.SubString(P + 1, Property.Length() - P);
  125. }
  126. //---------------------------------------------------------------------------
  127. #define BLOCK(KEY, CANCREATE, BLOCK) \
  128. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  129. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  130. #define REGCONFIG(CANCREATE) \
  131. BLOCK(L"Interface", CANCREATE, \
  132. KEY(String, RandomSeedFile); \
  133. KEY(String, PuttyRegistryStorageKey); \
  134. KEY(Bool, ConfirmOverwriting); \
  135. KEY(Bool, ConfirmResume); \
  136. KEY(Bool, AutoReadDirectoryAfterOp); \
  137. KEY(Integer, SessionReopenAuto); \
  138. KEY(Integer, SessionReopenBackground); \
  139. KEY(Integer, SessionReopenTimeout); \
  140. KEY(Integer, SessionReopenAutoStall); \
  141. KEY(Integer, TunnelLocalPortNumberLow); \
  142. KEY(Integer, TunnelLocalPortNumberHigh); \
  143. KEY(Integer, CacheDirectoryChangesMaxSize); \
  144. KEY(Bool, ShowFtpWelcomeMessage); \
  145. KEY(String, ExternalIpAddress); \
  146. KEY(Bool, TryFtpWhenSshFails); \
  147. KEY(Bool, CollectUsage); \
  148. ); \
  149. BLOCK(L"Logging", CANCREATE, \
  150. KEYEX(Bool, PermanentLogging, L"Logging"); \
  151. KEYEX(String,PermanentLogFileName, L"LogFileName"); \
  152. KEY(Bool, LogFileAppend); \
  153. KEY(Integer, LogWindowLines); \
  154. KEY(Integer, LogProtocol); \
  155. KEYEX(Bool, PermanentLogActions, L"LogActions"); \
  156. KEYEX(String,PermanentActionsLogFileName, L"ActionsLogFileName"); \
  157. );
  158. //---------------------------------------------------------------------------
  159. void __fastcall TConfiguration::SaveData(THierarchicalStorage * Storage, bool /*All*/)
  160. {
  161. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  162. REGCONFIG(true);
  163. #undef KEYEX
  164. if (Storage->OpenSubKey(L"Usage", true))
  165. {
  166. FUsage->Save(Storage);
  167. Storage->CloseSubKey();
  168. }
  169. }
  170. //---------------------------------------------------------------------------
  171. void __fastcall TConfiguration::Save()
  172. {
  173. // only modified, implicit
  174. DoSave(false, false);
  175. }
  176. //---------------------------------------------------------------------------
  177. void __fastcall TConfiguration::DoSave(bool All, bool Explicit)
  178. {
  179. if (FDontSave) return;
  180. THierarchicalStorage * AStorage = CreateScpStorage(false);
  181. try
  182. {
  183. AStorage->AccessMode = smReadWrite;
  184. AStorage->Explicit = Explicit;
  185. if (AStorage->OpenSubKey(ConfigurationSubKey, true))
  186. {
  187. SaveData(AStorage, All);
  188. }
  189. }
  190. __finally
  191. {
  192. delete AStorage;
  193. }
  194. Saved();
  195. if (All)
  196. {
  197. StoredSessions->Save(true, Explicit);
  198. }
  199. // clean up as last, so that if it fails (read only INI), the saving can proceed
  200. if (Storage == stRegistry)
  201. {
  202. CleanupIniFile();
  203. }
  204. }
  205. //---------------------------------------------------------------------------
  206. void __fastcall TConfiguration::Export(const UnicodeString & FileName)
  207. {
  208. THierarchicalStorage * Storage = NULL;
  209. THierarchicalStorage * ExportStorage = NULL;
  210. try
  211. {
  212. ExportStorage = new TIniFileStorage(FileName);
  213. ExportStorage->AccessMode = smReadWrite;
  214. ExportStorage->Explicit = true;
  215. Storage = CreateScpStorage(false);
  216. Storage->AccessMode = smRead;
  217. CopyData(Storage, ExportStorage);
  218. if (ExportStorage->OpenSubKey(ConfigurationSubKey, true))
  219. {
  220. SaveData(ExportStorage, true);
  221. }
  222. }
  223. __finally
  224. {
  225. delete ExportStorage;
  226. delete Storage;
  227. }
  228. StoredSessions->Export(FileName);
  229. }
  230. //---------------------------------------------------------------------------
  231. void __fastcall TConfiguration::Import(const UnicodeString & FileName)
  232. {
  233. THierarchicalStorage * Storage = NULL;
  234. THierarchicalStorage * ImportStorage = NULL;
  235. try
  236. {
  237. ImportStorage = new TIniFileStorage(FileName);
  238. ImportStorage->AccessMode = smRead;
  239. Storage = CreateScpStorage(false);
  240. Storage->AccessMode = smReadWrite;
  241. Storage->Explicit = true;
  242. CopyData(ImportStorage, Storage);
  243. Default();
  244. LoadFrom(ImportStorage);
  245. if (ImportStorage->OpenSubKey(Configuration->StoredSessionsSubKey, false))
  246. {
  247. StoredSessions->Clear();
  248. StoredSessions->DefaultSettings->Default();
  249. StoredSessions->Load(ImportStorage);
  250. }
  251. }
  252. __finally
  253. {
  254. delete ImportStorage;
  255. delete Storage;
  256. }
  257. // save all and explicit
  258. DoSave(true, true);
  259. }
  260. //---------------------------------------------------------------------------
  261. void __fastcall TConfiguration::LoadData(THierarchicalStorage * Storage)
  262. {
  263. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  264. #pragma warn -eas
  265. REGCONFIG(false);
  266. #pragma warn +eas
  267. #undef KEYEX
  268. if (Storage->OpenSubKey(L"Usage", false))
  269. {
  270. FUsage->Load(Storage);
  271. Storage->CloseSubKey();
  272. }
  273. if (FPermanentLogActions && FPermanentActionsLogFileName.IsEmpty() &&
  274. FPermanentLogging && !FPermanentLogFileName.IsEmpty())
  275. {
  276. FPermanentActionsLogFileName = FPermanentLogFileName;
  277. FPermanentLogging = false;
  278. FPermanentLogFileName = L"";
  279. }
  280. }
  281. //---------------------------------------------------------------------------
  282. void __fastcall TConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  283. {
  284. FDisablePasswordStoring = Storage->ReadBool(L"DisablePasswordStoring", FDisablePasswordStoring);
  285. FForceBanners = Storage->ReadBool(L"ForceBanners", FForceBanners);
  286. FDisableAcceptingHostKeys = Storage->ReadBool(L"DisableAcceptingHostKeys", FDisableAcceptingHostKeys);
  287. FDefaultCollectUsage = Storage->ReadBool(L"DefaultCollectUsage", FDefaultCollectUsage);
  288. }
  289. //---------------------------------------------------------------------------
  290. void __fastcall TConfiguration::LoadFrom(THierarchicalStorage * Storage)
  291. {
  292. if (Storage->OpenSubKey(ConfigurationSubKey, false))
  293. {
  294. LoadData(Storage);
  295. Storage->CloseSubKey();
  296. }
  297. }
  298. //---------------------------------------------------------------------------
  299. void __fastcall TConfiguration::Load()
  300. {
  301. TGuard Guard(FCriticalSection);
  302. THierarchicalStorage * Storage = CreateScpStorage(false);
  303. try
  304. {
  305. Storage->AccessMode = smRead;
  306. LoadFrom(Storage);
  307. }
  308. __finally
  309. {
  310. delete Storage;
  311. }
  312. }
  313. //---------------------------------------------------------------------------
  314. void __fastcall TConfiguration::CopyData(THierarchicalStorage * Source,
  315. THierarchicalStorage * Target)
  316. {
  317. TStrings * Names = new TStringList();
  318. try
  319. {
  320. if (Source->OpenSubKey(ConfigurationSubKey, false))
  321. {
  322. if (Target->OpenSubKey(ConfigurationSubKey, true))
  323. {
  324. if (Source->OpenSubKey(L"CDCache", false))
  325. {
  326. if (Target->OpenSubKey(L"CDCache", true))
  327. {
  328. Names->Clear();
  329. Source->GetValueNames(Names);
  330. for (int Index = 0; Index < Names->Count; Index++)
  331. {
  332. Target->WriteBinaryData(Names->Strings[Index],
  333. Source->ReadBinaryData(Names->Strings[Index]));
  334. }
  335. Target->CloseSubKey();
  336. }
  337. Source->CloseSubKey();
  338. }
  339. if (Source->OpenSubKey(L"Banners", false))
  340. {
  341. if (Target->OpenSubKey(L"Banners", true))
  342. {
  343. Names->Clear();
  344. Source->GetValueNames(Names);
  345. for (int Index = 0; Index < Names->Count; Index++)
  346. {
  347. Target->WriteString(Names->Strings[Index],
  348. Source->ReadString(Names->Strings[Index], L""));
  349. }
  350. Target->CloseSubKey();
  351. }
  352. Source->CloseSubKey();
  353. }
  354. Target->CloseSubKey();
  355. }
  356. Source->CloseSubKey();
  357. }
  358. if (Source->OpenSubKey(SshHostKeysSubKey, false))
  359. {
  360. if (Target->OpenSubKey(SshHostKeysSubKey, true))
  361. {
  362. Names->Clear();
  363. Source->GetValueNames(Names);
  364. for (int Index = 0; Index < Names->Count; Index++)
  365. {
  366. Target->WriteStringRaw(Names->Strings[Index],
  367. Source->ReadStringRaw(Names->Strings[Index], L""));
  368. }
  369. Target->CloseSubKey();
  370. }
  371. Source->CloseSubKey();
  372. }
  373. }
  374. __finally
  375. {
  376. delete Names;
  377. }
  378. }
  379. //---------------------------------------------------------------------------
  380. void __fastcall TConfiguration::LoadDirectoryChangesCache(const UnicodeString SessionKey,
  381. TRemoteDirectoryChangesCache * DirectoryChangesCache)
  382. {
  383. THierarchicalStorage * Storage = CreateScpStorage(false);
  384. try
  385. {
  386. Storage->AccessMode = smRead;
  387. if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
  388. Storage->OpenSubKey(L"CDCache", false) &&
  389. Storage->ValueExists(SessionKey))
  390. {
  391. DirectoryChangesCache->Deserialize(Storage->ReadBinaryData(SessionKey));
  392. }
  393. }
  394. __finally
  395. {
  396. delete Storage;
  397. }
  398. }
  399. //---------------------------------------------------------------------------
  400. void __fastcall TConfiguration::SaveDirectoryChangesCache(const UnicodeString SessionKey,
  401. TRemoteDirectoryChangesCache * DirectoryChangesCache)
  402. {
  403. THierarchicalStorage * Storage = CreateScpStorage(false);
  404. try
  405. {
  406. Storage->AccessMode = smReadWrite;
  407. if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
  408. Storage->OpenSubKey(L"CDCache", true))
  409. {
  410. UnicodeString Data;
  411. DirectoryChangesCache->Serialize(Data);
  412. Storage->WriteBinaryData(SessionKey, Data);
  413. }
  414. }
  415. __finally
  416. {
  417. delete Storage;
  418. }
  419. }
  420. //---------------------------------------------------------------------------
  421. UnicodeString __fastcall TConfiguration::BannerHash(const UnicodeString & Banner)
  422. {
  423. RawByteString Result;
  424. Result.SetLength(16);
  425. md5checksum(
  426. reinterpret_cast<const char*>(Banner.c_str()), Banner.Length() * sizeof(wchar_t),
  427. (unsigned char*)Result.c_str());
  428. return BytesToHex(Result);
  429. }
  430. //---------------------------------------------------------------------------
  431. bool __fastcall TConfiguration::ShowBanner(const UnicodeString SessionKey,
  432. const UnicodeString & Banner)
  433. {
  434. bool Result;
  435. THierarchicalStorage * Storage = CreateScpStorage(false);
  436. try
  437. {
  438. Storage->AccessMode = smRead;
  439. Result =
  440. !Storage->OpenSubKey(ConfigurationSubKey, false) ||
  441. !Storage->OpenSubKey(L"Banners", false) ||
  442. !Storage->ValueExists(SessionKey) ||
  443. (Storage->ReadString(SessionKey, L"") != BannerHash(Banner));
  444. }
  445. __finally
  446. {
  447. delete Storage;
  448. }
  449. return Result;
  450. }
  451. //---------------------------------------------------------------------------
  452. void __fastcall TConfiguration::NeverShowBanner(const UnicodeString SessionKey,
  453. const UnicodeString & Banner)
  454. {
  455. THierarchicalStorage * Storage = CreateScpStorage(false);
  456. try
  457. {
  458. Storage->AccessMode = smReadWrite;
  459. if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
  460. Storage->OpenSubKey(L"Banners", true))
  461. {
  462. Storage->WriteString(SessionKey, BannerHash(Banner));
  463. }
  464. }
  465. __finally
  466. {
  467. delete Storage;
  468. }
  469. }
  470. //---------------------------------------------------------------------------
  471. void __fastcall TConfiguration::Changed()
  472. {
  473. if (FUpdating == 0)
  474. {
  475. if (OnChange)
  476. {
  477. OnChange(this);
  478. }
  479. }
  480. else
  481. {
  482. FChanged = true;
  483. }
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TConfiguration::BeginUpdate()
  487. {
  488. if (FUpdating == 0)
  489. {
  490. FChanged = false;
  491. }
  492. FUpdating++;
  493. // Greater value would probably indicate some nesting problem in code
  494. assert(FUpdating < 6);
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TConfiguration::EndUpdate()
  498. {
  499. assert(FUpdating > 0);
  500. FUpdating--;
  501. if ((FUpdating == 0) && FChanged)
  502. {
  503. FChanged = false;
  504. Changed();
  505. }
  506. }
  507. //---------------------------------------------------------------------------
  508. void __fastcall TConfiguration::CleanupConfiguration()
  509. {
  510. try
  511. {
  512. CleanupRegistry(ConfigurationSubKey);
  513. if (Storage == stRegistry)
  514. {
  515. FDontSave = true;
  516. }
  517. }
  518. catch (Exception &E)
  519. {
  520. throw ExtException(&E, CLEANUP_CONFIG_ERROR);
  521. }
  522. }
  523. //---------------------------------------------------------------------------
  524. void __fastcall TConfiguration::CleanupRegistry(UnicodeString CleanupSubKey)
  525. {
  526. TRegistryStorage *Registry = new TRegistryStorage(RegistryStorageKey);
  527. try
  528. {
  529. Registry->RecursiveDeleteSubKey(CleanupSubKey);
  530. }
  531. __finally
  532. {
  533. delete Registry;
  534. }
  535. }
  536. //---------------------------------------------------------------------------
  537. void __fastcall TConfiguration::CleanupHostKeys()
  538. {
  539. try
  540. {
  541. CleanupRegistry(SshHostKeysSubKey);
  542. }
  543. catch (Exception &E)
  544. {
  545. throw ExtException(&E, CLEANUP_HOSTKEYS_ERROR);
  546. }
  547. }
  548. //---------------------------------------------------------------------------
  549. void __fastcall TConfiguration::CleanupRandomSeedFile()
  550. {
  551. try
  552. {
  553. DontSaveRandomSeed();
  554. if (FileExists(RandomSeedFileName))
  555. {
  556. if (!DeleteFile(RandomSeedFileName))
  557. {
  558. RaiseLastOSError();
  559. }
  560. }
  561. }
  562. catch (Exception &E)
  563. {
  564. throw ExtException(&E, CLEANUP_SEEDFILE_ERROR);
  565. }
  566. }
  567. //---------------------------------------------------------------------------
  568. void __fastcall TConfiguration::CleanupIniFile()
  569. {
  570. try
  571. {
  572. if (FileExists(IniFileStorageNameForReading))
  573. {
  574. if (!DeleteFile(IniFileStorageNameForReading))
  575. {
  576. RaiseLastOSError();
  577. }
  578. }
  579. if (Storage == stIniFile)
  580. {
  581. FDontSave = true;
  582. }
  583. }
  584. catch (Exception &E)
  585. {
  586. throw ExtException(&E, CLEANUP_INIFILE_ERROR);
  587. }
  588. }
  589. //---------------------------------------------------------------------------
  590. RawByteString __fastcall TConfiguration::EncryptPassword(UnicodeString Password, UnicodeString Key)
  591. {
  592. if (Password.IsEmpty())
  593. {
  594. return RawByteString();
  595. }
  596. else
  597. {
  598. return ::EncryptPassword(Password, Key);
  599. }
  600. }
  601. //---------------------------------------------------------------------------
  602. UnicodeString __fastcall TConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
  603. {
  604. if (Password.IsEmpty())
  605. {
  606. return UnicodeString();
  607. }
  608. else
  609. {
  610. return ::DecryptPassword(Password, Key);
  611. }
  612. }
  613. //---------------------------------------------------------------------------
  614. RawByteString __fastcall TConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString /*Key*/)
  615. {
  616. return Password;
  617. }
  618. //---------------------------------------------------------------------------
  619. UnicodeString __fastcall TConfiguration::GetOSVersionStr()
  620. {
  621. UnicodeString Result;
  622. OSVERSIONINFO OSVersionInfo;
  623. OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVersionInfo);
  624. if (GetVersionEx(&OSVersionInfo) != 0)
  625. {
  626. Result = FORMAT(L"%d.%d.%d %s", (int(OSVersionInfo.dwMajorVersion),
  627. int(OSVersionInfo.dwMinorVersion), int(OSVersionInfo.dwBuildNumber),
  628. OSVersionInfo.szCSDVersion)).Trim();
  629. }
  630. return Result;
  631. }
  632. //---------------------------------------------------------------------------
  633. TVSFixedFileInfo *__fastcall TConfiguration::GetFixedApplicationInfo()
  634. {
  635. return GetFixedFileInfo(ApplicationInfo);
  636. }
  637. //---------------------------------------------------------------------------
  638. int __fastcall TConfiguration::GetCompoundVersion()
  639. {
  640. TVSFixedFileInfo * FileInfo = FixedApplicationInfo;
  641. return CalculateCompoundVersion(
  642. HIWORD(FileInfo->dwFileVersionMS), LOWORD(FileInfo->dwFileVersionMS),
  643. HIWORD(FileInfo->dwFileVersionLS), LOWORD(FileInfo->dwFileVersionLS));
  644. }
  645. //---------------------------------------------------------------------------
  646. UnicodeString __fastcall TConfiguration::ModuleFileName()
  647. {
  648. return ParamStr(0);
  649. }
  650. //---------------------------------------------------------------------------
  651. void * __fastcall TConfiguration::GetFileApplicationInfo(const UnicodeString FileName)
  652. {
  653. void * Result;
  654. if (FileName.IsEmpty())
  655. {
  656. if (!FApplicationInfo)
  657. {
  658. FApplicationInfo = CreateFileInfo(ModuleFileName());
  659. }
  660. Result = FApplicationInfo;
  661. }
  662. else
  663. {
  664. Result = CreateFileInfo(FileName);
  665. }
  666. return Result;
  667. }
  668. //---------------------------------------------------------------------------
  669. void * __fastcall TConfiguration::GetApplicationInfo()
  670. {
  671. return GetFileApplicationInfo("");
  672. }
  673. //---------------------------------------------------------------------------
  674. UnicodeString __fastcall TConfiguration::GetFileProductName(const UnicodeString FileName)
  675. {
  676. return GetFileFileInfoString(L"ProductName", FileName);
  677. }
  678. //---------------------------------------------------------------------------
  679. UnicodeString __fastcall TConfiguration::GetFileCompanyName(const UnicodeString FileName)
  680. {
  681. return GetFileFileInfoString(L"CompanyName", FileName);
  682. }
  683. //---------------------------------------------------------------------------
  684. UnicodeString __fastcall TConfiguration::GetProductName()
  685. {
  686. return GetFileProductName(L"");
  687. }
  688. //---------------------------------------------------------------------------
  689. UnicodeString __fastcall TConfiguration::GetCompanyName()
  690. {
  691. return GetFileCompanyName(L"");
  692. }
  693. //---------------------------------------------------------------------------
  694. UnicodeString __fastcall TConfiguration::GetFileProductVersion(const UnicodeString FileName)
  695. {
  696. return TrimVersion(GetFileFileInfoString(L"ProductVersion", FileName));
  697. }
  698. //---------------------------------------------------------------------------
  699. UnicodeString __fastcall TConfiguration::GetFileDescription(const UnicodeString & FileName)
  700. {
  701. return GetFileFileInfoString(L"FileDescription", FileName);
  702. }
  703. //---------------------------------------------------------------------------
  704. UnicodeString __fastcall TConfiguration::GetProductVersion()
  705. {
  706. return GetFileProductVersion(L"");
  707. }
  708. //---------------------------------------------------------------------------
  709. UnicodeString __fastcall TConfiguration::TrimVersion(UnicodeString Version)
  710. {
  711. while ((Version.Pos(L".") != Version.LastDelimiter(L".")) &&
  712. (Version.SubString(Version.Length() - 1, 2) == L".0"))
  713. {
  714. Version.SetLength(Version.Length() - 2);
  715. }
  716. return Version;
  717. }
  718. //---------------------------------------------------------------------------
  719. UnicodeString __fastcall TConfiguration::GetVersionStr()
  720. {
  721. TGuard Guard(FCriticalSection);
  722. try
  723. {
  724. TVSFixedFileInfo * Info = FixedApplicationInfo;
  725. return FMTLOAD(VERSION, (
  726. HIWORD(Info->dwFileVersionMS),
  727. LOWORD(Info->dwFileVersionMS),
  728. HIWORD(Info->dwFileVersionLS),
  729. LOWORD(Info->dwFileVersionLS)));
  730. }
  731. catch (Exception &E)
  732. {
  733. throw ExtException(&E, L"Can't get application version");
  734. }
  735. }
  736. //---------------------------------------------------------------------------
  737. UnicodeString __fastcall TConfiguration::GetVersion()
  738. {
  739. TGuard Guard(FCriticalSection);
  740. try
  741. {
  742. TVSFixedFileInfo * Info = FixedApplicationInfo;
  743. UnicodeString Result;
  744. Result = TrimVersion(FORMAT(L"%d.%d.%d", (
  745. HIWORD(Info->dwFileVersionMS),
  746. LOWORD(Info->dwFileVersionMS),
  747. HIWORD(Info->dwFileVersionLS))));
  748. return Result;
  749. }
  750. catch (Exception &E)
  751. {
  752. throw ExtException(&E, L"Can't get application version");
  753. }
  754. }
  755. //---------------------------------------------------------------------------
  756. UnicodeString __fastcall TConfiguration::GetFileFileInfoString(const UnicodeString Key,
  757. const UnicodeString FileName)
  758. {
  759. TGuard Guard(FCriticalSection);
  760. UnicodeString Result;
  761. void * Info = GetFileApplicationInfo(FileName);
  762. try
  763. {
  764. if ((Info != NULL) && (GetTranslationCount(Info) > 0))
  765. {
  766. TTranslation Translation;
  767. Translation = GetTranslation(Info, 0);
  768. Result = ::GetFileInfoString(Info, Translation, Key);
  769. }
  770. else
  771. {
  772. assert(!FileName.IsEmpty());
  773. }
  774. }
  775. __finally
  776. {
  777. if (!FileName.IsEmpty())
  778. {
  779. FreeFileInfo(Info);
  780. }
  781. }
  782. return Result;
  783. }
  784. //---------------------------------------------------------------------------
  785. UnicodeString __fastcall TConfiguration::GetFileInfoString(const UnicodeString Key)
  786. {
  787. return GetFileFileInfoString(Key, L"");
  788. }
  789. //---------------------------------------------------------------------------
  790. UnicodeString __fastcall TConfiguration::GetRegistryStorageKey()
  791. {
  792. return GetRegistryKey();
  793. }
  794. //---------------------------------------------------------------------------
  795. void __fastcall TConfiguration::SetNulStorage()
  796. {
  797. FStorage = stNul;
  798. }
  799. //---------------------------------------------------------------------------
  800. void __fastcall TConfiguration::SetDefaultStorage()
  801. {
  802. FStorage = stDetect;
  803. }
  804. //---------------------------------------------------------------------------
  805. void __fastcall TConfiguration::SetIniFileStorageName(UnicodeString value)
  806. {
  807. FIniFileStorageName = value;
  808. FStorage = stIniFile;
  809. }
  810. //---------------------------------------------------------------------------
  811. UnicodeString __fastcall TConfiguration::GetIniFileStorageNameForReading()
  812. {
  813. return GetIniFileStorageName(true);
  814. }
  815. //---------------------------------------------------------------------------
  816. UnicodeString __fastcall TConfiguration::GetIniFileStorageNameForReadingWritting()
  817. {
  818. return GetIniFileStorageName(false);
  819. }
  820. //---------------------------------------------------------------------------
  821. UnicodeString __fastcall TConfiguration::GetIniFileStorageName(bool ReadingOnly)
  822. {
  823. if (FIniFileStorageName.IsEmpty())
  824. {
  825. UnicodeString ProgramPath = ParamStr(0);
  826. UnicodeString ProgramIniPath = ChangeFileExt(ProgramPath, L".ini");
  827. UnicodeString IniPath;
  828. if (FileExists(ProgramIniPath))
  829. {
  830. IniPath = ProgramIniPath;
  831. }
  832. else
  833. {
  834. UnicodeString AppDataIniPath =
  835. IncludeTrailingBackslash(GetShellFolderPath(CSIDL_APPDATA)) +
  836. ExtractFileName(ProgramIniPath);
  837. if (FileExists(AppDataIniPath))
  838. {
  839. IniPath = AppDataIniPath;
  840. }
  841. else
  842. {
  843. // avoid expensive test if we are interested in existing files only
  844. if (!ReadingOnly && (FProgramIniPathWrittable < 0))
  845. {
  846. UnicodeString ProgramDir = ExtractFilePath(ProgramPath);
  847. FProgramIniPathWrittable = IsDirectoryWriteable(ProgramDir) ? 1 : 0;
  848. }
  849. // does not really matter what we return when < 0
  850. IniPath = (FProgramIniPathWrittable == 0) ? AppDataIniPath : ProgramIniPath;
  851. }
  852. }
  853. if (FVirtualIniFileStorageName.IsEmpty() &&
  854. TPath::IsDriveRooted(IniPath))
  855. {
  856. UnicodeString LocalAppDataPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA);
  857. // virtual store for non-system drives have a different virtual store,
  858. // do not bother about them
  859. if (TPath::IsDriveRooted(LocalAppDataPath) &&
  860. SameText(ExtractFileDrive(IniPath), ExtractFileDrive(LocalAppDataPath)))
  861. {
  862. FVirtualIniFileStorageName =
  863. IncludeTrailingBackslash(LocalAppDataPath) +
  864. L"VirtualStore\\" +
  865. IniPath.SubString(4, IniPath.Length() - 3);
  866. }
  867. }
  868. if (!FVirtualIniFileStorageName.IsEmpty() &&
  869. FileExists(FVirtualIniFileStorageName))
  870. {
  871. return FVirtualIniFileStorageName;
  872. }
  873. else
  874. {
  875. return IniPath;
  876. }
  877. }
  878. else
  879. {
  880. return FIniFileStorageName;
  881. }
  882. }
  883. //---------------------------------------------------------------------------
  884. UnicodeString __fastcall TConfiguration::GetPuttySessionsKey()
  885. {
  886. return PuttyRegistryStorageKey + L"\\Sessions";
  887. }
  888. //---------------------------------------------------------------------------
  889. UnicodeString __fastcall TConfiguration::GetStoredSessionsSubKey()
  890. {
  891. return L"Sessions";
  892. }
  893. //---------------------------------------------------------------------------
  894. UnicodeString __fastcall TConfiguration::GetSshHostKeysSubKey()
  895. {
  896. return L"SshHostKeys";
  897. }
  898. //---------------------------------------------------------------------------
  899. UnicodeString __fastcall TConfiguration::GetConfigurationSubKey()
  900. {
  901. return L"Configuration";
  902. }
  903. //---------------------------------------------------------------------------
  904. UnicodeString __fastcall TConfiguration::GetRootKeyStr()
  905. {
  906. return RootKeyToStr(HKEY_CURRENT_USER);
  907. }
  908. //---------------------------------------------------------------------------
  909. bool __fastcall TConfiguration::GetGSSAPIInstalled()
  910. {
  911. return HasGSSAPI();
  912. }
  913. //---------------------------------------------------------------------------
  914. void __fastcall TConfiguration::SetStorage(TStorage value)
  915. {
  916. if (FStorage != value)
  917. {
  918. THierarchicalStorage * SourceStorage = NULL;
  919. THierarchicalStorage * TargetStorage = NULL;
  920. try
  921. {
  922. SourceStorage = CreateScpStorage(false);
  923. SourceStorage->AccessMode = smRead;
  924. FStorage = value;
  925. TargetStorage = CreateScpStorage(false);
  926. TargetStorage->AccessMode = smReadWrite;
  927. TargetStorage->Explicit = true;
  928. // copy before save as it removes the ini file,
  929. // when switching from ini to registry
  930. CopyData(SourceStorage, TargetStorage);
  931. }
  932. __finally
  933. {
  934. delete SourceStorage;
  935. delete TargetStorage;
  936. }
  937. // save all and explicit
  938. DoSave(true, true);
  939. }
  940. }
  941. //---------------------------------------------------------------------------
  942. void __fastcall TConfiguration::Saved()
  943. {
  944. // nothing
  945. }
  946. //---------------------------------------------------------------------------
  947. TStorage __fastcall TConfiguration::GetStorage()
  948. {
  949. if (FStorage == stDetect)
  950. {
  951. if (FileExists(IniFileStorageNameForReading))
  952. {
  953. FStorage = stIniFile;
  954. }
  955. else
  956. {
  957. FStorage = stRegistry;
  958. }
  959. }
  960. return FStorage;
  961. }
  962. //---------------------------------------------------------------------------
  963. void __fastcall TConfiguration::SetRandomSeedFile(UnicodeString value)
  964. {
  965. if (RandomSeedFile != value)
  966. {
  967. UnicodeString PrevRandomSeedFileName = RandomSeedFileName;
  968. FRandomSeedFile = value;
  969. // never allow empty seed file to avoid Putty trying to reinitialize the path
  970. if (RandomSeedFileName.IsEmpty())
  971. {
  972. FRandomSeedFile = FDefaultRandomSeedFile;
  973. }
  974. if (!PrevRandomSeedFileName.IsEmpty() &&
  975. (PrevRandomSeedFileName != RandomSeedFileName) &&
  976. FileExists(PrevRandomSeedFileName))
  977. {
  978. // ignore any error
  979. DeleteFile(PrevRandomSeedFileName);
  980. }
  981. }
  982. }
  983. //---------------------------------------------------------------------
  984. UnicodeString __fastcall TConfiguration::GetRandomSeedFileName()
  985. {
  986. return StripPathQuotes(ExpandEnvironmentVariables(FRandomSeedFile)).Trim();
  987. }
  988. //---------------------------------------------------------------------
  989. void __fastcall TConfiguration::SetExternalIpAddress(UnicodeString value)
  990. {
  991. SET_CONFIG_PROPERTY(ExternalIpAddress);
  992. }
  993. //---------------------------------------------------------------------
  994. void __fastcall TConfiguration::SetTryFtpWhenSshFails(bool value)
  995. {
  996. SET_CONFIG_PROPERTY(TryFtpWhenSshFails);
  997. }
  998. //---------------------------------------------------------------------
  999. void __fastcall TConfiguration::SetPuttyRegistryStorageKey(UnicodeString value)
  1000. {
  1001. SET_CONFIG_PROPERTY(PuttyRegistryStorageKey);
  1002. }
  1003. //---------------------------------------------------------------------------
  1004. TEOLType __fastcall TConfiguration::GetLocalEOLType()
  1005. {
  1006. return eolCRLF;
  1007. }
  1008. //---------------------------------------------------------------------
  1009. bool __fastcall TConfiguration::GetCollectUsage()
  1010. {
  1011. return FUsage->Collect;
  1012. }
  1013. //---------------------------------------------------------------------
  1014. void __fastcall TConfiguration::SetCollectUsage(bool value)
  1015. {
  1016. FUsage->Collect = value;
  1017. }
  1018. //---------------------------------------------------------------------
  1019. void __fastcall TConfiguration::TemporaryLogging(const UnicodeString ALogFileName)
  1020. {
  1021. if (SameText(ExtractFileExt(ALogFileName), L".xml"))
  1022. {
  1023. TemporaryActionsLogging(ALogFileName);
  1024. }
  1025. else
  1026. {
  1027. FLogging = true;
  1028. FLogFileName = ALogFileName;
  1029. UpdateActualLogProtocol();
  1030. }
  1031. }
  1032. //---------------------------------------------------------------------
  1033. void __fastcall TConfiguration::TemporaryActionsLogging(const UnicodeString ALogFileName)
  1034. {
  1035. FLogActions = true;
  1036. FActionsLogFileName = ALogFileName;
  1037. }
  1038. //---------------------------------------------------------------------
  1039. void __fastcall TConfiguration::SetLogging(bool value)
  1040. {
  1041. if (Logging != value)
  1042. {
  1043. FPermanentLogging = value;
  1044. FLogging = value;
  1045. UpdateActualLogProtocol();
  1046. Changed();
  1047. }
  1048. }
  1049. //---------------------------------------------------------------------
  1050. void __fastcall TConfiguration::SetLogFileName(UnicodeString value)
  1051. {
  1052. if (LogFileName != value)
  1053. {
  1054. FPermanentLogFileName = value;
  1055. FLogFileName = value;
  1056. Changed();
  1057. }
  1058. }
  1059. //---------------------------------------------------------------------
  1060. void __fastcall TConfiguration::SetActionsLogFileName(UnicodeString value)
  1061. {
  1062. if (ActionsLogFileName != value)
  1063. {
  1064. FPermanentActionsLogFileName = value;
  1065. FActionsLogFileName = value;
  1066. Changed();
  1067. }
  1068. }
  1069. //---------------------------------------------------------------------
  1070. bool __fastcall TConfiguration::GetLogToFile()
  1071. {
  1072. return !LogFileName.IsEmpty();
  1073. }
  1074. //---------------------------------------------------------------------
  1075. void __fastcall TConfiguration::UpdateActualLogProtocol()
  1076. {
  1077. FActualLogProtocol = FLogging ? FLogProtocol : 0;
  1078. }
  1079. //---------------------------------------------------------------------
  1080. void __fastcall TConfiguration::SetLogProtocol(int value)
  1081. {
  1082. SET_CONFIG_PROPERTY(LogProtocol);
  1083. UpdateActualLogProtocol();
  1084. }
  1085. //---------------------------------------------------------------------
  1086. void __fastcall TConfiguration::SetLogActions(bool value)
  1087. {
  1088. if (LogActions != value)
  1089. {
  1090. FPermanentLogActions = value;
  1091. FLogActions = value;
  1092. Changed();
  1093. }
  1094. }
  1095. //---------------------------------------------------------------------
  1096. void __fastcall TConfiguration::SetLogFileAppend(bool value)
  1097. {
  1098. SET_CONFIG_PROPERTY(LogFileAppend);
  1099. }
  1100. //---------------------------------------------------------------------
  1101. void __fastcall TConfiguration::SetLogWindowLines(int value)
  1102. {
  1103. SET_CONFIG_PROPERTY(LogWindowLines);
  1104. }
  1105. //---------------------------------------------------------------------
  1106. void __fastcall TConfiguration::SetLogWindowComplete(bool value)
  1107. {
  1108. if (value != LogWindowComplete)
  1109. {
  1110. LogWindowLines = value ? 0 : 50;
  1111. Changed();
  1112. }
  1113. }
  1114. //---------------------------------------------------------------------
  1115. bool __fastcall TConfiguration::GetLogWindowComplete()
  1116. {
  1117. return (bool)(LogWindowLines == 0);
  1118. }
  1119. //---------------------------------------------------------------------
  1120. UnicodeString __fastcall TConfiguration::GetDefaultLogFileName()
  1121. {
  1122. return L"%TEMP%\\!S.log";
  1123. }
  1124. //---------------------------------------------------------------------------
  1125. void __fastcall TConfiguration::SetConfirmOverwriting(bool value)
  1126. {
  1127. TGuard Guard(FCriticalSection);
  1128. SET_CONFIG_PROPERTY(ConfirmOverwriting);
  1129. }
  1130. //---------------------------------------------------------------------------
  1131. bool __fastcall TConfiguration::GetConfirmOverwriting()
  1132. {
  1133. TGuard Guard(FCriticalSection);
  1134. return FConfirmOverwriting;
  1135. }
  1136. //---------------------------------------------------------------------------
  1137. void __fastcall TConfiguration::SetConfirmResume(bool value)
  1138. {
  1139. TGuard Guard(FCriticalSection);
  1140. SET_CONFIG_PROPERTY(ConfirmResume);
  1141. }
  1142. //---------------------------------------------------------------------------
  1143. bool __fastcall TConfiguration::GetConfirmResume()
  1144. {
  1145. TGuard Guard(FCriticalSection);
  1146. return FConfirmResume;
  1147. }
  1148. //---------------------------------------------------------------------------
  1149. void __fastcall TConfiguration::SetAutoReadDirectoryAfterOp(bool value)
  1150. {
  1151. TGuard Guard(FCriticalSection);
  1152. SET_CONFIG_PROPERTY(AutoReadDirectoryAfterOp);
  1153. }
  1154. //---------------------------------------------------------------------------
  1155. bool __fastcall TConfiguration::GetAutoReadDirectoryAfterOp()
  1156. {
  1157. TGuard Guard(FCriticalSection);
  1158. return FAutoReadDirectoryAfterOp;
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. UnicodeString __fastcall TConfiguration::GetTimeFormat()
  1162. {
  1163. return L"h:nn:ss";
  1164. }
  1165. //---------------------------------------------------------------------------
  1166. UnicodeString __fastcall TConfiguration::GetPartialExt() const
  1167. {
  1168. return PARTIAL_EXT;
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. UnicodeString __fastcall TConfiguration::GetDefaultKeyFile()
  1172. {
  1173. return L"";
  1174. }
  1175. //---------------------------------------------------------------------------
  1176. bool __fastcall TConfiguration::GetRememberPassword()
  1177. {
  1178. return false;
  1179. }
  1180. //---------------------------------------------------------------------------
  1181. void __fastcall TConfiguration::SetSessionReopenAuto(int value)
  1182. {
  1183. SET_CONFIG_PROPERTY(SessionReopenAuto);
  1184. }
  1185. //---------------------------------------------------------------------------
  1186. void __fastcall TConfiguration::SetSessionReopenBackground(int value)
  1187. {
  1188. SET_CONFIG_PROPERTY(SessionReopenBackground);
  1189. }
  1190. //---------------------------------------------------------------------------
  1191. void __fastcall TConfiguration::SetSessionReopenTimeout(int value)
  1192. {
  1193. SET_CONFIG_PROPERTY(SessionReopenTimeout);
  1194. }
  1195. //---------------------------------------------------------------------------
  1196. void __fastcall TConfiguration::SetSessionReopenAutoStall(int value)
  1197. {
  1198. SET_CONFIG_PROPERTY(SessionReopenAutoStall);
  1199. }
  1200. //---------------------------------------------------------------------------
  1201. void __fastcall TConfiguration::SetTunnelLocalPortNumberLow(int value)
  1202. {
  1203. SET_CONFIG_PROPERTY(TunnelLocalPortNumberLow);
  1204. }
  1205. //---------------------------------------------------------------------------
  1206. void __fastcall TConfiguration::SetTunnelLocalPortNumberHigh(int value)
  1207. {
  1208. SET_CONFIG_PROPERTY(TunnelLocalPortNumberHigh);
  1209. }
  1210. //---------------------------------------------------------------------------
  1211. void __fastcall TConfiguration::SetCacheDirectoryChangesMaxSize(int value)
  1212. {
  1213. SET_CONFIG_PROPERTY(CacheDirectoryChangesMaxSize);
  1214. }
  1215. //---------------------------------------------------------------------------
  1216. void __fastcall TConfiguration::SetShowFtpWelcomeMessage(bool value)
  1217. {
  1218. SET_CONFIG_PROPERTY(ShowFtpWelcomeMessage);
  1219. }
  1220. //---------------------------------------------------------------------------
  1221. //---------------------------------------------------------------------------
  1222. void __fastcall TShortCuts::Add(TShortCut ShortCut)
  1223. {
  1224. FShortCuts.insert(ShortCut);
  1225. }
  1226. //---------------------------------------------------------------------------
  1227. bool __fastcall TShortCuts::Has(TShortCut ShortCut) const
  1228. {
  1229. return (FShortCuts.count(ShortCut) != 0);
  1230. }