WinConfiguration.cpp 129 KB

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