WinConfiguration.cpp 123 KB

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