Configuration.cpp 44 KB

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