WinConfiguration.cpp 130 KB

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