WinConfiguration.cpp 124 KB

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