WinConfiguration.cpp 122 KB

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