WinConfiguration.cpp 128 KB

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