WinConfiguration.cpp 123 KB

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