WinConfiguration.cpp 127 KB

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