WinConfiguration.cpp 127 KB

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