WinConfiguration.cpp 123 KB

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