1
0

WinConfiguration.cpp 130 KB

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