1
0

WinConfiguration.cpp 126 KB

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