WinConfiguration.cpp 127 KB

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