WinConfiguration.cpp 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796
  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 <OperationWithTimeout.hpp>
  24. #include "FileInfo.h"
  25. //---------------------------------------------------------------------------
  26. #pragma package(smart_init)
  27. //---------------------------------------------------------------------------
  28. TWinConfiguration * WinConfiguration = NULL;
  29. //---------------------------------------------------------------------------
  30. static UnicodeString NotepadName(L"notepad.exe");
  31. static UnicodeString ToolbarsLayoutKey(L"ToolbarsLayout2");
  32. static UnicodeString ToolbarsLayoutOldKey(L"ToolbarsLayout");
  33. //---------------------------------------------------------------------------
  34. static const wchar_t FileColorDataSeparator = L':';
  35. TFileColorData::TFileColorData() :
  36. Color(TColor())
  37. {
  38. }
  39. //---------------------------------------------------------------------------
  40. void TFileColorData::Load(const UnicodeString & S)
  41. {
  42. UnicodeString Buf(S);
  43. Color = RestoreColor(CutToChar(Buf, FileColorDataSeparator, true));
  44. FileMask = Buf;
  45. }
  46. //---------------------------------------------------------------------------
  47. UnicodeString TFileColorData::Save() const
  48. {
  49. UnicodeString Result = StoreColor(Color) + FileColorDataSeparator + FileMask.Masks;
  50. return Result;
  51. }
  52. //---------------------------------------------------------------------------
  53. void TFileColorData::LoadList(const UnicodeString & S, TList & List)
  54. {
  55. std::unique_ptr<TStringList> Strings(new TStringList());
  56. Strings->CommaText = S;
  57. List.clear();
  58. for (int Index = 0; Index < Strings->Count; Index++)
  59. {
  60. TFileColorData FileColorData;
  61. FileColorData.Load(Strings->Strings[Index]);
  62. List.push_back(FileColorData);
  63. }
  64. }
  65. //---------------------------------------------------------------------------
  66. UnicodeString TFileColorData::SaveList(const TList & List)
  67. {
  68. std::unique_ptr<TStringList> Strings(new TStringList());
  69. for (TFileColorData::TList::const_iterator Iter = List.begin(); Iter != List.end(); Iter++)
  70. {
  71. Strings->Add((*Iter).Save());
  72. }
  73. return Strings->CommaText;
  74. }
  75. //---------------------------------------------------------------------------
  76. //---------------------------------------------------------------------------
  77. __fastcall TEditorData::TEditorData() :
  78. FileMask(AnyMask),
  79. Editor(edInternal),
  80. ExternalEditor(L""),
  81. ExternalEditorText(false),
  82. SDIExternalEditor(false),
  83. DetectMDIExternalEditor(false)
  84. {
  85. }
  86. //---------------------------------------------------------------------------
  87. __fastcall TEditorData::TEditorData(const TEditorData & Source) :
  88. FileMask(Source.FileMask),
  89. Editor(Source.Editor),
  90. ExternalEditor(Source.ExternalEditor),
  91. ExternalEditorText(Source.ExternalEditorText),
  92. SDIExternalEditor(Source.SDIExternalEditor),
  93. DetectMDIExternalEditor(Source.DetectMDIExternalEditor)
  94. {
  95. }
  96. //---------------------------------------------------------------------------
  97. #define C(Property) (Property == rhd.Property)
  98. bool __fastcall TEditorData::operator==(const TEditorData & rhd) const
  99. {
  100. return
  101. C(FileMask) &&
  102. C(Editor) &&
  103. C(ExternalEditor) &&
  104. C(ExternalEditorText) &&
  105. C(SDIExternalEditor) &&
  106. C(DetectMDIExternalEditor) &&
  107. true;
  108. }
  109. #undef C
  110. //---------------------------------------------------------------------------
  111. bool __fastcall TEditorData::DecideExternalEditorText(UnicodeString ExternalEditor)
  112. {
  113. bool Result = false;
  114. // By default we use default transfer mode (binary),
  115. // as all reasonable 3rd party editors support all EOL styles.
  116. // A notable exception is Windows Notepad, so here's an exception for it.
  117. ReformatFileNameCommand(ExternalEditor);
  118. UnicodeString ProgramName = ExtractProgramName(ExternalEditor);
  119. // We explicitly do not use TEditorPreferences::GetDefaultExternalEditor(),
  120. // as we need to explicitly refer to the Notepad, even if the default external
  121. // editor ever changes
  122. UnicodeString NotepadProgramName = ExtractProgramName(NotepadName);
  123. if (SameText(ProgramName, NotepadProgramName))
  124. {
  125. Result = true;
  126. }
  127. return Result;
  128. }
  129. //---------------------------------------------------------------------------
  130. void __fastcall TEditorData::DecideExternalEditorText()
  131. {
  132. if (DecideExternalEditorText(ExternalEditor))
  133. {
  134. ExternalEditorText = true;
  135. }
  136. }
  137. //---------------------------------------------------------------------------
  138. __fastcall TEditorPreferences::TEditorPreferences()
  139. {
  140. }
  141. //---------------------------------------------------------------------------
  142. __fastcall TEditorPreferences::TEditorPreferences(const TEditorData & Data) :
  143. FData(Data)
  144. {
  145. }
  146. //---------------------------------------------------------------------------
  147. bool __fastcall TEditorPreferences::operator==(const TEditorPreferences & rhp) const
  148. {
  149. return (FData == rhp.FData);
  150. }
  151. #undef C
  152. //---------------------------------------------------------------------------
  153. bool __fastcall TEditorPreferences::Matches(const UnicodeString FileName,
  154. bool Local, const TFileMasks::TParams & Params) const
  155. {
  156. return FData.FileMask.Matches(FileName, Local, false, &Params);
  157. }
  158. //---------------------------------------------------------------------------
  159. UnicodeString __fastcall TEditorPreferences::GetDefaultExternalEditor()
  160. {
  161. return NotepadName;
  162. }
  163. //---------------------------------------------------------------------------
  164. void __fastcall TEditorPreferences::LegacyDefaults()
  165. {
  166. FData.ExternalEditor = GetDefaultExternalEditor();
  167. FData.DecideExternalEditorText();
  168. }
  169. //---------------------------------------------------------------------------
  170. UnicodeString __fastcall TEditorPreferences::ExtractExternalEditorName() const
  171. {
  172. DebugAssert(FData.Editor == edExternal);
  173. UnicodeString ExternalEditor = FData.ExternalEditor;
  174. ReformatFileNameCommand(ExternalEditor);
  175. // Trim is a workaround for unknown problem with "notepad " (2 trailing spaces)
  176. return ExtractProgramName(ExternalEditor).Trim();
  177. }
  178. //---------------------------------------------------------------------------
  179. void __fastcall TEditorPreferences::Load(THierarchicalStorage * Storage, bool Legacy)
  180. {
  181. if (!Legacy)
  182. {
  183. FData.FileMask = Storage->ReadString(L"FileMask", FData.FileMask.Masks);
  184. }
  185. FData.Editor = (TEditor)Storage->ReadInteger(L"Editor", FData.Editor);
  186. FData.ExternalEditor = Storage->ReadString(L"ExternalEditor", FData.ExternalEditor);
  187. FData.ExternalEditorText = Storage->ReadBool(L"ExternalEditorText", FData.ExternalEditorText);
  188. FData.SDIExternalEditor = Storage->ReadBool(L"SDIExternalEditor", FData.SDIExternalEditor);
  189. FData.DetectMDIExternalEditor = Storage->ReadBool(L"DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
  190. }
  191. //---------------------------------------------------------------------------
  192. void __fastcall TEditorPreferences::Save(THierarchicalStorage * Storage) const
  193. {
  194. Storage->WriteString(L"FileMask", FData.FileMask.Masks);
  195. Storage->WriteInteger(L"Editor", FData.Editor);
  196. Storage->WriteString(L"ExternalEditor", FData.ExternalEditor);
  197. Storage->WriteBool(L"ExternalEditorText", FData.ExternalEditorText);
  198. Storage->WriteBool(L"SDIExternalEditor", FData.SDIExternalEditor);
  199. Storage->WriteBool(L"DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
  200. }
  201. //---------------------------------------------------------------------------
  202. TEditorData * __fastcall TEditorPreferences::GetData()
  203. {
  204. // returning non-const data, possible data change, invalidate cached name
  205. FName = L"";
  206. return &FData;
  207. };
  208. //---------------------------------------------------------------------------
  209. UnicodeString __fastcall TEditorPreferences::GetName() const
  210. {
  211. if (FName.IsEmpty())
  212. {
  213. if (FData.Editor == edInternal)
  214. {
  215. // StripHotkey is relic from times when INTERNAL_EDITOR_NAME was used
  216. // also for the menu item caption
  217. FName = StripHotkey(LoadStr(INTERNAL_EDITOR_NAME));
  218. }
  219. else if (FData.Editor == edOpen)
  220. {
  221. FName = StripHotkey(LoadStr(OPEN_EDITOR_NAME));
  222. }
  223. else
  224. {
  225. UnicodeString Program, Params, Dir;
  226. UnicodeString ExternalEditor = FData.ExternalEditor;
  227. ReformatFileNameCommand(ExternalEditor);
  228. SplitCommand(ExternalEditor, Program, Params, Dir);
  229. FName = ExtractFileName(Program);
  230. int P = FName.LastDelimiter(L".");
  231. if (P > 0)
  232. {
  233. FName.SetLength(P - 1);
  234. }
  235. if (FName.ByteType(1) == mbSingleByte)
  236. {
  237. if (FName.UpperCase() == FName)
  238. {
  239. FName = FName.LowerCase();
  240. }
  241. if (FName.LowerCase() == FName)
  242. {
  243. FName = FName.SubString(1, 1).UpperCase() +
  244. FName.SubString(2, FName.Length() - 1);
  245. }
  246. }
  247. }
  248. }
  249. return FName;
  250. }
  251. //---------------------------------------------------------------------------
  252. //---------------------------------------------------------------------------
  253. __fastcall TEditorList::TEditorList()
  254. {
  255. Init();
  256. }
  257. //---------------------------------------------------------------------------
  258. void __fastcall TEditorList::Init()
  259. {
  260. FEditors = new TList();
  261. FModified = false;
  262. }
  263. //---------------------------------------------------------------------------
  264. __fastcall TEditorList::~TEditorList()
  265. {
  266. Clear();
  267. delete FEditors;
  268. }
  269. //---------------------------------------------------------------------
  270. void __fastcall TEditorList::Modify()
  271. {
  272. FModified = true;
  273. }
  274. //---------------------------------------------------------------------------
  275. void __fastcall TEditorList::Saved()
  276. {
  277. FModified = false;
  278. }
  279. //---------------------------------------------------------------------------
  280. TEditorList & __fastcall TEditorList::operator=(const TEditorList & rhl)
  281. {
  282. Clear();
  283. for (int Index = 0; Index < rhl.Count; Index++)
  284. {
  285. Add(new TEditorPreferences(*rhl.Editors[Index]));
  286. }
  287. // there should be comparison of with the assigned list, but we rely on caller
  288. // to do it instead (TWinConfiguration::SetEditorList)
  289. Modify();
  290. return *this;
  291. }
  292. //---------------------------------------------------------------------------
  293. bool __fastcall TEditorList::operator==(const TEditorList & rhl) const
  294. {
  295. bool Result = (Count == rhl.Count);
  296. if (Result)
  297. {
  298. int i = 0;
  299. while ((i < Count) && Result)
  300. {
  301. Result = (*Editors[i]) == (*rhl.Editors[i]);
  302. i++;
  303. }
  304. }
  305. return Result;
  306. }
  307. //---------------------------------------------------------------------------
  308. void __fastcall TEditorList::Clear()
  309. {
  310. for (int i = 0; i < Count; i++)
  311. {
  312. delete Editors[i];
  313. }
  314. FEditors->Clear();
  315. }
  316. //---------------------------------------------------------------------------
  317. void __fastcall TEditorList::Add(TEditorPreferences * Editor)
  318. {
  319. Insert(Count, Editor);
  320. }
  321. //---------------------------------------------------------------------------
  322. void __fastcall TEditorList::Insert(int Index, TEditorPreferences * Editor)
  323. {
  324. FEditors->Insert(Index, reinterpret_cast<TObject *>(Editor));
  325. Modify();
  326. }
  327. //---------------------------------------------------------------------------
  328. void __fastcall TEditorList::Change(int Index, TEditorPreferences * Editor)
  329. {
  330. if (!((*Editors[Index]) == *Editor))
  331. {
  332. delete Editors[Index];
  333. FEditors->Items[Index] = (reinterpret_cast<TObject *>(Editor));
  334. Modify();
  335. }
  336. else
  337. {
  338. delete Editor;
  339. }
  340. }
  341. //---------------------------------------------------------------------------
  342. void __fastcall TEditorList::Move(int CurIndex, int NewIndex)
  343. {
  344. if (CurIndex != NewIndex)
  345. {
  346. FEditors->Move(CurIndex, NewIndex);
  347. Modify();
  348. }
  349. }
  350. //---------------------------------------------------------------------------
  351. void __fastcall TEditorList::Delete(int Index)
  352. {
  353. DebugAssert((Index >= 0) && (Index < Count));
  354. delete Editors[Index];
  355. FEditors->Delete(Index);
  356. Modify();
  357. }
  358. //---------------------------------------------------------------------------
  359. const TEditorPreferences * __fastcall TEditorList::Find(
  360. const UnicodeString FileName, bool Local, const TFileMasks::TParams & Params) const
  361. {
  362. const TEditorPreferences * Result = NULL;
  363. int i = 0;
  364. while ((i < FEditors->Count) && (Result == NULL))
  365. {
  366. Result = Editors[i];
  367. if (!Result->Matches(FileName, Local, Params))
  368. {
  369. Result = NULL;
  370. }
  371. i++;
  372. }
  373. return Result;
  374. }
  375. //---------------------------------------------------------------------------
  376. void __fastcall TEditorList::Load(THierarchicalStorage * Storage)
  377. {
  378. int Index = 0;
  379. bool Next;
  380. do
  381. {
  382. UnicodeString Name = IntToStr(Index);
  383. TEditorPreferences * Editor = NULL;
  384. try
  385. {
  386. Next = Storage->OpenSubKey(Name, false);
  387. if (Next)
  388. {
  389. try
  390. {
  391. Editor = new TEditorPreferences();
  392. Editor->Load(Storage, false);
  393. }
  394. __finally
  395. {
  396. Storage->CloseSubKey();
  397. }
  398. }
  399. }
  400. catch(...)
  401. {
  402. delete Editor;
  403. throw;
  404. }
  405. if (Editor != NULL)
  406. {
  407. FEditors->Add(reinterpret_cast<TObject *>(Editor));
  408. }
  409. Index++;
  410. }
  411. while (Next);
  412. FModified = false;
  413. }
  414. //---------------------------------------------------------------------------
  415. void __fastcall TEditorList::Save(THierarchicalStorage * Storage) const
  416. {
  417. Storage->ClearSubKeys();
  418. for (int Index = 0; Index < Count; Index++)
  419. {
  420. if (Storage->OpenSubKey(IntToStr(Index), true))
  421. {
  422. try
  423. {
  424. Editors[Index]->Save(Storage);
  425. }
  426. __finally
  427. {
  428. Storage->CloseSubKey();
  429. }
  430. }
  431. }
  432. }
  433. //---------------------------------------------------------------------------
  434. int __fastcall TEditorList::GetCount() const
  435. {
  436. int X = FEditors->Count;
  437. return X;
  438. }
  439. //---------------------------------------------------------------------------
  440. const TEditorPreferences * __fastcall TEditorList::GetEditor(int Index) const
  441. {
  442. return reinterpret_cast<TEditorPreferences *>(FEditors->Items[Index]);
  443. }
  444. //---------------------------------------------------------------------------
  445. bool __fastcall TEditorList::IsDefaultList() const
  446. {
  447. bool Result = true;
  448. for (int Index = 0; Result && (Index < Count); Index++)
  449. {
  450. const TEditorPreferences * Editor = GetEditor(Index);
  451. if (Editor->Data->Editor == edInternal)
  452. {
  453. // noop (keeps Result true)
  454. }
  455. else if (Editor->Data->Editor == edExternal)
  456. {
  457. UnicodeString ExternalEditor = Editor->ExtractExternalEditorName();
  458. UnicodeString DefaultExternalEditor = ExtractProgramName(TEditorPreferences::GetDefaultExternalEditor());
  459. Result = SameText(ExternalEditor, DefaultExternalEditor);
  460. }
  461. else
  462. {
  463. Result = false;
  464. }
  465. }
  466. return Result;
  467. }
  468. //---------------------------------------------------------------------------
  469. //---------------------------------------------------------------------------
  470. __fastcall TWinConfiguration::TWinConfiguration(): TCustomWinConfiguration()
  471. {
  472. ResetSysDarkTheme();
  473. FInvalidDefaultTranslationMessage = L"";
  474. FDDExtInstalled = -1;
  475. FBookmarks = new TBookmarks();
  476. FCustomCommandList = new TCustomCommandList();
  477. FExtensionList = new TCustomCommandList();
  478. FEditorList = new TEditorList();
  479. FDefaultUpdatesPeriod = 0;
  480. FDontDecryptPasswords = 0;
  481. FMasterPasswordSession = 0;
  482. FMasterPasswordSessionAsked = false;
  483. FCustomCommandOptions.reset(new TStringList());
  484. FCustomCommandOptionsModified = false;
  485. FExtensionTranslations.reset(new TStringList());
  486. Default();
  487. // This matters only if the translations are in the executable folder and auto-loaded by VCL (System.Pas - DelayLoadResourceModule)
  488. try
  489. {
  490. UnicodeString ResourceModuleName = GetResourceModuleName(Application->Name, ModuleFileName().c_str());
  491. CheckTranslationVersion(ResourceModuleName, true);
  492. }
  493. catch(Exception & E)
  494. {
  495. FInvalidDefaultTranslationMessage = E.Message;
  496. }
  497. // Load complete locale according to the UI language
  498. SetLocaleInternal(NULL, true, true);
  499. FDefaultLocale = AppliedLocale;
  500. }
  501. //---------------------------------------------------------------------------
  502. __fastcall TWinConfiguration::~TWinConfiguration()
  503. {
  504. if (!FTemporarySessionFile.IsEmpty()) DeleteFile(ApiPath(FTemporarySessionFile));
  505. ClearTemporaryLoginData();
  506. ReleaseExtensionTranslations();
  507. delete FBookmarks;
  508. delete FCustomCommandList;
  509. delete FExtensionList;
  510. delete FEditorList;
  511. }
  512. //---------------------------------------------------------------------------
  513. void __fastcall TWinConfiguration::Default()
  514. {
  515. FCustomCommandsDefaults = true;
  516. FCustomCommandOptionsModified = false;
  517. TCustomWinConfiguration::Default();
  518. int WorkAreaWidthScaled = DimensionToDefaultPixelsPerInch(Screen->WorkAreaWidth);
  519. int WorkAreaHeightScaled = DimensionToDefaultPixelsPerInch(Screen->WorkAreaHeight);
  520. UnicodeString PixelsPerInchToolbarValue = "PixelsPerInch=" + SaveDefaultPixelsPerInch();
  521. FDDTransferConfirmation = asAuto;
  522. FDDTemporaryDirectory = L"";
  523. FDDDrives = L"";
  524. FDDWarnLackOfTempSpace = true;
  525. FDDWarnLackOfTempSpaceRatio = 1.1;
  526. FDDFakeFile = true;
  527. FDDExtTimeout = MSecsPerSec;
  528. FDeleteToRecycleBin = true;
  529. FSelectDirectories = false;
  530. FSelectMask = AnyMask;
  531. FShowHiddenFiles = false;
  532. FFormatSizeBytes = fbKilobytes;
  533. FPanelSearch = isNameStartOnly;
  534. FShowInaccesibleDirectories = true;
  535. FConfirmTransferring = true;
  536. FConfirmDeleting = true;
  537. FConfirmRecycling = true;
  538. FConfirmClosingSession = true;
  539. FDoubleClickAction = dcaEdit;
  540. FCopyOnDoubleClickConfirmation = false;
  541. FDimmHiddenFiles = true;
  542. FRenameWholeName = false;
  543. FAutoStartSession = L"";
  544. FExpertMode = true;
  545. FUseLocationProfiles = false;
  546. FUseSharedBookmarks = false;
  547. FDefaultDirIsHome = true;
  548. FDDDeleteDelay = 120;
  549. FTemporaryDirectoryAppendSession = false;
  550. FTemporaryDirectoryDeterministic = false;
  551. FTemporaryDirectoryAppendPath = true;
  552. FTemporaryDirectoryCleanup = true;
  553. FConfirmTemporaryDirectoryCleanup = true;
  554. FPreservePanelState = true;
  555. FDarkTheme = asAuto;
  556. FLastStoredSession = L"";
  557. // deliberately not being saved, so that when saving ad-hoc workspace,
  558. // we do not offer to overwrite the last saved workspace, what may be undesirable
  559. FLastWorkspace = L"";
  560. FAutoSaveWorkspace = false;
  561. FAutoSaveWorkspacePasswords = false;
  562. FAutoWorkspace = L"";
  563. FPathInCaption = picShort;
  564. FMinimizeToTray = false;
  565. FMinimizeToTrayOnce = false;
  566. FBalloonNotifications = true;
  567. FNotificationsTimeout = 10;
  568. FNotificationsStickTime = 2;
  569. FCopyParamAutoSelectNotice = true;
  570. FLockToolbars = false;
  571. FSelectiveToolbarText = true;
  572. FAutoOpenInPutty = false;
  573. FRefreshRemotePanel = false;
  574. FRefreshRemotePanelInterval = TDateTime(0, 1, 0, 0);
  575. FPanelFont.FontName = L"";
  576. FPanelFont.FontSize = 0;
  577. FPanelFont.FontStyle = 0;
  578. FPanelFont.FontCharset = DEFAULT_CHARSET;
  579. FNaturalOrderNumericalSorting = true;
  580. FFullRowSelect = false;
  581. FOfferedEditorAutoConfig = false;
  582. FVersionHistory = L"";
  583. AddVersionToHistory();
  584. FUseMasterPassword = false;
  585. FPlainMasterPasswordEncrypt = L"";
  586. FPlainMasterPasswordDecrypt = L"";
  587. FMasterPasswordVerifier = L"";
  588. FOpenedStoredSessionFolders = L"";
  589. FAutoImportedFromPuttyOrFilezilla = false;
  590. FGenerateUrlComponents = -1;
  591. FGenerateUrlCodeTarget = guctUrl;
  592. FGenerateUrlScriptFormat = sfScriptFile;
  593. FGenerateUrlAssemblyLanguage = alCSharp;
  594. FExternalSessionInExistingInstance = true;
  595. FKeepOpenWhenNoSession = false;
  596. FLocalIconsByExt = false;
  597. FBidiModeOverride = lfoLanguageIfRecommended;
  598. FFlipChildrenOverride = lfoLanguageIfRecommended;
  599. FShowTips = true;
  600. FTipsSeen = L"";
  601. FTipsShown = Now();
  602. FFileColors = L"";
  603. FRunsSinceLastTip = 0;
  604. FExtensionsDeleted = L"";
  605. FLockedInterface = false;
  606. HonorDrivePolicy = true;
  607. TimeoutShellOperations = true;
  608. TimeoutShellIconRetrieval = false;
  609. AllowWindowPrint = false;
  610. FEditor.Font.FontName = DefaultFixedWidthFontName;
  611. FEditor.Font.FontSize = DefaultFixedWidthFontSize;
  612. FEditor.Font.FontStyle = 0;
  613. FEditor.Font.FontCharset = DEFAULT_CHARSET;
  614. FEditor.FontColor = TColor(0);
  615. FEditor.BackgroundColor = TColor(0);
  616. FEditor.WordWrap = false;
  617. FEditor.FindText = L"";
  618. FEditor.ReplaceText = L"";
  619. FEditor.FindMatchCase = false;
  620. FEditor.FindWholeWord = false;
  621. FEditor.FindDown = true;
  622. FEditor.TabSize = 8;
  623. FEditor.MaxEditors = 500;
  624. FEditor.EarlyClose = 2; // seconds
  625. FEditor.SDIShellEditor = false;
  626. FEditor.WindowParams = L"";
  627. FEditor.Encoding = CP_ACP;
  628. FEditor.WarnOnEncodingFallback = true;
  629. FEditor.WarnOrLargeFileSize = true;
  630. FQueueView.Height = 140;
  631. FQueueView.HeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  632. // with 1000 pixels wide screen, both interfaces are wide enough to fit wider queue
  633. FQueueView.Layout =
  634. UnicodeString((WorkAreaWidthScaled > 1000) ? L"70,250,250,80,80,80,100" : L"70,160,160,80,80,80,100") +
  635. // WORKAROUND (the comma), see GetListViewStr
  636. L",;" + SaveDefaultPixelsPerInch();
  637. FQueueView.Show = qvHideWhenEmpty;
  638. FQueueView.LastHideShow = qvHideWhenEmpty;
  639. FQueueView.ToolBar = true;
  640. FQueueView.Label = true;
  641. FEnableQueueByDefault = true;
  642. FUpdates.Period = FDefaultUpdatesPeriod;
  643. FUpdates.LastCheck = 0;
  644. FUpdates.HaveResults = false;
  645. FUpdates.ShownResults = false;
  646. FUpdates.BetaVersions = asAuto;
  647. FUpdates.ShowOnStartup = true;
  648. FUpdates.AuthenticationEmail = L"";
  649. // for backward compatibility the default is decided based on value of ProxyHost
  650. FUpdates.ConnectionType = (TConnectionType)-1;
  651. FUpdates.ProxyHost = L""; // keep empty (see above)
  652. FUpdates.ProxyPort = 8080;
  653. FUpdates.Results.Reset();
  654. FUpdates.DotNetVersion = L"";
  655. FUpdates.ConsoleVersion = L"";
  656. int ExplorerWidth = Min(WorkAreaWidthScaled - 40, 960);
  657. int ExplorerHeight = Min(WorkAreaHeightScaled - 30, 720);
  658. FScpExplorer.WindowParams = FormatDefaultWindowParams(ExplorerWidth, ExplorerHeight);
  659. // WORKAROUND (the semicolon, see TCustomListViewColProperties.GetParamsStr, and see other instances below)
  660. 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";
  661. FScpExplorer.ToolbarsLayout =
  662. UnicodeString(
  663. L"Queue=1::0+-1,"
  664. "Menu=1:TopDock:0+0,"
  665. "Buttons=1:TopDock:2+0,"
  666. "Selection=0:TopDock:3+0,"
  667. "Session=0:TopDock:6+0,"
  668. "Preferences=1:TopDock:4+0,"
  669. "Sort=0:TopDock:5+0,"
  670. "Address=1:TopDock:1+0,"
  671. "Updates=1:TopDock:4+416,"
  672. "Transfer=1:TopDock:4+194,"
  673. "CustomCommands=0:TopDock:7+0,") +
  674. PixelsPerInchToolbarValue;
  675. FScpExplorer.ToolbarsButtons = UnicodeString();
  676. FScpExplorer.SessionsTabs = true;
  677. FScpExplorer.StatusBar = true;
  678. FScpExplorer.LastLocalTargetDirectory = GetPersonalFolder();
  679. FScpExplorer.ViewStyle = 0; /* vsIcon */
  680. FScpExplorer.ShowFullAddress = true;
  681. FScpExplorer.DriveView = true;
  682. FScpExplorer.DriveViewWidth = 180;
  683. FScpExplorer.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  684. int CommanderWidth = Min(WorkAreaWidthScaled - 40, 1090);
  685. int CommanderHeight = Min(WorkAreaHeightScaled - 30, 700);
  686. FScpCommander.WindowParams = FormatDefaultWindowParams(CommanderWidth, CommanderHeight);
  687. FScpCommander.LocalPanelWidth = 0.5;
  688. FScpCommander.SwappedPanels = false;
  689. FScpCommander.SessionsTabs = true;
  690. FScpCommander.StatusBar = true;
  691. FScpCommander.NortonLikeMode = nlKeyboard;
  692. FScpCommander.PreserveLocalDirectory = false;
  693. FScpCommander.ToolbarsLayout =
  694. UnicodeString(
  695. L"Queue=1::0+-1,"
  696. "Menu=1:TopDock:0+0,"
  697. "Preferences=1:TopDock:1+228,"
  698. "Session=0:TopDock:1+602,"
  699. "Sort=0:TopDock:2+0,"
  700. "Commands=1:TopDock:1+0,"
  701. "Updates=1:TopDock:1+619,"
  702. "Transfer=1:TopDock:1+364,"
  703. "CustomCommands=0:TopDock:3+0,"
  704. "RemoteHistory=1:RemoteTopDock:0+172,"
  705. "RemoteNavigation=1:RemoteTopDock:0+252,"
  706. "RemotePath=1:RemoteTopDock:0+0,"
  707. "RemoteFile=1:RemoteTopDock:1+0,"
  708. "RemoteSelection=1:RemoteTopDock:1+345,"
  709. "LocalHistory=1:LocalTopDock:0+207,"
  710. "LocalNavigation=1:LocalTopDock:0+287,"
  711. "LocalPath=1:LocalTopDock:0+0,"
  712. "LocalFile=1:LocalTopDock:1+0,"
  713. "LocalSelection=1:LocalTopDock:1+329,"
  714. "Toolbar2=0:BottomDock:1+0,"
  715. "CommandLine=0:BottomDock:0+0,") +
  716. PixelsPerInchToolbarValue;
  717. FScpCommander.ToolbarsButtons = UnicodeString();
  718. FScpCommander.CurrentPanel = osLocal;
  719. FScpCommander.CompareByTime = true;
  720. FScpCommander.CompareBySize = false;
  721. FScpCommander.TreeOnLeft = false;
  722. FScpCommander.ExplorerKeyboardShortcuts = false;
  723. FScpCommander.SystemContextMenu = false;
  724. 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";
  725. FScpCommander.RemotePanel.StatusBar = true;
  726. FScpCommander.RemotePanel.DriveView = false;
  727. FScpCommander.RemotePanel.DriveViewHeight = 100;
  728. FScpCommander.RemotePanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  729. FScpCommander.RemotePanel.DriveViewWidth = 100;
  730. FScpCommander.RemotePanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  731. FScpCommander.RemotePanel.LastPath = UnicodeString();
  732. 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";
  733. FScpCommander.LocalPanel.StatusBar = true;
  734. FScpCommander.LocalPanel.DriveView = false;
  735. FScpCommander.LocalPanel.DriveViewHeight = 100;
  736. FScpCommander.LocalPanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  737. FScpCommander.LocalPanel.DriveViewWidth = 100;
  738. FScpCommander.LocalPanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  739. FScpCommander.LocalPanel.LastPath = UnicodeString();
  740. FBookmarks->Clear();
  741. }
  742. //---------------------------------------------------------------------------
  743. void __fastcall TWinConfiguration::DefaultLocalized()
  744. {
  745. TGUIConfiguration::DefaultLocalized();
  746. if (FCustomCommandsDefaults)
  747. {
  748. FCustomCommandList->Clear();
  749. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_EXECUTE), L"\"./!\"", 0);
  750. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TOUCH), L"touch \"!\"", ccApplyToDirectories | ccRecursive);
  751. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TAR),
  752. FORMAT(L"tar -cz -f \"!?%s?archive.tgz!\" !&",
  753. (LoadStr(CUSTOM_COMMAND_TAR_ARCHIVE))), ccApplyToDirectories);
  754. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_UNTAR),
  755. FORMAT(L"tar -xz --directory=\"!?%s?.!\" -f \"!\"",
  756. (LoadStr(CUSTOM_COMMAND_UNTAR_DIRECTORY))), 0);
  757. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_GREP),
  758. FORMAT(L"grep \"!?%s?!\" !&", (LoadStr(CUSTOM_COMMAND_GREP_PATTERN))),
  759. ccShowResults);
  760. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_PRINT), L"notepad.exe /p \"!\"", ccLocal);
  761. FCustomCommandList->Reset();
  762. FCustomCommandsDefaults = true;
  763. }
  764. }
  765. //---------------------------------------------------------------------------
  766. bool __fastcall TWinConfiguration::DetectRegistryStorage(HKEY RootKey)
  767. {
  768. bool Result = false;
  769. TRegistryStorage * Storage = new TRegistryStorage(RegistryStorageKey, RootKey);
  770. try
  771. {
  772. if (Storage->OpenRootKey(false))
  773. {
  774. Result = true;
  775. Storage->CloseSubKey();
  776. }
  777. }
  778. __finally
  779. {
  780. delete Storage;
  781. }
  782. return Result;
  783. }
  784. //---------------------------------------------------------------------------
  785. bool __fastcall TWinConfiguration::CanWriteToStorage()
  786. {
  787. bool Result = false;
  788. try
  789. {
  790. THierarchicalStorage * Storage = CreateConfigStorage();
  791. try
  792. {
  793. Storage->AccessMode = smReadWrite;
  794. // This is actually not very good test, as we end up potentially with
  795. // the very same config, and TIniFileStorage file won't even try to
  796. // write the file then. Luckily, we use this for empty config only,
  797. // so we end up with at least an empty section.
  798. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  799. {
  800. Storage->WriteBool(L"WriteTest", true);
  801. Storage->DeleteValue(L"WriteTest");
  802. }
  803. Storage->Flush();
  804. }
  805. __finally
  806. {
  807. delete Storage;
  808. }
  809. Result = true;
  810. }
  811. catch(...)
  812. {
  813. }
  814. return Result;
  815. }
  816. //---------------------------------------------------------------------------
  817. TStorage __fastcall TWinConfiguration::GetStorage()
  818. {
  819. if (FStorage == stDetect)
  820. {
  821. if (FindResourceEx(NULL, RT_RCDATA, L"WINSCP_SESSION",
  822. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
  823. {
  824. FTemporarySessionFile =
  825. IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscps.tmp";
  826. DumpResourceToFile(L"WINSCP_SESSION", FTemporarySessionFile);
  827. FEmbeddedSessions = true;
  828. FTemporaryKeyFile =
  829. IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscpk.tmp";
  830. if (!DumpResourceToFile(L"WINSCP_KEY", FTemporaryKeyFile))
  831. {
  832. FTemporaryKeyFile = L"";
  833. }
  834. }
  835. FStorage = stIniFile;
  836. if (!FileExists(ApiPath(IniFileStorageNameForReading)))
  837. {
  838. if (DetectRegistryStorage(HKEY_CURRENT_USER) ||
  839. DetectRegistryStorage(HKEY_LOCAL_MACHINE) ||
  840. // FStorage is now stIniFile, so this tests writing to an INI file.
  841. // As we fall back to user profile folder, when application folder
  842. // is not writtable, it is actually unlikely that the below test ever fails.
  843. !CanWriteToStorage())
  844. {
  845. FStorage = stRegistry;
  846. }
  847. }
  848. }
  849. TStorage Result = TCustomWinConfiguration::GetStorage();
  850. return Result;
  851. }
  852. //---------------------------------------------------------------------------
  853. void __fastcall TWinConfiguration::Saved()
  854. {
  855. TCustomWinConfiguration::Saved();
  856. FBookmarks->ModifyAll(false);
  857. FCustomCommandList->Reset();
  858. FEditorList->Saved();
  859. }
  860. //---------------------------------------------------------------------------
  861. void __fastcall TWinConfiguration::RecryptPasswords(TStrings * RecryptPasswordErrors)
  862. {
  863. TCustomWinConfiguration::RecryptPasswords(RecryptPasswordErrors);
  864. try
  865. {
  866. TTerminalManager * Manager = TTerminalManager::Instance(false);
  867. DebugAssert(Manager != NULL);
  868. if (Manager != NULL)
  869. {
  870. Manager->RecryptPasswords();
  871. }
  872. }
  873. catch (Exception & E)
  874. {
  875. UnicodeString Message;
  876. if (ExceptionMessage(&E, Message))
  877. {
  878. // we do not expect this really to happen,
  879. // so we do not bother providing context
  880. RecryptPasswordErrors->Add(Message);
  881. }
  882. }
  883. }
  884. //---------------------------------------------------------------------------
  885. bool __fastcall TWinConfiguration::GetUseMasterPassword()
  886. {
  887. return FUseMasterPassword;
  888. }
  889. //---------------------------------------------------------------------------
  890. THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
  891. {
  892. // Detect embedded session, if not checked yet
  893. GetStorage();
  894. THierarchicalStorage * Result;
  895. if (SessionList && !FTemporarySessionFile.IsEmpty())
  896. {
  897. Result = TIniFileStorage::CreateFromPath(FTemporarySessionFile);
  898. // This is session-list specific store, so the only instance,
  899. // we do not reset the SessionList argument
  900. // (compare TConfiguration::CreateScpStorage)
  901. }
  902. else
  903. {
  904. Result = TCustomWinConfiguration::CreateScpStorage(SessionList);
  905. }
  906. return Result;
  907. }
  908. //---------------------------------------------------------------------------
  909. // duplicated from core\configuration.cpp
  910. #define LASTELEM(ELEM) \
  911. ELEM.SubString(ELEM.LastDelimiter(L".>")+1, ELEM.Length() - ELEM.LastDelimiter(L".>"))
  912. #define BLOCK(KEY, CANCREATE, BLOCK) \
  913. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  914. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  915. #define REGCONFIG(CANCREATE) \
  916. BLOCK(L"Interface", CANCREATE, \
  917. KEYEX(Integer,DoubleClickAction, L"CopyOnDoubleClick"); \
  918. KEY(Bool, CopyOnDoubleClickConfirmation); \
  919. KEYEX(Integer, DDTransferConfirmation, L"DDTransferConfirmation2"); \
  920. KEY(String, DDTemporaryDirectory); \
  921. KEY(String, DDDrives); \
  922. KEY(Bool, DDWarnLackOfTempSpace); \
  923. KEY(Float, DDWarnLackOfTempSpaceRatio); \
  924. KEY(Bool, DeleteToRecycleBin); \
  925. KEY(Bool, DimmHiddenFiles); \
  926. KEY(Bool, RenameWholeName); \
  927. KEY(Bool, SelectDirectories); \
  928. KEY(String, SelectMask); \
  929. KEY(Bool, ShowHiddenFiles); \
  930. KEY(Integer, FormatSizeBytes); \
  931. KEY(Integer, PanelSearch); \
  932. KEY(Bool, ShowInaccesibleDirectories); \
  933. KEY(Bool, ConfirmTransferring); \
  934. KEY(Bool, ConfirmDeleting); \
  935. KEY(Bool, ConfirmRecycling); \
  936. KEY(Bool, ConfirmClosingSession); \
  937. KEY(String, AutoStartSession); \
  938. KEY(Bool, UseLocationProfiles); \
  939. KEY(Bool, UseSharedBookmarks); \
  940. KEY(Integer, LocaleSafe); \
  941. KEY(Bool, DDFakeFile); \
  942. KEY(Integer, DDExtTimeout); \
  943. KEY(Bool, DefaultDirIsHome); \
  944. KEY(Bool, TemporaryDirectoryAppendSession); \
  945. KEY(Bool, TemporaryDirectoryAppendPath); \
  946. KEY(Bool, TemporaryDirectoryDeterministic); \
  947. KEY(Bool, TemporaryDirectoryCleanup); \
  948. KEY(Bool, ConfirmTemporaryDirectoryCleanup); \
  949. KEY(Bool, PreservePanelState); \
  950. KEY(Integer, DarkTheme); \
  951. KEY(String, LastStoredSession); \
  952. KEY(Bool, AutoSaveWorkspace); \
  953. KEY(Bool, AutoSaveWorkspacePasswords); \
  954. KEY(String, AutoWorkspace); \
  955. KEY(Integer, PathInCaption); \
  956. KEY(Bool, MinimizeToTray); \
  957. KEY(Bool, BalloonNotifications); \
  958. KEY(Integer, NotificationsTimeout); \
  959. KEY(Integer, NotificationsStickTime); \
  960. KEY(Bool, CopyParamAutoSelectNotice); \
  961. KEY(Bool, LockToolbars); \
  962. KEY(Bool, SelectiveToolbarText); \
  963. KEY(Bool, AutoOpenInPutty); \
  964. KEY(Bool, RefreshRemotePanel); \
  965. KEY(DateTime, RefreshRemotePanelInterval); \
  966. KEYEX(String, PanelFont.FontName, L"PanelFontName"); \
  967. KEYEX(Integer,PanelFont.FontSize, L"PanelFontSize"); \
  968. KEYEX(Integer,PanelFont.FontStyle, L"PanelFontStyle"); \
  969. KEYEX(Integer,PanelFont.FontCharset, L"PanelFontCharset"); \
  970. KEY(Bool, NaturalOrderNumericalSorting); \
  971. KEY(Bool, FullRowSelect); \
  972. KEY(Bool, OfferedEditorAutoConfig); \
  973. KEY(Integer, LastMonitor); \
  974. KEY(String, VersionHistory); \
  975. KEY(Bool, EnableQueueByDefault); \
  976. KEY(String, OpenedStoredSessionFolders); \
  977. KEY(Bool, AutoImportedFromPuttyOrFilezilla); \
  978. KEY(Integer, GenerateUrlComponents); \
  979. KEY(Integer, GenerateUrlCodeTarget); \
  980. KEY(Integer, GenerateUrlScriptFormat); \
  981. KEY(Integer, GenerateUrlAssemblyLanguage); \
  982. KEY(Bool, ExternalSessionInExistingInstance); \
  983. KEY(Bool, KeepOpenWhenNoSession); \
  984. KEY(Bool, LocalIconsByExt); \
  985. KEY(Integer, BidiModeOverride); \
  986. KEY(Integer, FlipChildrenOverride); \
  987. KEY(Bool, ShowTips); \
  988. KEY(String, TipsSeen); \
  989. KEY(DateTime, TipsShown); \
  990. KEY(String, FileColors); \
  991. KEY(Integer, RunsSinceLastTip); \
  992. KEY(Bool, HonorDrivePolicy); \
  993. KEY(Integer, LastMachineInstallations); \
  994. KEYEX(String, FExtensionsDeleted, L"ExtensionsDeleted"); \
  995. KEYEX(String, FExtensionsOrder, L"ExtensionsOrder"); \
  996. KEYEX(String, FExtensionsShortCuts, L"ExtensionsShortCuts"); \
  997. KEY(Bool, TimeoutShellOperations); \
  998. KEY(Bool, TimeoutShellIconRetrieval); \
  999. KEY(Bool, AllowWindowPrint); \
  1000. ); \
  1001. BLOCK(L"Interface\\Editor", CANCREATE, \
  1002. KEYEX(String, Editor.Font.FontName, L"FontName2"); \
  1003. KEY(Integer, Editor.Font.FontSize); \
  1004. KEY(Integer, Editor.Font.FontStyle); \
  1005. KEY(Integer, Editor.Font.FontCharset); \
  1006. KEY(Integer, Editor.FontColor); \
  1007. KEY(Integer, Editor.BackgroundColor); \
  1008. KEY(Bool, Editor.WordWrap); \
  1009. KEY(String, Editor.FindText); \
  1010. KEY(String, Editor.ReplaceText); \
  1011. KEY(Bool, Editor.FindMatchCase); \
  1012. KEY(Bool, Editor.FindWholeWord); \
  1013. KEY(Bool, Editor.FindDown); \
  1014. KEY(Integer, Editor.TabSize); \
  1015. KEY(Integer, Editor.MaxEditors); \
  1016. KEY(Integer, Editor.EarlyClose); \
  1017. KEY(Bool, Editor.SDIShellEditor); \
  1018. KEY(String, Editor.WindowParams); \
  1019. KEY(Integer, Editor.Encoding); \
  1020. KEY(Bool, Editor.WarnOnEncodingFallback); \
  1021. KEY(Bool, Editor.WarnOrLargeFileSize); \
  1022. ); \
  1023. BLOCK(L"Interface\\QueueView", CANCREATE, \
  1024. KEY(Integer, QueueView.Height); \
  1025. KEY(Integer, QueueView.HeightPixelsPerInch); \
  1026. KEY(String, QueueView.Layout); \
  1027. KEY(Integer, QueueView.Show); \
  1028. KEY(Integer, QueueView.LastHideShow); \
  1029. KEY(Bool, QueueView.ToolBar); \
  1030. KEY(Bool, QueueView.Label); \
  1031. ); \
  1032. BLOCK(L"Interface\\Updates", CANCREATE, \
  1033. KEY(Integer, FUpdates.Period); \
  1034. KEY(DateTime, FUpdates.LastCheck); \
  1035. KEY(Integer, FUpdates.HaveResults); \
  1036. KEY(Integer, FUpdates.ShownResults); \
  1037. KEY(Integer, FUpdates.BetaVersions); \
  1038. KEY(Bool, FUpdates.ShowOnStartup); \
  1039. KEY(String, FUpdates.AuthenticationEmail); \
  1040. KEY(Integer, FUpdates.ConnectionType); \
  1041. KEY(String, FUpdates.ProxyHost); \
  1042. KEY(Integer, FUpdates.ProxyPort); \
  1043. KEY(Integer, FUpdates.Results.ForVersion); \
  1044. KEY(Integer, FUpdates.Results.Version); \
  1045. KEY(String, FUpdates.Results.Message); \
  1046. KEY(Integer, FUpdates.Results.Critical); \
  1047. KEY(String, FUpdates.Results.Release); \
  1048. KEY(Bool, FUpdates.Results.Disabled); \
  1049. KEY(String, FUpdates.Results.Url); \
  1050. KEY(String, FUpdates.Results.UrlButton); \
  1051. KEY(String, FUpdates.Results.NewsUrl); \
  1052. KEYEX(Integer,FUpdates.Results.NewsSize.Width, L"NewsWidth"); \
  1053. KEYEX(Integer,FUpdates.Results.NewsSize.Height, L"NewsHeight"); \
  1054. KEY(String, FUpdates.Results.DownloadUrl); \
  1055. KEY(Int64, FUpdates.Results.DownloadSize); \
  1056. KEY(String, FUpdates.Results.DownloadSha256); \
  1057. KEY(String, FUpdates.Results.AuthenticationError); \
  1058. KEY(Bool, FUpdates.Results.OpenGettingStarted); \
  1059. KEY(String, FUpdates.Results.DownloadingUrl); \
  1060. KEYEX(Integer,FUpdates.Results.TipsSize.Width, L"TipsWidth"); \
  1061. KEYEX(Integer,FUpdates.Results.TipsSize.Height, L"TipsHeight"); \
  1062. KEY(String, FUpdates.Results.TipsUrl); \
  1063. KEY(String, FUpdates.Results.Tips); \
  1064. KEY(Integer, FUpdates.Results.TipsIntervalDays); \
  1065. KEY(Integer, FUpdates.Results.TipsIntervalRuns); \
  1066. KEY(String, FUpdates.DotNetVersion); \
  1067. KEY(String, FUpdates.ConsoleVersion); \
  1068. ); \
  1069. BLOCK(L"Interface\\Explorer", CANCREATE, \
  1070. KEYEX(String, ScpExplorer.ToolbarsLayout, ToolbarsLayoutKey); \
  1071. KEY(String, ScpExplorer.ToolbarsButtons); \
  1072. KEY(String, ScpExplorer.DirViewParams); \
  1073. KEY(String, ScpExplorer.LastLocalTargetDirectory); \
  1074. KEY(Bool, ScpExplorer.SessionsTabs); \
  1075. KEY(Bool, ScpExplorer.StatusBar); \
  1076. KEY(String, ScpExplorer.WindowParams); \
  1077. KEY(Integer, ScpExplorer.ViewStyle); \
  1078. KEY(Bool, ScpExplorer.ShowFullAddress); \
  1079. KEY(Bool, ScpExplorer.DriveView); \
  1080. KEY(Integer, ScpExplorer.DriveViewWidth); \
  1081. KEY(Integer, ScpExplorer.DriveViewWidthPixelsPerInch); \
  1082. ); \
  1083. BLOCK(L"Interface\\Commander", CANCREATE, \
  1084. KEYEX(String, ScpCommander.ToolbarsLayout, ToolbarsLayoutKey); \
  1085. KEY(String, ScpCommander.ToolbarsButtons); \
  1086. KEY(Integer, ScpCommander.CurrentPanel); \
  1087. KEY(Float, ScpCommander.LocalPanelWidth); \
  1088. KEY(Bool, ScpCommander.SwappedPanels); \
  1089. KEY(Bool, ScpCommander.SessionsTabs); \
  1090. KEY(Bool, ScpCommander.StatusBar); \
  1091. KEY(String, ScpCommander.WindowParams); \
  1092. KEYEX(Integer, ScpCommander.NortonLikeMode, L"ExplorerStyleSelection"); \
  1093. KEY(Bool, ScpCommander.PreserveLocalDirectory); \
  1094. KEY(Bool, ScpCommander.CompareByTime); \
  1095. KEY(Bool, ScpCommander.CompareBySize); \
  1096. KEY(Bool, ScpCommander.TreeOnLeft); \
  1097. KEY(Bool, ScpCommander.ExplorerKeyboardShortcuts); \
  1098. KEY(Bool, ScpCommander.SystemContextMenu); \
  1099. ); \
  1100. BLOCK(L"Interface\\Commander\\LocalPanel", CANCREATE, \
  1101. KEY(String, ScpCommander.LocalPanel.DirViewParams); \
  1102. KEY(Bool, ScpCommander.LocalPanel.StatusBar); \
  1103. KEY(Bool, ScpCommander.LocalPanel.DriveView); \
  1104. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeight); \
  1105. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeightPixelsPerInch); \
  1106. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidth); \
  1107. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidthPixelsPerInch); \
  1108. KEY(String, ScpCommander.LocalPanel.LastPath); \
  1109. ); \
  1110. BLOCK(L"Interface\\Commander\\RemotePanel", CANCREATE, \
  1111. KEY(String, ScpCommander.RemotePanel.DirViewParams); \
  1112. KEY(Bool, ScpCommander.RemotePanel.StatusBar); \
  1113. KEY(Bool, ScpCommander.RemotePanel.DriveView); \
  1114. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeight); \
  1115. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeightPixelsPerInch); \
  1116. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidth); \
  1117. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidthPixelsPerInch); \
  1118. KEY(String, ScpCommander.RemotePanel.LastPath); \
  1119. ); \
  1120. BLOCK(L"Security", CANCREATE, \
  1121. KEYEX(Bool, FUseMasterPassword, L"UseMasterPassword"); \
  1122. KEYEX(String,FMasterPasswordVerifier, L"MasterPasswordVerifier"); \
  1123. );
  1124. //---------------------------------------------------------------------------
  1125. void __fastcall TWinConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  1126. {
  1127. TCustomWinConfiguration::SaveData(Storage, All);
  1128. // duplicated from core\configuration.cpp
  1129. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  1130. REGCONFIG(true);
  1131. #undef KEYEX
  1132. if (Storage->OpenSubKey(L"Bookmarks", true))
  1133. {
  1134. FBookmarks->Save(Storage, All);
  1135. Storage->CloseSubKey();
  1136. }
  1137. if ((All && !FCustomCommandsDefaults) || FCustomCommandList->Modified)
  1138. {
  1139. FCustomCommandList->Save(Storage);
  1140. }
  1141. if ((All || FCustomCommandOptionsModified) &&
  1142. Storage->OpenSubKey(L"CustomCommandOptions", true))
  1143. {
  1144. Storage->ClearValues();
  1145. Storage->WriteValues(FCustomCommandOptions.get(), true);
  1146. Storage->CloseSubKey();
  1147. FCustomCommandOptionsModified = false;
  1148. }
  1149. if ((All || FEditorList->Modified) &&
  1150. Storage->OpenSubKey(L"Interface\\Editor", true, true))
  1151. try
  1152. {
  1153. FEditorList->Save(Storage);
  1154. }
  1155. __finally
  1156. {
  1157. Storage->CloseSubKey();
  1158. }
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. void __fastcall TWinConfiguration::LoadFrom(THierarchicalStorage * Storage)
  1162. {
  1163. FLegacyEditor = new TEditorPreferences();
  1164. try
  1165. {
  1166. FLegacyEditor->LegacyDefaults();
  1167. TCustomWinConfiguration::LoadFrom(Storage);
  1168. // Following needs to be done even if there's no Configuration key in the storage,
  1169. // so it cannot be in LoadData
  1170. int EditorCount = FEditorList->Count;
  1171. if (EditorCount == 0)
  1172. {
  1173. TEditorPreferences * AlternativeEditor = NULL;
  1174. try
  1175. {
  1176. if (FLegacyEditor->Data->Editor == edInternal)
  1177. {
  1178. if (!FLegacyEditor->Data->ExternalEditor.IsEmpty())
  1179. {
  1180. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  1181. AlternativeEditor->GetData()->Editor = edExternal;
  1182. FLegacyEditor->GetData()->ExternalEditor = L"";
  1183. }
  1184. }
  1185. else
  1186. {
  1187. if (FLegacyEditor->Data->ExternalEditor.IsEmpty())
  1188. {
  1189. FLegacyEditor->GetData()->Editor = edInternal;
  1190. }
  1191. else
  1192. {
  1193. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  1194. AlternativeEditor->GetData()->Editor = edInternal;
  1195. }
  1196. }
  1197. }
  1198. catch(...)
  1199. {
  1200. delete AlternativeEditor;
  1201. throw;
  1202. }
  1203. FEditorList->Add(FLegacyEditor);
  1204. FLegacyEditor = NULL;
  1205. if (AlternativeEditor != NULL)
  1206. {
  1207. FEditorList->Add(AlternativeEditor);
  1208. }
  1209. }
  1210. // Additionally, this needs to be after Locale is loaded
  1211. LoadExtensionTranslations();
  1212. // and this after the ExtensionsDeleted, ExtensionsOrder and ExtensionsShortCuts are loaded
  1213. LoadExtensionList();
  1214. }
  1215. __finally
  1216. {
  1217. delete FLegacyEditor;
  1218. FLegacyEditor = NULL;
  1219. }
  1220. if (FUpdates.ConnectionType == -1)
  1221. {
  1222. FUpdates.ConnectionType = (FUpdates.ProxyHost.IsEmpty() ? ctAuto : ctProxy);
  1223. }
  1224. AddVersionToHistory();
  1225. }
  1226. //---------------------------------------------------------------------------
  1227. void __fastcall TWinConfiguration::DoLoadExtensionList(
  1228. const UnicodeString & Path, const UnicodeString & PathId, TStringList * DeletedExtensions)
  1229. {
  1230. TSearchRecOwned SearchRec;
  1231. int FindAttrs = faReadOnly | faArchive;
  1232. if (FindFirstUnchecked(IncludeTrailingBackslash(Path) + L"*.*", FindAttrs, SearchRec) == 0)
  1233. {
  1234. do
  1235. {
  1236. UnicodeString Id = TCustomCommandType::GetExtensionId(SearchRec.Name);
  1237. if (!Id.IsEmpty())
  1238. {
  1239. Id = IncludeTrailingBackslash(PathId) + Id;
  1240. if (DeletedExtensions->IndexOf(Id) >= 0)
  1241. {
  1242. // reconstruct the list, so that we remove the commands that no longer exists
  1243. AddToList(FExtensionsDeleted, Id, L"|");
  1244. }
  1245. else
  1246. {
  1247. std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
  1248. CustomCommand->Id = Id;
  1249. try
  1250. {
  1251. CustomCommand->LoadExtension(IncludeTrailingBackslash(Path) + SearchRec.Name);
  1252. FExtensionList->Add(CustomCommand.release());
  1253. }
  1254. catch (...)
  1255. {
  1256. // skip invalid extension files
  1257. }
  1258. }
  1259. }
  1260. }
  1261. while (FindNextChecked(SearchRec) == 0);
  1262. }
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. void __fastcall ParseExtensionList(TStrings * Strings, UnicodeString S)
  1266. {
  1267. while (!S.IsEmpty())
  1268. {
  1269. UnicodeString Extension = CutToChar(S, L'|', false);
  1270. Strings->Add(Extension);
  1271. }
  1272. }
  1273. //---------------------------------------------------------------------------
  1274. const UnicodeString ExtensionsSubFolder(L"Extensions");
  1275. const UnicodeString ExtensionsCommonPathId(L"common");
  1276. const UnicodeString ExtensionsCommonExtPathId(L"commonext");
  1277. const UnicodeString ExtensionsUserExtPathId(L"userext");
  1278. //---------------------------------------------------------------------------
  1279. static UnicodeString __fastcall ExtractExtensionBaseName(const UnicodeString & FileName)
  1280. {
  1281. UnicodeString S = ExtractFileName(FileName);
  1282. // ExtractFileNameOnly trims the last extension only, we want to trim all extensions
  1283. UnicodeString Result = CutToChar(S, L'.', true);
  1284. return Result;
  1285. }
  1286. //---------------------------------------------------------------------------
  1287. UnicodeString __fastcall TWinConfiguration::GetProvisionaryExtensionId(const UnicodeString & FileName)
  1288. {
  1289. return IncludeTrailingBackslash(ExtensionsUserExtPathId) + ExtractExtensionBaseName(FileName);
  1290. }
  1291. //---------------------------------------------------------------------------
  1292. UnicodeString __fastcall TWinConfiguration::GetUserExtensionsPath()
  1293. {
  1294. return IncludeTrailingBackslash(GetShellFolderPath(CSIDL_APPDATA)) + L"WinSCP\\" + ExtensionsSubFolder;
  1295. }
  1296. //---------------------------------------------------------------------------
  1297. TStrings * __fastcall TWinConfiguration::GetExtensionsPaths()
  1298. {
  1299. std::unique_ptr<TStrings> Result(new TStringList());
  1300. UnicodeString ExeParentPath = ExcludeTrailingBackslash(ExtractFilePath(Application->ExeName));
  1301. Result->Values[ExtensionsCommonPathId] = ExeParentPath;
  1302. UnicodeString CommonExtensions = IncludeTrailingBackslash(ExeParentPath) + ExtensionsSubFolder;
  1303. Result->Values[ExtensionsCommonExtPathId] = CommonExtensions;
  1304. Result->Values[ExtensionsUserExtPathId] = GetUserExtensionsPath();
  1305. return Result.release();
  1306. }
  1307. //---------------------------------------------------------------------------
  1308. UnicodeString __fastcall TWinConfiguration::GetExtensionId(const UnicodeString & ExtensionPath)
  1309. {
  1310. UnicodeString Path = ExcludeTrailingBackslash(ExtractFilePath(ExtensionPath));
  1311. UnicodeString NameId = TCustomCommandType::GetExtensionId(ExtractFileName(ExtensionPath));
  1312. if (!NameId.IsEmpty())
  1313. {
  1314. std::unique_ptr<TStrings> ExtensionsPaths(GetExtensionsPaths());
  1315. for (int Index = 0; Index < ExtensionsPaths->Count; Index++)
  1316. {
  1317. if (IsPathToSameFile(Path, ExtensionsPaths->ValueFromIndex[Index]))
  1318. {
  1319. return IncludeTrailingBackslash(ExtensionsPaths->Names[Index]) + NameId;
  1320. }
  1321. }
  1322. }
  1323. return L"";
  1324. }
  1325. //---------------------------------------------------------------------------
  1326. void __fastcall TWinConfiguration::ReleaseExtensionTranslations()
  1327. {
  1328. for (int Index = 0; Index < FExtensionTranslations->Count; Index++)
  1329. {
  1330. delete FExtensionTranslations->Objects[Index];
  1331. }
  1332. FExtensionTranslations->Clear();
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TWinConfiguration::LoadExtensionTranslations()
  1336. {
  1337. ReleaseExtensionTranslations();
  1338. FExtensionTranslations.reset(new TStringList());
  1339. int Index = EXTENSION_STRINGS;
  1340. UnicodeString S;
  1341. while (!((S = LoadStr(Index)).IsEmpty()))
  1342. {
  1343. UnicodeString ExtensionName = CutToChar(S, L'.', false);
  1344. UnicodeString Original = CutToChar(S, L'=', false);
  1345. UnicodeString Translation = S;
  1346. int ExtensionIndex = FExtensionTranslations->IndexOf(ExtensionName);
  1347. if (ExtensionIndex < 0)
  1348. {
  1349. ExtensionIndex = FExtensionTranslations->AddObject(ExtensionName, new TStringList());
  1350. }
  1351. TStringList * ExtensionTranslation = DebugNotNull(dynamic_cast<TStringList *>(FExtensionTranslations->Objects[ExtensionIndex]));
  1352. ExtensionTranslation->Values[Original] = Translation;
  1353. Index++;
  1354. }
  1355. }
  1356. //---------------------------------------------------------------------------
  1357. UnicodeString __fastcall TWinConfiguration::UniqueExtensionName(const UnicodeString & ExtensionName, int Counter)
  1358. {
  1359. // See how the digits are removed in the ExtensionStringTranslation
  1360. return ExtensionName + IntToStr(Counter);
  1361. }
  1362. //---------------------------------------------------------------------------
  1363. UnicodeString __fastcall TWinConfiguration::ExtensionStringTranslation(const UnicodeString & ExtensionId, const UnicodeString & S)
  1364. {
  1365. UnicodeString Result = S;
  1366. if (!ExtensionId.IsEmpty())
  1367. {
  1368. UnicodeString ExtensionName = ExtractFileName(ExtensionId);
  1369. int ExtensionIndex;
  1370. bool Retry;
  1371. do
  1372. {
  1373. ExtensionIndex = FExtensionTranslations->IndexOf(ExtensionName);
  1374. // Try without trailing digits, possibly added by UniqueExtensionName
  1375. Retry = (ExtensionIndex < 0) && !ExtensionName.IsEmpty() && IsDigit(*ExtensionName.LastChar());
  1376. if (Retry)
  1377. {
  1378. ExtensionName.SetLength(ExtensionName.Length() - 1);
  1379. }
  1380. }
  1381. while (Retry);
  1382. if (ExtensionIndex >= 0)
  1383. {
  1384. TStrings * ExtensionTranslation = DebugNotNull(dynamic_cast<TStrings *>(FExtensionTranslations->Objects[ExtensionIndex]));
  1385. int StringIndex = ExtensionTranslation->IndexOfName(S);
  1386. if (StringIndex >= 0)
  1387. {
  1388. Result = ExtensionTranslation->ValueFromIndex[StringIndex];
  1389. }
  1390. }
  1391. }
  1392. return Result;
  1393. }
  1394. //---------------------------------------------------------------------------
  1395. void __fastcall TWinConfiguration::LoadExtensionList()
  1396. {
  1397. FExtensionList->Clear();
  1398. std::unique_ptr<TStringList> DeletedExtensions(CreateSortedStringList());
  1399. ParseExtensionList(DeletedExtensions.get(), FExtensionsDeleted);
  1400. // will reconstruct the list in DoLoadExtensionList
  1401. FExtensionsDeleted = L"";
  1402. std::unique_ptr<TStrings> ExtensionsPaths(GetExtensionsPaths());
  1403. for (int Index = 0; Index < ExtensionsPaths->Count; Index++)
  1404. {
  1405. DoLoadExtensionList(ExtensionsPaths->ValueFromIndex[Index], ExtensionsPaths->Names[Index], DeletedExtensions.get());
  1406. }
  1407. std::unique_ptr<TStringList> OrderedExtensions(new TStringList());
  1408. ParseExtensionList(OrderedExtensions.get(), FExtensionsOrder);
  1409. FExtensionList->SortBy(OrderedExtensions.get());
  1410. UnicodeString ShortCuts = FExtensionsShortCuts;
  1411. while (!ShortCuts.IsEmpty())
  1412. {
  1413. UnicodeString S = CutToChar(ShortCuts, L'|', false);
  1414. TShortCut ShortCut = static_cast<TShortCut>(StrToInt(CutToChar(S, L'=', false)));
  1415. for (int Index = 0; Index < FExtensionList->Count; Index++)
  1416. {
  1417. if (FExtensionList->Commands[Index]->Id == S)
  1418. {
  1419. const_cast<TCustomCommandType *>(FExtensionList->Commands[Index])->ShortCut = ShortCut;
  1420. }
  1421. }
  1422. }
  1423. }
  1424. //---------------------------------------------------------------------------
  1425. static UnicodeString KeyName(THierarchicalStorage * Storage, const UnicodeString & Name)
  1426. {
  1427. UnicodeString Result = Name;
  1428. if ((Result == ToolbarsLayoutKey) && !Storage->KeyExists(Result) && Storage->KeyExists(ToolbarsLayoutOldKey))
  1429. {
  1430. Result = ToolbarsLayoutOldKey;
  1431. }
  1432. return Result;
  1433. }
  1434. //---------------------------------------------------------------------------
  1435. void __fastcall TWinConfiguration::LoadData(THierarchicalStorage * Storage)
  1436. {
  1437. TCustomWinConfiguration::LoadData(Storage);
  1438. // duplicated from core\configuration.cpp
  1439. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(KeyName(Storage, NAME), VAR)
  1440. #pragma warn -eas
  1441. REGCONFIG(false);
  1442. #pragma warn +eas
  1443. #undef KEYEX
  1444. // to reflect changes to PanelFont
  1445. UpdateIconFont();
  1446. if (Storage->OpenSubKey(L"Bookmarks", false))
  1447. {
  1448. FBookmarks->Load(Storage);
  1449. Storage->CloseSubKey();
  1450. }
  1451. if (Storage->KeyExists(L"CustomCommands"))
  1452. {
  1453. FCustomCommandList->Load(Storage);
  1454. FCustomCommandsDefaults = false;
  1455. }
  1456. else if (FCustomCommandList->Modified)
  1457. {
  1458. // can this (=reloading of configuration) even happen?
  1459. // if it does, shouldn't we reset default commands?
  1460. DebugFail();
  1461. FCustomCommandList->Clear();
  1462. FCustomCommandsDefaults = false;
  1463. }
  1464. FCustomCommandList->Reset();
  1465. if (Storage->OpenSubKey(L"CustomCommandOptions", false))
  1466. {
  1467. Storage->ReadValues(FCustomCommandOptions.get(), true);
  1468. Storage->CloseSubKey();
  1469. FCustomCommandOptionsModified = false;
  1470. }
  1471. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1472. try
  1473. {
  1474. FEditorList->Clear();
  1475. FEditorList->Load(Storage);
  1476. }
  1477. __finally
  1478. {
  1479. Storage->CloseSubKey();
  1480. }
  1481. // load legacy editor configuration
  1482. DebugAssert(FLegacyEditor != NULL);
  1483. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1484. {
  1485. try
  1486. {
  1487. FLegacyEditor->Load(Storage, true);
  1488. }
  1489. __finally
  1490. {
  1491. Storage->CloseSubKey();
  1492. }
  1493. }
  1494. }
  1495. //---------------------------------------------------------------------------
  1496. void __fastcall TWinConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  1497. {
  1498. TCustomWinConfiguration::LoadAdmin(Storage);
  1499. FDisableOpenEdit = Storage->ReadBool(L"DisableOpenEdit", FDisableOpenEdit);
  1500. FDefaultUpdatesPeriod = Storage->ReadInteger(L"DefaultUpdatesPeriod", FDefaultUpdatesPeriod);
  1501. FMachineInstallations = Storage->ReadInteger(L"Installations", 0);
  1502. }
  1503. //---------------------------------------------------------------------------
  1504. void __fastcall TWinConfiguration::CopyData(THierarchicalStorage * Source, THierarchicalStorage * Target)
  1505. {
  1506. TCustomWinConfiguration::CopyData(Source, Target);
  1507. if (CopySubKey(Source, Target, ConfigurationSubKey))
  1508. {
  1509. Target->WriteString(L"JumpList", Source->ReadString(L"JumpList", L""));
  1510. Target->WriteString(L"JumpListWorkspaces", Source->ReadString(L"JumpListWorkspaces", L""));
  1511. Target->CloseSubKey();
  1512. Source->CloseSubKey();
  1513. }
  1514. }
  1515. //---------------------------------------------------------------------------
  1516. void __fastcall TWinConfiguration::ClearTemporaryLoginData()
  1517. {
  1518. if (!FTemporaryKeyFile.IsEmpty())
  1519. {
  1520. DeleteFile(ApiPath(FTemporaryKeyFile));
  1521. FTemporaryKeyFile = L"";
  1522. }
  1523. }
  1524. //---------------------------------------------------------------------------
  1525. void __fastcall TWinConfiguration::AddVersionToHistory()
  1526. {
  1527. int CurrentVersion = CompoundVersion;
  1528. int From = 1;
  1529. bool CurrentVersionPresent = false;
  1530. while (!CurrentVersionPresent && (From < FVersionHistory.Length()))
  1531. {
  1532. UnicodeString VersionInfo = CopyToChars(FVersionHistory, From, L";", true);
  1533. UnicodeString VersionStr = CutToChar(VersionInfo, L',', true);
  1534. int Version;
  1535. if (TryStrToInt(VersionStr, Version) &&
  1536. (Version == CurrentVersion))
  1537. {
  1538. CurrentVersionPresent = true;
  1539. }
  1540. }
  1541. if (!CurrentVersionPresent)
  1542. {
  1543. UnicodeString CurrentVersionInfo =
  1544. IntToStr(CurrentVersion) + L"," + GetReleaseType();
  1545. AddToList(FVersionHistory, CurrentVersionInfo, L';');
  1546. }
  1547. Usage->Set(L"AnyBetaUsed", AnyBetaInVersionHistory);
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. bool __fastcall TWinConfiguration::DoIsBeta(const UnicodeString & ReleaseType)
  1551. {
  1552. // What about "Development" release type?
  1553. return SameText(ReleaseType, L"beta") || SameText(ReleaseType, L"rc");
  1554. }
  1555. //---------------------------------------------------------------------------
  1556. bool __fastcall TWinConfiguration::GetIsBeta()
  1557. {
  1558. return DoIsBeta(GetReleaseType());
  1559. }
  1560. //---------------------------------------------------------------------------
  1561. bool __fastcall TWinConfiguration::GetAnyBetaInVersionHistory()
  1562. {
  1563. int From = 1;
  1564. bool AnyBeta = false;
  1565. while (!AnyBeta && (From < VersionHistory.Length()))
  1566. {
  1567. UnicodeString VersionInfo = CopyToChars(VersionHistory, From, L";", true);
  1568. CutToChar(VersionInfo, L',', true);
  1569. UnicodeString ReleaseType = CutToChar(VersionInfo, ',', true);
  1570. if (DoIsBeta(ReleaseType))
  1571. {
  1572. AnyBeta = true;
  1573. }
  1574. }
  1575. return AnyBeta;
  1576. }
  1577. //---------------------------------------------------------------------------
  1578. bool __fastcall TWinConfiguration::GetDDExtInstalled()
  1579. {
  1580. if (FDDExtInstalled < 0)
  1581. {
  1582. if (IsWin64())
  1583. {
  1584. // WORKAROUND
  1585. // We cannot load 64-bit COM class into 32-bit process,
  1586. // so we fallback to querying registration keys
  1587. #define CLSID_SIZE 39
  1588. wchar_t ClassID[CLSID_SIZE];
  1589. StringFromGUID2(CLSID_ShellExtension, ClassID, LENOF(ClassID));
  1590. NULL_TERMINATE(ClassID);
  1591. UnicodeString SubKey = UnicodeString(L"CLSID\\") + ClassID;
  1592. HKEY HKey;
  1593. LONG Result = RegOpenKeyEx(HKEY_CLASSES_ROOT, SubKey.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &HKey);
  1594. if (Result == ERROR_SUCCESS)
  1595. {
  1596. RegCloseKey(HKey);
  1597. FDDExtInstalled = 1;
  1598. }
  1599. else
  1600. {
  1601. FDDExtInstalled = 0;
  1602. }
  1603. }
  1604. else
  1605. {
  1606. void * DragExtRef;
  1607. int CreateResult =
  1608. CoCreateInstance(CLSID_ShellExtension, NULL,
  1609. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
  1610. &DragExtRef);
  1611. bool Result = (CreateResult == S_OK);
  1612. FDDExtInstalled = (Result ? 1 : 0);
  1613. if (Result)
  1614. {
  1615. reinterpret_cast<IUnknown *>(DragExtRef)->Release();
  1616. CoFreeUnusedLibraries();
  1617. }
  1618. }
  1619. }
  1620. return (FDDExtInstalled > 0);
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. bool __fastcall TWinConfiguration::IsDDExtRunning()
  1624. {
  1625. bool Result;
  1626. if (!DDExtInstalled)
  1627. {
  1628. Result = false;
  1629. }
  1630. else
  1631. {
  1632. HANDLE H = OpenMutex(SYNCHRONIZE, False, DRAG_EXT_RUNNING_MUTEX);
  1633. Result = (H != NULL);
  1634. CloseHandle(H);
  1635. }
  1636. return Result;
  1637. }
  1638. //---------------------------------------------------------------------------
  1639. bool __fastcall TWinConfiguration::IsDDExtBroken()
  1640. {
  1641. int Build = GetWindowsBuild();
  1642. return (Build >= 17134) && (Build < 17763);
  1643. }
  1644. //---------------------------------------------------------------------------
  1645. RawByteString __fastcall TWinConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString Key)
  1646. {
  1647. RawByteString Dummy;
  1648. RawByteString Result;
  1649. if (GetExternalEncryptedPassword(Password, Dummy) ||
  1650. !FUseMasterPassword)
  1651. {
  1652. // already-strongly encrypted
  1653. // or no master password set, so we cannot strongly-encrypt it
  1654. Result = Password;
  1655. }
  1656. else
  1657. {
  1658. UnicodeString PasswordText =
  1659. TCustomWinConfiguration::DecryptPassword(Password, Key);
  1660. if (!PasswordText.IsEmpty())
  1661. {
  1662. // can be not set for instance, when editing=>saving site with no prior password
  1663. AskForMasterPasswordIfNotSet();
  1664. Password = ScramblePassword(PasswordText);
  1665. AES256EncyptWithMAC(Password, FPlainMasterPasswordEncrypt, Result);
  1666. Result = SetExternalEncryptedPassword(Result);
  1667. }
  1668. }
  1669. return Result;
  1670. }
  1671. //---------------------------------------------------------------------------
  1672. UnicodeString __fastcall TWinConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
  1673. {
  1674. UnicodeString Result;
  1675. RawByteString Buf;
  1676. if (GetExternalEncryptedPassword(Password, Buf))
  1677. {
  1678. if (FDontDecryptPasswords == 0)
  1679. {
  1680. // As opposite to AskForMasterPasswordIfNotSet, we test here
  1681. // for decrypt password. This is important while recrypting password,
  1682. // when clearing master password, when encrypt password is already empty.
  1683. if (FPlainMasterPasswordDecrypt.IsEmpty())
  1684. {
  1685. AskForMasterPassword();
  1686. }
  1687. if (!AES256DecryptWithMAC(Buf, FPlainMasterPasswordDecrypt, Buf) ||
  1688. !UnscramblePassword(Buf, Result))
  1689. {
  1690. throw Exception(LoadStr(DECRYPT_PASSWORD_ERROR));
  1691. }
  1692. }
  1693. else
  1694. {
  1695. Abort();
  1696. }
  1697. }
  1698. else
  1699. {
  1700. Result = TCustomWinConfiguration::DecryptPassword(Password, Key);
  1701. }
  1702. return Result;
  1703. }
  1704. //---------------------------------------------------------------------------
  1705. void __fastcall TWinConfiguration::SetMasterPassword(UnicodeString value)
  1706. {
  1707. // just stores the plain-text version of the password
  1708. // we can get here even if master password is off,
  1709. // when we encounter stray encrypted password (e.g. manually imported site),
  1710. // make sure we do not set encrypt password to avoid starting encrypting
  1711. // new passwords
  1712. // (this is bit of edge case, not really well tested)
  1713. if (!FUseMasterPassword)
  1714. {
  1715. FPlainMasterPasswordDecrypt = value;
  1716. }
  1717. else if (DebugAlwaysTrue(FUseMasterPassword) &&
  1718. DebugAlwaysTrue(ValidateMasterPassword(value)))
  1719. {
  1720. FPlainMasterPasswordEncrypt = value;
  1721. FPlainMasterPasswordDecrypt = value;
  1722. }
  1723. }
  1724. //---------------------------------------------------------------------------
  1725. void __fastcall TWinConfiguration::ChangeMasterPassword(
  1726. UnicodeString value, TStrings * RecryptPasswordErrors)
  1727. {
  1728. RawByteString Verifier;
  1729. AES256CreateVerifier(value, Verifier);
  1730. FMasterPasswordVerifier = BytesToHex(Verifier);
  1731. FPlainMasterPasswordEncrypt = value;
  1732. FUseMasterPassword = true;
  1733. try
  1734. {
  1735. RecryptPasswords(RecryptPasswordErrors);
  1736. }
  1737. __finally
  1738. {
  1739. FPlainMasterPasswordDecrypt = value;
  1740. }
  1741. }
  1742. //---------------------------------------------------------------------------
  1743. bool __fastcall TWinConfiguration::ValidateMasterPassword(UnicodeString value)
  1744. {
  1745. DebugAssert(UseMasterPassword);
  1746. DebugAssert(!FMasterPasswordVerifier.IsEmpty());
  1747. bool Result = AES256Verify(value, HexToBytes(FMasterPasswordVerifier));
  1748. return Result;
  1749. }
  1750. //---------------------------------------------------------------------------
  1751. void __fastcall TWinConfiguration::ClearMasterPassword(TStrings * RecryptPasswordErrors)
  1752. {
  1753. FMasterPasswordVerifier = L"";
  1754. FUseMasterPassword = false;
  1755. Shred(FPlainMasterPasswordEncrypt);
  1756. try
  1757. {
  1758. RecryptPasswords(RecryptPasswordErrors);
  1759. }
  1760. __finally
  1761. {
  1762. Shred(FPlainMasterPasswordDecrypt);
  1763. }
  1764. }
  1765. //---------------------------------------------------------------------------
  1766. void __fastcall TWinConfiguration::AskForMasterPassword()
  1767. {
  1768. if (FMasterPasswordSession > 0)
  1769. {
  1770. if (FMasterPasswordSessionAsked)
  1771. {
  1772. Abort();
  1773. }
  1774. // set before call to OnMasterPasswordPrompt as it may abort
  1775. FMasterPasswordSessionAsked = true;
  1776. }
  1777. if (FOnMasterPasswordPrompt == NULL)
  1778. {
  1779. throw Exception(L"Master password handler not set");
  1780. }
  1781. else
  1782. {
  1783. FOnMasterPasswordPrompt();
  1784. DebugAssert(!FPlainMasterPasswordDecrypt.IsEmpty());
  1785. }
  1786. }
  1787. //---------------------------------------------------------------------------
  1788. void __fastcall TWinConfiguration::AskForMasterPasswordIfNotSet()
  1789. {
  1790. if (FPlainMasterPasswordEncrypt.IsEmpty())
  1791. {
  1792. AskForMasterPassword();
  1793. }
  1794. }
  1795. //---------------------------------------------------------------------------
  1796. void __fastcall TWinConfiguration::BeginMasterPasswordSession()
  1797. {
  1798. // We do not expect nesting
  1799. DebugAssert(FMasterPasswordSession == 0);
  1800. DebugAssert(!FMasterPasswordSessionAsked || (FMasterPasswordSession > 0));
  1801. // This should better be thread-specific
  1802. FMasterPasswordSession++;
  1803. }
  1804. //---------------------------------------------------------------------------
  1805. void __fastcall TWinConfiguration::EndMasterPasswordSession()
  1806. {
  1807. if (DebugAlwaysTrue(FMasterPasswordSession > 0))
  1808. {
  1809. FMasterPasswordSession--;
  1810. }
  1811. FMasterPasswordSessionAsked = false;
  1812. }
  1813. //---------------------------------------------------------------------------
  1814. void __fastcall TWinConfiguration::SetDDTransferConfirmation(TAutoSwitch value)
  1815. {
  1816. SET_CONFIG_PROPERTY(DDTransferConfirmation);
  1817. }
  1818. //---------------------------------------------------------------------------
  1819. void __fastcall TWinConfiguration::SetDDTemporaryDirectory(UnicodeString value)
  1820. {
  1821. SET_CONFIG_PROPERTY(DDTemporaryDirectory);
  1822. }
  1823. //---------------------------------------------------------------------------
  1824. void __fastcall TWinConfiguration::SetDDDrives(UnicodeString value)
  1825. {
  1826. SET_CONFIG_PROPERTY(DDDrives);
  1827. }
  1828. //---------------------------------------------------------------------------
  1829. void __fastcall TWinConfiguration::SetDDFakeFile(bool value)
  1830. {
  1831. SET_CONFIG_PROPERTY(DDFakeFile);
  1832. }
  1833. //---------------------------------------------------------------------------
  1834. void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
  1835. {
  1836. SET_CONFIG_PROPERTY(DDExtTimeout);
  1837. }
  1838. //---------------------------------------------------------------------------
  1839. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpace(bool value)
  1840. {
  1841. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpace);
  1842. }
  1843. //---------------------------------------------------------------------------
  1844. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpaceRatio(double value)
  1845. {
  1846. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpaceRatio);
  1847. }
  1848. //---------------------------------------------------------------------------
  1849. void __fastcall TWinConfiguration::SetScpExplorer(TScpExplorerConfiguration value)
  1850. {
  1851. SET_CONFIG_PROPERTY(ScpExplorer);
  1852. }
  1853. //---------------------------------------------------------------------------
  1854. void __fastcall TWinConfiguration::SetScpCommander(TScpCommanderConfiguration value)
  1855. {
  1856. SET_CONFIG_PROPERTY(ScpCommander);
  1857. }
  1858. //---------------------------------------------------------------------------
  1859. void __fastcall TWinConfiguration::SetEditor(TEditorConfiguration value)
  1860. {
  1861. SET_CONFIG_PROPERTY(Editor);
  1862. }
  1863. //---------------------------------------------------------------------------
  1864. void __fastcall TWinConfiguration::SetQueueView(TQueueViewConfiguration value)
  1865. {
  1866. SET_CONFIG_PROPERTY(QueueView);
  1867. }
  1868. //---------------------------------------------------------------------------
  1869. void __fastcall TWinConfiguration::SetEnableQueueByDefault(bool value)
  1870. {
  1871. SET_CONFIG_PROPERTY(EnableQueueByDefault);
  1872. }
  1873. //---------------------------------------------------------------------------
  1874. TUpdatesConfiguration __fastcall TWinConfiguration::GetUpdates()
  1875. {
  1876. TUpdatesConfiguration Result;
  1877. {
  1878. TGuard Guard(FCriticalSection);
  1879. Result = FUpdates;
  1880. }
  1881. return Result;
  1882. }
  1883. //---------------------------------------------------------------------------
  1884. void __fastcall TWinConfiguration::SetUpdates(TUpdatesConfiguration value)
  1885. {
  1886. TGuard Guard(FCriticalSection);
  1887. // do not use SET_CONFIG_PROPERTY to avoid OnChange handler call (not synchronized)
  1888. FUpdates = value;
  1889. }
  1890. //---------------------------------------------------------------------------
  1891. void __fastcall TWinConfiguration::SetVersionHistory(UnicodeString value)
  1892. {
  1893. SET_CONFIG_PROPERTY(VersionHistory);
  1894. }
  1895. //---------------------------------------------------------------------------
  1896. void __fastcall TWinConfiguration::SetDeleteToRecycleBin(bool value)
  1897. {
  1898. SET_CONFIG_PROPERTY(DeleteToRecycleBin);
  1899. }
  1900. //---------------------------------------------------------------------------
  1901. void __fastcall TWinConfiguration::SetSelectDirectories(bool value)
  1902. {
  1903. SET_CONFIG_PROPERTY(SelectDirectories);
  1904. }
  1905. //---------------------------------------------------------------------------
  1906. void __fastcall TWinConfiguration::SetShowHiddenFiles(bool value)
  1907. {
  1908. SET_CONFIG_PROPERTY(ShowHiddenFiles);
  1909. }
  1910. //---------------------------------------------------------------------------
  1911. void __fastcall TWinConfiguration::SetFormatSizeBytes(TFormatBytesStyle value)
  1912. {
  1913. SET_CONFIG_PROPERTY(FormatSizeBytes);
  1914. }
  1915. //---------------------------------------------------------------------------
  1916. void __fastcall TWinConfiguration::SetPanelSearch(TIncrementalSearch value)
  1917. {
  1918. SET_CONFIG_PROPERTY(PanelSearch);
  1919. }
  1920. //---------------------------------------------------------------------------
  1921. void __fastcall TWinConfiguration::SetShowInaccesibleDirectories(bool value)
  1922. {
  1923. SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
  1924. }
  1925. //---------------------------------------------------------------------------
  1926. void __fastcall TWinConfiguration::SetConfirmTransferring(bool value)
  1927. {
  1928. SET_CONFIG_PROPERTY(ConfirmTransferring);
  1929. }
  1930. //---------------------------------------------------------------------------
  1931. void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
  1932. {
  1933. SET_CONFIG_PROPERTY(ConfirmDeleting);
  1934. }
  1935. //---------------------------------------------------------------------------
  1936. void __fastcall TWinConfiguration::SetConfirmRecycling(bool value)
  1937. {
  1938. SET_CONFIG_PROPERTY(ConfirmRecycling);
  1939. }
  1940. //---------------------------------------------------------------------------
  1941. void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
  1942. {
  1943. SET_CONFIG_PROPERTY(UseLocationProfiles);
  1944. }
  1945. //---------------------------------------------------------------------------
  1946. void __fastcall TWinConfiguration::SetUseSharedBookmarks(bool value)
  1947. {
  1948. SET_CONFIG_PROPERTY(UseSharedBookmarks);
  1949. }
  1950. //---------------------------------------------------------------------------
  1951. void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
  1952. {
  1953. SET_CONFIG_PROPERTY(ConfirmClosingSession);
  1954. }
  1955. //---------------------------------------------------------------------------
  1956. void __fastcall TWinConfiguration::SetDoubleClickAction(TDoubleClickAction value)
  1957. {
  1958. SET_CONFIG_PROPERTY(DoubleClickAction);
  1959. }
  1960. //---------------------------------------------------------------------------
  1961. void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
  1962. {
  1963. SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
  1964. }
  1965. //---------------------------------------------------------------------------
  1966. void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
  1967. {
  1968. SET_CONFIG_PROPERTY(DimmHiddenFiles);
  1969. }
  1970. //---------------------------------------------------------------------------
  1971. void __fastcall TWinConfiguration::SetRenameWholeName(bool value)
  1972. {
  1973. SET_CONFIG_PROPERTY(RenameWholeName);
  1974. }
  1975. //---------------------------------------------------------------------------
  1976. void __fastcall TWinConfiguration::SetAutoStartSession(UnicodeString value)
  1977. {
  1978. SET_CONFIG_PROPERTY(AutoStartSession);
  1979. }
  1980. //---------------------------------------------------------------------------
  1981. void __fastcall TWinConfiguration::SetExpertMode(bool value)
  1982. {
  1983. SET_CONFIG_PROPERTY(ExpertMode);
  1984. }
  1985. //---------------------------------------------------------------------------
  1986. void __fastcall TWinConfiguration::SetDefaultDirIsHome(bool value)
  1987. {
  1988. SET_CONFIG_PROPERTY(DefaultDirIsHome);
  1989. }
  1990. //---------------------------------------------------------------------------
  1991. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendSession(bool value)
  1992. {
  1993. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendSession);
  1994. }
  1995. //---------------------------------------------------------------------------
  1996. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendPath(bool value)
  1997. {
  1998. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendPath);
  1999. }
  2000. //---------------------------------------------------------------------------
  2001. void __fastcall TWinConfiguration::SetTemporaryDirectoryDeterministic(bool value)
  2002. {
  2003. SET_CONFIG_PROPERTY(TemporaryDirectoryDeterministic);
  2004. }
  2005. //---------------------------------------------------------------------------
  2006. void __fastcall TWinConfiguration::SetTemporaryDirectoryCleanup(bool value)
  2007. {
  2008. SET_CONFIG_PROPERTY(TemporaryDirectoryCleanup);
  2009. }
  2010. //---------------------------------------------------------------------------
  2011. void __fastcall TWinConfiguration::SetConfirmTemporaryDirectoryCleanup(bool value)
  2012. {
  2013. SET_CONFIG_PROPERTY(ConfirmTemporaryDirectoryCleanup);
  2014. }
  2015. //---------------------------------------------------------------------------
  2016. void __fastcall TWinConfiguration::SetPreservePanelState(bool value)
  2017. {
  2018. SET_CONFIG_PROPERTY(PreservePanelState);
  2019. }
  2020. //---------------------------------------------------------------------------
  2021. void __fastcall TWinConfiguration::SetDarkTheme(TAutoSwitch value)
  2022. {
  2023. SET_CONFIG_PROPERTY_EX(DarkTheme, ConfigureInterface());
  2024. }
  2025. //---------------------------------------------------------------------------
  2026. static int __fastcall SysDarkTheme(HKEY RootKey)
  2027. {
  2028. std::unique_ptr<TRegistry> Registry(new TRegistry());
  2029. Registry->RootKey = RootKey;
  2030. UnicodeString ThemesPersonalizeKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
  2031. UnicodeString AppsUseLightThemeValue = L"AppsUseLightTheme";
  2032. int Result = -1;
  2033. if (Registry->OpenKeyReadOnly(ThemesPersonalizeKey) &&
  2034. Registry->ValueExists(AppsUseLightThemeValue))
  2035. {
  2036. Result = Registry->ReadBool(AppsUseLightThemeValue) ? 0 : 1;
  2037. }
  2038. return Result;
  2039. }
  2040. //---------------------------------------------------------------------------
  2041. void __fastcall TWinConfiguration::ResetSysDarkTheme()
  2042. {
  2043. FSysDarkTheme = -1;
  2044. }
  2045. //---------------------------------------------------------------------------
  2046. bool __fastcall TWinConfiguration::UseDarkTheme()
  2047. {
  2048. if (FSysDarkTheme < 0)
  2049. {
  2050. FSysDarkTheme = SysDarkTheme(HKEY_CURRENT_USER);
  2051. if (FSysDarkTheme < 0)
  2052. {
  2053. FSysDarkTheme = SysDarkTheme(HKEY_LOCAL_MACHINE);
  2054. if (FSysDarkTheme < 0)
  2055. {
  2056. FSysDarkTheme = 0;
  2057. }
  2058. }
  2059. }
  2060. switch (WinConfiguration->DarkTheme)
  2061. {
  2062. case asOn:
  2063. return true;
  2064. case asOff:
  2065. return false;
  2066. default:
  2067. return (FSysDarkTheme > 0);
  2068. }
  2069. }
  2070. //---------------------------------------------------------------------------
  2071. void __fastcall TWinConfiguration::SetLastStoredSession(UnicodeString value)
  2072. {
  2073. SET_CONFIG_PROPERTY(LastStoredSession);
  2074. }
  2075. //---------------------------------------------------------------------------
  2076. void __fastcall TWinConfiguration::SetAutoSaveWorkspace(bool value)
  2077. {
  2078. SET_CONFIG_PROPERTY(AutoSaveWorkspace);
  2079. }
  2080. //---------------------------------------------------------------------------
  2081. void __fastcall TWinConfiguration::SetAutoSaveWorkspacePasswords(bool value)
  2082. {
  2083. SET_CONFIG_PROPERTY(AutoSaveWorkspacePasswords);
  2084. }
  2085. //---------------------------------------------------------------------------
  2086. void __fastcall TWinConfiguration::SetAutoWorkspace(UnicodeString value)
  2087. {
  2088. SET_CONFIG_PROPERTY(AutoWorkspace);
  2089. }
  2090. //---------------------------------------------------------------------------
  2091. void __fastcall TWinConfiguration::SetPathInCaption(TPathInCaption value)
  2092. {
  2093. SET_CONFIG_PROPERTY(PathInCaption);
  2094. }
  2095. //---------------------------------------------------------------------------
  2096. void __fastcall TWinConfiguration::SetMinimizeToTray(bool value)
  2097. {
  2098. SET_CONFIG_PROPERTY(MinimizeToTray);
  2099. }
  2100. //---------------------------------------------------------------------------
  2101. void __fastcall TWinConfiguration::MinimizeToTrayOnce()
  2102. {
  2103. FMinimizeToTrayOnce = true;
  2104. }
  2105. //---------------------------------------------------------------------------
  2106. bool __fastcall TWinConfiguration::GetMinimizeToTray()
  2107. {
  2108. bool Result = FMinimizeToTrayOnce || FMinimizeToTray;
  2109. FMinimizeToTrayOnce = false;
  2110. return Result;
  2111. }
  2112. //---------------------------------------------------------------------------
  2113. void __fastcall TWinConfiguration::SetBalloonNotifications(bool value)
  2114. {
  2115. SET_CONFIG_PROPERTY(BalloonNotifications);
  2116. }
  2117. //---------------------------------------------------------------------------
  2118. void __fastcall TWinConfiguration::SetNotificationsTimeout(unsigned int value)
  2119. {
  2120. SET_CONFIG_PROPERTY(NotificationsTimeout);
  2121. }
  2122. //---------------------------------------------------------------------------
  2123. void __fastcall TWinConfiguration::SetNotificationsStickTime(unsigned int value)
  2124. {
  2125. SET_CONFIG_PROPERTY(NotificationsStickTime);
  2126. }
  2127. //---------------------------------------------------------------------------
  2128. void __fastcall TWinConfiguration::SetCopyParamAutoSelectNotice(bool value)
  2129. {
  2130. SET_CONFIG_PROPERTY(CopyParamAutoSelectNotice);
  2131. }
  2132. //---------------------------------------------------------------------------
  2133. void __fastcall TWinConfiguration::SetLockToolbars(bool value)
  2134. {
  2135. SET_CONFIG_PROPERTY(LockToolbars);
  2136. }
  2137. //---------------------------------------------------------------------------
  2138. void __fastcall TWinConfiguration::SetSelectiveToolbarText(bool value)
  2139. {
  2140. SET_CONFIG_PROPERTY(SelectiveToolbarText);
  2141. }
  2142. //---------------------------------------------------------------------------
  2143. void __fastcall TWinConfiguration::SetAutoOpenInPutty(bool value)
  2144. {
  2145. SET_CONFIG_PROPERTY(AutoOpenInPutty);
  2146. }
  2147. //---------------------------------------------------------------------------
  2148. void __fastcall TWinConfiguration::SetRefreshRemotePanel(bool value)
  2149. {
  2150. SET_CONFIG_PROPERTY(RefreshRemotePanel);
  2151. }
  2152. //---------------------------------------------------------------------------
  2153. void __fastcall TWinConfiguration::SetRefreshRemotePanelInterval(TDateTime value)
  2154. {
  2155. SET_CONFIG_PROPERTY(RefreshRemotePanelInterval);
  2156. }
  2157. //---------------------------------------------------------------------------
  2158. void __fastcall TWinConfiguration::UpdateIconFont()
  2159. {
  2160. UpdateDesktopFont();
  2161. }
  2162. //---------------------------------------------------------------------------
  2163. void __fastcall TWinConfiguration::SetPanelFont(const TFontConfiguration & value)
  2164. {
  2165. SET_CONFIG_PROPERTY_EX(PanelFont, UpdateIconFont());
  2166. }
  2167. //---------------------------------------------------------------------------
  2168. void __fastcall TWinConfiguration::SetNaturalOrderNumericalSorting(bool value)
  2169. {
  2170. SET_CONFIG_PROPERTY(NaturalOrderNumericalSorting);
  2171. }
  2172. //---------------------------------------------------------------------------
  2173. void __fastcall TWinConfiguration::SetFullRowSelect(bool value)
  2174. {
  2175. SET_CONFIG_PROPERTY(FullRowSelect);
  2176. }
  2177. //---------------------------------------------------------------------------
  2178. void __fastcall TWinConfiguration::SetOfferedEditorAutoConfig(bool value)
  2179. {
  2180. SET_CONFIG_PROPERTY(OfferedEditorAutoConfig);
  2181. }
  2182. //---------------------------------------------------------------------------
  2183. void __fastcall TWinConfiguration::SetOpenedStoredSessionFolders(UnicodeString value)
  2184. {
  2185. SET_CONFIG_PROPERTY(OpenedStoredSessionFolders);
  2186. }
  2187. //---------------------------------------------------------------------------
  2188. void __fastcall TWinConfiguration::SetAutoImportedFromPuttyOrFilezilla(bool value)
  2189. {
  2190. SET_CONFIG_PROPERTY(AutoImportedFromPuttyOrFilezilla);
  2191. }
  2192. //---------------------------------------------------------------------------
  2193. void __fastcall TWinConfiguration::SetGenerateUrlComponents(int value)
  2194. {
  2195. SET_CONFIG_PROPERTY(GenerateUrlComponents);
  2196. }
  2197. //---------------------------------------------------------------------------
  2198. void __fastcall TWinConfiguration::SetGenerateUrlCodeTarget(TGenerateUrlCodeTarget value)
  2199. {
  2200. SET_CONFIG_PROPERTY(GenerateUrlCodeTarget);
  2201. }
  2202. //---------------------------------------------------------------------------
  2203. void __fastcall TWinConfiguration::SetGenerateUrlScriptFormat(TScriptFormat value)
  2204. {
  2205. SET_CONFIG_PROPERTY(GenerateUrlScriptFormat);
  2206. }
  2207. //---------------------------------------------------------------------------
  2208. void __fastcall TWinConfiguration::SetGenerateUrlAssemblyLanguage(TAssemblyLanguage value)
  2209. {
  2210. SET_CONFIG_PROPERTY(GenerateUrlAssemblyLanguage);
  2211. }
  2212. //---------------------------------------------------------------------------
  2213. void __fastcall TWinConfiguration::SetExternalSessionInExistingInstance(bool value)
  2214. {
  2215. SET_CONFIG_PROPERTY(ExternalSessionInExistingInstance);
  2216. }
  2217. //---------------------------------------------------------------------------
  2218. void __fastcall TWinConfiguration::SetKeepOpenWhenNoSession(bool value)
  2219. {
  2220. SET_CONFIG_PROPERTY(KeepOpenWhenNoSession);
  2221. }
  2222. //---------------------------------------------------------------------------
  2223. void __fastcall TWinConfiguration::SetLocalIconsByExt(bool value)
  2224. {
  2225. SET_CONFIG_PROPERTY(LocalIconsByExt);
  2226. }
  2227. //---------------------------------------------------------------------------
  2228. void __fastcall TWinConfiguration::SetBidiModeOverride(TLocaleFlagOverride value)
  2229. {
  2230. SET_CONFIG_PROPERTY(BidiModeOverride);
  2231. }
  2232. //---------------------------------------------------------------------------
  2233. void __fastcall TWinConfiguration::SetFlipChildrenOverride(TLocaleFlagOverride value)
  2234. {
  2235. SET_CONFIG_PROPERTY(FlipChildrenOverride);
  2236. }
  2237. //---------------------------------------------------------------------------
  2238. void __fastcall TWinConfiguration::SetShowTips(bool value)
  2239. {
  2240. SET_CONFIG_PROPERTY(ShowTips);
  2241. }
  2242. //---------------------------------------------------------------------------
  2243. void __fastcall TWinConfiguration::SetTipsSeen(UnicodeString value)
  2244. {
  2245. SET_CONFIG_PROPERTY(TipsSeen);
  2246. }
  2247. //---------------------------------------------------------------------------
  2248. void __fastcall TWinConfiguration::SetTipsShown(TDateTime value)
  2249. {
  2250. SET_CONFIG_PROPERTY(TipsShown);
  2251. }
  2252. //---------------------------------------------------------------------------
  2253. void __fastcall TWinConfiguration::SetFileColors(UnicodeString value)
  2254. {
  2255. SET_CONFIG_PROPERTY(FileColors);
  2256. }
  2257. //---------------------------------------------------------------------------
  2258. void __fastcall TWinConfiguration::SetRunsSinceLastTip(int value)
  2259. {
  2260. SET_CONFIG_PROPERTY(RunsSinceLastTip);
  2261. }
  2262. //---------------------------------------------------------------------------
  2263. bool __fastcall TWinConfiguration::GetHonorDrivePolicy()
  2264. {
  2265. return DriveInfo->HonorDrivePolicy;
  2266. }
  2267. //---------------------------------------------------------------------------
  2268. void __fastcall TWinConfiguration::SetHonorDrivePolicy(bool value)
  2269. {
  2270. if (HonorDrivePolicy != value)
  2271. {
  2272. DriveInfo->HonorDrivePolicy = value;
  2273. Changed();
  2274. }
  2275. }
  2276. //---------------------------------------------------------------------------
  2277. void __fastcall TWinConfiguration::SetCustomCommandList(TCustomCommandList * value)
  2278. {
  2279. DebugAssert(FCustomCommandList);
  2280. if (!FCustomCommandList->Equals(value))
  2281. {
  2282. FCustomCommandList->Assign(value);
  2283. FCustomCommandsDefaults = false;
  2284. }
  2285. }
  2286. //---------------------------------------------------------------------------
  2287. void __fastcall TWinConfiguration::SetExtensionList(TCustomCommandList * value)
  2288. {
  2289. if (!ExtensionList->Equals(value))
  2290. {
  2291. std::unique_ptr<TStringList> DeletedExtensions(CreateSortedStringList());
  2292. ParseExtensionList(DeletedExtensions.get(), FExtensionsDeleted);
  2293. for (int Index = 0; Index < ExtensionList->Count; Index++)
  2294. {
  2295. const TCustomCommandType * CustomCommand = ExtensionList->Commands[Index];
  2296. int Index = value->FindIndexByFileName(CustomCommand->FileName);
  2297. if (Index < 0)
  2298. {
  2299. if (FileExists(CustomCommand->FileName) &&
  2300. !DeleteFile(CustomCommand->FileName))
  2301. {
  2302. DeletedExtensions->Add(CustomCommand->Id);
  2303. }
  2304. }
  2305. }
  2306. FExtensionsOrder = L"";
  2307. for (int Index = 0; Index < value->Count; Index++)
  2308. {
  2309. const TCustomCommandType * CustomCommand = value->Commands[Index];
  2310. AddToList(FExtensionsOrder, CustomCommand->Id, L"|");
  2311. int DeletedIndex = DeletedExtensions->IndexOf(CustomCommand->Id);
  2312. if (DeletedIndex >= 0)
  2313. {
  2314. DeletedExtensions->Delete(DeletedIndex);
  2315. }
  2316. }
  2317. FExtensionList->Assign(value);
  2318. FExtensionsDeleted = L"";
  2319. for (int Index = 0; Index < DeletedExtensions->Count; Index++)
  2320. {
  2321. AddToList(FExtensionsDeleted, DeletedExtensions->Strings[Index], L"|");
  2322. }
  2323. FExtensionsShortCuts = L"";
  2324. for (int Index = 0; Index < value->Count; Index++)
  2325. {
  2326. const TCustomCommandType * Extension = value->Commands[Index];
  2327. if (Extension->HasCustomShortCut())
  2328. {
  2329. AddToList(FExtensionsShortCuts, FORMAT(L"%d=%s", (Extension->ShortCut, Extension->Id)), L"|");
  2330. }
  2331. }
  2332. Changed();
  2333. }
  2334. }
  2335. //---------------------------------------------------------------------------
  2336. void __fastcall TWinConfiguration::CustomCommandShortCuts(TShortCuts & ShortCuts) const
  2337. {
  2338. CustomCommandList->ShortCuts(ShortCuts);
  2339. ExtensionList->ShortCuts(ShortCuts);
  2340. }
  2341. //---------------------------------------------------------------------------
  2342. void __fastcall TWinConfiguration::SetBookmarks(UnicodeString Key,
  2343. TBookmarkList * value)
  2344. {
  2345. FBookmarks->Bookmarks[Key] = value;
  2346. Changed();
  2347. }
  2348. //---------------------------------------------------------------------------
  2349. TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(UnicodeString Key)
  2350. {
  2351. return FBookmarks->Bookmarks[Key];
  2352. }
  2353. //---------------------------------------------------------------------------
  2354. void __fastcall TWinConfiguration::SetSharedBookmarks(TBookmarkList * value)
  2355. {
  2356. FBookmarks->SharedBookmarks = value;
  2357. Changed();
  2358. }
  2359. //---------------------------------------------------------------------------
  2360. TBookmarkList * __fastcall TWinConfiguration::GetSharedBookmarks()
  2361. {
  2362. return FBookmarks->SharedBookmarks;
  2363. }
  2364. //---------------------------------------------------------------------------
  2365. UnicodeString __fastcall TWinConfiguration::GetDefaultKeyFile()
  2366. {
  2367. return (!FDefaultKeyFile.IsEmpty() ? FDefaultKeyFile : FTemporaryKeyFile);
  2368. }
  2369. //---------------------------------------------------------------------------
  2370. void __fastcall TWinConfiguration::SetLastMonitor(int value)
  2371. {
  2372. ::SetLastMonitor(value);
  2373. }
  2374. //---------------------------------------------------------------------------
  2375. int __fastcall TWinConfiguration::GetLastMonitor()
  2376. {
  2377. return ::GetLastMonitor();
  2378. }
  2379. //---------------------------------------------------------------------------
  2380. UnicodeString __fastcall TWinConfiguration::ExpandedTemporaryDirectory()
  2381. {
  2382. UnicodeString Result =
  2383. ExpandFileName(ExpandEnvironmentVariables(DDTemporaryDirectory));
  2384. if (Result.IsEmpty())
  2385. {
  2386. Result = SystemTemporaryDirectory();
  2387. }
  2388. return Result;
  2389. }
  2390. //---------------------------------------------------------------------------
  2391. UnicodeString __fastcall TWinConfiguration::TemporaryDir(bool Mask)
  2392. {
  2393. return UniqTempDir(ExpandedTemporaryDirectory(), L"scp", Mask);
  2394. }
  2395. //---------------------------------------------------------------------------
  2396. TStrings * __fastcall TWinConfiguration::FindTemporaryFolders()
  2397. {
  2398. TStrings * Result = new TStringList();
  2399. try
  2400. {
  2401. TSearchRecOwned SRec;
  2402. UnicodeString Mask = TemporaryDir(true);
  2403. UnicodeString Directory = ExtractFilePath(Mask);
  2404. if (FindFirstUnchecked(Mask, faDirectory | faHidden, SRec) == 0)
  2405. {
  2406. do
  2407. {
  2408. if (SRec.IsDirectory())
  2409. {
  2410. Result->Add(Directory + SRec.Name);
  2411. }
  2412. }
  2413. while (FindNextChecked(SRec) == 0);
  2414. }
  2415. if (Result->Count == 0)
  2416. {
  2417. delete Result;
  2418. Result = NULL;
  2419. }
  2420. }
  2421. catch(...)
  2422. {
  2423. delete Result;
  2424. throw;
  2425. }
  2426. return Result;
  2427. }
  2428. //---------------------------------------------------------------------------
  2429. void __fastcall TWinConfiguration::CleanupTemporaryFolders(TStrings * Folders)
  2430. {
  2431. UnicodeString ErrorList;
  2432. TStrings * F;
  2433. if (Folders == NULL)
  2434. {
  2435. F = FindTemporaryFolders();
  2436. }
  2437. else
  2438. {
  2439. F = Folders;
  2440. }
  2441. if (F != NULL)
  2442. {
  2443. try
  2444. {
  2445. if (DebugAlwaysTrue(F->Count > 0))
  2446. {
  2447. Usage->Inc(L"TemporaryDirectoryCleanups");
  2448. }
  2449. for (int i = 0; i < F->Count; i++)
  2450. {
  2451. if (!DeleteDirectory(F->Strings[i]))
  2452. {
  2453. if (!ErrorList.IsEmpty())
  2454. {
  2455. ErrorList += L"\n";
  2456. }
  2457. ErrorList += F->Strings[i];
  2458. }
  2459. }
  2460. }
  2461. __finally
  2462. {
  2463. if (Folders == NULL)
  2464. {
  2465. delete F;
  2466. }
  2467. }
  2468. if (!ErrorList.IsEmpty())
  2469. {
  2470. throw ExtException(LoadStr(CLEANUP_TEMP_ERROR), ErrorList);
  2471. }
  2472. }
  2473. }
  2474. //---------------------------------------------------------------------------
  2475. int __fastcall TWinConfiguration::GetResourceModuleCompleteness(HINSTANCE Module)
  2476. {
  2477. UnicodeString CompletenessStr = LoadStrFrom(Module, TRANSLATION_COMPLETENESS);
  2478. return StrToIntDef(CompletenessStr, -1);
  2479. }
  2480. //---------------------------------------------------------------------------
  2481. int __fastcall TWinConfiguration::GetLocaleCompletenessTreshold()
  2482. {
  2483. return 80;
  2484. }
  2485. //---------------------------------------------------------------------------
  2486. bool __fastcall TWinConfiguration::IsTranslationComplete(HINSTANCE Module)
  2487. {
  2488. return (GetResourceModuleCompleteness(Module) >= LocaleCompletenessTreshold);
  2489. }
  2490. //---------------------------------------------------------------------------
  2491. HINSTANCE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
  2492. UnicodeString & FileName)
  2493. {
  2494. HINSTANCE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
  2495. if (Instance != NULL)
  2496. {
  2497. try
  2498. {
  2499. CheckTranslationVersion(FileName, false);
  2500. }
  2501. catch(...)
  2502. {
  2503. FreeResourceModule(Instance);
  2504. throw;
  2505. }
  2506. }
  2507. return Instance;
  2508. }
  2509. //---------------------------------------------------------------------------
  2510. void __fastcall TWinConfiguration::CheckTranslationVersion(const UnicodeString FileName,
  2511. bool InternalLocaleOnError)
  2512. {
  2513. UnicodeString TranslationProductVersion = GetFileProductVersion(FileName);
  2514. UnicodeString TranslationProductName = GetFileProductName(FileName);
  2515. if ((ProductName != TranslationProductName) ||
  2516. (ProductVersion != TranslationProductVersion))
  2517. {
  2518. if (InternalLocaleOnError)
  2519. {
  2520. LocaleSafe = InternalLocale();
  2521. }
  2522. if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
  2523. {
  2524. throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
  2525. }
  2526. else
  2527. {
  2528. throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
  2529. (FileName, TranslationProductName, TranslationProductVersion)));
  2530. }
  2531. }
  2532. }
  2533. //---------------------------------------------------------------------------
  2534. void __fastcall TWinConfiguration::CheckDefaultTranslation()
  2535. {
  2536. if (!FInvalidDefaultTranslationMessage.IsEmpty())
  2537. {
  2538. MoreMessageDialog(FMTLOAD(INVALID_DEFAULT_TRANSLATION,
  2539. (FInvalidDefaultTranslationMessage)), NULL, qtWarning, qaOK, HELP_NONE);
  2540. }
  2541. }
  2542. //---------------------------------------------------------------------------
  2543. const TEditorPreferences * __fastcall TWinConfiguration::DefaultEditorForFile(
  2544. const UnicodeString FileName, bool Local, const TFileMasks::TParams & MaskParams)
  2545. {
  2546. return FEditorList->Find(FileName, Local, MaskParams);
  2547. }
  2548. //---------------------------------------------------------------------------
  2549. const TEditorList * __fastcall TWinConfiguration::GetEditorList()
  2550. {
  2551. return FEditorList;
  2552. }
  2553. //---------------------------------------------------------------------------
  2554. void __fastcall TWinConfiguration::SetEditorList(const TEditorList * value)
  2555. {
  2556. if (!(*FEditorList == *value))
  2557. {
  2558. *FEditorList = *value;
  2559. Changed();
  2560. }
  2561. }
  2562. //---------------------------------------------------------------------------
  2563. TStrings * __fastcall TWinConfiguration::GetCustomCommandOptions()
  2564. {
  2565. return FCustomCommandOptions.get();
  2566. }
  2567. //---------------------------------------------------------------------------
  2568. void __fastcall TWinConfiguration::SetCustomCommandOptions(TStrings * value)
  2569. {
  2570. if (!FCustomCommandOptions->Equals(value))
  2571. {
  2572. FCustomCommandOptions->Assign(value);
  2573. FCustomCommandOptionsModified = true;
  2574. }
  2575. }
  2576. //---------------------------------------------------------------------------
  2577. void __fastcall TWinConfiguration::SetLockedInterface(bool value)
  2578. {
  2579. SET_CONFIG_PROPERTY(LockedInterface);
  2580. }
  2581. //---------------------------------------------------------------------------
  2582. bool __fastcall TWinConfiguration::GetTimeoutShellOperations()
  2583. {
  2584. return ::TimeoutShellOperations;
  2585. }
  2586. //---------------------------------------------------------------------------
  2587. void __fastcall TWinConfiguration::SetTimeoutShellOperations(bool value)
  2588. {
  2589. ::TimeoutShellOperations = value;
  2590. }
  2591. //---------------------------------------------------------------------------
  2592. void __fastcall TWinConfiguration::SetTimeoutShellIconRetrieval(bool value)
  2593. {
  2594. SET_CONFIG_PROPERTY(TimeoutShellIconRetrieval);
  2595. }
  2596. //---------------------------------------------------------------------------
  2597. void __fastcall TWinConfiguration::SetAllowWindowPrint(bool value)
  2598. {
  2599. SET_CONFIG_PROPERTY(AllowWindowPrint);
  2600. }
  2601. //---------------------------------------------------------------------------
  2602. TStringList * __fastcall TWinConfiguration::LoadJumpList(
  2603. THierarchicalStorage * Storage, UnicodeString Name)
  2604. {
  2605. UnicodeString JumpList = Storage->ReadString(Name, L"");
  2606. std::unique_ptr<TStringList> List(new TStringList());
  2607. List->CaseSensitive = false;
  2608. List->CommaText = JumpList;
  2609. return List.release();
  2610. }
  2611. //---------------------------------------------------------------------------
  2612. void __fastcall TWinConfiguration::SaveJumpList(
  2613. THierarchicalStorage * Storage, UnicodeString Name, TStringList * List)
  2614. {
  2615. UnicodeString JumpList = Storage->ReadString(Name, L"");
  2616. UnicodeString NewJumpList = List->CommaText;
  2617. if (NewJumpList != JumpList)
  2618. {
  2619. Storage->WriteString(Name, NewJumpList);
  2620. }
  2621. }
  2622. //---------------------------------------------------------------------------
  2623. void __fastcall TWinConfiguration::TrimJumpList(TStringList * List)
  2624. {
  2625. while (List->Count > 30)
  2626. {
  2627. List->Delete(List->Count - 1);
  2628. }
  2629. }
  2630. //---------------------------------------------------------------------------
  2631. void __fastcall TWinConfiguration::UpdateEntryInJumpList(
  2632. bool Session, const UnicodeString & Name, bool Add)
  2633. {
  2634. THierarchicalStorage * Storage = CreateConfigStorage();
  2635. try
  2636. {
  2637. FDontDecryptPasswords++;
  2638. Storage->AccessMode = smReadWrite;
  2639. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  2640. {
  2641. std::unique_ptr<TStringList> ListSessions(LoadJumpList(Storage, L"JumpList"));
  2642. std::unique_ptr<TStringList> ListWorkspaces(LoadJumpList(Storage, L"JumpListWorkspaces"));
  2643. if (!Name.IsEmpty())
  2644. {
  2645. TStringList * List = (Session ? ListSessions : ListWorkspaces).get();
  2646. int Index = List->IndexOf(Name);
  2647. if (Index >= 0)
  2648. {
  2649. List->Delete(Index);
  2650. }
  2651. if (Add)
  2652. {
  2653. List->Insert(0, Name);
  2654. }
  2655. }
  2656. TrimJumpList(ListSessions.get());
  2657. TrimJumpList(ListWorkspaces.get());
  2658. ::UpdateJumpList(ListSessions.get(), ListWorkspaces.get());
  2659. SaveJumpList(Storage, L"JumpList", ListSessions.get());
  2660. SaveJumpList(Storage, L"JumpListWorkspaces", ListWorkspaces.get());
  2661. }
  2662. }
  2663. __finally
  2664. {
  2665. FDontDecryptPasswords--;
  2666. delete Storage;
  2667. }
  2668. }
  2669. //---------------------------------------------------------------------------
  2670. void __fastcall TWinConfiguration::AddSessionToJumpList(UnicodeString SessionName)
  2671. {
  2672. UpdateEntryInJumpList(true, SessionName, true);
  2673. }
  2674. //---------------------------------------------------------------------------
  2675. void __fastcall TWinConfiguration::DeleteSessionFromJumpList(UnicodeString SessionName)
  2676. {
  2677. UpdateEntryInJumpList(true, SessionName, false);
  2678. }
  2679. //---------------------------------------------------------------------------
  2680. void __fastcall TWinConfiguration::AddWorkspaceToJumpList(UnicodeString Workspace)
  2681. {
  2682. UpdateEntryInJumpList(false, Workspace, true);
  2683. }
  2684. //---------------------------------------------------------------------------
  2685. void __fastcall TWinConfiguration::DeleteWorkspaceFromJumpList(UnicodeString Workspace)
  2686. {
  2687. UpdateEntryInJumpList(false, Workspace, false);
  2688. }
  2689. //---------------------------------------------------------------------------
  2690. void __fastcall TWinConfiguration::UpdateJumpList()
  2691. {
  2692. AddSessionToJumpList(L"");
  2693. }
  2694. //---------------------------------------------------------------------------
  2695. void __fastcall TWinConfiguration::UpdateStaticUsage()
  2696. {
  2697. // This is here because of TStoredSessionList::UpdateStaticUsage() call
  2698. // from TConfiguration::UpdateStaticUsage()
  2699. TAutoNestingCounter DontDecryptPasswordsAutoCounter(FDontDecryptPasswords);
  2700. TCustomWinConfiguration::UpdateStaticUsage();
  2701. Usage->Set(L"Beta", IsBeta);
  2702. Usage->Set(L"Interface", Interface);
  2703. Usage->Set(L"ThemeDark", UseDarkTheme());
  2704. Usage->Set(L"CustomCommandsCount", (FCustomCommandsDefaults ? 0 : FCustomCommandList->Count));
  2705. Usage->Set(L"UsingLocationProfiles", UseLocationProfiles);
  2706. Usage->Set(L"UsingMasterPassword", UseMasterPassword);
  2707. Usage->Set(L"UsingAutoSaveWorkspace", AutoSaveWorkspace);
  2708. Usage->Set(L"TreeVisible",
  2709. (Interface == ifExplorer) ?
  2710. ScpExplorer.DriveView :
  2711. (ScpCommander.LocalPanel.DriveView || ScpCommander.RemotePanel.DriveView));
  2712. Usage->Set(L"MinimizeToTray", MinimizeToTray);
  2713. UnicodeString ToolbarsButtons = (Interface == ifExplorer) ? ScpExplorer.ToolbarsButtons : ScpCommander.ToolbarsButtons;
  2714. Usage->Set(L"AnyHiddenToolbarButtons", !ToolbarsButtons.IsEmpty());
  2715. Usage->Set(L"FileColors", !FileColors.IsEmpty());
  2716. Usage->Set(L"DragDropDrives", !DDDrives.IsEmpty());
  2717. Usage->Set(L"ShowingTips", ShowTips);
  2718. TipsUpdateStaticUsage();
  2719. Usage->Set(L"CommanderNortonLikeMode", int(ScpCommander.NortonLikeMode));
  2720. Usage->Set(L"CommanderExplorerKeyboardShortcuts", ScpCommander.ExplorerKeyboardShortcuts);
  2721. Usage->Set(L"ExplorerViewStyle", ScpExplorer.ViewStyle);
  2722. Usage->Set(L"LastMonitor", LastMonitor);
  2723. UnicodeString ExternalEditors;
  2724. for (int Index = 0; Index < EditorList->Count; Index++)
  2725. {
  2726. const TEditorPreferences * Editor = EditorList->Editors[Index];
  2727. if (Editor->Data->Editor == edExternal)
  2728. {
  2729. AddToList(ExternalEditors, Editor->ExtractExternalEditorName(), ",");
  2730. }
  2731. }
  2732. Usage->Set(L"ExternalEditors", ExternalEditors);
  2733. if (LastMachineInstallations < FMachineInstallations)
  2734. {
  2735. Usage->Inc(L"InstallationsMachine", (FMachineInstallations - LastMachineInstallations));
  2736. LastMachineInstallations = FMachineInstallations;
  2737. }
  2738. int ExtensionsPortable = 0;
  2739. int ExtensionsInstalled = 0;
  2740. int ExtensionsUser = 0;
  2741. for (int Index = 0; Index < FExtensionList->Count; Index++)
  2742. {
  2743. const TCustomCommandType * CustomCommand = FExtensionList->Commands[Index];
  2744. UnicodeString PathId = ExcludeTrailingBackslash(ExtractFilePath(CustomCommand->Id));
  2745. if (SameText(PathId, ExtensionsCommonPathId))
  2746. {
  2747. ExtensionsPortable++;
  2748. }
  2749. else if (SameText(PathId, ExtensionsCommonExtPathId))
  2750. {
  2751. ExtensionsInstalled++;
  2752. }
  2753. else if (SameText(PathId, ExtensionsUserExtPathId))
  2754. {
  2755. ExtensionsUser++;
  2756. }
  2757. }
  2758. Usage->Set(L"ExtensionsPortableCount", (ExtensionsPortable));
  2759. Usage->Set(L"ExtensionsInstalledCount", (ExtensionsInstalled));
  2760. Usage->Set(L"ExtensionsUserCount", (ExtensionsUser));
  2761. std::unique_ptr<TStringList> DeletedExtensions(CreateSortedStringList());
  2762. ParseExtensionList(DeletedExtensions.get(), FExtensionsDeleted);
  2763. Usage->Set(L"ExtensionsDeleted", (DeletedExtensions->Count));
  2764. }
  2765. //---------------------------------------------------------------------------
  2766. void __fastcall TWinConfiguration::RestoreFont(
  2767. const TFontConfiguration & Configuration, TFont * Font)
  2768. {
  2769. Font->Name = Configuration.FontName;
  2770. Font->Size = Configuration.FontSize;
  2771. Font->Charset = Configuration.FontCharset;
  2772. Font->Style = IntToFontStyles(Configuration.FontStyle);
  2773. }
  2774. //---------------------------------------------------------------------------
  2775. void __fastcall TWinConfiguration::StoreFont(
  2776. TFont * Font, TFontConfiguration & Configuration)
  2777. {
  2778. Configuration.FontName = Font->Name;
  2779. Configuration.FontSize = Font->Size;
  2780. Configuration.FontCharset = Font->Charset;
  2781. Configuration.FontStyle = FontStylesToInt(Font->Style);
  2782. }
  2783. //---------------------------------------------------------------------------
  2784. //---------------------------------------------------------------------------
  2785. __fastcall TCustomCommandType::TCustomCommandType() :
  2786. FParams(0), FShortCut(0), FShortCutOriginal(0)
  2787. {
  2788. }
  2789. //---------------------------------------------------------------------------
  2790. __fastcall TCustomCommandType::TCustomCommandType(const TCustomCommandType & Other) :
  2791. FName(Other.FName),
  2792. FCommand(Other.FCommand),
  2793. FParams(Other.FParams),
  2794. FShortCut(Other.FShortCut),
  2795. FShortCutOriginal(Other.FShortCutOriginal),
  2796. FId(Other.FId),
  2797. FFileName(Other.FFileName),
  2798. FDescription(Other.FDescription),
  2799. FHomePage(Other.FHomePage),
  2800. FOptionsPage(Other.FOptionsPage),
  2801. FOptions(Other.FOptions)
  2802. {
  2803. }
  2804. //---------------------------------------------------------------------------
  2805. TCustomCommandType & TCustomCommandType::operator=(const TCustomCommandType & Other)
  2806. {
  2807. FName = Other.FName;
  2808. FCommand = Other.FCommand;
  2809. FParams = Other.FParams;
  2810. FShortCut = Other.FShortCut;
  2811. FShortCutOriginal = Other.FShortCutOriginal;
  2812. FId = Other.FId;
  2813. FFileName = Other.FFileName;
  2814. FDescription = Other.FDescription;
  2815. FHomePage = Other.FHomePage;
  2816. FOptionsPage = Other.FOptionsPage;
  2817. FOptions = Other.FOptions;
  2818. return *this;
  2819. }
  2820. //---------------------------------------------------------------------------
  2821. bool __fastcall TCustomCommandType::Equals(const TCustomCommandType * Other) const
  2822. {
  2823. return
  2824. (FName == Other->FName) &&
  2825. (FCommand == Other->FCommand) &&
  2826. (FParams == Other->FParams) &&
  2827. (FShortCut == Other->FShortCut) &&
  2828. (FShortCutOriginal == Other->FShortCutOriginal) &&
  2829. (FId == Other->FId) &&
  2830. (FFileName == Other->FFileName) &&
  2831. (FDescription == Other->FDescription) &&
  2832. (FHomePage == Other->FHomePage) &&
  2833. (FOptionsPage == Other->FOptionsPage) &&
  2834. (FOptions == Other->FOptions);
  2835. }
  2836. //---------------------------------------------------------------------------
  2837. const UnicodeString ExtensionNameDirective(L"name");
  2838. const UnicodeString ExtensionCommandDirective(L"command");
  2839. const wchar_t ExtensionMark = L'@';
  2840. const UnicodeString WinSCPExtensionExt(L".WinSCPextension");
  2841. //---------------------------------------------------------------------------
  2842. UnicodeString __fastcall TCustomCommandType::GetExtensionId(const UnicodeString & Name)
  2843. {
  2844. UnicodeString Result;
  2845. int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(Name));
  2846. // Ends with Ext or there's another extension after it
  2847. if ((P > 1) &&
  2848. ((Name.Length() == (P + WinSCPExtensionExt.Length() - 1)) || (Name[P + WinSCPExtensionExt.Length()] == L'.')))
  2849. {
  2850. Result = Name.SubString(1, P - 1);
  2851. }
  2852. return Result;
  2853. }
  2854. //---------------------------------------------------------------------------
  2855. void __fastcall TCustomCommandType::LoadExtension(const UnicodeString & Path)
  2856. {
  2857. std::unique_ptr<TStringList> Lines(new TStringList());
  2858. FileName = Path;
  2859. LoadScriptFromFile(Path, Lines.get());
  2860. LoadExtension(Lines.get(), Path);
  2861. Command = ReplaceStr(Command, L"%EXTENSION_PATH%", Path);
  2862. }
  2863. //---------------------------------------------------------------------------
  2864. void __fastcall TCustomCommandType::LoadExtension(TStrings * Lines, const UnicodeString & PathForBaseName)
  2865. {
  2866. Params = ccLocal;
  2867. bool AnythingFound = false;
  2868. std::set<UnicodeString> OptionIds;
  2869. UnicodeString ExtensionBaseName = ExtractExtensionBaseName(PathForBaseName);
  2870. UnicodeString ExtensionLine;
  2871. bool Break = false;
  2872. for (int Index = 0; !Break && (Index < Lines->Count); Index++)
  2873. {
  2874. UnicodeString Line = Lines->Strings[Index].Trim();
  2875. if (!Line.IsEmpty())
  2876. {
  2877. Line = ReplaceChar(Line, L'\t', L' ');
  2878. bool IsComment = false;
  2879. if (StartsText(ExtensionMark, Line))
  2880. {
  2881. IsComment = true;
  2882. }
  2883. else if (StartsText(L"rem ", Line))
  2884. {
  2885. IsComment = true;
  2886. Line.Delete(1, 4);
  2887. }
  2888. else if (StartsText(L"#", Line) || StartsText(L";", Line) || StartsText(L"'", Line))
  2889. {
  2890. IsComment = true;
  2891. Line.Delete(1, 1);
  2892. }
  2893. else if (StartsText(L"//", Line))
  2894. {
  2895. IsComment = true;
  2896. Line.Delete(1, 2);
  2897. }
  2898. if (!IsComment)
  2899. {
  2900. Break = true;
  2901. // ignore this and later lines, but finish processing the previous line with ^, if any
  2902. Line = L"";
  2903. }
  2904. else
  2905. {
  2906. Line = Line.Trim();
  2907. }
  2908. }
  2909. bool Continuation = (Line.Length() > 0) && (Line[Line.Length()] == L'^');
  2910. if (Continuation)
  2911. {
  2912. Line = Line.SubString(1, Line.Length() - 1).Trim();
  2913. }
  2914. AddToList(ExtensionLine, Line, L" ");
  2915. if (!Continuation)
  2916. {
  2917. int P;
  2918. if (!ExtensionLine.IsEmpty() && (ExtensionLine[1] == ExtensionMark) && ((P = Pos(L" ", ExtensionLine)) >= 2))
  2919. {
  2920. UnicodeString Key = ExtensionLine.SubString(2, P - 2).LowerCase();
  2921. UnicodeString Directive = UnicodeString(ExtensionMark) + Key;
  2922. UnicodeString Value = ExtensionLine.SubString(P + 1, ExtensionLine.Length() - P).Trim();
  2923. bool KnownKey = true;
  2924. if (Key == ExtensionNameDirective)
  2925. {
  2926. Name = WinConfiguration->ExtensionStringTranslation(Id, Value);
  2927. }
  2928. else if (Key == ExtensionCommandDirective)
  2929. {
  2930. Command = Value;
  2931. }
  2932. else if (Key == L"require")
  2933. {
  2934. UnicodeString DependencyVersion = Value;
  2935. UnicodeString Dependency = CutToChar(Value, L' ', true).LowerCase();
  2936. Value = Value.Trim();
  2937. bool Failed;
  2938. if (Dependency == L"winscp")
  2939. {
  2940. int Version = StrToCompoundVersion(Value);
  2941. Failed = (Version > WinConfiguration->CompoundVersion);
  2942. }
  2943. else if (Dependency == L".net")
  2944. {
  2945. Failed = (CompareVersion(Value, GetNetVersionStr()) > 0);
  2946. }
  2947. else if (Dependency == L"powershell")
  2948. {
  2949. Failed = (CompareVersion(Value, GetPowerShellVersionStr()) > 0);
  2950. }
  2951. else if (Dependency == L"windows")
  2952. {
  2953. Failed = (CompareVersion(Value, WindowsVersion()) > 0);
  2954. }
  2955. else
  2956. {
  2957. Failed = true;
  2958. }
  2959. if (Failed)
  2960. {
  2961. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DEPENDENCY_ERROR, (DependencyVersion))));
  2962. }
  2963. }
  2964. else if (Key == L"side")
  2965. {
  2966. if (SameText(Value, L"Local"))
  2967. {
  2968. Params |= ccLocal;
  2969. }
  2970. else if (SameText(Value, L"Remote"))
  2971. {
  2972. Params &= ~ccLocal;
  2973. }
  2974. else
  2975. {
  2976. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_ERROR, (Value, Directive))));
  2977. }
  2978. }
  2979. else if (Key == L"flag")
  2980. {
  2981. if (SameText(Value, L"ApplyToDirectories"))
  2982. {
  2983. Params |= ccApplyToDirectories;
  2984. }
  2985. else if (SameText(Value, L"Recursive"))
  2986. {
  2987. Params |= ccRecursive;
  2988. }
  2989. else if (SameText(Value, L"ShowResults"))
  2990. {
  2991. Params |= ccShowResults;
  2992. }
  2993. else if (SameText(Value, L"CopyResults"))
  2994. {
  2995. Params |= ccCopyResults;
  2996. }
  2997. else if (SameText(Value, L"RemoteFiles"))
  2998. {
  2999. Params |= ccRemoteFiles;
  3000. }
  3001. else if (SameText(Value, L"ShowResultsInMsgBox"))
  3002. {
  3003. Params |= ccShowResultsInMsgBox;
  3004. }
  3005. else
  3006. {
  3007. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_ERROR, (Value, Directive))));
  3008. }
  3009. }
  3010. else if (Key == L"shortcut")
  3011. {
  3012. TShortCut AShortCut = TextToShortCut(Value);
  3013. if (IsCustomShortCut(AShortCut))
  3014. {
  3015. ShortCut = AShortCut;
  3016. FShortCutOriginal = AShortCut;
  3017. }
  3018. else
  3019. {
  3020. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_ERROR, (Value, Directive))));
  3021. }
  3022. }
  3023. else if (Key == L"option")
  3024. {
  3025. TOption Option;
  3026. if (!ParseOption(Value, Option, ExtensionBaseName) ||
  3027. (Option.IsControl && (OptionIds.find(Option.Id.LowerCase()) != OptionIds.end())))
  3028. {
  3029. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_ERROR, (Value, Directive))));
  3030. }
  3031. else
  3032. {
  3033. FOptions.push_back(Option);
  3034. if (!Option.IsControl)
  3035. {
  3036. OptionIds.insert(Option.Id.LowerCase());
  3037. }
  3038. }
  3039. }
  3040. else if (Key == L"description")
  3041. {
  3042. Description = WinConfiguration->ExtensionStringTranslation(Id, Value);
  3043. }
  3044. else if (Key == L"author")
  3045. {
  3046. // noop
  3047. }
  3048. else if (Key == L"version")
  3049. {
  3050. // noop
  3051. }
  3052. else if (Key == L"homepage")
  3053. {
  3054. HomePage = Value;
  3055. }
  3056. else if (Key == L"optionspage")
  3057. {
  3058. OptionsPage = Value;
  3059. }
  3060. else if (Key == L"source")
  3061. {
  3062. // noop
  3063. }
  3064. else
  3065. {
  3066. KnownKey = false;
  3067. }
  3068. if (KnownKey)
  3069. {
  3070. AnythingFound = true;
  3071. }
  3072. }
  3073. ExtensionLine = L"";
  3074. }
  3075. }
  3076. if (!AnythingFound)
  3077. {
  3078. throw Exception(MainInstructions(LoadStr(EXTENSION_NOT_FOUND)));
  3079. }
  3080. if (Name.IsEmpty())
  3081. {
  3082. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_MISSING, (UnicodeString(ExtensionMark) + ExtensionNameDirective))));
  3083. }
  3084. if (Command.IsEmpty())
  3085. {
  3086. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DIRECTIVE_MISSING, (UnicodeString(ExtensionMark) + ExtensionCommandDirective))));
  3087. }
  3088. }
  3089. //---------------------------------------------------------------------------
  3090. bool __fastcall TCustomCommandType::ParseOption(const UnicodeString & Value, TOption & Option, const UnicodeString & ExtensionBaseName)
  3091. {
  3092. UnicodeString Buf = Value;
  3093. UnicodeString KindName;
  3094. bool Result = CutTokenEx(Buf, Option.Id);
  3095. if (Result)
  3096. {
  3097. Option.Flags = 0;
  3098. UnicodeString FlagName;
  3099. while (CutTokenEx(Buf, FlagName) && (FlagName.SubString(1, 1) == L"-"))
  3100. {
  3101. FlagName = FlagName.LowerCase();
  3102. if (FlagName == L"-run")
  3103. {
  3104. Option.Flags |= ofRun;
  3105. }
  3106. else if (FlagName == L"-config")
  3107. {
  3108. Option.Flags |= ofConfig;
  3109. }
  3110. else if (FlagName == L"-site")
  3111. {
  3112. Option.Flags |= ofSite;
  3113. }
  3114. else
  3115. {
  3116. Result = false;
  3117. }
  3118. }
  3119. if ((Option.Flags & (ofRun | ofConfig)) == 0)
  3120. {
  3121. Option.Flags |= ofConfig;
  3122. }
  3123. KindName = FlagName;
  3124. if (Result)
  3125. {
  3126. UnicodeString DefaultCaption;
  3127. UnicodeString DefaultDefault;
  3128. TOption::TParams DefaultParams;
  3129. KindName = KindName.LowerCase();
  3130. if (KindName == L"label")
  3131. {
  3132. Option.Kind = okLabel;
  3133. Result = !Option.IsControl;
  3134. }
  3135. else if (KindName == L"link")
  3136. {
  3137. Option.Kind = okLink;
  3138. Result = !Option.IsControl;
  3139. }
  3140. else if (KindName == L"separator")
  3141. {
  3142. Option.Kind = okSeparator;
  3143. Result = !Option.IsControl;
  3144. }
  3145. else if (KindName == L"group")
  3146. {
  3147. Option.Kind = okGroup;
  3148. Result = !Option.IsControl;
  3149. }
  3150. else if (KindName == L"textbox")
  3151. {
  3152. Option.Kind = okTextBox;
  3153. Result = Option.IsControl;
  3154. }
  3155. else if (KindName == L"file")
  3156. {
  3157. Option.Kind = okFile;
  3158. Result = Option.IsControl;
  3159. }
  3160. else if (KindName == L"sessionlogfile")
  3161. {
  3162. Option.Kind = okFile;
  3163. Result = Option.IsControl;
  3164. DefaultCaption = LoadStr(EXTENSION_SESSIONLOG_FILE);
  3165. Option.FileCaption = LoadStr(EXTENSION_SESSIONLOG_CAPTION);
  3166. Option.FileFilter = LoadStr(EXTENSION_SESSIONLOG_FILTER);
  3167. // Similar to TConfiguration::GetDefaultLogFileName
  3168. Option.FileInitial = L"%TEMP%\\" + ExtensionBaseName + L".log";
  3169. Option.FileExt = L"log";
  3170. }
  3171. else if (KindName == L"dropdownlist")
  3172. {
  3173. Option.Kind = okDropDownList;
  3174. Result = Option.IsControl;
  3175. }
  3176. else if (KindName == L"combobox")
  3177. {
  3178. Option.Kind = okComboBox;
  3179. Result = Option.IsControl;
  3180. }
  3181. else if (KindName == L"checkbox")
  3182. {
  3183. Option.Kind = okCheckBox;
  3184. Result = Option.IsControl;
  3185. }
  3186. else if (KindName == L"pausecheckbox")
  3187. {
  3188. Option.Kind = okCheckBox;
  3189. Result = Option.IsControl;
  3190. DefaultCaption = LoadStr(EXTENSION_PAUSE_CHECKBOX);
  3191. DefaultDefault = L"-pause";
  3192. DefaultParams.push_back(L"-pause");
  3193. }
  3194. else
  3195. {
  3196. Option.Kind = okUnknown;
  3197. }
  3198. if ((Option.Kind != okUnknown) &&
  3199. (Option.Kind != okSeparator))
  3200. {
  3201. Result =
  3202. CutTokenEx(Buf, Option.Caption);
  3203. if (!Result && !DefaultCaption.IsEmpty())
  3204. {
  3205. Option.Caption = DefaultCaption;
  3206. Result = true;
  3207. }
  3208. if (Result)
  3209. {
  3210. Option.Caption = WinConfiguration->ExtensionStringTranslation(Id, Option.Caption);
  3211. if (CutTokenEx(Buf, Option.Default))
  3212. {
  3213. UnicodeString Param;
  3214. while (CutTokenEx(Buf, Param))
  3215. {
  3216. Option.Params.push_back(Param);
  3217. }
  3218. }
  3219. else
  3220. {
  3221. Option.Default = DefaultDefault;
  3222. }
  3223. if (Option.Params.size() == 0)
  3224. {
  3225. Option.Params = DefaultParams;
  3226. }
  3227. }
  3228. }
  3229. }
  3230. }
  3231. return Result;
  3232. }
  3233. //---------------------------------------------------------------------------
  3234. int __fastcall TCustomCommandType::GetOptionsCount() const
  3235. {
  3236. return FOptions.size();
  3237. }
  3238. //---------------------------------------------------------------------------
  3239. const TCustomCommandType::TOption & __fastcall TCustomCommandType::GetOption(int Index) const
  3240. {
  3241. return FOptions[Index];
  3242. }
  3243. //---------------------------------------------------------------------------
  3244. UnicodeString __fastcall TCustomCommandType::GetOptionKey(
  3245. const TCustomCommandType::TOption & Option, const UnicodeString & Site) const
  3246. {
  3247. UnicodeString Result = Id + L"\\" + Option.Id;
  3248. if (FLAGSET(Option.Flags, ofSite))
  3249. {
  3250. Result += L"\\" + Site;
  3251. }
  3252. return Result;
  3253. }
  3254. //---------------------------------------------------------------------------
  3255. bool __fastcall TCustomCommandType::AnyOptionWithFlag(unsigned int Flag) const
  3256. {
  3257. bool Result = false;
  3258. for (int Index = 0; !Result && (Index < OptionsCount); Index++)
  3259. {
  3260. const TCustomCommandType::TOption & Option = GetOption(Index);
  3261. Result = FLAGSET(Option.Flags, Flag);
  3262. }
  3263. return Result;
  3264. }
  3265. //---------------------------------------------------------------------------
  3266. UnicodeString __fastcall TCustomCommandType::GetCommandWithExpandedOptions(
  3267. TStrings * CustomCommandOptions, const UnicodeString & Site) const
  3268. {
  3269. UnicodeString Result = Command;
  3270. for (int Index = 0; Index < OptionsCount; Index++)
  3271. {
  3272. const TCustomCommandType::TOption & Option = GetOption(Index);
  3273. if (Option.IsControl)
  3274. {
  3275. UnicodeString OptionKey = GetOptionKey(Option, Site);
  3276. UnicodeString OptionValue;
  3277. if (CustomCommandOptions->IndexOfName(OptionKey) >= 0)
  3278. {
  3279. OptionValue = CustomCommandOptions->Values[OptionKey];
  3280. }
  3281. else
  3282. {
  3283. OptionValue = Option.Default;
  3284. }
  3285. UnicodeString OptionCommand = GetOptionCommand(Option, OptionValue);
  3286. OptionCommand = TCustomCommand::Escape(OptionCommand);
  3287. Result = ReplaceText(Result, FORMAT(L"%%%s%%", (Option.Id)), OptionCommand);
  3288. }
  3289. }
  3290. return Result;
  3291. }
  3292. //---------------------------------------------------------------------------
  3293. UnicodeString __fastcall TCustomCommandType::GetOptionCommand(const TOption & Option, const UnicodeString & Value) const
  3294. {
  3295. UnicodeString Result = Value;
  3296. switch (Option.Kind)
  3297. {
  3298. case okUnknown:
  3299. case okTextBox:
  3300. case okDropDownList:
  3301. case okComboBox:
  3302. case okCheckBox:
  3303. // noop
  3304. break;
  3305. case okFile:
  3306. Result = ExpandEnvironmentVariables(Result);
  3307. break;
  3308. case okLabel:
  3309. case okLink:
  3310. case okSeparator:
  3311. case okGroup:
  3312. default:
  3313. DebugFail();
  3314. }
  3315. return Result;
  3316. }
  3317. //---------------------------------------------------------------------------
  3318. bool __fastcall TCustomCommandType::HasCustomShortCut() const
  3319. {
  3320. return (ShortCut != FShortCutOriginal);
  3321. }
  3322. //---------------------------------------------------------------------------
  3323. //---------------------------------------------------------------------------
  3324. bool __fastcall TCustomCommandType::TOption::GetIsControl() const
  3325. {
  3326. return (Id != L"-");
  3327. }
  3328. //---------------------------------------------------------------------------
  3329. bool TCustomCommandType::TOption::HasPatterns(TCustomCommand * CustomCommandForOptions) const
  3330. {
  3331. bool CanHavePatterns;
  3332. switch (Kind)
  3333. {
  3334. case okTextBox:
  3335. case okFile:
  3336. CanHavePatterns = true;
  3337. break;
  3338. default:
  3339. CanHavePatterns = false;
  3340. break;
  3341. }
  3342. bool Result =
  3343. CanHavePatterns &&
  3344. FLAGSET(Flags, TCustomCommandType::ofRun) &&
  3345. FLAGCLEAR(Flags, TCustomCommandType::ofConfig) &&
  3346. CustomCommandForOptions->HasAnyPatterns(Default);
  3347. return Result;
  3348. }
  3349. //---------------------------------------------------------------------------
  3350. bool TCustomCommandType::TOption::operator==(const TCustomCommandType::TOption & Other) const
  3351. {
  3352. // needed by vector<> but probably never used
  3353. return
  3354. (Id == Other.Id) &&
  3355. (Flags == Other.Flags) &&
  3356. (Kind == Other.Kind) &&
  3357. (Caption == Other.Caption) &&
  3358. (Default == Other.Default) &&
  3359. (Params == Other.Params) &&
  3360. (FileCaption == Other.FileCaption) &&
  3361. (FileFilter == Other.FileFilter) &&
  3362. (FileInitial == Other.FileInitial) &&
  3363. (FileExt == Other.FileExt);
  3364. }
  3365. //---------------------------------------------------------------------------
  3366. //---------------------------------------------------------------------------
  3367. __fastcall TCustomCommandList::TCustomCommandList()
  3368. {
  3369. FCommands = new TList();
  3370. FModified = false;
  3371. }
  3372. //---------------------------------------------------------------------------
  3373. __fastcall TCustomCommandList::~TCustomCommandList()
  3374. {
  3375. Clear();
  3376. delete FCommands;
  3377. }
  3378. //---------------------------------------------------------------------------
  3379. void __fastcall TCustomCommandList::Reset()
  3380. {
  3381. FModified = false;
  3382. }
  3383. //---------------------------------------------------------------------------
  3384. void __fastcall TCustomCommandList::Modify()
  3385. {
  3386. FModified = true;
  3387. }
  3388. //---------------------------------------------------------------------------
  3389. void __fastcall TCustomCommandList::Load(THierarchicalStorage * Storage)
  3390. {
  3391. Clear();
  3392. if (Storage->OpenSubKey(L"CustomCommands", false))
  3393. {
  3394. TStrings * Names = new TStringList();
  3395. try
  3396. {
  3397. Storage->ReadValues(Names, true);
  3398. for (int Index = 0; Index < Names->Count; Index++)
  3399. {
  3400. TCustomCommandType * Command = new TCustomCommandType();
  3401. Command->Name = Names->Names[Index];
  3402. Command->Command = Names->Values[Names->Names[Index]];
  3403. FCommands->Add(Command);
  3404. }
  3405. Storage->CloseSubKey();
  3406. }
  3407. __finally
  3408. {
  3409. delete Names;
  3410. }
  3411. }
  3412. if (Storage->OpenSubKey(L"CustomCommandsParams", false))
  3413. {
  3414. for (int Index = 0; Index < FCommands->Count; Index++)
  3415. {
  3416. TCustomCommandType * Command = GetCommand(Index);
  3417. Command->Params = Storage->ReadInteger(Command->Name, Command->Params);
  3418. }
  3419. Storage->CloseSubKey();
  3420. }
  3421. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", false))
  3422. {
  3423. for (int Index = 0; Index < FCommands->Count; Index++)
  3424. {
  3425. TCustomCommandType * Command = GetCommand(Index);
  3426. Command->ShortCut = (Word)Storage->ReadInteger(Command->Name, Command->ShortCut);
  3427. }
  3428. Storage->CloseSubKey();
  3429. }
  3430. Reset();
  3431. }
  3432. //---------------------------------------------------------------------------
  3433. void __fastcall TCustomCommandList::Save(THierarchicalStorage * Storage)
  3434. {
  3435. if (Storage->OpenSubKey(L"CustomCommands", true))
  3436. {
  3437. Storage->ClearValues();
  3438. for (int Index = 0; Index < FCommands->Count; Index++)
  3439. {
  3440. const TCustomCommandType * Command = Commands[Index];
  3441. Storage->WriteString(Command->Name, Command->Command);
  3442. }
  3443. Storage->CloseSubKey();
  3444. }
  3445. if (Storage->OpenSubKey(L"CustomCommandsParams", true))
  3446. {
  3447. Storage->ClearValues();
  3448. for (int Index = 0; Index < FCommands->Count; Index++)
  3449. {
  3450. const TCustomCommandType * Command = Commands[Index];
  3451. Storage->WriteInteger(Command->Name, Command->Params);
  3452. }
  3453. Storage->CloseSubKey();
  3454. }
  3455. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", true))
  3456. {
  3457. Storage->ClearValues();
  3458. for (int Index = 0; Index < FCommands->Count; Index++)
  3459. {
  3460. const TCustomCommandType * Command = Commands[Index];
  3461. if (Command->ShortCut != 0)
  3462. {
  3463. Storage->WriteInteger(Command->Name, Command->ShortCut);
  3464. }
  3465. }
  3466. Storage->CloseSubKey();
  3467. }
  3468. }
  3469. //---------------------------------------------------------------------------
  3470. void __fastcall TCustomCommandList::Clear()
  3471. {
  3472. for (int Index = 0; Index < FCommands->Count; Index++)
  3473. {
  3474. delete Commands[Index];
  3475. }
  3476. FCommands->Clear();
  3477. }
  3478. //---------------------------------------------------------------------------
  3479. void __fastcall TCustomCommandList::Add(const UnicodeString Name,
  3480. const UnicodeString ACommand, int Params)
  3481. {
  3482. TCustomCommandType * Command = new TCustomCommandType();
  3483. Command->Name = Name;
  3484. Command->Command = ACommand;
  3485. Command->Params = Params;
  3486. Add(Command);
  3487. }
  3488. //---------------------------------------------------------------------------
  3489. void __fastcall TCustomCommandList::Add(TCustomCommandType * Command)
  3490. {
  3491. Insert(Count, Command);
  3492. }
  3493. //---------------------------------------------------------------------------
  3494. void __fastcall TCustomCommandList::Insert(int Index, TCustomCommandType * Command)
  3495. {
  3496. FCommands->Insert(Index, Command);
  3497. Modify();
  3498. }
  3499. //---------------------------------------------------------------------------
  3500. void __fastcall TCustomCommandList::Change(int Index, TCustomCommandType * ACommand)
  3501. {
  3502. TCustomCommandType * Command = GetCommand(Index);
  3503. if (!Command->Equals(ACommand))
  3504. {
  3505. delete Command;
  3506. FCommands->Items[Index] = ACommand;
  3507. Modify();
  3508. }
  3509. else
  3510. {
  3511. delete ACommand;
  3512. }
  3513. }
  3514. //---------------------------------------------------------------------------
  3515. void __fastcall TCustomCommandList::Move(int CurIndex, int NewIndex)
  3516. {
  3517. if (CurIndex != NewIndex)
  3518. {
  3519. FCommands->Move(CurIndex, NewIndex);
  3520. Modify();
  3521. }
  3522. }
  3523. //---------------------------------------------------------------------------
  3524. void __fastcall TCustomCommandList::Delete(int Index)
  3525. {
  3526. DebugAssert((Index >= 0) && (Index < Count));
  3527. delete GetCommand(Index);
  3528. FCommands->Delete(Index);
  3529. Modify();
  3530. }
  3531. //---------------------------------------------------------------------------
  3532. class TCustomCommandCompareFunc : public TCppInterfacedObject<TListSortCompareFunc>
  3533. {
  3534. public:
  3535. TCustomCommandCompareFunc(TStrings * Ids)
  3536. {
  3537. FIds = Ids;
  3538. }
  3539. virtual int __fastcall Invoke(void * Item1, void * Item2)
  3540. {
  3541. TCustomCommandType * CustomCommand1 = static_cast<TCustomCommandType *>(Item1);
  3542. TCustomCommandType * CustomCommand2 = static_cast<TCustomCommandType *>(Item2);
  3543. int Index1 = FIds->IndexOf(CustomCommand1->Id);
  3544. int Index2 = FIds->IndexOf(CustomCommand2->Id);
  3545. int Result;
  3546. // new items to the end
  3547. if ((Index1 < 0) && (Index2 >= 0))
  3548. {
  3549. Result = 1;
  3550. }
  3551. else if ((Index2 < 0) && (Index1 >= 0))
  3552. {
  3553. Result = -1;
  3554. }
  3555. // fallback to comparing by name
  3556. else if ((Index1 < 0) && (Index2 < 0))
  3557. {
  3558. Result = TComparer__1<UnicodeString>::Default()->Compare(CustomCommand1->Name, CustomCommand2->Name);
  3559. }
  3560. else
  3561. {
  3562. Result = TComparer__1<int>::Default()->Compare(Index1, Index2);
  3563. }
  3564. return Result;
  3565. }
  3566. private:
  3567. TStrings * FIds;
  3568. };
  3569. //---------------------------------------------------------------------------
  3570. void __fastcall TCustomCommandList::SortBy(TStrings * Ids)
  3571. {
  3572. TCustomCommandCompareFunc * Func = new TCustomCommandCompareFunc(Ids);
  3573. FCommands->SortList(Func);
  3574. }
  3575. //---------------------------------------------------------------------------
  3576. int __fastcall TCustomCommandList::GetCount() const
  3577. {
  3578. return FCommands->Count;
  3579. }
  3580. //---------------------------------------------------------------------------
  3581. const TCustomCommandType * __fastcall TCustomCommandList::GetConstCommand(int Index) const
  3582. {
  3583. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  3584. }
  3585. //---------------------------------------------------------------------------
  3586. TCustomCommandType * __fastcall TCustomCommandList::GetCommand(int Index)
  3587. {
  3588. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  3589. }
  3590. //---------------------------------------------------------------------------
  3591. bool __fastcall TCustomCommandList::Equals(const TCustomCommandList * Other) const
  3592. {
  3593. bool Result = (Count == Other->Count);
  3594. for (int Index = 0; Result && (Index < Count); Index++)
  3595. {
  3596. Result = Commands[Index]->Equals(Other->Commands[Index]);
  3597. }
  3598. return Result;
  3599. }
  3600. //---------------------------------------------------------------------------
  3601. void __fastcall TCustomCommandList::Assign(const TCustomCommandList * Other)
  3602. {
  3603. Clear();
  3604. for (int Index = 0; Index < Other->Count; Index++)
  3605. {
  3606. Add(new TCustomCommandType(*Other->Commands[Index]));
  3607. }
  3608. // there should be comparison of with the assigned list, be we rely on caller
  3609. // to do it instead (TGUIConfiguration::SetCopyParamList)
  3610. Modify();
  3611. }
  3612. //---------------------------------------------------------------------------
  3613. const TCustomCommandType * TCustomCommandList::Find(const UnicodeString Name) const
  3614. {
  3615. for (int Index = 0; Index < FCommands->Count; Index++)
  3616. {
  3617. if (Commands[Index]->Name == Name)
  3618. {
  3619. return Commands[Index];
  3620. }
  3621. }
  3622. return NULL;
  3623. }
  3624. //---------------------------------------------------------------------------
  3625. const TCustomCommandType * TCustomCommandList::Find(TShortCut ShortCut) const
  3626. {
  3627. for (int Index = 0; Index < FCommands->Count; Index++)
  3628. {
  3629. if (Commands[Index]->ShortCut == ShortCut)
  3630. {
  3631. return Commands[Index];
  3632. }
  3633. }
  3634. return NULL;
  3635. }
  3636. //---------------------------------------------------------------------------
  3637. int TCustomCommandList::FindIndexByFileName(const UnicodeString & FileName) const
  3638. {
  3639. for (int Index = 0; Index < FCommands->Count; Index++)
  3640. {
  3641. if (IsPathToSameFile(Commands[Index]->FileName, FileName))
  3642. {
  3643. return Index;
  3644. }
  3645. }
  3646. return -1;
  3647. }
  3648. //---------------------------------------------------------------------------
  3649. void __fastcall TCustomCommandList::ShortCuts(TShortCuts & ShortCuts) const
  3650. {
  3651. for (int Index = 0; Index < FCommands->Count; Index++)
  3652. {
  3653. const TCustomCommandType * Command = Commands[Index];
  3654. if (Command->ShortCut != 0)
  3655. {
  3656. ShortCuts.Add(Command->ShortCut);
  3657. }
  3658. }
  3659. }