WinConfiguration.cpp 111 KB

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