GUIConfiguration.cpp 45 KB

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