WinConfiguration.cpp 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580
  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 <InitGUID.h>
  19. #include <DragExt.h>
  20. #include <Math.hpp>
  21. //---------------------------------------------------------------------------
  22. #pragma package(smart_init)
  23. //---------------------------------------------------------------------------
  24. TWinConfiguration * WinConfiguration = NULL;
  25. //---------------------------------------------------------------------------
  26. __fastcall TEditorData::TEditorData() :
  27. FileMask(L"*.*"),
  28. Editor(edInternal),
  29. ExternalEditor(L""),
  30. ExternalEditorText(true),
  31. SDIExternalEditor(false),
  32. DetectMDIExternalEditor(false)
  33. {
  34. }
  35. //---------------------------------------------------------------------------
  36. __fastcall TEditorData::TEditorData(const TEditorData & Source) :
  37. FileMask(Source.FileMask),
  38. Editor(Source.Editor),
  39. ExternalEditor(Source.ExternalEditor),
  40. ExternalEditorText(Source.ExternalEditorText),
  41. SDIExternalEditor(Source.SDIExternalEditor),
  42. DetectMDIExternalEditor(Source.DetectMDIExternalEditor)
  43. {
  44. }
  45. //---------------------------------------------------------------------------
  46. #define C(Property) (Property == rhd.Property)
  47. bool __fastcall TEditorData::operator==(const TEditorData & rhd) const
  48. {
  49. return
  50. C(FileMask) &&
  51. C(Editor) &&
  52. C(ExternalEditor) &&
  53. C(ExternalEditorText) &&
  54. C(SDIExternalEditor) &&
  55. C(DetectMDIExternalEditor) &&
  56. true;
  57. }
  58. #undef C
  59. //---------------------------------------------------------------------------
  60. __fastcall TEditorPreferences::TEditorPreferences()
  61. {
  62. }
  63. //---------------------------------------------------------------------------
  64. __fastcall TEditorPreferences::TEditorPreferences(const TEditorData & Data) :
  65. FData(Data)
  66. {
  67. }
  68. //---------------------------------------------------------------------------
  69. bool __fastcall TEditorPreferences::operator==(const TEditorPreferences & rhp) const
  70. {
  71. return (FData == rhp.FData);
  72. }
  73. #undef C
  74. //---------------------------------------------------------------------------
  75. bool __fastcall TEditorPreferences::Matches(const UnicodeString FileName,
  76. bool Local, const TFileMasks::TParams & Params) const
  77. {
  78. return FData.FileMask.Matches(FileName, Local, false, &Params);
  79. }
  80. //---------------------------------------------------------------------------
  81. UnicodeString __fastcall TEditorPreferences::GetDefaultExternalEditor()
  82. {
  83. return L"notepad.exe";
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TEditorPreferences::LegacyDefaults()
  87. {
  88. FData.ExternalEditor = GetDefaultExternalEditor();
  89. }
  90. //---------------------------------------------------------------------------
  91. void __fastcall TEditorPreferences::Load(THierarchicalStorage * Storage, bool Legacy)
  92. {
  93. if (!Legacy)
  94. {
  95. FData.FileMask = Storage->ReadString(L"FileMask", FData.FileMask.Masks);
  96. }
  97. FData.Editor = (TEditor)Storage->ReadInteger(L"Editor", FData.Editor);
  98. FData.ExternalEditor = Storage->ReadString(L"ExternalEditor", FData.ExternalEditor);
  99. FData.ExternalEditorText = Storage->ReadBool(L"ExternalEditorText", FData.ExternalEditorText);
  100. FData.SDIExternalEditor = Storage->ReadBool(L"SDIExternalEditor", FData.SDIExternalEditor);
  101. FData.DetectMDIExternalEditor = Storage->ReadBool(L"DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
  102. }
  103. //---------------------------------------------------------------------------
  104. void __fastcall TEditorPreferences::Save(THierarchicalStorage * Storage) const
  105. {
  106. Storage->WriteString(L"FileMask", FData.FileMask.Masks);
  107. Storage->WriteInteger(L"Editor", FData.Editor);
  108. Storage->WriteString(L"ExternalEditor", FData.ExternalEditor);
  109. Storage->WriteBool(L"ExternalEditorText", FData.ExternalEditorText);
  110. Storage->WriteBool(L"SDIExternalEditor", FData.SDIExternalEditor);
  111. Storage->WriteBool(L"DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
  112. }
  113. //---------------------------------------------------------------------------
  114. TEditorData * __fastcall TEditorPreferences::GetData()
  115. {
  116. // returning non-const data, possible data change, invalidate cached name
  117. FName = L"";
  118. return &FData;
  119. };
  120. //---------------------------------------------------------------------------
  121. UnicodeString __fastcall TEditorPreferences::GetName() const
  122. {
  123. if (FName.IsEmpty())
  124. {
  125. if (FData.Editor == edInternal)
  126. {
  127. // StripHotkey is relic from times when INTERNAL_EDITOR_NAME was used
  128. // also for the menu item caption
  129. FName = StripHotkey(LoadStr(INTERNAL_EDITOR_NAME));
  130. }
  131. else if (FData.Editor == edOpen)
  132. {
  133. FName = StripHotkey(LoadStr(OPEN_EDITOR_NAME));
  134. }
  135. else
  136. {
  137. UnicodeString Program, Params, Dir;
  138. UnicodeString ExternalEditor = FData.ExternalEditor;
  139. ReformatFileNameCommand(ExternalEditor);
  140. SplitCommand(ExternalEditor, Program, Params, Dir);
  141. FName = ExtractFileName(Program);
  142. int P = FName.LastDelimiter(L".");
  143. if (P > 0)
  144. {
  145. FName.SetLength(P - 1);
  146. }
  147. if (FName.ByteType(1) == mbSingleByte)
  148. {
  149. if (FName.UpperCase() == FName)
  150. {
  151. FName = FName.LowerCase();
  152. }
  153. if (FName.LowerCase() == FName)
  154. {
  155. FName = FName.SubString(1, 1).UpperCase() +
  156. FName.SubString(2, FName.Length() - 1);
  157. }
  158. }
  159. }
  160. }
  161. return FName;
  162. }
  163. //---------------------------------------------------------------------------
  164. //---------------------------------------------------------------------------
  165. __fastcall TEditorList::TEditorList()
  166. {
  167. Init();
  168. }
  169. //---------------------------------------------------------------------------
  170. void __fastcall TEditorList::Init()
  171. {
  172. FEditors = new TList();
  173. FModified = false;
  174. }
  175. //---------------------------------------------------------------------------
  176. __fastcall TEditorList::~TEditorList()
  177. {
  178. Clear();
  179. delete FEditors;
  180. }
  181. //---------------------------------------------------------------------
  182. void __fastcall TEditorList::Modify()
  183. {
  184. FModified = true;
  185. }
  186. //---------------------------------------------------------------------------
  187. void __fastcall TEditorList::Saved()
  188. {
  189. FModified = false;
  190. }
  191. //---------------------------------------------------------------------------
  192. TEditorList & __fastcall TEditorList::operator=(const TEditorList & rhl)
  193. {
  194. Clear();
  195. for (int Index = 0; Index < rhl.Count; Index++)
  196. {
  197. Add(new TEditorPreferences(*rhl.Editors[Index]));
  198. }
  199. // there should be comparison of with the assigned list, but we rely on caller
  200. // to do it instead (TWinConfiguration::SetEditorList)
  201. Modify();
  202. return *this;
  203. }
  204. //---------------------------------------------------------------------------
  205. bool __fastcall TEditorList::operator==(const TEditorList & rhl) const
  206. {
  207. bool Result = (Count == rhl.Count);
  208. if (Result)
  209. {
  210. int i = 0;
  211. while ((i < Count) && Result)
  212. {
  213. Result = (*Editors[i]) == (*rhl.Editors[i]);
  214. i++;
  215. }
  216. }
  217. return Result;
  218. }
  219. //---------------------------------------------------------------------------
  220. void __fastcall TEditorList::Clear()
  221. {
  222. for (int i = 0; i < Count; i++)
  223. {
  224. delete Editors[i];
  225. }
  226. FEditors->Clear();
  227. }
  228. //---------------------------------------------------------------------------
  229. void __fastcall TEditorList::Add(TEditorPreferences * Editor)
  230. {
  231. Insert(Count, Editor);
  232. }
  233. //---------------------------------------------------------------------------
  234. void __fastcall TEditorList::Insert(int Index, TEditorPreferences * Editor)
  235. {
  236. FEditors->Insert(Index, reinterpret_cast<TObject *>(Editor));
  237. Modify();
  238. }
  239. //---------------------------------------------------------------------------
  240. void __fastcall TEditorList::Change(int Index, TEditorPreferences * Editor)
  241. {
  242. if (!((*Editors[Index]) == *Editor))
  243. {
  244. delete Editors[Index];
  245. FEditors->Items[Index] = (reinterpret_cast<TObject *>(Editor));
  246. Modify();
  247. }
  248. else
  249. {
  250. delete Editor;
  251. }
  252. }
  253. //---------------------------------------------------------------------------
  254. void __fastcall TEditorList::Move(int CurIndex, int NewIndex)
  255. {
  256. if (CurIndex != NewIndex)
  257. {
  258. FEditors->Move(CurIndex, NewIndex);
  259. Modify();
  260. }
  261. }
  262. //---------------------------------------------------------------------------
  263. void __fastcall TEditorList::Delete(int Index)
  264. {
  265. assert((Index >= 0) && (Index < Count));
  266. delete Editors[Index];
  267. FEditors->Delete(Index);
  268. Modify();
  269. }
  270. //---------------------------------------------------------------------------
  271. const TEditorPreferences * __fastcall TEditorList::Find(
  272. const UnicodeString FileName, bool Local, const TFileMasks::TParams & Params) const
  273. {
  274. const TEditorPreferences * Result = NULL;
  275. int i = 0;
  276. while ((i < FEditors->Count) && (Result == NULL))
  277. {
  278. Result = Editors[i];
  279. if (!Result->Matches(FileName, Local, Params))
  280. {
  281. Result = NULL;
  282. }
  283. i++;
  284. }
  285. return Result;
  286. }
  287. //---------------------------------------------------------------------------
  288. void __fastcall TEditorList::Load(THierarchicalStorage * Storage)
  289. {
  290. int Index = 0;
  291. bool Next;
  292. do
  293. {
  294. UnicodeString Name = IntToStr(Index);
  295. TEditorPreferences * Editor = NULL;
  296. try
  297. {
  298. Next = Storage->OpenSubKey(Name, false);
  299. if (Next)
  300. {
  301. try
  302. {
  303. Editor = new TEditorPreferences();
  304. Editor->Load(Storage, false);
  305. }
  306. __finally
  307. {
  308. Storage->CloseSubKey();
  309. }
  310. }
  311. }
  312. catch(...)
  313. {
  314. delete Editor;
  315. throw;
  316. }
  317. if (Editor != NULL)
  318. {
  319. FEditors->Add(reinterpret_cast<TObject *>(Editor));
  320. }
  321. Index++;
  322. }
  323. while (Next);
  324. FModified = false;
  325. }
  326. //---------------------------------------------------------------------------
  327. void __fastcall TEditorList::Save(THierarchicalStorage * Storage) const
  328. {
  329. Storage->ClearSubKeys();
  330. for (int Index = 0; Index < Count; Index++)
  331. {
  332. if (Storage->OpenSubKey(IntToStr(Index), true))
  333. {
  334. try
  335. {
  336. Editors[Index]->Save(Storage);
  337. }
  338. __finally
  339. {
  340. Storage->CloseSubKey();
  341. }
  342. }
  343. }
  344. }
  345. //---------------------------------------------------------------------------
  346. int __fastcall TEditorList::GetCount() const
  347. {
  348. int X = FEditors->Count;
  349. return X;
  350. }
  351. //---------------------------------------------------------------------------
  352. const TEditorPreferences * __fastcall TEditorList::GetEditor(int Index) const
  353. {
  354. return reinterpret_cast<TEditorPreferences *>(FEditors->Items[Index]);
  355. }
  356. //---------------------------------------------------------------------------
  357. bool __fastcall TEditorList::IsDefaultList() const
  358. {
  359. bool Result = true;
  360. for (int Index = 0; Result && (Index < Count); Index++)
  361. {
  362. const TEditorPreferences * Editor = GetEditor(Index);
  363. Result =
  364. (Editor->Data->Editor == edInternal) ||
  365. ((Editor->Data->Editor == edExternal) &&
  366. (SameText(Editor->Data->ExternalEditor, TEditorPreferences::GetDefaultExternalEditor())));
  367. }
  368. return Result;
  369. }
  370. //---------------------------------------------------------------------------
  371. //---------------------------------------------------------------------------
  372. __fastcall TWinConfiguration::TWinConfiguration(): TCustomWinConfiguration()
  373. {
  374. FInvalidDefaultTranslationMessage = L"";
  375. FDDExtInstalled = -1;
  376. FBookmarks = new TBookmarks();
  377. FCustomCommandList = new TCustomCommandList();
  378. FEditorList = new TEditorList();
  379. FDefaultUpdatesPeriod = 0;
  380. FDontDecryptPasswords = 0;
  381. FMasterPasswordSession = 0;
  382. FMasterPasswordSessionAsked = false;
  383. Default();
  384. try
  385. {
  386. CheckTranslationVersion(
  387. GetResourceModuleName(Application->Name, ModuleFileName().c_str()), true);
  388. }
  389. catch(Exception & E)
  390. {
  391. FInvalidDefaultTranslationMessage = E.Message;
  392. }
  393. }
  394. //---------------------------------------------------------------------------
  395. __fastcall TWinConfiguration::~TWinConfiguration()
  396. {
  397. if (!FTemporarySessionFile.IsEmpty()) DeleteFile(::ApiPath(FTemporarySessionFile));
  398. ClearTemporaryLoginData();
  399. delete FBookmarks;
  400. delete FCustomCommandList;
  401. delete FEditorList;
  402. }
  403. //---------------------------------------------------------------------------
  404. void __fastcall TWinConfiguration::Default()
  405. {
  406. FCustomCommandsDefaults = true;
  407. TCustomWinConfiguration::Default();
  408. int WorkAreaWidthScaled = DimensionToDefaultPixelsPerInch(Screen->WorkAreaWidth);
  409. int WorkAreaHeightScaled = DimensionToDefaultPixelsPerInch(Screen->WorkAreaHeight);
  410. UnicodeString PixelsPerInchToolbarValue = "PixelsPerInch=" + SaveDefaultPixelsPerInch();
  411. FDDAllowMove = false;
  412. FDDAllowMoveInit = false;
  413. FDDTransferConfirmation = asAuto;
  414. FDDTemporaryDirectory = L"";
  415. FDDWarnLackOfTempSpace = true;
  416. FDDWarnLackOfTempSpaceRatio = 1.1;
  417. FDDExtEnabled = DDExtInstalled;
  418. FDDExtTimeout = MSecsPerSec;
  419. FDeleteToRecycleBin = true;
  420. FSelectDirectories = false;
  421. FSelectMask = L"*.*";
  422. FShowHiddenFiles = false;
  423. FFormatSizeBytes = fbKilobytes;
  424. FShowInaccesibleDirectories = true;
  425. FConfirmTransferring = true;
  426. FConfirmDeleting = true;
  427. FConfirmRecycling = true;
  428. FConfirmClosingSession = true;
  429. FDoubleClickAction = dcaEdit;
  430. FCopyOnDoubleClickConfirmation = false;
  431. FDimmHiddenFiles = true;
  432. FRenameWholeName = false;
  433. FAutoStartSession = L"";
  434. FExpertMode = true;
  435. FUseLocationProfiles = false;
  436. FUseSharedBookmarks = false;
  437. FDefaultDirIsHome = true;
  438. FDDDeleteDelay = 120;
  439. FTemporaryDirectoryAppendSession = false;
  440. FTemporaryDirectoryAppendPath = true;
  441. FTemporaryDirectoryCleanup = true;
  442. FConfirmTemporaryDirectoryCleanup = true;
  443. FPreservePanelState = true;
  444. FTheme = L"OfficeXP";
  445. FLastStoredSession = L"";
  446. // deliberately not being saved, so that when saving ad-hoc workspace,
  447. // we do not offer to overwrite the last saved workspace, what may be undesirable
  448. FLastWorkspace = L"";
  449. FAutoSaveWorkspace = false;
  450. FAutoSaveWorkspacePasswords = false;
  451. FAutoWorkspace = L"";
  452. FPathInCaption = picShort;
  453. FMinimizeToTray = false;
  454. FBalloonNotifications = true;
  455. FNotificationsTimeout = 10;
  456. FNotificationsStickTime = 2;
  457. FCopyParamAutoSelectNotice = true;
  458. FLockToolbars = false;
  459. FSelectiveToolbarText = true;
  460. FAutoOpenInPutty = false;
  461. FRefreshRemotePanel = false;
  462. FRefreshRemotePanelInterval = TDateTime(0, 1, 0, 0);
  463. FFullRowSelect = false;
  464. FOfferedEditorAutoConfig = false;
  465. FVersionHistory = L"";
  466. AddVersionToHistory();
  467. FUseMasterPassword = false;
  468. FPlainMasterPasswordEncrypt = L"";
  469. FPlainMasterPasswordDecrypt = L"";
  470. FMasterPasswordVerifier = L"";
  471. FOpenedStoredSessionFolders = L"";
  472. FAutoImportedFromPuttyOrFilezilla = false;
  473. FGenerateUrlComponents = -1;
  474. FExternalSessionInExistingInstance = true;
  475. FEditor.FontName = DefaultFixedWidthFontName;
  476. FEditor.FontSize = DefaultFixedWidthFontSize;
  477. FEditor.FontStyle = 0;
  478. FEditor.FontCharset = DEFAULT_CHARSET;
  479. FEditor.WordWrap = false;
  480. FEditor.FindText = L"";
  481. FEditor.ReplaceText = L"";
  482. FEditor.FindMatchCase = false;
  483. FEditor.FindWholeWord = false;
  484. FEditor.FindDown = true;
  485. FEditor.TabSize = 8;
  486. FEditor.MaxEditors = 500;
  487. FEditor.EarlyClose = 2; // seconds
  488. FEditor.SDIShellEditor = false;
  489. FEditor.WindowParams = L"";
  490. FEditor.Encoding = CP_ACP;
  491. FEditor.WarnOnEncodingFallback = true;
  492. FEditor.WarnOrLargeFileSize = true;
  493. FQueueView.Height = 140;
  494. FQueueView.HeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  495. // with 1000 pixels wide screen, both interfaces are wide enough to fit wider queue
  496. FQueueView.Layout =
  497. UnicodeString((WorkAreaWidthScaled > 1000) ? L"70,250,250,80,80,80,100" : L"70,160,160,80,80,80,100") +
  498. // WORKAROUND (the comma), see GetListViewStr
  499. L",;" + SaveDefaultPixelsPerInch();
  500. FQueueView.Show = qvHideWhenEmpty;
  501. FQueueView.LastHideShow = qvHideWhenEmpty;
  502. FQueueView.ToolBar = true;
  503. FQueueView.Label = true;
  504. FEnableQueueByDefault = true;
  505. FUpdates.Period = FDefaultUpdatesPeriod;
  506. FUpdates.LastCheck = 0;
  507. FUpdates.HaveResults = false;
  508. FUpdates.ShownResults = false;
  509. FUpdates.BetaVersions = asAuto;
  510. FUpdates.ShowOnStartup = true;
  511. // for backward compatibility the default is decided based on value of ProxyHost
  512. FUpdates.ConnectionType = (TConnectionType)-1;
  513. FUpdates.ProxyHost = L""; // keep empty (see above)
  514. FUpdates.ProxyPort = 8080;
  515. FUpdates.Results.Reset();
  516. FUpdates.DotNetVersion = L"";
  517. FUpdates.ConsoleVersion = L"";
  518. FLogWindowOnStartup = true;
  519. FLogWindowParams = FormatDefaultWindowParams(500, 400);
  520. int ExplorerWidth = Min(WorkAreaWidthScaled - 40, 960);
  521. int ExplorerHeight = Min(WorkAreaHeightScaled - 30, 720);
  522. FScpExplorer.WindowParams = FormatDefaultWindowParams(ExplorerWidth, ExplorerHeight);
  523. // WORKAROUND (the semicolon, see TCustomListViewColProperties.GetParamsStr, and see other instances below)
  524. FScpExplorer.DirViewParams = L"0;1;0|150,1;70,1;150,1;79,1;62,1;55,0;20,0;150,0;125,0;@" + SaveDefaultPixelsPerInch() + L"|6;7;8;0;1;2;3;4;5";
  525. FScpExplorer.ToolbarsLayout =
  526. UnicodeString(
  527. L"Queue_Visible=1,Queue_LastDock=QueueDock,Queue_DockRow=0,Queue_DockPos=-1,Queue_FloatLeft=0,Queue_FloatTop=0,Queue_FloatRightX=0,"
  528. "Menu_Visible=1,Menu_DockedTo=TopDock,Menu_LastDock=TopDock,Menu_DockRow=0,Menu_DockPos=0,Menu_FloatLeft=0,Menu_FloatTop=0,Menu_FloatRightX=0,"
  529. "Buttons_Visible=1,Buttons_DockedTo=TopDock,Buttons_LastDock=TopDock,Buttons_DockRow=2,Buttons_DockPos=0,Buttons_FloatLeft=0,Buttons_FloatTop=0,Buttons_FloatRightX=0,"
  530. "Selection_Visible=0,Selection_DockedTo=TopDock,Selection_LastDock=TopDock,Selection_DockRow=3,Selection_DockPos=0,Selection_FloatLeft=227,Selection_FloatTop=445,Selection_FloatRightX=0,"
  531. "Session_Visible=0,Session_DockedTo=TopDock,Session_LastDock=TopDock,Session_DockRow=6,Session_DockPos=0,Session_FloatLeft=39,Session_FloatTop=160,Session_FloatRightX=0,"
  532. "Preferences_Visible=1,Preferences_DockedTo=TopDock,Preferences_LastDock=TopDock,Preferences_DockRow=4,Preferences_DockPos=0,Preferences_FloatLeft=0,Preferences_FloatTop=0,Preferences_FloatRightX=0,"
  533. "Sort_Visible=0,Sort_DockedTo=TopDock,Sort_LastDock=TopDock,Sort_DockRow=5,Sort_DockPos=0,Sort_FloatLeft=0,Sort_FloatTop=0,Sort_FloatRightX=0,"
  534. "Address_Visible=1,Address_DockedTo=TopDock,Address_LastDock=TopDock,Address_DockRow=1,Address_DockPos=0,Address_FloatLeft=0,Address_FloatTop=0,Address_FloatRightX=0,"
  535. "Updates_Visible=1,Updates_DockedTo=TopDock,Updates_LastDock=TopDock,Updates_DockRow=4,Updates_DockPos=416,Updates_FloatLeft=0,Updates_FloatTop=0,Updates_FloatRightX=0,"
  536. "Transfer_Visible=1,Transfer_DockedTo=TopDock,Transfer_LastDock=TopDock,Transfer_DockRow=4,Transfer_DockPos=194,Transfer_FloatLeft=0,Transfer_FloatTop=0,Transfer_FloatRightX=0,"
  537. "CustomCommands_Visible=0,CustomCommands_DockedTo=TopDock,CustomCommands_LastDock=TopDock,CustomCommands_DockRow=7,CustomCommands_DockPos=0,CustomCommands_FloatLeft=0,CustomCommands_FloatTop=0,CustomCommands_FloatRightX=0,") +
  538. PixelsPerInchToolbarValue;
  539. FScpExplorer.SessionsTabs = true;
  540. FScpExplorer.StatusBar = true;
  541. FScpExplorer.LastLocalTargetDirectory = GetPersonalFolder();
  542. FScpExplorer.ViewStyle = 0; /* vsIcon */
  543. FScpExplorer.ShowFullAddress = true;
  544. FScpExplorer.DriveView = true;
  545. FScpExplorer.DriveViewWidth = 180;
  546. FScpExplorer.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  547. int CommanderWidth = Min(WorkAreaWidthScaled - 40, 1090);
  548. int CommanderHeight = Min(WorkAreaHeightScaled - 30, 700);
  549. FScpCommander.WindowParams = FormatDefaultWindowParams(CommanderWidth, CommanderHeight);
  550. FScpCommander.LocalPanelWidth = 0.5;
  551. FScpCommander.SwappedPanels = false;
  552. FScpCommander.SessionsTabs = true;
  553. FScpCommander.StatusBar = true;
  554. FScpCommander.NortonLikeMode = nlKeyboard;
  555. FScpCommander.PreserveLocalDirectory = false;
  556. // Toolbar2_FloatRightX=1 makes keybar apper initially "in column" when undocked
  557. FScpCommander.ToolbarsLayout =
  558. UnicodeString(
  559. L"Queue_Visible=1,Queue_LastDock=QueueDock,Queue_DockRow=0,Queue_DockPos=-1,Queue_FloatLeft=0,Queue_FloatTop=0,Queue_FloatRightX=0,"
  560. "Menu_Visible=1,Menu_DockedTo=TopDock,Menu_LastDock=TopDock,Menu_DockRow=0,Menu_DockPos=0,Menu_FloatLeft=0,Menu_FloatTop=0,Menu_FloatRightX=0,"
  561. "Preferences_Visible=1,Preferences_DockedTo=TopDock,Preferences_LastDock=TopDock,Preferences_DockRow=1,Preferences_DockPos=228,Preferences_FloatLeft=0,Preferences_FloatTop=0,Preferences_FloatRightX=0,"
  562. "Session_Visible=0,Session_DockedTo=TopDock,Session_LastDock=TopDock,Session_DockRow=1,Session_DockPos=602,Session_FloatLeft=380,Session_FloatTop=197,Session_FloatRightX=0,"
  563. "Sort_Visible=0,Sort_DockedTo=TopDock,Sort_LastDock=TopDock,Sort_DockRow=2,Sort_DockPos=0,Sort_FloatLeft=0,Sort_FloatTop=0,Sort_FloatRightX=0,"
  564. "Commands_Visible=1,Commands_DockedTo=TopDock,Commands_LastDock=TopDock,Commands_DockRow=1,Commands_DockPos=0,Commands_FloatLeft=0,Commands_FloatTop=0,Commands_FloatRightX=0,"
  565. "Updates_Visible=1,Updates_DockedTo=TopDock,Updates_LastDock=TopDock,Updates_DockRow=1,Updates_DockPos=619,Updates_FloatLeft=0,Updates_FloatTop=0,Updates_FloatRightX=0,"
  566. "Transfer_Visible=1,Transfer_DockedTo=TopDock,Transfer_LastDock=TopDock,Transfer_DockRow=1,Transfer_DockPos=364,Transfer_FloatLeft=0,Transfer_FloatTop=0,Transfer_FloatRightX=0,"
  567. "CustomCommands_Visible=0,CustomCommands_DockedTo=TopDock,CustomCommands_LastDock=TopDock,CustomCommands_DockRow=3,CustomCommands_DockPos=0,CustomCommands_FloatLeft=0,CustomCommands_FloatTop=0,CustomCommands_FloatRightX=0,"
  568. "RemoteHistory_Visible=1,RemoteHistory_DockedTo=RemoteTopDock,RemoteHistory_LastDock=RemoteTopDock,RemoteHistory_DockRow=0,RemoteHistory_DockPos=172,RemoteHistory_FloatLeft=0,RemoteHistory_FloatTop=0,RemoteHistory_FloatRightX=0,"
  569. "RemoteNavigation_Visible=1,RemoteNavigation_DockedTo=RemoteTopDock,RemoteNavigation_LastDock=RemoteTopDock,RemoteNavigation_DockRow=0,RemoteNavigation_DockPos=252,RemoteNavigation_FloatLeft=0,RemoteNavigation_FloatTop=0,RemoteNavigation_FloatRightX=0,"
  570. "RemotePath_Visible=1,RemotePath_DockedTo=RemoteTopDock,RemotePath_LastDock=RemoteTopDock,RemotePath_DockRow=0,RemotePath_DockPos=0,RemotePath_FloatLeft=0,RemotePath_FloatTop=0,RemotePath_FloatRightX=0,"
  571. "RemoteFile_Visible=1,RemoteFile_DockedTo=RemoteTopDock,RemoteFile_LastDock=RemoteTopDock,RemoteFile_DockRow=1,RemoteFile_DockPos=0,RemoteFile_FloatLeft=0,RemoteFile_FloatTop=0,RemoteFile_FloatRightX=0,"
  572. "RemoteSelection_Visible=1,RemoteSelection_DockedTo=RemoteTopDock,RemoteSelection_LastDock=RemoteTopDock,RemoteSelection_DockRow=1,RemoteSelection_DockPos=345,RemoteSelection_FloatLeft=0,RemoteSelection_FloatTop=0,RemoteSelection_FloatRightX=0,"
  573. "LocalHistory_Visible=1,LocalHistory_DockedTo=LocalTopDock,LocalHistory_LastDock=LocalTopDock,LocalHistory_DockRow=0,LocalHistory_DockPos=207,LocalHistory_FloatLeft=0,LocalHistory_FloatTop=0,LocalHistory_FloatRightX=0,"
  574. "LocalNavigation_Visible=1,LocalNavigation_DockedTo=LocalTopDock,LocalNavigation_LastDock=LocalTopDock,LocalNavigation_DockRow=0,LocalNavigation_DockPos=287,LocalNavigation_FloatLeft=0,LocalNavigation_FloatTop=0,LocalNavigation_FloatRightX=0,"
  575. "LocalPath_Visible=1,LocalPath_DockedTo=LocalTopDock,LocalPath_LastDock=LocalTopDock,LocalPath_DockRow=0,LocalPath_DockPos=0,LocalPath_FloatLeft=0,LocalPath_FloatTop=0,LocalPath_FloatRightX=0,"
  576. "LocalFile_Visible=1,LocalFile_DockedTo=LocalTopDock,LocalFile_LastDock=LocalTopDock,LocalFile_DockRow=1,LocalFile_DockPos=0,LocalFile_FloatLeft=0,LocalFile_FloatTop=0,LocalFile_FloatRightX=0,"
  577. "LocalSelection_Visible=1,LocalSelection_DockedTo=LocalTopDock,LocalSelection_LastDock=LocalTopDock,LocalSelection_DockRow=1,LocalSelection_DockPos=329,LocalSelection_FloatLeft=0,LocalSelection_FloatTop=0,LocalSelection_FloatRightX=0,"
  578. "Toolbar2_Visible=0,Toolbar2_DockedTo=BottomDock,Toolbar2_LastDock=BottomDock,Toolbar2_DockRow=1,Toolbar2_DockPos=0,Toolbar2_FloatLeft=0,Toolbar2_FloatTop=0,Toolbar2_FloatRightX=1,"
  579. "CommandLine_Visible=0,CommandLine_DockedTo=BottomDock,CommandLine_LastDock=BottomDock,CommandLine_DockRow=0,CommandLine_DockPos=0,CommandLine_FloatLeft=0,CommandLine_FloatTop=0,CommandLine_FloatRightX=0,") +
  580. PixelsPerInchToolbarValue;
  581. FScpCommander.CurrentPanel = osLocal;
  582. FScpCommander.CompareByTime = true;
  583. FScpCommander.CompareBySize = false;
  584. FScpCommander.TreeOnLeft = false;
  585. FScpCommander.ExplorerKeyboardShortcuts = false;
  586. FScpCommander.SystemContextMenu = false;
  587. FScpCommander.RemotePanel.DirViewParams = L"0;1;0|150,1;70,1;150,1;79,1;62,1;55,0;20,0;150,0;125,0;@" + SaveDefaultPixelsPerInch() + L"|6;7;8;0;1;2;3;4;5";
  588. FScpCommander.RemotePanel.StatusBar = true;
  589. FScpCommander.RemotePanel.DriveView = false;
  590. FScpCommander.RemotePanel.DriveViewHeight = 100;
  591. FScpCommander.RemotePanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  592. FScpCommander.RemotePanel.DriveViewWidth = 100;
  593. FScpCommander.RemotePanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  594. FScpCommander.LocalPanel.DirViewParams = L"0;1;0|150,1;70,1;120,1;150,1;55,0;55,0;@" + SaveDefaultPixelsPerInch() + L"|5;0;1;2;3;4";
  595. FScpCommander.LocalPanel.StatusBar = true;
  596. FScpCommander.LocalPanel.DriveView = false;
  597. FScpCommander.LocalPanel.DriveViewHeight = 100;
  598. FScpCommander.LocalPanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  599. FScpCommander.LocalPanel.DriveViewWidth = 100;
  600. FScpCommander.LocalPanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  601. FBookmarks->Clear();
  602. }
  603. //---------------------------------------------------------------------------
  604. void __fastcall TWinConfiguration::DefaultLocalized()
  605. {
  606. TGUIConfiguration::DefaultLocalized();
  607. if (FCustomCommandsDefaults)
  608. {
  609. FCustomCommandList->Clear();
  610. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_EXECUTE), L"\"./!\"", 0);
  611. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TOUCH), L"touch \"!\"", ccApplyToDirectories | ccRecursive);
  612. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TAR),
  613. FORMAT(L"tar -cz -f \"!?%s?archive.tgz!\" !&",
  614. (LoadStr(CUSTOM_COMMAND_TAR_ARCHIVE))), ccApplyToDirectories);
  615. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_UNTAR),
  616. FORMAT(L"tar -xz --directory=\"!?%s?.!\" -f \"!\"",
  617. (LoadStr(CUSTOM_COMMAND_UNTAR_DIRECTORY))), 0);
  618. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_GREP),
  619. FORMAT(L"grep \"!?%s?!\" !&", (LoadStr(CUSTOM_COMMAND_GREP_PATTERN))),
  620. ccShowResults);
  621. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_FC),
  622. L"cmd /c fc \"!\" \"\!^!\" | more && pause", ccLocal);
  623. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_PRINT), L"notepad.exe /p \"!\"", ccLocal);
  624. FCustomCommandList->Reset();
  625. FCustomCommandsDefaults = true;
  626. }
  627. }
  628. //---------------------------------------------------------------------------
  629. bool __fastcall TWinConfiguration::DetectRegistryStorage(HKEY RootKey)
  630. {
  631. bool Result = false;
  632. TRegistryStorage * Storage = new TRegistryStorage(RegistryStorageKey, RootKey);
  633. try
  634. {
  635. if (Storage->OpenRootKey(false))
  636. {
  637. Result = true;
  638. Storage->CloseSubKey();
  639. }
  640. }
  641. __finally
  642. {
  643. delete Storage;
  644. }
  645. return Result;
  646. }
  647. //---------------------------------------------------------------------------
  648. bool __fastcall TWinConfiguration::CanWriteToStorage()
  649. {
  650. bool Result = false;
  651. try
  652. {
  653. THierarchicalStorage * Storage = CreateScpStorage(false);
  654. try
  655. {
  656. Storage->AccessMode = smReadWrite;
  657. // This is actually not very good test, as we end up potentially with
  658. // the very same config, and TIniFileStorage file won't even try to
  659. // write the file then. Lucliky, we use this for empty config only,
  660. // so we end up with at least an empty section.
  661. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  662. {
  663. Storage->WriteBool(L"WriteTest", true);
  664. Storage->DeleteValue(L"WriteTest");
  665. }
  666. Storage->Flush();
  667. }
  668. __finally
  669. {
  670. delete Storage;
  671. }
  672. Result = true;
  673. }
  674. catch(...)
  675. {
  676. }
  677. return Result;
  678. }
  679. //---------------------------------------------------------------------------
  680. TStorage __fastcall TWinConfiguration::GetStorage()
  681. {
  682. if (FStorage == stDetect)
  683. {
  684. if (FindResourceEx(NULL, RT_RCDATA, L"WINSCP_SESSION",
  685. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
  686. {
  687. FTemporarySessionFile =
  688. IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscps.tmp";
  689. DumpResourceToFile(L"WINSCP_SESSION", FTemporarySessionFile);
  690. FEmbeddedSessions = true;
  691. FTemporaryKeyFile =
  692. IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscpk.tmp";
  693. if (!DumpResourceToFile(L"WINSCP_KEY", FTemporaryKeyFile))
  694. {
  695. FTemporaryKeyFile = L"";
  696. }
  697. }
  698. FStorage = stIniFile;
  699. if (!FileExists(::ApiPath(IniFileStorageNameForReading)))
  700. {
  701. if (DetectRegistryStorage(HKEY_CURRENT_USER) ||
  702. DetectRegistryStorage(HKEY_LOCAL_MACHINE) ||
  703. // FStorage is now stIniFile, so this tests writing to an INI file.
  704. // As we fall back to user profile folder, when application folder
  705. // is not writtable, it is actually unlikely that the below test ever fails.
  706. !CanWriteToStorage())
  707. {
  708. FStorage = stRegistry;
  709. }
  710. }
  711. }
  712. TStorage Result = TCustomWinConfiguration::GetStorage();
  713. return Result;
  714. }
  715. //---------------------------------------------------------------------------
  716. void __fastcall TWinConfiguration::Saved()
  717. {
  718. TCustomWinConfiguration::Saved();
  719. FBookmarks->ModifyAll(false);
  720. FCustomCommandList->Reset();
  721. FEditorList->Saved();
  722. }
  723. //---------------------------------------------------------------------------
  724. void __fastcall TWinConfiguration::RecryptPasswords(TStrings * RecryptPasswordErrors)
  725. {
  726. TCustomWinConfiguration::RecryptPasswords(RecryptPasswordErrors);
  727. try
  728. {
  729. TTerminalManager * Manager = TTerminalManager::Instance(false);
  730. assert(Manager != NULL);
  731. if (Manager != NULL)
  732. {
  733. Manager->RecryptPasswords();
  734. }
  735. }
  736. catch (Exception & E)
  737. {
  738. UnicodeString Message;
  739. if (ExceptionMessage(&E, Message))
  740. {
  741. // we do not expect this really to happen,
  742. // so we do not bother providing context
  743. RecryptPasswordErrors->Add(Message);
  744. }
  745. }
  746. }
  747. //---------------------------------------------------------------------------
  748. bool __fastcall TWinConfiguration::GetUseMasterPassword()
  749. {
  750. return FUseMasterPassword;
  751. }
  752. //---------------------------------------------------------------------------
  753. THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool SessionList)
  754. {
  755. THierarchicalStorage * Result;
  756. if (SessionList && !FTemporarySessionFile.IsEmpty())
  757. {
  758. Result = new TIniFileStorage(FTemporarySessionFile);
  759. }
  760. else
  761. {
  762. Result = TCustomWinConfiguration::CreateScpStorage(SessionList);
  763. }
  764. return Result;
  765. }
  766. //---------------------------------------------------------------------------
  767. // duplicated from core\configuration.cpp
  768. #define LASTELEM(ELEM) \
  769. ELEM.SubString(ELEM.LastDelimiter(L".>")+1, ELEM.Length() - ELEM.LastDelimiter(L".>"))
  770. #define BLOCK(KEY, CANCREATE, BLOCK) \
  771. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  772. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  773. #define REGCONFIG(CANCREATE) \
  774. BLOCK(L"Interface", CANCREATE, \
  775. KEYEX(Integer,DoubleClickAction, L"CopyOnDoubleClick"); \
  776. KEY(Bool, CopyOnDoubleClickConfirmation); \
  777. KEY(Bool, DDAllowMove); \
  778. KEY(Bool, DDAllowMoveInit); \
  779. KEYEX(Integer, DDTransferConfirmation, L"DDTransferConfirmation2"); \
  780. KEY(String, DDTemporaryDirectory); \
  781. KEY(Bool, DDWarnLackOfTempSpace); \
  782. KEY(Float, DDWarnLackOfTempSpaceRatio); \
  783. KEY(Bool, DeleteToRecycleBin); \
  784. KEY(Bool, DimmHiddenFiles); \
  785. KEY(Bool, RenameWholeName); \
  786. KEY(Bool, SelectDirectories); \
  787. KEY(String, SelectMask); \
  788. KEY(Bool, ShowHiddenFiles); \
  789. KEY(Integer, FormatSizeBytes); \
  790. KEY(Bool, ShowInaccesibleDirectories); \
  791. KEY(Bool, ConfirmTransferring); \
  792. KEY(Bool, ConfirmDeleting); \
  793. KEY(Bool, ConfirmRecycling); \
  794. KEY(Bool, ConfirmClosingSession); \
  795. KEY(String, AutoStartSession); \
  796. KEY(Bool, UseLocationProfiles); \
  797. KEY(Bool, UseSharedBookmarks); \
  798. KEY(Integer, LocaleSafe); \
  799. KEY(Bool, DDExtEnabled); \
  800. KEY(Integer, DDExtTimeout); \
  801. KEY(Bool, DefaultDirIsHome); \
  802. KEY(Bool, TemporaryDirectoryAppendSession); \
  803. KEY(Bool, TemporaryDirectoryAppendPath); \
  804. KEY(Bool, TemporaryDirectoryCleanup); \
  805. KEY(Bool, ConfirmTemporaryDirectoryCleanup); \
  806. KEY(Bool, PreservePanelState); \
  807. KEY(String, Theme); \
  808. KEY(String, LastStoredSession); \
  809. KEY(Bool, AutoSaveWorkspace); \
  810. KEY(Bool, AutoSaveWorkspacePasswords); \
  811. KEY(String, AutoWorkspace); \
  812. KEY(Integer, PathInCaption); \
  813. KEY(Bool, MinimizeToTray); \
  814. KEY(Bool, BalloonNotifications); \
  815. KEY(Integer, NotificationsTimeout); \
  816. KEY(Integer, NotificationsStickTime); \
  817. KEY(Bool, CopyParamAutoSelectNotice); \
  818. KEY(Bool, LockToolbars); \
  819. KEY(Bool, SelectiveToolbarText); \
  820. KEY(Bool, AutoOpenInPutty); \
  821. KEY(Bool, RefreshRemotePanel); \
  822. KEY(DateTime, RefreshRemotePanelInterval); \
  823. KEY(Bool, FullRowSelect); \
  824. KEY(Bool, OfferedEditorAutoConfig); \
  825. KEY(Integer, LastMonitor); \
  826. KEY(String, VersionHistory); \
  827. KEY(Bool, EnableQueueByDefault); \
  828. KEY(String, OpenedStoredSessionFolders); \
  829. KEY(Bool, AutoImportedFromPuttyOrFilezilla); \
  830. KEY(Integer, GenerateUrlComponents); \
  831. KEY(Bool, ExternalSessionInExistingInstance); \
  832. ); \
  833. BLOCK(L"Interface\\Editor", CANCREATE, \
  834. KEYEX(String, Editor.FontName, L"FontName2"); \
  835. KEY(Integer, Editor.FontSize); \
  836. KEY(Integer, Editor.FontStyle); \
  837. KEY(Integer, Editor.FontCharset); \
  838. KEY(Bool, Editor.WordWrap); \
  839. KEY(String, Editor.FindText); \
  840. KEY(String, Editor.ReplaceText); \
  841. KEY(Bool, Editor.FindMatchCase); \
  842. KEY(Bool, Editor.FindWholeWord); \
  843. KEY(Bool, Editor.FindDown); \
  844. KEY(Integer, Editor.TabSize); \
  845. KEY(Integer, Editor.MaxEditors); \
  846. KEY(Integer, Editor.EarlyClose); \
  847. KEY(Bool, Editor.SDIShellEditor); \
  848. KEY(String, Editor.WindowParams); \
  849. KEY(Integer, Editor.Encoding); \
  850. KEY(Bool, Editor.WarnOnEncodingFallback); \
  851. KEY(Bool, Editor.WarnOrLargeFileSize); \
  852. ); \
  853. BLOCK(L"Interface\\QueueView", CANCREATE, \
  854. KEY(Integer, QueueView.Height); \
  855. KEY(Integer, QueueView.HeightPixelsPerInch); \
  856. KEY(String, QueueView.Layout); \
  857. KEY(Integer, QueueView.Show); \
  858. KEY(Integer, QueueView.LastHideShow); \
  859. KEY(Bool, QueueView.ToolBar); \
  860. KEY(Bool, QueueView.Label); \
  861. ); \
  862. BLOCK(L"Interface\\Updates", CANCREATE, \
  863. KEY(Integer, FUpdates.Period); \
  864. KEY(DateTime, FUpdates.LastCheck); \
  865. KEY(Integer, FUpdates.HaveResults); \
  866. KEY(Integer, FUpdates.ShownResults); \
  867. KEY(Integer, FUpdates.BetaVersions); \
  868. KEY(Bool, FUpdates.ShowOnStartup); \
  869. KEY(Integer, FUpdates.ConnectionType); \
  870. KEY(String, FUpdates.ProxyHost); \
  871. KEY(Integer, FUpdates.ProxyPort); \
  872. KEY(Integer, FUpdates.Results.ForVersion); \
  873. KEY(Integer, FUpdates.Results.Version); \
  874. KEY(String, FUpdates.Results.Message); \
  875. KEY(Integer, FUpdates.Results.Critical); \
  876. KEY(String, FUpdates.Results.Release); \
  877. KEY(Bool, FUpdates.Results.Disabled); \
  878. KEY(String, FUpdates.Results.Url); \
  879. KEY(String, FUpdates.Results.UrlButton); \
  880. KEY(String, FUpdates.Results.NewsUrl); \
  881. KEYEX(Integer,FUpdates.Results.NewsSize.Width, L"NewsWidth"); \
  882. KEYEX(Integer,FUpdates.Results.NewsSize.Height, L"NewsHeight"); \
  883. KEY(String, FUpdates.DotNetVersion); \
  884. KEY(String, FUpdates.ConsoleVersion); \
  885. ); \
  886. BLOCK(L"Interface\\Explorer", CANCREATE, \
  887. KEY(String, ScpExplorer.ToolbarsLayout); \
  888. KEY(String, ScpExplorer.DirViewParams); \
  889. KEY(String, ScpExplorer.LastLocalTargetDirectory); \
  890. KEY(Bool, ScpExplorer.SessionsTabs); \
  891. KEY(Bool, ScpExplorer.StatusBar); \
  892. KEY(String, ScpExplorer.WindowParams); \
  893. KEY(Integer, ScpExplorer.ViewStyle); \
  894. KEY(Bool, ScpExplorer.ShowFullAddress); \
  895. KEY(Bool, ScpExplorer.DriveView); \
  896. KEY(Integer, ScpExplorer.DriveViewWidth); \
  897. KEY(Integer, ScpExplorer.DriveViewWidthPixelsPerInch); \
  898. ); \
  899. BLOCK(L"Interface\\Commander", CANCREATE, \
  900. KEY(String, ScpCommander.ToolbarsLayout); \
  901. KEY(Integer, ScpCommander.CurrentPanel); \
  902. KEY(Float, ScpCommander.LocalPanelWidth); \
  903. KEY(Bool, ScpCommander.SwappedPanels); \
  904. KEY(Bool, ScpCommander.SessionsTabs); \
  905. KEY(Bool, ScpCommander.StatusBar); \
  906. KEY(String, ScpCommander.WindowParams); \
  907. KEYEX(Integer, ScpCommander.NortonLikeMode, L"ExplorerStyleSelection"); \
  908. KEY(Bool, ScpCommander.PreserveLocalDirectory); \
  909. KEY(Bool, ScpCommander.CompareByTime); \
  910. KEY(Bool, ScpCommander.CompareBySize); \
  911. KEY(Bool, ScpCommander.TreeOnLeft); \
  912. KEY(Bool, ScpCommander.ExplorerKeyboardShortcuts); \
  913. KEY(Bool, ScpCommander.SystemContextMenu); \
  914. ); \
  915. BLOCK(L"Interface\\Commander\\LocalPanel", CANCREATE, \
  916. KEY(String, ScpCommander.LocalPanel.DirViewParams); \
  917. KEY(Bool, ScpCommander.LocalPanel.StatusBar); \
  918. KEY(Bool, ScpCommander.LocalPanel.DriveView); \
  919. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeight); \
  920. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeightPixelsPerInch); \
  921. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidth); \
  922. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidthPixelsPerInch); \
  923. ); \
  924. BLOCK(L"Interface\\Commander\\RemotePanel", CANCREATE, \
  925. KEY(String, ScpCommander.RemotePanel.DirViewParams); \
  926. KEY(Bool, ScpCommander.RemotePanel.StatusBar); \
  927. KEY(Bool, ScpCommander.RemotePanel.DriveView); \
  928. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeight); \
  929. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeightPixelsPerInch); \
  930. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidth); \
  931. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidthPixelsPerInch); \
  932. ); \
  933. BLOCK(L"Logging", CANCREATE, \
  934. KEY(Bool, LogWindowOnStartup); \
  935. KEY(String, LogWindowParams); \
  936. ); \
  937. BLOCK(L"Security", CANCREATE, \
  938. KEYEX(Bool, FUseMasterPassword, L"UseMasterPassword"); \
  939. KEYEX(String,FMasterPasswordVerifier, L"MasterPasswordVerifier"); \
  940. );
  941. //---------------------------------------------------------------------------
  942. void __fastcall TWinConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  943. {
  944. TCustomWinConfiguration::SaveData(Storage, All);
  945. // duplicated from core\configuration.cpp
  946. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  947. REGCONFIG(true);
  948. #undef KEYEX
  949. if (Storage->OpenSubKey(L"Bookmarks", true))
  950. {
  951. FBookmarks->Save(Storage, All);
  952. Storage->CloseSubKey();
  953. }
  954. if ((All && !FCustomCommandsDefaults) || FCustomCommandList->Modified)
  955. {
  956. FCustomCommandList->Save(Storage);
  957. }
  958. if ((All || FEditorList->Modified) &&
  959. Storage->OpenSubKey(L"Interface\\Editor", true, true))
  960. try
  961. {
  962. FEditorList->Save(Storage);
  963. }
  964. __finally
  965. {
  966. Storage->CloseSubKey();
  967. }
  968. }
  969. //---------------------------------------------------------------------------
  970. void __fastcall TWinConfiguration::LoadFrom(THierarchicalStorage * Storage)
  971. {
  972. FLegacyEditor = new TEditorPreferences();
  973. try
  974. {
  975. FLegacyEditor->LegacyDefaults();
  976. TCustomWinConfiguration::LoadFrom(Storage);
  977. // This needs to be done even if there's no Configuration key in the storage,
  978. // so it cannot be in LoadData
  979. int EditorCount = FEditorList->Count;
  980. if (EditorCount == 0)
  981. {
  982. TEditorPreferences * AlternativeEditor = NULL;
  983. try
  984. {
  985. if (FLegacyEditor->Data->Editor == edInternal)
  986. {
  987. if (!FLegacyEditor->Data->ExternalEditor.IsEmpty())
  988. {
  989. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  990. AlternativeEditor->GetData()->Editor = edExternal;
  991. FLegacyEditor->GetData()->ExternalEditor = L"";
  992. }
  993. }
  994. else
  995. {
  996. if (FLegacyEditor->Data->ExternalEditor.IsEmpty())
  997. {
  998. FLegacyEditor->GetData()->Editor = edInternal;
  999. }
  1000. else
  1001. {
  1002. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  1003. AlternativeEditor->GetData()->Editor = edInternal;
  1004. }
  1005. }
  1006. }
  1007. catch(...)
  1008. {
  1009. delete AlternativeEditor;
  1010. throw;
  1011. }
  1012. FEditorList->Add(FLegacyEditor);
  1013. FLegacyEditor = NULL;
  1014. if (AlternativeEditor != NULL)
  1015. {
  1016. FEditorList->Add(AlternativeEditor);
  1017. }
  1018. }
  1019. }
  1020. __finally
  1021. {
  1022. delete FLegacyEditor;
  1023. FLegacyEditor = NULL;
  1024. }
  1025. if (FUpdates.ConnectionType == -1)
  1026. {
  1027. FUpdates.ConnectionType = (FUpdates.ProxyHost.IsEmpty() ? ctAuto : ctProxy);
  1028. }
  1029. AddVersionToHistory();
  1030. }
  1031. //---------------------------------------------------------------------------
  1032. void __fastcall TWinConfiguration::LoadData(THierarchicalStorage * Storage)
  1033. {
  1034. TCustomWinConfiguration::LoadData(Storage);
  1035. // duplicated from core\configuration.cpp
  1036. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  1037. #pragma warn -eas
  1038. REGCONFIG(false);
  1039. #pragma warn +eas
  1040. #undef KEYEX
  1041. if (Storage->OpenSubKey(L"Bookmarks", false))
  1042. {
  1043. FBookmarks->Load(Storage);
  1044. Storage->CloseSubKey();
  1045. }
  1046. if (Storage->HasSubKey("CustomCommands"))
  1047. {
  1048. FCustomCommandList->Load(Storage);
  1049. FCustomCommandsDefaults = false;
  1050. }
  1051. else if (FCustomCommandList->Modified)
  1052. {
  1053. // can this (=reloading of configuration) even happen?
  1054. // if it does, shouldn't we reset default commands?
  1055. FAIL;
  1056. FCustomCommandList->Clear();
  1057. FCustomCommandsDefaults = false;
  1058. }
  1059. FCustomCommandList->Reset();
  1060. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1061. try
  1062. {
  1063. FEditorList->Clear();
  1064. FEditorList->Load(Storage);
  1065. }
  1066. __finally
  1067. {
  1068. Storage->CloseSubKey();
  1069. }
  1070. // load legacy editor configuration
  1071. assert(FLegacyEditor != NULL);
  1072. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1073. {
  1074. try
  1075. {
  1076. FLegacyEditor->Load(Storage, true);
  1077. }
  1078. __finally
  1079. {
  1080. Storage->CloseSubKey();
  1081. }
  1082. }
  1083. }
  1084. //---------------------------------------------------------------------------
  1085. void __fastcall TWinConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  1086. {
  1087. TCustomWinConfiguration::LoadAdmin(Storage);
  1088. FDisableOpenEdit = Storage->ReadBool(L"DisableOpenEdit", FDisableOpenEdit);
  1089. FDefaultUpdatesPeriod = Storage->ReadInteger(L"DefaultUpdatesPeriod", FDefaultUpdatesPeriod);
  1090. }
  1091. //---------------------------------------------------------------------------
  1092. void __fastcall TWinConfiguration::CopyData(THierarchicalStorage * Source, THierarchicalStorage * Target)
  1093. {
  1094. TCustomWinConfiguration::CopyData(Source, Target);
  1095. if (Source->OpenSubKey(ConfigurationSubKey, false))
  1096. {
  1097. if (Target->OpenSubKey(ConfigurationSubKey, true))
  1098. {
  1099. Target->WriteString(L"JumpList", Source->ReadString(L"JumpList", L""));
  1100. Target->WriteString(L"JumpListWorkspaces", Source->ReadString(L"JumpListWorkspaces", L""));
  1101. Target->CloseSubKey();
  1102. }
  1103. Source->CloseSubKey();
  1104. }
  1105. }
  1106. //---------------------------------------------------------------------------
  1107. void __fastcall TWinConfiguration::ClearTemporaryLoginData()
  1108. {
  1109. if (!FTemporaryKeyFile.IsEmpty())
  1110. {
  1111. DeleteFile(::ApiPath(FTemporaryKeyFile));
  1112. FTemporaryKeyFile = L"";
  1113. }
  1114. }
  1115. //---------------------------------------------------------------------------
  1116. void __fastcall TWinConfiguration::AddVersionToHistory()
  1117. {
  1118. int CurrentVersion = CompoundVersion;
  1119. int From = 1;
  1120. bool CurrentVersionPresent = false;
  1121. while (!CurrentVersionPresent && (From < FVersionHistory.Length()))
  1122. {
  1123. UnicodeString VersionInfo = CopyToChars(FVersionHistory, From, L";", true);
  1124. UnicodeString VersionStr = ::CutToChar(VersionInfo, L',', true);
  1125. int Version;
  1126. if (TryStrToInt(VersionStr, Version) &&
  1127. (Version == CurrentVersion))
  1128. {
  1129. CurrentVersionPresent = true;
  1130. }
  1131. }
  1132. if (!CurrentVersionPresent)
  1133. {
  1134. UnicodeString CurrentVersionInfo =
  1135. IntToStr(CurrentVersion) + L"," + FileInfoString[L"ReleaseType"];
  1136. AddToList(FVersionHistory, CurrentVersionInfo, L';');
  1137. }
  1138. Usage->Set(L"AnyBetaUsed", AnyBetaInVersionHistory);
  1139. }
  1140. //---------------------------------------------------------------------------
  1141. bool __fastcall TWinConfiguration::DoIsBeta(const UnicodeString & ReleaseType)
  1142. {
  1143. return AnsiSameText(ReleaseType, L"beta") || AnsiSameText(ReleaseType, L"rc");
  1144. }
  1145. //---------------------------------------------------------------------------
  1146. bool __fastcall TWinConfiguration::GetIsBeta()
  1147. {
  1148. return DoIsBeta(FileInfoString[L"ReleaseType"]);
  1149. }
  1150. //---------------------------------------------------------------------------
  1151. bool __fastcall TWinConfiguration::GetAnyBetaInVersionHistory()
  1152. {
  1153. int From = 1;
  1154. bool AnyBeta = false;
  1155. while (!AnyBeta && (From < VersionHistory.Length()))
  1156. {
  1157. UnicodeString VersionInfo = CopyToChars(VersionHistory, From, L";", true);
  1158. ::CutToChar(VersionInfo, L',', true);
  1159. UnicodeString ReleaseType = ::CutToChar(VersionInfo, ',', true);
  1160. if (DoIsBeta(ReleaseType))
  1161. {
  1162. AnyBeta = true;
  1163. }
  1164. }
  1165. return AnyBeta;
  1166. }
  1167. //---------------------------------------------------------------------------
  1168. bool __fastcall TWinConfiguration::GetDDExtInstalled()
  1169. {
  1170. if (FDDExtInstalled < 0)
  1171. {
  1172. if (IsWin64())
  1173. {
  1174. // WORKAROUND
  1175. // We cannot load 64-bit COM class into 32-bit process,
  1176. // so we fallback to querying registration keys
  1177. #define CLSID_SIZE 39
  1178. wchar_t ClassID[CLSID_SIZE];
  1179. StringFromGUID2(CLSID_ShellExtension, ClassID, LENOF(ClassID));
  1180. NULL_TERMINATE(ClassID);
  1181. UnicodeString SubKey = UnicodeString(L"CLSID\\") + ClassID;
  1182. HKEY HKey;
  1183. LONG Result = RegOpenKeyEx(HKEY_CLASSES_ROOT, SubKey.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &HKey);
  1184. if (Result == ERROR_SUCCESS)
  1185. {
  1186. RegCloseKey(HKey);
  1187. FDDExtInstalled = 1;
  1188. }
  1189. else
  1190. {
  1191. FDDExtInstalled = 0;
  1192. }
  1193. }
  1194. else
  1195. {
  1196. void * DragExtRef;
  1197. int CreateResult =
  1198. CoCreateInstance(CLSID_ShellExtension, NULL,
  1199. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
  1200. &DragExtRef);
  1201. bool Result = (CreateResult == S_OK);
  1202. FDDExtInstalled = (Result ? 1 : 0);
  1203. if (Result)
  1204. {
  1205. reinterpret_cast<IUnknown *>(DragExtRef)->Release();
  1206. CoFreeUnusedLibraries();
  1207. }
  1208. }
  1209. }
  1210. return (FDDExtInstalled > 0);
  1211. }
  1212. //---------------------------------------------------------------------------
  1213. RawByteString __fastcall TWinConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString Key)
  1214. {
  1215. RawByteString Dummy;
  1216. RawByteString Result;
  1217. if (GetExternalEncryptedPassword(Password, Dummy) ||
  1218. !FUseMasterPassword)
  1219. {
  1220. // already-strongly encrypted
  1221. // or no master password set, so we cannot strongly-encrypt it
  1222. Result = Password;
  1223. }
  1224. else
  1225. {
  1226. UnicodeString PasswordText =
  1227. TCustomWinConfiguration::DecryptPassword(Password, Key);
  1228. if (!PasswordText.IsEmpty())
  1229. {
  1230. // can be not set for instance, when editing=>saving site with no prior password
  1231. AskForMasterPasswordIfNotSet();
  1232. Password = ScramblePassword(PasswordText);
  1233. AES256EncyptWithMAC(Password, FPlainMasterPasswordEncrypt, Result);
  1234. Result = SetExternalEncryptedPassword(Result);
  1235. }
  1236. }
  1237. return Result;
  1238. }
  1239. //---------------------------------------------------------------------------
  1240. UnicodeString __fastcall TWinConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
  1241. {
  1242. UnicodeString Result;
  1243. RawByteString Buf;
  1244. if (GetExternalEncryptedPassword(Password, Buf))
  1245. {
  1246. if (FDontDecryptPasswords == 0)
  1247. {
  1248. // As opposite to AskForMasterPasswordIfNotSet, we test here
  1249. // for decrypt password. This is important while recrypting password,
  1250. // when clearing master password, when encrypt password is already empty.
  1251. if (FPlainMasterPasswordDecrypt.IsEmpty())
  1252. {
  1253. AskForMasterPassword();
  1254. }
  1255. if (!AES256DecryptWithMAC(Buf, FPlainMasterPasswordDecrypt, Buf) ||
  1256. !UnscramblePassword(Buf, Result))
  1257. {
  1258. throw Exception(LoadStr(DECRYPT_PASSWORD_ERROR));
  1259. }
  1260. }
  1261. else
  1262. {
  1263. Abort();
  1264. }
  1265. }
  1266. else
  1267. {
  1268. Result = TCustomWinConfiguration::DecryptPassword(Password, Key);
  1269. }
  1270. return Result;
  1271. }
  1272. //---------------------------------------------------------------------------
  1273. void __fastcall TWinConfiguration::SetMasterPassword(UnicodeString value)
  1274. {
  1275. // just stores the plain-text version of the password
  1276. // we can get here even if master password is off,
  1277. // when we encounter stray encrypted password (e.g. manually imported site),
  1278. // make sure we do not set encrypt password to avoid starting encrypting
  1279. // new passwords
  1280. // (this is bit of edge case, not really well tested)
  1281. if (!FUseMasterPassword)
  1282. {
  1283. FPlainMasterPasswordDecrypt = value;
  1284. }
  1285. else if (ALWAYS_TRUE(FUseMasterPassword) &&
  1286. ALWAYS_TRUE(ValidateMasterPassword(value)))
  1287. {
  1288. FPlainMasterPasswordEncrypt = value;
  1289. FPlainMasterPasswordDecrypt = value;
  1290. }
  1291. }
  1292. //---------------------------------------------------------------------------
  1293. void __fastcall TWinConfiguration::ChangeMasterPassword(
  1294. UnicodeString value, TStrings * RecryptPasswordErrors)
  1295. {
  1296. RawByteString Verifier;
  1297. AES256CreateVerifier(value, Verifier);
  1298. FMasterPasswordVerifier = BytesToHex(Verifier);
  1299. FPlainMasterPasswordEncrypt = value;
  1300. FUseMasterPassword = true;
  1301. try
  1302. {
  1303. RecryptPasswords(RecryptPasswordErrors);
  1304. }
  1305. __finally
  1306. {
  1307. FPlainMasterPasswordDecrypt = value;
  1308. }
  1309. }
  1310. //---------------------------------------------------------------------------
  1311. bool __fastcall TWinConfiguration::ValidateMasterPassword(UnicodeString value)
  1312. {
  1313. assert(UseMasterPassword);
  1314. assert(!FMasterPasswordVerifier.IsEmpty());
  1315. bool Result = AES256Verify(value, HexToBytes(FMasterPasswordVerifier));
  1316. return Result;
  1317. }
  1318. //---------------------------------------------------------------------------
  1319. void __fastcall TWinConfiguration::ClearMasterPassword(TStrings * RecryptPasswordErrors)
  1320. {
  1321. FMasterPasswordVerifier = L"";
  1322. FUseMasterPassword = false;
  1323. Shred(FPlainMasterPasswordEncrypt);
  1324. try
  1325. {
  1326. RecryptPasswords(RecryptPasswordErrors);
  1327. }
  1328. __finally
  1329. {
  1330. Shred(FPlainMasterPasswordDecrypt);
  1331. }
  1332. }
  1333. //---------------------------------------------------------------------------
  1334. void __fastcall TWinConfiguration::AskForMasterPassword()
  1335. {
  1336. if (FMasterPasswordSession > 0)
  1337. {
  1338. if (FMasterPasswordSessionAsked)
  1339. {
  1340. Abort();
  1341. }
  1342. // set before call to OnMasterPasswordPrompt as it may abort
  1343. FMasterPasswordSessionAsked = true;
  1344. }
  1345. if (FOnMasterPasswordPrompt == NULL)
  1346. {
  1347. throw Exception(L"Master password handler not set");
  1348. }
  1349. else
  1350. {
  1351. FOnMasterPasswordPrompt();
  1352. assert(!FPlainMasterPasswordDecrypt.IsEmpty());
  1353. }
  1354. }
  1355. //---------------------------------------------------------------------------
  1356. void __fastcall TWinConfiguration::AskForMasterPasswordIfNotSet()
  1357. {
  1358. if (FPlainMasterPasswordEncrypt.IsEmpty())
  1359. {
  1360. AskForMasterPassword();
  1361. }
  1362. }
  1363. //---------------------------------------------------------------------------
  1364. void __fastcall TWinConfiguration::BeginMasterPasswordSession()
  1365. {
  1366. // We do not expect nesting
  1367. assert(FMasterPasswordSession == 0);
  1368. assert(!FMasterPasswordSessionAsked || (FMasterPasswordSession > 0));
  1369. // This should better be thread-specific
  1370. FMasterPasswordSession++;
  1371. }
  1372. //---------------------------------------------------------------------------
  1373. void __fastcall TWinConfiguration::EndMasterPasswordSession()
  1374. {
  1375. if (ALWAYS_TRUE(FMasterPasswordSession > 0))
  1376. {
  1377. FMasterPasswordSession--;
  1378. }
  1379. FMasterPasswordSessionAsked = false;
  1380. }
  1381. //---------------------------------------------------------------------------
  1382. void __fastcall TWinConfiguration::SetLogWindowOnStartup(bool value)
  1383. {
  1384. SET_CONFIG_PROPERTY(LogWindowOnStartup);
  1385. }
  1386. //---------------------------------------------------------------------------
  1387. void __fastcall TWinConfiguration::SetLogWindowParams(UnicodeString value)
  1388. {
  1389. SET_CONFIG_PROPERTY(LogWindowParams);
  1390. }
  1391. //---------------------------------------------------------------------------
  1392. void __fastcall TWinConfiguration::SetDDAllowMove(bool value)
  1393. {
  1394. SET_CONFIG_PROPERTY(DDAllowMove);
  1395. }
  1396. //---------------------------------------------------------------------------
  1397. void __fastcall TWinConfiguration::SetDDAllowMoveInit(bool value)
  1398. {
  1399. SET_CONFIG_PROPERTY(DDAllowMoveInit);
  1400. }
  1401. //---------------------------------------------------------------------------
  1402. void __fastcall TWinConfiguration::SetDDTransferConfirmation(TAutoSwitch value)
  1403. {
  1404. SET_CONFIG_PROPERTY(DDTransferConfirmation);
  1405. }
  1406. //---------------------------------------------------------------------------
  1407. void __fastcall TWinConfiguration::SetDDTemporaryDirectory(UnicodeString value)
  1408. {
  1409. SET_CONFIG_PROPERTY(DDTemporaryDirectory);
  1410. }
  1411. //---------------------------------------------------------------------------
  1412. void __fastcall TWinConfiguration::SetDDExtEnabled(bool value)
  1413. {
  1414. SET_CONFIG_PROPERTY(DDExtEnabled);
  1415. }
  1416. //---------------------------------------------------------------------------
  1417. void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
  1418. {
  1419. SET_CONFIG_PROPERTY(DDExtTimeout);
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpace(bool value)
  1423. {
  1424. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpace);
  1425. }
  1426. //---------------------------------------------------------------------------
  1427. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpaceRatio(double value)
  1428. {
  1429. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpaceRatio);
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TWinConfiguration::SetScpExplorer(TScpExplorerConfiguration value)
  1433. {
  1434. SET_CONFIG_PROPERTY(ScpExplorer);
  1435. }
  1436. //---------------------------------------------------------------------------
  1437. void __fastcall TWinConfiguration::SetScpCommander(TScpCommanderConfiguration value)
  1438. {
  1439. SET_CONFIG_PROPERTY(ScpCommander);
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TWinConfiguration::SetEditor(TEditorConfiguration value)
  1443. {
  1444. SET_CONFIG_PROPERTY(Editor);
  1445. }
  1446. //---------------------------------------------------------------------------
  1447. void __fastcall TWinConfiguration::SetQueueView(TQueueViewConfiguration value)
  1448. {
  1449. SET_CONFIG_PROPERTY(QueueView);
  1450. }
  1451. //---------------------------------------------------------------------------
  1452. void __fastcall TWinConfiguration::SetEnableQueueByDefault(bool value)
  1453. {
  1454. SET_CONFIG_PROPERTY(EnableQueueByDefault);
  1455. }
  1456. //---------------------------------------------------------------------------
  1457. TUpdatesConfiguration __fastcall TWinConfiguration::GetUpdates()
  1458. {
  1459. TUpdatesConfiguration Result;
  1460. {
  1461. TGuard Guard(FCriticalSection);
  1462. Result = FUpdates;
  1463. }
  1464. return Result;
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. void __fastcall TWinConfiguration::SetUpdates(TUpdatesConfiguration value)
  1468. {
  1469. TGuard Guard(FCriticalSection);
  1470. // do not use SET_CONFIG_PROPERTY to avoid OnChange handler call (not synchronized)
  1471. FUpdates = value;
  1472. }
  1473. //---------------------------------------------------------------------------
  1474. void __fastcall TWinConfiguration::SetVersionHistory(UnicodeString value)
  1475. {
  1476. SET_CONFIG_PROPERTY(VersionHistory);
  1477. }
  1478. //---------------------------------------------------------------------------
  1479. void __fastcall TWinConfiguration::SetDeleteToRecycleBin(bool value)
  1480. {
  1481. SET_CONFIG_PROPERTY(DeleteToRecycleBin);
  1482. }
  1483. //---------------------------------------------------------------------------
  1484. void __fastcall TWinConfiguration::SetSelectDirectories(bool value)
  1485. {
  1486. SET_CONFIG_PROPERTY(SelectDirectories);
  1487. }
  1488. //---------------------------------------------------------------------------
  1489. void __fastcall TWinConfiguration::SetShowHiddenFiles(bool value)
  1490. {
  1491. SET_CONFIG_PROPERTY(ShowHiddenFiles);
  1492. }
  1493. //---------------------------------------------------------------------------
  1494. void __fastcall TWinConfiguration::SetFormatSizeBytes(TFormatBytesStyle value)
  1495. {
  1496. SET_CONFIG_PROPERTY(FormatSizeBytes);
  1497. }
  1498. //---------------------------------------------------------------------------
  1499. void __fastcall TWinConfiguration::SetShowInaccesibleDirectories(bool value)
  1500. {
  1501. SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
  1502. }
  1503. //---------------------------------------------------------------------------
  1504. void __fastcall TWinConfiguration::SetConfirmTransferring(bool value)
  1505. {
  1506. SET_CONFIG_PROPERTY(ConfirmTransferring);
  1507. }
  1508. //---------------------------------------------------------------------------
  1509. void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
  1510. {
  1511. SET_CONFIG_PROPERTY(ConfirmDeleting);
  1512. }
  1513. //---------------------------------------------------------------------------
  1514. void __fastcall TWinConfiguration::SetConfirmRecycling(bool value)
  1515. {
  1516. SET_CONFIG_PROPERTY(ConfirmRecycling);
  1517. }
  1518. //---------------------------------------------------------------------------
  1519. void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
  1520. {
  1521. SET_CONFIG_PROPERTY(UseLocationProfiles);
  1522. }
  1523. //---------------------------------------------------------------------------
  1524. void __fastcall TWinConfiguration::SetUseSharedBookmarks(bool value)
  1525. {
  1526. SET_CONFIG_PROPERTY(UseSharedBookmarks);
  1527. }
  1528. //---------------------------------------------------------------------------
  1529. void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
  1530. {
  1531. SET_CONFIG_PROPERTY(ConfirmClosingSession);
  1532. }
  1533. //---------------------------------------------------------------------------
  1534. void __fastcall TWinConfiguration::SetDoubleClickAction(TDoubleClickAction value)
  1535. {
  1536. SET_CONFIG_PROPERTY(DoubleClickAction);
  1537. }
  1538. //---------------------------------------------------------------------------
  1539. void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
  1540. {
  1541. SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
  1542. }
  1543. //---------------------------------------------------------------------------
  1544. void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
  1545. {
  1546. SET_CONFIG_PROPERTY(DimmHiddenFiles);
  1547. }
  1548. //---------------------------------------------------------------------------
  1549. void __fastcall TWinConfiguration::SetRenameWholeName(bool value)
  1550. {
  1551. SET_CONFIG_PROPERTY(RenameWholeName);
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. void __fastcall TWinConfiguration::SetAutoStartSession(UnicodeString value)
  1555. {
  1556. SET_CONFIG_PROPERTY(AutoStartSession);
  1557. }
  1558. //---------------------------------------------------------------------------
  1559. void __fastcall TWinConfiguration::SetExpertMode(bool value)
  1560. {
  1561. SET_CONFIG_PROPERTY(ExpertMode);
  1562. }
  1563. //---------------------------------------------------------------------------
  1564. void __fastcall TWinConfiguration::SetDefaultDirIsHome(bool value)
  1565. {
  1566. SET_CONFIG_PROPERTY(DefaultDirIsHome);
  1567. }
  1568. //---------------------------------------------------------------------------
  1569. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendSession(bool value)
  1570. {
  1571. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendSession);
  1572. }
  1573. //---------------------------------------------------------------------------
  1574. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendPath(bool value)
  1575. {
  1576. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendPath);
  1577. }
  1578. //---------------------------------------------------------------------------
  1579. void __fastcall TWinConfiguration::SetTemporaryDirectoryCleanup(bool value)
  1580. {
  1581. SET_CONFIG_PROPERTY(TemporaryDirectoryCleanup);
  1582. }
  1583. //---------------------------------------------------------------------------
  1584. void __fastcall TWinConfiguration::SetConfirmTemporaryDirectoryCleanup(bool value)
  1585. {
  1586. SET_CONFIG_PROPERTY(ConfirmTemporaryDirectoryCleanup);
  1587. }
  1588. //---------------------------------------------------------------------------
  1589. void __fastcall TWinConfiguration::SetPreservePanelState(bool value)
  1590. {
  1591. SET_CONFIG_PROPERTY(PreservePanelState);
  1592. }
  1593. //---------------------------------------------------------------------------
  1594. void __fastcall TWinConfiguration::SetTheme(UnicodeString value)
  1595. {
  1596. SET_CONFIG_PROPERTY_EX(Theme, ConfigureInterface());
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. void __fastcall TWinConfiguration::SetLastStoredSession(UnicodeString value)
  1600. {
  1601. SET_CONFIG_PROPERTY(LastStoredSession);
  1602. }
  1603. //---------------------------------------------------------------------------
  1604. void __fastcall TWinConfiguration::SetAutoSaveWorkspace(bool value)
  1605. {
  1606. SET_CONFIG_PROPERTY(AutoSaveWorkspace);
  1607. }
  1608. //---------------------------------------------------------------------------
  1609. void __fastcall TWinConfiguration::SetAutoSaveWorkspacePasswords(bool value)
  1610. {
  1611. SET_CONFIG_PROPERTY(AutoSaveWorkspacePasswords);
  1612. }
  1613. //---------------------------------------------------------------------------
  1614. void __fastcall TWinConfiguration::SetAutoWorkspace(UnicodeString value)
  1615. {
  1616. SET_CONFIG_PROPERTY(AutoWorkspace);
  1617. }
  1618. //---------------------------------------------------------------------------
  1619. void __fastcall TWinConfiguration::SetPathInCaption(TPathInCaption value)
  1620. {
  1621. SET_CONFIG_PROPERTY(PathInCaption);
  1622. }
  1623. //---------------------------------------------------------------------------
  1624. void __fastcall TWinConfiguration::SetMinimizeToTray(bool value)
  1625. {
  1626. SET_CONFIG_PROPERTY(MinimizeToTray);
  1627. }
  1628. //---------------------------------------------------------------------------
  1629. void __fastcall TWinConfiguration::SetBalloonNotifications(bool value)
  1630. {
  1631. SET_CONFIG_PROPERTY(BalloonNotifications);
  1632. }
  1633. //---------------------------------------------------------------------------
  1634. void __fastcall TWinConfiguration::SetNotificationsTimeout(unsigned int value)
  1635. {
  1636. SET_CONFIG_PROPERTY(NotificationsTimeout);
  1637. }
  1638. //---------------------------------------------------------------------------
  1639. void __fastcall TWinConfiguration::SetNotificationsStickTime(unsigned int value)
  1640. {
  1641. SET_CONFIG_PROPERTY(NotificationsStickTime);
  1642. }
  1643. //---------------------------------------------------------------------------
  1644. void __fastcall TWinConfiguration::SetCopyParamAutoSelectNotice(bool value)
  1645. {
  1646. SET_CONFIG_PROPERTY(CopyParamAutoSelectNotice);
  1647. }
  1648. //---------------------------------------------------------------------------
  1649. void __fastcall TWinConfiguration::SetLockToolbars(bool value)
  1650. {
  1651. SET_CONFIG_PROPERTY(LockToolbars);
  1652. }
  1653. //---------------------------------------------------------------------------
  1654. void __fastcall TWinConfiguration::SetSelectiveToolbarText(bool value)
  1655. {
  1656. SET_CONFIG_PROPERTY(SelectiveToolbarText);
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. void __fastcall TWinConfiguration::SetAutoOpenInPutty(bool value)
  1660. {
  1661. SET_CONFIG_PROPERTY(AutoOpenInPutty);
  1662. }
  1663. //---------------------------------------------------------------------------
  1664. void __fastcall TWinConfiguration::SetRefreshRemotePanel(bool value)
  1665. {
  1666. SET_CONFIG_PROPERTY(RefreshRemotePanel);
  1667. }
  1668. //---------------------------------------------------------------------------
  1669. void __fastcall TWinConfiguration::SetRefreshRemotePanelInterval(TDateTime value)
  1670. {
  1671. SET_CONFIG_PROPERTY(RefreshRemotePanelInterval);
  1672. }
  1673. //---------------------------------------------------------------------------
  1674. void __fastcall TWinConfiguration::SetFullRowSelect(bool value)
  1675. {
  1676. SET_CONFIG_PROPERTY(FullRowSelect);
  1677. }
  1678. //---------------------------------------------------------------------------
  1679. void __fastcall TWinConfiguration::SetOfferedEditorAutoConfig(bool value)
  1680. {
  1681. SET_CONFIG_PROPERTY(OfferedEditorAutoConfig);
  1682. }
  1683. //---------------------------------------------------------------------------
  1684. void __fastcall TWinConfiguration::SetOpenedStoredSessionFolders(UnicodeString value)
  1685. {
  1686. SET_CONFIG_PROPERTY(OpenedStoredSessionFolders);
  1687. }
  1688. //---------------------------------------------------------------------------
  1689. void __fastcall TWinConfiguration::SetAutoImportedFromPuttyOrFilezilla(bool value)
  1690. {
  1691. SET_CONFIG_PROPERTY(AutoImportedFromPuttyOrFilezilla);
  1692. }
  1693. //---------------------------------------------------------------------------
  1694. void __fastcall TWinConfiguration::SetGenerateUrlComponents(int value)
  1695. {
  1696. SET_CONFIG_PROPERTY(GenerateUrlComponents);
  1697. }
  1698. //---------------------------------------------------------------------------
  1699. void __fastcall TWinConfiguration::SetExternalSessionInExistingInstance(bool value)
  1700. {
  1701. SET_CONFIG_PROPERTY(ExternalSessionInExistingInstance);
  1702. }
  1703. //---------------------------------------------------------------------------
  1704. void __fastcall TWinConfiguration::SetCustomCommandList(TCustomCommandList * value)
  1705. {
  1706. assert(FCustomCommandList);
  1707. if (!FCustomCommandList->Equals(value))
  1708. {
  1709. FCustomCommandList->Assign(value);
  1710. FCustomCommandsDefaults = false;
  1711. }
  1712. }
  1713. //---------------------------------------------------------------------------
  1714. void __fastcall TWinConfiguration::SetBookmarks(UnicodeString Key,
  1715. TBookmarkList * value)
  1716. {
  1717. FBookmarks->Bookmarks[Key] = value;
  1718. Changed();
  1719. }
  1720. //---------------------------------------------------------------------------
  1721. TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(UnicodeString Key)
  1722. {
  1723. return FBookmarks->Bookmarks[Key];
  1724. }
  1725. //---------------------------------------------------------------------------
  1726. void __fastcall TWinConfiguration::SetSharedBookmarks(TBookmarkList * value)
  1727. {
  1728. FBookmarks->SharedBookmarks = value;
  1729. Changed();
  1730. }
  1731. //---------------------------------------------------------------------------
  1732. TBookmarkList * __fastcall TWinConfiguration::GetSharedBookmarks()
  1733. {
  1734. return FBookmarks->SharedBookmarks;
  1735. }
  1736. //---------------------------------------------------------------------------
  1737. UnicodeString __fastcall TWinConfiguration::GetDefaultKeyFile()
  1738. {
  1739. return (!FDefaultKeyFile.IsEmpty() ? FDefaultKeyFile : FTemporaryKeyFile);
  1740. }
  1741. //---------------------------------------------------------------------------
  1742. void __fastcall TWinConfiguration::SetLastMonitor(int value)
  1743. {
  1744. ::SetLastMonitor(value);
  1745. }
  1746. //---------------------------------------------------------------------------
  1747. int __fastcall TWinConfiguration::GetLastMonitor()
  1748. {
  1749. return ::GetLastMonitor();
  1750. }
  1751. //---------------------------------------------------------------------------
  1752. UnicodeString __fastcall TWinConfiguration::TemporaryDir(bool Mask)
  1753. {
  1754. return UniqTempDir(ExpandFileName(ExpandEnvironmentVariables(DDTemporaryDirectory)),
  1755. L"scp", Mask);
  1756. }
  1757. //---------------------------------------------------------------------------
  1758. TStrings * __fastcall TWinConfiguration::FindTemporaryFolders()
  1759. {
  1760. TStrings * Result = new TStringList();
  1761. try
  1762. {
  1763. TSearchRecChecked SRec;
  1764. UnicodeString Mask = TemporaryDir(true);
  1765. UnicodeString Directory = ExtractFilePath(Mask);
  1766. if (FindFirstUnchecked(Mask, faDirectory, SRec) == 0)
  1767. {
  1768. do
  1769. {
  1770. if (FLAGSET(SRec.Attr, faDirectory))
  1771. {
  1772. Result->Add(Directory + SRec.Name);
  1773. }
  1774. }
  1775. while (FindNextChecked(SRec) == 0);
  1776. }
  1777. if (Result->Count == 0)
  1778. {
  1779. delete Result;
  1780. Result = NULL;
  1781. }
  1782. }
  1783. catch(...)
  1784. {
  1785. delete Result;
  1786. throw;
  1787. }
  1788. return Result;
  1789. }
  1790. //---------------------------------------------------------------------------
  1791. void __fastcall TWinConfiguration::CleanupTemporaryFolders(TStrings * Folders)
  1792. {
  1793. UnicodeString ErrorList;
  1794. TStrings * F;
  1795. if (Folders == NULL)
  1796. {
  1797. F = FindTemporaryFolders();
  1798. }
  1799. else
  1800. {
  1801. F = Folders;
  1802. }
  1803. if (F != NULL)
  1804. {
  1805. try
  1806. {
  1807. if (ALWAYS_TRUE(F->Count > 0))
  1808. {
  1809. Usage->Inc(L"TemporaryDirectoryCleanups");
  1810. }
  1811. for (int i = 0; i < F->Count; i++)
  1812. {
  1813. if (!DeleteDirectory(F->Strings[i]))
  1814. {
  1815. if (!ErrorList.IsEmpty())
  1816. {
  1817. ErrorList += L"\n";
  1818. }
  1819. ErrorList += F->Strings[i];
  1820. }
  1821. }
  1822. }
  1823. __finally
  1824. {
  1825. if (Folders == NULL)
  1826. {
  1827. delete F;
  1828. }
  1829. }
  1830. if (!ErrorList.IsEmpty())
  1831. {
  1832. throw ExtException(LoadStr(CLEANUP_TEMP_ERROR), ErrorList);
  1833. }
  1834. }
  1835. }
  1836. //---------------------------------------------------------------------------
  1837. //---------------------------------------------------------------------------
  1838. #pragma warn -inl
  1839. //---------------------------------------------------------------------------
  1840. class TAsInheritedReader : public TReader
  1841. {
  1842. public:
  1843. __fastcall TAsInheritedReader(TStream * Stream, int BufSize) :
  1844. TReader(Stream, BufSize)
  1845. {
  1846. OnAncestorNotFound = AncestorNotFound;
  1847. }
  1848. virtual void __fastcall ReadPrefix(TFilerFlags & Flags, int & AChildPos)
  1849. {
  1850. TReader::ReadPrefix(Flags, AChildPos);
  1851. Flags << ffInherited;
  1852. }
  1853. void __fastcall AncestorNotFound(TReader * Reader,
  1854. const UnicodeString ComponentName, TMetaClass * ComponentClass,
  1855. TComponent *& Component)
  1856. {
  1857. assert(!Component);
  1858. if (ComponentName.IsEmpty())
  1859. {
  1860. for (int Index = 0; Index < LookupRoot->ComponentCount; Index++)
  1861. {
  1862. Component = LookupRoot->Components[Index];
  1863. if (Component->Name.IsEmpty())
  1864. {
  1865. return;
  1866. }
  1867. }
  1868. Component = NULL;
  1869. }
  1870. }
  1871. };
  1872. //---------------------------------------------------------------------------
  1873. #pragma warn .inl
  1874. //---------------------------------------------------------------------------
  1875. bool __fastcall TWinConfiguration::InternalReloadComponentRes(const UnicodeString ResName,
  1876. HINSTANCE HInst, TComponent * Instance)
  1877. {
  1878. HANDLE HRsrc;
  1879. bool Result;
  1880. if (!HInst)
  1881. {
  1882. HInst = HInstance;
  1883. }
  1884. HRsrc = FindResource(HInst, ResName.c_str(), RT_RCDATA);
  1885. Result = (HRsrc != 0);
  1886. if (Result)
  1887. {
  1888. TResourceStream * ResStream = new TResourceStream(
  1889. reinterpret_cast<int>(HInst), ResName, RT_RCDATA);
  1890. try
  1891. {
  1892. TReader * Reader;
  1893. Reader = new TAsInheritedReader(ResStream, 4096);
  1894. try
  1895. {
  1896. /*Instance =*/ Reader->ReadRootComponent(Instance);
  1897. }
  1898. __finally
  1899. {
  1900. delete Reader;
  1901. }
  1902. }
  1903. __finally
  1904. {
  1905. delete ResStream;
  1906. }
  1907. }
  1908. return Result;
  1909. }
  1910. //---------------------------------------------------------------------------
  1911. bool __fastcall TWinConfiguration::InitComponent(TComponent * Instance,
  1912. TClass RootAncestor, TClass ClassType)
  1913. {
  1914. bool Result = false;
  1915. if ((ClassType != __classid(TComponent)) && (ClassType != RootAncestor))
  1916. {
  1917. if (InitComponent(Instance, RootAncestor, ClassType->ClassParent()))
  1918. {
  1919. Result = true;
  1920. }
  1921. if (InternalReloadComponentRes(ClassType->ClassName(),
  1922. reinterpret_cast<HINSTANCE>(FindResourceHInstance(FindClassHInstance(ClassType))),
  1923. Instance))
  1924. {
  1925. Result = true;
  1926. }
  1927. }
  1928. return Result;
  1929. }
  1930. //---------------------------------------------------------------------------
  1931. LCID __fastcall TWinConfiguration::GetLocale()
  1932. {
  1933. if (!FLocale)
  1934. {
  1935. UnicodeString ResourceModule =
  1936. GetResourceModuleName(Application->Name, ModuleFileName().c_str());
  1937. if (!ResourceModule.IsEmpty())
  1938. {
  1939. UnicodeString ResourceExt = ExtractFileExt(ResourceModule).UpperCase();
  1940. ResourceExt.Delete(1, 1);
  1941. TLanguages * Langs = Languages();
  1942. int Index, Count;
  1943. Count = Langs->Count;
  1944. Index = 0;
  1945. while ((Index < Count) && !FLocale)
  1946. {
  1947. if (Langs->Ext[Index] == ResourceExt)
  1948. {
  1949. SetInitialLocale(Langs->LocaleID[Index]);
  1950. }
  1951. else if (Langs->Ext[Index].SubString(1, 2) == ResourceExt)
  1952. {
  1953. SetInitialLocale(
  1954. MAKELANGID(PRIMARYLANGID(Langs->LocaleID[Index]),
  1955. SUBLANG_DEFAULT));
  1956. }
  1957. Index++;
  1958. }
  1959. }
  1960. }
  1961. return TCustomWinConfiguration::GetLocale();
  1962. }
  1963. //---------------------------------------------------------------------------
  1964. HINSTANCE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
  1965. UnicodeString * FileName)
  1966. {
  1967. UnicodeString FileNameStorage;
  1968. if (FileName == NULL)
  1969. {
  1970. FileName = &FileNameStorage;
  1971. }
  1972. HINSTANCE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
  1973. if (Instance != NULL)
  1974. {
  1975. try
  1976. {
  1977. CheckTranslationVersion(*FileName, false);
  1978. }
  1979. catch(...)
  1980. {
  1981. FreeResourceModule(Instance);
  1982. throw;
  1983. }
  1984. }
  1985. return Instance;
  1986. }
  1987. //---------------------------------------------------------------------------
  1988. void __fastcall TWinConfiguration::SetResourceModule(HINSTANCE Instance)
  1989. {
  1990. TCustomWinConfiguration::SetResourceModule(Instance);
  1991. TOperationVisualizer Visualizer;
  1992. int Count;
  1993. UnicodeString OrigName;
  1994. int OrigLeft;
  1995. int OrigTop;
  1996. TForm * Form;
  1997. Count = Screen->FormCount;
  1998. for (int Index = 0; Index < Count; Index++)
  1999. {
  2000. Form = Screen->Forms[Index];
  2001. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 0, 1);
  2002. }
  2003. ConfigureInterface();
  2004. for (int Index = 0; Index < Count; Index++)
  2005. {
  2006. Form = Screen->Forms[Index];
  2007. TComponent * Component;
  2008. for (int Index = 0; Index < Form->ComponentCount; Index++)
  2009. {
  2010. Component = Form->Components[Index];
  2011. if (dynamic_cast<TFrame*>(Component))
  2012. {
  2013. OrigName = Component->Name;
  2014. InitComponent(Component, __classid(TFrame), Component->ClassType());
  2015. Component->Name = OrigName;
  2016. }
  2017. }
  2018. OrigLeft = Form->Left;
  2019. OrigTop = Form->Top;
  2020. OrigName = Form->Name;
  2021. InitComponent(Form, __classid(TForm), Form->ClassType());
  2022. Form->Name = OrigName;
  2023. Form->Position = poDesigned;
  2024. Form->Left = OrigLeft;
  2025. Form->Top = OrigTop;
  2026. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 1, 1);
  2027. }
  2028. TDataModule * DataModule;
  2029. Count = Screen->DataModuleCount;
  2030. for (int Index = 0; Index < Count; Index++)
  2031. {
  2032. DataModule = Screen->DataModules[Index];
  2033. OrigName = DataModule->Name;
  2034. InitComponent(DataModule, __classid(TDataModule), DataModule->ClassType());
  2035. DataModule->Name = OrigName;
  2036. }
  2037. }
  2038. //---------------------------------------------------------------------------
  2039. void __fastcall TWinConfiguration::CheckTranslationVersion(const UnicodeString FileName,
  2040. bool InternalLocaleOnError)
  2041. {
  2042. UnicodeString TranslationProductVersion = GetFileProductVersion(FileName);
  2043. UnicodeString TranslationProductName = GetFileProductName(FileName);
  2044. if ((ProductName != TranslationProductName) ||
  2045. (ProductVersion != TranslationProductVersion))
  2046. {
  2047. if (InternalLocaleOnError)
  2048. {
  2049. LocaleSafe = InternalLocale();
  2050. }
  2051. if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
  2052. {
  2053. throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
  2054. }
  2055. else
  2056. {
  2057. throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
  2058. (FileName, TranslationProductName, TranslationProductVersion)));
  2059. }
  2060. }
  2061. }
  2062. //---------------------------------------------------------------------------
  2063. void __fastcall TWinConfiguration::CheckDefaultTranslation()
  2064. {
  2065. if (!FInvalidDefaultTranslationMessage.IsEmpty())
  2066. {
  2067. MoreMessageDialog(FMTLOAD(INVALID_DEFAULT_TRANSLATION,
  2068. (FInvalidDefaultTranslationMessage)), NULL, qtWarning, qaOK, HELP_NONE);
  2069. }
  2070. }
  2071. //---------------------------------------------------------------------------
  2072. const TEditorPreferences * __fastcall TWinConfiguration::DefaultEditorForFile(
  2073. const UnicodeString FileName, bool Local, const TFileMasks::TParams & MaskParams)
  2074. {
  2075. return FEditorList->Find(FileName, Local, MaskParams);
  2076. }
  2077. //---------------------------------------------------------------------------
  2078. const TEditorList * __fastcall TWinConfiguration::GetEditorList()
  2079. {
  2080. return FEditorList;
  2081. }
  2082. //---------------------------------------------------------------------------
  2083. void __fastcall TWinConfiguration::SetEditorList(const TEditorList * value)
  2084. {
  2085. if (!(*FEditorList == *value))
  2086. {
  2087. *FEditorList = *value;
  2088. Changed();
  2089. }
  2090. }
  2091. //---------------------------------------------------------------------------
  2092. TStringList * __fastcall TWinConfiguration::LoadJumpList(
  2093. THierarchicalStorage * Storage, UnicodeString Name)
  2094. {
  2095. UnicodeString JumpList = Storage->ReadString(Name, L"");
  2096. std::unique_ptr<TStringList> List(new TStringList());
  2097. List->CaseSensitive = false;
  2098. List->CommaText = JumpList;
  2099. return List.release();
  2100. }
  2101. //---------------------------------------------------------------------------
  2102. void __fastcall TWinConfiguration::SaveJumpList(
  2103. THierarchicalStorage * Storage, UnicodeString Name, TStringList * List)
  2104. {
  2105. UnicodeString JumpList = Storage->ReadString(Name, L"");
  2106. UnicodeString NewJumpList = List->CommaText;
  2107. if (NewJumpList != JumpList)
  2108. {
  2109. Storage->WriteString(Name, NewJumpList);
  2110. }
  2111. }
  2112. //---------------------------------------------------------------------------
  2113. void __fastcall TWinConfiguration::TrimJumpList(TStringList * List)
  2114. {
  2115. while (List->Count > 30)
  2116. {
  2117. List->Delete(List->Count - 1);
  2118. }
  2119. }
  2120. //---------------------------------------------------------------------------
  2121. void __fastcall TWinConfiguration::UpdateEntryInJumpList(
  2122. bool Session, const UnicodeString & Name, bool Add)
  2123. {
  2124. THierarchicalStorage * Storage = CreateScpStorage(false);
  2125. try
  2126. {
  2127. FDontDecryptPasswords++;
  2128. Storage->AccessMode = smReadWrite;
  2129. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  2130. {
  2131. std::unique_ptr<TStringList> ListSessions(LoadJumpList(Storage, L"JumpList"));
  2132. std::unique_ptr<TStringList> ListWorkspaces(LoadJumpList(Storage, L"JumpListWorkspaces"));
  2133. if (!Name.IsEmpty())
  2134. {
  2135. TStringList * List = (Session ? ListSessions : ListWorkspaces).get();
  2136. int Index = List->IndexOf(Name);
  2137. if (Index >= 0)
  2138. {
  2139. List->Delete(Index);
  2140. }
  2141. if (Add)
  2142. {
  2143. List->Insert(0, Name);
  2144. }
  2145. }
  2146. TrimJumpList(ListSessions.get());
  2147. TrimJumpList(ListWorkspaces.get());
  2148. ::UpdateJumpList(ListSessions.get(), ListWorkspaces.get());
  2149. SaveJumpList(Storage, L"JumpList", ListSessions.get());
  2150. SaveJumpList(Storage, L"JumpListWorkspaces", ListWorkspaces.get());
  2151. }
  2152. }
  2153. __finally
  2154. {
  2155. FDontDecryptPasswords--;
  2156. delete Storage;
  2157. }
  2158. }
  2159. //---------------------------------------------------------------------------
  2160. void __fastcall TWinConfiguration::AddSessionToJumpList(UnicodeString SessionName)
  2161. {
  2162. UpdateEntryInJumpList(true, SessionName, true);
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TWinConfiguration::DeleteSessionFromJumpList(UnicodeString SessionName)
  2166. {
  2167. UpdateEntryInJumpList(true, SessionName, false);
  2168. }
  2169. //---------------------------------------------------------------------------
  2170. void __fastcall TWinConfiguration::AddWorkspaceToJumpList(UnicodeString Workspace)
  2171. {
  2172. UpdateEntryInJumpList(false, Workspace, true);
  2173. }
  2174. //---------------------------------------------------------------------------
  2175. void __fastcall TWinConfiguration::DeleteWorkspaceFromJumpList(UnicodeString Workspace)
  2176. {
  2177. UpdateEntryInJumpList(false, Workspace, false);
  2178. }
  2179. //---------------------------------------------------------------------------
  2180. void __fastcall TWinConfiguration::UpdateJumpList()
  2181. {
  2182. AddSessionToJumpList(L"");
  2183. }
  2184. //---------------------------------------------------------------------------
  2185. void __fastcall TWinConfiguration::UpdateStaticUsage()
  2186. {
  2187. // This is here because of TStoredSessionList::UpdateStaticUsage() call
  2188. // from TConfiguration::UpdateStaticUsage()
  2189. TAutoNestingCounter DontDecryptPasswordsAutoCounter(FDontDecryptPasswords);
  2190. TCustomWinConfiguration::UpdateStaticUsage();
  2191. Usage->Set(L"Beta", IsBeta);
  2192. Usage->Set(L"Interface", Interface);
  2193. Usage->Set(L"CustomCommandsCount", (FCustomCommandsDefaults ? 0 : FCustomCommandList->Count));
  2194. Usage->Set(L"UsingLocationProfiles", UseLocationProfiles);
  2195. Usage->Set(L"UsingMasterPassword", UseMasterPassword);
  2196. Usage->Set(L"UsingAutoSaveWorkspace", AutoSaveWorkspace);
  2197. Usage->Set(L"TreeVisible",
  2198. (Interface == ifExplorer) ?
  2199. ScpExplorer.DriveView :
  2200. (ScpCommander.LocalPanel.DriveView || ScpCommander.RemotePanel.DriveView));
  2201. Usage->Set(L"MinimizeToTray", MinimizeToTray);
  2202. Usage->Set(L"CommanderNortonLikeMode", int(ScpCommander.NortonLikeMode));
  2203. Usage->Set(L"CommanderExplorerKeyboardShortcuts", ScpCommander.ExplorerKeyboardShortcuts);
  2204. Usage->Set(L"ExplorerViewStyle", ScpExplorer.ViewStyle);
  2205. Usage->Set(L"LastMonitor", LastMonitor);
  2206. UnicodeString ExternalEditors;
  2207. for (int Index = 0; Index < EditorList->Count; Index++)
  2208. {
  2209. const TEditorPreferences * Editor = EditorList->Editors[Index];
  2210. if (Editor->Data->Editor == edExternal)
  2211. {
  2212. UnicodeString ExternalEditor = Editor->Data->ExternalEditor;
  2213. ReformatFileNameCommand(ExternalEditor);
  2214. UnicodeString Name = ExtractProgramName(ExternalEditor);
  2215. AddToList(ExternalEditors, Name, ",");
  2216. }
  2217. }
  2218. Usage->Set(L"ExternalEditors", ExternalEditors);
  2219. }
  2220. //---------------------------------------------------------------------------
  2221. //---------------------------------------------------------------------------
  2222. __fastcall TCustomCommandType::TCustomCommandType() :
  2223. FParams(0), FShortCut(0)
  2224. {
  2225. }
  2226. //---------------------------------------------------------------------------
  2227. __fastcall TCustomCommandType::TCustomCommandType(const TCustomCommandType & Other) :
  2228. FName(Other.FName),
  2229. FCommand(Other.FCommand),
  2230. FParams(Other.FParams),
  2231. FShortCut(Other.FShortCut)
  2232. {
  2233. }
  2234. //---------------------------------------------------------------------------
  2235. TCustomCommandType & TCustomCommandType::operator=(const TCustomCommandType & Other)
  2236. {
  2237. FName = Other.FName;
  2238. FCommand = Other.FCommand;
  2239. FParams = Other.FParams;
  2240. FShortCut = Other.FShortCut;
  2241. return *this;
  2242. }
  2243. //---------------------------------------------------------------------------
  2244. bool __fastcall TCustomCommandType::Equals(const TCustomCommandType * Other) const
  2245. {
  2246. return
  2247. (FName == Other->FName) &&
  2248. (FCommand == Other->FCommand) &&
  2249. (FParams == Other->FParams) &&
  2250. (FShortCut == Other->FShortCut);
  2251. }
  2252. //---------------------------------------------------------------------------
  2253. //---------------------------------------------------------------------------
  2254. __fastcall TCustomCommandList::TCustomCommandList()
  2255. {
  2256. FCommands = new TList();
  2257. FModified = false;
  2258. }
  2259. //---------------------------------------------------------------------------
  2260. __fastcall TCustomCommandList::~TCustomCommandList()
  2261. {
  2262. Clear();
  2263. delete FCommands;
  2264. }
  2265. //---------------------------------------------------------------------------
  2266. void __fastcall TCustomCommandList::Reset()
  2267. {
  2268. FModified = false;
  2269. }
  2270. //---------------------------------------------------------------------------
  2271. void __fastcall TCustomCommandList::Modify()
  2272. {
  2273. FModified = true;
  2274. }
  2275. //---------------------------------------------------------------------------
  2276. void __fastcall TCustomCommandList::Load(THierarchicalStorage * Storage)
  2277. {
  2278. Clear();
  2279. if (Storage->OpenSubKey(L"CustomCommands", false))
  2280. {
  2281. TStrings * Names = new TStringList();
  2282. try
  2283. {
  2284. Storage->ReadValues(Names, true);
  2285. for (int Index = 0; Index < Names->Count; Index++)
  2286. {
  2287. TCustomCommandType * Command = new TCustomCommandType();
  2288. Command->Name = Names->Names[Index];
  2289. Command->Command = Names->Values[Names->Names[Index]];
  2290. FCommands->Add(Command);
  2291. }
  2292. Storage->CloseSubKey();
  2293. }
  2294. __finally
  2295. {
  2296. delete Names;
  2297. }
  2298. }
  2299. if (Storage->OpenSubKey(L"CustomCommandsParams", false))
  2300. {
  2301. for (int Index = 0; Index < FCommands->Count; Index++)
  2302. {
  2303. TCustomCommandType * Command = GetCommand(Index);
  2304. Command->Params = Storage->ReadInteger(Command->Name, Command->Params);
  2305. }
  2306. Storage->CloseSubKey();
  2307. }
  2308. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", false))
  2309. {
  2310. for (int Index = 0; Index < FCommands->Count; Index++)
  2311. {
  2312. TCustomCommandType * Command = GetCommand(Index);
  2313. Command->ShortCut = (Word)Storage->ReadInteger(Command->Name, Command->ShortCut);
  2314. }
  2315. Storage->CloseSubKey();
  2316. }
  2317. Reset();
  2318. }
  2319. //---------------------------------------------------------------------------
  2320. void __fastcall TCustomCommandList::Save(THierarchicalStorage * Storage)
  2321. {
  2322. if (Storage->OpenSubKey(L"CustomCommands", true))
  2323. {
  2324. Storage->ClearValues();
  2325. for (int Index = 0; Index < FCommands->Count; Index++)
  2326. {
  2327. const TCustomCommandType * Command = Commands[Index];
  2328. Storage->WriteString(Command->Name, Command->Command);
  2329. }
  2330. Storage->CloseSubKey();
  2331. }
  2332. if (Storage->OpenSubKey(L"CustomCommandsParams", true))
  2333. {
  2334. Storage->ClearValues();
  2335. for (int Index = 0; Index < FCommands->Count; Index++)
  2336. {
  2337. const TCustomCommandType * Command = Commands[Index];
  2338. Storage->WriteInteger(Command->Name, Command->Params);
  2339. }
  2340. Storage->CloseSubKey();
  2341. }
  2342. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", true))
  2343. {
  2344. Storage->ClearValues();
  2345. for (int Index = 0; Index < FCommands->Count; Index++)
  2346. {
  2347. const TCustomCommandType * Command = Commands[Index];
  2348. if (Command->ShortCut != 0)
  2349. {
  2350. Storage->WriteInteger(Command->Name, Command->ShortCut);
  2351. }
  2352. }
  2353. Storage->CloseSubKey();
  2354. }
  2355. }
  2356. //---------------------------------------------------------------------------
  2357. void __fastcall TCustomCommandList::Clear()
  2358. {
  2359. for (int Index = 0; Index < FCommands->Count; Index++)
  2360. {
  2361. delete Commands[Index];
  2362. }
  2363. FCommands->Clear();
  2364. }
  2365. //---------------------------------------------------------------------------
  2366. void __fastcall TCustomCommandList::Add(const UnicodeString Name,
  2367. const UnicodeString ACommand, int Params)
  2368. {
  2369. TCustomCommandType * Command = new TCustomCommandType();
  2370. Command->Name = Name;
  2371. Command->Command = ACommand;
  2372. Command->Params = Params;
  2373. Add(Command);
  2374. }
  2375. //---------------------------------------------------------------------------
  2376. void __fastcall TCustomCommandList::Add(TCustomCommandType * Command)
  2377. {
  2378. Insert(Count, Command);
  2379. }
  2380. //---------------------------------------------------------------------------
  2381. void __fastcall TCustomCommandList::Insert(int Index, TCustomCommandType * Command)
  2382. {
  2383. FCommands->Insert(Index, Command);
  2384. Modify();
  2385. }
  2386. //---------------------------------------------------------------------------
  2387. void __fastcall TCustomCommandList::Change(int Index, TCustomCommandType * ACommand)
  2388. {
  2389. TCustomCommandType * Command = GetCommand(Index);
  2390. if (!Command->Equals(ACommand))
  2391. {
  2392. delete Command;
  2393. FCommands->Items[Index] = ACommand;
  2394. Modify();
  2395. }
  2396. else
  2397. {
  2398. delete ACommand;
  2399. }
  2400. }
  2401. //---------------------------------------------------------------------------
  2402. void __fastcall TCustomCommandList::Move(int CurIndex, int NewIndex)
  2403. {
  2404. if (CurIndex != NewIndex)
  2405. {
  2406. FCommands->Move(CurIndex, NewIndex);
  2407. Modify();
  2408. }
  2409. }
  2410. //---------------------------------------------------------------------------
  2411. void __fastcall TCustomCommandList::Delete(int Index)
  2412. {
  2413. assert((Index >= 0) && (Index < Count));
  2414. delete GetCommand(Index);
  2415. FCommands->Delete(Index);
  2416. Modify();
  2417. }
  2418. //---------------------------------------------------------------------------
  2419. int __fastcall TCustomCommandList::GetCount() const
  2420. {
  2421. return FCommands->Count;
  2422. }
  2423. //---------------------------------------------------------------------------
  2424. const TCustomCommandType * __fastcall TCustomCommandList::GetConstCommand(int Index) const
  2425. {
  2426. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2427. }
  2428. //---------------------------------------------------------------------------
  2429. TCustomCommandType * __fastcall TCustomCommandList::GetCommand(int Index)
  2430. {
  2431. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2432. }
  2433. //---------------------------------------------------------------------------
  2434. bool __fastcall TCustomCommandList::Equals(const TCustomCommandList * Other) const
  2435. {
  2436. bool Result = (Count == Other->Count);
  2437. for (int Index = 0; Result && (Index < Count); Index++)
  2438. {
  2439. Result = Commands[Index]->Equals(Other->Commands[Index]);
  2440. }
  2441. return Result;
  2442. }
  2443. //---------------------------------------------------------------------------
  2444. void __fastcall TCustomCommandList::Assign(const TCustomCommandList * Other)
  2445. {
  2446. Clear();
  2447. for (int Index = 0; Index < Other->Count; Index++)
  2448. {
  2449. Add(new TCustomCommandType(*Other->Commands[Index]));
  2450. }
  2451. // there should be comparison of with the assigned list, be we rely on caller
  2452. // to do it instead (TGUIConfiguration::SetCopyParamList)
  2453. Modify();
  2454. }
  2455. //---------------------------------------------------------------------------
  2456. const TCustomCommandType * TCustomCommandList::Find(const UnicodeString Name) const
  2457. {
  2458. for (int Index = 0; Index < FCommands->Count; Index++)
  2459. {
  2460. if (Commands[Index]->Name == Name)
  2461. {
  2462. return Commands[Index];
  2463. }
  2464. }
  2465. return NULL;
  2466. }
  2467. //---------------------------------------------------------------------------
  2468. const TCustomCommandType * TCustomCommandList::Find(TShortCut ShortCut) const
  2469. {
  2470. for (int Index = 0; Index < FCommands->Count; Index++)
  2471. {
  2472. if (Commands[Index]->ShortCut == ShortCut)
  2473. {
  2474. return Commands[Index];
  2475. }
  2476. }
  2477. return NULL;
  2478. }
  2479. //---------------------------------------------------------------------------
  2480. void __fastcall TCustomCommandList::ShortCuts(TShortCuts & ShortCuts) const
  2481. {
  2482. for (int Index = 0; Index < FCommands->Count; Index++)
  2483. {
  2484. const TCustomCommandType * Command = Commands[Index];
  2485. if (Command->ShortCut != 0)
  2486. {
  2487. ShortCuts.Add(Command->ShortCut);
  2488. }
  2489. }
  2490. }