Configuration.cpp 43 KB

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