GUIConfiguration.cpp 45 KB

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