WinConfiguration.cpp 96 KB

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