WinConfiguration.cpp 129 KB

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