WinConfiguration.cpp 125 KB

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