WinConfiguration.cpp 129 KB

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