WinConfiguration.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "WinConfiguration.h"
  5. #include "Common.h"
  6. #include "Bookmarks.h"
  7. #include "Terminal.h"
  8. #include "TextsWin.h"
  9. #include "WinInterface.h"
  10. #include "GUITools.h"
  11. #include <stdio.h>
  12. #include <ResourceModule.hpp>
  13. #include <InitGUID.h>
  14. #include <DragExt.h>
  15. //---------------------------------------------------------------------------
  16. #pragma package(smart_init)
  17. //---------------------------------------------------------------------------
  18. const char ShellCommandFileNamePattern[] = "!.!";
  19. //---------------------------------------------------------------------------
  20. __fastcall TWinConfiguration::TWinConfiguration(): TCustomWinConfiguration()
  21. {
  22. FDDExtInstalled = -1;
  23. FBookmarks = new TBookmarks();
  24. FCustomCommands = new TCustomCommands();
  25. Default();
  26. try
  27. {
  28. CheckTranslationVersion(GetResourceModule(ModuleFileName().c_str()));
  29. }
  30. catch(...)
  31. {
  32. LocaleSafe = InternalLocale();
  33. }
  34. }
  35. //---------------------------------------------------------------------------
  36. __fastcall TWinConfiguration::~TWinConfiguration()
  37. {
  38. if (!FTemporarySessionFile.IsEmpty()) DeleteFile(FTemporarySessionFile);
  39. ClearTemporaryLoginData();
  40. delete FBookmarks;
  41. delete FCustomCommands;
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TWinConfiguration::Default()
  45. {
  46. TCustomWinConfiguration::Default();
  47. FDDAllowMove = false;
  48. FDDTransferConfirmation = true;
  49. FDDTemporaryDirectory = "";
  50. FDDWarnLackOfTempSpace = true;
  51. FDDWarnLackOfTempSpaceRatio = 1.1;
  52. FDDExtEnabled = true;
  53. FDDExtTimeout = 1000;
  54. FDDExtCopySlipTimeout = 100;
  55. FDeleteToRecycleBin = true;
  56. FSelectDirectories = false;
  57. FSelectMask = "*.*";
  58. FShowHiddenFiles = true;
  59. FShowInaccesibleDirectories = true;
  60. FConfirmDeleting = true;
  61. FConfirmClosingSession = true;
  62. FConfirmExitOnCompletion = true;
  63. FForceDeleteTempFolder = true;
  64. FCopyOnDoubleClick = false;
  65. FCopyOnDoubleClickConfirmation = false;
  66. FDimmHiddenFiles = true;
  67. FAutoStartSession = "";
  68. FExpertMode = true;
  69. FUseLocationProfiles = false;
  70. FEditor.Editor = edInternal;
  71. FEditor.ExternalEditor = "notepad.exe";
  72. FEditor.FontName = "Courier New";
  73. FEditor.FontHeight = -12;
  74. FEditor.FontStyle = 0;
  75. FEditor.FontCharset = DEFAULT_CHARSET;
  76. FEditor.WordWrap = false;
  77. FEditor.FindText = "";
  78. FEditor.ReplaceText = "";
  79. FEditor.FindMatchCase = false;
  80. FEditor.FindWholeWord = false;
  81. FLogWindowOnStartup = true;
  82. FLogWindowParams = "-1;-1;500;400";
  83. FScpExplorer.WindowParams = "-1;-1;600;400;0";
  84. FScpExplorer.DirViewParams = "0;1;0|150,1;70,1;101,1;79,1;62,1;55,1|0;1;2;3;4;5";
  85. FScpExplorer.CoolBarLayout = "5,0,0,94,6;1,1,0,638,5;4,0,0,239,4;3,1,0,424,3;6,1,0,206,2;2,1,1,634,1;0,1,1,634,0";
  86. FScpExplorer.StatusBar = true;
  87. AnsiString PersonalFolder;
  88. SpecialFolderLocation(CSIDL_PERSONAL, PersonalFolder);
  89. FScpExplorer.LastLocalTargetDirectory = PersonalFolder;
  90. FScpExplorer.ViewStyle = 0; /* vsIcon */
  91. FScpExplorer.ShowFullAddress = true;
  92. FScpCommander.WindowParams = "-1;-1;600;400;0";
  93. FScpCommander.LocalPanelWidth = 0.5;
  94. FScpCommander.StatusBar = true;
  95. FScpCommander.ToolBar = true;
  96. FScpCommander.CommandLine = false;
  97. FScpCommander.ExplorerStyleSelection = false;
  98. FScpCommander.PreserveLocalDirectory = false;
  99. FScpCommander.CoolBarLayout = "5,0,0,219,6;1,1,0,319,5;4,0,0,227,4;3,1,0,136,3;6,1,0,121,2;2,1,1,67,1;0,1,1,649,0";
  100. FScpCommander.CurrentPanel = osLocal;
  101. FScpCommander.CompareByTime = true;
  102. FScpCommander.CompareBySize = false;
  103. FScpCommander.SynchronizeBrowsing = false;
  104. FScpCommander.RemotePanel.DirViewParams = "0;1;0|150,1;70,1;101,1;79,1;62,1;55,0|0;1;2;3;4;5";
  105. FScpCommander.RemotePanel.StatusBar = true;
  106. FScpCommander.RemotePanel.CoolBarLayout = "2,1,0,137,2;1,1,0,86,1;0,1,1,91,0";
  107. FScpCommander.LocalPanel.DirViewParams = "0;1;0|150,1;70,1;101,1;79,1;62,1;55,0|0;1;2;3;4;5";
  108. FScpCommander.LocalPanel.StatusBar = true;
  109. FScpCommander.LocalPanel.CoolBarLayout = "2,1,0,137,2;1,1,0,86,1;0,1,1,91,0";
  110. FBookmarks->Clear();
  111. FCustomCommands->Clear();
  112. FCustomCommands->Values[LoadStr(CUSTOM_COMMAND_EXECUTE)] = "\"!\"";
  113. FCustomCommands->Params[LoadStr(CUSTOM_COMMAND_EXECUTE)] = 0;
  114. FCustomCommands->Values[LoadStr(CUSTOM_COMMAND_TOUCH)] = "touch \"!\"";
  115. FCustomCommands->Params[LoadStr(CUSTOM_COMMAND_TOUCH)] = ccApplyToDirectories | ccRecursive;
  116. FCustomCommands->Values[LoadStr(CUSTOM_COMMAND_MOVE)] =
  117. FORMAT("mv \"!\" \"!?%s?!\"", (LoadStr(CUSTOM_COMMAND_MOVE_PARAM)));
  118. FCustomCommands->Params[LoadStr(CUSTOM_COMMAND_MOVE)] = ccApplyToDirectories;
  119. FCustomCommandsModified = false;
  120. }
  121. //---------------------------------------------------------------------------
  122. TStorage __fastcall TWinConfiguration::GetStorage()
  123. {
  124. if (FStorage == stDetect)
  125. {
  126. if (FindResourceEx(NULL, RT_RCDATA, "WINSCP_SESSION",
  127. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
  128. {
  129. FTemporarySessionFile = GetTemporaryPath() + "winscp3s.tmp";
  130. DumpResourceToFile("WINSCP_SESSION", FTemporarySessionFile);
  131. FEmbeddedSessions = true;
  132. FTemporaryKeyFile = GetTemporaryPath() + "winscp3k.tmp";
  133. if (!DumpResourceToFile("WINSCP_KEY", FTemporaryKeyFile))
  134. {
  135. FTemporaryKeyFile = "";
  136. }
  137. }
  138. }
  139. return TCustomWinConfiguration::GetStorage();
  140. }
  141. //---------------------------------------------------------------------------
  142. void __fastcall TWinConfiguration::ModifyAll()
  143. {
  144. TCustomWinConfiguration::ModifyAll();
  145. FBookmarks->ModifyAll(true);
  146. FCustomCommandsModified = true;
  147. }
  148. //---------------------------------------------------------------------------
  149. THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool SessionList)
  150. {
  151. if (SessionList && !FTemporarySessionFile.IsEmpty())
  152. {
  153. return new TIniFileStorage(FTemporarySessionFile);
  154. }
  155. else
  156. {
  157. return TCustomWinConfiguration::CreateScpStorage(SessionList);
  158. }
  159. }
  160. //---------------------------------------------------------------------------
  161. // duplicated from core\configuration.cpp
  162. #define LASTELEM(ELEM) \
  163. ELEM.SubString(ELEM.LastDelimiter(".>")+1, ELEM.Length() - ELEM.LastDelimiter(".>"))
  164. #define BLOCK(KEY, CANCREATE, BLOCK) \
  165. if (Storage->OpenSubKey(KEY, CANCREATE)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  166. #define REGCONFIG(CANCREATE) \
  167. BLOCK("Interface", CANCREATE, \
  168. KEY(Bool, CopyOnDoubleClick); \
  169. KEY(Bool, CopyOnDoubleClickConfirmation); \
  170. KEY(Bool, DDAllowMove); \
  171. KEY(Bool, DDTransferConfirmation); \
  172. KEY(String, DDTemporaryDirectory); \
  173. KEY(Bool, DDWarnLackOfTempSpace); \
  174. KEY(Float, DDWarnLackOfTempSpaceRatio); \
  175. KEY(Bool, DeleteToRecycleBin); \
  176. KEY(Bool, DimmHiddenFiles); \
  177. KEY(Bool, SelectDirectories); \
  178. KEY(String, SelectMask); \
  179. KEY(Bool, ShowHiddenFiles); \
  180. KEY(Bool, ShowInaccesibleDirectories); \
  181. KEY(Bool, ConfirmDeleting); \
  182. KEY(Bool, ConfirmClosingSession); \
  183. KEY(Bool, ConfirmExitOnCompletion); \
  184. KEY(String, AutoStartSession); \
  185. KEY(Bool, UseLocationProfiles); \
  186. KEY(Bool, ForceDeleteTempFolder); \
  187. KEY(Integer, LocaleSafe); \
  188. KEY(Bool, DDExtEnabled); \
  189. KEY(Integer, DDExtTimeout); \
  190. KEY(Integer, DDExtCopySlipTimeout); \
  191. ); \
  192. BLOCK("Interface\\Editor", CANCREATE, \
  193. KEY(Integer, Editor.Editor); \
  194. KEY(String, Editor.ExternalEditor); \
  195. KEY(String, Editor.FontName); \
  196. KEY(Integer, Editor.FontHeight); \
  197. KEY(Integer, Editor.FontStyle); \
  198. KEY(Integer, Editor.FontCharset); \
  199. KEY(Bool, Editor.WordWrap); \
  200. KEY(String, Editor.FindText); \
  201. KEY(String, Editor.ReplaceText); \
  202. KEY(Bool, Editor.FindMatchCase); \
  203. KEY(Bool, Editor.FindWholeWord); \
  204. ); \
  205. BLOCK("Interface\\Explorer", CANCREATE, \
  206. KEY(String, ScpExplorer.CoolBarLayout); \
  207. KEY(String, ScpExplorer.DirViewParams); \
  208. KEY(String, ScpExplorer.LastLocalTargetDirectory); \
  209. KEY(Bool, ScpExplorer.StatusBar); \
  210. KEY(String, ScpExplorer.WindowParams); \
  211. KEY(Integer, ScpExplorer.ViewStyle); \
  212. KEY(Bool, ScpExplorer.ShowFullAddress); \
  213. ); \
  214. BLOCK("Interface\\Commander", CANCREATE, \
  215. KEY(String, ScpCommander.CoolBarLayout); \
  216. KEY(Integer, ScpCommander.CurrentPanel); \
  217. KEY(Float, ScpCommander.LocalPanelWidth); \
  218. KEY(Bool, ScpCommander.StatusBar); \
  219. KEY(Bool, ScpCommander.CommandLine); \
  220. KEY(Bool, ScpCommander.ToolBar); \
  221. KEY(String, ScpCommander.WindowParams); \
  222. KEY(Bool, ScpCommander.ExplorerStyleSelection); \
  223. KEY(Bool, ScpCommander.PreserveLocalDirectory); \
  224. KEY(Bool, ScpCommander.CompareByTime); \
  225. KEY(Bool, ScpCommander.CompareBySize); \
  226. KEY(Bool, ScpCommander.SynchronizeBrowsing); \
  227. ); \
  228. BLOCK("Interface\\Commander\\LocalPanel", CANCREATE, \
  229. KEY(String, ScpCommander.LocalPanel.CoolBarLayout); \
  230. KEY(String, ScpCommander.LocalPanel.DirViewParams); \
  231. KEY(Bool, ScpCommander.LocalPanel.StatusBar); \
  232. ); \
  233. BLOCK("Interface\\Commander\\RemotePanel", CANCREATE, \
  234. KEY(String, ScpCommander.RemotePanel.CoolBarLayout); \
  235. KEY(String, ScpCommander.RemotePanel.DirViewParams); \
  236. KEY(Bool, ScpCommander.RemotePanel.StatusBar); \
  237. ); \
  238. BLOCK("Logging", CANCREATE, \
  239. KEY(Bool, LogWindowOnStartup); \
  240. KEY(String, LogWindowParams); \
  241. );
  242. //---------------------------------------------------------------------------
  243. void __fastcall TWinConfiguration::SaveSpecial(THierarchicalStorage * Storage)
  244. {
  245. TCustomWinConfiguration::SaveSpecial(Storage);
  246. // duplicated from core\configuration.cpp
  247. #define KEY(TYPE, VAR) Storage->Write ## TYPE(LASTELEM(AnsiString(#VAR)), VAR)
  248. REGCONFIG(true);
  249. #undef KEY
  250. if (Storage->OpenSubKey("Bookmarks", true))
  251. {
  252. FBookmarks->Save(Storage);
  253. Storage->CloseSubKey();
  254. }
  255. if (FCustomCommandsModified)
  256. {
  257. if (Storage->OpenSubKey("CustomCommands", true))
  258. {
  259. Storage->WriteValues(FCustomCommands, true);
  260. Storage->CloseSubKey();
  261. }
  262. if (Storage->OpenSubKey("CustomCommandsParams", true))
  263. {
  264. Storage->ClearValues();
  265. for (int Index = 0; Index < FCustomCommands->Count; Index++)
  266. {
  267. Storage->WriteInteger(FCustomCommands->Names[Index],
  268. FCustomCommands->Params[FCustomCommands->Names[Index]]);
  269. }
  270. Storage->CloseSubKey();
  271. }
  272. FCustomCommandsModified = false;
  273. }
  274. }
  275. //---------------------------------------------------------------------------
  276. void __fastcall TWinConfiguration::LoadSpecial(THierarchicalStorage * Storage)
  277. {
  278. TCustomWinConfiguration::LoadSpecial(Storage);
  279. // duplicated from core\configuration.cpp
  280. #define KEY(TYPE, VAR) VAR = Storage->Read ## TYPE(LASTELEM(AnsiString(#VAR)), VAR)
  281. #pragma warn -eas
  282. REGCONFIG(false);
  283. #pragma warn +eas
  284. #undef KEY
  285. if (Storage->OpenSubKey("Bookmarks", false))
  286. {
  287. FBookmarks->Load(Storage);
  288. Storage->CloseSubKey();
  289. }
  290. if (Storage->OpenSubKey("CustomCommands", false))
  291. {
  292. FCustomCommands->Clear();
  293. Storage->ReadValues(FCustomCommands, true);
  294. Storage->CloseSubKey();
  295. if (Storage->OpenSubKey("CustomCommandsParams", false))
  296. {
  297. for (int Index = 0; Index < FCustomCommands->Count; Index++)
  298. {
  299. AnsiString Name = FCustomCommands->Names[Index];
  300. FCustomCommands->Params[Name] =
  301. Storage->ReadInteger(Name, FCustomCommands->Params[Name]);
  302. }
  303. Storage->CloseSubKey();
  304. }
  305. }
  306. else if (FCustomCommandsModified)
  307. {
  308. FCustomCommands->Clear();
  309. }
  310. FCustomCommandsModified = false;
  311. }
  312. //---------------------------------------------------------------------------
  313. void __fastcall TWinConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  314. {
  315. TConfiguration::LoadAdmin(Storage);
  316. FDisableOpenEdit = Storage->ReadBool("DisableOpenEdit", FDisableOpenEdit);
  317. }
  318. //---------------------------------------------------------------------------
  319. void __fastcall TWinConfiguration::ClearTemporaryLoginData()
  320. {
  321. if (!FTemporaryKeyFile.IsEmpty())
  322. {
  323. DeleteFile(FTemporaryKeyFile);
  324. FTemporaryKeyFile = "";
  325. }
  326. }
  327. //---------------------------------------------------------------------------
  328. bool __fastcall TWinConfiguration::DumpResourceToFile(
  329. const AnsiString ResName, const AnsiString FileName)
  330. {
  331. HRSRC Resource;
  332. Resource = FindResourceEx(NULL, RT_RCDATA, ResName.c_str(),
  333. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
  334. if (Resource)
  335. {
  336. unsigned long Size = SizeofResource(NULL, Resource);
  337. if (!Size)
  338. {
  339. throw Exception(FORMAT("Cannot get size of resource %s", (ResName)));
  340. }
  341. void * Content = LoadResource(NULL, Resource);
  342. if (!Content)
  343. {
  344. throw Exception(FORMAT("Cannot read resource %s", (ResName)));
  345. }
  346. Content = LockResource(Content);
  347. if (!Content)
  348. {
  349. throw Exception(FORMAT("Cannot lock resource %s", (ResName)));
  350. }
  351. FILE * f = fopen(FileName.c_str(), "wb");
  352. if (!f)
  353. {
  354. throw Exception(FORMAT("Cannot create file %s", (FileName)));
  355. }
  356. if (fwrite(Content, 1, Size, f) != Size)
  357. {
  358. throw Exception(FORMAT("Cannot write to file %s", (FileName)));
  359. }
  360. fclose(f);
  361. }
  362. return (Resource != NULL);
  363. }
  364. //---------------------------------------------------------------------------
  365. void __fastcall TWinConfiguration::RestoreForm(AnsiString Data, TCustomForm * Form)
  366. {
  367. assert(Form);
  368. if (!Data.IsEmpty())
  369. {
  370. TRect Bounds = Form->BoundsRect;
  371. Bounds.Left = StrToIntDef(::CutToChar(Data, ';', true), Bounds.Left);
  372. Bounds.Top = StrToIntDef(::CutToChar(Data, ';', true), Bounds.Top);
  373. Bounds.Right = StrToIntDef(::CutToChar(Data, ';', true), Bounds.Right);
  374. Bounds.Bottom = StrToIntDef(::CutToChar(Data, ';', true), Bounds.Bottom);
  375. TWindowState State = (TWindowState)StrToIntDef(::CutToChar(Data, ';', true), (int)wsNormal);
  376. ((TForm*)Form)->WindowState = State;
  377. if (State == wsNormal)
  378. {
  379. if (Bounds.Width() > Screen->Width) Bounds.Right -= (Bounds.Width() - Screen->Width);
  380. if (Bounds.Height() > Screen->Height) Bounds.Bottom -= (Bounds.Height() - Screen->Height);
  381. Form->BoundsRect = Bounds;
  382. #define POS_RANGE(x, prop) (x < 0) || (x > Screen->prop)
  383. if (POS_RANGE(Bounds.Left, Width - 20) || POS_RANGE(Bounds.Top, Height - 40))
  384. {
  385. ((TForm*)Form)->Position = poDefaultPosOnly;
  386. }
  387. else
  388. {
  389. ((TForm*)Form)->Position = poDesigned;
  390. }
  391. #undef POS_RANGE
  392. }
  393. }
  394. else if (((TForm*)Form)->Position == poDesigned)
  395. {
  396. ((TForm*)Form)->Position = poDefaultPosOnly;
  397. }
  398. }
  399. //---------------------------------------------------------------------------
  400. AnsiString __fastcall TWinConfiguration::StoreForm(TCustomForm * Form)
  401. {
  402. assert(Form);
  403. return FORMAT("%d;%d;%d;%d;%d", ((int)Form->BoundsRect.Left, (int)Form->BoundsRect.Top,
  404. (int)Form->BoundsRect.Right, (int)Form->BoundsRect.Bottom,
  405. (int)Form->WindowState));
  406. }
  407. //---------------------------------------------------------------------------
  408. bool __fastcall TWinConfiguration::GetDDExtInstalled()
  409. {
  410. if (FDDExtInstalled < 0)
  411. {
  412. void* DragExtRef;
  413. bool Result;
  414. Result = (CoCreateInstance(CLSID_ShellExtension, NULL,
  415. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
  416. &DragExtRef) == S_OK);
  417. FDDExtInstalled = (Result ? 1 : 0);
  418. }
  419. return (FDDExtInstalled > 0);
  420. }
  421. //---------------------------------------------------------------------------
  422. void __fastcall TWinConfiguration::SetLogWindowOnStartup(bool value)
  423. {
  424. SET_CONFIG_PROPERTY(LogWindowOnStartup);
  425. }
  426. //---------------------------------------------------------------------------
  427. void __fastcall TWinConfiguration::SetLogWindowParams(AnsiString value)
  428. {
  429. SET_CONFIG_PROPERTY(LogWindowParams);
  430. }
  431. //---------------------------------------------------------------------------
  432. void __fastcall TWinConfiguration::SetDDAllowMove(bool value)
  433. {
  434. SET_CONFIG_PROPERTY(DDAllowMove);
  435. }
  436. //---------------------------------------------------------------------------
  437. void __fastcall TWinConfiguration::SetDDTransferConfirmation(bool value)
  438. {
  439. SET_CONFIG_PROPERTY(DDTransferConfirmation);
  440. }
  441. //---------------------------------------------------------------------------
  442. void __fastcall TWinConfiguration::SetDDTemporaryDirectory(AnsiString value)
  443. {
  444. SET_CONFIG_PROPERTY(DDTemporaryDirectory);
  445. }
  446. //---------------------------------------------------------------------------
  447. void __fastcall TWinConfiguration::SetDDExtEnabled(bool value)
  448. {
  449. SET_CONFIG_PROPERTY(DDExtEnabled);
  450. }
  451. //---------------------------------------------------------------------------
  452. void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
  453. {
  454. SET_CONFIG_PROPERTY(DDExtTimeout);
  455. }
  456. //---------------------------------------------------------------------------
  457. void __fastcall TWinConfiguration::SetDDExtCopySlipTimeout(int value)
  458. {
  459. SET_CONFIG_PROPERTY(DDExtCopySlipTimeout);
  460. }
  461. //---------------------------------------------------------------------------
  462. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpace(bool value)
  463. {
  464. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpace);
  465. }
  466. //---------------------------------------------------------------------------
  467. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpaceRatio(double value)
  468. {
  469. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpaceRatio);
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TWinConfiguration::SetScpExplorer(TScpExplorerConfiguration value)
  473. {
  474. SET_CONFIG_PROPERTY(ScpExplorer);
  475. }
  476. //---------------------------------------------------------------------------
  477. void __fastcall TWinConfiguration::SetScpCommander(TScpCommanderConfiguration value)
  478. {
  479. SET_CONFIG_PROPERTY(ScpCommander);
  480. }
  481. //---------------------------------------------------------------------------
  482. void __fastcall TWinConfiguration::SetEditor(TEditorConfiguration value)
  483. {
  484. SET_CONFIG_PROPERTY(Editor);
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TWinConfiguration::SetDeleteToRecycleBin(bool value)
  488. {
  489. SET_CONFIG_PROPERTY(DeleteToRecycleBin);
  490. }
  491. //---------------------------------------------------------------------------
  492. void __fastcall TWinConfiguration::SetSelectDirectories(bool value)
  493. {
  494. SET_CONFIG_PROPERTY(SelectDirectories);
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TWinConfiguration::SetShowHiddenFiles(bool value)
  498. {
  499. SET_CONFIG_PROPERTY(ShowHiddenFiles);
  500. }
  501. //---------------------------------------------------------------------------
  502. void __fastcall TWinConfiguration::SetShowInaccesibleDirectories(bool value)
  503. {
  504. SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
  505. }
  506. //---------------------------------------------------------------------------
  507. void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
  508. {
  509. SET_CONFIG_PROPERTY(ConfirmDeleting);
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
  513. {
  514. SET_CONFIG_PROPERTY(UseLocationProfiles);
  515. }
  516. //---------------------------------------------------------------------------
  517. void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
  518. {
  519. SET_CONFIG_PROPERTY(ConfirmClosingSession);
  520. }
  521. //---------------------------------------------------------------------------
  522. void __fastcall TWinConfiguration::SetConfirmExitOnCompletion(bool value)
  523. {
  524. SET_CONFIG_PROPERTY(ConfirmExitOnCompletion);
  525. }
  526. //---------------------------------------------------------------------------
  527. void __fastcall TWinConfiguration::SetForceDeleteTempFolder(bool value)
  528. {
  529. SET_CONFIG_PROPERTY(ForceDeleteTempFolder);
  530. }
  531. //---------------------------------------------------------------------------
  532. void __fastcall TWinConfiguration::SetCopyOnDoubleClick(bool value)
  533. {
  534. SET_CONFIG_PROPERTY(CopyOnDoubleClick);
  535. }
  536. //---------------------------------------------------------------------------
  537. void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
  538. {
  539. SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
  540. }
  541. //---------------------------------------------------------------------------
  542. void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
  543. {
  544. SET_CONFIG_PROPERTY(DimmHiddenFiles);
  545. }
  546. //---------------------------------------------------------------------------
  547. void __fastcall TWinConfiguration::SetAutoStartSession(AnsiString value)
  548. {
  549. SET_CONFIG_PROPERTY(AutoStartSession);
  550. }
  551. //---------------------------------------------------------------------------
  552. void __fastcall TWinConfiguration::SetExpertMode(bool value)
  553. {
  554. SET_CONFIG_PROPERTY(ExpertMode);
  555. }
  556. //---------------------------------------------------------------------------
  557. void __fastcall TWinConfiguration::SetCustomCommands(TCustomCommands * value)
  558. {
  559. assert(FCustomCommands);
  560. if (!FCustomCommands->Equals(value))
  561. {
  562. FCustomCommands->Assign(value);
  563. FCustomCommandsModified = true;
  564. }
  565. }
  566. //---------------------------------------------------------------------------
  567. void __fastcall TWinConfiguration::SetBookmarks(AnsiString Key,
  568. TBookmarkList * value)
  569. {
  570. FBookmarks->Bookmarks[Key] = value;
  571. Changed();
  572. }
  573. //---------------------------------------------------------------------------
  574. TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(AnsiString Key)
  575. {
  576. return FBookmarks->Bookmarks[Key];
  577. }
  578. //---------------------------------------------------------------------------
  579. void TWinConfiguration::ReformatFileNameCommand(AnsiString & Command)
  580. {
  581. AnsiString Program, Params, Dir;
  582. SplitCommand(Command, Program, Params, Dir);
  583. if (Params.Pos(ShellCommandFileNamePattern) == 0)
  584. {
  585. Params = Params + (Params.IsEmpty() ? "" : " ") + ShellCommandFileNamePattern;
  586. }
  587. Command = FormatCommand(Program, Params);
  588. }
  589. //---------------------------------------------------------------------------
  590. AnsiString __fastcall TWinConfiguration::GetDefaultKeyFile()
  591. {
  592. return FTemporaryKeyFile;
  593. }
  594. //---------------------------------------------------------------------------
  595. //---------------------------------------------------------------------------
  596. class TAsInheritedReader : public TReader
  597. {
  598. public:
  599. __fastcall TAsInheritedReader(TStream * Stream, int BufSize) :
  600. TReader(Stream, BufSize)
  601. {
  602. OnAncestorNotFound = AncestorNotFound;
  603. }
  604. virtual void __fastcall ReadPrefix(TFilerFlags & Flags, int & AChildPos)
  605. {
  606. TReader::ReadPrefix(Flags, AChildPos);
  607. Flags << ffInherited;
  608. }
  609. void __fastcall AncestorNotFound(TReader * Reader,
  610. const AnsiString ComponentName, TMetaClass * ComponentClass,
  611. TComponent *& Component)
  612. {
  613. assert(!Component);
  614. if (ComponentName.IsEmpty())
  615. {
  616. for (int Index = 0; Index < LookupRoot->ComponentCount; Index++)
  617. {
  618. Component = LookupRoot->Components[Index];
  619. if (Component->Name.IsEmpty())
  620. {
  621. return;
  622. }
  623. }
  624. Component = NULL;
  625. }
  626. }
  627. };
  628. //---------------------------------------------------------------------------
  629. bool __fastcall TWinConfiguration::InternalReloadComponentRes(const AnsiString ResName,
  630. HANDLE HInst, TComponent * Instance)
  631. {
  632. HANDLE HRsrc;
  633. bool Result;
  634. if (!HInst)
  635. {
  636. HInst = HInstance;
  637. }
  638. HRsrc = FindResource(HInst, ResName.c_str(), RT_RCDATA);
  639. Result = (HRsrc != 0);
  640. if (Result)
  641. {
  642. TResourceStream * ResStream = new TResourceStream(
  643. reinterpret_cast<int>(HInst), ResName, RT_RCDATA);
  644. try
  645. {
  646. TReader * Reader;
  647. Reader = new TAsInheritedReader(ResStream, 4096);
  648. try
  649. {
  650. /*Instance =*/ Reader->ReadRootComponent(Instance);
  651. }
  652. __finally
  653. {
  654. delete Reader;
  655. }
  656. }
  657. __finally
  658. {
  659. delete ResStream;
  660. }
  661. }
  662. return Result;
  663. }
  664. //---------------------------------------------------------------------------
  665. bool __fastcall TWinConfiguration::InitComponent(TComponent * Instance,
  666. TClass RootAncestor, TClass ClassType)
  667. {
  668. bool Result = false;
  669. if ((ClassType != __classid(TComponent)) && (ClassType != RootAncestor))
  670. {
  671. if (InitComponent(Instance, RootAncestor, ClassType->ClassParent()))
  672. {
  673. Result = true;
  674. }
  675. if (InternalReloadComponentRes(ClassType->ClassName(),
  676. reinterpret_cast<HANDLE>(FindResourceHInstance(FindClassHInstance(ClassType))),
  677. Instance))
  678. {
  679. Result = true;
  680. }
  681. }
  682. return Result;
  683. }
  684. //---------------------------------------------------------------------------
  685. LCID __fastcall TWinConfiguration::GetLocale()
  686. {
  687. if (!FLocale)
  688. {
  689. AnsiString ResourceModule = GetResourceModule(ModuleFileName().c_str());
  690. if (!ResourceModule.IsEmpty())
  691. {
  692. AnsiString ResourceExt = ExtractFileExt(ResourceModule).UpperCase();
  693. ResourceExt.Delete(1, 1);
  694. TLanguages * Langs = Languages();
  695. int Index, Count;
  696. Count = Langs->Count;
  697. Index = 0;
  698. while ((Index < Count) && !FLocale)
  699. {
  700. if (Langs->Ext[Index] == ResourceExt)
  701. {
  702. FLocale = Langs->LocaleID[Index];
  703. }
  704. else if (Langs->Ext[Index].SubString(1, 2) == ResourceExt)
  705. {
  706. FLocale = MAKELANGID(PRIMARYLANGID(Langs->LocaleID[Index]),
  707. SUBLANG_DEFAULT);
  708. }
  709. Index++;
  710. }
  711. }
  712. }
  713. return TCustomWinConfiguration::GetLocale();
  714. }
  715. //---------------------------------------------------------------------------
  716. HANDLE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
  717. AnsiString * FileName)
  718. {
  719. AnsiString FileNameStorage;
  720. if (FileName == NULL)
  721. {
  722. FileName = &FileNameStorage;
  723. }
  724. HANDLE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
  725. if (Instance != NULL)
  726. {
  727. try
  728. {
  729. CheckTranslationVersion(*FileName);
  730. }
  731. catch(...)
  732. {
  733. FreeResourceModule(Instance);
  734. throw;
  735. }
  736. }
  737. return Instance;
  738. }
  739. //---------------------------------------------------------------------------
  740. void __fastcall TWinConfiguration::SetResourceModule(HANDLE Instance)
  741. {
  742. TCustomWinConfiguration::SetResourceModule(Instance);
  743. Busy(true);
  744. try
  745. {
  746. int Count;
  747. AnsiString OrigName;
  748. int OrigLeft;
  749. int OrigTop;
  750. TForm * Form;
  751. Count = Screen->FormCount;
  752. for (int Index = 0; Index < Count; Index++)
  753. {
  754. Form = Screen->Forms[Index];
  755. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 0, 1);
  756. }
  757. ConfigureInterface();
  758. for (int Index = 0; Index < Count; Index++)
  759. {
  760. TComponent * Component;
  761. for (int Index = 0; Index < Form->ComponentCount; Index++)
  762. {
  763. Component = Form->Components[Index];
  764. if (dynamic_cast<TFrame*>(Component))
  765. {
  766. OrigName = Component->Name;
  767. InitComponent(Component, __classid(TFrame), Component->ClassType());
  768. Component->Name = OrigName;
  769. }
  770. }
  771. OrigLeft = Form->Left;
  772. OrigTop = Form->Top;
  773. OrigName = Form->Name;
  774. InitComponent(Form, __classid(TForm), Form->ClassType());
  775. Form->Name = OrigName;
  776. Form->Position = poDesigned;
  777. Form->Left = OrigLeft;
  778. Form->Top = OrigTop;
  779. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 1, 1);
  780. }
  781. TDataModule * DataModule;
  782. Count = Screen->DataModuleCount;
  783. for (int Index = 0; Index < Count; Index++)
  784. {
  785. DataModule = Screen->DataModules[Index];
  786. OrigName = DataModule->Name;
  787. InitComponent(DataModule, __classid(TDataModule), DataModule->ClassType());
  788. DataModule->Name = OrigName;
  789. }
  790. }
  791. __finally
  792. {
  793. Busy(false);
  794. }
  795. }
  796. //---------------------------------------------------------------------------
  797. void __fastcall TWinConfiguration::CheckTranslationVersion(const AnsiString FileName)
  798. {
  799. AnsiString TranslationProductVersion = GetFileProductVersion(FileName);
  800. AnsiString TranslationProductName = GetFileProductName(FileName);
  801. if ((ProductName != TranslationProductName) ||
  802. (ProductVersion != TranslationProductVersion))
  803. {
  804. if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
  805. {
  806. throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
  807. }
  808. else
  809. {
  810. throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
  811. (FileName, TranslationProductName, TranslationProductVersion)));
  812. }
  813. }
  814. }
  815. //---------------------------------------------------------------------------
  816. //---------------------------------------------------------------------------
  817. int __fastcall TCustomCommands::GetParam(const AnsiString & Name)
  818. {
  819. int Index = IndexOfName(Name);
  820. if (Index >= 0)
  821. {
  822. return int(Objects[Index]);
  823. }
  824. else
  825. {
  826. return 0;
  827. }
  828. }
  829. //---------------------------------------------------------------------------
  830. void __fastcall TCustomCommands::SetParam(const AnsiString & Name, int value)
  831. {
  832. int Index = IndexOfName(Name);
  833. if (Index >= 0)
  834. {
  835. Objects[Index] = (TObject *)value;
  836. }
  837. else
  838. {
  839. Values[Name] = "";
  840. Index = IndexOfName(Name);
  841. assert(Index >= 0);
  842. Objects[Index] = (TObject *)value;
  843. }
  844. }
  845. //---------------------------------------------------------------------------
  846. bool __fastcall TCustomCommands::Equals(TCustomCommands * Commands)
  847. {
  848. bool Result = TStringList::Equals(Commands);
  849. if (Result)
  850. {
  851. int Index = 0;
  852. while ((Index < Count) && Result)
  853. {
  854. if (Objects[Index] != Commands->Objects[Index])
  855. {
  856. Result = false;
  857. }
  858. Index++;
  859. }
  860. }
  861. return Result;
  862. }