Configuration.cpp 44 KB

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