GUIConfiguration.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "GUIConfiguration.h"
  5. #include "GUITools.h"
  6. #include <Common.h>
  7. #include <FileInfo.h>
  8. #include <TextsCore.h>
  9. #include <Terminal.h>
  10. #include <CoreMain.h>
  11. #include <shlobj.h>
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. //---------------------------------------------------------------------------
  15. const int ccLocal = ccUser;
  16. const int ccShowResults = ccUser << 1;
  17. const int ccCopyResults = ccUser << 2;
  18. const int ccSet = 0x80000000;
  19. //---------------------------------------------------------------------------
  20. static const unsigned int AdditionaLanguageMask = 0xFFFFFF00;
  21. static const UnicodeString AdditionaLanguagePrefix(L"XX");
  22. //---------------------------------------------------------------------------
  23. TGUIConfiguration * GUIConfiguration = NULL;
  24. //---------------------------------------------------------------------------
  25. __fastcall TGUICopyParamType::TGUICopyParamType()
  26. : TCopyParamType()
  27. {
  28. GUIDefault();
  29. }
  30. //---------------------------------------------------------------------------
  31. __fastcall TGUICopyParamType::TGUICopyParamType(const TCopyParamType & Source)
  32. : TCopyParamType(Source)
  33. {
  34. GUIDefault();
  35. }
  36. //---------------------------------------------------------------------------
  37. __fastcall TGUICopyParamType::TGUICopyParamType(const TGUICopyParamType & Source)
  38. : TCopyParamType(Source)
  39. {
  40. GUIAssign(&Source);
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TGUICopyParamType::Assign(const TCopyParamType * Source)
  44. {
  45. TCopyParamType::Assign(Source);
  46. const TGUICopyParamType * GUISource;
  47. GUISource = dynamic_cast<const TGUICopyParamType *>(Source);
  48. if (GUISource != NULL)
  49. {
  50. GUIAssign(GUISource);
  51. }
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TGUICopyParamType::GUIAssign(const TGUICopyParamType * Source)
  55. {
  56. Queue = Source->Queue;
  57. QueueNoConfirmation = Source->QueueNoConfirmation;
  58. QueueIndividually = Source->QueueIndividually;
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TGUICopyParamType::Default()
  62. {
  63. TCopyParamType::Default();
  64. GUIDefault();
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TGUICopyParamType::GUIDefault()
  68. {
  69. Queue = false;
  70. QueueNoConfirmation = true;
  71. QueueIndividually = false;
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TGUICopyParamType::Load(THierarchicalStorage * Storage)
  75. {
  76. TCopyParamType::Load(Storage);
  77. Queue = Storage->ReadBool(L"Queue", Queue);
  78. QueueNoConfirmation = Storage->ReadBool(L"QueueNoConfirmation", QueueNoConfirmation);
  79. QueueIndividually = Storage->ReadBool(L"QueueIndividually", QueueIndividually);
  80. }
  81. //---------------------------------------------------------------------------
  82. void __fastcall TGUICopyParamType::Save(THierarchicalStorage * Storage)
  83. {
  84. TCopyParamType::Save(Storage);
  85. Storage->WriteBool(L"Queue", Queue);
  86. Storage->WriteBool(L"QueueNoConfirmation", QueueNoConfirmation);
  87. Storage->WriteBool(L"QueueIndividually", QueueIndividually);
  88. }
  89. //---------------------------------------------------------------------------
  90. TGUICopyParamType & __fastcall TGUICopyParamType::operator =(const TCopyParamType & rhp)
  91. {
  92. Assign(&rhp);
  93. return *this;
  94. }
  95. //---------------------------------------------------------------------------
  96. TGUICopyParamType & __fastcall TGUICopyParamType::operator =(const TGUICopyParamType & rhp)
  97. {
  98. Assign(&rhp);
  99. return *this;
  100. }
  101. //---------------------------------------------------------------------------
  102. //---------------------------------------------------------------------------
  103. void __fastcall TCopyParamRuleData::Default()
  104. {
  105. HostName = L"";
  106. UserName = L"";
  107. RemoteDirectory = L"";
  108. LocalDirectory = L"";
  109. }
  110. //---------------------------------------------------------------------------
  111. //---------------------------------------------------------------------------
  112. __fastcall TCopyParamRule::TCopyParamRule()
  113. {
  114. }
  115. //---------------------------------------------------------------------------
  116. __fastcall TCopyParamRule::TCopyParamRule(const TCopyParamRuleData & Data)
  117. {
  118. FData = Data;
  119. }
  120. //---------------------------------------------------------------------------
  121. __fastcall TCopyParamRule::TCopyParamRule(const TCopyParamRule & Source)
  122. {
  123. FData.HostName = Source.FData.HostName;
  124. FData.UserName = Source.FData.UserName;
  125. FData.RemoteDirectory = Source.FData.RemoteDirectory;
  126. FData.LocalDirectory = Source.FData.LocalDirectory;
  127. }
  128. //---------------------------------------------------------------------------
  129. #define C(Property) (Property == rhp.Property)
  130. bool __fastcall TCopyParamRule::operator==(const TCopyParamRule & rhp) const
  131. {
  132. return
  133. C(FData.HostName) &&
  134. C(FData.UserName) &&
  135. C(FData.RemoteDirectory) &&
  136. C(FData.LocalDirectory) &&
  137. true;
  138. }
  139. #undef C
  140. //---------------------------------------------------------------------------
  141. bool __fastcall TCopyParamRule::Match(const UnicodeString & Mask,
  142. const UnicodeString & Value, bool Path, bool Local, int ForceDirectoryMasks) const
  143. {
  144. bool Result;
  145. if (Mask.IsEmpty())
  146. {
  147. Result = true;
  148. }
  149. else
  150. {
  151. TFileMasks M(ForceDirectoryMasks);
  152. M.Masks = Mask;
  153. if (Path)
  154. {
  155. Result = M.Matches(Value, Local, true);
  156. }
  157. else
  158. {
  159. Result = M.Matches(Value, false);
  160. }
  161. }
  162. return Result;
  163. }
  164. //---------------------------------------------------------------------------
  165. bool __fastcall TCopyParamRule::Matches(const TCopyParamRuleData & Value) const
  166. {
  167. return
  168. Match(FData.HostName, Value.HostName, false, true, 0) &&
  169. Match(FData.UserName, Value.UserName, false, true, 0) &&
  170. Match(FData.RemoteDirectory, Value.RemoteDirectory, true, false, 1) &&
  171. Match(FData.LocalDirectory, Value.LocalDirectory, true, true, 1);
  172. }
  173. //---------------------------------------------------------------------------
  174. void __fastcall TCopyParamRule::Load(THierarchicalStorage * Storage)
  175. {
  176. FData.HostName = Storage->ReadString(L"HostName", FData.HostName);
  177. FData.UserName = Storage->ReadString(L"UserName", FData.UserName);
  178. FData.RemoteDirectory = Storage->ReadString(L"RemoteDirectory", FData.RemoteDirectory);
  179. FData.LocalDirectory = Storage->ReadString(L"LocalDirectory", FData.LocalDirectory);
  180. }
  181. //---------------------------------------------------------------------------
  182. void __fastcall TCopyParamRule::Save(THierarchicalStorage * Storage) const
  183. {
  184. Storage->WriteString(L"HostName", FData.HostName);
  185. Storage->WriteString(L"UserName", FData.UserName);
  186. Storage->WriteString(L"RemoteDirectory", FData.RemoteDirectory);
  187. Storage->WriteString(L"LocalDirectory", FData.LocalDirectory);
  188. }
  189. //---------------------------------------------------------------------------
  190. bool __fastcall TCopyParamRule::GetEmpty() const
  191. {
  192. return
  193. FData.HostName.IsEmpty() &&
  194. FData.UserName.IsEmpty() &&
  195. FData.RemoteDirectory.IsEmpty() &&
  196. FData.LocalDirectory.IsEmpty();
  197. }
  198. //---------------------------------------------------------------------------
  199. UnicodeString __fastcall TCopyParamRule::GetInfoStr(UnicodeString Separator) const
  200. {
  201. UnicodeString Result;
  202. #define ADD(FMT, ELEM) \
  203. if (!FData.ELEM.IsEmpty()) \
  204. Result += (Result.IsEmpty() ? UnicodeString() : Separator) + FMTLOAD(FMT, (FData.ELEM));
  205. ADD(COPY_RULE_HOSTNAME, HostName);
  206. ADD(COPY_RULE_USERNAME, UserName);
  207. ADD(COPY_RULE_REMOTE_DIR, RemoteDirectory);
  208. ADD(COPY_RULE_LOCAL_DIR, LocalDirectory);
  209. #undef ADD
  210. return Result;
  211. }
  212. //---------------------------------------------------------------------------
  213. //---------------------------------------------------------------------------
  214. UnicodeString TCopyParamList::FInvalidChars(L"/\\[]");
  215. //---------------------------------------------------------------------------
  216. __fastcall TCopyParamList::TCopyParamList()
  217. {
  218. Init();
  219. }
  220. //---------------------------------------------------------------------------
  221. void __fastcall TCopyParamList::Init()
  222. {
  223. FCopyParams = new TList();
  224. FRules = new TList();
  225. FNames = new TStringList();
  226. FNameList = NULL;
  227. FModified = false;
  228. }
  229. //---------------------------------------------------------------------------
  230. __fastcall TCopyParamList::~TCopyParamList()
  231. {
  232. Clear();
  233. delete FCopyParams;
  234. delete FRules;
  235. delete FNames;
  236. delete FNameList;
  237. }
  238. //---------------------------------------------------------------------------
  239. void __fastcall TCopyParamList::Reset()
  240. {
  241. SAFE_DESTROY(FNameList);
  242. FModified = false;
  243. }
  244. //---------------------------------------------------------------------
  245. void __fastcall TCopyParamList::Modify()
  246. {
  247. SAFE_DESTROY(FNameList);
  248. FModified = true;
  249. }
  250. //---------------------------------------------------------------------
  251. void __fastcall TCopyParamList::ValidateName(const UnicodeString Name)
  252. {
  253. if (Name.LastDelimiter(FInvalidChars) > 0)
  254. {
  255. throw Exception(FMTLOAD(ITEM_NAME_INVALID, (Name, FInvalidChars)));
  256. }
  257. }
  258. //---------------------------------------------------------------------------
  259. TCopyParamList & __fastcall TCopyParamList::operator=(const TCopyParamList & rhl)
  260. {
  261. Clear();
  262. for (int Index = 0; Index < rhl.Count; Index++)
  263. {
  264. TCopyParamType * CopyParam = new TCopyParamType(*rhl.CopyParams[Index]);
  265. TCopyParamRule * Rule = NULL;
  266. if (rhl.Rules[Index] != NULL)
  267. {
  268. Rule = new TCopyParamRule(*rhl.Rules[Index]);
  269. }
  270. Add(rhl.Names[Index], CopyParam, Rule);
  271. }
  272. // there should be comparison of with the assigned list, but we rely on caller
  273. // to do it instead (TGUIConfiguration::SetCopyParamList)
  274. Modify();
  275. return *this;
  276. }
  277. //---------------------------------------------------------------------------
  278. bool __fastcall TCopyParamList::operator==(const TCopyParamList & rhl) const
  279. {
  280. bool Result = (Count == rhl.Count);
  281. if (Result)
  282. {
  283. int i = 0;
  284. while ((i < Count) && Result)
  285. {
  286. Result =
  287. (Names[i] == rhl.Names[i]) &&
  288. CompareItem(i, rhl.CopyParams[i], rhl.Rules[i]);
  289. i++;
  290. }
  291. }
  292. return Result;
  293. }
  294. //---------------------------------------------------------------------------
  295. int __fastcall TCopyParamList::IndexOfName(const UnicodeString Name) const
  296. {
  297. return FNames->IndexOf(Name);
  298. }
  299. //---------------------------------------------------------------------------
  300. bool __fastcall TCopyParamList::CompareItem(int Index,
  301. const TCopyParamType * CopyParam, const TCopyParamRule * Rule) const
  302. {
  303. return
  304. ((*CopyParams[Index]) == *CopyParam) &&
  305. ((Rules[Index] == NULL) ?
  306. (Rule == NULL) :
  307. ((Rule != NULL) && (*Rules[Index]) == (*Rule)));
  308. }
  309. //---------------------------------------------------------------------------
  310. void __fastcall TCopyParamList::Clear()
  311. {
  312. for (int i = 0; i < Count; i++)
  313. {
  314. delete CopyParams[i];
  315. delete Rules[i];
  316. }
  317. FCopyParams->Clear();
  318. FRules->Clear();
  319. FNames->Clear();
  320. }
  321. //---------------------------------------------------------------------------
  322. void __fastcall TCopyParamList::Add(const UnicodeString Name,
  323. TCopyParamType * CopyParam, TCopyParamRule * Rule)
  324. {
  325. Insert(Count, Name, CopyParam, Rule);
  326. }
  327. //---------------------------------------------------------------------------
  328. void __fastcall TCopyParamList::Insert(int Index, const UnicodeString Name,
  329. TCopyParamType * CopyParam, TCopyParamRule * Rule)
  330. {
  331. assert(FNames->IndexOf(Name) < 0);
  332. FNames->Insert(Index, Name);
  333. assert(CopyParam != NULL);
  334. FCopyParams->Insert(Index, reinterpret_cast<TObject *>(CopyParam));
  335. FRules->Insert(Index, reinterpret_cast<TObject *>(Rule));
  336. Modify();
  337. }
  338. //---------------------------------------------------------------------------
  339. void __fastcall TCopyParamList::Change(int Index, const UnicodeString Name,
  340. TCopyParamType * CopyParam, TCopyParamRule * Rule)
  341. {
  342. if ((Name != Names[Index]) || !CompareItem(Index, CopyParam, Rule))
  343. {
  344. FNames->Strings[Index] = Name;
  345. delete CopyParams[Index];
  346. FCopyParams->Items[Index] = (reinterpret_cast<TObject *>(CopyParam));
  347. delete Rules[Index];
  348. FRules->Items[Index] = (reinterpret_cast<TObject *>(Rule));
  349. Modify();
  350. }
  351. else
  352. {
  353. delete CopyParam;
  354. delete Rule;
  355. }
  356. }
  357. //---------------------------------------------------------------------------
  358. void __fastcall TCopyParamList::Move(int CurIndex, int NewIndex)
  359. {
  360. if (CurIndex != NewIndex)
  361. {
  362. FNames->Move(CurIndex, NewIndex);
  363. FCopyParams->Move(CurIndex, NewIndex);
  364. FRules->Move(CurIndex, NewIndex);
  365. Modify();
  366. }
  367. }
  368. //---------------------------------------------------------------------------
  369. void __fastcall TCopyParamList::Delete(int Index)
  370. {
  371. assert((Index >= 0) && (Index < Count));
  372. FNames->Delete(Index);
  373. delete CopyParams[Index];
  374. FCopyParams->Delete(Index);
  375. delete Rules[Index];
  376. FRules->Delete(Index);
  377. Modify();
  378. }
  379. //---------------------------------------------------------------------------
  380. int __fastcall TCopyParamList::Find(const TCopyParamRuleData & Value) const
  381. {
  382. int Result = -1;
  383. int i = 0;
  384. while ((i < FRules->Count) && (Result < 0))
  385. {
  386. if (FRules->Items[i] != NULL)
  387. {
  388. if (Rules[i]->Matches(Value))
  389. {
  390. Result = i;
  391. }
  392. }
  393. i++;
  394. }
  395. return Result;
  396. }
  397. //---------------------------------------------------------------------------
  398. void __fastcall TCopyParamList::Load(THierarchicalStorage * Storage, int ACount)
  399. {
  400. for (int Index = 0; Index < ACount; Index++)
  401. {
  402. UnicodeString Name = IntToStr(Index);
  403. TCopyParamRule * Rule = NULL;
  404. TCopyParamType * CopyParam = new TCopyParamType();
  405. try
  406. {
  407. if (Storage->OpenSubKey(Name, false))
  408. {
  409. try
  410. {
  411. Name = Storage->ReadString(L"Name", Name);
  412. CopyParam->Load(Storage);
  413. if (Storage->ReadBool(L"HasRule", false))
  414. {
  415. Rule = new TCopyParamRule();
  416. Rule->Load(Storage);
  417. }
  418. }
  419. __finally
  420. {
  421. Storage->CloseSubKey();
  422. }
  423. }
  424. }
  425. catch(...)
  426. {
  427. delete CopyParam;
  428. delete Rule;
  429. throw;
  430. }
  431. FCopyParams->Add(reinterpret_cast<TObject *>(CopyParam));
  432. FRules->Add(reinterpret_cast<TObject *>(Rule));
  433. FNames->Add(Name);
  434. }
  435. Reset();
  436. }
  437. //---------------------------------------------------------------------------
  438. void __fastcall TCopyParamList::Save(THierarchicalStorage * Storage) const
  439. {
  440. Storage->ClearSubKeys();
  441. for (int Index = 0; Index < Count; Index++)
  442. {
  443. if (Storage->OpenSubKey(IntToStr(Index), true))
  444. {
  445. try
  446. {
  447. const TCopyParamType * CopyParam = CopyParams[Index];
  448. const TCopyParamRule * Rule = Rules[Index];
  449. Storage->WriteString(L"Name", Names[Index]);
  450. CopyParam->Save(Storage);
  451. Storage->WriteBool(L"HasRule", (Rule != NULL));
  452. if (Rule != NULL)
  453. {
  454. Rule->Save(Storage);
  455. }
  456. }
  457. __finally
  458. {
  459. Storage->CloseSubKey();
  460. }
  461. }
  462. }
  463. }
  464. //---------------------------------------------------------------------------
  465. int __fastcall TCopyParamList::GetCount() const
  466. {
  467. return FCopyParams->Count;
  468. }
  469. //---------------------------------------------------------------------------
  470. const TCopyParamRule * __fastcall TCopyParamList::GetRule(int Index) const
  471. {
  472. return reinterpret_cast<TCopyParamRule *>(FRules->Items[Index]);
  473. }
  474. //---------------------------------------------------------------------------
  475. const TCopyParamType * __fastcall TCopyParamList::GetCopyParam(int Index) const
  476. {
  477. return reinterpret_cast<TCopyParamType *>(FCopyParams->Items[Index]);
  478. }
  479. //---------------------------------------------------------------------------
  480. UnicodeString __fastcall TCopyParamList::GetName(int Index) const
  481. {
  482. return FNames->Strings[Index];
  483. }
  484. //---------------------------------------------------------------------------
  485. TStrings * __fastcall TCopyParamList::GetNameList() const
  486. {
  487. if (FNameList == NULL)
  488. {
  489. FNameList = new TStringList();
  490. for (int i = 0; i < Count; i++)
  491. {
  492. FNameList->Add(FNames->Strings[i]);
  493. }
  494. }
  495. return FNameList;
  496. }
  497. //---------------------------------------------------------------------------
  498. bool __fastcall TCopyParamList::GetAnyRule() const
  499. {
  500. bool Result = false;
  501. int i = 0;
  502. while ((i < Count) && !Result)
  503. {
  504. Result = (Rules[i] != NULL);
  505. i++;
  506. }
  507. return Result;
  508. }
  509. //---------------------------------------------------------------------------
  510. //---------------------------------------------------------------------------
  511. __fastcall TGUIConfiguration::TGUIConfiguration(): TConfiguration()
  512. {
  513. SetInitialLocale(0);
  514. FLocales = new TStringList();
  515. FLastLocalesExts = L"*";
  516. dynamic_cast<TStringList*>(FLocales)->Sorted = true;
  517. dynamic_cast<TStringList*>(FLocales)->CaseSensitive = false;
  518. FCopyParamList = new TCopyParamList();
  519. CoreSetResourceModule(GetResourceModule());
  520. // allow loading configured locale, DetectScalingType needs to get called
  521. // only after that, but before user can ever try to change the locale
  522. FCanApplyLocaleImmediately = true;
  523. }
  524. //---------------------------------------------------------------------------
  525. __fastcall TGUIConfiguration::~TGUIConfiguration()
  526. {
  527. delete FLocales;
  528. delete FCopyParamList;
  529. }
  530. //---------------------------------------------------------------------------
  531. void __fastcall TGUIConfiguration::DetectScalingType()
  532. {
  533. // USER_DEFAULT_SCREEN_DPI (96) DPI is 100%
  534. FCanApplyLocaleImmediately = (Screen->PixelsPerInch == USER_DEFAULT_SCREEN_DPI);
  535. }
  536. //---------------------------------------------------------------------------
  537. void __fastcall TGUIConfiguration::Default()
  538. {
  539. TConfiguration::Default();
  540. // reset before call to DefaultLocalized()
  541. FDefaultCopyParam.Default();
  542. FCopyParamListDefaults = true;
  543. DefaultLocalized();
  544. FIgnoreCancelBeforeFinish = TDateTime(0, 0, 3, 0);
  545. FContinueOnError = false;
  546. FConfirmCommandSession = true;
  547. FSynchronizeParams = TTerminal::spDefault;
  548. FSynchronizeModeAuto = -1;
  549. FSynchronizeMode = TTerminal::smRemote;
  550. FMaxWatchDirectories = 500;
  551. FSynchronizeOptions = soRecurse | soSynchronizeAsk;
  552. FQueueTransfersLimit = 2;
  553. FQueueKeepDoneItems = true;
  554. FQueueKeepDoneItemsFor = 15;
  555. FQueueAutoPopup = true;
  556. FSessionRememberPassword = false;
  557. UnicodeString ProgramsFolder;
  558. SpecialFolderLocation(CSIDL_PROGRAM_FILES, ProgramsFolder);
  559. FDefaultPuttyPathOnly = IncludeTrailingBackslash(ProgramsFolder) + L"PuTTY\\" + OriginalPuttyExecutable;
  560. FDefaultPuttyPath = L"%PROGRAMFILES%\\PuTTY\\" + OriginalPuttyExecutable;
  561. FPuttyPath = FormatCommand(FDefaultPuttyPath, L"");
  562. PSftpPath = FormatCommand(L"%PROGRAMFILES%\\PuTTY\\psftp.exe", L"");
  563. FPuttyPassword = false;
  564. FTelnetForFtpInPutty = true;
  565. FPuttySession = L"WinSCP temporary session";
  566. FBeepOnFinish = false;
  567. FBeepOnFinishAfter = TDateTime(0, 0, 30, 0);
  568. FCopyParamCurrent = L"";
  569. FKeepUpToDateChangeDelay = 500;
  570. FChecksumAlg = L"md5";
  571. FSessionReopenAutoIdle = 9000;
  572. FNewDirectoryProperties.Default();
  573. FNewDirectoryProperties.Rights = TRights::rfDefault | TRights::rfExec;
  574. }
  575. //---------------------------------------------------------------------------
  576. void __fastcall TGUIConfiguration::DefaultLocalized()
  577. {
  578. if (FCopyParamListDefaults)
  579. {
  580. FCopyParamList->Clear();
  581. // guard against "empty resource string" from obsolete traslations
  582. // (DefaultLocalized is called for the first time before detection of
  583. // obsolete translations)
  584. if (!LoadStr(COPY_PARAM_PRESET_ASCII).IsEmpty())
  585. {
  586. TCopyParamType * CopyParam;
  587. CopyParam = new TCopyParamType(FDefaultCopyParam);
  588. CopyParam->TransferMode = tmAscii;
  589. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_ASCII), CopyParam, NULL);
  590. CopyParam = new TCopyParamType(FDefaultCopyParam);
  591. CopyParam->TransferMode = tmBinary;
  592. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_BINARY), CopyParam, NULL);
  593. CopyParam = new TCopyParamType(FDefaultCopyParam);
  594. CopyParam->NewerOnly = true;
  595. FCopyParamList->Add(LoadStr(COPY_PARAM_NEWER_ONLY), CopyParam, NULL);
  596. }
  597. FCopyParamList->Reset();
  598. }
  599. }
  600. //---------------------------------------------------------------------------
  601. void __fastcall TGUIConfiguration::UpdateStaticUsage()
  602. {
  603. TConfiguration::UpdateStaticUsage();
  604. Usage->Set(L"CopyParamsCount", (FCopyParamListDefaults ? 0 : FCopyParamList->Count));
  605. Usage->Set(L"Putty", ExtractProgramName(PuttyPath));
  606. }
  607. //---------------------------------------------------------------------------
  608. // duplicated from core\configuration.cpp
  609. #define BLOCK(KEY, CANCREATE, BLOCK) \
  610. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  611. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  612. #define REGCONFIG(CANCREATE) \
  613. BLOCK(L"Interface", CANCREATE, \
  614. KEY(Bool, ContinueOnError); \
  615. KEY(Bool, ConfirmCommandSession); \
  616. KEY(Integer, SynchronizeParams); \
  617. KEY(Integer, SynchronizeOptions); \
  618. KEY(Integer, SynchronizeModeAuto); \
  619. KEY(Integer, SynchronizeMode); \
  620. KEY(Integer, MaxWatchDirectories); \
  621. KEY(Integer, QueueTransfersLimit); \
  622. KEY(Integer, QueueKeepDoneItems); \
  623. KEY(Integer, QueueKeepDoneItemsFor); \
  624. KEY(Bool, QueueAutoPopup); \
  625. KEYEX(Bool, SessionRememberPassword, L"QueueRememberPassword"); \
  626. KEY(String, PuttySession); \
  627. KEY(String, PuttyPath); \
  628. KEY(Bool, PuttyPassword); \
  629. KEY(Bool, TelnetForFtpInPutty); \
  630. KEY(DateTime, IgnoreCancelBeforeFinish); \
  631. KEY(Bool, BeepOnFinish); \
  632. KEY(DateTime, BeepOnFinishAfter); \
  633. KEY(Integer, KeepUpToDateChangeDelay); \
  634. KEY(String, ChecksumAlg); \
  635. KEY(Integer, SessionReopenAutoIdle); \
  636. ); \
  637. //---------------------------------------------------------------------------
  638. void __fastcall TGUIConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  639. {
  640. TConfiguration::SaveData(Storage, All);
  641. // duplicated from core\configuration.cpp
  642. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  643. REGCONFIG(true);
  644. #undef KEYEX
  645. if (Storage->OpenSubKey(L"Interface\\CopyParam", true, true))
  646. try
  647. {
  648. FDefaultCopyParam.Save(Storage);
  649. if (FCopyParamListDefaults)
  650. {
  651. assert(!FCopyParamList->Modified);
  652. Storage->WriteInteger(L"CopyParamList", -1);
  653. }
  654. else if (All || FCopyParamList->Modified)
  655. {
  656. Storage->WriteInteger(L"CopyParamList", FCopyParamList->Count);
  657. FCopyParamList->Save(Storage);
  658. }
  659. }
  660. __finally
  661. {
  662. Storage->CloseSubKey();
  663. }
  664. if (Storage->OpenSubKey(L"Interface\\NewDirectory2", true, true))
  665. try
  666. {
  667. FNewDirectoryProperties.Save(Storage);
  668. }
  669. __finally
  670. {
  671. Storage->CloseSubKey();
  672. }
  673. }
  674. //---------------------------------------------------------------------------
  675. void __fastcall TGUIConfiguration::LoadData(THierarchicalStorage * Storage)
  676. {
  677. TConfiguration::LoadData(Storage);
  678. // duplicated from core\configuration.cpp
  679. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  680. #pragma warn -eas
  681. REGCONFIG(false);
  682. #pragma warn +eas
  683. #undef KEYEX
  684. if (Storage->OpenSubKey(L"Interface\\CopyParam", false, true))
  685. try
  686. {
  687. // must be loaded before eventual setting defaults for CopyParamList
  688. FDefaultCopyParam.Load(Storage);
  689. int CopyParamListCount = Storage->ReadInteger(L"CopyParamList", -1);
  690. FCopyParamListDefaults = (CopyParamListCount < 0);
  691. if (!FCopyParamListDefaults)
  692. {
  693. FCopyParamList->Clear();
  694. FCopyParamList->Load(Storage, CopyParamListCount);
  695. }
  696. else if (FCopyParamList->Modified)
  697. {
  698. FCopyParamList->Clear();
  699. FCopyParamListDefaults = false;
  700. }
  701. FCopyParamList->Reset();
  702. }
  703. __finally
  704. {
  705. Storage->CloseSubKey();
  706. }
  707. // Make it compatible with versions prior to 3.7.1 that have not saved PuttyPath
  708. // with quotes. First check for absence of quotes.
  709. // Add quotes either if the path is set to default putty path (even if it does
  710. // not exists) or when the path points to existing file (so there are no parameters
  711. // yet in the string). Note that FileExists may display error dialog, but as
  712. // it should be called only for custom users path, let's expect that the user
  713. // can take care of it.
  714. if ((FPuttyPath.SubString(1, 1) != L"\"") &&
  715. (CompareFileName(ExpandEnvironmentVariables(FPuttyPath), FDefaultPuttyPathOnly) ||
  716. FileExists(ApiPath(ExpandEnvironmentVariables(FPuttyPath)))))
  717. {
  718. FPuttyPath = FormatCommand(FPuttyPath, L"");
  719. }
  720. if (Storage->OpenSubKey(L"Interface\\NewDirectory2", false, true))
  721. try
  722. {
  723. FNewDirectoryProperties.Load(Storage);
  724. }
  725. __finally
  726. {
  727. Storage->CloseSubKey();
  728. }
  729. }
  730. //---------------------------------------------------------------------------
  731. void __fastcall TGUIConfiguration::Saved()
  732. {
  733. TConfiguration::Saved();
  734. FCopyParamList->Reset();
  735. }
  736. //---------------------------------------------------------------------------
  737. //---------------------------------------------------------------------------
  738. HINSTANCE __fastcall TGUIConfiguration::LoadNewResourceModule(LCID ALocale,
  739. UnicodeString * FileName)
  740. {
  741. UnicodeString LibraryFileName;
  742. HINSTANCE NewInstance = 0;
  743. bool Internal = (ALocale == InternalLocale());
  744. if (!Internal)
  745. {
  746. UnicodeString Module;
  747. UnicodeString LocaleName;
  748. Module = ModuleFileName();
  749. if ((ALocale & AdditionaLanguageMask) != AdditionaLanguageMask)
  750. {
  751. wchar_t LocaleStr[4];
  752. GetLocaleInfo(ALocale, LOCALE_SABBREVLANGNAME, LocaleStr, LENOF(LocaleStr));
  753. LocaleName = LocaleStr;
  754. assert(!LocaleName.IsEmpty());
  755. }
  756. else
  757. {
  758. LocaleName = AdditionaLanguagePrefix +
  759. char(ALocale & ~AdditionaLanguageMask);
  760. }
  761. Module = ChangeFileExt(Module, UnicodeString(L".") + LocaleName);
  762. // Look for a potential language/country translation
  763. NewInstance = LoadLibraryEx(Module.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  764. if (!NewInstance)
  765. {
  766. // Finally look for a language only translation
  767. Module.SetLength(Module.Length() - 1);
  768. NewInstance = LoadLibraryEx(Module.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  769. if (NewInstance)
  770. {
  771. LibraryFileName = Module;
  772. }
  773. }
  774. else
  775. {
  776. LibraryFileName = Module;
  777. }
  778. }
  779. if (!NewInstance && !Internal)
  780. {
  781. throw Exception(FMTLOAD(LOCALE_LOAD_ERROR, (int(ALocale))));
  782. }
  783. else
  784. {
  785. if (Internal)
  786. {
  787. NewInstance = HInstance;
  788. }
  789. }
  790. if (FileName != NULL)
  791. {
  792. *FileName = LibraryFileName;
  793. }
  794. return NewInstance;
  795. }
  796. //---------------------------------------------------------------------------
  797. LCID __fastcall TGUIConfiguration::InternalLocale()
  798. {
  799. LCID Result;
  800. if (GetTranslationCount(ApplicationInfo) > 0)
  801. {
  802. TTranslation Translation;
  803. Translation = GetTranslation(ApplicationInfo, 0);
  804. Result = MAKELANGID(PRIMARYLANGID(Translation.Language), SUBLANG_DEFAULT);
  805. }
  806. else
  807. {
  808. FAIL;
  809. Result = 0;
  810. }
  811. return Result;
  812. }
  813. //---------------------------------------------------------------------------
  814. LCID __fastcall TGUIConfiguration::GetLocale()
  815. {
  816. if (!FLocale)
  817. {
  818. SetInitialLocale(InternalLocale());
  819. }
  820. return FLocale;
  821. }
  822. //---------------------------------------------------------------------------
  823. void __fastcall TGUIConfiguration::SetLocale(LCID value)
  824. {
  825. SetLocaleInternal(value, false);
  826. }
  827. //---------------------------------------------------------------------------
  828. void __fastcall TGUIConfiguration::SetLocaleSafe(LCID value)
  829. {
  830. SetLocaleInternal(value, true);
  831. }
  832. //---------------------------------------------------------------------------
  833. void __fastcall TGUIConfiguration::SetLocaleInternal(LCID value, bool Safe)
  834. {
  835. if (Locale != value)
  836. {
  837. HINSTANCE Module;
  838. try
  839. {
  840. Module = LoadNewResourceModule(value);
  841. assert(Module != NULL);
  842. }
  843. catch(...)
  844. {
  845. if (Safe)
  846. {
  847. // ignore any exception while loading locale
  848. Module = NULL;
  849. }
  850. else
  851. {
  852. throw;
  853. }
  854. }
  855. if (Module != NULL)
  856. {
  857. FLocale = value;
  858. if (CanApplyLocaleImmediately)
  859. {
  860. FAppliedLocale = value;
  861. SetResourceModule(Module);
  862. }
  863. }
  864. }
  865. }
  866. //---------------------------------------------------------------------------
  867. void __fastcall TGUIConfiguration::SetInitialLocale(LCID value)
  868. {
  869. FLocale = value;
  870. FAppliedLocale = value;
  871. }
  872. //---------------------------------------------------------------------------
  873. void __fastcall TGUIConfiguration::FreeResourceModule(HANDLE Instance)
  874. {
  875. TLibModule * MainModule = FindModule(HInstance);
  876. if ((unsigned)Instance != MainModule->Instance)
  877. {
  878. FreeLibrary(static_cast<HMODULE>(Instance));
  879. }
  880. }
  881. //---------------------------------------------------------------------------
  882. HANDLE __fastcall TGUIConfiguration::ChangeResourceModule(HANDLE Instance)
  883. {
  884. if (Instance == NULL)
  885. {
  886. Instance = HInstance;
  887. }
  888. TLibModule * MainModule = FindModule(HInstance);
  889. HANDLE Result = (HANDLE)MainModule->ResInstance;
  890. MainModule->ResInstance = (unsigned)Instance;
  891. CoreSetResourceModule(Instance);
  892. return Result;
  893. }
  894. //---------------------------------------------------------------------------
  895. HANDLE __fastcall TGUIConfiguration::GetResourceModule()
  896. {
  897. return (HANDLE)FindModule(HInstance)->ResInstance;
  898. }
  899. //---------------------------------------------------------------------------
  900. void __fastcall TGUIConfiguration::SetResourceModule(HINSTANCE Instance)
  901. {
  902. HANDLE PrevHandle = ChangeResourceModule(Instance);
  903. FreeResourceModule(PrevHandle);
  904. DefaultLocalized();
  905. }
  906. //---------------------------------------------------------------------------
  907. TStrings * __fastcall TGUIConfiguration::GetLocales()
  908. {
  909. UnicodeString LocalesExts;
  910. TStringList * Exts = new TStringList();
  911. try
  912. {
  913. Exts->Sorted = true;
  914. Exts->CaseSensitive = false;
  915. int FindAttrs = faReadOnly | faArchive;
  916. TSearchRecChecked SearchRec;
  917. bool Found;
  918. Found =
  919. (FindFirstUnchecked(ChangeFileExt(ModuleFileName(), L".*"),
  920. FindAttrs, SearchRec) == 0);
  921. try
  922. {
  923. UnicodeString Ext;
  924. while (Found)
  925. {
  926. Ext = ExtractFileExt(SearchRec.Name).UpperCase();
  927. if ((Ext.Length() >= 3) && (Ext != L".EXE") && (Ext != L".COM") &&
  928. (Ext != L".DLL") && (Ext != L".INI"))
  929. {
  930. Ext = Ext.SubString(2, Ext.Length() - 1);
  931. LocalesExts += Ext;
  932. Exts->Add(Ext);
  933. }
  934. Found = (FindNextChecked(SearchRec) == 0);
  935. }
  936. }
  937. __finally
  938. {
  939. FindClose(SearchRec);
  940. }
  941. if (FLastLocalesExts != LocalesExts)
  942. {
  943. FLastLocalesExts = LocalesExts;
  944. FLocales->Clear();
  945. TLanguages * Langs = Languages();
  946. int Ext, Index, Count;
  947. wchar_t LocaleStr[255];
  948. LCID Locale;
  949. Count = Langs->Count;
  950. Index = -1;
  951. while (Index < Count)
  952. {
  953. if (Index >= 0)
  954. {
  955. Locale = Langs->LocaleID[Index];
  956. Ext = Exts->IndexOf(Langs->Ext[Index]);
  957. if (Ext < 0)
  958. {
  959. Ext = Exts->IndexOf(Langs->Ext[Index].SubString(1, 2));
  960. if (Ext >= 0)
  961. {
  962. Locale = MAKELANGID(PRIMARYLANGID(Locale), SUBLANG_DEFAULT);
  963. }
  964. }
  965. if (Ext >= 0)
  966. {
  967. Exts->Objects[Ext] = reinterpret_cast<TObject*>(Locale);
  968. }
  969. else
  970. {
  971. Locale = 0;
  972. }
  973. }
  974. else
  975. {
  976. Locale = InternalLocale();
  977. }
  978. if (Locale)
  979. {
  980. UnicodeString Name;
  981. GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE,
  982. LocaleStr, LENOF(LocaleStr));
  983. Name = LocaleStr;
  984. Name += L" - ";
  985. // LOCALE_SNATIVELANGNAME
  986. GetLocaleInfo(Locale, LOCALE_SLANGUAGE,
  987. LocaleStr, LENOF(LocaleStr));
  988. Name += LocaleStr;
  989. FLocales->AddObject(Name, reinterpret_cast<TObject*>(Locale));
  990. }
  991. Index++;
  992. }
  993. for (int Index = 0; Index < Exts->Count; Index++)
  994. {
  995. if ((Exts->Objects[Index] == NULL) &&
  996. (Exts->Strings[Index].Length() == 3) &&
  997. SameText(Exts->Strings[Index].SubString(1, 2), AdditionaLanguagePrefix))
  998. {
  999. UnicodeString LangName = GetFileFileInfoString(L"LangName",
  1000. ChangeFileExt(ModuleFileName(), UnicodeString(L".") + Exts->Strings[Index]));
  1001. if (!LangName.IsEmpty())
  1002. {
  1003. FLocales->AddObject(LangName, reinterpret_cast<TObject*>(
  1004. AdditionaLanguageMask + Exts->Strings[Index][3]));
  1005. }
  1006. }
  1007. }
  1008. }
  1009. }
  1010. __finally
  1011. {
  1012. delete Exts;
  1013. }
  1014. return FLocales;
  1015. }
  1016. //---------------------------------------------------------------------------
  1017. void __fastcall TGUIConfiguration::SetDefaultCopyParam(const TGUICopyParamType & value)
  1018. {
  1019. FDefaultCopyParam.Assign(&value);
  1020. Changed();
  1021. }
  1022. //---------------------------------------------------------------------------
  1023. bool __fastcall TGUIConfiguration::GetRememberPassword()
  1024. {
  1025. return SessionRememberPassword || PuttyPassword;
  1026. }
  1027. //---------------------------------------------------------------------------
  1028. const TCopyParamList * __fastcall TGUIConfiguration::GetCopyParamList()
  1029. {
  1030. return FCopyParamList;
  1031. }
  1032. //---------------------------------------------------------------------------
  1033. void __fastcall TGUIConfiguration::SetCopyParamList(const TCopyParamList * value)
  1034. {
  1035. if (!(*FCopyParamList == *value))
  1036. {
  1037. *FCopyParamList = *value;
  1038. FCopyParamListDefaults = false;
  1039. Changed();
  1040. }
  1041. }
  1042. //---------------------------------------------------------------------------
  1043. int __fastcall TGUIConfiguration::GetCopyParamIndex()
  1044. {
  1045. int Result;
  1046. if (FCopyParamCurrent.IsEmpty())
  1047. {
  1048. Result = -1;
  1049. }
  1050. else
  1051. {
  1052. Result = FCopyParamList->IndexOfName(FCopyParamCurrent);
  1053. }
  1054. return Result;
  1055. }
  1056. //---------------------------------------------------------------------------
  1057. void __fastcall TGUIConfiguration::SetCopyParamIndex(int value)
  1058. {
  1059. UnicodeString Name;
  1060. if (value < 0)
  1061. {
  1062. Name = L"";
  1063. }
  1064. else
  1065. {
  1066. Name = FCopyParamList->Names[value];
  1067. }
  1068. CopyParamCurrent = Name;
  1069. }
  1070. //---------------------------------------------------------------------------
  1071. void __fastcall TGUIConfiguration::SetCopyParamCurrent(UnicodeString value)
  1072. {
  1073. SET_CONFIG_PROPERTY(CopyParamCurrent);
  1074. }
  1075. //---------------------------------------------------------------------------
  1076. TGUICopyParamType __fastcall TGUIConfiguration::GetCurrentCopyParam()
  1077. {
  1078. return CopyParamPreset[CopyParamCurrent];
  1079. }
  1080. //---------------------------------------------------------------------------
  1081. TGUICopyParamType __fastcall TGUIConfiguration::GetCopyParamPreset(UnicodeString Name)
  1082. {
  1083. TGUICopyParamType Result = FDefaultCopyParam;
  1084. if (!Name.IsEmpty())
  1085. {
  1086. int Index = FCopyParamList->IndexOfName(Name);
  1087. assert(Index >= 0);
  1088. if (Index >= 0)
  1089. {
  1090. const TCopyParamType * Preset = FCopyParamList->CopyParams[Index];
  1091. assert(Preset != NULL);
  1092. Result.Assign(Preset); // overwrite all but GUI options
  1093. // reset all options known not to be configurable per-preset
  1094. // kind of hack
  1095. Result.ResumeSupport = FDefaultCopyParam.ResumeSupport;
  1096. Result.ResumeThreshold = FDefaultCopyParam.ResumeThreshold;
  1097. Result.LocalInvalidChars = FDefaultCopyParam.LocalInvalidChars;
  1098. }
  1099. }
  1100. return Result;
  1101. }
  1102. //---------------------------------------------------------------------------
  1103. bool __fastcall TGUIConfiguration::GetHasCopyParamPreset(UnicodeString Name)
  1104. {
  1105. return Name.IsEmpty() || (FCopyParamList->IndexOfName(Name) >= 0);
  1106. }
  1107. //---------------------------------------------------------------------------
  1108. void __fastcall TGUIConfiguration::SetNewDirectoryProperties(
  1109. const TRemoteProperties & value)
  1110. {
  1111. SET_CONFIG_PROPERTY(NewDirectoryProperties);
  1112. }
  1113. //---------------------------------------------------------------------------
  1114. void __fastcall TGUIConfiguration::SetQueueTransfersLimit(int value)
  1115. {
  1116. SET_CONFIG_PROPERTY(QueueTransfersLimit);
  1117. }
  1118. //---------------------------------------------------------------------------
  1119. void __fastcall TGUIConfiguration::SetQueueKeepDoneItems(bool value)
  1120. {
  1121. SET_CONFIG_PROPERTY(QueueKeepDoneItems);
  1122. }
  1123. //---------------------------------------------------------------------------
  1124. void __fastcall TGUIConfiguration::SetQueueKeepDoneItemsFor(int value)
  1125. {
  1126. SET_CONFIG_PROPERTY(QueueKeepDoneItemsFor);
  1127. }
  1128. //---------------------------------------------------------------------
  1129. TStoredSessionList * __fastcall TGUIConfiguration::SelectPuttySessionsForImport(
  1130. TStoredSessionList * Sessions)
  1131. {
  1132. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1133. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1134. std::unique_ptr<TRegistryStorage> Storage(new TRegistryStorage(PuttySessionsKey));
  1135. Storage->ForceAnsi = true;
  1136. if (Storage->OpenRootKey(false))
  1137. {
  1138. ImportSessionList->Load(Storage.get(), false, true);
  1139. }
  1140. TSessionData * PuttySessionData =
  1141. (TSessionData *)ImportSessionList->FindByName(PuttySession);
  1142. if (PuttySessionData != NULL)
  1143. {
  1144. ImportSessionList->Remove(PuttySessionData);
  1145. }
  1146. ImportSessionList->SelectSessionsToImport(Sessions, true);
  1147. return ImportSessionList.release();
  1148. }
  1149. //---------------------------------------------------------------------
  1150. bool __fastcall TGUIConfiguration::AnyPuttySessionForImport(TStoredSessionList * Sessions)
  1151. {
  1152. try
  1153. {
  1154. std::unique_ptr<TStoredSessionList> Sesssions(SelectPuttySessionsForImport(Sessions));
  1155. return (Sesssions->Count > 0);
  1156. }
  1157. catch (...)
  1158. {
  1159. return false;
  1160. }
  1161. }
  1162. //---------------------------------------------------------------------
  1163. TStoredSessionList * __fastcall TGUIConfiguration::SelectFilezillaSessionsForImport(
  1164. TStoredSessionList * Sessions)
  1165. {
  1166. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1167. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1168. UnicodeString AppDataPath = GetShellFolderPath(CSIDL_APPDATA);
  1169. UnicodeString FilezillaSiteManagerFile =
  1170. IncludeTrailingBackslash(AppDataPath) + L"FileZilla\\sitemanager.xml";
  1171. if (FileExists(ApiPath(FilezillaSiteManagerFile)))
  1172. {
  1173. ImportSessionList->ImportFromFilezilla(FilezillaSiteManagerFile);
  1174. ImportSessionList->SelectSessionsToImport(Sessions, true);
  1175. }
  1176. return ImportSessionList.release();
  1177. }
  1178. //---------------------------------------------------------------------
  1179. bool __fastcall TGUIConfiguration::AnyFilezillaSessionForImport(TStoredSessionList * Sessions)
  1180. {
  1181. try
  1182. {
  1183. std::unique_ptr<TStoredSessionList> Sesssions(SelectFilezillaSessionsForImport(Sessions));
  1184. return (Sesssions->Count > 0);
  1185. }
  1186. catch (...)
  1187. {
  1188. return false;
  1189. }
  1190. }
  1191. //---------------------------------------------------------------------------