WinConfiguration.cpp 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "WinConfiguration.h"
  5. #include "Common.h"
  6. #include "Exceptions.h"
  7. #include "Bookmarks.h"
  8. #include "Terminal.h"
  9. #include "TextsWin.h"
  10. #include "WinInterface.h"
  11. #include "GUITools.h"
  12. #include "Tools.h"
  13. #include "Setup.h"
  14. #include "Security.h"
  15. #include "TerminalManager.h"
  16. #include "Cryptography.h"
  17. #include <VCLCommon.h>
  18. #include <ResourceModule.hpp>
  19. #include <LanguagesDEPfix.hpp>
  20. #include <InitGUID.h>
  21. #include <DragExt.h>
  22. //---------------------------------------------------------------------------
  23. #pragma package(smart_init)
  24. //---------------------------------------------------------------------------
  25. __fastcall TEditorData::TEditorData() :
  26. FileMask("*.*"),
  27. Editor(edInternal),
  28. ExternalEditor(""),
  29. ExternalEditorText(true),
  30. SDIExternalEditor(false),
  31. DetectMDIExternalEditor(false)
  32. {
  33. }
  34. //---------------------------------------------------------------------------
  35. __fastcall TEditorData::TEditorData(const TEditorData & Source) :
  36. FileMask(Source.FileMask),
  37. Editor(Source.Editor),
  38. ExternalEditor(Source.ExternalEditor),
  39. ExternalEditorText(Source.ExternalEditorText),
  40. SDIExternalEditor(Source.SDIExternalEditor),
  41. DetectMDIExternalEditor(Source.DetectMDIExternalEditor)
  42. {
  43. }
  44. //---------------------------------------------------------------------------
  45. #define C(Property) (Property == rhd.Property)
  46. bool __fastcall TEditorData::operator==(const TEditorData & rhd) const
  47. {
  48. return
  49. C(FileMask) &&
  50. C(Editor) &&
  51. C(ExternalEditor) &&
  52. C(ExternalEditorText) &&
  53. C(SDIExternalEditor) &&
  54. C(DetectMDIExternalEditor) &&
  55. true;
  56. }
  57. #undef C
  58. //---------------------------------------------------------------------------
  59. __fastcall TEditorPreferences::TEditorPreferences()
  60. {
  61. }
  62. //---------------------------------------------------------------------------
  63. __fastcall TEditorPreferences::TEditorPreferences(const TEditorData & Data) :
  64. FData(Data)
  65. {
  66. }
  67. //---------------------------------------------------------------------------
  68. bool __fastcall TEditorPreferences::operator==(const TEditorPreferences & rhp) const
  69. {
  70. return (FData == rhp.FData);
  71. }
  72. #undef C
  73. //---------------------------------------------------------------------------
  74. bool __fastcall TEditorPreferences::Matches(const AnsiString FileName,
  75. bool Local, const TFileMasks::TParams & Params) const
  76. {
  77. return FData.FileMask.Matches(FileName, Local, false, &Params);
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TEditorPreferences::LegacyDefaults()
  81. {
  82. FData.ExternalEditor = "notepad.exe";
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TEditorPreferences::Load(THierarchicalStorage * Storage, bool Legacy)
  86. {
  87. if (!Legacy)
  88. {
  89. FData.FileMask = Storage->ReadString("FileMask", FData.FileMask.Masks);
  90. }
  91. FData.Editor = (TEditor)Storage->ReadInteger("Editor", FData.Editor);
  92. FData.ExternalEditor = Storage->ReadString("ExternalEditor", FData.ExternalEditor);
  93. FData.ExternalEditorText = Storage->ReadBool("ExternalEditorText", FData.ExternalEditorText);
  94. FData.SDIExternalEditor = Storage->ReadBool("SDIExternalEditor", FData.SDIExternalEditor);
  95. FData.DetectMDIExternalEditor = Storage->ReadBool("DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TEditorPreferences::Save(THierarchicalStorage * Storage) const
  99. {
  100. Storage->WriteString("FileMask", FData.FileMask.Masks);
  101. Storage->WriteInteger("Editor", FData.Editor);
  102. Storage->WriteString("ExternalEditor", FData.ExternalEditor);
  103. Storage->WriteBool("ExternalEditorText", FData.ExternalEditorText);
  104. Storage->WriteBool("SDIExternalEditor", FData.SDIExternalEditor);
  105. Storage->WriteBool("DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
  106. }
  107. //---------------------------------------------------------------------------
  108. TEditorData * __fastcall TEditorPreferences::GetData()
  109. {
  110. // returning non-const data, possible data change, invalidate cached name
  111. FName = "";
  112. return &FData;
  113. };
  114. //---------------------------------------------------------------------------
  115. AnsiString __fastcall TEditorPreferences::GetName() const
  116. {
  117. if (FName.IsEmpty())
  118. {
  119. if (FData.Editor == edInternal)
  120. {
  121. FName = StripHotkey(LoadStr(INTERNAL_EDITOR_NAME));
  122. }
  123. else if (FData.Editor == edOpen)
  124. {
  125. FName = StripHotkey(LoadStr(OPEN_EDITOR_NAME));
  126. }
  127. else
  128. {
  129. AnsiString Program, Params, Dir;
  130. AnsiString ExternalEditor = FData.ExternalEditor;
  131. ReformatFileNameCommand(ExternalEditor);
  132. SplitCommand(ExternalEditor, Program, Params, Dir);
  133. FName = ExtractFileName(Program);
  134. int P = FName.LastDelimiter(".");
  135. if (P > 0)
  136. {
  137. FName.SetLength(P - 1);
  138. }
  139. if (FName.ByteType(1) == mbSingleByte)
  140. {
  141. if (FName.UpperCase() == FName)
  142. {
  143. FName = FName.LowerCase();
  144. }
  145. if (FName.LowerCase() == FName)
  146. {
  147. FName = FName.SubString(1, 1).UpperCase() +
  148. FName.SubString(2, FName.Length() - 1);
  149. }
  150. }
  151. }
  152. }
  153. return FName;
  154. }
  155. //---------------------------------------------------------------------------
  156. //---------------------------------------------------------------------------
  157. __fastcall TEditorList::TEditorList()
  158. {
  159. Init();
  160. }
  161. //---------------------------------------------------------------------------
  162. void __fastcall TEditorList::Init()
  163. {
  164. FEditors = new TList();
  165. FModified = false;
  166. }
  167. //---------------------------------------------------------------------------
  168. __fastcall TEditorList::~TEditorList()
  169. {
  170. Clear();
  171. delete FEditors;
  172. }
  173. //---------------------------------------------------------------------
  174. void __fastcall TEditorList::Modify()
  175. {
  176. FModified = true;
  177. }
  178. //---------------------------------------------------------------------------
  179. void __fastcall TEditorList::Saved()
  180. {
  181. FModified = false;
  182. }
  183. //---------------------------------------------------------------------------
  184. void __fastcall TEditorList::operator=(const TEditorList & rhl)
  185. {
  186. Clear();
  187. for (int Index = 0; Index < rhl.Count; Index++)
  188. {
  189. Add(new TEditorPreferences(*rhl.Editors[Index]));
  190. }
  191. // there should be comparison of with the assigned list, but we rely on caller
  192. // to do it instead (TWinConfiguration::SetEditorList)
  193. Modify();
  194. }
  195. //---------------------------------------------------------------------------
  196. bool __fastcall TEditorList::operator==(const TEditorList & rhl) const
  197. {
  198. bool Result = (Count == rhl.Count);
  199. if (Result)
  200. {
  201. int i = 0;
  202. while ((i < Count) && Result)
  203. {
  204. Result = (*Editors[i]) == (*rhl.Editors[i]);
  205. i++;
  206. }
  207. }
  208. return Result;
  209. }
  210. //---------------------------------------------------------------------------
  211. void __fastcall TEditorList::Clear()
  212. {
  213. for (int i = 0; i < Count; i++)
  214. {
  215. delete Editors[i];
  216. }
  217. FEditors->Clear();
  218. }
  219. //---------------------------------------------------------------------------
  220. void __fastcall TEditorList::Add(TEditorPreferences * Editor)
  221. {
  222. Insert(Count, Editor);
  223. }
  224. //---------------------------------------------------------------------------
  225. void __fastcall TEditorList::Insert(int Index, TEditorPreferences * Editor)
  226. {
  227. FEditors->Insert(Index, reinterpret_cast<TObject *>(Editor));
  228. Modify();
  229. }
  230. //---------------------------------------------------------------------------
  231. void __fastcall TEditorList::Change(int Index, TEditorPreferences * Editor)
  232. {
  233. if (!((*Editors[Index]) == *Editor))
  234. {
  235. delete Editors[Index];
  236. FEditors->Items[Index] = (reinterpret_cast<TObject *>(Editor));
  237. Modify();
  238. }
  239. else
  240. {
  241. delete Editor;
  242. }
  243. }
  244. //---------------------------------------------------------------------------
  245. void __fastcall TEditorList::Move(int CurIndex, int NewIndex)
  246. {
  247. if (CurIndex != NewIndex)
  248. {
  249. FEditors->Move(CurIndex, NewIndex);
  250. Modify();
  251. }
  252. }
  253. //---------------------------------------------------------------------------
  254. void __fastcall TEditorList::Delete(int Index)
  255. {
  256. assert((Index >= 0) && (Index < Count));
  257. delete Editors[Index];
  258. FEditors->Delete(Index);
  259. Modify();
  260. }
  261. //---------------------------------------------------------------------------
  262. const TEditorPreferences * __fastcall TEditorList::Find(
  263. const AnsiString FileName, bool Local, const TFileMasks::TParams & Params) const
  264. {
  265. const TEditorPreferences * Result = NULL;
  266. int i = 0;
  267. while ((i < FEditors->Count) && (Result == NULL))
  268. {
  269. Result = Editors[i];
  270. if (!Result->Matches(FileName, Local, Params))
  271. {
  272. Result = NULL;
  273. }
  274. i++;
  275. }
  276. return Result;
  277. }
  278. //---------------------------------------------------------------------------
  279. void __fastcall TEditorList::Load(THierarchicalStorage * Storage)
  280. {
  281. int Index = 0;
  282. bool Next;
  283. do
  284. {
  285. AnsiString Name = IntToStr(Index);
  286. TEditorPreferences * Editor = NULL;
  287. try
  288. {
  289. Next = Storage->OpenSubKey(Name, false);
  290. if (Next)
  291. {
  292. try
  293. {
  294. Editor = new TEditorPreferences();
  295. Editor->Load(Storage, false);
  296. }
  297. __finally
  298. {
  299. Storage->CloseSubKey();
  300. }
  301. }
  302. }
  303. catch(...)
  304. {
  305. delete Editor;
  306. throw;
  307. }
  308. if (Editor != NULL)
  309. {
  310. FEditors->Add(reinterpret_cast<TObject *>(Editor));
  311. }
  312. Index++;
  313. }
  314. while (Next);
  315. FModified = false;
  316. }
  317. //---------------------------------------------------------------------------
  318. void __fastcall TEditorList::Save(THierarchicalStorage * Storage) const
  319. {
  320. Storage->ClearSubKeys();
  321. for (int Index = 0; Index < Count; Index++)
  322. {
  323. if (Storage->OpenSubKey(IntToStr(Index), true))
  324. {
  325. try
  326. {
  327. Editors[Index]->Save(Storage);
  328. }
  329. __finally
  330. {
  331. Storage->CloseSubKey();
  332. }
  333. }
  334. }
  335. }
  336. //---------------------------------------------------------------------------
  337. int __fastcall TEditorList::GetCount() const
  338. {
  339. int X = FEditors->Count;
  340. return X;
  341. }
  342. //---------------------------------------------------------------------------
  343. const TEditorPreferences * __fastcall TEditorList::GetEditor(int Index) const
  344. {
  345. return reinterpret_cast<TEditorPreferences *>(FEditors->Items[Index]);
  346. }
  347. //---------------------------------------------------------------------------
  348. //---------------------------------------------------------------------------
  349. __fastcall TWinConfiguration::TWinConfiguration(): TCustomWinConfiguration()
  350. {
  351. FInvalidDefaultTranslationMessage = "";
  352. FDDExtInstalled = -1;
  353. FBookmarks = new TBookmarks();
  354. FCustomCommandList = new TCustomCommandList();
  355. FEditorList = new TEditorList();
  356. FDefaultUpdatesPeriod = 0;
  357. Default();
  358. try
  359. {
  360. CheckTranslationVersion(::GetResourceModule(ModuleFileName().c_str()), true);
  361. }
  362. catch(Exception & E)
  363. {
  364. FInvalidDefaultTranslationMessage = E.Message;
  365. }
  366. }
  367. //---------------------------------------------------------------------------
  368. __fastcall TWinConfiguration::~TWinConfiguration()
  369. {
  370. if (!FTemporarySessionFile.IsEmpty()) DeleteFile(FTemporarySessionFile);
  371. ClearTemporaryLoginData();
  372. delete FBookmarks;
  373. delete FCustomCommandList;
  374. delete FEditorList;
  375. }
  376. //---------------------------------------------------------------------------
  377. void __fastcall TWinConfiguration::Default()
  378. {
  379. FCustomCommandsDefaults = true;
  380. TCustomWinConfiguration::Default();
  381. FDDAllowMove = false;
  382. FDDAllowMoveInit = false;
  383. FDDTransferConfirmation = true;
  384. FDDTemporaryDirectory = "";
  385. FDDWarnLackOfTempSpace = true;
  386. FDDWarnLackOfTempSpaceRatio = 1.1;
  387. FDDExtEnabled = DDExtInstalled;
  388. FDDExtTimeout = 1000;
  389. FDeleteToRecycleBin = true;
  390. FSelectDirectories = false;
  391. FSelectMask = "*.*";
  392. FShowHiddenFiles = true;
  393. FShowInaccesibleDirectories = true;
  394. FConfirmTransferring = true;
  395. FConfirmDeleting = true;
  396. FConfirmRecycling = true;
  397. FConfirmClosingSession = true;
  398. FDoubleClickAction = dcaEdit;
  399. FCopyOnDoubleClickConfirmation = false;
  400. FDimmHiddenFiles = true;
  401. FRenameWholeName = false;
  402. FAutoStartSession = "";
  403. FExpertMode = true;
  404. FUseLocationProfiles = false;
  405. FUseSharedBookmarks = false;
  406. FDefaultDirIsHome = true;
  407. FDDDeleteDelay = 120;
  408. FTemporaryDirectoryAppendSession = false;
  409. FTemporaryDirectoryAppendPath = true;
  410. FTemporaryDirectoryCleanup = true;
  411. FConfirmTemporaryDirectoryCleanup = true;
  412. FPreservePanelState = true;
  413. FTheme = "OfficeXP";
  414. FPathInCaption = picShort;
  415. FMinimizeToTray = false;
  416. FBalloonNotifications = true;
  417. FNotificationsTimeout = 10;
  418. FNotificationsStickTime = 2;
  419. FCopyParamAutoSelectNotice = true;
  420. FSessionToolbarAutoShown = false;
  421. FLockToolbars = false;
  422. FAutoOpenInPutty = false;
  423. FVersionHistory = "";
  424. AddVersionToHistory(FVersionHistory);
  425. FUseMasterPassword = false;
  426. FPlainMasterPasswordEncrypt = "";
  427. FPlainMasterPasswordDecrypt = "";
  428. FMasterPasswordVerifier = "";
  429. FEditor.FontName = "Courier New";
  430. FEditor.FontHeight = -12;
  431. FEditor.FontStyle = 0;
  432. FEditor.FontCharset = DEFAULT_CHARSET;
  433. FEditor.WordWrap = false;
  434. FEditor.FindText = "";
  435. FEditor.ReplaceText = "";
  436. FEditor.FindMatchCase = false;
  437. FEditor.FindWholeWord = false;
  438. FEditor.FindDown = true;
  439. FEditor.TabSize = 7;
  440. FEditor.MaxEditors = 500;
  441. FEditor.EarlyClose = 2; // seconds
  442. FEditor.SDIShellEditor = false;
  443. FEditor.WindowParams = "";
  444. FQueueView.Height = 100;
  445. FQueueView.Layout = "70,160,160,80,80,80";
  446. FQueueView.Show = qvHideWhenEmpty;
  447. FQueueView.LastHideShow = qvHideWhenEmpty;
  448. FQueueView.ToolBar = false;
  449. FUpdates.Period = FDefaultUpdatesPeriod;
  450. FUpdates.LastCheck = 0;
  451. FUpdates.HaveResults = false;
  452. FUpdates.ShownResults = false;
  453. FUpdates.BetaVersions = asAuto;
  454. // for backward compatibility the default is decided based on value of ProxyHost
  455. FUpdates.ConnectionType = (TConnectionType)-1;
  456. FUpdates.ProxyHost = ""; // keep empty (see above)
  457. FUpdates.ProxyPort = 8080;
  458. FUpdates.Results.Reset();
  459. FLogWindowOnStartup = true;
  460. FLogWindowParams = "-1;-1;500;400";
  461. FScpExplorer.WindowParams = "-1;-1;600;400;0";
  462. FScpExplorer.DirViewParams = "0;1;0|150,1;70,1;101,1;79,1;62,1;55,1;20,0;150,0;125,0|0;1;8;2;3;4;5;6;7";
  463. FScpExplorer.ToolbarsLayout =
  464. "Queue_Visible=1,Queue_LastDock=QueueDock,Queue_DockRow=0,Queue_DockPos=-1,Queue_FloatLeft=0,Queue_FloatTop=0,Queue_FloatRightX=0,"
  465. "Menu_Visible=1,Menu_DockedTo=TopDock,Menu_LastDock=TopDock,Menu_DockRow=0,Menu_DockPos=0,Menu_FloatLeft=0,Menu_FloatTop=0,Menu_FloatRightX=0,"
  466. "Buttons_Visible=1,Buttons_DockedTo=TopDock,Buttons_LastDock=TopDock,Buttons_DockRow=2,Buttons_DockPos=0,Buttons_FloatLeft=0,Buttons_FloatTop=0,Buttons_FloatRightX=0,"
  467. "Selection_Visible=0,Selection_DockedTo=TopDock,Selection_LastDock=TopDock,Selection_DockRow=3,Selection_DockPos=0,Selection_FloatLeft=227,Selection_FloatTop=445,Selection_FloatRightX=0,"
  468. "Session_Visible=0,Session_DockedTo=TopDock,Session_LastDock=TopDock,Session_DockRow=6,Session_DockPos=0,Session_FloatLeft=39,Session_FloatTop=160,Session_FloatRightX=0,"
  469. "Preferences_Visible=1,Preferences_DockedTo=TopDock,Preferences_LastDock=TopDock,Preferences_DockRow=4,Preferences_DockPos=0,Preferences_FloatLeft=0,Preferences_FloatTop=0,Preferences_FloatRightX=0,"
  470. "Sort_Visible=0,Sort_DockedTo=TopDock,Sort_LastDock=TopDock,Sort_DockRow=5,Sort_DockPos=0,Sort_FloatLeft=0,Sort_FloatTop=0,Sort_FloatRightX=0,"
  471. "Address_Visible=1,Address_DockedTo=TopDock,Address_LastDock=TopDock,Address_DockRow=1,Address_DockPos=0,Address_FloatLeft=0,Address_FloatTop=0,Address_FloatRightX=0,"
  472. "Updates_Visible=1,Updates_DockedTo=TopDock,Updates_LastDock=TopDock,Updates_DockRow=4,Updates_DockPos=302,Updates_FloatLeft=0,Updates_FloatTop=0,Updates_FloatRightX=0,"
  473. "Transfer_Visible=1,Transfer_DockedTo=TopDock,Transfer_LastDock=TopDock,Transfer_DockRow=4,Transfer_DockPos=155,Transfer_FloatLeft=0,Transfer_FloatTop=0,Transfer_FloatRightX=0"
  474. "CustomCommands_Visible=0,CustomCommands_DockedTo=TopDock,CustomCommands_LastDock=TopDock,CustomCommands_DockRow=7,CustomCommands_DockPos=0,CustomCommands_FloatLeft=0,CustomCommands_FloatTop=0,CustomCommands_FloatRightX=0";
  475. FScpExplorer.StatusBar = true;
  476. AnsiString PersonalFolder;
  477. ::SpecialFolderLocation(CSIDL_PERSONAL, PersonalFolder);
  478. FScpExplorer.LastLocalTargetDirectory = PersonalFolder;
  479. FScpExplorer.ViewStyle = 0; /* vsIcon */
  480. FScpExplorer.ShowFullAddress = true;
  481. FScpExplorer.DriveView = true;
  482. FScpExplorer.DriveViewWidth = 180;
  483. FScpCommander.WindowParams = ((Screen->Width > 900) && (Screen->Height > 700)) ?
  484. "-1;-1;850;650;0" : "-1;-1;600;400;0";
  485. FScpCommander.LocalPanelWidth = 0.5;
  486. FScpCommander.SwappedPanels = false;
  487. FScpCommander.StatusBar = true;
  488. FScpCommander.NortonLikeMode = nlKeyboard;
  489. FScpCommander.PreserveLocalDirectory = false;
  490. // Toolbar_FloatRightX=1 makes keybar apper initialy "in column" when undocked
  491. FScpCommander.ToolbarsLayout =
  492. "Queue_Visible=1,Queue_LastDock=QueueDock,Queue_DockRow=0,Queue_DockPos=-1,Queue_FloatLeft=0,Queue_FloatTop=0,Queue_FloatRightX=0,"
  493. "Session_Visible=0,Session_DockedTo=TopDock,Session_LastDock=TopDock,Session_DockRow=1,Session_DockPos=602,Session_FloatLeft=380,Session_FloatTop=197,Session_FloatRightX=0,"
  494. "Preferences_Visible=1,Preferences_DockedTo=TopDock,Preferences_LastDock=TopDock,Preferences_DockRow=1,Preferences_DockPos=0,Preferences_FloatLeft=0,Preferences_FloatTop=0,Preferences_FloatRightX=0,"
  495. "Selection_Visible=1,Selection_DockedTo=TopDock,Selection_LastDock=TopDock,Selection_DockRow=1,Selection_DockPos=257,Selection_FloatLeft=0,Selection_FloatTop=0,Selection_FloatRightX=0,"
  496. "Command_Visible=0,Command_DockedTo=TopDock,Command_LastDock=TopDock,Command_DockRow=2,Command_DockPos=0,Command_FloatLeft=0,Command_FloatTop=0,Command_FloatRightX=0,"
  497. "Sort_Visible=0,Sort_DockedTo=TopDock,Sort_LastDock=TopDock,Sort_DockRow=3,Sort_DockPos=0,Sort_FloatLeft=0,Sort_FloatTop=0,Sort_FloatRightX=0,"
  498. "Commands_Visible=1,Commands_DockedTo=TopDock,Commands_LastDock=TopDock,Commands_DockRow=1,Commands_DockPos=97,Commands_FloatLeft=0,Commands_FloatTop=0,Commands_FloatRightX=0,"
  499. "Menu_Visible=1,Menu_DockedTo=TopDock,Menu_LastDock=TopDock,Menu_DockRow=0,Menu_DockPos=0,Menu_FloatLeft=0,Menu_FloatTop=0,Menu_FloatRightX=0,"
  500. "Updates_Visible=1,Updates_DockedTo=TopDock,Updates_LastDock=TopDock,Updates_DockRow=1,Updates_DockPos=557,Updates_FloatLeft=0,Updates_FloatTop=0,Updates_FloatRightX=0,"
  501. "Transfer_Visible=1,Transfer_DockedTo=TopDock,Transfer_LastDock=TopDock,Transfer_DockRow=1,Transfer_DockPos=411,Transfer_FloatLeft=0,Transfer_FloatTop=0,Transfer_FloatRightX=0,"
  502. "UploadDownload_Visible=0,UploadDownload_DockedTo=TopDock,UploadDownload_LastDock=TopDock,UploadDownload_DockRow=4,UploadDownload_DockPos=0,UploadDownload_FloatLeft=0,UploadDownload_FloatTop=0,UploadDownload_FloatRightX=0,"
  503. "CustomCommands_Visible=0,CustomCommands_DockedTo=TopDock,CustomCommands_LastDock=TopDock,CustomCommands_DockRow=5,CustomCommands_DockPos=0,CustomCommands_FloatLeft=0,CustomCommands_FloatTop=0,CustomCommands_FloatRightX=0,"
  504. "RemotePath_Visible=1,RemotePath_DockedTo=RemoteTopDock,RemotePath_LastDock=RemoteTopDock,RemotePath_DockRow=0,RemotePath_DockPos=0,RemotePath_FloatLeft=0,RemotePath_FloatTop=0,RemotePath_FloatRightX=0,"
  505. "RemoteHistory_Visible=1,RemoteHistory_DockedTo=RemoteTopDock,RemoteHistory_LastDock=RemoteTopDock,RemoteHistory_DockRow=0,RemoteHistory_DockPos=208,RemoteHistory_FloatLeft=0,RemoteHistory_FloatTop=0,RemoteHistory_FloatRightX=0,"
  506. "RemoteNavigation_Visible=1,RemoteNavigation_DockedTo=RemoteTopDock,RemoteNavigation_LastDock=RemoteTopDock,RemoteNavigation_DockRow=0,RemoteNavigation_DockPos=288,RemoteNavigation_FloatLeft=0,RemoteNavigation_FloatTop=0,RemoteNavigation_FloatRightX=0,"
  507. "LocalPath_Visible=1,LocalPath_DockedTo=LocalTopDock,LocalPath_LastDock=LocalTopDock,LocalPath_DockRow=0,LocalPath_DockPos=0,LocalPath_FloatLeft=0,LocalPath_FloatTop=0,LocalPath_FloatRightX=0,"
  508. "LocalHistory_Visible=1,LocalHistory_DockedTo=LocalTopDock,LocalHistory_LastDock=LocalTopDock,LocalHistory_DockRow=0,LocalHistory_DockPos=207,LocalHistory_FloatLeft=0,LocalHistory_FloatTop=0,LocalHistory_FloatRightX=0,"
  509. "LocalNavigation_Visible=1,LocalNavigation_DockedTo=LocalTopDock,LocalNavigation_LastDock=LocalTopDock,LocalNavigation_DockRow=0,LocalNavigation_DockPos=287,LocalNavigation_FloatLeft=0,LocalNavigation_FloatTop=0,LocalNavigation_FloatRightX=0,"
  510. "Toolbar_Visible=1,Toolbar_DockedTo=BottomDock,Toolbar_LastDock=BottomDock,Toolbar_DockRow=1,Toolbar_DockPos=0,Toolbar_FloatLeft=0,Toolbar_FloatTop=0,Toolbar_FloatRightX=1,"
  511. "CommandLine_Visible=0,CommandLine_DockedTo=BottomDock,CommandLine_LastDock=BottomDock,CommandLine_DockRow=0,CommandLine_DockPos=0,CommandLine_FloatLeft=0,CommandLine_FloatTop=0,CommandLine_FloatRightX=0";
  512. FScpCommander.CurrentPanel = osLocal;
  513. FScpCommander.CompareByTime = true;
  514. FScpCommander.CompareBySize = false;
  515. FScpCommander.FullRowSelect = true;
  516. FScpCommander.TreeOnLeft = false;
  517. FScpCommander.RemotePanel.DirViewParams = "0;1;0|150,1;70,1;101,1;79,1;62,1;55,0;20,0;150,0;125,0|0;1;8;2;3;4;5;6;7";
  518. FScpCommander.RemotePanel.StatusBar = true;
  519. FScpCommander.RemotePanel.DriveView = false;
  520. FScpCommander.RemotePanel.DriveViewHeight = 100;
  521. FScpCommander.RemotePanel.DriveViewWidth = 100;
  522. FScpCommander.LocalPanel.DirViewParams = "0;1;0|150,1;70,1;101,1;79,1;62,1;55,0|0;1;2;3;4;5";
  523. FScpCommander.LocalPanel.StatusBar = true;
  524. FScpCommander.LocalPanel.DriveView = false;
  525. FScpCommander.LocalPanel.DriveViewHeight = 100;
  526. FScpCommander.LocalPanel.DriveViewWidth = 100;
  527. FBookmarks->Clear();
  528. }
  529. //---------------------------------------------------------------------------
  530. void __fastcall TWinConfiguration::DefaultLocalized()
  531. {
  532. TGUIConfiguration::DefaultLocalized();
  533. if (FCustomCommandsDefaults)
  534. {
  535. FCustomCommandList->Clear();
  536. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_EXECUTE), "\"./!\"", 0);
  537. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TOUCH), "touch \"!\"", ccApplyToDirectories | ccRecursive);
  538. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TAR),
  539. FORMAT("tar -cz -f \"!?%s?archive.tgz!\" !&",
  540. (LoadStr(CUSTOM_COMMAND_TAR_ARCHIVE))), ccApplyToDirectories);
  541. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_UNTAR),
  542. FORMAT("tar -xz --directory=\"!?%s?.!\" -f \"!\"",
  543. (LoadStr(CUSTOM_COMMAND_UNTAR_DIRECTORY))), 0);
  544. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_GREP),
  545. FORMAT("grep \"!?%s?!\" !&", (LoadStr(CUSTOM_COMMAND_GREP_PATTERN))),
  546. ccShowResults);
  547. if (Win32Platform == VER_PLATFORM_WIN32_NT)
  548. {
  549. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_FC),
  550. "cmd /c fc \"!\" \"\!^!\" | more && pause", ccLocal);
  551. }
  552. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_PRINT), "notepad.exe /p \"!\"", ccLocal);
  553. FCustomCommandList->Reset();
  554. FCustomCommandsDefaults = true;
  555. }
  556. }
  557. //---------------------------------------------------------------------------
  558. bool __fastcall TWinConfiguration::DetectRegistryStorage(HKEY RootKey)
  559. {
  560. bool Result = false;
  561. TRegistryStorage * Storage = new TRegistryStorage(RegistryStorageKey, RootKey);
  562. try
  563. {
  564. if (Storage->OpenRootKey(false))
  565. {
  566. Result = true;
  567. Storage->CloseSubKey();
  568. }
  569. }
  570. __finally
  571. {
  572. delete Storage;
  573. }
  574. return Result;
  575. }
  576. //---------------------------------------------------------------------------
  577. bool __fastcall TWinConfiguration::CanWriteToStorage()
  578. {
  579. bool Result = false;
  580. try
  581. {
  582. THierarchicalStorage * Storage = CreateScpStorage(false);
  583. try
  584. {
  585. Storage->AccessMode = smReadWrite;
  586. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  587. {
  588. Storage->WriteBool("WriteTest", true);
  589. Storage->DeleteValue("WriteTest");
  590. }
  591. }
  592. __finally
  593. {
  594. delete Storage;
  595. }
  596. Result = true;
  597. }
  598. catch(...)
  599. {
  600. }
  601. return Result;
  602. }
  603. //---------------------------------------------------------------------------
  604. TStorage __fastcall TWinConfiguration::GetStorage()
  605. {
  606. if (FStorage == stDetect)
  607. {
  608. if (FindResourceEx(NULL, RT_RCDATA, "WINSCP_SESSION",
  609. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
  610. {
  611. FTemporarySessionFile =
  612. IncludeTrailingBackslash(SystemTemporaryDirectory()) + "winscps.tmp";
  613. DumpResourceToFile("WINSCP_SESSION", FTemporarySessionFile);
  614. FEmbeddedSessions = true;
  615. FTemporaryKeyFile =
  616. IncludeTrailingBackslash(SystemTemporaryDirectory()) + "winscpk.tmp";
  617. if (!DumpResourceToFile("WINSCP_KEY", FTemporaryKeyFile))
  618. {
  619. FTemporaryKeyFile = "";
  620. }
  621. }
  622. FStorage = stIniFile;
  623. if (!FileExists(IniFileStorageName))
  624. {
  625. if (DetectRegistryStorage(HKEY_CURRENT_USER) ||
  626. DetectRegistryStorage(HKEY_LOCAL_MACHINE) ||
  627. !CanWriteToStorage())
  628. {
  629. FStorage = stRegistry;
  630. }
  631. }
  632. }
  633. return TCustomWinConfiguration::GetStorage();
  634. }
  635. //---------------------------------------------------------------------------
  636. void __fastcall TWinConfiguration::Saved()
  637. {
  638. TCustomWinConfiguration::Saved();
  639. FBookmarks->ModifyAll(false);
  640. FCustomCommandList->Reset();
  641. FEditorList->Saved();
  642. }
  643. //---------------------------------------------------------------------------
  644. void __fastcall TWinConfiguration::RecryptPasswords()
  645. {
  646. TCustomWinConfiguration::RecryptPasswords();
  647. TTerminalManager * Manager = TTerminalManager::Instance(false);
  648. assert(Manager != NULL);
  649. if (Manager != NULL)
  650. {
  651. Manager->RecryptPasswords();
  652. }
  653. }
  654. //---------------------------------------------------------------------------
  655. bool __fastcall TWinConfiguration::GetUseMasterPassword()
  656. {
  657. return FUseMasterPassword;
  658. }
  659. //---------------------------------------------------------------------------
  660. THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool SessionList)
  661. {
  662. if (SessionList && !FTemporarySessionFile.IsEmpty())
  663. {
  664. return new TIniFileStorage(FTemporarySessionFile);
  665. }
  666. else
  667. {
  668. return TCustomWinConfiguration::CreateScpStorage(SessionList);
  669. }
  670. }
  671. //---------------------------------------------------------------------------
  672. // duplicated from core\configuration.cpp
  673. #define LASTELEM(ELEM) \
  674. ELEM.SubString(ELEM.LastDelimiter(".>")+1, ELEM.Length() - ELEM.LastDelimiter(".>"))
  675. #define BLOCK(KEY, CANCREATE, BLOCK) \
  676. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  677. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, VAR)
  678. #define REGCONFIG(CANCREATE) \
  679. BLOCK("Interface", CANCREATE, \
  680. KEYEX(Integer,DoubleClickAction, CopyOnDoubleClick); \
  681. KEY(Bool, CopyOnDoubleClickConfirmation); \
  682. KEY(Bool, DDAllowMove); \
  683. KEY(Bool, DDAllowMoveInit); \
  684. KEY(Bool, DDTransferConfirmation); \
  685. KEY(String, DDTemporaryDirectory); \
  686. KEY(Bool, DDWarnLackOfTempSpace); \
  687. KEY(Float, DDWarnLackOfTempSpaceRatio); \
  688. KEY(Bool, DeleteToRecycleBin); \
  689. KEY(Bool, DimmHiddenFiles); \
  690. KEY(Bool, RenameWholeName); \
  691. KEY(Bool, SelectDirectories); \
  692. KEY(String, SelectMask); \
  693. KEY(Bool, ShowHiddenFiles); \
  694. KEY(Bool, ShowInaccesibleDirectories); \
  695. KEY(Bool, ConfirmTransferring); \
  696. KEY(Bool, ConfirmDeleting); \
  697. KEY(Bool, ConfirmRecycling); \
  698. KEY(Bool, ConfirmClosingSession); \
  699. KEY(String, AutoStartSession); \
  700. KEY(Bool, UseLocationProfiles); \
  701. KEY(Bool, UseSharedBookmarks); \
  702. KEY(Integer, LocaleSafe); \
  703. KEY(Bool, DDExtEnabled); \
  704. KEY(Integer, DDExtTimeout); \
  705. KEY(Bool, DefaultDirIsHome); \
  706. KEY(Bool, TemporaryDirectoryAppendSession); \
  707. KEY(Bool, TemporaryDirectoryAppendPath); \
  708. KEY(Bool, TemporaryDirectoryCleanup); \
  709. KEY(Bool, ConfirmTemporaryDirectoryCleanup); \
  710. KEY(Bool, PreservePanelState); \
  711. KEY(String, Theme); \
  712. KEY(Integer, PathInCaption); \
  713. KEY(Bool, MinimizeToTray); \
  714. KEY(Bool, BalloonNotifications); \
  715. KEY(Integer, NotificationsTimeout); \
  716. KEY(Integer, NotificationsStickTime); \
  717. KEY(Bool, CopyParamAutoSelectNotice); \
  718. KEY(Bool, SessionToolbarAutoShown); \
  719. KEY(Bool, LockToolbars); \
  720. KEY(Bool, AutoOpenInPutty); \
  721. KEY(Integer, LastMonitor); \
  722. KEY(String, VersionHistory); \
  723. ); \
  724. BLOCK("Interface\\Editor", CANCREATE, \
  725. KEY(String, Editor.FontName); \
  726. KEY(Integer, Editor.FontHeight); \
  727. KEY(Integer, Editor.FontStyle); \
  728. KEY(Integer, Editor.FontCharset); \
  729. KEY(Bool, Editor.WordWrap); \
  730. KEY(String, Editor.FindText); \
  731. KEY(String, Editor.ReplaceText); \
  732. KEY(Bool, Editor.FindMatchCase); \
  733. KEY(Bool, Editor.FindWholeWord); \
  734. KEY(Bool, Editor.FindDown); \
  735. KEY(Integer, Editor.TabSize); \
  736. KEY(Integer, Editor.MaxEditors); \
  737. KEY(Integer, Editor.EarlyClose); \
  738. KEY(Bool, Editor.SDIShellEditor); \
  739. KEY(String, Editor.WindowParams); \
  740. ); \
  741. BLOCK("Interface\\QueueView", CANCREATE, \
  742. KEY(Integer, QueueView.Height); \
  743. KEY(String, QueueView.Layout); \
  744. KEY(Integer, QueueView.Show); \
  745. KEY(Integer, QueueView.LastHideShow); \
  746. KEY(Bool, QueueView.ToolBar); \
  747. ); \
  748. BLOCK("Interface\\Updates", CANCREATE, \
  749. KEY(Integer, FUpdates.Period); \
  750. KEY(DateTime, FUpdates.LastCheck); \
  751. KEY(Integer, FUpdates.HaveResults); \
  752. KEY(Integer, FUpdates.ShownResults); \
  753. KEY(Integer, FUpdates.BetaVersions); \
  754. KEY(Integer, FUpdates.ConnectionType); \
  755. KEY(String, FUpdates.ProxyHost); \
  756. KEY(Integer, FUpdates.ProxyPort); \
  757. KEY(Integer, FUpdates.Results.ForVersion); \
  758. KEY(Integer, FUpdates.Results.Version); \
  759. KEY(String, FUpdates.Results.Message); \
  760. KEY(Integer, FUpdates.Results.Critical); \
  761. KEY(String, FUpdates.Results.Release); \
  762. KEY(Bool, FUpdates.Results.Disabled); \
  763. KEY(String, FUpdates.Results.Url); \
  764. KEY(String, FUpdates.Results.UrlButton); \
  765. ); \
  766. BLOCK("Interface\\Explorer", CANCREATE, \
  767. KEY(String, ScpExplorer.ToolbarsLayout); \
  768. KEY(String, ScpExplorer.DirViewParams); \
  769. KEY(String, ScpExplorer.LastLocalTargetDirectory); \
  770. KEY(Bool, ScpExplorer.StatusBar); \
  771. KEY(String, ScpExplorer.WindowParams); \
  772. KEY(Integer, ScpExplorer.ViewStyle); \
  773. KEY(Bool, ScpExplorer.ShowFullAddress); \
  774. KEY(Bool, ScpExplorer.DriveView); \
  775. KEY(Integer, ScpExplorer.DriveViewWidth); \
  776. ); \
  777. BLOCK("Interface\\Commander", CANCREATE, \
  778. KEY(String, ScpCommander.ToolbarsLayout); \
  779. KEY(Integer, ScpCommander.CurrentPanel); \
  780. KEY(Float, ScpCommander.LocalPanelWidth); \
  781. KEY(Bool, ScpCommander.SwappedPanels); \
  782. KEY(Bool, ScpCommander.StatusBar); \
  783. KEY(String, ScpCommander.WindowParams); \
  784. KEYEX(Integer, ScpCommander.NortonLikeMode, ExplorerStyleSelection); \
  785. KEY(Bool, ScpCommander.PreserveLocalDirectory); \
  786. KEY(Bool, ScpCommander.CompareByTime); \
  787. KEY(Bool, ScpCommander.CompareBySize); \
  788. KEY(Bool, ScpCommander.FullRowSelect); \
  789. KEY(Bool, ScpCommander.TreeOnLeft); \
  790. ); \
  791. BLOCK("Interface\\Commander\\LocalPanel", CANCREATE, \
  792. KEY(String, ScpCommander.LocalPanel.DirViewParams); \
  793. KEY(Bool, ScpCommander.LocalPanel.StatusBar); \
  794. KEY(Bool, ScpCommander.LocalPanel.DriveView); \
  795. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeight); \
  796. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidth); \
  797. ); \
  798. BLOCK("Interface\\Commander\\RemotePanel", CANCREATE, \
  799. KEY(String, ScpCommander.RemotePanel.DirViewParams); \
  800. KEY(Bool, ScpCommander.RemotePanel.StatusBar); \
  801. KEY(Bool, ScpCommander.RemotePanel.DriveView); \
  802. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeight); \
  803. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidth); \
  804. ); \
  805. BLOCK("Logging", CANCREATE, \
  806. KEY(Bool, LogWindowOnStartup); \
  807. KEY(String, LogWindowParams); \
  808. ); \
  809. BLOCK("Security", CANCREATE, \
  810. KEYEX(Bool, FUseMasterPassword, UseMasterPassword); \
  811. KEYEX(String,FMasterPasswordVerifier, MasterPasswordVerifier); \
  812. );
  813. //---------------------------------------------------------------------------
  814. void __fastcall TWinConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  815. {
  816. TCustomWinConfiguration::SaveData(Storage, All);
  817. // duplicated from core\configuration.cpp
  818. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(LASTELEM(AnsiString(#NAME)), VAR)
  819. REGCONFIG(true);
  820. #undef KEYEX
  821. if (Storage->OpenSubKey("Bookmarks", true))
  822. {
  823. FBookmarks->Save(Storage, All);
  824. Storage->CloseSubKey();
  825. }
  826. if ((All && !FCustomCommandsDefaults) || FCustomCommandList->Modified)
  827. {
  828. FCustomCommandList->Save(Storage);
  829. }
  830. if ((All || FEditorList->Modified) &&
  831. Storage->OpenSubKey("Interface\\Editor", true, true))
  832. try
  833. {
  834. FEditorList->Save(Storage);
  835. }
  836. __finally
  837. {
  838. Storage->CloseSubKey();
  839. }
  840. }
  841. //---------------------------------------------------------------------------
  842. void __fastcall TWinConfiguration::Load()
  843. {
  844. FLegacyEditor = new TEditorPreferences();
  845. try
  846. {
  847. FLegacyEditor->LegacyDefaults();
  848. TCustomWinConfiguration::Load();
  849. int EditorCount = FEditorList->Count;
  850. if (EditorCount == 0)
  851. {
  852. TEditorPreferences * AlternativeEditor = NULL;
  853. try
  854. {
  855. if (FLegacyEditor->Data->Editor == edInternal)
  856. {
  857. if (!FLegacyEditor->Data->ExternalEditor.IsEmpty())
  858. {
  859. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  860. AlternativeEditor->GetData()->Editor = edExternal;
  861. FLegacyEditor->GetData()->ExternalEditor = "";
  862. }
  863. }
  864. else
  865. {
  866. if (FLegacyEditor->Data->ExternalEditor.IsEmpty())
  867. {
  868. FLegacyEditor->GetData()->Editor = edInternal;
  869. }
  870. else
  871. {
  872. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  873. AlternativeEditor->GetData()->Editor = edInternal;
  874. }
  875. }
  876. }
  877. catch(...)
  878. {
  879. delete AlternativeEditor;
  880. throw;
  881. }
  882. FEditorList->Add(FLegacyEditor);
  883. FLegacyEditor = NULL;
  884. if (AlternativeEditor != NULL)
  885. {
  886. FEditorList->Add(AlternativeEditor);
  887. }
  888. }
  889. }
  890. __finally
  891. {
  892. delete FLegacyEditor;
  893. FLegacyEditor = NULL;
  894. }
  895. if (FUpdates.ConnectionType == -1)
  896. {
  897. FUpdates.ConnectionType = (FUpdates.ProxyHost.IsEmpty() ? ctAuto : ctProxy);
  898. }
  899. AddVersionToHistory(FVersionHistory);
  900. }
  901. //---------------------------------------------------------------------------
  902. void __fastcall TWinConfiguration::LoadData(THierarchicalStorage * Storage)
  903. {
  904. TCustomWinConfiguration::LoadData(Storage);
  905. // duplicated from core\configuration.cpp
  906. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(LASTELEM(AnsiString(#NAME)), VAR)
  907. #pragma warn -eas
  908. REGCONFIG(false);
  909. #pragma warn +eas
  910. #undef KEYEX
  911. if (Storage->OpenSubKey("Bookmarks", false))
  912. {
  913. FBookmarks->Load(Storage);
  914. Storage->CloseSubKey();
  915. }
  916. if (Storage->HasSubKey("CustomCommands"))
  917. {
  918. FCustomCommandList->Load(Storage);
  919. FCustomCommandsDefaults = false;
  920. }
  921. else if (FCustomCommandList->Modified)
  922. {
  923. // can this (=reloading of configuration) even happen?
  924. // if it does, shouldn't we reset default commands?
  925. assert(false);
  926. FCustomCommandList->Clear();
  927. FCustomCommandsDefaults = false;
  928. }
  929. FCustomCommandList->Reset();
  930. if (Storage->OpenSubKey("Interface\\Editor", false, true))
  931. try
  932. {
  933. FEditorList->Clear();
  934. FEditorList->Load(Storage);
  935. }
  936. __finally
  937. {
  938. Storage->CloseSubKey();
  939. }
  940. // load legacy editor configuration
  941. assert(FLegacyEditor != NULL);
  942. if (Storage->OpenSubKey("Interface\\Editor", false, true))
  943. {
  944. try
  945. {
  946. FLegacyEditor->Load(Storage, true);
  947. }
  948. __finally
  949. {
  950. Storage->CloseSubKey();
  951. }
  952. }
  953. }
  954. //---------------------------------------------------------------------------
  955. void __fastcall TWinConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  956. {
  957. TCustomWinConfiguration::LoadAdmin(Storage);
  958. FDisableOpenEdit = Storage->ReadBool("DisableOpenEdit", FDisableOpenEdit);
  959. FDefaultUpdatesPeriod = Storage->ReadInteger("DefaultUpdatesPeriod", FDefaultUpdatesPeriod);
  960. }
  961. //---------------------------------------------------------------------------
  962. void __fastcall TWinConfiguration::ClearTemporaryLoginData()
  963. {
  964. if (!FTemporaryKeyFile.IsEmpty())
  965. {
  966. DeleteFile(FTemporaryKeyFile);
  967. FTemporaryKeyFile = "";
  968. }
  969. }
  970. //---------------------------------------------------------------------------
  971. void __fastcall TWinConfiguration::AddVersionToHistory(AnsiString & VersionHistory)
  972. {
  973. int CurrentVersion = CompoundVersion;
  974. int From = 1;
  975. bool CurrentVersionPresent = false;
  976. while (!CurrentVersionPresent && (From < VersionHistory.Length()))
  977. {
  978. AnsiString VersionInfo = CopyToChars(VersionHistory, From, ";", true);
  979. AnsiString VersionStr = ::CutToChar(VersionInfo, ',', true);
  980. int Version;
  981. if (TryStrToInt(VersionStr, Version) &&
  982. (Version == CurrentVersion))
  983. {
  984. CurrentVersionPresent = true;
  985. }
  986. }
  987. if (!CurrentVersionPresent)
  988. {
  989. AnsiString CurrentVersionInfo =
  990. IntToStr(CurrentVersion) + "," + FileInfoString["ReleaseType"];
  991. AddToList(VersionHistory, CurrentVersionInfo, ';');
  992. }
  993. }
  994. //---------------------------------------------------------------------------
  995. bool __fastcall TWinConfiguration::GetAnyBetaInVersionHistory()
  996. {
  997. int From = 1;
  998. bool AnyBeta = false;
  999. while (!AnyBeta && (From < VersionHistory.Length()))
  1000. {
  1001. AnsiString VersionInfo = CopyToChars(VersionHistory, From, ";", true);
  1002. ::CutToChar(VersionInfo, ',', true);
  1003. AnsiString ReleaseType = ::CutToChar(VersionInfo, ',', true);
  1004. if (AnsiSameText(ReleaseType, "beta"))
  1005. {
  1006. AnyBeta = true;
  1007. }
  1008. }
  1009. return AnyBeta;
  1010. }
  1011. //---------------------------------------------------------------------------
  1012. bool __fastcall TWinConfiguration::GetDDExtInstalled()
  1013. {
  1014. if (FDDExtInstalled < 0)
  1015. {
  1016. if (IsWin64())
  1017. {
  1018. // temporarily consider dragext always present on 64-bit system
  1019. FDDExtInstalled = 1;
  1020. }
  1021. else
  1022. {
  1023. void * DragExtRef;
  1024. int CreateResult =
  1025. CoCreateInstance(CLSID_ShellExtension, NULL,
  1026. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
  1027. &DragExtRef);
  1028. bool Result = (CreateResult == S_OK);
  1029. FDDExtInstalled = (Result ? 1 : 0);
  1030. if (Result)
  1031. {
  1032. reinterpret_cast<IUnknown *>(DragExtRef)->Release();
  1033. CoFreeUnusedLibraries();
  1034. }
  1035. }
  1036. }
  1037. return (FDDExtInstalled > 0);
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. AnsiString __fastcall TWinConfiguration::StronglyRecryptPassword(AnsiString Password, AnsiString Key)
  1041. {
  1042. AnsiString Dummy;
  1043. AnsiString Result;
  1044. if (GetExternalEncryptedPassword(Password, Dummy) ||
  1045. !FUseMasterPassword)
  1046. {
  1047. // already-strongly encrypted
  1048. // or no master password set, so we cannot strongly-encrypt it
  1049. Result = Password;
  1050. }
  1051. else
  1052. {
  1053. Password = TCustomWinConfiguration::DecryptPassword(Password, Key);
  1054. if (!Password.IsEmpty())
  1055. {
  1056. assert(!FPlainMasterPasswordEncrypt.IsEmpty());
  1057. ScramblePassword(Password);
  1058. AES256EncyptWithMAC(Password, FPlainMasterPasswordEncrypt, Result);
  1059. Result = SetExternalEncryptedPassword(Result);
  1060. }
  1061. }
  1062. return Result;
  1063. }
  1064. //---------------------------------------------------------------------------
  1065. AnsiString __fastcall TWinConfiguration::DecryptPassword(AnsiString Password, AnsiString Key)
  1066. {
  1067. AnsiString Result;
  1068. if (GetExternalEncryptedPassword(Password, Result))
  1069. {
  1070. if (FPlainMasterPasswordDecrypt.IsEmpty())
  1071. {
  1072. assert(FOnMasterPasswordPrompt != NULL);
  1073. FOnMasterPasswordPrompt();
  1074. }
  1075. if (!AES256DecryptWithMAC(Result, FPlainMasterPasswordDecrypt, Result) ||
  1076. !UnscramblePassword(Result))
  1077. {
  1078. throw Exception(LoadStr(DECRYPT_PASSWORD_ERROR));
  1079. }
  1080. }
  1081. else
  1082. {
  1083. Result = TCustomWinConfiguration::DecryptPassword(Password, Key);
  1084. }
  1085. return Result;
  1086. }
  1087. //---------------------------------------------------------------------------
  1088. void __fastcall TWinConfiguration::SetMasterPassword(AnsiString value)
  1089. {
  1090. if (FUseMasterPassword && ValidateMasterPassword(value))
  1091. {
  1092. // just store the plain-text version of the password
  1093. FPlainMasterPasswordEncrypt = value;
  1094. FPlainMasterPasswordDecrypt = value;
  1095. }
  1096. else
  1097. {
  1098. AnsiString Verifier;
  1099. AES256CreateVerifier(value, Verifier);
  1100. FMasterPasswordVerifier = StrToHex(Verifier);
  1101. FPlainMasterPasswordEncrypt = value;
  1102. FUseMasterPassword = true;
  1103. try
  1104. {
  1105. RecryptPasswords();
  1106. }
  1107. __finally
  1108. {
  1109. FPlainMasterPasswordDecrypt = value;
  1110. }
  1111. }
  1112. }
  1113. //---------------------------------------------------------------------------
  1114. bool __fastcall TWinConfiguration::ValidateMasterPassword(AnsiString value)
  1115. {
  1116. assert(UseMasterPassword);
  1117. assert(!FMasterPasswordVerifier.IsEmpty());
  1118. return AES256Verify(value, HexToStr(FMasterPasswordVerifier));
  1119. }
  1120. //---------------------------------------------------------------------------
  1121. void __fastcall TWinConfiguration::PurgePassword(AnsiString & Password)
  1122. {
  1123. Password.Unique();
  1124. memset(Password.c_str(), 0, Password.Length());
  1125. Password = "";
  1126. }
  1127. //---------------------------------------------------------------------------
  1128. void __fastcall TWinConfiguration::ClearMasterPassword()
  1129. {
  1130. FMasterPasswordVerifier = "";
  1131. FUseMasterPassword = false;
  1132. PurgePassword(FPlainMasterPasswordEncrypt);
  1133. try
  1134. {
  1135. RecryptPasswords();
  1136. }
  1137. __finally
  1138. {
  1139. PurgePassword(FPlainMasterPasswordDecrypt);
  1140. }
  1141. }
  1142. //---------------------------------------------------------------------------
  1143. void __fastcall TWinConfiguration::AskForMasterPasswordIfNotSet()
  1144. {
  1145. if (FPlainMasterPasswordEncrypt.IsEmpty())
  1146. {
  1147. assert(FOnMasterPasswordPrompt != NULL);
  1148. FOnMasterPasswordPrompt();
  1149. assert(!FPlainMasterPasswordDecrypt.IsEmpty());
  1150. }
  1151. }
  1152. //---------------------------------------------------------------------------
  1153. void __fastcall TWinConfiguration::SetLogWindowOnStartup(bool value)
  1154. {
  1155. SET_CONFIG_PROPERTY(LogWindowOnStartup);
  1156. }
  1157. //---------------------------------------------------------------------------
  1158. void __fastcall TWinConfiguration::SetLogWindowParams(AnsiString value)
  1159. {
  1160. SET_CONFIG_PROPERTY(LogWindowParams);
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. void __fastcall TWinConfiguration::SetDDAllowMove(bool value)
  1164. {
  1165. SET_CONFIG_PROPERTY(DDAllowMove);
  1166. }
  1167. //---------------------------------------------------------------------------
  1168. void __fastcall TWinConfiguration::SetDDAllowMoveInit(bool value)
  1169. {
  1170. SET_CONFIG_PROPERTY(DDAllowMoveInit);
  1171. }
  1172. //---------------------------------------------------------------------------
  1173. void __fastcall TWinConfiguration::SetDDTransferConfirmation(bool value)
  1174. {
  1175. SET_CONFIG_PROPERTY(DDTransferConfirmation);
  1176. }
  1177. //---------------------------------------------------------------------------
  1178. void __fastcall TWinConfiguration::SetDDTemporaryDirectory(AnsiString value)
  1179. {
  1180. SET_CONFIG_PROPERTY(DDTemporaryDirectory);
  1181. }
  1182. //---------------------------------------------------------------------------
  1183. void __fastcall TWinConfiguration::SetDDExtEnabled(bool value)
  1184. {
  1185. SET_CONFIG_PROPERTY(DDExtEnabled);
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
  1189. {
  1190. SET_CONFIG_PROPERTY(DDExtTimeout);
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpace(bool value)
  1194. {
  1195. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpace);
  1196. }
  1197. //---------------------------------------------------------------------------
  1198. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpaceRatio(double value)
  1199. {
  1200. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpaceRatio);
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TWinConfiguration::SetScpExplorer(TScpExplorerConfiguration value)
  1204. {
  1205. SET_CONFIG_PROPERTY(ScpExplorer);
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. void __fastcall TWinConfiguration::SetScpCommander(TScpCommanderConfiguration value)
  1209. {
  1210. SET_CONFIG_PROPERTY(ScpCommander);
  1211. }
  1212. //---------------------------------------------------------------------------
  1213. void __fastcall TWinConfiguration::SetEditor(TEditorConfiguration value)
  1214. {
  1215. SET_CONFIG_PROPERTY(Editor);
  1216. }
  1217. //---------------------------------------------------------------------------
  1218. void __fastcall TWinConfiguration::SetQueueView(TQueueViewConfiguration value)
  1219. {
  1220. SET_CONFIG_PROPERTY(QueueView);
  1221. }
  1222. //---------------------------------------------------------------------------
  1223. TUpdatesConfiguration __fastcall TWinConfiguration::GetUpdates()
  1224. {
  1225. TUpdatesConfiguration Result;
  1226. {
  1227. TGuard Guard(FCriticalSection);
  1228. Result = FUpdates;
  1229. }
  1230. return Result;
  1231. }
  1232. //---------------------------------------------------------------------------
  1233. void __fastcall TWinConfiguration::SetUpdates(TUpdatesConfiguration value)
  1234. {
  1235. TGuard Guard(FCriticalSection);
  1236. // do not use SET_CONFIG_PROPERTY to avoid OnChange handler call (not synchronized)
  1237. FUpdates = value;
  1238. }
  1239. //---------------------------------------------------------------------------
  1240. void __fastcall TWinConfiguration::SetVersionHistory(AnsiString value)
  1241. {
  1242. SET_CONFIG_PROPERTY(VersionHistory);
  1243. }
  1244. //---------------------------------------------------------------------------
  1245. void __fastcall TWinConfiguration::SetDeleteToRecycleBin(bool value)
  1246. {
  1247. SET_CONFIG_PROPERTY(DeleteToRecycleBin);
  1248. }
  1249. //---------------------------------------------------------------------------
  1250. void __fastcall TWinConfiguration::SetSelectDirectories(bool value)
  1251. {
  1252. SET_CONFIG_PROPERTY(SelectDirectories);
  1253. }
  1254. //---------------------------------------------------------------------------
  1255. void __fastcall TWinConfiguration::SetShowHiddenFiles(bool value)
  1256. {
  1257. SET_CONFIG_PROPERTY(ShowHiddenFiles);
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. void __fastcall TWinConfiguration::SetShowInaccesibleDirectories(bool value)
  1261. {
  1262. SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. void __fastcall TWinConfiguration::SetConfirmTransferring(bool value)
  1266. {
  1267. SET_CONFIG_PROPERTY(ConfirmTransferring);
  1268. }
  1269. //---------------------------------------------------------------------------
  1270. void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
  1271. {
  1272. SET_CONFIG_PROPERTY(ConfirmDeleting);
  1273. }
  1274. //---------------------------------------------------------------------------
  1275. void __fastcall TWinConfiguration::SetConfirmRecycling(bool value)
  1276. {
  1277. SET_CONFIG_PROPERTY(ConfirmRecycling);
  1278. }
  1279. //---------------------------------------------------------------------------
  1280. void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
  1281. {
  1282. SET_CONFIG_PROPERTY(UseLocationProfiles);
  1283. }
  1284. //---------------------------------------------------------------------------
  1285. void __fastcall TWinConfiguration::SetUseSharedBookmarks(bool value)
  1286. {
  1287. SET_CONFIG_PROPERTY(UseSharedBookmarks);
  1288. }
  1289. //---------------------------------------------------------------------------
  1290. void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
  1291. {
  1292. SET_CONFIG_PROPERTY(ConfirmClosingSession);
  1293. }
  1294. //---------------------------------------------------------------------------
  1295. void __fastcall TWinConfiguration::SetDoubleClickAction(TDoubleClickAction value)
  1296. {
  1297. SET_CONFIG_PROPERTY(DoubleClickAction);
  1298. }
  1299. //---------------------------------------------------------------------------
  1300. void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
  1301. {
  1302. SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
  1303. }
  1304. //---------------------------------------------------------------------------
  1305. void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
  1306. {
  1307. SET_CONFIG_PROPERTY(DimmHiddenFiles);
  1308. }
  1309. //---------------------------------------------------------------------------
  1310. void __fastcall TWinConfiguration::SetRenameWholeName(bool value)
  1311. {
  1312. SET_CONFIG_PROPERTY(RenameWholeName);
  1313. }
  1314. //---------------------------------------------------------------------------
  1315. void __fastcall TWinConfiguration::SetAutoStartSession(AnsiString value)
  1316. {
  1317. SET_CONFIG_PROPERTY(AutoStartSession);
  1318. }
  1319. //---------------------------------------------------------------------------
  1320. void __fastcall TWinConfiguration::SetExpertMode(bool value)
  1321. {
  1322. SET_CONFIG_PROPERTY(ExpertMode);
  1323. }
  1324. //---------------------------------------------------------------------------
  1325. void __fastcall TWinConfiguration::SetDefaultDirIsHome(bool value)
  1326. {
  1327. SET_CONFIG_PROPERTY(DefaultDirIsHome);
  1328. }
  1329. //---------------------------------------------------------------------------
  1330. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendSession(bool value)
  1331. {
  1332. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendSession);
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendPath(bool value)
  1336. {
  1337. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendPath);
  1338. }
  1339. //---------------------------------------------------------------------------
  1340. void __fastcall TWinConfiguration::SetTemporaryDirectoryCleanup(bool value)
  1341. {
  1342. SET_CONFIG_PROPERTY(TemporaryDirectoryCleanup);
  1343. }
  1344. //---------------------------------------------------------------------------
  1345. void __fastcall TWinConfiguration::SetConfirmTemporaryDirectoryCleanup(bool value)
  1346. {
  1347. SET_CONFIG_PROPERTY(ConfirmTemporaryDirectoryCleanup);
  1348. }
  1349. //---------------------------------------------------------------------------
  1350. void __fastcall TWinConfiguration::SetPreservePanelState(bool value)
  1351. {
  1352. SET_CONFIG_PROPERTY(PreservePanelState);
  1353. }
  1354. //---------------------------------------------------------------------------
  1355. void __fastcall TWinConfiguration::SetTheme(AnsiString value)
  1356. {
  1357. SET_CONFIG_PROPERTY_EX(Theme, ConfigureInterface());
  1358. }
  1359. //---------------------------------------------------------------------------
  1360. void __fastcall TWinConfiguration::SetPathInCaption(TPathInCaption value)
  1361. {
  1362. SET_CONFIG_PROPERTY(PathInCaption);
  1363. }
  1364. //---------------------------------------------------------------------------
  1365. void __fastcall TWinConfiguration::SetMinimizeToTray(bool value)
  1366. {
  1367. SET_CONFIG_PROPERTY(MinimizeToTray);
  1368. }
  1369. //---------------------------------------------------------------------------
  1370. void __fastcall TWinConfiguration::SetBalloonNotifications(bool value)
  1371. {
  1372. SET_CONFIG_PROPERTY(BalloonNotifications);
  1373. }
  1374. //---------------------------------------------------------------------------
  1375. void __fastcall TWinConfiguration::SetNotificationsTimeout(unsigned int value)
  1376. {
  1377. SET_CONFIG_PROPERTY(NotificationsTimeout);
  1378. }
  1379. //---------------------------------------------------------------------------
  1380. void __fastcall TWinConfiguration::SetNotificationsStickTime(unsigned int value)
  1381. {
  1382. SET_CONFIG_PROPERTY(NotificationsStickTime);
  1383. }
  1384. //---------------------------------------------------------------------------
  1385. void __fastcall TWinConfiguration::SetCopyParamAutoSelectNotice(bool value)
  1386. {
  1387. SET_CONFIG_PROPERTY(CopyParamAutoSelectNotice);
  1388. }
  1389. //---------------------------------------------------------------------------
  1390. void __fastcall TWinConfiguration::SetSessionToolbarAutoShown(bool value)
  1391. {
  1392. SET_CONFIG_PROPERTY(SessionToolbarAutoShown);
  1393. }
  1394. //---------------------------------------------------------------------------
  1395. void __fastcall TWinConfiguration::SetLockToolbars(bool value)
  1396. {
  1397. SET_CONFIG_PROPERTY(LockToolbars);
  1398. }
  1399. //---------------------------------------------------------------------------
  1400. void __fastcall TWinConfiguration::SetAutoOpenInPutty(bool value)
  1401. {
  1402. SET_CONFIG_PROPERTY(AutoOpenInPutty);
  1403. }
  1404. //---------------------------------------------------------------------------
  1405. void __fastcall TWinConfiguration::SetCustomCommandList(TCustomCommandList * value)
  1406. {
  1407. assert(FCustomCommandList);
  1408. if (!FCustomCommandList->Equals(value))
  1409. {
  1410. FCustomCommandList->Assign(value);
  1411. FCustomCommandsDefaults = false;
  1412. }
  1413. }
  1414. //---------------------------------------------------------------------------
  1415. void __fastcall TWinConfiguration::SetBookmarks(AnsiString Key,
  1416. TBookmarkList * value)
  1417. {
  1418. FBookmarks->Bookmarks[Key] = value;
  1419. Changed();
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(AnsiString Key)
  1423. {
  1424. return FBookmarks->Bookmarks[Key];
  1425. }
  1426. //---------------------------------------------------------------------------
  1427. void __fastcall TWinConfiguration::SetSharedBookmarks(TBookmarkList * value)
  1428. {
  1429. FBookmarks->SharedBookmarks = value;
  1430. Changed();
  1431. }
  1432. //---------------------------------------------------------------------------
  1433. TBookmarkList * __fastcall TWinConfiguration::GetSharedBookmarks()
  1434. {
  1435. return FBookmarks->SharedBookmarks;
  1436. }
  1437. //---------------------------------------------------------------------------
  1438. AnsiString __fastcall TWinConfiguration::GetDefaultKeyFile()
  1439. {
  1440. return (!FDefaultKeyFile.IsEmpty() ? FDefaultKeyFile : FTemporaryKeyFile);
  1441. }
  1442. //---------------------------------------------------------------------------
  1443. void __fastcall TWinConfiguration::SetLastMonitor(int value)
  1444. {
  1445. ::SetLastMonitor(value);
  1446. }
  1447. //---------------------------------------------------------------------------
  1448. int __fastcall TWinConfiguration::GetLastMonitor()
  1449. {
  1450. return ::GetLastMonitor();
  1451. }
  1452. //---------------------------------------------------------------------------
  1453. AnsiString __fastcall TWinConfiguration::TemporaryDir(bool Mask)
  1454. {
  1455. return UniqTempDir(ExpandFileName(ExpandEnvironmentVariables(DDTemporaryDirectory)),
  1456. "scp", Mask);
  1457. }
  1458. //---------------------------------------------------------------------------
  1459. TStrings * __fastcall TWinConfiguration::FindTemporaryFolders()
  1460. {
  1461. TStrings * Result = new TStringList();
  1462. try
  1463. {
  1464. TSearchRec SRec;
  1465. AnsiString Mask = TemporaryDir(true);
  1466. AnsiString Directory = ExtractFilePath(Mask);
  1467. if (FindFirst(Mask, faDirectory, SRec) == 0)
  1468. {
  1469. do
  1470. {
  1471. if (FLAGSET(SRec.Attr, faDirectory))
  1472. {
  1473. Result->Add(Directory + SRec.Name);
  1474. }
  1475. }
  1476. while (FindNext(SRec) == 0);
  1477. }
  1478. if (Result->Count == 0)
  1479. {
  1480. delete Result;
  1481. Result = NULL;
  1482. }
  1483. }
  1484. catch(...)
  1485. {
  1486. delete Result;
  1487. throw;
  1488. }
  1489. return Result;
  1490. }
  1491. //---------------------------------------------------------------------------
  1492. void __fastcall TWinConfiguration::CleanupTemporaryFolders(TStrings * Folders)
  1493. {
  1494. AnsiString ErrorList;
  1495. TStrings * F;
  1496. if (Folders == NULL)
  1497. {
  1498. F = FindTemporaryFolders();
  1499. }
  1500. else
  1501. {
  1502. F = Folders;
  1503. }
  1504. if (F != NULL)
  1505. {
  1506. try
  1507. {
  1508. for (int i = 0; i < F->Count; i++)
  1509. {
  1510. if (!DeleteDirectory(F->Strings[i]))
  1511. {
  1512. if (!ErrorList.IsEmpty())
  1513. {
  1514. ErrorList += "\n";
  1515. }
  1516. ErrorList += F->Strings[i];
  1517. }
  1518. }
  1519. }
  1520. __finally
  1521. {
  1522. if (Folders == NULL)
  1523. {
  1524. delete F;
  1525. }
  1526. }
  1527. if (!ErrorList.IsEmpty())
  1528. {
  1529. throw ExtException(LoadStr(CLEANUP_TEMP_ERROR), ErrorList);
  1530. }
  1531. }
  1532. }
  1533. //---------------------------------------------------------------------------
  1534. //---------------------------------------------------------------------------
  1535. #pragma warn -inl
  1536. //---------------------------------------------------------------------------
  1537. class TAsInheritedReader : public TReader
  1538. {
  1539. public:
  1540. __fastcall TAsInheritedReader(TStream * Stream, int BufSize) :
  1541. TReader(Stream, BufSize)
  1542. {
  1543. OnAncestorNotFound = AncestorNotFound;
  1544. }
  1545. virtual void __fastcall ReadPrefix(TFilerFlags & Flags, int & AChildPos)
  1546. {
  1547. TReader::ReadPrefix(Flags, AChildPos);
  1548. Flags << ffInherited;
  1549. }
  1550. void __fastcall AncestorNotFound(TReader * Reader,
  1551. const AnsiString ComponentName, TMetaClass * ComponentClass,
  1552. TComponent *& Component)
  1553. {
  1554. assert(!Component);
  1555. if (ComponentName.IsEmpty())
  1556. {
  1557. for (int Index = 0; Index < LookupRoot->ComponentCount; Index++)
  1558. {
  1559. Component = LookupRoot->Components[Index];
  1560. if (Component->Name.IsEmpty())
  1561. {
  1562. return;
  1563. }
  1564. }
  1565. Component = NULL;
  1566. }
  1567. }
  1568. };
  1569. //---------------------------------------------------------------------------
  1570. #pragma warn .inl
  1571. //---------------------------------------------------------------------------
  1572. bool __fastcall TWinConfiguration::InternalReloadComponentRes(const AnsiString ResName,
  1573. HANDLE HInst, TComponent * Instance)
  1574. {
  1575. HANDLE HRsrc;
  1576. bool Result;
  1577. if (!HInst)
  1578. {
  1579. HInst = HInstance;
  1580. }
  1581. HRsrc = FindResource(HInst, ResName.c_str(), RT_RCDATA);
  1582. Result = (HRsrc != 0);
  1583. if (Result)
  1584. {
  1585. TResourceStream * ResStream = new TResourceStream(
  1586. reinterpret_cast<int>(HInst), ResName, RT_RCDATA);
  1587. try
  1588. {
  1589. TReader * Reader;
  1590. Reader = new TAsInheritedReader(ResStream, 4096);
  1591. try
  1592. {
  1593. /*Instance =*/ Reader->ReadRootComponent(Instance);
  1594. }
  1595. __finally
  1596. {
  1597. delete Reader;
  1598. }
  1599. }
  1600. __finally
  1601. {
  1602. delete ResStream;
  1603. }
  1604. }
  1605. return Result;
  1606. }
  1607. //---------------------------------------------------------------------------
  1608. bool __fastcall TWinConfiguration::InitComponent(TComponent * Instance,
  1609. TClass RootAncestor, TClass ClassType)
  1610. {
  1611. bool Result = false;
  1612. if ((ClassType != __classid(TComponent)) && (ClassType != RootAncestor))
  1613. {
  1614. if (InitComponent(Instance, RootAncestor, ClassType->ClassParent()))
  1615. {
  1616. Result = true;
  1617. }
  1618. if (InternalReloadComponentRes(ClassType->ClassName(),
  1619. reinterpret_cast<HANDLE>(FindResourceHInstance(FindClassHInstance(ClassType))),
  1620. Instance))
  1621. {
  1622. Result = true;
  1623. }
  1624. }
  1625. return Result;
  1626. }
  1627. //---------------------------------------------------------------------------
  1628. LCID __fastcall TWinConfiguration::GetLocale()
  1629. {
  1630. if (!FLocale)
  1631. {
  1632. AnsiString ResourceModule = ::GetResourceModule(ModuleFileName().c_str());
  1633. if (!ResourceModule.IsEmpty())
  1634. {
  1635. AnsiString ResourceExt = ExtractFileExt(ResourceModule).UpperCase();
  1636. ResourceExt.Delete(1, 1);
  1637. TLanguages * Langs = LanguagesDEPF();
  1638. int Index, Count;
  1639. Count = Langs->Count;
  1640. Index = 0;
  1641. while ((Index < Count) && !FLocale)
  1642. {
  1643. if (Langs->Ext[Index] == ResourceExt)
  1644. {
  1645. FLocale = Langs->LocaleID[Index];
  1646. }
  1647. else if (Langs->Ext[Index].SubString(1, 2) == ResourceExt)
  1648. {
  1649. FLocale = MAKELANGID(PRIMARYLANGID(Langs->LocaleID[Index]),
  1650. SUBLANG_DEFAULT);
  1651. }
  1652. Index++;
  1653. }
  1654. }
  1655. }
  1656. return TCustomWinConfiguration::GetLocale();
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. HINSTANCE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
  1660. AnsiString * FileName)
  1661. {
  1662. AnsiString FileNameStorage;
  1663. if (FileName == NULL)
  1664. {
  1665. FileName = &FileNameStorage;
  1666. }
  1667. HINSTANCE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
  1668. if (Instance != NULL)
  1669. {
  1670. try
  1671. {
  1672. CheckTranslationVersion(*FileName, false);
  1673. }
  1674. catch(...)
  1675. {
  1676. FreeResourceModule(Instance);
  1677. throw;
  1678. }
  1679. }
  1680. return Instance;
  1681. }
  1682. //---------------------------------------------------------------------------
  1683. void __fastcall TWinConfiguration::SetResourceModule(HINSTANCE Instance)
  1684. {
  1685. TCustomWinConfiguration::SetResourceModule(Instance);
  1686. Busy(true);
  1687. try
  1688. {
  1689. int Count;
  1690. AnsiString OrigName;
  1691. int OrigLeft;
  1692. int OrigTop;
  1693. TForm * Form;
  1694. Count = Screen->FormCount;
  1695. for (int Index = 0; Index < Count; Index++)
  1696. {
  1697. Form = Screen->Forms[Index];
  1698. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 0, 1);
  1699. }
  1700. ConfigureInterface();
  1701. for (int Index = 0; Index < Count; Index++)
  1702. {
  1703. Form = Screen->Forms[Index];
  1704. TComponent * Component;
  1705. for (int Index = 0; Index < Form->ComponentCount; Index++)
  1706. {
  1707. Component = Form->Components[Index];
  1708. if (dynamic_cast<TFrame*>(Component))
  1709. {
  1710. OrigName = Component->Name;
  1711. InitComponent(Component, __classid(TFrame), Component->ClassType());
  1712. Component->Name = OrigName;
  1713. }
  1714. }
  1715. OrigLeft = Form->Left;
  1716. OrigTop = Form->Top;
  1717. OrigName = Form->Name;
  1718. InitComponent(Form, __classid(TForm), Form->ClassType());
  1719. Form->Name = OrigName;
  1720. Form->Position = poDesigned;
  1721. Form->Left = OrigLeft;
  1722. Form->Top = OrigTop;
  1723. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 1, 1);
  1724. }
  1725. TDataModule * DataModule;
  1726. Count = Screen->DataModuleCount;
  1727. for (int Index = 0; Index < Count; Index++)
  1728. {
  1729. DataModule = Screen->DataModules[Index];
  1730. OrigName = DataModule->Name;
  1731. InitComponent(DataModule, __classid(TDataModule), DataModule->ClassType());
  1732. DataModule->Name = OrigName;
  1733. }
  1734. }
  1735. __finally
  1736. {
  1737. Busy(false);
  1738. }
  1739. }
  1740. //---------------------------------------------------------------------------
  1741. void __fastcall TWinConfiguration::CheckTranslationVersion(const AnsiString FileName,
  1742. bool InternalLocaleOnError)
  1743. {
  1744. AnsiString TranslationProductVersion = GetFileProductVersion(FileName);
  1745. AnsiString TranslationProductName = GetFileProductName(FileName);
  1746. if ((ProductName != TranslationProductName) ||
  1747. (ProductVersion != TranslationProductVersion))
  1748. {
  1749. if (InternalLocaleOnError)
  1750. {
  1751. LocaleSafe = InternalLocale();
  1752. }
  1753. if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
  1754. {
  1755. throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
  1756. }
  1757. else
  1758. {
  1759. throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
  1760. (FileName, TranslationProductName, TranslationProductVersion)));
  1761. }
  1762. }
  1763. }
  1764. //---------------------------------------------------------------------------
  1765. void __fastcall TWinConfiguration::CheckDefaultTranslation()
  1766. {
  1767. if (!FInvalidDefaultTranslationMessage.IsEmpty())
  1768. {
  1769. MoreMessageDialog(FMTLOAD(INVALID_DEFAULT_TRANSLATION,
  1770. (FInvalidDefaultTranslationMessage)), NULL, qtWarning, qaOK, HELP_NONE);
  1771. }
  1772. }
  1773. //---------------------------------------------------------------------------
  1774. const TEditorPreferences * __fastcall TWinConfiguration::DefaultEditorForFile(
  1775. const AnsiString FileName, bool Local, const TFileMasks::TParams & MaskParams)
  1776. {
  1777. return FEditorList->Find(FileName, Local, MaskParams);
  1778. }
  1779. //---------------------------------------------------------------------------
  1780. const TEditorList * __fastcall TWinConfiguration::GetEditorList()
  1781. {
  1782. return FEditorList;
  1783. }
  1784. //---------------------------------------------------------------------------
  1785. void __fastcall TWinConfiguration::SetEditorList(const TEditorList * value)
  1786. {
  1787. if (!(*FEditorList == *value))
  1788. {
  1789. *FEditorList = *value;
  1790. Changed();
  1791. }
  1792. }
  1793. //---------------------------------------------------------------------------
  1794. //---------------------------------------------------------------------------
  1795. __fastcall TCustomCommandType::TCustomCommandType() :
  1796. FParams(0), FShortCut(0)
  1797. {
  1798. }
  1799. //---------------------------------------------------------------------------
  1800. __fastcall TCustomCommandType::TCustomCommandType(const TCustomCommandType & Other) :
  1801. FName(Other.FName),
  1802. FCommand(Other.FCommand),
  1803. FParams(Other.FParams),
  1804. FShortCut(Other.FShortCut)
  1805. {
  1806. }
  1807. //---------------------------------------------------------------------------
  1808. TCustomCommandType & TCustomCommandType::operator=(const TCustomCommandType & Other)
  1809. {
  1810. FName = Other.FName;
  1811. FCommand = Other.FCommand;
  1812. FParams = Other.FParams;
  1813. FShortCut = Other.FShortCut;
  1814. return *this;
  1815. }
  1816. //---------------------------------------------------------------------------
  1817. bool __fastcall TCustomCommandType::Equals(const TCustomCommandType * Other) const
  1818. {
  1819. return
  1820. (FName == Other->FName) &&
  1821. (FCommand == Other->FCommand) &&
  1822. (FParams == Other->FParams) &&
  1823. (FShortCut == Other->FShortCut);
  1824. }
  1825. //---------------------------------------------------------------------------
  1826. //---------------------------------------------------------------------------
  1827. __fastcall TCustomCommandList::TCustomCommandList()
  1828. {
  1829. FCommands = new TList();
  1830. FModified = false;
  1831. }
  1832. //---------------------------------------------------------------------------
  1833. __fastcall TCustomCommandList::~TCustomCommandList()
  1834. {
  1835. Clear();
  1836. delete FCommands;
  1837. }
  1838. //---------------------------------------------------------------------------
  1839. void __fastcall TCustomCommandList::Reset()
  1840. {
  1841. FModified = false;
  1842. }
  1843. //---------------------------------------------------------------------------
  1844. void __fastcall TCustomCommandList::Modify()
  1845. {
  1846. FModified = true;
  1847. }
  1848. //---------------------------------------------------------------------------
  1849. void __fastcall TCustomCommandList::Load(THierarchicalStorage * Storage)
  1850. {
  1851. Clear();
  1852. if (Storage->OpenSubKey("CustomCommands", false))
  1853. {
  1854. TStrings * Names = new TStringList();
  1855. try
  1856. {
  1857. Storage->ReadValues(Names, true);
  1858. for (int Index = 0; Index < Names->Count; Index++)
  1859. {
  1860. TCustomCommandType * Command = new TCustomCommandType();
  1861. Command->Name = Names->Names[Index];
  1862. Command->Command = Names->Values[Names->Names[Index]];
  1863. FCommands->Add(Command);
  1864. }
  1865. Storage->CloseSubKey();
  1866. }
  1867. __finally
  1868. {
  1869. delete Names;
  1870. }
  1871. }
  1872. if (Storage->OpenSubKey("CustomCommandsParams", false))
  1873. {
  1874. for (int Index = 0; Index < FCommands->Count; Index++)
  1875. {
  1876. TCustomCommandType * Command = GetCommand(Index);
  1877. Command->Params = Storage->ReadInteger(Command->Name, Command->Params);
  1878. }
  1879. Storage->CloseSubKey();
  1880. }
  1881. if (Storage->OpenSubKey("CustomCommandsShortCuts", false))
  1882. {
  1883. for (int Index = 0; Index < FCommands->Count; Index++)
  1884. {
  1885. TCustomCommandType * Command = GetCommand(Index);
  1886. Command->ShortCut = (Word)Storage->ReadInteger(Command->Name, Command->ShortCut);
  1887. }
  1888. Storage->CloseSubKey();
  1889. }
  1890. Reset();
  1891. }
  1892. //---------------------------------------------------------------------------
  1893. void __fastcall TCustomCommandList::Save(THierarchicalStorage * Storage)
  1894. {
  1895. if (Storage->OpenSubKey("CustomCommands", true))
  1896. {
  1897. Storage->ClearValues();
  1898. for (int Index = 0; Index < FCommands->Count; Index++)
  1899. {
  1900. const TCustomCommandType * Command = Commands[Index];
  1901. Storage->WriteString(Command->Name, Command->Command);
  1902. }
  1903. Storage->CloseSubKey();
  1904. }
  1905. if (Storage->OpenSubKey("CustomCommandsParams", true))
  1906. {
  1907. Storage->ClearValues();
  1908. for (int Index = 0; Index < FCommands->Count; Index++)
  1909. {
  1910. const TCustomCommandType * Command = Commands[Index];
  1911. Storage->WriteInteger(Command->Name, Command->Params);
  1912. }
  1913. Storage->CloseSubKey();
  1914. }
  1915. if (Storage->OpenSubKey("CustomCommandsShortCuts", true))
  1916. {
  1917. Storage->ClearValues();
  1918. for (int Index = 0; Index < FCommands->Count; Index++)
  1919. {
  1920. const TCustomCommandType * Command = Commands[Index];
  1921. if (Command->ShortCut != 0)
  1922. {
  1923. Storage->WriteInteger(Command->Name, Command->ShortCut);
  1924. }
  1925. }
  1926. Storage->CloseSubKey();
  1927. }
  1928. }
  1929. //---------------------------------------------------------------------------
  1930. void __fastcall TCustomCommandList::Clear()
  1931. {
  1932. for (int Index = 0; Index < FCommands->Count; Index++)
  1933. {
  1934. delete Commands[Index];
  1935. }
  1936. FCommands->Clear();
  1937. }
  1938. //---------------------------------------------------------------------------
  1939. void __fastcall TCustomCommandList::Add(const AnsiString Name,
  1940. const AnsiString ACommand, int Params)
  1941. {
  1942. TCustomCommandType * Command = new TCustomCommandType();
  1943. Command->Name = Name;
  1944. Command->Command = ACommand;
  1945. Command->Params = Params;
  1946. Add(Command);
  1947. }
  1948. //---------------------------------------------------------------------------
  1949. void __fastcall TCustomCommandList::Add(TCustomCommandType * Command)
  1950. {
  1951. Insert(Count, Command);
  1952. }
  1953. //---------------------------------------------------------------------------
  1954. void __fastcall TCustomCommandList::Insert(int Index, TCustomCommandType * Command)
  1955. {
  1956. FCommands->Insert(Index, Command);
  1957. Modify();
  1958. }
  1959. //---------------------------------------------------------------------------
  1960. void __fastcall TCustomCommandList::Change(int Index, TCustomCommandType * ACommand)
  1961. {
  1962. TCustomCommandType * Command = GetCommand(Index);
  1963. if (!Command->Equals(ACommand))
  1964. {
  1965. delete Command;
  1966. FCommands->Items[Index] = ACommand;
  1967. Modify();
  1968. }
  1969. else
  1970. {
  1971. delete ACommand;
  1972. }
  1973. }
  1974. //---------------------------------------------------------------------------
  1975. void __fastcall TCustomCommandList::Move(int CurIndex, int NewIndex)
  1976. {
  1977. if (CurIndex != NewIndex)
  1978. {
  1979. FCommands->Move(CurIndex, NewIndex);
  1980. Modify();
  1981. }
  1982. }
  1983. //---------------------------------------------------------------------------
  1984. void __fastcall TCustomCommandList::Delete(int Index)
  1985. {
  1986. assert((Index >= 0) && (Index < Count));
  1987. delete GetCommand(Index);
  1988. FCommands->Delete(Index);
  1989. Modify();
  1990. }
  1991. //---------------------------------------------------------------------------
  1992. int __fastcall TCustomCommandList::GetCount() const
  1993. {
  1994. return FCommands->Count;
  1995. }
  1996. //---------------------------------------------------------------------------
  1997. const TCustomCommandType * __fastcall TCustomCommandList::GetConstCommand(int Index) const
  1998. {
  1999. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2000. }
  2001. //---------------------------------------------------------------------------
  2002. TCustomCommandType * __fastcall TCustomCommandList::GetCommand(int Index)
  2003. {
  2004. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2005. }
  2006. //---------------------------------------------------------------------------
  2007. bool __fastcall TCustomCommandList::Equals(const TCustomCommandList * Other) const
  2008. {
  2009. bool Result = (Count == Other->Count);
  2010. for (int Index = 0; Result && (Index < Count); Index++)
  2011. {
  2012. Result = Commands[Index]->Equals(Other->Commands[Index]);
  2013. }
  2014. return Result;
  2015. }
  2016. //---------------------------------------------------------------------------
  2017. void __fastcall TCustomCommandList::Assign(const TCustomCommandList * Other)
  2018. {
  2019. Clear();
  2020. for (int Index = 0; Index < Other->Count; Index++)
  2021. {
  2022. Add(new TCustomCommandType(*Other->Commands[Index]));
  2023. }
  2024. // there should be comparison of with the assigned list, be we rely on caller
  2025. // to do it instead (TGUIConfiguration::SetCopyParamList)
  2026. Modify();
  2027. }
  2028. //---------------------------------------------------------------------------
  2029. const TCustomCommandType * TCustomCommandList::Find(const AnsiString Name) const
  2030. {
  2031. for (int Index = 0; Index < FCommands->Count; Index++)
  2032. {
  2033. if (Commands[Index]->Name == Name)
  2034. {
  2035. return Commands[Index];
  2036. }
  2037. }
  2038. return NULL;
  2039. }
  2040. //---------------------------------------------------------------------------
  2041. const TCustomCommandType * TCustomCommandList::Find(TShortCut ShortCut) const
  2042. {
  2043. for (int Index = 0; Index < FCommands->Count; Index++)
  2044. {
  2045. if (Commands[Index]->ShortCut == ShortCut)
  2046. {
  2047. return Commands[Index];
  2048. }
  2049. }
  2050. return NULL;
  2051. }
  2052. //---------------------------------------------------------------------------
  2053. void __fastcall TCustomCommandList::ShortCuts(TShortCuts & ShortCuts) const
  2054. {
  2055. for (int Index = 0; Index < FCommands->Count; Index++)
  2056. {
  2057. const TCustomCommandType * Command = Commands[Index];
  2058. if (Command->ShortCut != 0)
  2059. {
  2060. ShortCuts.Add(Command->ShortCut);
  2061. }
  2062. }
  2063. }