GUIConfiguration.cpp 43 KB

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