WinConfiguration.cpp 124 KB

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