WinConfiguration.cpp 129 KB

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