Configuration.cpp 57 KB

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