WinConfiguration.cpp 126 KB

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