Configuration.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  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. RawByteString __fastcall TConfiguration::EncryptPassword(UnicodeString Password, UnicodeString Key)
  641. {
  642. if (Password.IsEmpty())
  643. {
  644. return RawByteString();
  645. }
  646. else
  647. {
  648. return ::EncryptPassword(Password, Key);
  649. }
  650. }
  651. //---------------------------------------------------------------------------
  652. UnicodeString __fastcall TConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
  653. {
  654. if (Password.IsEmpty())
  655. {
  656. return UnicodeString();
  657. }
  658. else
  659. {
  660. return ::DecryptPassword(Password, Key);
  661. }
  662. }
  663. //---------------------------------------------------------------------------
  664. RawByteString __fastcall TConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString /*Key*/)
  665. {
  666. return Password;
  667. }
  668. //---------------------------------------------------------------------------
  669. UnicodeString __fastcall TConfiguration::GetOSVersionStr()
  670. {
  671. UnicodeString Result;
  672. OSVERSIONINFO OSVersionInfo;
  673. OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVersionInfo);
  674. if (GetVersionEx(&OSVersionInfo) != 0)
  675. {
  676. Result = FORMAT(L"%d.%d.%d", (int(OSVersionInfo.dwMajorVersion),
  677. int(OSVersionInfo.dwMinorVersion), int(OSVersionInfo.dwBuildNumber)));
  678. UnicodeString CSDVersion = OSVersionInfo.szCSDVersion;
  679. if (!CSDVersion.IsEmpty())
  680. {
  681. Result += L" " + CSDVersion;
  682. }
  683. UnicodeString ProductName = WindowsProductName();
  684. if (!ProductName.IsEmpty())
  685. {
  686. Result += L" - " + ProductName;
  687. }
  688. }
  689. return Result;
  690. }
  691. //---------------------------------------------------------------------------
  692. TVSFixedFileInfo *__fastcall TConfiguration::GetFixedApplicationInfo()
  693. {
  694. return GetFixedFileInfo(ApplicationInfo);
  695. }
  696. //---------------------------------------------------------------------------
  697. int __fastcall TConfiguration::GetCompoundVersion()
  698. {
  699. TVSFixedFileInfo * FileInfo = FixedApplicationInfo;
  700. return CalculateCompoundVersion(
  701. HIWORD(FileInfo->dwFileVersionMS), LOWORD(FileInfo->dwFileVersionMS),
  702. HIWORD(FileInfo->dwFileVersionLS), LOWORD(FileInfo->dwFileVersionLS));
  703. }
  704. //---------------------------------------------------------------------------
  705. UnicodeString __fastcall TConfiguration::ModuleFileName()
  706. {
  707. return ParamStr(0);
  708. }
  709. //---------------------------------------------------------------------------
  710. void * __fastcall TConfiguration::GetFileApplicationInfo(const UnicodeString FileName)
  711. {
  712. void * Result;
  713. if (FileName.IsEmpty())
  714. {
  715. if (!FApplicationInfo)
  716. {
  717. FApplicationInfo = CreateFileInfo(ModuleFileName());
  718. }
  719. Result = FApplicationInfo;
  720. }
  721. else
  722. {
  723. Result = CreateFileInfo(FileName);
  724. }
  725. return Result;
  726. }
  727. //---------------------------------------------------------------------------
  728. void * __fastcall TConfiguration::GetApplicationInfo()
  729. {
  730. return GetFileApplicationInfo("");
  731. }
  732. //---------------------------------------------------------------------------
  733. UnicodeString __fastcall TConfiguration::GetFileProductName(const UnicodeString FileName)
  734. {
  735. return GetFileFileInfoString(L"ProductName", FileName);
  736. }
  737. //---------------------------------------------------------------------------
  738. UnicodeString __fastcall TConfiguration::GetFileCompanyName(const UnicodeString FileName)
  739. {
  740. // particularly in IDE build, company name is empty
  741. return GetFileFileInfoString(L"CompanyName", FileName, true);
  742. }
  743. //---------------------------------------------------------------------------
  744. UnicodeString __fastcall TConfiguration::GetProductName()
  745. {
  746. return GetFileProductName(L"");
  747. }
  748. //---------------------------------------------------------------------------
  749. UnicodeString __fastcall TConfiguration::GetCompanyName()
  750. {
  751. return GetFileCompanyName(L"");
  752. }
  753. //---------------------------------------------------------------------------
  754. UnicodeString __fastcall TConfiguration::GetFileProductVersion(const UnicodeString FileName)
  755. {
  756. return TrimVersion(GetFileFileInfoString(L"ProductVersion", FileName));
  757. }
  758. //---------------------------------------------------------------------------
  759. UnicodeString __fastcall TConfiguration::GetFileDescription(const UnicodeString & FileName)
  760. {
  761. return GetFileFileInfoString(L"FileDescription", FileName);
  762. }
  763. //---------------------------------------------------------------------------
  764. UnicodeString __fastcall TConfiguration::GetProductVersion()
  765. {
  766. return GetFileProductVersion(L"");
  767. }
  768. //---------------------------------------------------------------------------
  769. bool __fastcall TConfiguration::GetIsUnofficial()
  770. {
  771. #ifdef BUILD_OFFICIAL
  772. return false;
  773. #else
  774. return true;
  775. #endif
  776. }
  777. //---------------------------------------------------------------------------
  778. UnicodeString __fastcall TConfiguration::GetVersionStr()
  779. {
  780. TGuard Guard(FCriticalSection);
  781. try
  782. {
  783. UnicodeString BuildStr;
  784. if (!IsUnofficial)
  785. {
  786. BuildStr = LoadStr(VERSION_BUILD);
  787. }
  788. else
  789. {
  790. #ifdef _DEBUG
  791. BuildStr = LoadStr(VERSION_DEBUG_BUILD);
  792. #else
  793. BuildStr = LoadStr(VERSION_DEV_BUILD);
  794. #endif
  795. }
  796. int Build = LOWORD(FixedApplicationInfo->dwFileVersionLS);
  797. if (Build > 0)
  798. {
  799. BuildStr += L" " + IntToStr(Build);
  800. }
  801. #ifndef BUILD_OFFICIAL
  802. UnicodeString BuildDate = __DATE__;
  803. UnicodeString MonthStr = CutToChar(BuildDate, L' ', true);
  804. int Month = ParseShortEngMonthName(MonthStr);
  805. int Day = StrToInt(CutToChar(BuildDate, L' ', true));
  806. int Year = StrToInt(Trim(BuildDate));
  807. UnicodeString DateStr = FORMAT(L"%d-%2.2d-%2.2d", (Year, Month, Day));
  808. AddToList(BuildStr, DateStr, L" ");
  809. #endif
  810. UnicodeString Result = FMTLOAD(VERSION2, (Version, BuildStr));
  811. #ifndef BUILD_OFFICIAL
  812. Result += L" " + LoadStr(VERSION_DONT_DISTRIBUTE);
  813. #endif
  814. return Result;
  815. }
  816. catch (Exception &E)
  817. {
  818. throw ExtException(&E, L"Can't get application version");
  819. }
  820. }
  821. //---------------------------------------------------------------------------
  822. UnicodeString __fastcall TConfiguration::GetVersion()
  823. {
  824. TGuard Guard(FCriticalSection);
  825. try
  826. {
  827. TVSFixedFileInfo * Info = FixedApplicationInfo;
  828. UnicodeString Result =
  829. FormatVersion(
  830. HIWORD(Info->dwFileVersionMS),
  831. LOWORD(Info->dwFileVersionMS),
  832. HIWORD(Info->dwFileVersionLS));
  833. return Result;
  834. }
  835. catch (Exception &E)
  836. {
  837. throw ExtException(&E, L"Can't get application version");
  838. }
  839. }
  840. //---------------------------------------------------------------------------
  841. UnicodeString __fastcall TConfiguration::GetFileFileInfoString(const UnicodeString Key,
  842. const UnicodeString FileName, bool AllowEmpty)
  843. {
  844. TGuard Guard(FCriticalSection);
  845. UnicodeString Result;
  846. void * Info = GetFileApplicationInfo(FileName);
  847. try
  848. {
  849. if ((Info != NULL) && (GetTranslationCount(Info) > 0))
  850. {
  851. TTranslation Translation;
  852. Translation = GetTranslation(Info, 0);
  853. Result = ::GetFileInfoString(Info, Translation, Key, AllowEmpty);
  854. }
  855. else
  856. {
  857. assert(!FileName.IsEmpty());
  858. }
  859. }
  860. __finally
  861. {
  862. if (!FileName.IsEmpty())
  863. {
  864. FreeFileInfo(Info);
  865. }
  866. }
  867. return Result;
  868. }
  869. //---------------------------------------------------------------------------
  870. UnicodeString __fastcall TConfiguration::GetFileInfoString(const UnicodeString Key)
  871. {
  872. return GetFileFileInfoString(Key, L"");
  873. }
  874. //---------------------------------------------------------------------------
  875. UnicodeString __fastcall TConfiguration::GetRegistryStorageKey()
  876. {
  877. return GetRegistryKey();
  878. }
  879. //---------------------------------------------------------------------------
  880. void __fastcall TConfiguration::SetNulStorage()
  881. {
  882. FStorage = stNul;
  883. }
  884. //---------------------------------------------------------------------------
  885. void __fastcall TConfiguration::SetDefaultStorage()
  886. {
  887. FStorage = stDetect;
  888. }
  889. //---------------------------------------------------------------------------
  890. void __fastcall TConfiguration::SetIniFileStorageName(UnicodeString value)
  891. {
  892. FIniFileStorageName = value;
  893. FStorage = stIniFile;
  894. }
  895. //---------------------------------------------------------------------------
  896. UnicodeString __fastcall TConfiguration::GetIniFileStorageNameForReading()
  897. {
  898. return GetIniFileStorageName(true);
  899. }
  900. //---------------------------------------------------------------------------
  901. UnicodeString __fastcall TConfiguration::GetIniFileStorageNameForReadingWriting()
  902. {
  903. return GetIniFileStorageName(false);
  904. }
  905. //---------------------------------------------------------------------------
  906. UnicodeString __fastcall TConfiguration::GetIniFileStorageName(bool ReadingOnly)
  907. {
  908. if (FIniFileStorageName.IsEmpty())
  909. {
  910. UnicodeString ProgramPath = ParamStr(0);
  911. UnicodeString ProgramIniPath = ChangeFileExt(ProgramPath, L".ini");
  912. UnicodeString IniPath;
  913. if (FileExists(ApiPath(ProgramIniPath)))
  914. {
  915. IniPath = ProgramIniPath;
  916. }
  917. else
  918. {
  919. UnicodeString AppDataIniPath =
  920. IncludeTrailingBackslash(GetShellFolderPath(CSIDL_APPDATA)) +
  921. ExtractFileName(ProgramIniPath);
  922. if (FileExists(ApiPath(AppDataIniPath)))
  923. {
  924. IniPath = AppDataIniPath;
  925. }
  926. else
  927. {
  928. // avoid expensive test if we are interested in existing files only
  929. if (!ReadingOnly && (FProgramIniPathWrittable < 0))
  930. {
  931. UnicodeString ProgramDir = ExtractFilePath(ProgramPath);
  932. FProgramIniPathWrittable = IsDirectoryWriteable(ProgramDir) ? 1 : 0;
  933. }
  934. // does not really matter what we return when < 0
  935. IniPath = (FProgramIniPathWrittable == 0) ? AppDataIniPath : ProgramIniPath;
  936. }
  937. }
  938. // BACKWARD COMPATIBILITY with 4.x
  939. if (FVirtualIniFileStorageName.IsEmpty() &&
  940. TPath::IsDriveRooted(IniPath))
  941. {
  942. UnicodeString LocalAppDataPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA);
  943. // virtual store for non-system drives have a different virtual store,
  944. // do not bother about them
  945. if (TPath::IsDriveRooted(LocalAppDataPath) &&
  946. SameText(ExtractFileDrive(IniPath), ExtractFileDrive(LocalAppDataPath)))
  947. {
  948. FVirtualIniFileStorageName =
  949. IncludeTrailingBackslash(LocalAppDataPath) +
  950. L"VirtualStore\\" +
  951. IniPath.SubString(4, IniPath.Length() - 3);
  952. }
  953. }
  954. if (!FVirtualIniFileStorageName.IsEmpty() &&
  955. FileExists(ApiPath(FVirtualIniFileStorageName)))
  956. {
  957. return FVirtualIniFileStorageName;
  958. }
  959. else
  960. {
  961. return IniPath;
  962. }
  963. }
  964. else
  965. {
  966. return FIniFileStorageName;
  967. }
  968. }
  969. //---------------------------------------------------------------------------
  970. void __fastcall TConfiguration::SetOptionsStorage(TStrings * value)
  971. {
  972. if (FOptionsStorage.get() == NULL)
  973. {
  974. FOptionsStorage.reset(new TStringList());
  975. }
  976. FOptionsStorage->AddStrings(value);
  977. }
  978. //---------------------------------------------------------------------------
  979. TStrings * __fastcall TConfiguration::GetOptionsStorage()
  980. {
  981. return FOptionsStorage.get();
  982. }
  983. //---------------------------------------------------------------------------
  984. UnicodeString __fastcall TConfiguration::GetPuttySessionsKey()
  985. {
  986. return PuttyRegistryStorageKey + L"\\Sessions";
  987. }
  988. //---------------------------------------------------------------------------
  989. UnicodeString __fastcall TConfiguration::GetStoredSessionsSubKey()
  990. {
  991. return L"Sessions";
  992. }
  993. //---------------------------------------------------------------------------
  994. UnicodeString __fastcall TConfiguration::GetSshHostKeysSubKey()
  995. {
  996. return L"SshHostKeys";
  997. }
  998. //---------------------------------------------------------------------------
  999. UnicodeString __fastcall TConfiguration::GetConfigurationSubKey()
  1000. {
  1001. return L"Configuration";
  1002. }
  1003. //---------------------------------------------------------------------------
  1004. UnicodeString __fastcall TConfiguration::GetRootKeyStr()
  1005. {
  1006. return RootKeyToStr(HKEY_CURRENT_USER);
  1007. }
  1008. //---------------------------------------------------------------------------
  1009. void __fastcall TConfiguration::SetStorage(TStorage value)
  1010. {
  1011. if (FStorage != value)
  1012. {
  1013. TStorage StorageBak = FStorage;
  1014. try
  1015. {
  1016. THierarchicalStorage * SourceStorage = NULL;
  1017. THierarchicalStorage * TargetStorage = NULL;
  1018. try
  1019. {
  1020. SourceStorage = CreateConfigStorage();
  1021. SourceStorage->AccessMode = smRead;
  1022. FStorage = value;
  1023. TargetStorage = CreateConfigStorage();
  1024. TargetStorage->AccessMode = smReadWrite;
  1025. TargetStorage->Explicit = true;
  1026. // copy before save as it removes the ini file,
  1027. // when switching from ini to registry
  1028. CopyData(SourceStorage, TargetStorage);
  1029. }
  1030. __finally
  1031. {
  1032. delete SourceStorage;
  1033. delete TargetStorage;
  1034. }
  1035. // save all and explicit,
  1036. // this also removes an INI file, when switching to registry storage
  1037. DoSave(true, true);
  1038. }
  1039. catch (...)
  1040. {
  1041. // If this fails, do not pretend that storage was switched.
  1042. // For instance:
  1043. // - When writing to an INI file fails (unlikely, as we fallback to user profile)
  1044. // - When removing INI file fails, when switching to registry
  1045. // (possible, when the INI file is in Program Files folder)
  1046. FStorage = StorageBak;
  1047. throw;
  1048. }
  1049. }
  1050. }
  1051. //---------------------------------------------------------------------------
  1052. void __fastcall TConfiguration::Saved()
  1053. {
  1054. // nothing
  1055. }
  1056. //---------------------------------------------------------------------------
  1057. TStorage __fastcall TConfiguration::GetStorage()
  1058. {
  1059. if (FStorage == stDetect)
  1060. {
  1061. if (FileExists(ApiPath(IniFileStorageNameForReading)))
  1062. {
  1063. FStorage = stIniFile;
  1064. }
  1065. else
  1066. {
  1067. FStorage = stRegistry;
  1068. }
  1069. }
  1070. return FStorage;
  1071. }
  1072. //---------------------------------------------------------------------------
  1073. void __fastcall TConfiguration::SetRandomSeedFile(UnicodeString value)
  1074. {
  1075. if (RandomSeedFile != value)
  1076. {
  1077. UnicodeString PrevRandomSeedFileName = RandomSeedFileName;
  1078. FRandomSeedFile = value;
  1079. // never allow empty seed file to avoid Putty trying to reinitialize the path
  1080. if (RandomSeedFileName.IsEmpty())
  1081. {
  1082. FRandomSeedFile = FDefaultRandomSeedFile;
  1083. }
  1084. if (!PrevRandomSeedFileName.IsEmpty() &&
  1085. (PrevRandomSeedFileName != RandomSeedFileName) &&
  1086. FileExists(ApiPath(PrevRandomSeedFileName)))
  1087. {
  1088. // ignore any error
  1089. DeleteFile(ApiPath(PrevRandomSeedFileName));
  1090. }
  1091. }
  1092. }
  1093. //---------------------------------------------------------------------
  1094. UnicodeString __fastcall TConfiguration::GetRandomSeedFileName()
  1095. {
  1096. return StripPathQuotes(ExpandEnvironmentVariables(FRandomSeedFile)).Trim();
  1097. }
  1098. //---------------------------------------------------------------------
  1099. void __fastcall TConfiguration::SetExternalIpAddress(UnicodeString value)
  1100. {
  1101. SET_CONFIG_PROPERTY(ExternalIpAddress);
  1102. }
  1103. //---------------------------------------------------------------------
  1104. void __fastcall TConfiguration::SetTryFtpWhenSshFails(bool value)
  1105. {
  1106. SET_CONFIG_PROPERTY(TryFtpWhenSshFails);
  1107. }
  1108. //---------------------------------------------------------------------
  1109. void __fastcall TConfiguration::SetPuttyRegistryStorageKey(UnicodeString value)
  1110. {
  1111. SET_CONFIG_PROPERTY(PuttyRegistryStorageKey);
  1112. }
  1113. //---------------------------------------------------------------------------
  1114. TEOLType __fastcall TConfiguration::GetLocalEOLType()
  1115. {
  1116. return eolCRLF;
  1117. }
  1118. //---------------------------------------------------------------------
  1119. bool __fastcall TConfiguration::GetCollectUsage()
  1120. {
  1121. return FUsage->Collect;
  1122. }
  1123. //---------------------------------------------------------------------
  1124. void __fastcall TConfiguration::SetCollectUsage(bool value)
  1125. {
  1126. FUsage->Collect = value;
  1127. }
  1128. //---------------------------------------------------------------------
  1129. void __fastcall TConfiguration::TemporaryLogging(const UnicodeString ALogFileName)
  1130. {
  1131. if (SameText(ExtractFileExt(ALogFileName), L".xml"))
  1132. {
  1133. TemporaryActionsLogging(ALogFileName);
  1134. }
  1135. else
  1136. {
  1137. FLogging = true;
  1138. FLogFileName = ALogFileName;
  1139. UpdateActualLogProtocol();
  1140. }
  1141. }
  1142. //---------------------------------------------------------------------
  1143. void __fastcall TConfiguration::TemporaryActionsLogging(const UnicodeString ALogFileName)
  1144. {
  1145. FLogActions = true;
  1146. FActionsLogFileName = ALogFileName;
  1147. }
  1148. //---------------------------------------------------------------------
  1149. void __fastcall TConfiguration::SetLogging(bool value)
  1150. {
  1151. if (Logging != value)
  1152. {
  1153. FPermanentLogging = value;
  1154. FLogging = value;
  1155. UpdateActualLogProtocol();
  1156. Changed();
  1157. }
  1158. }
  1159. //---------------------------------------------------------------------
  1160. void __fastcall TConfiguration::SetLogFileName(UnicodeString value)
  1161. {
  1162. if (LogFileName != value)
  1163. {
  1164. FPermanentLogFileName = value;
  1165. FLogFileName = value;
  1166. Changed();
  1167. }
  1168. }
  1169. //---------------------------------------------------------------------
  1170. void __fastcall TConfiguration::SetActionsLogFileName(UnicodeString value)
  1171. {
  1172. if (ActionsLogFileName != value)
  1173. {
  1174. FPermanentActionsLogFileName = value;
  1175. FActionsLogFileName = value;
  1176. Changed();
  1177. }
  1178. }
  1179. //---------------------------------------------------------------------
  1180. bool __fastcall TConfiguration::GetLogToFile()
  1181. {
  1182. return !LogFileName.IsEmpty();
  1183. }
  1184. //---------------------------------------------------------------------
  1185. void __fastcall TConfiguration::UpdateActualLogProtocol()
  1186. {
  1187. FActualLogProtocol = FLogging ? FLogProtocol : 0;
  1188. }
  1189. //---------------------------------------------------------------------
  1190. void __fastcall TConfiguration::SetLogProtocol(int value)
  1191. {
  1192. SET_CONFIG_PROPERTY(LogProtocol);
  1193. UpdateActualLogProtocol();
  1194. }
  1195. //---------------------------------------------------------------------
  1196. void __fastcall TConfiguration::SetLogActions(bool value)
  1197. {
  1198. if (LogActions != value)
  1199. {
  1200. FPermanentLogActions = value;
  1201. FLogActions = value;
  1202. Changed();
  1203. }
  1204. }
  1205. //---------------------------------------------------------------------
  1206. void __fastcall TConfiguration::SetLogFileAppend(bool value)
  1207. {
  1208. SET_CONFIG_PROPERTY(LogFileAppend);
  1209. }
  1210. //---------------------------------------------------------------------
  1211. void __fastcall TConfiguration::SetLogSensitive(bool value)
  1212. {
  1213. SET_CONFIG_PROPERTY(LogSensitive);
  1214. }
  1215. //---------------------------------------------------------------------
  1216. void __fastcall TConfiguration::SetLogWindowLines(int value)
  1217. {
  1218. SET_CONFIG_PROPERTY(LogWindowLines);
  1219. }
  1220. //---------------------------------------------------------------------
  1221. void __fastcall TConfiguration::SetLogWindowComplete(bool value)
  1222. {
  1223. if (value != LogWindowComplete)
  1224. {
  1225. LogWindowLines = value ? 0 : 50;
  1226. Changed();
  1227. }
  1228. }
  1229. //---------------------------------------------------------------------
  1230. bool __fastcall TConfiguration::GetLogWindowComplete()
  1231. {
  1232. return (bool)(LogWindowLines == 0);
  1233. }
  1234. //---------------------------------------------------------------------
  1235. UnicodeString __fastcall TConfiguration::GetDefaultLogFileName()
  1236. {
  1237. return L"%TEMP%\\!S.log";
  1238. }
  1239. //---------------------------------------------------------------------------
  1240. void __fastcall TConfiguration::SetConfirmOverwriting(bool value)
  1241. {
  1242. TGuard Guard(FCriticalSection);
  1243. SET_CONFIG_PROPERTY(ConfirmOverwriting);
  1244. }
  1245. //---------------------------------------------------------------------------
  1246. bool __fastcall TConfiguration::GetConfirmOverwriting()
  1247. {
  1248. TGuard Guard(FCriticalSection);
  1249. return FConfirmOverwriting;
  1250. }
  1251. //---------------------------------------------------------------------------
  1252. void __fastcall TConfiguration::SetConfirmResume(bool value)
  1253. {
  1254. TGuard Guard(FCriticalSection);
  1255. SET_CONFIG_PROPERTY(ConfirmResume);
  1256. }
  1257. //---------------------------------------------------------------------------
  1258. bool __fastcall TConfiguration::GetConfirmResume()
  1259. {
  1260. TGuard Guard(FCriticalSection);
  1261. return FConfirmResume;
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. void __fastcall TConfiguration::SetAutoReadDirectoryAfterOp(bool value)
  1265. {
  1266. TGuard Guard(FCriticalSection);
  1267. SET_CONFIG_PROPERTY(AutoReadDirectoryAfterOp);
  1268. }
  1269. //---------------------------------------------------------------------------
  1270. bool __fastcall TConfiguration::GetAutoReadDirectoryAfterOp()
  1271. {
  1272. TGuard Guard(FCriticalSection);
  1273. return FAutoReadDirectoryAfterOp;
  1274. }
  1275. //---------------------------------------------------------------------------
  1276. UnicodeString __fastcall TConfiguration::GetTimeFormat()
  1277. {
  1278. return L"h:nn:ss";
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. UnicodeString __fastcall TConfiguration::GetPartialExt() const
  1282. {
  1283. return PARTIAL_EXT;
  1284. }
  1285. //---------------------------------------------------------------------------
  1286. UnicodeString __fastcall TConfiguration::GetDefaultKeyFile()
  1287. {
  1288. return L"";
  1289. }
  1290. //---------------------------------------------------------------------------
  1291. bool __fastcall TConfiguration::GetRememberPassword()
  1292. {
  1293. return false;
  1294. }
  1295. //---------------------------------------------------------------------------
  1296. void __fastcall TConfiguration::SetSessionReopenAuto(int value)
  1297. {
  1298. SET_CONFIG_PROPERTY(SessionReopenAuto);
  1299. }
  1300. //---------------------------------------------------------------------------
  1301. void __fastcall TConfiguration::SetSessionReopenBackground(int value)
  1302. {
  1303. SET_CONFIG_PROPERTY(SessionReopenBackground);
  1304. }
  1305. //---------------------------------------------------------------------------
  1306. void __fastcall TConfiguration::SetSessionReopenTimeout(int value)
  1307. {
  1308. SET_CONFIG_PROPERTY(SessionReopenTimeout);
  1309. }
  1310. //---------------------------------------------------------------------------
  1311. void __fastcall TConfiguration::SetSessionReopenAutoStall(int value)
  1312. {
  1313. SET_CONFIG_PROPERTY(SessionReopenAutoStall);
  1314. }
  1315. //---------------------------------------------------------------------------
  1316. void __fastcall TConfiguration::SetTunnelLocalPortNumberLow(int value)
  1317. {
  1318. SET_CONFIG_PROPERTY(TunnelLocalPortNumberLow);
  1319. }
  1320. //---------------------------------------------------------------------------
  1321. void __fastcall TConfiguration::SetTunnelLocalPortNumberHigh(int value)
  1322. {
  1323. SET_CONFIG_PROPERTY(TunnelLocalPortNumberHigh);
  1324. }
  1325. //---------------------------------------------------------------------------
  1326. void __fastcall TConfiguration::SetCacheDirectoryChangesMaxSize(int value)
  1327. {
  1328. SET_CONFIG_PROPERTY(CacheDirectoryChangesMaxSize);
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TConfiguration::SetShowFtpWelcomeMessage(bool value)
  1332. {
  1333. SET_CONFIG_PROPERTY(ShowFtpWelcomeMessage);
  1334. }
  1335. //---------------------------------------------------------------------------
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TShortCuts::Add(TShortCut ShortCut)
  1338. {
  1339. FShortCuts.insert(ShortCut);
  1340. }
  1341. //---------------------------------------------------------------------------
  1342. bool __fastcall TShortCuts::Has(TShortCut ShortCut) const
  1343. {
  1344. return (FShortCuts.count(ShortCut) != 0);
  1345. }