GUIConfiguration.cpp 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  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. bool __fastcall TGUIConfiguration::DoSaveCopyParam(THierarchicalStorage * Storage, const TCopyParamType * CopyParam, const TCopyParamType * Defaults)
  637. {
  638. bool Result = Storage->OpenSubKey(L"Interface\\CopyParam", true, true);
  639. if (Result)
  640. {
  641. CopyParam->Save(Storage, Defaults);
  642. }
  643. return Result;
  644. }
  645. //---------------------------------------------------------------------------
  646. bool __fastcall TGUIConfiguration::SaveCopyParam(THierarchicalStorage * Storage, const TCopyParamType * CopyParam, const TCopyParamType * Defaults)
  647. {
  648. bool Result = DoSaveCopyParam(Storage, CopyParam, Defaults);
  649. if (Result)
  650. {
  651. Storage->CloseSubKey();
  652. }
  653. return Result;
  654. }
  655. //---------------------------------------------------------------------------
  656. void __fastcall TGUIConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  657. {
  658. TConfiguration::SaveData(Storage, All);
  659. // duplicated from core\configuration.cpp
  660. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  661. REGCONFIG(true);
  662. #undef KEYEX
  663. if (DoSaveCopyParam(Storage, &FDefaultCopyParam, NULL))
  664. try
  665. {
  666. FDefaultCopyParam.Save(Storage);
  667. if (FCopyParamListDefaults)
  668. {
  669. DebugAssert(!FCopyParamList->Modified);
  670. Storage->WriteInteger(L"CopyParamList", -1);
  671. }
  672. else if (All || FCopyParamList->Modified)
  673. {
  674. Storage->WriteInteger(L"CopyParamList", FCopyParamList->Count);
  675. FCopyParamList->Save(Storage);
  676. }
  677. }
  678. __finally
  679. {
  680. Storage->CloseSubKey();
  681. }
  682. if (Storage->OpenSubKey(L"Interface\\NewDirectory2", true, true))
  683. try
  684. {
  685. FNewDirectoryProperties.Save(Storage);
  686. }
  687. __finally
  688. {
  689. Storage->CloseSubKey();
  690. }
  691. }
  692. //---------------------------------------------------------------------------
  693. bool __fastcall TGUIConfiguration::LoadCopyParam(THierarchicalStorage * Storage, TCopyParamType * CopyParam)
  694. {
  695. bool Result =
  696. Storage->OpenSubKey(L"Interface\\CopyParam", false, true);
  697. if (Result)
  698. {
  699. try
  700. {
  701. CopyParam->Load(Storage);
  702. }
  703. catch (...)
  704. {
  705. Storage->CloseSubKey();
  706. throw;
  707. }
  708. }
  709. return Result;
  710. }
  711. //---------------------------------------------------------------------------
  712. void __fastcall TGUIConfiguration::LoadData(THierarchicalStorage * Storage)
  713. {
  714. TConfiguration::LoadData(Storage);
  715. // duplicated from core\configuration.cpp
  716. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  717. #pragma warn -eas
  718. REGCONFIG(false);
  719. #pragma warn +eas
  720. #undef KEYEX
  721. // FDefaultCopyParam must be loaded before eventual setting defaults for CopyParamList
  722. if (LoadCopyParam(Storage, &FDefaultCopyParam))
  723. try
  724. {
  725. int CopyParamListCount = Storage->ReadInteger(L"CopyParamList", -1);
  726. FCopyParamListDefaults = (CopyParamListCount < 0);
  727. if (!FCopyParamListDefaults)
  728. {
  729. FCopyParamList->Clear();
  730. FCopyParamList->Load(Storage, CopyParamListCount);
  731. }
  732. else if (FCopyParamList->Modified)
  733. {
  734. FCopyParamList->Clear();
  735. FCopyParamListDefaults = false;
  736. }
  737. FCopyParamList->Reset();
  738. }
  739. __finally
  740. {
  741. Storage->CloseSubKey();
  742. }
  743. // Make it compatible with versions prior to 3.7.1 that have not saved PuttyPath
  744. // with quotes. First check for absence of quotes.
  745. // Add quotes either if the path is set to default putty path (even if it does
  746. // not exists) or when the path points to existing file (so there are no parameters
  747. // yet in the string). Note that FileExists may display error dialog, but as
  748. // it should be called only for custom users path, let's expect that the user
  749. // can take care of it.
  750. if ((FPuttyPath.SubString(1, 1) != L"\"") &&
  751. (IsPathToSameFile(ExpandEnvironmentVariables(FPuttyPath), FDefaultPuttyPathOnly) ||
  752. FileExists(ApiPath(ExpandEnvironmentVariables(FPuttyPath)))))
  753. {
  754. FPuttyPath = FormatCommand(FPuttyPath, L"");
  755. }
  756. if (Storage->OpenSubKey(L"Interface\\NewDirectory2", false, true))
  757. try
  758. {
  759. FNewDirectoryProperties.Load(Storage);
  760. }
  761. __finally
  762. {
  763. Storage->CloseSubKey();
  764. }
  765. }
  766. //---------------------------------------------------------------------------
  767. void __fastcall TGUIConfiguration::Saved()
  768. {
  769. TConfiguration::Saved();
  770. FCopyParamList->Reset();
  771. }
  772. //---------------------------------------------------------------------------
  773. //---------------------------------------------------------------------------
  774. UnicodeString __fastcall TGUIConfiguration::GetTranslationModule(const UnicodeString & Path)
  775. {
  776. UnicodeString SubPath = AddTranslationsSubFolder(Path);
  777. UnicodeString Result;
  778. // Prefer the SubPath. Default to SubPath.
  779. if (FileExists(Path) && !FileExists(SubPath))
  780. {
  781. Result = Path;
  782. }
  783. else
  784. {
  785. Result = SubPath;
  786. }
  787. return Result;
  788. }
  789. //---------------------------------------------------------------------------
  790. UnicodeString __fastcall TGUIConfiguration::AddTranslationsSubFolder(const UnicodeString & Path)
  791. {
  792. return
  793. IncludeTrailingBackslash(IncludeTrailingBackslash(ExtractFilePath(Path)) + TranslationsSubFolder) +
  794. ExtractFileName(Path);
  795. }
  796. //---------------------------------------------------------------------------
  797. HINSTANCE __fastcall TGUIConfiguration::LoadNewResourceModule(LCID ALocale,
  798. UnicodeString & FileName)
  799. {
  800. UnicodeString LibraryFileName;
  801. HINSTANCE NewInstance = 0;
  802. bool Internal = (ALocale == InternalLocale());
  803. if (!Internal)
  804. {
  805. UnicodeString Module;
  806. UnicodeString LocaleName;
  807. Module = ModuleFileName();
  808. if ((ALocale & AdditionaLanguageMask) != AdditionaLanguageMask)
  809. {
  810. wchar_t LocaleStr[4];
  811. GetLocaleInfo(ALocale, LOCALE_SABBREVLANGNAME, LocaleStr, LENOF(LocaleStr));
  812. LocaleName = LocaleStr;
  813. DebugAssert(!LocaleName.IsEmpty());
  814. }
  815. else
  816. {
  817. LocaleName = AdditionaLanguagePrefix +
  818. char(ALocale & ~AdditionaLanguageMask);
  819. }
  820. Module = ChangeFileExt(Module, UnicodeString(L".") + LocaleName);
  821. // Look for a potential language/country translation
  822. UnicodeString ModulePath = GetTranslationModule(Module);
  823. NewInstance = LoadLibraryEx(ModulePath.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  824. if (NewInstance)
  825. {
  826. LibraryFileName = ModulePath;
  827. }
  828. else
  829. {
  830. DWORD PrimaryLang = PRIMARYLANGID(ALocale);
  831. DWORD SubLang = SUBLANGID(ALocale);
  832. DebugAssert(SUBLANG_DEFAULT == SUBLANG_CHINESE_TRADITIONAL);
  833. // Finally look for a language-only translation.
  834. // But for Chinese, never use "traditional" (what is the "default" Chinese), if we want "Simplified"
  835. // (the same what Inno Setup does)
  836. if ((PrimaryLang != LANG_CHINESE) ||
  837. (SubLang == SUBLANG_CHINESE_TRADITIONAL))
  838. {
  839. Module.SetLength(Module.Length() - 1);
  840. ModulePath = GetTranslationModule(Module);
  841. NewInstance = LoadLibraryEx(ModulePath.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  842. if (NewInstance)
  843. {
  844. LibraryFileName = ModulePath;
  845. }
  846. }
  847. }
  848. }
  849. if (!NewInstance && !Internal)
  850. {
  851. throw Exception(FMTLOAD(LOCALE_LOAD_ERROR, (int(ALocale))));
  852. }
  853. else
  854. {
  855. if (Internal)
  856. {
  857. NewInstance = HInstance;
  858. }
  859. }
  860. FileName = LibraryFileName;
  861. return NewInstance;
  862. }
  863. //---------------------------------------------------------------------------
  864. LCID __fastcall TGUIConfiguration::InternalLocale()
  865. {
  866. LCID Result;
  867. if (GetTranslationCount(ApplicationInfo) > 0)
  868. {
  869. TTranslation Translation;
  870. Translation = GetTranslation(ApplicationInfo, 0);
  871. Result = MAKELANGID(PRIMARYLANGID(Translation.Language), SUBLANG_DEFAULT);
  872. }
  873. else
  874. {
  875. DebugFail();
  876. Result = 0;
  877. }
  878. return Result;
  879. }
  880. //---------------------------------------------------------------------------
  881. LCID __fastcall TGUIConfiguration::GetLocale()
  882. {
  883. return FLocale;
  884. }
  885. //---------------------------------------------------------------------------
  886. void __fastcall TGUIConfiguration::SetLocale(LCID value)
  887. {
  888. if (Locale != value)
  889. {
  890. SetLocaleInternal(value, false, false);
  891. }
  892. }
  893. //---------------------------------------------------------------------------
  894. void __fastcall TGUIConfiguration::SetLocaleSafe(LCID value)
  895. {
  896. if (Locale != value)
  897. {
  898. SetLocaleInternal(value, true, false);
  899. }
  900. }
  901. //---------------------------------------------------------------------------
  902. UnicodeString __fastcall TGUIConfiguration::GetAppliedLocaleHex()
  903. {
  904. return IntToHex(__int64(AppliedLocale), 4);
  905. }
  906. //---------------------------------------------------------------------------
  907. int __fastcall TGUIConfiguration::GetResourceModuleCompleteness(HINSTANCE /*Module*/)
  908. {
  909. return 100;
  910. }
  911. //---------------------------------------------------------------------------
  912. bool __fastcall TGUIConfiguration::IsTranslationComplete(HINSTANCE /*Module*/)
  913. {
  914. return true;
  915. }
  916. //---------------------------------------------------------------------------
  917. void __fastcall TGUIConfiguration::SetLocaleInternal(LCID value, bool Safe, bool CompleteOnly)
  918. {
  919. LCID L = value;
  920. if (L == NULL)
  921. {
  922. L = GetUserDefaultUILanguage();
  923. }
  924. HINSTANCE Module = NULL;
  925. UnicodeString FileName;
  926. try
  927. {
  928. Module = LoadNewResourceModule(L, FileName);
  929. DebugAssert(Module != NULL);
  930. if (CompleteOnly && !IsTranslationComplete(Module))
  931. {
  932. Abort();
  933. }
  934. }
  935. catch (...)
  936. {
  937. if (Module != NULL)
  938. {
  939. FreeResourceModule(Module);
  940. Module = NULL;
  941. }
  942. if (Safe)
  943. {
  944. // ignore any exception while loading locale
  945. }
  946. else
  947. {
  948. throw;
  949. }
  950. }
  951. if (Module != NULL)
  952. {
  953. FLocale = value;
  954. if (CanApplyLocaleImmediately)
  955. {
  956. SetAppliedLocale(L, FileName);
  957. SetResourceModule(Module);
  958. }
  959. }
  960. }
  961. //---------------------------------------------------------------------------
  962. bool __fastcall TGUIConfiguration::GetCanApplyLocaleImmediately()
  963. {
  964. return
  965. (Screen->FormCount == 0) &&
  966. (Screen->DataModuleCount == 0);
  967. }
  968. //---------------------------------------------------------------------------
  969. UnicodeString __fastcall TGUIConfiguration::AppliedLocaleCopyright()
  970. {
  971. UnicodeString Result;
  972. if ((FAppliedLocale == 0) || (FAppliedLocale == InternalLocale()))
  973. {
  974. DebugFail(); // we do not expect to get called with internal locale
  975. Result = UnicodeString();
  976. }
  977. else
  978. {
  979. DebugAssert(!FLocaleModuleName.IsEmpty());
  980. Result = GetFileFileInfoString(L"LegalCopyright", FLocaleModuleName);
  981. }
  982. return Result;
  983. }
  984. //---------------------------------------------------------------------------
  985. UnicodeString __fastcall TGUIConfiguration::AppliedLocaleVersion()
  986. {
  987. UnicodeString Result;
  988. if ((FAppliedLocale == 0) || (FAppliedLocale == InternalLocale()))
  989. {
  990. // noop
  991. }
  992. else
  993. {
  994. Result = GetFileVersion(FLocaleModuleName);
  995. }
  996. return Result;
  997. }
  998. //---------------------------------------------------------------------------
  999. void __fastcall TGUIConfiguration::SetAppliedLocale(LCID AppliedLocale, const UnicodeString & LocaleModuleName)
  1000. {
  1001. FAppliedLocale = AppliedLocale;
  1002. FLocaleModuleName = LocaleModuleName;
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. void __fastcall TGUIConfiguration::FreeResourceModule(HANDLE Instance)
  1006. {
  1007. TLibModule * MainModule = FindModule(HInstance);
  1008. if ((unsigned)Instance != MainModule->Instance)
  1009. {
  1010. FreeLibrary(static_cast<HMODULE>(Instance));
  1011. }
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. HANDLE __fastcall TGUIConfiguration::ChangeToDefaultResourceModule()
  1015. {
  1016. return ChangeResourceModule(NULL);
  1017. }
  1018. //---------------------------------------------------------------------------
  1019. HANDLE __fastcall TGUIConfiguration::ChangeResourceModule(HANDLE Instance)
  1020. {
  1021. if (Instance == NULL)
  1022. {
  1023. Instance = HInstance;
  1024. }
  1025. TLibModule * MainModule = FindModule(HInstance);
  1026. HANDLE Result = (HANDLE)MainModule->ResInstance;
  1027. MainModule->ResInstance = (unsigned)Instance;
  1028. CoreSetResourceModule(Instance);
  1029. return Result;
  1030. }
  1031. //---------------------------------------------------------------------------
  1032. HANDLE __fastcall TGUIConfiguration::GetResourceModule()
  1033. {
  1034. return (HANDLE)FindModule(HInstance)->ResInstance;
  1035. }
  1036. //---------------------------------------------------------------------------
  1037. void __fastcall TGUIConfiguration::SetResourceModule(HINSTANCE Instance)
  1038. {
  1039. HANDLE PrevHandle = ChangeResourceModule(Instance);
  1040. FreeResourceModule(PrevHandle);
  1041. DefaultLocalized();
  1042. }
  1043. //---------------------------------------------------------------------------
  1044. void __fastcall TGUIConfiguration::FindLocales(const UnicodeString & LocalesMask, TStrings * Exts, UnicodeString & LocalesExts)
  1045. {
  1046. int FindAttrs = faReadOnly | faArchive;
  1047. TSearchRecOwned SearchRec;
  1048. bool Found = (FindFirstUnchecked(LocalesMask, FindAttrs, SearchRec) == 0);
  1049. while (Found)
  1050. {
  1051. UnicodeString Ext = ExtractFileExt(SearchRec.Name).UpperCase();
  1052. // DLL is a remnant from times the .NET assembly was winscp.dll, not winscpnet.dll
  1053. if ((Ext.Length() >= 3) && (Ext != L".EXE") && (Ext != L".COM") &&
  1054. (Ext != L".DLL") && (Ext != L".INI") && (Ext != L".MAP"))
  1055. {
  1056. Ext = Ext.SubString(2, Ext.Length() - 1);
  1057. LocalesExts += Ext;
  1058. Exts->Add(Ext);
  1059. }
  1060. Found = (FindNextChecked(SearchRec) == 0);
  1061. }
  1062. }
  1063. //---------------------------------------------------------------------------
  1064. void __fastcall TGUIConfiguration::AddLocale(LCID Locale, const UnicodeString & Name)
  1065. {
  1066. std::unique_ptr<TLocaleInfo> LocaleInfo(new TLocaleInfo());
  1067. LocaleInfo->Locale = Locale;
  1068. LocaleInfo->Name = Name;
  1069. try
  1070. {
  1071. UnicodeString FileName;
  1072. HINSTANCE Module = LoadNewResourceModule(Locale, FileName);
  1073. try
  1074. {
  1075. LocaleInfo->Completeness = GetResourceModuleCompleteness(Module);
  1076. }
  1077. __finally
  1078. {
  1079. FreeResourceModule(Module);
  1080. }
  1081. }
  1082. catch (...)
  1083. {
  1084. LocaleInfo->Completeness = -1;
  1085. }
  1086. FLocales->Add(LocaleInfo.release());
  1087. }
  1088. //---------------------------------------------------------------------------
  1089. int __fastcall TGUIConfiguration::LocalesCompare(void * Item1, void * Item2)
  1090. {
  1091. TLocaleInfo * LocaleInfo1 = static_cast<TLocaleInfo *>(Item1);
  1092. TLocaleInfo * LocaleInfo2 = static_cast<TLocaleInfo *>(Item2);
  1093. return CompareText(LocaleInfo1->Name, LocaleInfo2->Name);
  1094. }
  1095. //---------------------------------------------------------------------------
  1096. TObjectList * __fastcall TGUIConfiguration::GetLocales()
  1097. {
  1098. UnicodeString LocalesMask = ChangeFileExt(ModuleFileName(), L".*");
  1099. UnicodeString SubLocalesMask = AddTranslationsSubFolder(LocalesMask);
  1100. UnicodeString LocalesExts;
  1101. std::unique_ptr<TStringList> Exts(CreateSortedStringList());
  1102. FindLocales(SubLocalesMask, Exts.get(), LocalesExts);
  1103. FindLocales(LocalesMask, Exts.get(), LocalesExts);
  1104. if (FLastLocalesExts != LocalesExts)
  1105. {
  1106. FLastLocalesExts = LocalesExts;
  1107. FLocales->Clear();
  1108. TLanguages * Langs = Languages();
  1109. int Count = Langs->Count;
  1110. int Index = -1;
  1111. while (Index < Count)
  1112. {
  1113. LCID Locale;
  1114. if (Index >= 0)
  1115. {
  1116. Locale = Langs->LocaleID[Index];
  1117. DWORD SubLang = SUBLANGID(Locale);
  1118. int Ext = Exts->IndexOf(Langs->Ext[Index]);
  1119. if ((Ext >= 0) && (Exts->Objects[Ext] == NULL))
  1120. {
  1121. // noop
  1122. }
  1123. else if (SubLang == SUBLANG_DEFAULT)
  1124. {
  1125. Ext = Exts->IndexOf(Langs->Ext[Index].SubString(1, 2));
  1126. if ((Ext >= 0) && (Exts->Objects[Ext] == NULL))
  1127. {
  1128. Locale = MAKELANGID(PRIMARYLANGID(Locale), SUBLANG_DEFAULT);
  1129. }
  1130. }
  1131. if (Ext >= 0)
  1132. {
  1133. Exts->Objects[Ext] = reinterpret_cast<TObject*>(Locale);
  1134. }
  1135. else
  1136. {
  1137. Locale = 0;
  1138. }
  1139. }
  1140. else
  1141. {
  1142. Locale = InternalLocale();
  1143. }
  1144. if (Locale)
  1145. {
  1146. wchar_t LocaleStr[255];
  1147. GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE,
  1148. LocaleStr, LENOF(LocaleStr));
  1149. UnicodeString Name = LocaleStr;
  1150. Name += L" - ";
  1151. // LOCALE_SNATIVELANGNAME
  1152. GetLocaleInfo(Locale, LOCALE_SLANGUAGE,
  1153. LocaleStr, LENOF(LocaleStr));
  1154. Name += LocaleStr;
  1155. AddLocale(Locale, Name);
  1156. }
  1157. Index++;
  1158. }
  1159. for (int Index = 0; Index < Exts->Count; Index++)
  1160. {
  1161. if ((Exts->Objects[Index] == NULL) &&
  1162. (Exts->Strings[Index].Length() == 3) &&
  1163. SameText(Exts->Strings[Index].SubString(1, 2), AdditionaLanguagePrefix))
  1164. {
  1165. UnicodeString ModulePath = ChangeFileExt(ModuleFileName(), UnicodeString(L".") + Exts->Strings[Index]);
  1166. ModulePath = GetTranslationModule(ModulePath);
  1167. UnicodeString LangName = GetFileFileInfoString(L"LangName", ModulePath);
  1168. if (!LangName.IsEmpty())
  1169. {
  1170. AddLocale(AdditionaLanguageMask + Exts->Strings[Index][3], LangName);
  1171. }
  1172. }
  1173. }
  1174. FLocales->Sort(LocalesCompare);
  1175. }
  1176. return FLocales;
  1177. }
  1178. //---------------------------------------------------------------------------
  1179. void __fastcall TGUIConfiguration::SetDefaultCopyParam(const TGUICopyParamType & value)
  1180. {
  1181. FDefaultCopyParam.Assign(&value);
  1182. Changed();
  1183. }
  1184. //---------------------------------------------------------------------------
  1185. bool __fastcall TGUIConfiguration::GetRememberPassword()
  1186. {
  1187. bool Result = SessionRememberPassword || PuttyPassword;
  1188. if (!Result)
  1189. {
  1190. try
  1191. {
  1192. TRemoteCustomCommand RemoteCustomCommand;
  1193. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1194. UnicodeString APuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1195. Result = RemoteCustomCommand.IsPasswordCommand(PuttyPath);
  1196. }
  1197. catch (...)
  1198. {
  1199. // noop
  1200. }
  1201. }
  1202. return Result;
  1203. }
  1204. //---------------------------------------------------------------------------
  1205. const TCopyParamList * __fastcall TGUIConfiguration::GetCopyParamList()
  1206. {
  1207. return FCopyParamList;
  1208. }
  1209. //---------------------------------------------------------------------------
  1210. void __fastcall TGUIConfiguration::SetCopyParamList(const TCopyParamList * value)
  1211. {
  1212. if (!(*FCopyParamList == *value))
  1213. {
  1214. *FCopyParamList = *value;
  1215. FCopyParamListDefaults = false;
  1216. Changed();
  1217. }
  1218. }
  1219. //---------------------------------------------------------------------------
  1220. int __fastcall TGUIConfiguration::GetCopyParamIndex()
  1221. {
  1222. int Result;
  1223. if (FCopyParamCurrent.IsEmpty())
  1224. {
  1225. Result = -1;
  1226. }
  1227. else
  1228. {
  1229. Result = FCopyParamList->IndexOfName(FCopyParamCurrent);
  1230. }
  1231. return Result;
  1232. }
  1233. //---------------------------------------------------------------------------
  1234. void __fastcall TGUIConfiguration::SetCopyParamIndex(int value)
  1235. {
  1236. UnicodeString Name;
  1237. if (value < 0)
  1238. {
  1239. Name = L"";
  1240. }
  1241. else
  1242. {
  1243. Name = FCopyParamList->Names[value];
  1244. }
  1245. CopyParamCurrent = Name;
  1246. }
  1247. //---------------------------------------------------------------------------
  1248. void __fastcall TGUIConfiguration::SetCopyParamCurrent(UnicodeString value)
  1249. {
  1250. SET_CONFIG_PROPERTY(CopyParamCurrent);
  1251. }
  1252. //---------------------------------------------------------------------------
  1253. TGUICopyParamType __fastcall TGUIConfiguration::GetCurrentCopyParam()
  1254. {
  1255. return CopyParamPreset[CopyParamCurrent];
  1256. }
  1257. //---------------------------------------------------------------------------
  1258. TGUICopyParamType __fastcall TGUIConfiguration::GetCopyParamPreset(UnicodeString Name)
  1259. {
  1260. TGUICopyParamType Result = FDefaultCopyParam;
  1261. if (!Name.IsEmpty())
  1262. {
  1263. int Index = FCopyParamList->IndexOfName(Name);
  1264. DebugAssert(Index >= 0);
  1265. if (Index >= 0)
  1266. {
  1267. const TCopyParamType * Preset = FCopyParamList->CopyParams[Index];
  1268. DebugAssert(Preset != NULL);
  1269. Result.Assign(Preset); // overwrite all but GUI options
  1270. // reset all options known not to be configurable per-preset
  1271. // kind of hack
  1272. Result.ResumeSupport = FDefaultCopyParam.ResumeSupport;
  1273. Result.ResumeThreshold = FDefaultCopyParam.ResumeThreshold;
  1274. Result.LocalInvalidChars = FDefaultCopyParam.LocalInvalidChars;
  1275. }
  1276. }
  1277. return Result;
  1278. }
  1279. //---------------------------------------------------------------------------
  1280. bool __fastcall TGUIConfiguration::GetHasCopyParamPreset(UnicodeString Name)
  1281. {
  1282. return Name.IsEmpty() || (FCopyParamList->IndexOfName(Name) >= 0);
  1283. }
  1284. //---------------------------------------------------------------------------
  1285. void __fastcall TGUIConfiguration::SetNewDirectoryProperties(
  1286. const TRemoteProperties & value)
  1287. {
  1288. SET_CONFIG_PROPERTY(NewDirectoryProperties);
  1289. }
  1290. //---------------------------------------------------------------------------
  1291. void __fastcall TGUIConfiguration::SetQueueTransfersLimit(int value)
  1292. {
  1293. SET_CONFIG_PROPERTY(QueueTransfersLimit);
  1294. }
  1295. //---------------------------------------------------------------------------
  1296. void __fastcall TGUIConfiguration::SetQueueKeepDoneItems(bool value)
  1297. {
  1298. SET_CONFIG_PROPERTY(QueueKeepDoneItems);
  1299. }
  1300. //---------------------------------------------------------------------------
  1301. void __fastcall TGUIConfiguration::SetQueueKeepDoneItemsFor(int value)
  1302. {
  1303. SET_CONFIG_PROPERTY(QueueKeepDoneItemsFor);
  1304. }
  1305. //---------------------------------------------------------------------
  1306. TStoredSessionList * __fastcall TGUIConfiguration::SelectPuttySessionsForImport(
  1307. TStoredSessionList * Sessions, UnicodeString & Error)
  1308. {
  1309. std::unique_ptr<TStoredSessionList> ImportSessionList(new TStoredSessionList(true));
  1310. ImportSessionList->DefaultSettings = Sessions->DefaultSettings;
  1311. std::unique_ptr<TRegistryStorage> Storage(new TRegistryStorage(PuttySessionsKey));
  1312. Storage->ForceAnsi = true;
  1313. if (Storage->OpenRootKey(false))
  1314. {
  1315. ImportSessionList->Load(Storage.get(), false, true, true);
  1316. }
  1317. TSessionData * PuttySessionData =
  1318. (TSessionData *)ImportSessionList->FindByName(PuttySession);
  1319. if (PuttySessionData != NULL)
  1320. {
  1321. ImportSessionList->Remove(PuttySessionData);
  1322. }
  1323. if (ImportSessionList->Count > 0)
  1324. {
  1325. ImportSessionList->SelectSessionsToImport(Sessions, true);
  1326. }
  1327. else
  1328. {
  1329. Error = FMTLOAD(PUTTY_NO_SITES, (PuttySessionsKey));
  1330. }
  1331. return ImportSessionList.release();
  1332. }
  1333. //---------------------------------------------------------------------
  1334. bool __fastcall TGUIConfiguration::AnyPuttySessionForImport(TStoredSessionList * Sessions)
  1335. {
  1336. try
  1337. {
  1338. UnicodeString Error;
  1339. std::unique_ptr<TStoredSessionList> Sesssions(SelectPuttySessionsForImport(Sessions, Error));
  1340. return (Sesssions->Count > 0);
  1341. }
  1342. catch (...)
  1343. {
  1344. return false;
  1345. }
  1346. }
  1347. //---------------------------------------------------------------------------