GUIConfiguration.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "GUIConfiguration.h"
  6. #include "GUITools.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. DebugAssert(FNames->IndexOf(Name) < 0);
  334. FNames->Insert(Index, Name);
  335. DebugAssert(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. DebugAssert((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. }
  521. //---------------------------------------------------------------------------
  522. __fastcall TGUIConfiguration::~TGUIConfiguration()
  523. {
  524. delete FLocales;
  525. delete FCopyParamList;
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TGUIConfiguration::Default()
  529. {
  530. TConfiguration::Default();
  531. // reset before call to DefaultLocalized()
  532. FDefaultCopyParam.Default();
  533. FCopyParamListDefaults = true;
  534. DefaultLocalized();
  535. FIgnoreCancelBeforeFinish = TDateTime(0, 0, 3, 0);
  536. FContinueOnError = false;
  537. FConfirmCommandSession = true;
  538. FSynchronizeParams = TTerminal::spDefault;
  539. FSynchronizeModeAuto = -1;
  540. FSynchronizeMode = TTerminal::smRemote;
  541. FMaxWatchDirectories = 500;
  542. FSynchronizeOptions = soRecurse | soSynchronizeAsk;
  543. FQueueTransfersLimit = 2;
  544. FQueueKeepDoneItems = true;
  545. FQueueKeepDoneItemsFor = 15;
  546. FQueueAutoPopup = true;
  547. FSessionRememberPassword = true;
  548. UnicodeString ProgramsFolder;
  549. SpecialFolderLocation(CSIDL_PROGRAM_FILES, ProgramsFolder);
  550. FDefaultPuttyPathOnly = IncludeTrailingBackslash(ProgramsFolder) + L"PuTTY\\" + OriginalPuttyExecutable;
  551. FDefaultPuttyPath = L"%PROGRAMFILES%\\PuTTY\\" + OriginalPuttyExecutable;
  552. FPuttyPath = FormatCommand(FDefaultPuttyPath, L"");
  553. PSftpPath = FormatCommand(L"%PROGRAMFILES%\\PuTTY\\psftp.exe", L"");
  554. FPuttyPassword = false;
  555. FTelnetForFtpInPutty = true;
  556. FPuttySession = L"WinSCP temporary session";
  557. FBeepOnFinish = false;
  558. FBeepOnFinishAfter = TDateTime(0, 0, 30, 0);
  559. FBeepSound = L"SystemDefault";
  560. FCopyParamCurrent = L"";
  561. FKeepUpToDateChangeDelay = 500;
  562. FChecksumAlg = L"sha1";
  563. FSessionReopenAutoIdle = 9000;
  564. FNewDirectoryProperties.Default();
  565. FNewDirectoryProperties.Rights = TRights::rfDefault | TRights::rfExec;
  566. }
  567. //---------------------------------------------------------------------------
  568. void __fastcall TGUIConfiguration::DefaultLocalized()
  569. {
  570. if (FCopyParamListDefaults)
  571. {
  572. FCopyParamList->Clear();
  573. // guard against "empty resource string" from obsolete traslations
  574. // (DefaultLocalized is called for the first time before detection of
  575. // obsolete translations)
  576. if (!LoadStr(COPY_PARAM_PRESET_ASCII).IsEmpty())
  577. {
  578. TCopyParamType * CopyParam;
  579. CopyParam = new TCopyParamType(FDefaultCopyParam);
  580. CopyParam->TransferMode = tmAscii;
  581. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_ASCII), CopyParam, NULL);
  582. CopyParam = new TCopyParamType(FDefaultCopyParam);
  583. CopyParam->TransferMode = tmBinary;
  584. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_BINARY), CopyParam, NULL);
  585. CopyParam = new TCopyParamType(FDefaultCopyParam);
  586. CopyParam->NewerOnly = true;
  587. FCopyParamList->Add(LoadStr(COPY_PARAM_NEWER_ONLY), CopyParam, NULL);
  588. CopyParam = new TCopyParamType(FDefaultCopyParam);
  589. CopyParam->IncludeFileMask = TFileMasks(FORMAT(L"%s */", (IncludeExcludeFileMasksDelimiter)));
  590. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_EXCLUDE_ALL_DIR), CopyParam, NULL);
  591. }
  592. FCopyParamList->Reset();
  593. }
  594. }
  595. //---------------------------------------------------------------------------
  596. void __fastcall TGUIConfiguration::UpdateStaticUsage()
  597. {
  598. TConfiguration::UpdateStaticUsage();
  599. Usage->Set(L"CopyParamsCount", (FCopyParamListDefaults ? 0 : FCopyParamList->Count));
  600. Usage->Set(L"Putty", ExtractProgramName(PuttyPath));
  601. }
  602. //---------------------------------------------------------------------------
  603. // duplicated from core\configuration.cpp
  604. #define BLOCK(KEY, CANCREATE, BLOCK) \
  605. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  606. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  607. #define REGCONFIG(CANCREATE) \
  608. BLOCK(L"Interface", CANCREATE, \
  609. KEY(Bool, ContinueOnError); \
  610. KEY(Bool, ConfirmCommandSession); \
  611. KEY(Integer, SynchronizeParams); \
  612. KEY(Integer, SynchronizeOptions); \
  613. KEY(Integer, SynchronizeModeAuto); \
  614. KEY(Integer, SynchronizeMode); \
  615. KEY(Integer, MaxWatchDirectories); \
  616. KEY(Integer, QueueTransfersLimit); \
  617. KEY(Integer, QueueKeepDoneItems); \
  618. KEY(Integer, QueueKeepDoneItemsFor); \
  619. KEY(Bool, QueueAutoPopup); \
  620. KEYEX(Bool, SessionRememberPassword, L"QueueRememberPassword"); \
  621. KEY(String, PuttySession); \
  622. KEY(String, PuttyPath); \
  623. KEY(Bool, PuttyPassword); \
  624. KEY(Bool, TelnetForFtpInPutty); \
  625. KEY(DateTime, IgnoreCancelBeforeFinish); \
  626. KEY(Bool, BeepOnFinish); \
  627. KEY(DateTime, BeepOnFinishAfter); \
  628. KEY(String, BeepSound); \
  629. KEY(Integer, KeepUpToDateChangeDelay); \
  630. KEY(String, ChecksumAlg); \
  631. KEY(Integer, SessionReopenAutoIdle); \
  632. ); \
  633. //---------------------------------------------------------------------------
  634. void __fastcall TGUIConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  635. {
  636. TConfiguration::SaveData(Storage, All);
  637. // duplicated from core\configuration.cpp
  638. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  639. REGCONFIG(true);
  640. #undef KEYEX
  641. if (Storage->OpenSubKey(L"Interface\\CopyParam", true, true))
  642. try
  643. {
  644. FDefaultCopyParam.Save(Storage);
  645. if (FCopyParamListDefaults)
  646. {
  647. DebugAssert(!FCopyParamList->Modified);
  648. Storage->WriteInteger(L"CopyParamList", -1);
  649. }
  650. else if (All || FCopyParamList->Modified)
  651. {
  652. Storage->WriteInteger(L"CopyParamList", FCopyParamList->Count);
  653. FCopyParamList->Save(Storage);
  654. }
  655. }
  656. __finally
  657. {
  658. Storage->CloseSubKey();
  659. }
  660. if (Storage->OpenSubKey(L"Interface\\NewDirectory2", true, true))
  661. try
  662. {
  663. FNewDirectoryProperties.Save(Storage);
  664. }
  665. __finally
  666. {
  667. Storage->CloseSubKey();
  668. }
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TGUIConfiguration::LoadData(THierarchicalStorage * Storage)
  672. {
  673. TConfiguration::LoadData(Storage);
  674. // duplicated from core\configuration.cpp
  675. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  676. #pragma warn -eas
  677. REGCONFIG(false);
  678. #pragma warn +eas
  679. #undef KEYEX
  680. if (Storage->OpenSubKey(L"Interface\\CopyParam", false, true))
  681. try
  682. {
  683. // must be loaded before eventual setting defaults for CopyParamList
  684. FDefaultCopyParam.Load(Storage);
  685. int CopyParamListCount = Storage->ReadInteger(L"CopyParamList", -1);
  686. FCopyParamListDefaults = (CopyParamListCount < 0);
  687. if (!FCopyParamListDefaults)
  688. {
  689. FCopyParamList->Clear();
  690. FCopyParamList->Load(Storage, CopyParamListCount);
  691. }
  692. else if (FCopyParamList->Modified)
  693. {
  694. FCopyParamList->Clear();
  695. FCopyParamListDefaults = false;
  696. }
  697. FCopyParamList->Reset();
  698. }
  699. __finally
  700. {
  701. Storage->CloseSubKey();
  702. }
  703. // Make it compatible with versions prior to 3.7.1 that have not saved PuttyPath
  704. // with quotes. First check for absence of quotes.
  705. // Add quotes either if the path is set to default putty path (even if it does
  706. // not exists) or when the path points to existing file (so there are no parameters
  707. // yet in the string). Note that FileExists may display error dialog, but as
  708. // it should be called only for custom users path, let's expect that the user
  709. // can take care of it.
  710. if ((FPuttyPath.SubString(1, 1) != L"\"") &&
  711. (CompareFileName(ExpandEnvironmentVariables(FPuttyPath), FDefaultPuttyPathOnly) ||
  712. FileExists(ApiPath(ExpandEnvironmentVariables(FPuttyPath)))))
  713. {
  714. FPuttyPath = FormatCommand(FPuttyPath, L"");
  715. }
  716. if (Storage->OpenSubKey(L"Interface\\NewDirectory2", false, true))
  717. try
  718. {
  719. FNewDirectoryProperties.Load(Storage);
  720. }
  721. __finally
  722. {
  723. Storage->CloseSubKey();
  724. }
  725. }
  726. //---------------------------------------------------------------------------
  727. void __fastcall TGUIConfiguration::Saved()
  728. {
  729. TConfiguration::Saved();
  730. FCopyParamList->Reset();
  731. }
  732. //---------------------------------------------------------------------------
  733. //---------------------------------------------------------------------------
  734. HINSTANCE __fastcall TGUIConfiguration::LoadNewResourceModule(LCID ALocale,
  735. UnicodeString & FileName)
  736. {
  737. UnicodeString LibraryFileName;
  738. HINSTANCE NewInstance = 0;
  739. bool Internal = (ALocale == InternalLocale());
  740. if (!Internal)
  741. {
  742. UnicodeString Module;
  743. UnicodeString LocaleName;
  744. Module = ModuleFileName();
  745. if ((ALocale & AdditionaLanguageMask) != AdditionaLanguageMask)
  746. {
  747. wchar_t LocaleStr[4];
  748. GetLocaleInfo(ALocale, LOCALE_SABBREVLANGNAME, LocaleStr, LENOF(LocaleStr));
  749. LocaleName = LocaleStr;
  750. DebugAssert(!LocaleName.IsEmpty());
  751. }
  752. else
  753. {
  754. LocaleName = AdditionaLanguagePrefix +
  755. char(ALocale & ~AdditionaLanguageMask);
  756. }
  757. Module = ChangeFileExt(Module, UnicodeString(L".") + LocaleName);
  758. // Look for a potential language/country translation
  759. NewInstance = LoadLibraryEx(Module.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  760. if (!NewInstance)
  761. {
  762. // Finally look for a language only translation
  763. Module.SetLength(Module.Length() - 1);
  764. NewInstance = LoadLibraryEx(Module.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  765. if (NewInstance)
  766. {
  767. LibraryFileName = Module;
  768. }
  769. }
  770. else
  771. {
  772. LibraryFileName = Module;
  773. }
  774. }
  775. if (!NewInstance && !Internal)
  776. {
  777. throw Exception(FMTLOAD(LOCALE_LOAD_ERROR, (int(ALocale))));
  778. }
  779. else
  780. {
  781. if (Internal)
  782. {
  783. NewInstance = HInstance;
  784. }
  785. }
  786. FileName = LibraryFileName;
  787. return NewInstance;
  788. }
  789. //---------------------------------------------------------------------------
  790. LCID __fastcall TGUIConfiguration::InternalLocale()
  791. {
  792. LCID Result;
  793. if (GetTranslationCount(ApplicationInfo) > 0)
  794. {
  795. TTranslation Translation;
  796. Translation = GetTranslation(ApplicationInfo, 0);
  797. Result = MAKELANGID(PRIMARYLANGID(Translation.Language), SUBLANG_DEFAULT);
  798. }
  799. else
  800. {
  801. DebugFail();
  802. Result = 0;
  803. }
  804. return Result;
  805. }
  806. //---------------------------------------------------------------------------
  807. LCID __fastcall TGUIConfiguration::GetLocale()
  808. {
  809. if (!FLocale)
  810. {
  811. SetInitialLocale(InternalLocale());
  812. }
  813. return FLocale;
  814. }
  815. //---------------------------------------------------------------------------
  816. void __fastcall TGUIConfiguration::SetLocale(LCID value)
  817. {
  818. SetLocaleInternal(value, false);
  819. }
  820. //---------------------------------------------------------------------------
  821. void __fastcall TGUIConfiguration::SetLocaleSafe(LCID value)
  822. {
  823. SetLocaleInternal(value, true);
  824. }
  825. //---------------------------------------------------------------------------
  826. UnicodeString __fastcall TGUIConfiguration::GetLocaleHex()
  827. {
  828. return IntToHex(__int64(GUIConfiguration->Locale), 4);
  829. }
  830. //---------------------------------------------------------------------------
  831. void __fastcall TGUIConfiguration::SetLocaleInternal(LCID value, bool Safe)
  832. {
  833. if (Locale != value)
  834. {
  835. HINSTANCE Module;
  836. UnicodeString FileName;
  837. try
  838. {
  839. Module = LoadNewResourceModule(value, FileName);
  840. DebugAssert(Module != NULL);
  841. }
  842. catch(...)
  843. {
  844. if (Safe)
  845. {
  846. // ignore any exception while loading locale
  847. Module = NULL;
  848. }
  849. else
  850. {
  851. throw;
  852. }
  853. }
  854. if (Module != NULL)
  855. {
  856. FLocale = value;
  857. if (CanApplyLocaleImmediately)
  858. {
  859. FAppliedLocale = value;
  860. SetResourceModule(Module);
  861. FLocaleModuleName = FileName;
  862. }
  863. }
  864. }
  865. }
  866. //---------------------------------------------------------------------------
  867. bool __fastcall TGUIConfiguration::GetCanApplyLocaleImmediately()
  868. {
  869. return
  870. (Screen->FormCount == 0) &&
  871. (Screen->DataModuleCount == 0);
  872. }
  873. //---------------------------------------------------------------------------
  874. UnicodeString __fastcall TGUIConfiguration::LocaleCopyright()
  875. {
  876. UnicodeString Result;
  877. if ((FAppliedLocale == 0) || (FAppliedLocale == InternalLocale()))
  878. {
  879. DebugFail(); // we do not expect to get called with internal locale
  880. Result = UnicodeString();
  881. }
  882. else
  883. {
  884. DebugAssert(!FLocaleModuleName.IsEmpty());
  885. Result = GetFileFileInfoString(L"LegalCopyright", FLocaleModuleName);
  886. }
  887. return Result;
  888. }
  889. //---------------------------------------------------------------------------
  890. UnicodeString __fastcall TGUIConfiguration::LocaleVersion()
  891. {
  892. UnicodeString Result;
  893. if ((FAppliedLocale == 0) || (FAppliedLocale == InternalLocale()))
  894. {
  895. // noop
  896. }
  897. else
  898. {
  899. Result = GetFileVersion(FLocaleModuleName);
  900. }
  901. return Result;
  902. }
  903. //---------------------------------------------------------------------------
  904. void __fastcall TGUIConfiguration::SetInitialLocale(LCID value)
  905. {
  906. FLocale = value;
  907. FAppliedLocale = value;
  908. }
  909. //---------------------------------------------------------------------------
  910. void __fastcall TGUIConfiguration::FreeResourceModule(HANDLE Instance)
  911. {
  912. TLibModule * MainModule = FindModule(HInstance);
  913. if ((unsigned)Instance != MainModule->Instance)
  914. {
  915. FreeLibrary(static_cast<HMODULE>(Instance));
  916. }
  917. }
  918. //---------------------------------------------------------------------------
  919. HANDLE __fastcall TGUIConfiguration::ChangeToDefaultResourceModule()
  920. {
  921. return ChangeResourceModule(NULL);
  922. }
  923. //---------------------------------------------------------------------------
  924. HANDLE __fastcall TGUIConfiguration::ChangeResourceModule(HANDLE Instance)
  925. {
  926. if (Instance == NULL)
  927. {
  928. Instance = HInstance;
  929. }
  930. TLibModule * MainModule = FindModule(HInstance);
  931. HANDLE Result = (HANDLE)MainModule->ResInstance;
  932. MainModule->ResInstance = (unsigned)Instance;
  933. CoreSetResourceModule(Instance);
  934. return Result;
  935. }
  936. //---------------------------------------------------------------------------
  937. HANDLE __fastcall TGUIConfiguration::GetResourceModule()
  938. {
  939. return (HANDLE)FindModule(HInstance)->ResInstance;
  940. }
  941. //---------------------------------------------------------------------------
  942. void __fastcall TGUIConfiguration::SetResourceModule(HINSTANCE Instance)
  943. {
  944. HANDLE PrevHandle = ChangeResourceModule(Instance);
  945. FreeResourceModule(PrevHandle);
  946. DefaultLocalized();
  947. }
  948. //---------------------------------------------------------------------------
  949. TStrings * __fastcall TGUIConfiguration::GetLocales()
  950. {
  951. UnicodeString LocalesExts;
  952. TStringList * Exts = CreateSortedStringList();
  953. try
  954. {
  955. int FindAttrs = faReadOnly | faArchive;
  956. TSearchRecChecked SearchRec;
  957. bool Found;
  958. Found =
  959. (FindFirstUnchecked(ChangeFileExt(ModuleFileName(), L".*"),
  960. FindAttrs, SearchRec) == 0);
  961. try
  962. {
  963. UnicodeString Ext;
  964. while (Found)
  965. {
  966. Ext = ExtractFileExt(SearchRec.Name).UpperCase();
  967. if ((Ext.Length() >= 3) && (Ext != L".EXE") && (Ext != L".COM") &&
  968. (Ext != L".DLL") && (Ext != L".INI"))
  969. {
  970. Ext = Ext.SubString(2, Ext.Length() - 1);
  971. LocalesExts += Ext;
  972. Exts->Add(Ext);
  973. }
  974. Found = (FindNextChecked(SearchRec) == 0);
  975. }
  976. }
  977. __finally
  978. {
  979. FindClose(SearchRec);
  980. }
  981. if (FLastLocalesExts != LocalesExts)
  982. {
  983. FLastLocalesExts = LocalesExts;
  984. FLocales->Clear();
  985. TLanguages * Langs = Languages();
  986. int Ext, Index, Count;
  987. wchar_t LocaleStr[255];
  988. LCID Locale;
  989. Count = Langs->Count;
  990. Index = -1;
  991. while (Index < Count)
  992. {
  993. if (Index >= 0)
  994. {
  995. Locale = Langs->LocaleID[Index];
  996. Ext = Exts->IndexOf(Langs->Ext[Index]);
  997. if (Ext < 0)
  998. {
  999. Ext = Exts->IndexOf(Langs->Ext[Index].SubString(1, 2));
  1000. if (Ext >= 0)
  1001. {
  1002. Locale = MAKELANGID(PRIMARYLANGID(Locale), SUBLANG_DEFAULT);
  1003. }
  1004. }
  1005. if (Ext >= 0)
  1006. {
  1007. Exts->Objects[Ext] = reinterpret_cast<TObject*>(Locale);
  1008. }
  1009. else
  1010. {
  1011. Locale = 0;
  1012. }
  1013. }
  1014. else
  1015. {
  1016. Locale = InternalLocale();
  1017. }
  1018. if (Locale)
  1019. {
  1020. UnicodeString Name;
  1021. GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE,
  1022. LocaleStr, LENOF(LocaleStr));
  1023. Name = LocaleStr;
  1024. Name += L" - ";
  1025. // LOCALE_SNATIVELANGNAME
  1026. GetLocaleInfo(Locale, LOCALE_SLANGUAGE,
  1027. LocaleStr, LENOF(LocaleStr));
  1028. Name += LocaleStr;
  1029. FLocales->AddObject(Name, reinterpret_cast<TObject*>(Locale));
  1030. }
  1031. Index++;
  1032. }
  1033. for (int Index = 0; Index < Exts->Count; Index++)
  1034. {
  1035. if ((Exts->Objects[Index] == NULL) &&
  1036. (Exts->Strings[Index].Length() == 3) &&
  1037. SameText(Exts->Strings[Index].SubString(1, 2), AdditionaLanguagePrefix))
  1038. {
  1039. UnicodeString LangName = GetFileFileInfoString(L"LangName",
  1040. ChangeFileExt(ModuleFileName(), UnicodeString(L".") + Exts->Strings[Index]));
  1041. if (!LangName.IsEmpty())
  1042. {
  1043. FLocales->AddObject(LangName, reinterpret_cast<TObject*>(
  1044. AdditionaLanguageMask + Exts->Strings[Index][3]));
  1045. }
  1046. }
  1047. }
  1048. }
  1049. }
  1050. __finally
  1051. {
  1052. delete Exts;
  1053. }
  1054. return FLocales;
  1055. }
  1056. //---------------------------------------------------------------------------
  1057. void __fastcall TGUIConfiguration::SetDefaultCopyParam(const TGUICopyParamType & value)
  1058. {
  1059. FDefaultCopyParam.Assign(&value);
  1060. Changed();
  1061. }
  1062. //---------------------------------------------------------------------------
  1063. bool __fastcall TGUIConfiguration::GetRememberPassword()
  1064. {
  1065. bool Result = SessionRememberPassword || PuttyPassword;
  1066. if (!Result)
  1067. {
  1068. try
  1069. {
  1070. TRemoteCustomCommand RemoteCustomCommand;
  1071. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1072. UnicodeString APuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1073. Result = RemoteCustomCommand.IsPasswordCommand(PuttyPath);
  1074. }
  1075. catch (...)
  1076. {
  1077. // noop
  1078. }
  1079. }
  1080. return Result;
  1081. }
  1082. //---------------------------------------------------------------------------
  1083. const TCopyParamList * __fastcall TGUIConfiguration::GetCopyParamList()
  1084. {
  1085. return FCopyParamList;
  1086. }
  1087. //---------------------------------------------------------------------------
  1088. void __fastcall TGUIConfiguration::SetCopyParamList(const TCopyParamList * value)
  1089. {
  1090. if (!(*FCopyParamList == *value))
  1091. {
  1092. *FCopyParamList = *value;
  1093. FCopyParamListDefaults = false;
  1094. Changed();
  1095. }
  1096. }
  1097. //---------------------------------------------------------------------------
  1098. int __fastcall TGUIConfiguration::GetCopyParamIndex()
  1099. {
  1100. int Result;
  1101. if (FCopyParamCurrent.IsEmpty())
  1102. {
  1103. Result = -1;
  1104. }
  1105. else
  1106. {
  1107. Result = FCopyParamList->IndexOfName(FCopyParamCurrent);
  1108. }
  1109. return Result;
  1110. }
  1111. //---------------------------------------------------------------------------
  1112. void __fastcall TGUIConfiguration::SetCopyParamIndex(int value)
  1113. {
  1114. UnicodeString Name;
  1115. if (value < 0)
  1116. {
  1117. Name = L"";
  1118. }
  1119. else
  1120. {
  1121. Name = FCopyParamList->Names[value];
  1122. }
  1123. CopyParamCurrent = Name;
  1124. }
  1125. //---------------------------------------------------------------------------
  1126. void __fastcall TGUIConfiguration::SetCopyParamCurrent(UnicodeString value)
  1127. {
  1128. SET_CONFIG_PROPERTY(CopyParamCurrent);
  1129. }
  1130. //---------------------------------------------------------------------------
  1131. TGUICopyParamType __fastcall TGUIConfiguration::GetCurrentCopyParam()
  1132. {
  1133. return CopyParamPreset[CopyParamCurrent];
  1134. }
  1135. //---------------------------------------------------------------------------
  1136. TGUICopyParamType __fastcall TGUIConfiguration::GetCopyParamPreset(UnicodeString Name)
  1137. {
  1138. TGUICopyParamType Result = FDefaultCopyParam;
  1139. if (!Name.IsEmpty())
  1140. {
  1141. int Index = FCopyParamList->IndexOfName(Name);
  1142. DebugAssert(Index >= 0);
  1143. if (Index >= 0)
  1144. {
  1145. const TCopyParamType * Preset = FCopyParamList->CopyParams[Index];
  1146. DebugAssert(Preset != NULL);
  1147. Result.Assign(Preset); // overwrite all but GUI options
  1148. // reset all options known not to be configurable per-preset
  1149. // kind of hack
  1150. Result.ResumeSupport = FDefaultCopyParam.ResumeSupport;
  1151. Result.ResumeThreshold = FDefaultCopyParam.ResumeThreshold;
  1152. Result.LocalInvalidChars = FDefaultCopyParam.LocalInvalidChars;
  1153. }
  1154. }
  1155. return Result;
  1156. }
  1157. //---------------------------------------------------------------------------
  1158. bool __fastcall TGUIConfiguration::GetHasCopyParamPreset(UnicodeString Name)
  1159. {
  1160. return Name.IsEmpty() || (FCopyParamList->IndexOfName(Name) >= 0);
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. void __fastcall TGUIConfiguration::SetNewDirectoryProperties(
  1164. const TRemoteProperties & value)
  1165. {
  1166. SET_CONFIG_PROPERTY(NewDirectoryProperties);
  1167. }
  1168. //---------------------------------------------------------------------------
  1169. void __fastcall TGUIConfiguration::SetQueueTransfersLimit(int value)
  1170. {
  1171. SET_CONFIG_PROPERTY(QueueTransfersLimit);
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void __fastcall TGUIConfiguration::SetQueueKeepDoneItems(bool value)
  1175. {
  1176. SET_CONFIG_PROPERTY(QueueKeepDoneItems);
  1177. }
  1178. //---------------------------------------------------------------------------
  1179. void __fastcall TGUIConfiguration::SetQueueKeepDoneItemsFor(int value)
  1180. {
  1181. SET_CONFIG_PROPERTY(QueueKeepDoneItemsFor);
  1182. }
  1183. //---------------------------------------------------------------------
  1184. TStoredSessionList * __fastcall TGUIConfiguration::SelectPuttySessionsForImport(
  1185. TStoredSessionList * Sessions, UnicodeString & Error)
  1186. {
  1187. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1188. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1189. std::unique_ptr<TRegistryStorage> Storage(new TRegistryStorage(PuttySessionsKey));
  1190. Storage->ForceAnsi = true;
  1191. if (Storage->OpenRootKey(false))
  1192. {
  1193. ImportSessionList->Load(Storage.get(), false, true, true);
  1194. }
  1195. TSessionData * PuttySessionData =
  1196. (TSessionData *)ImportSessionList->FindByName(PuttySession);
  1197. if (PuttySessionData != NULL)
  1198. {
  1199. ImportSessionList->Remove(PuttySessionData);
  1200. }
  1201. if (ImportSessionList->Count > 0)
  1202. {
  1203. ImportSessionList->SelectSessionsToImport(Sessions, true);
  1204. }
  1205. else
  1206. {
  1207. Error = FMTLOAD(PUTTY_NO_SITES, (PuttySessionsKey));
  1208. }
  1209. return ImportSessionList.release();
  1210. }
  1211. //---------------------------------------------------------------------
  1212. bool __fastcall TGUIConfiguration::AnyPuttySessionForImport(TStoredSessionList * Sessions)
  1213. {
  1214. try
  1215. {
  1216. UnicodeString Error;
  1217. std::unique_ptr<TStoredSessionList> Sesssions(SelectPuttySessionsForImport(Sessions, Error));
  1218. return (Sesssions->Count > 0);
  1219. }
  1220. catch (...)
  1221. {
  1222. return false;
  1223. }
  1224. }
  1225. //---------------------------------------------------------------------------