WinConfiguration.cpp 129 KB

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