WinConfiguration.cpp 96 KB

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