GUIConfiguration.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <LanguagesDEPfix.hpp>
  5. #include "GUIConfiguration.h"
  6. #include "GUITools.h"
  7. #include <Common.h>
  8. #include <FileInfo.h>
  9. #include <TextsCore.h>
  10. #include <Terminal.h>
  11. #include <CoreMain.h>
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. //---------------------------------------------------------------------------
  15. const ccLocal = ccUser;
  16. const ccShowResults = ccUser << 1;
  17. const ccCopyResults = ccUser << 2;
  18. const ccSet = 0x80000000;
  19. //---------------------------------------------------------------------------
  20. static const unsigned int AdditionaLanguageMask = 0xFFFFFF00;
  21. static const AnsiString AdditionaLanguagePrefix("XX");
  22. //---------------------------------------------------------------------------
  23. __fastcall TGUICopyParamType::TGUICopyParamType()
  24. : TCopyParamType()
  25. {
  26. GUIDefault();
  27. }
  28. //---------------------------------------------------------------------------
  29. __fastcall TGUICopyParamType::TGUICopyParamType(const TCopyParamType & Source)
  30. : TCopyParamType(Source)
  31. {
  32. GUIDefault();
  33. }
  34. //---------------------------------------------------------------------------
  35. __fastcall TGUICopyParamType::TGUICopyParamType(const TGUICopyParamType & Source)
  36. : TCopyParamType(Source)
  37. {
  38. GUIAssign(&Source);
  39. }
  40. //---------------------------------------------------------------------------
  41. void __fastcall TGUICopyParamType::Assign(const TCopyParamType * Source)
  42. {
  43. TCopyParamType::Assign(Source);
  44. const TGUICopyParamType * GUISource;
  45. GUISource = dynamic_cast<const TGUICopyParamType *>(Source);
  46. if (GUISource != NULL)
  47. {
  48. GUIAssign(GUISource);
  49. }
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TGUICopyParamType::GUIAssign(const TGUICopyParamType * Source)
  53. {
  54. Queue = Source->Queue;
  55. QueueNoConfirmation = Source->QueueNoConfirmation;
  56. QueueIndividually = Source->QueueIndividually;
  57. NewerOnly = Source->NewerOnly;
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TGUICopyParamType::Default()
  61. {
  62. TCopyParamType::Default();
  63. GUIDefault();
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TGUICopyParamType::GUIDefault()
  67. {
  68. Queue = false;
  69. QueueNoConfirmation = true;
  70. QueueIndividually = false;
  71. NewerOnly = false;
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TGUICopyParamType::Load(THierarchicalStorage * Storage)
  75. {
  76. TCopyParamType::Load(Storage);
  77. Queue = Storage->ReadBool("Queue", Queue);
  78. QueueNoConfirmation = Storage->ReadBool("QueueNoConfirmation", QueueNoConfirmation);
  79. QueueIndividually = Storage->ReadBool("QueueIndividually", QueueIndividually);
  80. NewerOnly = Storage->ReadBool("NewerOnly", NewerOnly);
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TGUICopyParamType::Save(THierarchicalStorage * Storage)
  84. {
  85. TCopyParamType::Save(Storage);
  86. Storage->WriteBool("Queue", Queue);
  87. Storage->WriteBool("QueueNoConfirmation", QueueNoConfirmation);
  88. Storage->WriteBool("QueueIndividually", QueueIndividually);
  89. Storage->WriteBool("NewerOnly", NewerOnly);
  90. }
  91. //---------------------------------------------------------------------------
  92. TGUICopyParamType & __fastcall TGUICopyParamType::operator =(const TCopyParamType & rhp)
  93. {
  94. Assign(&rhp);
  95. return *this;
  96. }
  97. //---------------------------------------------------------------------------
  98. TGUICopyParamType & __fastcall TGUICopyParamType::operator =(const TGUICopyParamType & rhp)
  99. {
  100. Assign(&rhp);
  101. return *this;
  102. }
  103. //---------------------------------------------------------------------------
  104. //---------------------------------------------------------------------------
  105. void __fastcall TCopyParamRuleData::Default()
  106. {
  107. HostName = "";
  108. UserName = "";
  109. RemoteDirectory = "";
  110. LocalDirectory = "";
  111. }
  112. //---------------------------------------------------------------------------
  113. //---------------------------------------------------------------------------
  114. __fastcall TCopyParamRule::TCopyParamRule()
  115. {
  116. }
  117. //---------------------------------------------------------------------------
  118. __fastcall TCopyParamRule::TCopyParamRule(const TCopyParamRuleData & Data)
  119. {
  120. FData = Data;
  121. }
  122. //---------------------------------------------------------------------------
  123. __fastcall TCopyParamRule::TCopyParamRule(const TCopyParamRule & Source)
  124. {
  125. FData.HostName = Source.FData.HostName;
  126. FData.UserName = Source.FData.UserName;
  127. FData.RemoteDirectory = Source.FData.RemoteDirectory;
  128. FData.LocalDirectory = Source.FData.LocalDirectory;
  129. }
  130. //---------------------------------------------------------------------------
  131. #define C(Property) (Property == rhp.Property)
  132. bool __fastcall TCopyParamRule::operator==(const TCopyParamRule & rhp) const
  133. {
  134. return
  135. C(FData.HostName) &&
  136. C(FData.UserName) &&
  137. C(FData.RemoteDirectory) &&
  138. C(FData.LocalDirectory) &&
  139. true;
  140. }
  141. #undef C
  142. //---------------------------------------------------------------------------
  143. bool __fastcall TCopyParamRule::Match(const AnsiString & Mask,
  144. const AnsiString & Value, bool Path, bool Local) const
  145. {
  146. bool Result;
  147. if (Mask.IsEmpty())
  148. {
  149. Result = true;
  150. }
  151. else
  152. {
  153. TFileMasks M(Mask);
  154. if (Path)
  155. {
  156. Result = M.Matches(Value, Local, true);
  157. }
  158. else
  159. {
  160. Result = M.Matches(Value, false);
  161. }
  162. }
  163. return Result;
  164. }
  165. //---------------------------------------------------------------------------
  166. bool __fastcall TCopyParamRule::Matches(const TCopyParamRuleData & Value) const
  167. {
  168. return
  169. Match(FData.HostName, Value.HostName, false) &&
  170. Match(FData.UserName, Value.UserName, false) &&
  171. Match(FData.RemoteDirectory, Value.RemoteDirectory, true, false) &&
  172. Match(FData.LocalDirectory, Value.LocalDirectory, true, true);
  173. }
  174. //---------------------------------------------------------------------------
  175. void __fastcall TCopyParamRule::Load(THierarchicalStorage * Storage)
  176. {
  177. FData.HostName = Storage->ReadString("HostName", FData.HostName);
  178. FData.UserName = Storage->ReadString("UserName", FData.UserName);
  179. FData.RemoteDirectory = Storage->ReadString("RemoteDirectory", FData.RemoteDirectory);
  180. FData.LocalDirectory = Storage->ReadString("LocalDirectory", FData.LocalDirectory);
  181. }
  182. //---------------------------------------------------------------------------
  183. void __fastcall TCopyParamRule::Save(THierarchicalStorage * Storage) const
  184. {
  185. Storage->WriteString("HostName", FData.HostName);
  186. Storage->WriteString("UserName", FData.UserName);
  187. Storage->WriteString("RemoteDirectory", FData.RemoteDirectory);
  188. Storage->WriteString("LocalDirectory", FData.LocalDirectory);
  189. }
  190. //---------------------------------------------------------------------------
  191. bool __fastcall TCopyParamRule::GetEmpty() const
  192. {
  193. return
  194. FData.HostName.IsEmpty() &&
  195. FData.UserName.IsEmpty() &&
  196. FData.RemoteDirectory.IsEmpty() &&
  197. FData.LocalDirectory.IsEmpty();
  198. }
  199. //---------------------------------------------------------------------------
  200. AnsiString __fastcall TCopyParamRule::GetInfoStr(AnsiString Separator) const
  201. {
  202. AnsiString Result;
  203. #define ADD(FMT, ELEM) \
  204. if (!FData.ELEM.IsEmpty()) \
  205. Result += (Result.IsEmpty() ? AnsiString() : Separator) + FMTLOAD(FMT, (FData.ELEM));
  206. ADD(COPY_RULE_HOSTNAME, HostName);
  207. ADD(COPY_RULE_USERNAME, UserName);
  208. ADD(COPY_RULE_REMOTE_DIR, RemoteDirectory);
  209. ADD(COPY_RULE_LOCAL_DIR, LocalDirectory);
  210. #undef ADD
  211. return Result;
  212. }
  213. //---------------------------------------------------------------------------
  214. //---------------------------------------------------------------------------
  215. AnsiString TCopyParamList::FInvalidChars("/\\[]");
  216. //---------------------------------------------------------------------------
  217. __fastcall TCopyParamList::TCopyParamList()
  218. {
  219. Init();
  220. }
  221. //---------------------------------------------------------------------------
  222. void __fastcall TCopyParamList::Init()
  223. {
  224. FCopyParams = new TList();
  225. FRules = new TList();
  226. FNames = new TStringList();
  227. FNameList = NULL;
  228. FModified = false;
  229. }
  230. //---------------------------------------------------------------------------
  231. __fastcall TCopyParamList::~TCopyParamList()
  232. {
  233. Clear();
  234. delete FCopyParams;
  235. delete FRules;
  236. delete FNames;
  237. delete FNameList;
  238. }
  239. //---------------------------------------------------------------------------
  240. void __fastcall TCopyParamList::Reset()
  241. {
  242. SAFE_DESTROY(FNameList);
  243. FModified = false;
  244. }
  245. //---------------------------------------------------------------------
  246. void __fastcall TCopyParamList::Modify()
  247. {
  248. SAFE_DESTROY(FNameList);
  249. FModified = true;
  250. }
  251. //---------------------------------------------------------------------
  252. void __fastcall TCopyParamList::ValidateName(const AnsiString Name)
  253. {
  254. if (Name.LastDelimiter(FInvalidChars) > 0)
  255. {
  256. throw Exception(FMTLOAD(ITEM_NAME_INVALID, (Name, FInvalidChars)));
  257. }
  258. }
  259. //---------------------------------------------------------------------------
  260. void __fastcall TCopyParamList::operator=(const TCopyParamList & rhl)
  261. {
  262. Clear();
  263. for (int Index = 0; Index < rhl.Count; Index++)
  264. {
  265. TCopyParamType * CopyParam = new TCopyParamType(*rhl.CopyParams[Index]);
  266. TCopyParamRule * Rule = NULL;
  267. if (rhl.Rules[Index] != NULL)
  268. {
  269. Rule = new TCopyParamRule(*rhl.Rules[Index]);
  270. }
  271. Add(rhl.Names[Index], CopyParam, Rule);
  272. }
  273. // there should be comparison of with the assigned list, be we rely on caller
  274. // to do it instead (TGUIConfiguration::SetCopyParamList)
  275. Modify();
  276. }
  277. //---------------------------------------------------------------------------
  278. bool __fastcall TCopyParamList::operator==(const TCopyParamList & rhl) const
  279. {
  280. bool Result = (Count == rhl.Count);
  281. if (Result)
  282. {
  283. int i = 0;
  284. while ((i < Count) && Result)
  285. {
  286. Result =
  287. (Names[i] == rhl.Names[i]) &&
  288. CompareItem(i, rhl.CopyParams[i], rhl.Rules[i]);
  289. i++;
  290. }
  291. }
  292. return Result;
  293. }
  294. //---------------------------------------------------------------------------
  295. int __fastcall TCopyParamList::IndexOfName(const AnsiString Name) const
  296. {
  297. return FNames->IndexOf(Name);
  298. }
  299. //---------------------------------------------------------------------------
  300. bool __fastcall TCopyParamList::CompareItem(int Index,
  301. const TCopyParamType * CopyParam, const TCopyParamRule * Rule) const
  302. {
  303. return
  304. ((*CopyParams[Index]) == *CopyParam) &&
  305. ((Rules[Index] == NULL) ?
  306. (Rule == NULL) :
  307. ((Rule != NULL) && (*Rules[Index]) == (*Rule)));
  308. }
  309. //---------------------------------------------------------------------------
  310. void __fastcall TCopyParamList::Clear()
  311. {
  312. for (int i = 0; i < Count; i++)
  313. {
  314. delete CopyParams[i];
  315. delete Rules[i];
  316. }
  317. FCopyParams->Clear();
  318. FRules->Clear();
  319. FNames->Clear();
  320. }
  321. //---------------------------------------------------------------------------
  322. void __fastcall TCopyParamList::Add(const AnsiString Name,
  323. TCopyParamType * CopyParam, TCopyParamRule * Rule)
  324. {
  325. Insert(Count, Name, CopyParam, Rule);
  326. }
  327. //---------------------------------------------------------------------------
  328. void __fastcall TCopyParamList::Insert(int Index, const AnsiString Name,
  329. TCopyParamType * CopyParam, TCopyParamRule * Rule)
  330. {
  331. assert(FNames->IndexOf(Name) < 0);
  332. FNames->Insert(Index, Name);
  333. assert(CopyParam != NULL);
  334. FCopyParams->Insert(Index, reinterpret_cast<TObject *>(CopyParam));
  335. FRules->Insert(Index, reinterpret_cast<TObject *>(Rule));
  336. Modify();
  337. }
  338. //---------------------------------------------------------------------------
  339. void __fastcall TCopyParamList::Change(int Index, const AnsiString Name,
  340. TCopyParamType * CopyParam, TCopyParamRule * Rule)
  341. {
  342. if ((Name != Names[Index]) || !CompareItem(Index, CopyParam, Rule))
  343. {
  344. FNames->Strings[Index] = Name;
  345. delete CopyParams[Index];
  346. FCopyParams->Items[Index] = (reinterpret_cast<TObject *>(CopyParam));
  347. delete Rules[Index];
  348. FRules->Items[Index] = (reinterpret_cast<TObject *>(Rule));
  349. Modify();
  350. }
  351. else
  352. {
  353. delete CopyParam;
  354. delete Rule;
  355. }
  356. }
  357. //---------------------------------------------------------------------------
  358. void __fastcall TCopyParamList::Move(int CurIndex, int NewIndex)
  359. {
  360. if (CurIndex != NewIndex)
  361. {
  362. FNames->Move(CurIndex, NewIndex);
  363. FCopyParams->Move(CurIndex, NewIndex);
  364. FRules->Move(CurIndex, NewIndex);
  365. Modify();
  366. }
  367. }
  368. //---------------------------------------------------------------------------
  369. void __fastcall TCopyParamList::Delete(int Index)
  370. {
  371. assert((Index >= 0) && (Index < Count));
  372. FNames->Delete(Index);
  373. delete CopyParams[Index];
  374. FCopyParams->Delete(Index);
  375. delete Rules[Index];
  376. FRules->Delete(Index);
  377. Modify();
  378. }
  379. //---------------------------------------------------------------------------
  380. int __fastcall TCopyParamList::Find(const TCopyParamRuleData & Value) const
  381. {
  382. int Result = -1;
  383. int i = 0;
  384. while ((i < FRules->Count) && (Result < 0))
  385. {
  386. if (FRules->Items[i] != NULL)
  387. {
  388. if (Rules[i]->Matches(Value))
  389. {
  390. Result = i;
  391. }
  392. }
  393. i++;
  394. }
  395. return Result;
  396. }
  397. //---------------------------------------------------------------------------
  398. void __fastcall TCopyParamList::Load(THierarchicalStorage * Storage, int ACount)
  399. {
  400. for (int Index = 0; Index < ACount; Index++)
  401. {
  402. AnsiString Name = IntToStr(Index);
  403. TCopyParamRule * Rule = NULL;
  404. TCopyParamType * CopyParam = new TCopyParamType();
  405. try
  406. {
  407. if (Storage->OpenSubKey(Name, false))
  408. {
  409. try
  410. {
  411. Name = Storage->ReadString("Name", Name);
  412. CopyParam->Load(Storage);
  413. if (Storage->ReadBool("HasRule", false))
  414. {
  415. Rule = new TCopyParamRule();
  416. Rule->Load(Storage);
  417. }
  418. }
  419. __finally
  420. {
  421. Storage->CloseSubKey();
  422. }
  423. }
  424. }
  425. catch(...)
  426. {
  427. delete CopyParam;
  428. delete Rule;
  429. throw;
  430. }
  431. FCopyParams->Add(reinterpret_cast<TObject *>(CopyParam));
  432. FRules->Add(reinterpret_cast<TObject *>(Rule));
  433. FNames->Add(Name);
  434. }
  435. Reset();
  436. }
  437. //---------------------------------------------------------------------------
  438. void __fastcall TCopyParamList::Save(THierarchicalStorage * Storage) const
  439. {
  440. Storage->ClearSubKeys();
  441. for (int Index = 0; Index < Count; Index++)
  442. {
  443. if (Storage->OpenSubKey(IntToStr(Index), true))
  444. {
  445. try
  446. {
  447. const TCopyParamType * CopyParam = CopyParams[Index];
  448. const TCopyParamRule * Rule = Rules[Index];
  449. Storage->WriteString("Name", Names[Index]);
  450. CopyParam->Save(Storage);
  451. Storage->WriteBool("HasRule", (Rule != NULL));
  452. if (Rule != NULL)
  453. {
  454. Rule->Save(Storage);
  455. }
  456. }
  457. __finally
  458. {
  459. Storage->CloseSubKey();
  460. }
  461. }
  462. }
  463. }
  464. //---------------------------------------------------------------------------
  465. int __fastcall TCopyParamList::GetCount() const
  466. {
  467. return FCopyParams->Count;
  468. }
  469. //---------------------------------------------------------------------------
  470. const TCopyParamRule * __fastcall TCopyParamList::GetRule(int Index) const
  471. {
  472. return reinterpret_cast<TCopyParamRule *>(FRules->Items[Index]);
  473. }
  474. //---------------------------------------------------------------------------
  475. const TCopyParamType * __fastcall TCopyParamList::GetCopyParam(int Index) const
  476. {
  477. return reinterpret_cast<TCopyParamType *>(FCopyParams->Items[Index]);
  478. }
  479. //---------------------------------------------------------------------------
  480. AnsiString __fastcall TCopyParamList::GetName(int Index) const
  481. {
  482. return FNames->Strings[Index];
  483. }
  484. //---------------------------------------------------------------------------
  485. TStrings * __fastcall TCopyParamList::GetNameList() const
  486. {
  487. if (FNameList == NULL)
  488. {
  489. FNameList = new TStringList();
  490. for (int i = 0; i < Count; i++)
  491. {
  492. FNameList->Add(FNames->Strings[i]);
  493. }
  494. }
  495. return FNameList;
  496. }
  497. //---------------------------------------------------------------------------
  498. bool __fastcall TCopyParamList::GetAnyRule() const
  499. {
  500. bool Result = false;
  501. int i = 0;
  502. while ((i < Count) && !Result)
  503. {
  504. Result = (Rules[i] != NULL);
  505. i++;
  506. }
  507. return Result;
  508. }
  509. //---------------------------------------------------------------------------
  510. //---------------------------------------------------------------------------
  511. __fastcall TGUIConfiguration::TGUIConfiguration(): TConfiguration()
  512. {
  513. FLocale = 0;
  514. FLocales = new TStringList();
  515. FLastLocalesExts = "*";
  516. dynamic_cast<TStringList*>(FLocales)->Sorted = true;
  517. dynamic_cast<TStringList*>(FLocales)->CaseSensitive = false;
  518. FCopyParamList = new TCopyParamList();
  519. CoreSetResourceModule(GetResourceModule());
  520. }
  521. //---------------------------------------------------------------------------
  522. __fastcall TGUIConfiguration::~TGUIConfiguration()
  523. {
  524. delete FLocales;
  525. delete FCopyParamList;
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TGUIConfiguration::Default()
  529. {
  530. TConfiguration::Default();
  531. // reset before call to DefaultLocalized()
  532. FDefaultCopyParam.Default();
  533. FCopyParamListDefaults = true;
  534. DefaultLocalized();
  535. FIgnoreCancelBeforeFinish = TDateTime(0, 0, 3, 0);
  536. FContinueOnError = false;
  537. FConfirmCommandSession = true;
  538. FSynchronizeParams = TTerminal::spNoConfirmation | TTerminal::spPreviewChanges;
  539. FSynchronizeModeAuto = -1;
  540. FSynchronizeMode = TTerminal::smRemote;
  541. FMaxWatchDirectories = 500;
  542. FSynchronizeOptions = soRecurse | soSynchronizeAsk;
  543. FQueueTransfersLimit = 2;
  544. FQueueAutoPopup = true;
  545. FQueueRememberPassword = false;
  546. AnsiString ProgramsFolder;
  547. SpecialFolderLocation(CSIDL_PROGRAM_FILES, ProgramsFolder);
  548. FDefaultPuttyPathOnly = IncludeTrailingBackslash(ProgramsFolder) + "PuTTY\\putty.exe";
  549. FDefaultPuttyPath = FormatCommand("%PROGRAMFILES%\\PuTTY\\putty.exe", "");
  550. FPuttyPath = FDefaultPuttyPath;
  551. PSftpPath = FormatCommand("%PROGRAMFILES%\\PuTTY\\psftp.exe", "");
  552. FPuttyPassword = false;
  553. FTelnetForFtpInPutty = true;
  554. FPuttySession = "WinSCP temporary session";
  555. FBeepOnFinish = false;
  556. FBeepOnFinishAfter = TDateTime(0, 0, 30, 0);
  557. FSynchronizeBrowsing = false;
  558. FCopyParamCurrent = "";
  559. FKeepUpToDateChangeDelay = 500;
  560. FChecksumAlg = "md5";
  561. FSessionReopenAutoIdle = 5000;
  562. FNewDirectoryProperties.Default();
  563. FNewDirectoryProperties.Rights = TRights::rfDefault | TRights::rfExec;
  564. }
  565. //---------------------------------------------------------------------------
  566. void __fastcall TGUIConfiguration::DefaultLocalized()
  567. {
  568. if (FCopyParamListDefaults)
  569. {
  570. FCopyParamList->Clear();
  571. // guard against "empty resourse string" from obsolete traslations
  572. // (DefaultLocalized is called for the first time before detection of
  573. // obsolete translations)
  574. if (!LoadStr(COPY_PARAM_PRESET_ASCII).IsEmpty())
  575. {
  576. TCopyParamType * CopyParam;
  577. CopyParam = new TCopyParamType(FDefaultCopyParam);
  578. CopyParam->TransferMode = tmAscii;
  579. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_ASCII), CopyParam, NULL);
  580. CopyParam = new TCopyParamType(FDefaultCopyParam);
  581. CopyParam->TransferMode = tmBinary;
  582. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_BINARY), CopyParam, NULL);
  583. CopyParam = new TCopyParamType(FDefaultCopyParam);
  584. CopyParam->ExcludeFileMask.Masks = "*.bak; *.tmp; ~$*; *.wbk; *~; #*; .#*";
  585. CopyParam->NegativeExclude = false; // just for sure
  586. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_EXCLUDE), CopyParam, NULL);
  587. }
  588. FCopyParamList->Reset();
  589. }
  590. }
  591. //---------------------------------------------------------------------------
  592. AnsiString __fastcall TGUIConfiguration::PropertyToKey(const AnsiString Property)
  593. {
  594. // no longer useful
  595. int P = Property.LastDelimiter(".>");
  596. return Property.SubString(P + 1, Property.Length() - P);
  597. }
  598. //---------------------------------------------------------------------------
  599. // duplicated from core\configuration.cpp
  600. #define BLOCK(KEY, CANCREATE, BLOCK) \
  601. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  602. #define REGCONFIG(CANCREATE) \
  603. BLOCK("Interface", CANCREATE, \
  604. KEY(Bool, ContinueOnError); \
  605. KEY(Bool, ConfirmCommandSession); \
  606. KEY(Integer, SynchronizeParams); \
  607. KEY(Integer, SynchronizeOptions); \
  608. KEY(Integer, SynchronizeModeAuto); \
  609. KEY(Integer, SynchronizeMode); \
  610. KEY(Integer, MaxWatchDirectories); \
  611. KEY(Integer, QueueTransfersLimit); \
  612. KEY(Bool, QueueAutoPopup); \
  613. KEY(Bool, QueueRememberPassword); \
  614. KEY(String, PuttySession); \
  615. KEY(String, PuttyPath); \
  616. KEY(Bool, PuttyPassword); \
  617. KEY(Bool, TelnetForFtpInPutty); \
  618. KEY(DateTime, IgnoreCancelBeforeFinish); \
  619. KEY(Bool, BeepOnFinish); \
  620. KEY(DateTime, BeepOnFinishAfter); \
  621. KEY(Bool, SynchronizeBrowsing); \
  622. KEY(Integer, KeepUpToDateChangeDelay); \
  623. KEY(String, ChecksumAlg); \
  624. KEY(Integer, SessionReopenAutoIdle); \
  625. ); \
  626. //---------------------------------------------------------------------------
  627. void __fastcall TGUIConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  628. {
  629. TConfiguration::SaveData(Storage, All);
  630. // duplicated from core\configuration.cpp
  631. #define KEY(TYPE, VAR) Storage->Write ## TYPE(PropertyToKey(#VAR), VAR)
  632. REGCONFIG(true);
  633. #undef KEY
  634. if (Storage->OpenSubKey("Interface\\CopyParam", true, true))
  635. try
  636. {
  637. FDefaultCopyParam.Save(Storage);
  638. if (FCopyParamListDefaults)
  639. {
  640. assert(!FCopyParamList->Modified);
  641. Storage->WriteInteger("CopyParamList", -1);
  642. }
  643. else if (All || FCopyParamList->Modified)
  644. {
  645. Storage->WriteInteger("CopyParamList", FCopyParamList->Count);
  646. FCopyParamList->Save(Storage);
  647. }
  648. }
  649. __finally
  650. {
  651. Storage->CloseSubKey();
  652. }
  653. if (Storage->OpenSubKey("Interface\\NewDirectory2", true, true))
  654. try
  655. {
  656. FNewDirectoryProperties.Save(Storage);
  657. }
  658. __finally
  659. {
  660. Storage->CloseSubKey();
  661. }
  662. }
  663. //---------------------------------------------------------------------------
  664. void __fastcall TGUIConfiguration::LoadData(THierarchicalStorage * Storage)
  665. {
  666. TConfiguration::LoadData(Storage);
  667. // duplicated from core\configuration.cpp
  668. #define KEY(TYPE, VAR) VAR = Storage->Read ## TYPE(PropertyToKey(#VAR), VAR)
  669. #pragma warn -eas
  670. REGCONFIG(false);
  671. #pragma warn +eas
  672. #undef KEY
  673. if (Storage->OpenSubKey("Interface\\CopyParam", false, true))
  674. try
  675. {
  676. // must be loaded before eventual setting defaults for CopyParamList
  677. FDefaultCopyParam.Load(Storage);
  678. int CopyParamListCount = Storage->ReadInteger("CopyParamList", -1);
  679. FCopyParamListDefaults = (CopyParamListCount < 0);
  680. if (!FCopyParamListDefaults)
  681. {
  682. FCopyParamList->Clear();
  683. FCopyParamList->Load(Storage, CopyParamListCount);
  684. }
  685. else if (FCopyParamList->Modified)
  686. {
  687. FCopyParamList->Clear();
  688. FCopyParamListDefaults = false;
  689. }
  690. FCopyParamList->Reset();
  691. }
  692. __finally
  693. {
  694. Storage->CloseSubKey();
  695. }
  696. // Make it compatible with versions prior to 3.7.1 that have not saved PuttyPath
  697. // with quotes. First check for absence of quotes.
  698. // Add quotes either if the path is set to default putty path (even if it does
  699. // not exists) or when the path points to existing file (so there are no parameters
  700. // yet in the string). Note that FileExists may display error dialog, but as
  701. // it should be called only for custom users path, let's expect that the user
  702. // can take care of it.
  703. if ((FPuttyPath.SubString(1, 1) != "\"") &&
  704. (CompareFileName(ExpandEnvironmentVariables(FPuttyPath), FDefaultPuttyPathOnly) ||
  705. FileExists(ExpandEnvironmentVariables(FPuttyPath))))
  706. {
  707. FPuttyPath = FormatCommand(FPuttyPath, "");
  708. }
  709. if (Storage->OpenSubKey("Interface\\NewDirectory2", false, true))
  710. try
  711. {
  712. FNewDirectoryProperties.Load(Storage);
  713. }
  714. __finally
  715. {
  716. Storage->CloseSubKey();
  717. }
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TGUIConfiguration::Saved()
  721. {
  722. TConfiguration::Saved();
  723. FCopyParamList->Reset();
  724. }
  725. //---------------------------------------------------------------------------
  726. //---------------------------------------------------------------------------
  727. HANDLE __fastcall TGUIConfiguration::LoadNewResourceModule(LCID ALocale,
  728. AnsiString * FileName)
  729. {
  730. AnsiString LibraryFileName;
  731. HANDLE NewInstance = 0;
  732. bool Internal = (ALocale == InternalLocale());
  733. if (!Internal)
  734. {
  735. AnsiString Module;
  736. AnsiString LocaleName;
  737. Module = ModuleFileName();
  738. if ((ALocale & AdditionaLanguageMask) != AdditionaLanguageMask)
  739. {
  740. char LocaleStr[4];
  741. GetLocaleInfo(ALocale, LOCALE_SABBREVLANGNAME, LocaleStr, sizeof(LocaleStr));
  742. LocaleName = LocaleStr;
  743. assert(!LocaleName.IsEmpty());
  744. }
  745. else
  746. {
  747. LocaleName = AdditionaLanguagePrefix +
  748. char(ALocale & ~AdditionaLanguageMask);
  749. }
  750. Module = ChangeFileExt(Module, AnsiString(".") + LocaleName);
  751. // Look for a potential language/country translation
  752. NewInstance = LoadLibraryEx(Module.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  753. if (!NewInstance)
  754. {
  755. // Finally look for a language only translation
  756. Module.SetLength(Module.Length() - 1);
  757. NewInstance = LoadLibraryEx(Module.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  758. if (NewInstance)
  759. {
  760. LibraryFileName = Module;
  761. }
  762. }
  763. else
  764. {
  765. LibraryFileName = Module;
  766. }
  767. }
  768. if (!NewInstance && !Internal)
  769. {
  770. throw Exception(FMTLOAD(LOCALE_LOAD_ERROR, (int(ALocale))));
  771. }
  772. else
  773. {
  774. if (Internal)
  775. {
  776. NewInstance = HInstance;
  777. }
  778. }
  779. if (FileName != NULL)
  780. {
  781. *FileName = LibraryFileName;
  782. }
  783. return NewInstance;
  784. }
  785. //---------------------------------------------------------------------------
  786. LCID __fastcall TGUIConfiguration::InternalLocale()
  787. {
  788. LCID Result;
  789. if (GetTranslationCount(ApplicationInfo) > 0)
  790. {
  791. TTranslation Translation;
  792. Translation = GetTranslation(ApplicationInfo, 0);
  793. Result = MAKELANGID(PRIMARYLANGID(Translation.Language), SUBLANG_DEFAULT);
  794. }
  795. else
  796. {
  797. assert(false);
  798. Result = 0;
  799. }
  800. return Result;
  801. }
  802. //---------------------------------------------------------------------------
  803. LCID __fastcall TGUIConfiguration::GetLocale()
  804. {
  805. if (!FLocale)
  806. {
  807. FLocale = InternalLocale();
  808. }
  809. return FLocale;
  810. }
  811. //---------------------------------------------------------------------------
  812. void __fastcall TGUIConfiguration::SetLocale(LCID value)
  813. {
  814. if (Locale != value)
  815. {
  816. HANDLE Module = LoadNewResourceModule(value);
  817. if (Module != NULL)
  818. {
  819. FLocale = value;
  820. SetResourceModule(Module);
  821. }
  822. else
  823. {
  824. assert(false);
  825. }
  826. }
  827. }
  828. //---------------------------------------------------------------------------
  829. void __fastcall TGUIConfiguration::SetLocaleSafe(LCID value)
  830. {
  831. if (Locale != value)
  832. {
  833. HANDLE Module;
  834. try
  835. {
  836. Module = LoadNewResourceModule(value);
  837. }
  838. catch(...)
  839. {
  840. // ignore any exception while loading locale
  841. Module = NULL;
  842. }
  843. if (Module != NULL)
  844. {
  845. FLocale = value;
  846. SetResourceModule(Module);
  847. }
  848. }
  849. }
  850. //---------------------------------------------------------------------------
  851. void __fastcall TGUIConfiguration::FreeResourceModule(HANDLE Instance)
  852. {
  853. TPasLibModule * MainModule = FindModule(HInstance);
  854. if (Instance != MainModule->Instance)
  855. {
  856. FreeLibrary(static_cast<HMODULE>(Instance));
  857. }
  858. }
  859. //---------------------------------------------------------------------------
  860. HANDLE __fastcall TGUIConfiguration::ChangeResourceModule(HANDLE Instance)
  861. {
  862. if (Instance == NULL)
  863. {
  864. Instance = HInstance;
  865. }
  866. TPasLibModule * MainModule = FindModule(HInstance);
  867. HANDLE Result = MainModule->ResInstance;
  868. MainModule->ResInstance = Instance;
  869. CoreSetResourceModule(Instance);
  870. return Result;
  871. }
  872. //---------------------------------------------------------------------------
  873. HANDLE __fastcall TGUIConfiguration::GetResourceModule()
  874. {
  875. return FindModule(HInstance)->ResInstance;
  876. }
  877. //---------------------------------------------------------------------------
  878. void __fastcall TGUIConfiguration::SetResourceModule(HANDLE Instance)
  879. {
  880. HANDLE PrevHandle = ChangeResourceModule(Instance);
  881. FreeResourceModule(PrevHandle);
  882. DefaultLocalized();
  883. }
  884. //---------------------------------------------------------------------------
  885. TStrings * __fastcall TGUIConfiguration::GetLocales()
  886. {
  887. AnsiString LocalesExts;
  888. TStringList * Exts = new TStringList();
  889. try
  890. {
  891. Exts->Sorted = true;
  892. Exts->CaseSensitive = false;
  893. int FindAttrs = faReadOnly | faArchive;
  894. TSearchRec SearchRec;
  895. bool Found;
  896. Found = (bool)(FindFirst(ChangeFileExt(ModuleFileName(), ".*"),
  897. FindAttrs, SearchRec) == 0);
  898. try
  899. {
  900. AnsiString Ext;
  901. while (Found)
  902. {
  903. Ext = ExtractFileExt(SearchRec.Name).UpperCase();
  904. if ((Ext.Length() >= 3) && (Ext != ".EXE") && (Ext != ".COM") &&
  905. (Ext != ".DLL") && (Ext != ".INI"))
  906. {
  907. Ext = Ext.SubString(2, Ext.Length() - 1);
  908. LocalesExts += Ext;
  909. Exts->Add(Ext);
  910. }
  911. Found = (FindNext(SearchRec) == 0);
  912. }
  913. }
  914. __finally
  915. {
  916. FindClose(SearchRec);
  917. }
  918. if (FLastLocalesExts != LocalesExts)
  919. {
  920. FLastLocalesExts = LocalesExts;
  921. FLocales->Clear();
  922. TLanguages * Langs = LanguagesDEPF();
  923. int Ext, Index, Count;
  924. char LocaleStr[255];
  925. LCID Locale;
  926. Count = Langs->Count;
  927. Index = -1;
  928. while (Index < Count)
  929. {
  930. if (Index >= 0)
  931. {
  932. Locale = Langs->LocaleID[Index];
  933. Ext = Exts->IndexOf(Langs->Ext[Index]);
  934. if (Ext < 0)
  935. {
  936. Ext = Exts->IndexOf(Langs->Ext[Index].SubString(1, 2));
  937. if (Ext >= 0)
  938. {
  939. Locale = MAKELANGID(PRIMARYLANGID(Locale), SUBLANG_DEFAULT);
  940. }
  941. }
  942. if (Ext >= 0)
  943. {
  944. Exts->Objects[Ext] = reinterpret_cast<TObject*>(Locale);
  945. }
  946. else
  947. {
  948. Locale = 0;
  949. }
  950. }
  951. else
  952. {
  953. Locale = InternalLocale();
  954. }
  955. if (Locale)
  956. {
  957. AnsiString Name;
  958. GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE,
  959. LocaleStr, sizeof(LocaleStr));
  960. Name = LocaleStr;
  961. Name += " - ";
  962. // LOCALE_SNATIVELANGNAME
  963. GetLocaleInfo(Locale, LOCALE_SLANGUAGE,
  964. LocaleStr, sizeof(LocaleStr));
  965. Name += LocaleStr;
  966. FLocales->AddObject(Name, reinterpret_cast<TObject*>(Locale));
  967. }
  968. Index++;
  969. }
  970. for (int Index = 0; Index < Exts->Count; Index++)
  971. {
  972. if ((Exts->Objects[Index] == NULL) &&
  973. (Exts->Strings[Index].Length() == 3) &&
  974. SameText(Exts->Strings[Index].SubString(1, 2), AdditionaLanguagePrefix))
  975. {
  976. AnsiString LangName = GetFileFileInfoString("LangName",
  977. ChangeFileExt(ModuleFileName(), AnsiString(".") + Exts->Strings[Index]));
  978. if (!LangName.IsEmpty())
  979. {
  980. FLocales->AddObject(LangName, reinterpret_cast<TObject*>(
  981. AdditionaLanguageMask + Exts->Strings[Index][3]));
  982. }
  983. }
  984. }
  985. }
  986. }
  987. __finally
  988. {
  989. delete Exts;
  990. }
  991. return FLocales;
  992. }
  993. //---------------------------------------------------------------------------
  994. void __fastcall TGUIConfiguration::SetDefaultCopyParam(const TGUICopyParamType & value)
  995. {
  996. FDefaultCopyParam.Assign(&value);
  997. Changed();
  998. }
  999. //---------------------------------------------------------------------------
  1000. bool __fastcall TGUIConfiguration::GetRememberPassword()
  1001. {
  1002. return QueueRememberPassword || PuttyPassword;
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. const TCopyParamList * __fastcall TGUIConfiguration::GetCopyParamList()
  1006. {
  1007. return FCopyParamList;
  1008. }
  1009. //---------------------------------------------------------------------------
  1010. void __fastcall TGUIConfiguration::SetCopyParamList(const TCopyParamList * value)
  1011. {
  1012. if (!(*FCopyParamList == *value))
  1013. {
  1014. *FCopyParamList = *value;
  1015. FCopyParamListDefaults = false;
  1016. Changed();
  1017. }
  1018. }
  1019. //---------------------------------------------------------------------------
  1020. int __fastcall TGUIConfiguration::GetCopyParamIndex()
  1021. {
  1022. int Result;
  1023. if (FCopyParamCurrent.IsEmpty())
  1024. {
  1025. Result = -1;
  1026. }
  1027. else
  1028. {
  1029. Result = FCopyParamList->IndexOfName(FCopyParamCurrent);
  1030. }
  1031. return Result;
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void __fastcall TGUIConfiguration::SetCopyParamIndex(int value)
  1035. {
  1036. AnsiString Name;
  1037. if (value < 0)
  1038. {
  1039. Name = "";
  1040. }
  1041. else
  1042. {
  1043. Name = FCopyParamList->Names[value];
  1044. }
  1045. CopyParamCurrent = Name;
  1046. }
  1047. //---------------------------------------------------------------------------
  1048. void __fastcall TGUIConfiguration::SetCopyParamCurrent(AnsiString value)
  1049. {
  1050. SET_CONFIG_PROPERTY(CopyParamCurrent);
  1051. }
  1052. //---------------------------------------------------------------------------
  1053. TGUICopyParamType __fastcall TGUIConfiguration::GetCurrentCopyParam()
  1054. {
  1055. return CopyParamPreset[CopyParamCurrent];
  1056. }
  1057. //---------------------------------------------------------------------------
  1058. TGUICopyParamType __fastcall TGUIConfiguration::GetCopyParamPreset(AnsiString Name)
  1059. {
  1060. TGUICopyParamType Result = FDefaultCopyParam;
  1061. if (!Name.IsEmpty())
  1062. {
  1063. int Index = FCopyParamList->IndexOfName(Name);
  1064. assert(Index >= 0);
  1065. if (Index >= 0)
  1066. {
  1067. const TCopyParamType * Preset = FCopyParamList->CopyParams[Index];
  1068. assert(Preset != NULL);
  1069. Result.Assign(Preset); // overwrite all but GUI options
  1070. // reset all options known not to be configurable per-preset
  1071. // kind of hack
  1072. Result.ResumeSupport = FDefaultCopyParam.ResumeSupport;
  1073. Result.ResumeThreshold = FDefaultCopyParam.ResumeThreshold;
  1074. Result.LocalInvalidChars = FDefaultCopyParam.LocalInvalidChars;
  1075. }
  1076. }
  1077. return Result;
  1078. }
  1079. //---------------------------------------------------------------------------
  1080. void __fastcall TGUIConfiguration::SetNewDirectoryProperties(
  1081. const TRemoteProperties & value)
  1082. {
  1083. SET_CONFIG_PROPERTY(NewDirectoryProperties);
  1084. }
  1085. //---------------------------------------------------------------------------