WinConfiguration.cpp 129 KB

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