WinConfiguration.cpp 90 KB

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