1
0

WinConfiguration.cpp 127 KB

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