GUIConfiguration.cpp 35 KB

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