WinConfiguration.cpp 123 KB

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