WinConfiguration.cpp 108 KB

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