WinConfiguration.cpp 129 KB

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