Configuration.cpp 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  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 "FileMasks.h"
  14. #include <shlobj.h>
  15. #include <System.IOUtils.hpp>
  16. #include <System.StrUtils.hpp>
  17. //---------------------------------------------------------------------------
  18. #pragma package(smart_init)
  19. //---------------------------------------------------------------------------
  20. const wchar_t * AutoSwitchNames = L"On;Off;Auto";
  21. const wchar_t * NotAutoSwitchNames = L"Off;On;Auto";
  22. //---------------------------------------------------------------------------
  23. // See https://www.iana.org/assignments/hash-function-text-names/hash-function-text-names.xhtml
  24. const UnicodeString Sha1ChecksumAlg(L"sha-1");
  25. const UnicodeString Sha224ChecksumAlg(L"sha-224");
  26. const UnicodeString Sha256ChecksumAlg(L"sha-256");
  27. const UnicodeString Sha384ChecksumAlg(L"sha-384");
  28. const UnicodeString Sha512ChecksumAlg(L"sha-512");
  29. const UnicodeString Md5ChecksumAlg(L"md5");
  30. // Not defined by IANA
  31. const UnicodeString Crc32ChecksumAlg(L"crc32");
  32. //---------------------------------------------------------------------------
  33. const UnicodeString SshFingerprintType(L"ssh");
  34. const UnicodeString TlsFingerprintType(L"tls");
  35. //---------------------------------------------------------------------------
  36. const UnicodeString HttpsCertificateStorageKey(L"HttpsCertificates");
  37. //---------------------------------------------------------------------------
  38. __fastcall TConfiguration::TConfiguration()
  39. {
  40. FCriticalSection = new TCriticalSection();
  41. FUpdating = 0;
  42. FStorage = stDetect;
  43. FDontSave = false;
  44. FForceSave = false;
  45. FApplicationInfo = NULL;
  46. FUsage = new TUsage(this);
  47. FDefaultCollectUsage = false;
  48. FScripting = false;
  49. UnicodeString RandomSeedPath;
  50. if (!GetEnvironmentVariable(L"APPDATA").IsEmpty())
  51. {
  52. RandomSeedPath = L"%APPDATA%";
  53. }
  54. else
  55. {
  56. RandomSeedPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA);
  57. if (RandomSeedPath.IsEmpty())
  58. {
  59. RandomSeedPath = GetShellFolderPath(CSIDL_APPDATA);
  60. }
  61. }
  62. FDefaultRandomSeedFile = IncludeTrailingBackslash(RandomSeedPath) + L"winscp.rnd";
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TConfiguration::Default()
  66. {
  67. TGuard Guard(FCriticalSection);
  68. FDisablePasswordStoring = false;
  69. FForceBanners = false;
  70. FDisableAcceptingHostKeys = false;
  71. TRegistryStorage * AdminStorage;
  72. AdminStorage = new TRegistryStorage(RegistryStorageKey, HKEY_LOCAL_MACHINE);
  73. try
  74. {
  75. if (AdminStorage->OpenRootKey(false))
  76. {
  77. LoadAdmin(AdminStorage);
  78. AdminStorage->CloseSubKey();
  79. }
  80. }
  81. __finally
  82. {
  83. delete AdminStorage;
  84. }
  85. RandomSeedFile = FDefaultRandomSeedFile;
  86. PuttyRegistryStorageKey = OriginalPuttyRegistryStorageKey;
  87. FConfirmOverwriting = true;
  88. FConfirmResume = true;
  89. FAutoReadDirectoryAfterOp = true;
  90. FSessionReopenAuto = 5000;
  91. FSessionReopenBackground = 2000;
  92. FSessionReopenTimeout = 0;
  93. FSessionReopenAutoStall = 60000;
  94. FTunnelLocalPortNumberLow = 50000;
  95. FTunnelLocalPortNumberHigh = 50099;
  96. FCacheDirectoryChangesMaxSize = 100;
  97. FShowFtpWelcomeMessage = false;
  98. FExternalIpAddress = L"";
  99. FTryFtpWhenSshFails = true;
  100. FParallelDurationThreshold = 10;
  101. FMimeTypes = UnicodeString();
  102. FDontReloadMoreThanSessions = 1000;
  103. CollectUsage = FDefaultCollectUsage;
  104. FLogging = false;
  105. FPermanentLogging = false;
  106. FLogFileName = DefaultLogFileName;
  107. FPermanentLogFileName = FLogFileName;
  108. FLogFileAppend = true;
  109. FLogSensitive = false;
  110. FPermanentLogSensitive = FLogSensitive;
  111. FLogMaxSize = 0;
  112. FPermanentLogMaxSize = FLogMaxSize;
  113. FLogMaxCount = 0;
  114. FPermanentLogMaxCount = FLogMaxCount;
  115. FLogProtocol = 0;
  116. FPermanentLogProtocol = FLogProtocol;
  117. UpdateActualLogProtocol();
  118. FLogActions = false;
  119. FPermanentLogActions = false;
  120. FLogActionsRequired = false;
  121. FActionsLogFileName = L"%TEMP%\\!S.xml";
  122. FPermanentActionsLogFileName = FActionsLogFileName;
  123. FProgramIniPathWrittable = -1;
  124. FCustomIniFileStorageName = LoadCustomIniFileStorageName();
  125. Changed();
  126. }
  127. //---------------------------------------------------------------------------
  128. __fastcall TConfiguration::~TConfiguration()
  129. {
  130. DebugAssert(!FUpdating);
  131. if (FApplicationInfo) FreeFileInfo(FApplicationInfo);
  132. delete FCriticalSection;
  133. delete FUsage;
  134. }
  135. //---------------------------------------------------------------------------
  136. void __fastcall TConfiguration::UpdateStaticUsage()
  137. {
  138. Usage->Set(L"ConfigurationIniFile", (Storage == stIniFile));
  139. Usage->Set(L"ConfigurationIniFileCustom", !CustomIniFileStorageName.IsEmpty());
  140. Usage->Set("Unofficial", IsUnofficial);
  141. // this is called from here, because we are guarded from calling into
  142. // master password handler here, see TWinConfiguration::UpdateStaticUsage
  143. StoredSessions->UpdateStaticUsage();
  144. }
  145. //---------------------------------------------------------------------------
  146. THierarchicalStorage * TConfiguration::CreateConfigStorage()
  147. {
  148. bool SessionList = false;
  149. return CreateScpStorage(SessionList);
  150. }
  151. //---------------------------------------------------------------------------
  152. THierarchicalStorage * TConfiguration::CreateScpStorage(bool & SessionList)
  153. {
  154. TGuard Guard(FCriticalSection);
  155. THierarchicalStorage * Result;
  156. if (Storage == stRegistry)
  157. {
  158. Result = new TRegistryStorage(RegistryStorageKey);
  159. }
  160. else if (Storage == stNul)
  161. {
  162. Result = TIniFileStorage::CreateFromPath(INI_NUL);
  163. }
  164. else
  165. {
  166. UnicodeString StorageName = IniFileStorageName;
  167. Result = TIniFileStorage::CreateFromPath(StorageName);
  168. }
  169. if ((FOptionsStorage.get() != NULL) && (FOptionsStorage->Count > 0))
  170. {
  171. if (!SessionList)
  172. {
  173. Result = new TOptionsStorage(FOptionsStorage.get(), ConfigurationSubKey, Result);
  174. }
  175. else
  176. {
  177. // cannot reuse session list storage for configuration as for it we need
  178. // the option-override storage above
  179. }
  180. }
  181. else
  182. {
  183. // All the above stores can be reused for configuration,
  184. // if no options-overrides are set
  185. SessionList = false;
  186. }
  187. return Result;
  188. }
  189. //---------------------------------------------------------------------------
  190. UnicodeString __fastcall TConfiguration::PropertyToKey(const UnicodeString & Property)
  191. {
  192. // no longer useful
  193. int P = Property.LastDelimiter(L".>");
  194. return Property.SubString(P + 1, Property.Length() - P);
  195. }
  196. //---------------------------------------------------------------------------
  197. #define BLOCK(KEY, CANCREATE, BLOCK) \
  198. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  199. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  200. #define REGCONFIG(CANCREATE) \
  201. BLOCK(L"Interface", CANCREATE, \
  202. KEY(String, RandomSeedFile); \
  203. KEY(String, PuttyRegistryStorageKey); \
  204. KEY(Bool, ConfirmOverwriting); \
  205. KEY(Bool, ConfirmResume); \
  206. KEY(Bool, AutoReadDirectoryAfterOp); \
  207. KEY(Integer, SessionReopenAuto); \
  208. KEY(Integer, SessionReopenBackground); \
  209. KEY(Integer, SessionReopenTimeout); \
  210. KEY(Integer, SessionReopenAutoStall); \
  211. KEY(Integer, TunnelLocalPortNumberLow); \
  212. KEY(Integer, TunnelLocalPortNumberHigh); \
  213. KEY(Integer, CacheDirectoryChangesMaxSize); \
  214. KEY(Bool, ShowFtpWelcomeMessage); \
  215. KEY(String, ExternalIpAddress); \
  216. KEY(Bool, TryFtpWhenSshFails); \
  217. KEY(Integer, ParallelDurationThreshold); \
  218. KEY(String, MimeTypes); \
  219. KEY(Integer, DontReloadMoreThanSessions); \
  220. KEY(Bool, CollectUsage); \
  221. ); \
  222. BLOCK(L"Logging", CANCREATE, \
  223. KEYEX(Bool, PermanentLogging, L"Logging"); \
  224. KEYEX(String,PermanentLogFileName, L"LogFileName"); \
  225. KEY(Bool, LogFileAppend); \
  226. KEYEX(Bool, PermanentLogSensitive, L"LogSensitive"); \
  227. KEYEX(Int64, PermanentLogMaxSize, L"LogMaxSize"); \
  228. KEYEX(Integer, PermanentLogMaxCount, L"LogMaxCount"); \
  229. KEYEX(Integer,PermanentLogProtocol, L"LogProtocol"); \
  230. KEYEX(Bool, PermanentLogActions, L"LogActions"); \
  231. KEYEX(String,PermanentActionsLogFileName, L"ActionsLogFileName"); \
  232. );
  233. //---------------------------------------------------------------------------
  234. void __fastcall TConfiguration::SaveData(THierarchicalStorage * Storage, bool /*All*/)
  235. {
  236. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  237. REGCONFIG(true);
  238. #undef KEYEX
  239. if (Storage->OpenSubKey(L"Usage", true))
  240. {
  241. FUsage->Save(Storage);
  242. Storage->CloseSubKey();
  243. }
  244. }
  245. //---------------------------------------------------------------------------
  246. void __fastcall TConfiguration::Save()
  247. {
  248. // only modified, implicit
  249. DoSave(false, false);
  250. }
  251. //---------------------------------------------------------------------------
  252. void __fastcall TConfiguration::SaveExplicit()
  253. {
  254. // only modified, explicit
  255. DoSave(false, true);
  256. }
  257. //---------------------------------------------------------------------------
  258. void __fastcall TConfiguration::DoSave(bool All, bool Explicit)
  259. {
  260. if (FDontSave) return;
  261. THierarchicalStorage * AStorage = CreateConfigStorage();
  262. try
  263. {
  264. AStorage->AccessMode = smReadWrite;
  265. AStorage->Explicit = Explicit;
  266. AStorage->ForceSave = FForceSave;
  267. if (AStorage->OpenSubKey(ConfigurationSubKey, true))
  268. {
  269. // if saving to TOptionsStorage, make sure we save everything so that
  270. // all configuration is properly transferred to the master storage
  271. bool ConfigAll = All || AStorage->Temporary;
  272. SaveData(AStorage, ConfigAll);
  273. }
  274. }
  275. __finally
  276. {
  277. delete AStorage;
  278. }
  279. Saved();
  280. if (All)
  281. {
  282. StoredSessions->Save(true, Explicit);
  283. }
  284. // clean up as last, so that if it fails (read only INI), the saving can proceed
  285. if (Storage == stRegistry)
  286. {
  287. CleanupIniFile();
  288. }
  289. SaveCustomIniFileStorageName();
  290. }
  291. //---------------------------------------------------------------------------
  292. void __fastcall TConfiguration::SaveCustomIniFileStorageName()
  293. {
  294. // Particularly, not to create an empty "Override" key, unless the custom INI file is ever set
  295. if (CustomIniFileStorageName != LoadCustomIniFileStorageName())
  296. {
  297. std::unique_ptr<TRegistryStorage> RegistryStorage(new TRegistryStorage(GetRegistryStorageOverrideKey()));
  298. RegistryStorage->AccessMode = smReadWrite;
  299. RegistryStorage->Explicit = true;
  300. if (RegistryStorage->OpenRootKey(true))
  301. {
  302. RegistryStorage->WriteString(L"IniFile", CustomIniFileStorageName);
  303. RegistryStorage->CloseSubKey();
  304. }
  305. }
  306. }
  307. //---------------------------------------------------------------------------
  308. void __fastcall TConfiguration::Export(const UnicodeString & FileName)
  309. {
  310. // not to "append" the export to an existing file
  311. if (FileExists(FileName))
  312. {
  313. DeleteFileChecked(FileName);
  314. }
  315. THierarchicalStorage * Storage = NULL;
  316. THierarchicalStorage * ExportStorage = NULL;
  317. try
  318. {
  319. ExportStorage = TIniFileStorage::CreateFromPath(FileName);
  320. ExportStorage->AccessMode = smReadWrite;
  321. ExportStorage->Explicit = true;
  322. Storage = CreateConfigStorage();
  323. Storage->AccessMode = smRead;
  324. CopyData(Storage, ExportStorage);
  325. if (ExportStorage->OpenSubKey(ConfigurationSubKey, true))
  326. {
  327. SaveData(ExportStorage, true);
  328. }
  329. }
  330. __finally
  331. {
  332. delete ExportStorage;
  333. delete Storage;
  334. }
  335. StoredSessions->Export(FileName);
  336. }
  337. //---------------------------------------------------------------------------
  338. void __fastcall TConfiguration::Import(const UnicodeString & FileName)
  339. {
  340. THierarchicalStorage * Storage = NULL;
  341. THierarchicalStorage * ImportStorage = NULL;
  342. try
  343. {
  344. ImportStorage = TIniFileStorage::CreateFromPath(FileName);
  345. ImportStorage->AccessMode = smRead;
  346. Storage = CreateConfigStorage();
  347. Storage->AccessMode = smReadWrite;
  348. Storage->Explicit = true;
  349. CopyData(ImportStorage, Storage);
  350. Default();
  351. LoadFrom(ImportStorage);
  352. if (ImportStorage->OpenSubKey(Configuration->StoredSessionsSubKey, false))
  353. {
  354. StoredSessions->Clear();
  355. StoredSessions->DefaultSettings->Default();
  356. StoredSessions->Load(ImportStorage);
  357. }
  358. }
  359. __finally
  360. {
  361. delete ImportStorage;
  362. delete Storage;
  363. }
  364. // save all and explicit
  365. DoSave(true, true);
  366. }
  367. //---------------------------------------------------------------------------
  368. void __fastcall TConfiguration::LoadData(THierarchicalStorage * Storage)
  369. {
  370. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  371. #pragma warn -eas
  372. REGCONFIG(false);
  373. #pragma warn +eas
  374. #undef KEYEX
  375. if (Storage->OpenSubKey(L"Usage", false))
  376. {
  377. FUsage->Load(Storage);
  378. Storage->CloseSubKey();
  379. }
  380. if (FPermanentLogActions && FPermanentActionsLogFileName.IsEmpty() &&
  381. FPermanentLogging && !FPermanentLogFileName.IsEmpty())
  382. {
  383. FPermanentActionsLogFileName = FPermanentLogFileName;
  384. FPermanentLogging = false;
  385. FPermanentLogFileName = L"";
  386. }
  387. }
  388. //---------------------------------------------------------------------------
  389. void __fastcall TConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  390. {
  391. FDisablePasswordStoring = Storage->ReadBool(L"DisablePasswordStoring", FDisablePasswordStoring);
  392. FForceBanners = Storage->ReadBool(L"ForceBanners", FForceBanners);
  393. FDisableAcceptingHostKeys = Storage->ReadBool(L"DisableAcceptingHostKeys", FDisableAcceptingHostKeys);
  394. FDefaultCollectUsage = Storage->ReadBool(L"DefaultCollectUsage", FDefaultCollectUsage);
  395. }
  396. //---------------------------------------------------------------------------
  397. void __fastcall TConfiguration::LoadFrom(THierarchicalStorage * Storage)
  398. {
  399. if (Storage->OpenSubKey(ConfigurationSubKey, false))
  400. {
  401. LoadData(Storage);
  402. Storage->CloseSubKey();
  403. }
  404. }
  405. //---------------------------------------------------------------------------
  406. UnicodeString __fastcall TConfiguration::GetRegistryStorageOverrideKey()
  407. {
  408. return GetRegistryStorageKey() + L" Override";
  409. }
  410. //---------------------------------------------------------------------------
  411. UnicodeString __fastcall TConfiguration::LoadCustomIniFileStorageName()
  412. {
  413. UnicodeString Result;
  414. std::unique_ptr<TRegistryStorage> RegistryStorage(new TRegistryStorage(GetRegistryStorageOverrideKey()));
  415. if (RegistryStorage->OpenRootKey(false))
  416. {
  417. Result = RegistryStorage->ReadString(L"IniFile", L"");
  418. RegistryStorage->CloseSubKey();
  419. }
  420. RegistryStorage.reset(NULL);
  421. return Result;
  422. }
  423. //---------------------------------------------------------------------------
  424. void __fastcall TConfiguration::Load(THierarchicalStorage * Storage)
  425. {
  426. TGuard Guard(FCriticalSection);
  427. TStorageAccessMode StorageAccessMode = Storage->AccessMode;
  428. try
  429. {
  430. Storage->AccessMode = smRead;
  431. LoadFrom(Storage);
  432. }
  433. __finally
  434. {
  435. Storage->AccessMode = StorageAccessMode;
  436. }
  437. }
  438. //---------------------------------------------------------------------------
  439. void __fastcall TConfiguration::CopyData(THierarchicalStorage * Source,
  440. THierarchicalStorage * Target)
  441. {
  442. TStrings * Names = new TStringList();
  443. try
  444. {
  445. if (Source->OpenSubKey(ConfigurationSubKey, false))
  446. {
  447. if (Target->OpenSubKey(ConfigurationSubKey, true))
  448. {
  449. if (Source->OpenSubKey(L"CDCache", false))
  450. {
  451. if (Target->OpenSubKey(L"CDCache", true))
  452. {
  453. Names->Clear();
  454. Source->GetValueNames(Names);
  455. for (int Index = 0; Index < Names->Count; Index++)
  456. {
  457. Target->WriteBinaryData(Names->Strings[Index],
  458. Source->ReadBinaryData(Names->Strings[Index]));
  459. }
  460. Target->CloseSubKey();
  461. }
  462. Source->CloseSubKey();
  463. }
  464. if (Source->OpenSubKey(L"Banners", false))
  465. {
  466. if (Target->OpenSubKey(L"Banners", true))
  467. {
  468. Names->Clear();
  469. Source->GetValueNames(Names);
  470. for (int Index = 0; Index < Names->Count; Index++)
  471. {
  472. Target->WriteString(Names->Strings[Index],
  473. Source->ReadString(Names->Strings[Index], L""));
  474. }
  475. Target->CloseSubKey();
  476. }
  477. Source->CloseSubKey();
  478. }
  479. Target->CloseSubKey();
  480. }
  481. Source->CloseSubKey();
  482. }
  483. if (Source->OpenSubKey(SshHostKeysSubKey, false))
  484. {
  485. if (Target->OpenSubKey(SshHostKeysSubKey, true))
  486. {
  487. Names->Clear();
  488. Source->GetValueNames(Names);
  489. for (int Index = 0; Index < Names->Count; Index++)
  490. {
  491. Target->WriteStringRaw(Names->Strings[Index],
  492. Source->ReadStringRaw(Names->Strings[Index], L""));
  493. }
  494. Target->CloseSubKey();
  495. }
  496. Source->CloseSubKey();
  497. }
  498. }
  499. __finally
  500. {
  501. delete Names;
  502. }
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TConfiguration::LoadDirectoryChangesCache(const UnicodeString SessionKey,
  506. TRemoteDirectoryChangesCache * DirectoryChangesCache)
  507. {
  508. THierarchicalStorage * Storage = CreateConfigStorage();
  509. try
  510. {
  511. Storage->AccessMode = smRead;
  512. if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
  513. Storage->OpenSubKey(L"CDCache", false) &&
  514. Storage->ValueExists(SessionKey))
  515. {
  516. DirectoryChangesCache->Deserialize(Storage->ReadBinaryData(SessionKey));
  517. }
  518. }
  519. __finally
  520. {
  521. delete Storage;
  522. }
  523. }
  524. //---------------------------------------------------------------------------
  525. void __fastcall TConfiguration::SaveDirectoryChangesCache(const UnicodeString SessionKey,
  526. TRemoteDirectoryChangesCache * DirectoryChangesCache)
  527. {
  528. THierarchicalStorage * Storage = CreateConfigStorage();
  529. try
  530. {
  531. Storage->AccessMode = smReadWrite;
  532. if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
  533. Storage->OpenSubKey(L"CDCache", true))
  534. {
  535. UnicodeString Data;
  536. DirectoryChangesCache->Serialize(Data);
  537. Storage->WriteBinaryData(SessionKey, Data);
  538. }
  539. }
  540. __finally
  541. {
  542. delete Storage;
  543. }
  544. }
  545. //---------------------------------------------------------------------------
  546. UnicodeString __fastcall TConfiguration::BannerHash(const UnicodeString & Banner)
  547. {
  548. RawByteString Result;
  549. Result.SetLength(16);
  550. md5checksum(
  551. reinterpret_cast<const char*>(Banner.c_str()), Banner.Length() * sizeof(wchar_t),
  552. (unsigned char*)Result.c_str());
  553. return BytesToHex(Result);
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TConfiguration::GetBannerData(
  557. const UnicodeString & SessionKey, UnicodeString & BannerHash, unsigned int & Params)
  558. {
  559. BannerHash = UnicodeString();
  560. Params = 0;
  561. std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
  562. Storage->AccessMode = smRead;
  563. if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
  564. Storage->OpenSubKey(L"Banners", false))
  565. {
  566. UnicodeString S = Storage->ReadString(SessionKey, L"");
  567. BannerHash = CutToChar(S, L',', true);
  568. Params = StrToIntDef(L"$" + CutToChar(S, L',', true), 0);
  569. }
  570. }
  571. //---------------------------------------------------------------------------
  572. bool __fastcall TConfiguration::ShowBanner(
  573. const UnicodeString & SessionKey, const UnicodeString & Banner, unsigned int & Params)
  574. {
  575. UnicodeString StoredBannerHash;
  576. GetBannerData(SessionKey, StoredBannerHash, Params);
  577. bool Result = (StoredBannerHash != BannerHash(Banner));
  578. return Result;
  579. }
  580. //---------------------------------------------------------------------------
  581. void __fastcall TConfiguration::SetBannerData(
  582. const UnicodeString & SessionKey, const UnicodeString & BannerHash, unsigned int Params)
  583. {
  584. std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
  585. Storage->AccessMode = smReadWrite;
  586. if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
  587. Storage->OpenSubKey(L"Banners", true))
  588. {
  589. Storage->WriteString(SessionKey, BannerHash + L"," + UIntToStr(Params));
  590. }
  591. }
  592. //---------------------------------------------------------------------------
  593. void __fastcall TConfiguration::NeverShowBanner(const UnicodeString & SessionKey, const UnicodeString & Banner)
  594. {
  595. UnicodeString DummyBannerHash;
  596. unsigned int Params;
  597. GetBannerData(SessionKey, DummyBannerHash, Params);
  598. SetBannerData(SessionKey, BannerHash(Banner), Params);
  599. }
  600. //---------------------------------------------------------------------------
  601. void __fastcall TConfiguration::SetBannerParams(const UnicodeString & SessionKey, unsigned int Params)
  602. {
  603. UnicodeString BannerHash;
  604. unsigned int DummyParams;
  605. GetBannerData(SessionKey, BannerHash, DummyParams);
  606. SetBannerData(SessionKey, BannerHash, Params);
  607. }
  608. //---------------------------------------------------------------------------
  609. UnicodeString __fastcall TConfiguration::FormatFingerprintKey(const UnicodeString & SiteKey, const UnicodeString & FingerprintType)
  610. {
  611. return FORMAT(L"%s:%s", (SiteKey, FingerprintType));
  612. }
  613. //---------------------------------------------------------------------------
  614. void __fastcall TConfiguration::RememberLastFingerprint(const UnicodeString & SiteKey, const UnicodeString & FingerprintType, const UnicodeString & Fingerprint)
  615. {
  616. std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
  617. Storage->AccessMode = smReadWrite;
  618. if (Storage->OpenSubKey(ConfigurationSubKey, true) &&
  619. Storage->OpenSubKey(L"LastFingerprints", true))
  620. {
  621. UnicodeString FingerprintKey = FormatFingerprintKey(SiteKey, FingerprintType);
  622. Storage->WriteString(FingerprintKey, Fingerprint);
  623. }
  624. }
  625. //---------------------------------------------------------------------------
  626. UnicodeString __fastcall TConfiguration::LastFingerprint(const UnicodeString & SiteKey, const UnicodeString & FingerprintType)
  627. {
  628. UnicodeString Result;
  629. std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
  630. Storage->AccessMode = smRead;
  631. if (Storage->OpenSubKey(ConfigurationSubKey, false) &&
  632. Storage->OpenSubKey(L"LastFingerprints", false))
  633. {
  634. UnicodeString FingerprintKey = FormatFingerprintKey(SiteKey, FingerprintType);
  635. Result = Storage->ReadString(FingerprintKey, L"");
  636. }
  637. return Result;
  638. }
  639. //---------------------------------------------------------------------------
  640. void __fastcall TConfiguration::Changed()
  641. {
  642. TNotifyEvent AOnChange = NULL;
  643. {
  644. TGuard Guard(FCriticalSection);
  645. if (FUpdating == 0)
  646. {
  647. AOnChange = OnChange;
  648. }
  649. else
  650. {
  651. FChanged = true;
  652. }
  653. }
  654. // No specific reason to call this outside of a guard, just that it is less of a change to a previous unguarded code
  655. if (AOnChange != NULL)
  656. {
  657. AOnChange(this);
  658. }
  659. }
  660. //---------------------------------------------------------------------------
  661. void __fastcall TConfiguration::BeginUpdate()
  662. {
  663. FCriticalSection->Enter();
  664. if (FUpdating == 0)
  665. {
  666. FChanged = false;
  667. }
  668. FUpdating++;
  669. // Greater value would probably indicate some nesting problem in code
  670. DebugAssert(FUpdating < 6);
  671. }
  672. //---------------------------------------------------------------------------
  673. void __fastcall TConfiguration::EndUpdate()
  674. {
  675. DebugAssert(FUpdating > 0);
  676. FUpdating--;
  677. if ((FUpdating == 0) && FChanged)
  678. {
  679. FChanged = false;
  680. Changed();
  681. }
  682. FCriticalSection->Leave();
  683. }
  684. //---------------------------------------------------------------------------
  685. void __fastcall TConfiguration::CleanupConfiguration()
  686. {
  687. try
  688. {
  689. CleanupRegistry(ConfigurationSubKey);
  690. if (Storage == stRegistry)
  691. {
  692. FDontSave = true;
  693. }
  694. }
  695. catch (Exception &E)
  696. {
  697. throw ExtException(&E, LoadStr(CLEANUP_CONFIG_ERROR));
  698. }
  699. }
  700. //---------------------------------------------------------------------------
  701. void __fastcall TConfiguration::CleanupRegistry(UnicodeString CleanupSubKey)
  702. {
  703. TRegistryStorage *Registry = new TRegistryStorage(RegistryStorageKey);
  704. try
  705. {
  706. Registry->RecursiveDeleteSubKey(CleanupSubKey);
  707. }
  708. __finally
  709. {
  710. delete Registry;
  711. }
  712. }
  713. //---------------------------------------------------------------------------
  714. void __fastcall TConfiguration::CleanupHostKeys()
  715. {
  716. try
  717. {
  718. CleanupRegistry(SshHostKeysSubKey);
  719. }
  720. catch (Exception &E)
  721. {
  722. throw ExtException(&E, LoadStr(CLEANUP_HOSTKEYS_ERROR));
  723. }
  724. }
  725. //---------------------------------------------------------------------------
  726. void __fastcall TConfiguration::CleanupRandomSeedFile()
  727. {
  728. try
  729. {
  730. DontSaveRandomSeed();
  731. if (FileExists(ApiPath(RandomSeedFileName)))
  732. {
  733. DeleteFileChecked(RandomSeedFileName);
  734. }
  735. }
  736. catch (Exception &E)
  737. {
  738. throw ExtException(&E, LoadStr(CLEANUP_SEEDFILE_ERROR));
  739. }
  740. }
  741. //---------------------------------------------------------------------------
  742. void __fastcall TConfiguration::CleanupIniFile()
  743. {
  744. try
  745. {
  746. if (FileExists(ApiPath(IniFileStorageNameForReading)))
  747. {
  748. DeleteFileChecked(IniFileStorageNameForReading);
  749. }
  750. if (Storage == stIniFile)
  751. {
  752. FDontSave = true;
  753. }
  754. }
  755. catch (Exception &E)
  756. {
  757. throw ExtException(&E, LoadStr(CLEANUP_INIFILE_ERROR));
  758. }
  759. }
  760. //---------------------------------------------------------------------------
  761. void __fastcall TConfiguration::DontSave()
  762. {
  763. FDontSave = true;
  764. }
  765. //---------------------------------------------------------------------------
  766. RawByteString __fastcall TConfiguration::EncryptPassword(UnicodeString Password, UnicodeString Key)
  767. {
  768. if (Password.IsEmpty())
  769. {
  770. return RawByteString();
  771. }
  772. else
  773. {
  774. return ::EncryptPassword(Password, Key);
  775. }
  776. }
  777. //---------------------------------------------------------------------------
  778. UnicodeString __fastcall TConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
  779. {
  780. if (Password.IsEmpty())
  781. {
  782. return UnicodeString();
  783. }
  784. else
  785. {
  786. return ::DecryptPassword(Password, Key);
  787. }
  788. }
  789. //---------------------------------------------------------------------------
  790. RawByteString __fastcall TConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString /*Key*/)
  791. {
  792. return Password;
  793. }
  794. //---------------------------------------------------------------------------
  795. TVSFixedFileInfo *__fastcall TConfiguration::GetFixedApplicationInfo()
  796. {
  797. return GetFixedFileInfo(ApplicationInfo);
  798. }
  799. //---------------------------------------------------------------------------
  800. int __fastcall TConfiguration::GetCompoundVersion()
  801. {
  802. TVSFixedFileInfo * FileInfo = FixedApplicationInfo;
  803. return CalculateCompoundVersion(
  804. HIWORD(FileInfo->dwFileVersionMS), LOWORD(FileInfo->dwFileVersionMS),
  805. HIWORD(FileInfo->dwFileVersionLS), LOWORD(FileInfo->dwFileVersionLS));
  806. }
  807. //---------------------------------------------------------------------------
  808. UnicodeString __fastcall TConfiguration::ModuleFileName()
  809. {
  810. return ParamStr(0);
  811. }
  812. //---------------------------------------------------------------------------
  813. void * __fastcall TConfiguration::GetFileApplicationInfo(const UnicodeString FileName)
  814. {
  815. void * Result;
  816. if (FileName.IsEmpty())
  817. {
  818. if (!FApplicationInfo)
  819. {
  820. FApplicationInfo = CreateFileInfo(ModuleFileName());
  821. }
  822. Result = FApplicationInfo;
  823. }
  824. else
  825. {
  826. Result = CreateFileInfo(FileName);
  827. }
  828. return Result;
  829. }
  830. //---------------------------------------------------------------------------
  831. void * __fastcall TConfiguration::GetApplicationInfo()
  832. {
  833. return GetFileApplicationInfo("");
  834. }
  835. //---------------------------------------------------------------------------
  836. UnicodeString __fastcall TConfiguration::GetFileProductName(const UnicodeString FileName)
  837. {
  838. return GetFileFileInfoString(L"ProductName", FileName);
  839. }
  840. //---------------------------------------------------------------------------
  841. UnicodeString __fastcall TConfiguration::GetFileCompanyName(const UnicodeString FileName)
  842. {
  843. // particularly in IDE build, company name is empty
  844. return GetFileFileInfoString(L"CompanyName", FileName, true);
  845. }
  846. //---------------------------------------------------------------------------
  847. UnicodeString __fastcall TConfiguration::GetProductName()
  848. {
  849. return GetFileProductName(L"");
  850. }
  851. //---------------------------------------------------------------------------
  852. UnicodeString __fastcall TConfiguration::GetCompanyName()
  853. {
  854. return GetFileCompanyName(L"");
  855. }
  856. //---------------------------------------------------------------------------
  857. UnicodeString __fastcall TConfiguration::GetFileProductVersion(const UnicodeString FileName)
  858. {
  859. return TrimVersion(GetFileFileInfoString(L"ProductVersion", FileName));
  860. }
  861. //---------------------------------------------------------------------------
  862. UnicodeString __fastcall TConfiguration::GetFileDescription(const UnicodeString & FileName)
  863. {
  864. return GetFileFileInfoString(L"FileDescription", FileName);
  865. }
  866. //---------------------------------------------------------------------------
  867. UnicodeString __fastcall TConfiguration::GetProductVersion()
  868. {
  869. return GetFileProductVersion(L"");
  870. }
  871. //---------------------------------------------------------------------------
  872. UnicodeString __fastcall TConfiguration::GetReleaseType()
  873. {
  874. return GetFileInfoString(L"ReleaseType");
  875. }
  876. //---------------------------------------------------------------------------
  877. bool __fastcall TConfiguration::GetIsUnofficial()
  878. {
  879. #ifdef BUILD_OFFICIAL
  880. return false;
  881. #else
  882. return true;
  883. #endif
  884. }
  885. //---------------------------------------------------------------------------
  886. UnicodeString __fastcall TConfiguration::GetVersionStr()
  887. {
  888. TGuard Guard(FCriticalSection);
  889. try
  890. {
  891. UnicodeString BuildStr;
  892. if (!IsUnofficial)
  893. {
  894. BuildStr = LoadStr(VERSION_BUILD);
  895. }
  896. else
  897. {
  898. #ifdef _DEBUG
  899. BuildStr = LoadStr(VERSION_DEBUG_BUILD);
  900. #else
  901. BuildStr = LoadStr(VERSION_DEV_BUILD);
  902. #endif
  903. }
  904. int Build = LOWORD(FixedApplicationInfo->dwFileVersionLS);
  905. if (Build > 0)
  906. {
  907. BuildStr += L" " + IntToStr(Build);
  908. }
  909. #ifndef BUILD_OFFICIAL
  910. UnicodeString BuildDate = __DATE__;
  911. UnicodeString MonthStr = CutToChar(BuildDate, L' ', true);
  912. int Month = ParseShortEngMonthName(MonthStr);
  913. int Day = StrToInt(CutToChar(BuildDate, L' ', true));
  914. int Year = StrToInt(Trim(BuildDate));
  915. UnicodeString DateStr = FORMAT(L"%d-%2.2d-%2.2d", (Year, Month, Day));
  916. AddToList(BuildStr, DateStr, L" ");
  917. #endif
  918. UnicodeString FullVersion = Version;
  919. UnicodeString AReleaseType = GetReleaseType();
  920. if (DebugAlwaysTrue(!AReleaseType.IsEmpty()) &&
  921. !SameText(AReleaseType, L"stable") &&
  922. !SameText(AReleaseType, L"development"))
  923. {
  924. FullVersion += L" " + AReleaseType;
  925. }
  926. UnicodeString Result = FMTLOAD(VERSION2, (FullVersion, BuildStr));
  927. #ifndef BUILD_OFFICIAL
  928. Result += L" " + LoadStr(VERSION_DONT_DISTRIBUTE);
  929. #endif
  930. return Result;
  931. }
  932. catch (Exception &E)
  933. {
  934. throw ExtException(&E, L"Can't get application version");
  935. }
  936. }
  937. //---------------------------------------------------------------------------
  938. UnicodeString __fastcall TConfiguration::GetFileVersion(const UnicodeString & FileName)
  939. {
  940. UnicodeString Result;
  941. void * FileInfo = CreateFileInfo(FileName);
  942. try
  943. {
  944. Result = GetFileVersion(GetFixedFileInfo(FileInfo));
  945. }
  946. __finally
  947. {
  948. FreeFileInfo(FileInfo);
  949. }
  950. return Result;
  951. }
  952. //---------------------------------------------------------------------------
  953. UnicodeString __fastcall TConfiguration::GetFileVersion(TVSFixedFileInfo * Info)
  954. {
  955. TGuard Guard(FCriticalSection);
  956. try
  957. {
  958. UnicodeString Result =
  959. FormatVersion(
  960. HIWORD(Info->dwFileVersionMS),
  961. LOWORD(Info->dwFileVersionMS),
  962. HIWORD(Info->dwFileVersionLS));
  963. return Result;
  964. }
  965. catch (Exception &E)
  966. {
  967. throw ExtException(&E, L"Can't get file version");
  968. }
  969. }
  970. //---------------------------------------------------------------------------
  971. UnicodeString __fastcall TConfiguration::GetVersion()
  972. {
  973. return GetFileVersion(FixedApplicationInfo);
  974. }
  975. //---------------------------------------------------------------------------
  976. UnicodeString __fastcall TConfiguration::GetFileFileInfoString(const UnicodeString Key,
  977. const UnicodeString FileName, bool AllowEmpty)
  978. {
  979. TGuard Guard(FCriticalSection);
  980. UnicodeString Result;
  981. void * Info = GetFileApplicationInfo(FileName);
  982. try
  983. {
  984. if ((Info != NULL) && (GetTranslationCount(Info) > 0))
  985. {
  986. TTranslation Translation;
  987. Translation = GetTranslation(Info, 0);
  988. Result = ::GetFileInfoString(Info, Translation, Key, AllowEmpty);
  989. }
  990. else
  991. {
  992. DebugAssert(!FileName.IsEmpty());
  993. }
  994. }
  995. __finally
  996. {
  997. if (!FileName.IsEmpty())
  998. {
  999. FreeFileInfo(Info);
  1000. }
  1001. }
  1002. return Result;
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. UnicodeString __fastcall TConfiguration::GetFileInfoString(const UnicodeString Key)
  1006. {
  1007. return GetFileFileInfoString(Key, L"");
  1008. }
  1009. //---------------------------------------------------------------------------
  1010. UnicodeString __fastcall TConfiguration::GetFileMimeType(const UnicodeString & FileName)
  1011. {
  1012. UnicodeString Result;
  1013. bool Found = false;
  1014. if (!MimeTypes.IsEmpty())
  1015. {
  1016. UnicodeString FileNameOnly = ExtractFileName(FileName);
  1017. UnicodeString AMimeTypes = MimeTypes;
  1018. while (!Found && !AMimeTypes.IsEmpty())
  1019. {
  1020. UnicodeString Token = CutToChar(AMimeTypes, L',', true);
  1021. UnicodeString MaskStr = CutToChar(Token, L'=', true);
  1022. TFileMasks Mask(MaskStr);
  1023. if (Mask.Matches(FileNameOnly))
  1024. {
  1025. Result = Token.Trim();
  1026. Found = true;
  1027. }
  1028. }
  1029. }
  1030. if (!Found) // allow an override to "no" Content-Type
  1031. {
  1032. Result = ::GetFileMimeType(FileName);
  1033. }
  1034. return Result;
  1035. }
  1036. //---------------------------------------------------------------------------
  1037. UnicodeString __fastcall TConfiguration::GetRegistryStorageKey()
  1038. {
  1039. return GetRegistryKey();
  1040. }
  1041. //---------------------------------------------------------------------------
  1042. void __fastcall TConfiguration::SetNulStorage()
  1043. {
  1044. FStorage = stNul;
  1045. }
  1046. //---------------------------------------------------------------------------
  1047. void __fastcall TConfiguration::SetDefaultStorage()
  1048. {
  1049. FStorage = stDetect;
  1050. }
  1051. //---------------------------------------------------------------------------
  1052. void __fastcall TConfiguration::SetIniFileStorageName(UnicodeString value)
  1053. {
  1054. FIniFileStorageName = value;
  1055. FStorage = stIniFile;
  1056. }
  1057. //---------------------------------------------------------------------------
  1058. UnicodeString __fastcall TConfiguration::GetDefaultIniFileExportPath()
  1059. {
  1060. UnicodeString PersonalDirectory = GetPersonalFolder();
  1061. UnicodeString FileName = IncludeTrailingBackslash(PersonalDirectory) +
  1062. ExtractFileName(ExpandEnvironmentVariables(IniFileStorageName));
  1063. return FileName;
  1064. }
  1065. //---------------------------------------------------------------------------
  1066. UnicodeString __fastcall TConfiguration::GetIniFileStorageNameForReading()
  1067. {
  1068. return GetIniFileStorageName(true);
  1069. }
  1070. //---------------------------------------------------------------------------
  1071. UnicodeString __fastcall TConfiguration::GetIniFileStorageNameForReadingWriting()
  1072. {
  1073. return GetIniFileStorageName(false);
  1074. }
  1075. //---------------------------------------------------------------------------
  1076. UnicodeString __fastcall TConfiguration::GetAutomaticIniFileStorageName(bool ReadingOnly)
  1077. {
  1078. UnicodeString ProgramPath = ParamStr(0);
  1079. UnicodeString ProgramIniPath = ChangeFileExt(ProgramPath, L".ini");
  1080. UnicodeString IniPath;
  1081. if (FileExists(ApiPath(ProgramIniPath)))
  1082. {
  1083. IniPath = ProgramIniPath;
  1084. }
  1085. else
  1086. {
  1087. UnicodeString AppDataIniPath =
  1088. IncludeTrailingBackslash(GetShellFolderPath(CSIDL_APPDATA)) +
  1089. ExtractFileName(ProgramIniPath);
  1090. if (FileExists(ApiPath(AppDataIniPath)))
  1091. {
  1092. IniPath = AppDataIniPath;
  1093. }
  1094. else
  1095. {
  1096. // avoid expensive test if we are interested in existing files only
  1097. if (!ReadingOnly && (FProgramIniPathWrittable < 0))
  1098. {
  1099. UnicodeString ProgramDir = ExtractFilePath(ProgramPath);
  1100. FProgramIniPathWrittable = IsDirectoryWriteable(ProgramDir) ? 1 : 0;
  1101. }
  1102. // does not really matter what we return when < 0
  1103. IniPath = (FProgramIniPathWrittable == 0) ? AppDataIniPath : ProgramIniPath;
  1104. }
  1105. }
  1106. // BACKWARD COMPATIBILITY with 4.x
  1107. if (FVirtualIniFileStorageName.IsEmpty() &&
  1108. TPath::IsDriveRooted(IniPath))
  1109. {
  1110. UnicodeString LocalAppDataPath = GetShellFolderPath(CSIDL_LOCAL_APPDATA);
  1111. // virtual store for non-system drives have a different virtual store,
  1112. // do not bother about them
  1113. if (TPath::IsDriveRooted(LocalAppDataPath) &&
  1114. SameText(ExtractFileDrive(IniPath), ExtractFileDrive(LocalAppDataPath)))
  1115. {
  1116. FVirtualIniFileStorageName =
  1117. IncludeTrailingBackslash(LocalAppDataPath) +
  1118. L"VirtualStore\\" +
  1119. IniPath.SubString(4, IniPath.Length() - 3);
  1120. }
  1121. }
  1122. if (!FVirtualIniFileStorageName.IsEmpty() &&
  1123. FileExists(ApiPath(FVirtualIniFileStorageName)))
  1124. {
  1125. return FVirtualIniFileStorageName;
  1126. }
  1127. else
  1128. {
  1129. return IniPath;
  1130. }
  1131. }
  1132. //---------------------------------------------------------------------------
  1133. UnicodeString __fastcall TConfiguration::GetIniFileStorageName(bool ReadingOnly)
  1134. {
  1135. UnicodeString Result;
  1136. if (!FIniFileStorageName.IsEmpty())
  1137. {
  1138. Result = FIniFileStorageName;
  1139. }
  1140. else if (!FCustomIniFileStorageName.IsEmpty())
  1141. {
  1142. Result = FCustomIniFileStorageName;
  1143. }
  1144. else
  1145. {
  1146. Result = GetAutomaticIniFileStorageName(ReadingOnly);
  1147. }
  1148. return Result;
  1149. }
  1150. //---------------------------------------------------------------------------
  1151. void __fastcall TConfiguration::SetOptionsStorage(TStrings * value)
  1152. {
  1153. TGuard Guard(FCriticalSection);
  1154. if (FOptionsStorage.get() == NULL)
  1155. {
  1156. FOptionsStorage.reset(new TStringList());
  1157. }
  1158. FOptionsStorage->AddStrings(value);
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. TStrings * __fastcall TConfiguration::GetOptionsStorage()
  1162. {
  1163. return FOptionsStorage.get();
  1164. }
  1165. //---------------------------------------------------------------------------
  1166. UnicodeString __fastcall TConfiguration::GetPuttySessionsKey()
  1167. {
  1168. return PuttyRegistryStorageKey + L"\\Sessions";
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. UnicodeString __fastcall TConfiguration::GetStoredSessionsSubKey()
  1172. {
  1173. return L"Sessions";
  1174. }
  1175. //---------------------------------------------------------------------------
  1176. UnicodeString __fastcall TConfiguration::GetSshHostKeysSubKey()
  1177. {
  1178. return L"SshHostKeys";
  1179. }
  1180. //---------------------------------------------------------------------------
  1181. UnicodeString __fastcall TConfiguration::GetConfigurationSubKey()
  1182. {
  1183. return L"Configuration";
  1184. }
  1185. //---------------------------------------------------------------------------
  1186. UnicodeString __fastcall TConfiguration::GetRootKeyStr()
  1187. {
  1188. return RootKeyToStr(HKEY_CURRENT_USER);
  1189. }
  1190. //---------------------------------------------------------------------------
  1191. void __fastcall TConfiguration::MoveStorage(TStorage AStorage, const UnicodeString & ACustomIniFileStorageName)
  1192. {
  1193. if ((FStorage != AStorage) ||
  1194. !IsPathToSameFile(FCustomIniFileStorageName, ACustomIniFileStorageName))
  1195. {
  1196. TStorage StorageBak = FStorage;
  1197. UnicodeString CustomIniFileStorageNameBak = FCustomIniFileStorageName;
  1198. try
  1199. {
  1200. THierarchicalStorage * SourceStorage = NULL;
  1201. THierarchicalStorage * TargetStorage = NULL;
  1202. try
  1203. {
  1204. SourceStorage = CreateConfigStorage();
  1205. SourceStorage->AccessMode = smRead;
  1206. FStorage = AStorage;
  1207. FCustomIniFileStorageName = ACustomIniFileStorageName;
  1208. TargetStorage = CreateConfigStorage();
  1209. TargetStorage->AccessMode = smReadWrite;
  1210. TargetStorage->Explicit = true;
  1211. // copy before save as it removes the ini file,
  1212. // when switching from ini to registry
  1213. CopyData(SourceStorage, TargetStorage);
  1214. }
  1215. __finally
  1216. {
  1217. delete SourceStorage;
  1218. delete TargetStorage;
  1219. }
  1220. // save all and explicit,
  1221. // this also removes an INI file, when switching to registry storage
  1222. DoSave(true, true);
  1223. }
  1224. catch (...)
  1225. {
  1226. // If this fails, do not pretend that storage was switched.
  1227. // For instance:
  1228. // - When writing to an INI file fails (unlikely, as we fallback to user profile)
  1229. // - When removing INI file fails, when switching to registry
  1230. // (possible, when the INI file is in Program Files folder)
  1231. FStorage = StorageBak;
  1232. FCustomIniFileStorageName = CustomIniFileStorageNameBak;
  1233. throw;
  1234. }
  1235. }
  1236. }
  1237. //---------------------------------------------------------------------------
  1238. void __fastcall TConfiguration::ScheduleCustomIniFileStorageUse(const UnicodeString & ACustomIniFileStorageName)
  1239. {
  1240. FStorage = stIniFile;
  1241. FCustomIniFileStorageName = ACustomIniFileStorageName;
  1242. SaveCustomIniFileStorageName();
  1243. }
  1244. //---------------------------------------------------------------------------
  1245. void __fastcall TConfiguration::Saved()
  1246. {
  1247. // nothing
  1248. }
  1249. //---------------------------------------------------------------------------
  1250. TStorage __fastcall TConfiguration::GetStorage()
  1251. {
  1252. TGuard Guard(FCriticalSection);
  1253. if (FStorage == stDetect)
  1254. {
  1255. if (FileExists(ApiPath(IniFileStorageNameForReading)))
  1256. {
  1257. FStorage = stIniFile;
  1258. }
  1259. else
  1260. {
  1261. FStorage = stRegistry;
  1262. }
  1263. }
  1264. return FStorage;
  1265. }
  1266. //---------------------------------------------------------------------
  1267. TStoredSessionList * __fastcall TConfiguration::SelectFilezillaSessionsForImport(
  1268. TStoredSessionList * Sessions, UnicodeString & Error)
  1269. {
  1270. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1271. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1272. UnicodeString AppDataPath = GetShellFolderPath(CSIDL_APPDATA);
  1273. UnicodeString FilezillaSiteManagerFile =
  1274. IncludeTrailingBackslash(AppDataPath) + L"FileZilla\\sitemanager.xml";
  1275. UnicodeString FilezillaConfigurationFile =
  1276. IncludeTrailingBackslash(AppDataPath) + L"FileZilla\\filezilla.xml";
  1277. if (FileExists(ApiPath(FilezillaSiteManagerFile)))
  1278. {
  1279. ImportSessionList->ImportFromFilezilla(FilezillaSiteManagerFile, FilezillaConfigurationFile);
  1280. if (ImportSessionList->Count > 0)
  1281. {
  1282. ImportSessionList->SelectSessionsToImport(Sessions, true);
  1283. }
  1284. else
  1285. {
  1286. Error = FMTLOAD(FILEZILLA_NO_SITES, (FilezillaSiteManagerFile));
  1287. }
  1288. }
  1289. else
  1290. {
  1291. Error = FMTLOAD(FILEZILLA_SITE_MANAGER_NOT_FOUND, (FilezillaSiteManagerFile));
  1292. }
  1293. return ImportSessionList.release();
  1294. }
  1295. //---------------------------------------------------------------------
  1296. bool __fastcall TConfiguration::AnyFilezillaSessionForImport(TStoredSessionList * Sessions)
  1297. {
  1298. try
  1299. {
  1300. UnicodeString Error;
  1301. std::unique_ptr<TStoredSessionList> Sesssions(SelectFilezillaSessionsForImport(Sessions, Error));
  1302. return (Sesssions->Count > 0);
  1303. }
  1304. catch (...)
  1305. {
  1306. return false;
  1307. }
  1308. }
  1309. //---------------------------------------------------------------------
  1310. TStoredSessionList * __fastcall TConfiguration::SelectKnownHostsSessionsForImport(
  1311. TStoredSessionList * Sessions, UnicodeString & Error)
  1312. {
  1313. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1314. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1315. UnicodeString ProfilePath = GetShellFolderPath(CSIDL_PROFILE);
  1316. UnicodeString KnownHostsFile = IncludeTrailingBackslash(ProfilePath) + L".ssh\\known_hosts";
  1317. try
  1318. {
  1319. if (FileExists(ApiPath(KnownHostsFile)))
  1320. {
  1321. std::unique_ptr<TStrings> Lines(new TStringList());
  1322. LoadScriptFromFile(KnownHostsFile, Lines.get());
  1323. ImportSessionList->ImportFromKnownHosts(Lines.get());
  1324. }
  1325. else
  1326. {
  1327. throw Exception(LoadStr(KNOWN_HOSTS_NOT_FOUND));
  1328. }
  1329. }
  1330. catch (Exception & E)
  1331. {
  1332. Error = FORMAT(L"%s\n(%s)", (E.Message, KnownHostsFile));
  1333. }
  1334. return ImportSessionList.release();
  1335. }
  1336. //---------------------------------------------------------------------
  1337. TStoredSessionList * __fastcall TConfiguration::SelectKnownHostsSessionsForImport(
  1338. TStrings * Lines, TStoredSessionList * Sessions, UnicodeString & Error)
  1339. {
  1340. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1341. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1342. try
  1343. {
  1344. ImportSessionList->ImportFromKnownHosts(Lines);
  1345. }
  1346. catch (Exception & E)
  1347. {
  1348. Error = E.Message;
  1349. }
  1350. return ImportSessionList.release();
  1351. }
  1352. //---------------------------------------------------------------------------
  1353. void __fastcall TConfiguration::SetRandomSeedFile(UnicodeString value)
  1354. {
  1355. if (RandomSeedFile != value)
  1356. {
  1357. UnicodeString PrevRandomSeedFileName = RandomSeedFileName;
  1358. FRandomSeedFile = value;
  1359. // never allow empty seed file to avoid Putty trying to reinitialize the path
  1360. if (RandomSeedFileName.IsEmpty())
  1361. {
  1362. FRandomSeedFile = FDefaultRandomSeedFile;
  1363. }
  1364. if (!PrevRandomSeedFileName.IsEmpty() &&
  1365. (PrevRandomSeedFileName != RandomSeedFileName) &&
  1366. FileExists(ApiPath(PrevRandomSeedFileName)))
  1367. {
  1368. // ignore any error
  1369. DeleteFile(ApiPath(PrevRandomSeedFileName));
  1370. }
  1371. }
  1372. }
  1373. //---------------------------------------------------------------------
  1374. UnicodeString __fastcall TConfiguration::GetRandomSeedFileName()
  1375. {
  1376. // StripPathQuotes should not be needed as we do not feed quotes anymore
  1377. return StripPathQuotes(ExpandEnvironmentVariables(FRandomSeedFile)).Trim();
  1378. }
  1379. //---------------------------------------------------------------------
  1380. void __fastcall TConfiguration::SetExternalIpAddress(UnicodeString value)
  1381. {
  1382. SET_CONFIG_PROPERTY(ExternalIpAddress);
  1383. }
  1384. //---------------------------------------------------------------------
  1385. void __fastcall TConfiguration::SetMimeTypes(UnicodeString value)
  1386. {
  1387. SET_CONFIG_PROPERTY(MimeTypes);
  1388. }
  1389. //---------------------------------------------------------------------
  1390. void __fastcall TConfiguration::SetTryFtpWhenSshFails(bool value)
  1391. {
  1392. SET_CONFIG_PROPERTY(TryFtpWhenSshFails);
  1393. }
  1394. //---------------------------------------------------------------------
  1395. void __fastcall TConfiguration::SetParallelDurationThreshold(int value)
  1396. {
  1397. SET_CONFIG_PROPERTY(ParallelDurationThreshold);
  1398. }
  1399. //---------------------------------------------------------------------
  1400. void __fastcall TConfiguration::SetPuttyRegistryStorageKey(UnicodeString value)
  1401. {
  1402. SET_CONFIG_PROPERTY(PuttyRegistryStorageKey);
  1403. }
  1404. //---------------------------------------------------------------------------
  1405. TEOLType __fastcall TConfiguration::GetLocalEOLType()
  1406. {
  1407. return eolCRLF;
  1408. }
  1409. //---------------------------------------------------------------------
  1410. bool __fastcall TConfiguration::GetCollectUsage()
  1411. {
  1412. return FUsage->Collect;
  1413. }
  1414. //---------------------------------------------------------------------
  1415. void __fastcall TConfiguration::SetCollectUsage(bool value)
  1416. {
  1417. FUsage->Collect = value;
  1418. }
  1419. //---------------------------------------------------------------------
  1420. void __fastcall TConfiguration::TemporaryLogging(const UnicodeString ALogFileName)
  1421. {
  1422. if (SameText(ExtractFileExt(ALogFileName), L".xml"))
  1423. {
  1424. TemporaryActionsLogging(ALogFileName);
  1425. }
  1426. else
  1427. {
  1428. FLogging = true;
  1429. FLogFileName = ALogFileName;
  1430. UpdateActualLogProtocol();
  1431. }
  1432. }
  1433. //---------------------------------------------------------------------
  1434. void __fastcall TConfiguration::TemporaryActionsLogging(const UnicodeString ALogFileName)
  1435. {
  1436. FLogActions = true;
  1437. FActionsLogFileName = ALogFileName;
  1438. }
  1439. //---------------------------------------------------------------------
  1440. void __fastcall TConfiguration::TemporaryLogProtocol(int ALogProtocol)
  1441. {
  1442. FLogProtocol = ALogProtocol;
  1443. UpdateActualLogProtocol();
  1444. }
  1445. //---------------------------------------------------------------------
  1446. void __fastcall TConfiguration::TemporaryLogSensitive(bool ALogSensitive)
  1447. {
  1448. FLogSensitive = ALogSensitive;
  1449. }
  1450. //---------------------------------------------------------------------
  1451. void __fastcall TConfiguration::TemporaryLogMaxSize(__int64 ALogMaxSize)
  1452. {
  1453. FLogMaxSize = ALogMaxSize;
  1454. }
  1455. //---------------------------------------------------------------------
  1456. void __fastcall TConfiguration::TemporaryLogMaxCount(int ALogMaxCount)
  1457. {
  1458. FLogMaxCount = ALogMaxCount;
  1459. }
  1460. //---------------------------------------------------------------------
  1461. void __fastcall TConfiguration::SetLogging(bool value)
  1462. {
  1463. TGuard Guard(FCriticalSection);
  1464. if (Logging != value)
  1465. {
  1466. FPermanentLogging = value;
  1467. FLogging = value;
  1468. UpdateActualLogProtocol();
  1469. Changed();
  1470. }
  1471. }
  1472. //---------------------------------------------------------------------
  1473. bool __fastcall TConfiguration::GetLogging()
  1474. {
  1475. TGuard Guard(FCriticalSection);
  1476. return FPermanentLogging;
  1477. }
  1478. //---------------------------------------------------------------------
  1479. void __fastcall TConfiguration::SetLogFileName(UnicodeString value)
  1480. {
  1481. TGuard Guard(FCriticalSection);
  1482. if (LogFileName != value)
  1483. {
  1484. FPermanentLogFileName = value;
  1485. FLogFileName = value;
  1486. Changed();
  1487. }
  1488. }
  1489. //---------------------------------------------------------------------
  1490. UnicodeString __fastcall TConfiguration::GetLogFileName()
  1491. {
  1492. TGuard Guard(FCriticalSection);
  1493. return FPermanentLogFileName;
  1494. }
  1495. //---------------------------------------------------------------------
  1496. void __fastcall TConfiguration::SetActionsLogFileName(UnicodeString value)
  1497. {
  1498. TGuard Guard(FCriticalSection);
  1499. if (ActionsLogFileName != value)
  1500. {
  1501. FPermanentActionsLogFileName = value;
  1502. FActionsLogFileName = value;
  1503. Changed();
  1504. }
  1505. }
  1506. //---------------------------------------------------------------------
  1507. UnicodeString __fastcall TConfiguration::GetPermanentActionsLogFileName()
  1508. {
  1509. TGuard Guard(FCriticalSection);
  1510. return FPermanentActionsLogFileName;
  1511. }
  1512. //---------------------------------------------------------------------
  1513. UnicodeString __fastcall TConfiguration::GetActionsLogFileName()
  1514. {
  1515. TGuard Guard(FCriticalSection);
  1516. return FActionsLogFileName;
  1517. }
  1518. //---------------------------------------------------------------------
  1519. bool __fastcall TConfiguration::GetLogToFile()
  1520. {
  1521. // guarded within GetLogFileName
  1522. return !LogFileName.IsEmpty();
  1523. }
  1524. //---------------------------------------------------------------------
  1525. void __fastcall TConfiguration::UpdateActualLogProtocol()
  1526. {
  1527. FActualLogProtocol = FLogging ? FLogProtocol : 0;
  1528. }
  1529. //---------------------------------------------------------------------
  1530. void __fastcall TConfiguration::SetLogProtocol(int value)
  1531. {
  1532. TGuard Guard(FCriticalSection);
  1533. if (LogProtocol != value)
  1534. {
  1535. FPermanentLogProtocol = value;
  1536. FLogProtocol = value;
  1537. Changed();
  1538. UpdateActualLogProtocol();
  1539. }
  1540. }
  1541. //---------------------------------------------------------------------
  1542. void __fastcall TConfiguration::SetLogActions(bool value)
  1543. {
  1544. TGuard Guard(FCriticalSection);
  1545. if (LogActions != value)
  1546. {
  1547. FPermanentLogActions = value;
  1548. FLogActions = value;
  1549. Changed();
  1550. }
  1551. }
  1552. //---------------------------------------------------------------------
  1553. bool __fastcall TConfiguration::GetLogActions()
  1554. {
  1555. TGuard Guard(FCriticalSection);
  1556. return FPermanentLogActions;
  1557. }
  1558. //---------------------------------------------------------------------
  1559. void __fastcall TConfiguration::SetLogFileAppend(bool value)
  1560. {
  1561. SET_CONFIG_PROPERTY(LogFileAppend);
  1562. }
  1563. //---------------------------------------------------------------------
  1564. void __fastcall TConfiguration::SetLogSensitive(bool value)
  1565. {
  1566. if (LogSensitive != value)
  1567. {
  1568. FPermanentLogSensitive = value;
  1569. FLogSensitive = value;
  1570. Changed();
  1571. }
  1572. }
  1573. //---------------------------------------------------------------------
  1574. void __fastcall TConfiguration::SetLogMaxSize(__int64 value)
  1575. {
  1576. TGuard Guard(FCriticalSection);
  1577. if (LogMaxSize != value)
  1578. {
  1579. FPermanentLogMaxSize = value;
  1580. FLogMaxSize = value;
  1581. Changed();
  1582. }
  1583. }
  1584. //---------------------------------------------------------------------
  1585. __int64 __fastcall TConfiguration::GetLogMaxSize()
  1586. {
  1587. TGuard Guard(FCriticalSection);
  1588. return FPermanentLogMaxSize;
  1589. }
  1590. //---------------------------------------------------------------------
  1591. void __fastcall TConfiguration::SetLogMaxCount(int value)
  1592. {
  1593. if (LogMaxCount != value)
  1594. {
  1595. FPermanentLogMaxCount = value;
  1596. FLogMaxCount = value;
  1597. Changed();
  1598. }
  1599. }
  1600. //---------------------------------------------------------------------
  1601. int __fastcall TConfiguration::GetLogMaxCount()
  1602. {
  1603. TGuard Guard(FCriticalSection);
  1604. return FPermanentLogMaxCount;
  1605. }
  1606. //---------------------------------------------------------------------
  1607. UnicodeString __fastcall TConfiguration::GetDefaultLogFileName()
  1608. {
  1609. return L"%TEMP%\\!S.log";
  1610. }
  1611. //---------------------------------------------------------------------------
  1612. void __fastcall TConfiguration::SetConfirmOverwriting(bool value)
  1613. {
  1614. TGuard Guard(FCriticalSection);
  1615. SET_CONFIG_PROPERTY(ConfirmOverwriting);
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. bool __fastcall TConfiguration::GetConfirmOverwriting()
  1619. {
  1620. TGuard Guard(FCriticalSection);
  1621. return FConfirmOverwriting;
  1622. }
  1623. //---------------------------------------------------------------------------
  1624. void __fastcall TConfiguration::SetConfirmResume(bool value)
  1625. {
  1626. TGuard Guard(FCriticalSection);
  1627. SET_CONFIG_PROPERTY(ConfirmResume);
  1628. }
  1629. //---------------------------------------------------------------------------
  1630. bool __fastcall TConfiguration::GetConfirmResume()
  1631. {
  1632. TGuard Guard(FCriticalSection);
  1633. return FConfirmResume;
  1634. }
  1635. //---------------------------------------------------------------------------
  1636. void __fastcall TConfiguration::SetAutoReadDirectoryAfterOp(bool value)
  1637. {
  1638. TGuard Guard(FCriticalSection);
  1639. SET_CONFIG_PROPERTY(AutoReadDirectoryAfterOp);
  1640. }
  1641. //---------------------------------------------------------------------------
  1642. bool __fastcall TConfiguration::GetAutoReadDirectoryAfterOp()
  1643. {
  1644. TGuard Guard(FCriticalSection);
  1645. return FAutoReadDirectoryAfterOp;
  1646. }
  1647. //---------------------------------------------------------------------------
  1648. UnicodeString __fastcall TConfiguration::GetTimeFormat()
  1649. {
  1650. return L"h:nn:ss";
  1651. }
  1652. //---------------------------------------------------------------------------
  1653. UnicodeString __fastcall TConfiguration::GetPartialExt() const
  1654. {
  1655. return PARTIAL_EXT;
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. UnicodeString __fastcall TConfiguration::GetDefaultKeyFile()
  1659. {
  1660. return L"";
  1661. }
  1662. //---------------------------------------------------------------------------
  1663. bool __fastcall TConfiguration::GetRememberPassword()
  1664. {
  1665. return false;
  1666. }
  1667. //---------------------------------------------------------------------------
  1668. void __fastcall TConfiguration::SetSessionReopenAuto(int value)
  1669. {
  1670. SET_CONFIG_PROPERTY(SessionReopenAuto);
  1671. }
  1672. //---------------------------------------------------------------------------
  1673. void __fastcall TConfiguration::SetSessionReopenBackground(int value)
  1674. {
  1675. SET_CONFIG_PROPERTY(SessionReopenBackground);
  1676. }
  1677. //---------------------------------------------------------------------------
  1678. void __fastcall TConfiguration::SetSessionReopenTimeout(int value)
  1679. {
  1680. SET_CONFIG_PROPERTY(SessionReopenTimeout);
  1681. }
  1682. //---------------------------------------------------------------------------
  1683. void __fastcall TConfiguration::SetSessionReopenAutoStall(int value)
  1684. {
  1685. SET_CONFIG_PROPERTY(SessionReopenAutoStall);
  1686. }
  1687. //---------------------------------------------------------------------------
  1688. void __fastcall TConfiguration::SetTunnelLocalPortNumberLow(int value)
  1689. {
  1690. SET_CONFIG_PROPERTY(TunnelLocalPortNumberLow);
  1691. }
  1692. //---------------------------------------------------------------------------
  1693. void __fastcall TConfiguration::SetTunnelLocalPortNumberHigh(int value)
  1694. {
  1695. SET_CONFIG_PROPERTY(TunnelLocalPortNumberHigh);
  1696. }
  1697. //---------------------------------------------------------------------------
  1698. void __fastcall TConfiguration::SetCacheDirectoryChangesMaxSize(int value)
  1699. {
  1700. SET_CONFIG_PROPERTY(CacheDirectoryChangesMaxSize);
  1701. }
  1702. //---------------------------------------------------------------------------
  1703. void __fastcall TConfiguration::SetShowFtpWelcomeMessage(bool value)
  1704. {
  1705. SET_CONFIG_PROPERTY(ShowFtpWelcomeMessage);
  1706. }
  1707. //---------------------------------------------------------------------------
  1708. bool __fastcall TConfiguration::GetPersistent()
  1709. {
  1710. return (Storage != stNul) && !FDontSave;
  1711. }
  1712. //---------------------------------------------------------------------------
  1713. //---------------------------------------------------------------------------
  1714. void __fastcall TShortCuts::Add(TShortCut ShortCut)
  1715. {
  1716. FShortCuts.insert(ShortCut);
  1717. }
  1718. //---------------------------------------------------------------------------
  1719. bool __fastcall TShortCuts::Has(TShortCut ShortCut) const
  1720. {
  1721. return (FShortCuts.count(ShortCut) != 0);
  1722. }