WinConfiguration.cpp 128 KB

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