WinConfiguration.cpp 96 KB

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