WinConfiguration.cpp 128 KB

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