WinConfiguration.cpp 123 KB

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