GUIConfiguration.cpp 43 KB

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