WinConfiguration.cpp 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124
  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 = nlOn;
  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. bool Result;
  1025. Result = (CoCreateInstance(CLSID_ShellExtension, NULL,
  1026. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
  1027. &DragExtRef) == S_OK);
  1028. FDDExtInstalled = (Result ? 1 : 0);
  1029. if (Result)
  1030. {
  1031. reinterpret_cast<IUnknown *>(DragExtRef)->Release();
  1032. CoFreeUnusedLibraries();
  1033. }
  1034. }
  1035. }
  1036. return (FDDExtInstalled > 0);
  1037. }
  1038. //---------------------------------------------------------------------------
  1039. AnsiString __fastcall TWinConfiguration::StronglyRecryptPassword(AnsiString Password, AnsiString Key)
  1040. {
  1041. AnsiString Dummy;
  1042. AnsiString Result;
  1043. if (GetExternalEncryptedPassword(Password, Dummy) ||
  1044. !FUseMasterPassword)
  1045. {
  1046. // already-strongly encrypted
  1047. // or no master password set, so we cannot strongly-encrypt it
  1048. Result = Password;
  1049. }
  1050. else
  1051. {
  1052. Password = TCustomWinConfiguration::DecryptPassword(Password, Key);
  1053. if (!Password.IsEmpty())
  1054. {
  1055. assert(!FPlainMasterPasswordEncrypt.IsEmpty());
  1056. ScramblePassword(Password);
  1057. AES256EncyptWithMAC(Password, FPlainMasterPasswordEncrypt, Result);
  1058. Result = SetExternalEncryptedPassword(Result);
  1059. }
  1060. }
  1061. return Result;
  1062. }
  1063. //---------------------------------------------------------------------------
  1064. AnsiString __fastcall TWinConfiguration::DecryptPassword(AnsiString Password, AnsiString Key)
  1065. {
  1066. AnsiString Result;
  1067. if (GetExternalEncryptedPassword(Password, Result))
  1068. {
  1069. if (FPlainMasterPasswordDecrypt.IsEmpty())
  1070. {
  1071. assert(FOnMasterPasswordPrompt != NULL);
  1072. FOnMasterPasswordPrompt();
  1073. }
  1074. if (!AES256DecryptWithMAC(Result, FPlainMasterPasswordDecrypt, Result) ||
  1075. !UnscramblePassword(Result))
  1076. {
  1077. throw Exception(LoadStr(DECRYPT_PASSWORD_ERROR));
  1078. }
  1079. }
  1080. else
  1081. {
  1082. Result = TCustomWinConfiguration::DecryptPassword(Password, Key);
  1083. }
  1084. return Result;
  1085. }
  1086. //---------------------------------------------------------------------------
  1087. void __fastcall TWinConfiguration::SetMasterPassword(AnsiString value)
  1088. {
  1089. if (FUseMasterPassword && ValidateMasterPassword(value))
  1090. {
  1091. // just store the plain-text version of the password
  1092. FPlainMasterPasswordEncrypt = value;
  1093. FPlainMasterPasswordDecrypt = value;
  1094. }
  1095. else
  1096. {
  1097. AnsiString Verifier;
  1098. AES256CreateVerifier(value, Verifier);
  1099. FMasterPasswordVerifier = StrToHex(Verifier);
  1100. FPlainMasterPasswordEncrypt = value;
  1101. FUseMasterPassword = true;
  1102. try
  1103. {
  1104. RecryptPasswords();
  1105. }
  1106. __finally
  1107. {
  1108. FPlainMasterPasswordDecrypt = value;
  1109. }
  1110. }
  1111. }
  1112. //---------------------------------------------------------------------------
  1113. bool __fastcall TWinConfiguration::ValidateMasterPassword(AnsiString value)
  1114. {
  1115. assert(UseMasterPassword);
  1116. assert(!FMasterPasswordVerifier.IsEmpty());
  1117. return AES256Verify(value, HexToStr(FMasterPasswordVerifier));
  1118. }
  1119. //---------------------------------------------------------------------------
  1120. void __fastcall TWinConfiguration::PurgePassword(AnsiString & Password)
  1121. {
  1122. Password.Unique();
  1123. memset(Password.c_str(), 0, Password.Length());
  1124. Password = "";
  1125. }
  1126. //---------------------------------------------------------------------------
  1127. void __fastcall TWinConfiguration::ClearMasterPassword()
  1128. {
  1129. FMasterPasswordVerifier = "";
  1130. FUseMasterPassword = false;
  1131. PurgePassword(FPlainMasterPasswordEncrypt);
  1132. try
  1133. {
  1134. RecryptPasswords();
  1135. }
  1136. __finally
  1137. {
  1138. PurgePassword(FPlainMasterPasswordDecrypt);
  1139. }
  1140. }
  1141. //---------------------------------------------------------------------------
  1142. void __fastcall TWinConfiguration::AskForMasterPasswordIfNotSet()
  1143. {
  1144. if (FPlainMasterPasswordEncrypt.IsEmpty())
  1145. {
  1146. assert(FOnMasterPasswordPrompt != NULL);
  1147. FOnMasterPasswordPrompt();
  1148. assert(!FPlainMasterPasswordDecrypt.IsEmpty());
  1149. }
  1150. }
  1151. //---------------------------------------------------------------------------
  1152. void __fastcall TWinConfiguration::SetLogWindowOnStartup(bool value)
  1153. {
  1154. SET_CONFIG_PROPERTY(LogWindowOnStartup);
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TWinConfiguration::SetLogWindowParams(AnsiString value)
  1158. {
  1159. SET_CONFIG_PROPERTY(LogWindowParams);
  1160. }
  1161. //---------------------------------------------------------------------------
  1162. void __fastcall TWinConfiguration::SetDDAllowMove(bool value)
  1163. {
  1164. SET_CONFIG_PROPERTY(DDAllowMove);
  1165. }
  1166. //---------------------------------------------------------------------------
  1167. void __fastcall TWinConfiguration::SetDDAllowMoveInit(bool value)
  1168. {
  1169. SET_CONFIG_PROPERTY(DDAllowMoveInit);
  1170. }
  1171. //---------------------------------------------------------------------------
  1172. void __fastcall TWinConfiguration::SetDDTransferConfirmation(bool value)
  1173. {
  1174. SET_CONFIG_PROPERTY(DDTransferConfirmation);
  1175. }
  1176. //---------------------------------------------------------------------------
  1177. void __fastcall TWinConfiguration::SetDDTemporaryDirectory(AnsiString value)
  1178. {
  1179. SET_CONFIG_PROPERTY(DDTemporaryDirectory);
  1180. }
  1181. //---------------------------------------------------------------------------
  1182. void __fastcall TWinConfiguration::SetDDExtEnabled(bool value)
  1183. {
  1184. SET_CONFIG_PROPERTY(DDExtEnabled);
  1185. }
  1186. //---------------------------------------------------------------------------
  1187. void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
  1188. {
  1189. SET_CONFIG_PROPERTY(DDExtTimeout);
  1190. }
  1191. //---------------------------------------------------------------------------
  1192. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpace(bool value)
  1193. {
  1194. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpace);
  1195. }
  1196. //---------------------------------------------------------------------------
  1197. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpaceRatio(double value)
  1198. {
  1199. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpaceRatio);
  1200. }
  1201. //---------------------------------------------------------------------------
  1202. void __fastcall TWinConfiguration::SetScpExplorer(TScpExplorerConfiguration value)
  1203. {
  1204. SET_CONFIG_PROPERTY(ScpExplorer);
  1205. }
  1206. //---------------------------------------------------------------------------
  1207. void __fastcall TWinConfiguration::SetScpCommander(TScpCommanderConfiguration value)
  1208. {
  1209. SET_CONFIG_PROPERTY(ScpCommander);
  1210. }
  1211. //---------------------------------------------------------------------------
  1212. void __fastcall TWinConfiguration::SetEditor(TEditorConfiguration value)
  1213. {
  1214. SET_CONFIG_PROPERTY(Editor);
  1215. }
  1216. //---------------------------------------------------------------------------
  1217. void __fastcall TWinConfiguration::SetQueueView(TQueueViewConfiguration value)
  1218. {
  1219. SET_CONFIG_PROPERTY(QueueView);
  1220. }
  1221. //---------------------------------------------------------------------------
  1222. TUpdatesConfiguration __fastcall TWinConfiguration::GetUpdates()
  1223. {
  1224. TUpdatesConfiguration Result;
  1225. {
  1226. TGuard Guard(FCriticalSection);
  1227. Result = FUpdates;
  1228. }
  1229. return Result;
  1230. }
  1231. //---------------------------------------------------------------------------
  1232. void __fastcall TWinConfiguration::SetUpdates(TUpdatesConfiguration value)
  1233. {
  1234. TGuard Guard(FCriticalSection);
  1235. // do not use SET_CONFIG_PROPERTY to avoid OnChange handler call (not synchronized)
  1236. FUpdates = value;
  1237. }
  1238. //---------------------------------------------------------------------------
  1239. void __fastcall TWinConfiguration::SetVersionHistory(AnsiString value)
  1240. {
  1241. SET_CONFIG_PROPERTY(VersionHistory);
  1242. }
  1243. //---------------------------------------------------------------------------
  1244. void __fastcall TWinConfiguration::SetDeleteToRecycleBin(bool value)
  1245. {
  1246. SET_CONFIG_PROPERTY(DeleteToRecycleBin);
  1247. }
  1248. //---------------------------------------------------------------------------
  1249. void __fastcall TWinConfiguration::SetSelectDirectories(bool value)
  1250. {
  1251. SET_CONFIG_PROPERTY(SelectDirectories);
  1252. }
  1253. //---------------------------------------------------------------------------
  1254. void __fastcall TWinConfiguration::SetShowHiddenFiles(bool value)
  1255. {
  1256. SET_CONFIG_PROPERTY(ShowHiddenFiles);
  1257. }
  1258. //---------------------------------------------------------------------------
  1259. void __fastcall TWinConfiguration::SetShowInaccesibleDirectories(bool value)
  1260. {
  1261. SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. void __fastcall TWinConfiguration::SetConfirmTransferring(bool value)
  1265. {
  1266. SET_CONFIG_PROPERTY(ConfirmTransferring);
  1267. }
  1268. //---------------------------------------------------------------------------
  1269. void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
  1270. {
  1271. SET_CONFIG_PROPERTY(ConfirmDeleting);
  1272. }
  1273. //---------------------------------------------------------------------------
  1274. void __fastcall TWinConfiguration::SetConfirmRecycling(bool value)
  1275. {
  1276. SET_CONFIG_PROPERTY(ConfirmRecycling);
  1277. }
  1278. //---------------------------------------------------------------------------
  1279. void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
  1280. {
  1281. SET_CONFIG_PROPERTY(UseLocationProfiles);
  1282. }
  1283. //---------------------------------------------------------------------------
  1284. void __fastcall TWinConfiguration::SetUseSharedBookmarks(bool value)
  1285. {
  1286. SET_CONFIG_PROPERTY(UseSharedBookmarks);
  1287. }
  1288. //---------------------------------------------------------------------------
  1289. void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
  1290. {
  1291. SET_CONFIG_PROPERTY(ConfirmClosingSession);
  1292. }
  1293. //---------------------------------------------------------------------------
  1294. void __fastcall TWinConfiguration::SetDoubleClickAction(TDoubleClickAction value)
  1295. {
  1296. SET_CONFIG_PROPERTY(DoubleClickAction);
  1297. }
  1298. //---------------------------------------------------------------------------
  1299. void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
  1300. {
  1301. SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
  1302. }
  1303. //---------------------------------------------------------------------------
  1304. void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
  1305. {
  1306. SET_CONFIG_PROPERTY(DimmHiddenFiles);
  1307. }
  1308. //---------------------------------------------------------------------------
  1309. void __fastcall TWinConfiguration::SetRenameWholeName(bool value)
  1310. {
  1311. SET_CONFIG_PROPERTY(RenameWholeName);
  1312. }
  1313. //---------------------------------------------------------------------------
  1314. void __fastcall TWinConfiguration::SetAutoStartSession(AnsiString value)
  1315. {
  1316. SET_CONFIG_PROPERTY(AutoStartSession);
  1317. }
  1318. //---------------------------------------------------------------------------
  1319. void __fastcall TWinConfiguration::SetExpertMode(bool value)
  1320. {
  1321. SET_CONFIG_PROPERTY(ExpertMode);
  1322. }
  1323. //---------------------------------------------------------------------------
  1324. void __fastcall TWinConfiguration::SetDefaultDirIsHome(bool value)
  1325. {
  1326. SET_CONFIG_PROPERTY(DefaultDirIsHome);
  1327. }
  1328. //---------------------------------------------------------------------------
  1329. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendSession(bool value)
  1330. {
  1331. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendSession);
  1332. }
  1333. //---------------------------------------------------------------------------
  1334. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendPath(bool value)
  1335. {
  1336. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendPath);
  1337. }
  1338. //---------------------------------------------------------------------------
  1339. void __fastcall TWinConfiguration::SetTemporaryDirectoryCleanup(bool value)
  1340. {
  1341. SET_CONFIG_PROPERTY(TemporaryDirectoryCleanup);
  1342. }
  1343. //---------------------------------------------------------------------------
  1344. void __fastcall TWinConfiguration::SetConfirmTemporaryDirectoryCleanup(bool value)
  1345. {
  1346. SET_CONFIG_PROPERTY(ConfirmTemporaryDirectoryCleanup);
  1347. }
  1348. //---------------------------------------------------------------------------
  1349. void __fastcall TWinConfiguration::SetPreservePanelState(bool value)
  1350. {
  1351. SET_CONFIG_PROPERTY(PreservePanelState);
  1352. }
  1353. //---------------------------------------------------------------------------
  1354. void __fastcall TWinConfiguration::SetTheme(AnsiString value)
  1355. {
  1356. SET_CONFIG_PROPERTY_EX(Theme, ConfigureInterface());
  1357. }
  1358. //---------------------------------------------------------------------------
  1359. void __fastcall TWinConfiguration::SetPathInCaption(TPathInCaption value)
  1360. {
  1361. SET_CONFIG_PROPERTY(PathInCaption);
  1362. }
  1363. //---------------------------------------------------------------------------
  1364. void __fastcall TWinConfiguration::SetMinimizeToTray(bool value)
  1365. {
  1366. SET_CONFIG_PROPERTY(MinimizeToTray);
  1367. }
  1368. //---------------------------------------------------------------------------
  1369. void __fastcall TWinConfiguration::SetBalloonNotifications(bool value)
  1370. {
  1371. SET_CONFIG_PROPERTY(BalloonNotifications);
  1372. }
  1373. //---------------------------------------------------------------------------
  1374. void __fastcall TWinConfiguration::SetNotificationsTimeout(unsigned int value)
  1375. {
  1376. SET_CONFIG_PROPERTY(NotificationsTimeout);
  1377. }
  1378. //---------------------------------------------------------------------------
  1379. void __fastcall TWinConfiguration::SetNotificationsStickTime(unsigned int value)
  1380. {
  1381. SET_CONFIG_PROPERTY(NotificationsStickTime);
  1382. }
  1383. //---------------------------------------------------------------------------
  1384. void __fastcall TWinConfiguration::SetCopyParamAutoSelectNotice(bool value)
  1385. {
  1386. SET_CONFIG_PROPERTY(CopyParamAutoSelectNotice);
  1387. }
  1388. //---------------------------------------------------------------------------
  1389. void __fastcall TWinConfiguration::SetSessionToolbarAutoShown(bool value)
  1390. {
  1391. SET_CONFIG_PROPERTY(SessionToolbarAutoShown);
  1392. }
  1393. //---------------------------------------------------------------------------
  1394. void __fastcall TWinConfiguration::SetLockToolbars(bool value)
  1395. {
  1396. SET_CONFIG_PROPERTY(LockToolbars);
  1397. }
  1398. //---------------------------------------------------------------------------
  1399. void __fastcall TWinConfiguration::SetAutoOpenInPutty(bool value)
  1400. {
  1401. SET_CONFIG_PROPERTY(AutoOpenInPutty);
  1402. }
  1403. //---------------------------------------------------------------------------
  1404. void __fastcall TWinConfiguration::SetCustomCommandList(TCustomCommandList * value)
  1405. {
  1406. assert(FCustomCommandList);
  1407. if (!FCustomCommandList->Equals(value))
  1408. {
  1409. FCustomCommandList->Assign(value);
  1410. FCustomCommandsDefaults = false;
  1411. }
  1412. }
  1413. //---------------------------------------------------------------------------
  1414. void __fastcall TWinConfiguration::SetBookmarks(AnsiString Key,
  1415. TBookmarkList * value)
  1416. {
  1417. FBookmarks->Bookmarks[Key] = value;
  1418. Changed();
  1419. }
  1420. //---------------------------------------------------------------------------
  1421. TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(AnsiString Key)
  1422. {
  1423. return FBookmarks->Bookmarks[Key];
  1424. }
  1425. //---------------------------------------------------------------------------
  1426. void __fastcall TWinConfiguration::SetSharedBookmarks(TBookmarkList * value)
  1427. {
  1428. FBookmarks->SharedBookmarks = value;
  1429. Changed();
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. TBookmarkList * __fastcall TWinConfiguration::GetSharedBookmarks()
  1433. {
  1434. return FBookmarks->SharedBookmarks;
  1435. }
  1436. //---------------------------------------------------------------------------
  1437. AnsiString __fastcall TWinConfiguration::GetDefaultKeyFile()
  1438. {
  1439. return (!FDefaultKeyFile.IsEmpty() ? FDefaultKeyFile : FTemporaryKeyFile);
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TWinConfiguration::SetLastMonitor(int value)
  1443. {
  1444. ::SetLastMonitor(value);
  1445. }
  1446. //---------------------------------------------------------------------------
  1447. int __fastcall TWinConfiguration::GetLastMonitor()
  1448. {
  1449. return ::GetLastMonitor();
  1450. }
  1451. //---------------------------------------------------------------------------
  1452. AnsiString __fastcall TWinConfiguration::TemporaryDir(bool Mask)
  1453. {
  1454. return UniqTempDir(ExpandFileName(ExpandEnvironmentVariables(DDTemporaryDirectory)),
  1455. "scp", Mask);
  1456. }
  1457. //---------------------------------------------------------------------------
  1458. TStrings * __fastcall TWinConfiguration::FindTemporaryFolders()
  1459. {
  1460. TStrings * Result = new TStringList();
  1461. try
  1462. {
  1463. TSearchRec SRec;
  1464. AnsiString Mask = TemporaryDir(true);
  1465. AnsiString Directory = ExtractFilePath(Mask);
  1466. if (FindFirst(Mask, faDirectory, SRec) == 0)
  1467. {
  1468. do
  1469. {
  1470. if (FLAGSET(SRec.Attr, faDirectory))
  1471. {
  1472. Result->Add(Directory + SRec.Name);
  1473. }
  1474. }
  1475. while (FindNext(SRec) == 0);
  1476. }
  1477. if (Result->Count == 0)
  1478. {
  1479. delete Result;
  1480. Result = NULL;
  1481. }
  1482. }
  1483. catch(...)
  1484. {
  1485. delete Result;
  1486. throw;
  1487. }
  1488. return Result;
  1489. }
  1490. //---------------------------------------------------------------------------
  1491. void __fastcall TWinConfiguration::CleanupTemporaryFolders(TStrings * Folders)
  1492. {
  1493. AnsiString ErrorList;
  1494. TStrings * F;
  1495. if (Folders == NULL)
  1496. {
  1497. F = FindTemporaryFolders();
  1498. }
  1499. else
  1500. {
  1501. F = Folders;
  1502. }
  1503. if (F != NULL)
  1504. {
  1505. try
  1506. {
  1507. for (int i = 0; i < F->Count; i++)
  1508. {
  1509. if (!DeleteDirectory(F->Strings[i]))
  1510. {
  1511. if (!ErrorList.IsEmpty())
  1512. {
  1513. ErrorList += "\n";
  1514. }
  1515. ErrorList += F->Strings[i];
  1516. }
  1517. }
  1518. }
  1519. __finally
  1520. {
  1521. if (Folders == NULL)
  1522. {
  1523. delete F;
  1524. }
  1525. }
  1526. if (!ErrorList.IsEmpty())
  1527. {
  1528. throw ExtException(LoadStr(CLEANUP_TEMP_ERROR), ErrorList);
  1529. }
  1530. }
  1531. }
  1532. //---------------------------------------------------------------------------
  1533. //---------------------------------------------------------------------------
  1534. #pragma warn -inl
  1535. //---------------------------------------------------------------------------
  1536. class TAsInheritedReader : public TReader
  1537. {
  1538. public:
  1539. __fastcall TAsInheritedReader(TStream * Stream, int BufSize) :
  1540. TReader(Stream, BufSize)
  1541. {
  1542. OnAncestorNotFound = AncestorNotFound;
  1543. }
  1544. virtual void __fastcall ReadPrefix(TFilerFlags & Flags, int & AChildPos)
  1545. {
  1546. TReader::ReadPrefix(Flags, AChildPos);
  1547. Flags << ffInherited;
  1548. }
  1549. void __fastcall AncestorNotFound(TReader * Reader,
  1550. const AnsiString ComponentName, TMetaClass * ComponentClass,
  1551. TComponent *& Component)
  1552. {
  1553. assert(!Component);
  1554. if (ComponentName.IsEmpty())
  1555. {
  1556. for (int Index = 0; Index < LookupRoot->ComponentCount; Index++)
  1557. {
  1558. Component = LookupRoot->Components[Index];
  1559. if (Component->Name.IsEmpty())
  1560. {
  1561. return;
  1562. }
  1563. }
  1564. Component = NULL;
  1565. }
  1566. }
  1567. };
  1568. //---------------------------------------------------------------------------
  1569. #pragma warn .inl
  1570. //---------------------------------------------------------------------------
  1571. bool __fastcall TWinConfiguration::InternalReloadComponentRes(const AnsiString ResName,
  1572. HANDLE HInst, TComponent * Instance)
  1573. {
  1574. HANDLE HRsrc;
  1575. bool Result;
  1576. if (!HInst)
  1577. {
  1578. HInst = HInstance;
  1579. }
  1580. HRsrc = FindResource(HInst, ResName.c_str(), RT_RCDATA);
  1581. Result = (HRsrc != 0);
  1582. if (Result)
  1583. {
  1584. TResourceStream * ResStream = new TResourceStream(
  1585. reinterpret_cast<int>(HInst), ResName, RT_RCDATA);
  1586. try
  1587. {
  1588. TReader * Reader;
  1589. Reader = new TAsInheritedReader(ResStream, 4096);
  1590. try
  1591. {
  1592. /*Instance =*/ Reader->ReadRootComponent(Instance);
  1593. }
  1594. __finally
  1595. {
  1596. delete Reader;
  1597. }
  1598. }
  1599. __finally
  1600. {
  1601. delete ResStream;
  1602. }
  1603. }
  1604. return Result;
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. bool __fastcall TWinConfiguration::InitComponent(TComponent * Instance,
  1608. TClass RootAncestor, TClass ClassType)
  1609. {
  1610. bool Result = false;
  1611. if ((ClassType != __classid(TComponent)) && (ClassType != RootAncestor))
  1612. {
  1613. if (InitComponent(Instance, RootAncestor, ClassType->ClassParent()))
  1614. {
  1615. Result = true;
  1616. }
  1617. if (InternalReloadComponentRes(ClassType->ClassName(),
  1618. reinterpret_cast<HANDLE>(FindResourceHInstance(FindClassHInstance(ClassType))),
  1619. Instance))
  1620. {
  1621. Result = true;
  1622. }
  1623. }
  1624. return Result;
  1625. }
  1626. //---------------------------------------------------------------------------
  1627. LCID __fastcall TWinConfiguration::GetLocale()
  1628. {
  1629. if (!FLocale)
  1630. {
  1631. AnsiString ResourceModule = ::GetResourceModule(ModuleFileName().c_str());
  1632. if (!ResourceModule.IsEmpty())
  1633. {
  1634. AnsiString ResourceExt = ExtractFileExt(ResourceModule).UpperCase();
  1635. ResourceExt.Delete(1, 1);
  1636. TLanguages * Langs = LanguagesDEPF();
  1637. int Index, Count;
  1638. Count = Langs->Count;
  1639. Index = 0;
  1640. while ((Index < Count) && !FLocale)
  1641. {
  1642. if (Langs->Ext[Index] == ResourceExt)
  1643. {
  1644. FLocale = Langs->LocaleID[Index];
  1645. }
  1646. else if (Langs->Ext[Index].SubString(1, 2) == ResourceExt)
  1647. {
  1648. FLocale = MAKELANGID(PRIMARYLANGID(Langs->LocaleID[Index]),
  1649. SUBLANG_DEFAULT);
  1650. }
  1651. Index++;
  1652. }
  1653. }
  1654. }
  1655. return TCustomWinConfiguration::GetLocale();
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. HINSTANCE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
  1659. AnsiString * FileName)
  1660. {
  1661. AnsiString FileNameStorage;
  1662. if (FileName == NULL)
  1663. {
  1664. FileName = &FileNameStorage;
  1665. }
  1666. HINSTANCE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
  1667. if (Instance != NULL)
  1668. {
  1669. try
  1670. {
  1671. CheckTranslationVersion(*FileName, false);
  1672. }
  1673. catch(...)
  1674. {
  1675. FreeResourceModule(Instance);
  1676. throw;
  1677. }
  1678. }
  1679. return Instance;
  1680. }
  1681. //---------------------------------------------------------------------------
  1682. void __fastcall TWinConfiguration::SetResourceModule(HINSTANCE Instance)
  1683. {
  1684. TCustomWinConfiguration::SetResourceModule(Instance);
  1685. Busy(true);
  1686. try
  1687. {
  1688. int Count;
  1689. AnsiString OrigName;
  1690. int OrigLeft;
  1691. int OrigTop;
  1692. TForm * Form;
  1693. Count = Screen->FormCount;
  1694. for (int Index = 0; Index < Count; Index++)
  1695. {
  1696. Form = Screen->Forms[Index];
  1697. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 0, 1);
  1698. }
  1699. ConfigureInterface();
  1700. for (int Index = 0; Index < Count; Index++)
  1701. {
  1702. Form = Screen->Forms[Index];
  1703. TComponent * Component;
  1704. for (int Index = 0; Index < Form->ComponentCount; Index++)
  1705. {
  1706. Component = Form->Components[Index];
  1707. if (dynamic_cast<TFrame*>(Component))
  1708. {
  1709. OrigName = Component->Name;
  1710. InitComponent(Component, __classid(TFrame), Component->ClassType());
  1711. Component->Name = OrigName;
  1712. }
  1713. }
  1714. OrigLeft = Form->Left;
  1715. OrigTop = Form->Top;
  1716. OrigName = Form->Name;
  1717. InitComponent(Form, __classid(TForm), Form->ClassType());
  1718. Form->Name = OrigName;
  1719. Form->Position = poDesigned;
  1720. Form->Left = OrigLeft;
  1721. Form->Top = OrigTop;
  1722. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 1, 1);
  1723. }
  1724. TDataModule * DataModule;
  1725. Count = Screen->DataModuleCount;
  1726. for (int Index = 0; Index < Count; Index++)
  1727. {
  1728. DataModule = Screen->DataModules[Index];
  1729. OrigName = DataModule->Name;
  1730. InitComponent(DataModule, __classid(TDataModule), DataModule->ClassType());
  1731. DataModule->Name = OrigName;
  1732. }
  1733. }
  1734. __finally
  1735. {
  1736. Busy(false);
  1737. }
  1738. }
  1739. //---------------------------------------------------------------------------
  1740. void __fastcall TWinConfiguration::CheckTranslationVersion(const AnsiString FileName,
  1741. bool InternalLocaleOnError)
  1742. {
  1743. AnsiString TranslationProductVersion = GetFileProductVersion(FileName);
  1744. AnsiString TranslationProductName = GetFileProductName(FileName);
  1745. if ((ProductName != TranslationProductName) ||
  1746. (ProductVersion != TranslationProductVersion))
  1747. {
  1748. if (InternalLocaleOnError)
  1749. {
  1750. LocaleSafe = InternalLocale();
  1751. }
  1752. if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
  1753. {
  1754. throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
  1755. }
  1756. else
  1757. {
  1758. throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
  1759. (FileName, TranslationProductName, TranslationProductVersion)));
  1760. }
  1761. }
  1762. }
  1763. //---------------------------------------------------------------------------
  1764. void __fastcall TWinConfiguration::CheckDefaultTranslation()
  1765. {
  1766. if (!FInvalidDefaultTranslationMessage.IsEmpty())
  1767. {
  1768. MoreMessageDialog(FMTLOAD(INVALID_DEFAULT_TRANSLATION,
  1769. (FInvalidDefaultTranslationMessage)), NULL, qtWarning, qaOK, HELP_NONE);
  1770. }
  1771. }
  1772. //---------------------------------------------------------------------------
  1773. const TEditorPreferences * __fastcall TWinConfiguration::DefaultEditorForFile(
  1774. const AnsiString FileName, bool Local, const TFileMasks::TParams & MaskParams)
  1775. {
  1776. return FEditorList->Find(FileName, Local, MaskParams);
  1777. }
  1778. //---------------------------------------------------------------------------
  1779. const TEditorList * __fastcall TWinConfiguration::GetEditorList()
  1780. {
  1781. return FEditorList;
  1782. }
  1783. //---------------------------------------------------------------------------
  1784. void __fastcall TWinConfiguration::SetEditorList(const TEditorList * value)
  1785. {
  1786. if (!(*FEditorList == *value))
  1787. {
  1788. *FEditorList = *value;
  1789. Changed();
  1790. }
  1791. }
  1792. //---------------------------------------------------------------------------
  1793. //---------------------------------------------------------------------------
  1794. __fastcall TCustomCommandType::TCustomCommandType() :
  1795. FParams(0), FShortCut(0)
  1796. {
  1797. }
  1798. //---------------------------------------------------------------------------
  1799. __fastcall TCustomCommandType::TCustomCommandType(const TCustomCommandType & Other) :
  1800. FName(Other.FName),
  1801. FCommand(Other.FCommand),
  1802. FParams(Other.FParams),
  1803. FShortCut(Other.FShortCut)
  1804. {
  1805. }
  1806. //---------------------------------------------------------------------------
  1807. TCustomCommandType & TCustomCommandType::operator=(const TCustomCommandType & Other)
  1808. {
  1809. FName = Other.FName;
  1810. FCommand = Other.FCommand;
  1811. FParams = Other.FParams;
  1812. FShortCut = Other.FShortCut;
  1813. return *this;
  1814. }
  1815. //---------------------------------------------------------------------------
  1816. bool __fastcall TCustomCommandType::Equals(const TCustomCommandType * Other) const
  1817. {
  1818. return
  1819. (FName == Other->FName) &&
  1820. (FCommand == Other->FCommand) &&
  1821. (FParams == Other->FParams) &&
  1822. (FShortCut == Other->FShortCut);
  1823. }
  1824. //---------------------------------------------------------------------------
  1825. //---------------------------------------------------------------------------
  1826. __fastcall TCustomCommandList::TCustomCommandList()
  1827. {
  1828. FCommands = new TList();
  1829. FModified = false;
  1830. }
  1831. //---------------------------------------------------------------------------
  1832. __fastcall TCustomCommandList::~TCustomCommandList()
  1833. {
  1834. Clear();
  1835. delete FCommands;
  1836. }
  1837. //---------------------------------------------------------------------------
  1838. void __fastcall TCustomCommandList::Reset()
  1839. {
  1840. FModified = false;
  1841. }
  1842. //---------------------------------------------------------------------------
  1843. void __fastcall TCustomCommandList::Modify()
  1844. {
  1845. FModified = true;
  1846. }
  1847. //---------------------------------------------------------------------------
  1848. void __fastcall TCustomCommandList::Load(THierarchicalStorage * Storage)
  1849. {
  1850. Clear();
  1851. if (Storage->OpenSubKey("CustomCommands", false))
  1852. {
  1853. TStrings * Names = new TStringList();
  1854. try
  1855. {
  1856. Storage->ReadValues(Names, true);
  1857. for (int Index = 0; Index < Names->Count; Index++)
  1858. {
  1859. TCustomCommandType * Command = new TCustomCommandType();
  1860. Command->Name = Names->Names[Index];
  1861. Command->Command = Names->Values[Names->Names[Index]];
  1862. FCommands->Add(Command);
  1863. }
  1864. Storage->CloseSubKey();
  1865. }
  1866. __finally
  1867. {
  1868. delete Names;
  1869. }
  1870. }
  1871. if (Storage->OpenSubKey("CustomCommandsParams", false))
  1872. {
  1873. for (int Index = 0; Index < FCommands->Count; Index++)
  1874. {
  1875. TCustomCommandType * Command = GetCommand(Index);
  1876. Command->Params = Storage->ReadInteger(Command->Name, Command->Params);
  1877. }
  1878. Storage->CloseSubKey();
  1879. }
  1880. if (Storage->OpenSubKey("CustomCommandsShortCuts", false))
  1881. {
  1882. for (int Index = 0; Index < FCommands->Count; Index++)
  1883. {
  1884. TCustomCommandType * Command = GetCommand(Index);
  1885. Command->ShortCut = (Word)Storage->ReadInteger(Command->Name, Command->ShortCut);
  1886. }
  1887. Storage->CloseSubKey();
  1888. }
  1889. Reset();
  1890. }
  1891. //---------------------------------------------------------------------------
  1892. void __fastcall TCustomCommandList::Save(THierarchicalStorage * Storage)
  1893. {
  1894. if (Storage->OpenSubKey("CustomCommands", true))
  1895. {
  1896. Storage->ClearValues();
  1897. for (int Index = 0; Index < FCommands->Count; Index++)
  1898. {
  1899. const TCustomCommandType * Command = Commands[Index];
  1900. Storage->WriteString(Command->Name, Command->Command);
  1901. }
  1902. Storage->CloseSubKey();
  1903. }
  1904. if (Storage->OpenSubKey("CustomCommandsParams", true))
  1905. {
  1906. Storage->ClearValues();
  1907. for (int Index = 0; Index < FCommands->Count; Index++)
  1908. {
  1909. const TCustomCommandType * Command = Commands[Index];
  1910. Storage->WriteInteger(Command->Name, Command->Params);
  1911. }
  1912. Storage->CloseSubKey();
  1913. }
  1914. if (Storage->OpenSubKey("CustomCommandsShortCuts", true))
  1915. {
  1916. Storage->ClearValues();
  1917. for (int Index = 0; Index < FCommands->Count; Index++)
  1918. {
  1919. const TCustomCommandType * Command = Commands[Index];
  1920. if (Command->ShortCut != 0)
  1921. {
  1922. Storage->WriteInteger(Command->Name, Command->ShortCut);
  1923. }
  1924. }
  1925. Storage->CloseSubKey();
  1926. }
  1927. }
  1928. //---------------------------------------------------------------------------
  1929. void __fastcall TCustomCommandList::Clear()
  1930. {
  1931. for (int Index = 0; Index < FCommands->Count; Index++)
  1932. {
  1933. delete Commands[Index];
  1934. }
  1935. FCommands->Clear();
  1936. }
  1937. //---------------------------------------------------------------------------
  1938. void __fastcall TCustomCommandList::Add(const AnsiString Name,
  1939. const AnsiString ACommand, int Params)
  1940. {
  1941. TCustomCommandType * Command = new TCustomCommandType();
  1942. Command->Name = Name;
  1943. Command->Command = ACommand;
  1944. Command->Params = Params;
  1945. Add(Command);
  1946. }
  1947. //---------------------------------------------------------------------------
  1948. void __fastcall TCustomCommandList::Add(TCustomCommandType * Command)
  1949. {
  1950. Insert(Count, Command);
  1951. }
  1952. //---------------------------------------------------------------------------
  1953. void __fastcall TCustomCommandList::Insert(int Index, TCustomCommandType * Command)
  1954. {
  1955. FCommands->Insert(Index, Command);
  1956. Modify();
  1957. }
  1958. //---------------------------------------------------------------------------
  1959. void __fastcall TCustomCommandList::Change(int Index, TCustomCommandType * ACommand)
  1960. {
  1961. TCustomCommandType * Command = GetCommand(Index);
  1962. if (!Command->Equals(ACommand))
  1963. {
  1964. delete Command;
  1965. FCommands->Items[Index] = ACommand;
  1966. Modify();
  1967. }
  1968. else
  1969. {
  1970. delete ACommand;
  1971. }
  1972. }
  1973. //---------------------------------------------------------------------------
  1974. void __fastcall TCustomCommandList::Move(int CurIndex, int NewIndex)
  1975. {
  1976. if (CurIndex != NewIndex)
  1977. {
  1978. FCommands->Move(CurIndex, NewIndex);
  1979. Modify();
  1980. }
  1981. }
  1982. //---------------------------------------------------------------------------
  1983. void __fastcall TCustomCommandList::Delete(int Index)
  1984. {
  1985. assert((Index >= 0) && (Index < Count));
  1986. delete GetCommand(Index);
  1987. FCommands->Delete(Index);
  1988. Modify();
  1989. }
  1990. //---------------------------------------------------------------------------
  1991. int __fastcall TCustomCommandList::GetCount() const
  1992. {
  1993. return FCommands->Count;
  1994. }
  1995. //---------------------------------------------------------------------------
  1996. const TCustomCommandType * __fastcall TCustomCommandList::GetConstCommand(int Index) const
  1997. {
  1998. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  1999. }
  2000. //---------------------------------------------------------------------------
  2001. TCustomCommandType * __fastcall TCustomCommandList::GetCommand(int Index)
  2002. {
  2003. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2004. }
  2005. //---------------------------------------------------------------------------
  2006. bool __fastcall TCustomCommandList::Equals(const TCustomCommandList * Other) const
  2007. {
  2008. bool Result = (Count == Other->Count);
  2009. for (int Index = 0; Result && (Index < Count); Index++)
  2010. {
  2011. Result = Commands[Index]->Equals(Other->Commands[Index]);
  2012. }
  2013. return Result;
  2014. }
  2015. //---------------------------------------------------------------------------
  2016. void __fastcall TCustomCommandList::Assign(const TCustomCommandList * Other)
  2017. {
  2018. Clear();
  2019. for (int Index = 0; Index < Other->Count; Index++)
  2020. {
  2021. Add(new TCustomCommandType(*Other->Commands[Index]));
  2022. }
  2023. // there should be comparison of with the assigned list, be we rely on caller
  2024. // to do it instead (TGUIConfiguration::SetCopyParamList)
  2025. Modify();
  2026. }
  2027. //---------------------------------------------------------------------------
  2028. const TCustomCommandType * TCustomCommandList::Find(const AnsiString Name) const
  2029. {
  2030. for (int Index = 0; Index < FCommands->Count; Index++)
  2031. {
  2032. if (Commands[Index]->Name == Name)
  2033. {
  2034. return Commands[Index];
  2035. }
  2036. }
  2037. return NULL;
  2038. }
  2039. //---------------------------------------------------------------------------
  2040. const TCustomCommandType * TCustomCommandList::Find(TShortCut ShortCut) const
  2041. {
  2042. for (int Index = 0; Index < FCommands->Count; Index++)
  2043. {
  2044. if (Commands[Index]->ShortCut == ShortCut)
  2045. {
  2046. return Commands[Index];
  2047. }
  2048. }
  2049. return NULL;
  2050. }
  2051. //---------------------------------------------------------------------------
  2052. void __fastcall TCustomCommandList::ShortCuts(TShortCuts & ShortCuts) const
  2053. {
  2054. for (int Index = 0; Index < FCommands->Count; Index++)
  2055. {
  2056. const TCustomCommandType * Command = Commands[Index];
  2057. if (Command->ShortCut != 0)
  2058. {
  2059. ShortCuts.Add(Command->ShortCut);
  2060. }
  2061. }
  2062. }