GUIConfiguration.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  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. FErrorDialogExpanded = false;
  534. FContinueOnError = false;
  535. FConfirmCommandSession = true;
  536. FSynchronizeParams = TTerminal::spNoConfirmation | TTerminal::spPreviewChanges;
  537. FSynchronizeModeAuto = -1;
  538. FSynchronizeMode = TTerminal::smRemote;
  539. FMaxWatchDirectories = 500;
  540. FSynchronizeOptions = soRecurse | soSynchronizeAsk;
  541. FQueueTransfersLimit = 2;
  542. FQueueAutoPopup = true;
  543. FQueueRememberPassword = false;
  544. AnsiString ProgramsFolder;
  545. SpecialFolderLocation(CSIDL_PROGRAM_FILES, ProgramsFolder);
  546. FDefaultPuttyPathOnly = IncludeTrailingBackslash(ProgramsFolder) + "PuTTY\\putty.exe";
  547. FDefaultPuttyPath = FormatCommand("%PROGRAMFILES%\\PuTTY\\putty.exe", "");
  548. FPuttyPath = FDefaultPuttyPath;
  549. PSftpPath = FormatCommand("%PROGRAMFILES%\\PuTTY\\psftp.exe", "");
  550. FPuttyPassword = false;
  551. FTelnetForFtpInPutty = true;
  552. FPuttySession = "WinSCP temporary session";
  553. FBeepOnFinish = false;
  554. FBeepOnFinishAfter = TDateTime(0, 0, 30, 0);
  555. FSynchronizeBrowsing = false;
  556. FCopyParamCurrent = "";
  557. FKeepUpToDateChangeDelay = 500;
  558. FChecksumAlg = "md5";
  559. FNewDirectoryProperties.Default();
  560. FNewDirectoryProperties.Rights = TRights::rfDefault;
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TGUIConfiguration::DefaultLocalized()
  564. {
  565. if (FCopyParamListDefaults)
  566. {
  567. FCopyParamList->Clear();
  568. // guard against "empty resourse string" from obsolete traslations
  569. // (DefaultLocalized is called for the first time before detection of
  570. // obsolete translations)
  571. if (!LoadStr(COPY_PARAM_PRESET_ASCII).IsEmpty())
  572. {
  573. TCopyParamType * CopyParam;
  574. CopyParam = new TCopyParamType(FDefaultCopyParam);
  575. CopyParam->TransferMode = tmAscii;
  576. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_ASCII), CopyParam, NULL);
  577. CopyParam = new TCopyParamType(FDefaultCopyParam);
  578. CopyParam->TransferMode = tmBinary;
  579. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_BINARY), CopyParam, NULL);
  580. CopyParam = new TCopyParamType(FDefaultCopyParam);
  581. CopyParam->ExcludeFileMask.Masks = "*.bak; *.tmp; ~$*; *.wbk; *~; #*; .#*";
  582. CopyParam->NegativeExclude = false; // just for sure
  583. FCopyParamList->Add(LoadStr(COPY_PARAM_PRESET_EXCLUDE), CopyParam, NULL);
  584. }
  585. FCopyParamList->Reset();
  586. }
  587. }
  588. //---------------------------------------------------------------------------
  589. AnsiString __fastcall TGUIConfiguration::PropertyToKey(const AnsiString Property)
  590. {
  591. // no longer useful
  592. int P = Property.LastDelimiter(".>");
  593. return Property.SubString(P + 1, Property.Length() - P);
  594. }
  595. //---------------------------------------------------------------------------
  596. // duplicated from core\configuration.cpp
  597. #define BLOCK(KEY, CANCREATE, BLOCK) \
  598. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  599. #define REGCONFIG(CANCREATE) \
  600. BLOCK("Interface", CANCREATE, \
  601. KEY(Bool, CopyParamDialogExpanded); \
  602. KEY(Bool, ErrorDialogExpanded); \
  603. KEY(Bool, ContinueOnError); \
  604. KEY(Bool, ConfirmCommandSession); \
  605. KEY(Integer, SynchronizeParams); \
  606. KEY(Integer, SynchronizeOptions); \
  607. KEY(Integer, SynchronizeModeAuto); \
  608. KEY(Integer, SynchronizeMode); \
  609. KEY(Integer, MaxWatchDirectories); \
  610. KEY(Integer, QueueTransfersLimit); \
  611. KEY(Bool, QueueAutoPopup); \
  612. KEY(Bool, QueueRememberPassword); \
  613. KEY(String, PuttySession); \
  614. KEY(String, PuttyPath); \
  615. KEY(Bool, PuttyPassword); \
  616. KEY(Bool, TelnetForFtpInPutty); \
  617. KEY(DateTime, IgnoreCancelBeforeFinish); \
  618. KEY(Bool, BeepOnFinish); \
  619. KEY(DateTime, BeepOnFinishAfter); \
  620. KEY(Bool, SynchronizeBrowsing); \
  621. KEY(Integer, KeepUpToDateChangeDelay); \
  622. KEY(String, ChecksumAlg); \
  623. ); \
  624. //---------------------------------------------------------------------------
  625. void __fastcall TGUIConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  626. {
  627. TConfiguration::SaveData(Storage, All);
  628. // duplicated from core\configuration.cpp
  629. #define KEY(TYPE, VAR) Storage->Write ## TYPE(PropertyToKey(#VAR), VAR)
  630. REGCONFIG(true);
  631. #undef KEY
  632. if (Storage->OpenSubKey("Interface\\CopyParam", true, true))
  633. try
  634. {
  635. FDefaultCopyParam.Save(Storage);
  636. if (FCopyParamListDefaults)
  637. {
  638. assert(!FCopyParamList->Modified);
  639. Storage->WriteInteger("CopyParamList", -1);
  640. }
  641. else if (All || FCopyParamList->Modified)
  642. {
  643. Storage->WriteInteger("CopyParamList", FCopyParamList->Count);
  644. FCopyParamList->Save(Storage);
  645. }
  646. }
  647. __finally
  648. {
  649. Storage->CloseSubKey();
  650. }
  651. if (Storage->OpenSubKey("Interface\\NewDirectory", true, true))
  652. try
  653. {
  654. FNewDirectoryProperties.Save(Storage);
  655. }
  656. __finally
  657. {
  658. Storage->CloseSubKey();
  659. }
  660. }
  661. //---------------------------------------------------------------------------
  662. void __fastcall TGUIConfiguration::LoadData(THierarchicalStorage * Storage)
  663. {
  664. TConfiguration::LoadData(Storage);
  665. // duplicated from core\configuration.cpp
  666. #define KEY(TYPE, VAR) VAR = Storage->Read ## TYPE(PropertyToKey(#VAR), VAR)
  667. #pragma warn -eas
  668. REGCONFIG(false);
  669. #pragma warn +eas
  670. #undef KEY
  671. if (Storage->OpenSubKey("Interface\\CopyParam", false, true))
  672. try
  673. {
  674. // must be loaded before eventual setting defaults for CopyParamList
  675. FDefaultCopyParam.Load(Storage);
  676. int CopyParamListCount = Storage->ReadInteger("CopyParamList", -1);
  677. FCopyParamListDefaults = (CopyParamListCount < 0);
  678. if (!FCopyParamListDefaults)
  679. {
  680. FCopyParamList->Clear();
  681. FCopyParamList->Load(Storage, CopyParamListCount);
  682. }
  683. else if (FCopyParamList->Modified)
  684. {
  685. FCopyParamList->Clear();
  686. FCopyParamListDefaults = false;
  687. }
  688. FCopyParamList->Reset();
  689. }
  690. __finally
  691. {
  692. Storage->CloseSubKey();
  693. }
  694. // Make it compatible with versions prior to 3.7.1 that have not saved PuttyPath
  695. // with quotes. First check for absence of quotes.
  696. // Add quotes either if the path is set to default putty path (even if it does
  697. // not exists) or when the path points to existing file (so there are no parameters
  698. // yet in the string). Note that FileExists may display error dialog, but as
  699. // it should be called only for custom users path, let's expect that the user
  700. // can take care of it.
  701. if ((FPuttyPath.SubString(1, 1) != "\"") &&
  702. (CompareFileName(ExpandEnvironmentVariables(FPuttyPath), FDefaultPuttyPathOnly) ||
  703. FileExists(ExpandEnvironmentVariables(FPuttyPath))))
  704. {
  705. FPuttyPath = FormatCommand(FPuttyPath, "");
  706. }
  707. if (Storage->OpenSubKey("Interface\\NewDirectory", false, true))
  708. try
  709. {
  710. FNewDirectoryProperties.Load(Storage);
  711. }
  712. __finally
  713. {
  714. Storage->CloseSubKey();
  715. }
  716. }
  717. //---------------------------------------------------------------------------
  718. void __fastcall TGUIConfiguration::Saved()
  719. {
  720. TConfiguration::Saved();
  721. FCopyParamList->Reset();
  722. }
  723. //---------------------------------------------------------------------------
  724. //---------------------------------------------------------------------------
  725. HANDLE __fastcall TGUIConfiguration::LoadNewResourceModule(LCID ALocale,
  726. AnsiString * FileName)
  727. {
  728. AnsiString LibraryFileName;
  729. HANDLE NewInstance = 0;
  730. bool Internal = (ALocale == InternalLocale());
  731. if (!Internal)
  732. {
  733. AnsiString Module;
  734. AnsiString LocaleName;
  735. Module = ModuleFileName();
  736. if ((ALocale & AdditionaLanguageMask) != AdditionaLanguageMask)
  737. {
  738. char LocaleStr[4];
  739. GetLocaleInfo(ALocale, LOCALE_SABBREVLANGNAME, LocaleStr, sizeof(LocaleStr));
  740. LocaleName = LocaleStr;
  741. assert(!LocaleName.IsEmpty());
  742. }
  743. else
  744. {
  745. LocaleName = AdditionaLanguagePrefix +
  746. char(ALocale & ~AdditionaLanguageMask);
  747. }
  748. Module = ChangeFileExt(Module, AnsiString(".") + LocaleName);
  749. // Look for a potential language/country translation
  750. NewInstance = LoadLibraryEx(Module.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  751. if (!NewInstance)
  752. {
  753. // Finally look for a language only translation
  754. Module.SetLength(Module.Length() - 1);
  755. NewInstance = LoadLibraryEx(Module.c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
  756. if (NewInstance)
  757. {
  758. LibraryFileName = Module;
  759. }
  760. }
  761. else
  762. {
  763. LibraryFileName = Module;
  764. }
  765. }
  766. if (!NewInstance && !Internal)
  767. {
  768. throw Exception(FMTLOAD(LOCALE_LOAD_ERROR, (int(ALocale))));
  769. }
  770. else
  771. {
  772. if (Internal)
  773. {
  774. NewInstance = HInstance;
  775. }
  776. }
  777. if (FileName != NULL)
  778. {
  779. *FileName = LibraryFileName;
  780. }
  781. return NewInstance;
  782. }
  783. //---------------------------------------------------------------------------
  784. LCID __fastcall TGUIConfiguration::InternalLocale()
  785. {
  786. LCID Result;
  787. if (GetTranslationCount(ApplicationInfo) > 0)
  788. {
  789. TTranslation Translation;
  790. Translation = GetTranslation(ApplicationInfo, 0);
  791. Result = MAKELANGID(PRIMARYLANGID(Translation.Language), SUBLANG_DEFAULT);
  792. }
  793. else
  794. {
  795. assert(false);
  796. Result = 0;
  797. }
  798. return Result;
  799. }
  800. //---------------------------------------------------------------------------
  801. LCID __fastcall TGUIConfiguration::GetLocale()
  802. {
  803. if (!FLocale)
  804. {
  805. FLocale = InternalLocale();
  806. }
  807. return FLocale;
  808. }
  809. //---------------------------------------------------------------------------
  810. void __fastcall TGUIConfiguration::SetLocale(LCID value)
  811. {
  812. if (Locale != value)
  813. {
  814. HANDLE Module = LoadNewResourceModule(value);
  815. if (Module != NULL)
  816. {
  817. FLocale = value;
  818. SetResourceModule(Module);
  819. }
  820. else
  821. {
  822. assert(false);
  823. }
  824. }
  825. }
  826. //---------------------------------------------------------------------------
  827. void __fastcall TGUIConfiguration::SetLocaleSafe(LCID value)
  828. {
  829. if (Locale != value)
  830. {
  831. HANDLE Module;
  832. try
  833. {
  834. Module = LoadNewResourceModule(value);
  835. }
  836. catch(...)
  837. {
  838. // ignore any exception while loading locale
  839. Module = NULL;
  840. }
  841. if (Module != NULL)
  842. {
  843. FLocale = value;
  844. SetResourceModule(Module);
  845. }
  846. }
  847. }
  848. //---------------------------------------------------------------------------
  849. void __fastcall TGUIConfiguration::FreeResourceModule(HANDLE Instance)
  850. {
  851. TPasLibModule * MainModule = FindModule(HInstance);
  852. if (Instance != MainModule->Instance)
  853. {
  854. FreeLibrary(static_cast<HMODULE>(Instance));
  855. }
  856. }
  857. //---------------------------------------------------------------------------
  858. HANDLE __fastcall TGUIConfiguration::ChangeResourceModule(HANDLE Instance)
  859. {
  860. if (Instance == NULL)
  861. {
  862. Instance = HInstance;
  863. }
  864. TPasLibModule * MainModule = FindModule(HInstance);
  865. HANDLE Result = MainModule->ResInstance;
  866. MainModule->ResInstance = Instance;
  867. CoreSetResourceModule(Instance);
  868. return Result;
  869. }
  870. //---------------------------------------------------------------------------
  871. HANDLE __fastcall TGUIConfiguration::GetResourceModule()
  872. {
  873. return FindModule(HInstance)->ResInstance;
  874. }
  875. //---------------------------------------------------------------------------
  876. void __fastcall TGUIConfiguration::SetResourceModule(HANDLE Instance)
  877. {
  878. HANDLE PrevHandle = ChangeResourceModule(Instance);
  879. FreeResourceModule(PrevHandle);
  880. DefaultLocalized();
  881. }
  882. //---------------------------------------------------------------------------
  883. TStrings * __fastcall TGUIConfiguration::GetLocales()
  884. {
  885. AnsiString LocalesExts;
  886. TStringList * Exts = new TStringList();
  887. try
  888. {
  889. Exts->Sorted = true;
  890. Exts->CaseSensitive = false;
  891. int FindAttrs = faReadOnly | faArchive;
  892. TSearchRec SearchRec;
  893. bool Found;
  894. Found = (bool)(FindFirst(ChangeFileExt(ModuleFileName(), ".*"),
  895. FindAttrs, SearchRec) == 0);
  896. try
  897. {
  898. AnsiString Ext;
  899. while (Found)
  900. {
  901. Ext = ExtractFileExt(SearchRec.Name).UpperCase();
  902. if ((Ext.Length() >= 3) && (Ext != ".EXE") && (Ext != ".COM") &&
  903. (Ext != ".DLL") && (Ext != ".INI"))
  904. {
  905. Ext = Ext.SubString(2, Ext.Length() - 1);
  906. LocalesExts += Ext;
  907. Exts->Add(Ext);
  908. }
  909. Found = (FindNext(SearchRec) == 0);
  910. }
  911. }
  912. __finally
  913. {
  914. FindClose(SearchRec);
  915. }
  916. if (FLastLocalesExts != LocalesExts)
  917. {
  918. FLastLocalesExts = LocalesExts;
  919. FLocales->Clear();
  920. TLanguages * Langs = LanguagesDEPF();
  921. int Ext, Index, Count;
  922. char LocaleStr[255];
  923. LCID Locale;
  924. Count = Langs->Count;
  925. Index = -1;
  926. while (Index < Count)
  927. {
  928. if (Index >= 0)
  929. {
  930. Locale = Langs->LocaleID[Index];
  931. Ext = Exts->IndexOf(Langs->Ext[Index]);
  932. if (Ext < 0)
  933. {
  934. Ext = Exts->IndexOf(Langs->Ext[Index].SubString(1, 2));
  935. if (Ext >= 0)
  936. {
  937. Locale = MAKELANGID(PRIMARYLANGID(Locale), SUBLANG_DEFAULT);
  938. }
  939. }
  940. if (Ext >= 0)
  941. {
  942. Exts->Objects[Ext] = reinterpret_cast<TObject*>(Locale);
  943. }
  944. else
  945. {
  946. Locale = 0;
  947. }
  948. }
  949. else
  950. {
  951. Locale = InternalLocale();
  952. }
  953. if (Locale)
  954. {
  955. AnsiString Name;
  956. GetLocaleInfo(Locale, LOCALE_SENGLANGUAGE,
  957. LocaleStr, sizeof(LocaleStr));
  958. Name = LocaleStr;
  959. Name += " - ";
  960. // LOCALE_SNATIVELANGNAME
  961. GetLocaleInfo(Locale, LOCALE_SLANGUAGE,
  962. LocaleStr, sizeof(LocaleStr));
  963. Name += LocaleStr;
  964. FLocales->AddObject(Name, reinterpret_cast<TObject*>(Locale));
  965. }
  966. Index++;
  967. }
  968. for (int Index = 0; Index < Exts->Count; Index++)
  969. {
  970. if ((Exts->Objects[Index] == NULL) &&
  971. (Exts->Strings[Index].Length() == 3) &&
  972. SameText(Exts->Strings[Index].SubString(1, 2), AdditionaLanguagePrefix))
  973. {
  974. AnsiString LangName = GetFileFileInfoString("LangName",
  975. ChangeFileExt(ModuleFileName(), AnsiString(".") + Exts->Strings[Index]));
  976. if (!LangName.IsEmpty())
  977. {
  978. FLocales->AddObject(LangName, reinterpret_cast<TObject*>(
  979. AdditionaLanguageMask + Exts->Strings[Index][3]));
  980. }
  981. }
  982. }
  983. }
  984. }
  985. __finally
  986. {
  987. delete Exts;
  988. }
  989. return FLocales;
  990. }
  991. //---------------------------------------------------------------------------
  992. void __fastcall TGUIConfiguration::SetDefaultCopyParam(const TGUICopyParamType & value)
  993. {
  994. FDefaultCopyParam.Assign(&value);
  995. Changed();
  996. }
  997. //---------------------------------------------------------------------------
  998. bool __fastcall TGUIConfiguration::GetRememberPassword()
  999. {
  1000. return QueueRememberPassword || PuttyPassword;
  1001. }
  1002. //---------------------------------------------------------------------------
  1003. const TCopyParamList * __fastcall TGUIConfiguration::GetCopyParamList()
  1004. {
  1005. return FCopyParamList;
  1006. }
  1007. //---------------------------------------------------------------------------
  1008. void __fastcall TGUIConfiguration::SetCopyParamList(const TCopyParamList * value)
  1009. {
  1010. if (!(*FCopyParamList == *value))
  1011. {
  1012. *FCopyParamList = *value;
  1013. FCopyParamListDefaults = false;
  1014. Changed();
  1015. }
  1016. }
  1017. //---------------------------------------------------------------------------
  1018. int __fastcall TGUIConfiguration::GetCopyParamIndex()
  1019. {
  1020. int Result;
  1021. if (FCopyParamCurrent.IsEmpty())
  1022. {
  1023. Result = -1;
  1024. }
  1025. else
  1026. {
  1027. Result = FCopyParamList->IndexOfName(FCopyParamCurrent);
  1028. }
  1029. return Result;
  1030. }
  1031. //---------------------------------------------------------------------------
  1032. void __fastcall TGUIConfiguration::SetCopyParamIndex(int value)
  1033. {
  1034. AnsiString Name;
  1035. if (value < 0)
  1036. {
  1037. Name = "";
  1038. }
  1039. else
  1040. {
  1041. Name = FCopyParamList->Names[value];
  1042. }
  1043. CopyParamCurrent = Name;
  1044. }
  1045. //---------------------------------------------------------------------------
  1046. void __fastcall TGUIConfiguration::SetCopyParamCurrent(AnsiString value)
  1047. {
  1048. SET_CONFIG_PROPERTY(CopyParamCurrent);
  1049. }
  1050. //---------------------------------------------------------------------------
  1051. TGUICopyParamType __fastcall TGUIConfiguration::GetCurrentCopyParam()
  1052. {
  1053. return CopyParamPreset[CopyParamCurrent];
  1054. }
  1055. //---------------------------------------------------------------------------
  1056. TGUICopyParamType __fastcall TGUIConfiguration::GetCopyParamPreset(AnsiString Name)
  1057. {
  1058. TGUICopyParamType Result = FDefaultCopyParam;
  1059. if (!Name.IsEmpty())
  1060. {
  1061. int Index = FCopyParamList->IndexOfName(Name);
  1062. assert(Index >= 0);
  1063. if (Index >= 0)
  1064. {
  1065. const TCopyParamType * Preset = FCopyParamList->CopyParams[Index];
  1066. assert(Preset != NULL);
  1067. Result.Assign(Preset); // overwrite all but GUI options
  1068. // reset all options known not to be configurable per-preset
  1069. // kind of hack
  1070. Result.ResumeSupport = FDefaultCopyParam.ResumeSupport;
  1071. Result.ResumeThreshold = FDefaultCopyParam.ResumeThreshold;
  1072. Result.LocalInvalidChars = FDefaultCopyParam.LocalInvalidChars;
  1073. }
  1074. }
  1075. return Result;
  1076. }
  1077. //---------------------------------------------------------------------------
  1078. void __fastcall TGUIConfiguration::SetNewDirectoryProperties(
  1079. const TRemoteProperties & value)
  1080. {
  1081. SET_CONFIG_PROPERTY(NewDirectoryProperties);
  1082. }
  1083. //---------------------------------------------------------------------------