Configuration.cpp 57 KB

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