GUIConfiguration.cpp 39 KB

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