GUIConfiguration.cpp 40 KB

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