Configuration.cpp 42 KB

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