WinConfiguration.cpp 128 KB

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