WinConfiguration.cpp 128 KB

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