WinConfiguration.cpp 123 KB

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