GUIConfiguration.cpp 39 KB

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