WinConfiguration.cpp 31 KB

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