WinConfiguration.cpp 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690
  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. //---------------------------------------------------------------------------
  22. #pragma package(smart_init)
  23. //---------------------------------------------------------------------------
  24. TWinConfiguration * WinConfiguration = NULL;
  25. //---------------------------------------------------------------------------
  26. static UnicodeString NotepadName(L"notepad.exe");
  27. //---------------------------------------------------------------------------
  28. __fastcall TEditorData::TEditorData() :
  29. FileMask(L"*.*"),
  30. Editor(edInternal),
  31. ExternalEditor(L""),
  32. ExternalEditorText(false),
  33. SDIExternalEditor(false),
  34. DetectMDIExternalEditor(false)
  35. {
  36. }
  37. //---------------------------------------------------------------------------
  38. __fastcall TEditorData::TEditorData(const TEditorData & Source) :
  39. FileMask(Source.FileMask),
  40. Editor(Source.Editor),
  41. ExternalEditor(Source.ExternalEditor),
  42. ExternalEditorText(Source.ExternalEditorText),
  43. SDIExternalEditor(Source.SDIExternalEditor),
  44. DetectMDIExternalEditor(Source.DetectMDIExternalEditor)
  45. {
  46. }
  47. //---------------------------------------------------------------------------
  48. #define C(Property) (Property == rhd.Property)
  49. bool __fastcall TEditorData::operator==(const TEditorData & rhd) const
  50. {
  51. return
  52. C(FileMask) &&
  53. C(Editor) &&
  54. C(ExternalEditor) &&
  55. C(ExternalEditorText) &&
  56. C(SDIExternalEditor) &&
  57. C(DetectMDIExternalEditor) &&
  58. true;
  59. }
  60. #undef C
  61. //---------------------------------------------------------------------------
  62. bool __fastcall TEditorData::DecideExternalEditorText(UnicodeString ExternalEditor)
  63. {
  64. bool Result = false;
  65. // By default we use default transfer mode (binary),
  66. // as all reasonable 3rd party editors support all EOL styles.
  67. // A notable exception is Windows Notepad, so here's an exception for it.
  68. ReformatFileNameCommand(ExternalEditor);
  69. UnicodeString ProgramName = ExtractProgramName(ExternalEditor);
  70. // We explicitly do not use TEditorPreferences::GetDefaultExternalEditor(),
  71. // as we need to explicitly refer to the Notepad, even if the default external
  72. // editor ever changes
  73. UnicodeString NotepadProgramName = ExtractProgramName(NotepadName);
  74. if (SameText(ProgramName, NotepadProgramName))
  75. {
  76. Result = true;
  77. }
  78. return Result;
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TEditorData::DecideExternalEditorText()
  82. {
  83. if (DecideExternalEditorText(ExternalEditor))
  84. {
  85. ExternalEditorText = true;
  86. }
  87. }
  88. //---------------------------------------------------------------------------
  89. __fastcall TEditorPreferences::TEditorPreferences()
  90. {
  91. }
  92. //---------------------------------------------------------------------------
  93. __fastcall TEditorPreferences::TEditorPreferences(const TEditorData & Data) :
  94. FData(Data)
  95. {
  96. }
  97. //---------------------------------------------------------------------------
  98. bool __fastcall TEditorPreferences::operator==(const TEditorPreferences & rhp) const
  99. {
  100. return (FData == rhp.FData);
  101. }
  102. #undef C
  103. //---------------------------------------------------------------------------
  104. bool __fastcall TEditorPreferences::Matches(const UnicodeString FileName,
  105. bool Local, const TFileMasks::TParams & Params) const
  106. {
  107. return FData.FileMask.Matches(FileName, Local, false, &Params);
  108. }
  109. //---------------------------------------------------------------------------
  110. UnicodeString __fastcall TEditorPreferences::GetDefaultExternalEditor()
  111. {
  112. return NotepadName;
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TEditorPreferences::LegacyDefaults()
  116. {
  117. FData.ExternalEditor = GetDefaultExternalEditor();
  118. FData.DecideExternalEditorText();
  119. }
  120. //---------------------------------------------------------------------------
  121. UnicodeString __fastcall TEditorPreferences::ExtractExternalEditorName() const
  122. {
  123. DebugAssert(FData.Editor == edExternal);
  124. UnicodeString ExternalEditor = FData.ExternalEditor;
  125. ReformatFileNameCommand(ExternalEditor);
  126. // Trim is a workaround for unknown problem with "notepad " (2 trailing spaces)
  127. return ExtractProgramName(ExternalEditor).Trim();
  128. }
  129. //---------------------------------------------------------------------------
  130. void __fastcall TEditorPreferences::Load(THierarchicalStorage * Storage, bool Legacy)
  131. {
  132. if (!Legacy)
  133. {
  134. FData.FileMask = Storage->ReadString(L"FileMask", FData.FileMask.Masks);
  135. }
  136. FData.Editor = (TEditor)Storage->ReadInteger(L"Editor", FData.Editor);
  137. FData.ExternalEditor = Storage->ReadString(L"ExternalEditor", FData.ExternalEditor);
  138. FData.ExternalEditorText = Storage->ReadBool(L"ExternalEditorText", FData.ExternalEditorText);
  139. FData.SDIExternalEditor = Storage->ReadBool(L"SDIExternalEditor", FData.SDIExternalEditor);
  140. FData.DetectMDIExternalEditor = Storage->ReadBool(L"DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
  141. }
  142. //---------------------------------------------------------------------------
  143. void __fastcall TEditorPreferences::Save(THierarchicalStorage * Storage) const
  144. {
  145. Storage->WriteString(L"FileMask", FData.FileMask.Masks);
  146. Storage->WriteInteger(L"Editor", FData.Editor);
  147. Storage->WriteString(L"ExternalEditor", FData.ExternalEditor);
  148. Storage->WriteBool(L"ExternalEditorText", FData.ExternalEditorText);
  149. Storage->WriteBool(L"SDIExternalEditor", FData.SDIExternalEditor);
  150. Storage->WriteBool(L"DetectMDIExternalEditor", FData.DetectMDIExternalEditor);
  151. }
  152. //---------------------------------------------------------------------------
  153. TEditorData * __fastcall TEditorPreferences::GetData()
  154. {
  155. // returning non-const data, possible data change, invalidate cached name
  156. FName = L"";
  157. return &FData;
  158. };
  159. //---------------------------------------------------------------------------
  160. UnicodeString __fastcall TEditorPreferences::GetName() const
  161. {
  162. if (FName.IsEmpty())
  163. {
  164. if (FData.Editor == edInternal)
  165. {
  166. // StripHotkey is relic from times when INTERNAL_EDITOR_NAME was used
  167. // also for the menu item caption
  168. FName = StripHotkey(LoadStr(INTERNAL_EDITOR_NAME));
  169. }
  170. else if (FData.Editor == edOpen)
  171. {
  172. FName = StripHotkey(LoadStr(OPEN_EDITOR_NAME));
  173. }
  174. else
  175. {
  176. UnicodeString Program, Params, Dir;
  177. UnicodeString ExternalEditor = FData.ExternalEditor;
  178. ReformatFileNameCommand(ExternalEditor);
  179. SplitCommand(ExternalEditor, Program, Params, Dir);
  180. FName = ExtractFileName(Program);
  181. int P = FName.LastDelimiter(L".");
  182. if (P > 0)
  183. {
  184. FName.SetLength(P - 1);
  185. }
  186. if (FName.ByteType(1) == mbSingleByte)
  187. {
  188. if (FName.UpperCase() == FName)
  189. {
  190. FName = FName.LowerCase();
  191. }
  192. if (FName.LowerCase() == FName)
  193. {
  194. FName = FName.SubString(1, 1).UpperCase() +
  195. FName.SubString(2, FName.Length() - 1);
  196. }
  197. }
  198. }
  199. }
  200. return FName;
  201. }
  202. //---------------------------------------------------------------------------
  203. //---------------------------------------------------------------------------
  204. __fastcall TEditorList::TEditorList()
  205. {
  206. Init();
  207. }
  208. //---------------------------------------------------------------------------
  209. void __fastcall TEditorList::Init()
  210. {
  211. FEditors = new TList();
  212. FModified = false;
  213. }
  214. //---------------------------------------------------------------------------
  215. __fastcall TEditorList::~TEditorList()
  216. {
  217. Clear();
  218. delete FEditors;
  219. }
  220. //---------------------------------------------------------------------
  221. void __fastcall TEditorList::Modify()
  222. {
  223. FModified = true;
  224. }
  225. //---------------------------------------------------------------------------
  226. void __fastcall TEditorList::Saved()
  227. {
  228. FModified = false;
  229. }
  230. //---------------------------------------------------------------------------
  231. TEditorList & __fastcall TEditorList::operator=(const TEditorList & rhl)
  232. {
  233. Clear();
  234. for (int Index = 0; Index < rhl.Count; Index++)
  235. {
  236. Add(new TEditorPreferences(*rhl.Editors[Index]));
  237. }
  238. // there should be comparison of with the assigned list, but we rely on caller
  239. // to do it instead (TWinConfiguration::SetEditorList)
  240. Modify();
  241. return *this;
  242. }
  243. //---------------------------------------------------------------------------
  244. bool __fastcall TEditorList::operator==(const TEditorList & rhl) const
  245. {
  246. bool Result = (Count == rhl.Count);
  247. if (Result)
  248. {
  249. int i = 0;
  250. while ((i < Count) && Result)
  251. {
  252. Result = (*Editors[i]) == (*rhl.Editors[i]);
  253. i++;
  254. }
  255. }
  256. return Result;
  257. }
  258. //---------------------------------------------------------------------------
  259. void __fastcall TEditorList::Clear()
  260. {
  261. for (int i = 0; i < Count; i++)
  262. {
  263. delete Editors[i];
  264. }
  265. FEditors->Clear();
  266. }
  267. //---------------------------------------------------------------------------
  268. void __fastcall TEditorList::Add(TEditorPreferences * Editor)
  269. {
  270. Insert(Count, Editor);
  271. }
  272. //---------------------------------------------------------------------------
  273. void __fastcall TEditorList::Insert(int Index, TEditorPreferences * Editor)
  274. {
  275. FEditors->Insert(Index, reinterpret_cast<TObject *>(Editor));
  276. Modify();
  277. }
  278. //---------------------------------------------------------------------------
  279. void __fastcall TEditorList::Change(int Index, TEditorPreferences * Editor)
  280. {
  281. if (!((*Editors[Index]) == *Editor))
  282. {
  283. delete Editors[Index];
  284. FEditors->Items[Index] = (reinterpret_cast<TObject *>(Editor));
  285. Modify();
  286. }
  287. else
  288. {
  289. delete Editor;
  290. }
  291. }
  292. //---------------------------------------------------------------------------
  293. void __fastcall TEditorList::Move(int CurIndex, int NewIndex)
  294. {
  295. if (CurIndex != NewIndex)
  296. {
  297. FEditors->Move(CurIndex, NewIndex);
  298. Modify();
  299. }
  300. }
  301. //---------------------------------------------------------------------------
  302. void __fastcall TEditorList::Delete(int Index)
  303. {
  304. DebugAssert((Index >= 0) && (Index < Count));
  305. delete Editors[Index];
  306. FEditors->Delete(Index);
  307. Modify();
  308. }
  309. //---------------------------------------------------------------------------
  310. const TEditorPreferences * __fastcall TEditorList::Find(
  311. const UnicodeString FileName, bool Local, const TFileMasks::TParams & Params) const
  312. {
  313. const TEditorPreferences * Result = NULL;
  314. int i = 0;
  315. while ((i < FEditors->Count) && (Result == NULL))
  316. {
  317. Result = Editors[i];
  318. if (!Result->Matches(FileName, Local, Params))
  319. {
  320. Result = NULL;
  321. }
  322. i++;
  323. }
  324. return Result;
  325. }
  326. //---------------------------------------------------------------------------
  327. void __fastcall TEditorList::Load(THierarchicalStorage * Storage)
  328. {
  329. int Index = 0;
  330. bool Next;
  331. do
  332. {
  333. UnicodeString Name = IntToStr(Index);
  334. TEditorPreferences * Editor = NULL;
  335. try
  336. {
  337. Next = Storage->OpenSubKey(Name, false);
  338. if (Next)
  339. {
  340. try
  341. {
  342. Editor = new TEditorPreferences();
  343. Editor->Load(Storage, false);
  344. }
  345. __finally
  346. {
  347. Storage->CloseSubKey();
  348. }
  349. }
  350. }
  351. catch(...)
  352. {
  353. delete Editor;
  354. throw;
  355. }
  356. if (Editor != NULL)
  357. {
  358. FEditors->Add(reinterpret_cast<TObject *>(Editor));
  359. }
  360. Index++;
  361. }
  362. while (Next);
  363. FModified = false;
  364. }
  365. //---------------------------------------------------------------------------
  366. void __fastcall TEditorList::Save(THierarchicalStorage * Storage) const
  367. {
  368. Storage->ClearSubKeys();
  369. for (int Index = 0; Index < Count; Index++)
  370. {
  371. if (Storage->OpenSubKey(IntToStr(Index), true))
  372. {
  373. try
  374. {
  375. Editors[Index]->Save(Storage);
  376. }
  377. __finally
  378. {
  379. Storage->CloseSubKey();
  380. }
  381. }
  382. }
  383. }
  384. //---------------------------------------------------------------------------
  385. int __fastcall TEditorList::GetCount() const
  386. {
  387. int X = FEditors->Count;
  388. return X;
  389. }
  390. //---------------------------------------------------------------------------
  391. const TEditorPreferences * __fastcall TEditorList::GetEditor(int Index) const
  392. {
  393. return reinterpret_cast<TEditorPreferences *>(FEditors->Items[Index]);
  394. }
  395. //---------------------------------------------------------------------------
  396. bool __fastcall TEditorList::IsDefaultList() const
  397. {
  398. bool Result = true;
  399. for (int Index = 0; Result && (Index < Count); Index++)
  400. {
  401. const TEditorPreferences * Editor = GetEditor(Index);
  402. if (Editor->Data->Editor == edInternal)
  403. {
  404. // noop (keeps Result true)
  405. }
  406. else if (Editor->Data->Editor == edExternal)
  407. {
  408. UnicodeString ExternalEditor = Editor->ExtractExternalEditorName();
  409. UnicodeString DefaultExternalEditor = ExtractProgramName(TEditorPreferences::GetDefaultExternalEditor());
  410. Result = SameText(ExternalEditor, DefaultExternalEditor);
  411. }
  412. else
  413. {
  414. Result = false;
  415. }
  416. }
  417. return Result;
  418. }
  419. //---------------------------------------------------------------------------
  420. //---------------------------------------------------------------------------
  421. __fastcall TWinConfiguration::TWinConfiguration(): TCustomWinConfiguration()
  422. {
  423. FInvalidDefaultTranslationMessage = L"";
  424. FDDExtInstalled = -1;
  425. FBookmarks = new TBookmarks();
  426. FCustomCommandList = new TCustomCommandList();
  427. FEditorList = new TEditorList();
  428. FDefaultUpdatesPeriod = 0;
  429. FDontDecryptPasswords = 0;
  430. FMasterPasswordSession = 0;
  431. FMasterPasswordSessionAsked = false;
  432. FSystemIconFont.reset(new TFont());
  433. UpdateSystemIconFont();
  434. Default();
  435. try
  436. {
  437. CheckTranslationVersion(
  438. GetResourceModuleName(Application->Name, ModuleFileName().c_str()), true);
  439. }
  440. catch(Exception & E)
  441. {
  442. FInvalidDefaultTranslationMessage = E.Message;
  443. }
  444. }
  445. //---------------------------------------------------------------------------
  446. __fastcall TWinConfiguration::~TWinConfiguration()
  447. {
  448. if (!FTemporarySessionFile.IsEmpty()) DeleteFile(ApiPath(FTemporarySessionFile));
  449. ClearTemporaryLoginData();
  450. delete FBookmarks;
  451. delete FCustomCommandList;
  452. delete FEditorList;
  453. }
  454. //---------------------------------------------------------------------------
  455. void __fastcall TWinConfiguration::Default()
  456. {
  457. FCustomCommandsDefaults = true;
  458. TCustomWinConfiguration::Default();
  459. int WorkAreaWidthScaled = DimensionToDefaultPixelsPerInch(Screen->WorkAreaWidth);
  460. int WorkAreaHeightScaled = DimensionToDefaultPixelsPerInch(Screen->WorkAreaHeight);
  461. UnicodeString PixelsPerInchToolbarValue = "PixelsPerInch=" + SaveDefaultPixelsPerInch();
  462. FDDAllowMove = false;
  463. FDDAllowMoveInit = false;
  464. FDDTransferConfirmation = asAuto;
  465. FDDTemporaryDirectory = L"";
  466. FDDWarnLackOfTempSpace = true;
  467. FDDWarnLackOfTempSpaceRatio = 1.1;
  468. FDDExtEnabled = DDExtInstalled;
  469. FDDExtTimeout = MSecsPerSec;
  470. FDeleteToRecycleBin = true;
  471. FSelectDirectories = false;
  472. FSelectMask = L"*.*";
  473. FShowHiddenFiles = false;
  474. FFormatSizeBytes = fbKilobytes;
  475. FShowInaccesibleDirectories = true;
  476. FConfirmTransferring = true;
  477. FConfirmDeleting = true;
  478. FConfirmRecycling = true;
  479. FConfirmClosingSession = true;
  480. FDoubleClickAction = dcaEdit;
  481. FCopyOnDoubleClickConfirmation = false;
  482. FDimmHiddenFiles = true;
  483. FRenameWholeName = false;
  484. FAutoStartSession = L"";
  485. FExpertMode = true;
  486. FUseLocationProfiles = false;
  487. FUseSharedBookmarks = false;
  488. FDefaultDirIsHome = true;
  489. FDDDeleteDelay = 120;
  490. FTemporaryDirectoryAppendSession = false;
  491. FTemporaryDirectoryDeterministic = false;
  492. FTemporaryDirectoryAppendPath = true;
  493. FTemporaryDirectoryCleanup = true;
  494. FConfirmTemporaryDirectoryCleanup = true;
  495. FPreservePanelState = true;
  496. FLastStoredSession = L"";
  497. // deliberately not being saved, so that when saving ad-hoc workspace,
  498. // we do not offer to overwrite the last saved workspace, what may be undesirable
  499. FLastWorkspace = L"";
  500. FAutoSaveWorkspace = false;
  501. FAutoSaveWorkspacePasswords = false;
  502. FAutoWorkspace = L"";
  503. FPathInCaption = picShort;
  504. FMinimizeToTray = false;
  505. FMinimizeToTrayOnce = false;
  506. FBalloonNotifications = true;
  507. FNotificationsTimeout = 10;
  508. FNotificationsStickTime = 2;
  509. FCopyParamAutoSelectNotice = true;
  510. FLockToolbars = false;
  511. FSelectiveToolbarText = true;
  512. FAutoOpenInPutty = false;
  513. FRefreshRemotePanel = false;
  514. FRefreshRemotePanelInterval = TDateTime(0, 1, 0, 0);
  515. FPanelFont.FontName = L"";
  516. FPanelFont.FontSize = 0;
  517. FPanelFont.FontStyle = 0;
  518. FPanelFont.FontCharset = DEFAULT_CHARSET;
  519. FFullRowSelect = false;
  520. FOfferedEditorAutoConfig = false;
  521. FVersionHistory = L"";
  522. AddVersionToHistory();
  523. FUseMasterPassword = false;
  524. FPlainMasterPasswordEncrypt = L"";
  525. FPlainMasterPasswordDecrypt = L"";
  526. FMasterPasswordVerifier = L"";
  527. FOpenedStoredSessionFolders = L"";
  528. FAutoImportedFromPuttyOrFilezilla = false;
  529. FGenerateUrlComponents = -1;
  530. FGenerateUrlCodeTarget = guctUrl;
  531. FGenerateUrlScriptFormat = sfScriptFile;
  532. FGenerateUrlAssemblyLanguage = alCSharp;
  533. FExternalSessionInExistingInstance = true;
  534. FKeepOpenWhenNoSession = false;
  535. FLocalIconsByExt = false;
  536. FBidiModeOverride = lfoLanguageIfRecommended;
  537. FFlipChildrenOverride = lfoLanguageIfRecommended;
  538. FShowTips = true;
  539. FTipsSeen = L"";
  540. FTipsShown = Now();
  541. FRunsSinceLastTip = 0;
  542. HonorDrivePolicy = true;
  543. FEditor.Font.FontName = DefaultFixedWidthFontName;
  544. FEditor.Font.FontSize = DefaultFixedWidthFontSize;
  545. FEditor.Font.FontStyle = 0;
  546. FEditor.Font.FontCharset = DEFAULT_CHARSET;
  547. FEditor.FontColor = TColor(0);
  548. FEditor.BackgroundColor = TColor(0);
  549. FEditor.WordWrap = false;
  550. FEditor.FindText = L"";
  551. FEditor.ReplaceText = L"";
  552. FEditor.FindMatchCase = false;
  553. FEditor.FindWholeWord = false;
  554. FEditor.FindDown = true;
  555. FEditor.TabSize = 8;
  556. FEditor.MaxEditors = 500;
  557. FEditor.EarlyClose = 2; // seconds
  558. FEditor.SDIShellEditor = false;
  559. FEditor.WindowParams = L"";
  560. FEditor.Encoding = CP_ACP;
  561. FEditor.WarnOnEncodingFallback = true;
  562. FEditor.WarnOrLargeFileSize = true;
  563. FQueueView.Height = 140;
  564. FQueueView.HeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  565. // with 1000 pixels wide screen, both interfaces are wide enough to fit wider queue
  566. FQueueView.Layout =
  567. UnicodeString((WorkAreaWidthScaled > 1000) ? L"70,250,250,80,80,80,100" : L"70,160,160,80,80,80,100") +
  568. // WORKAROUND (the comma), see GetListViewStr
  569. L",;" + SaveDefaultPixelsPerInch();
  570. FQueueView.Show = qvHideWhenEmpty;
  571. FQueueView.LastHideShow = qvHideWhenEmpty;
  572. FQueueView.ToolBar = true;
  573. FQueueView.Label = true;
  574. FEnableQueueByDefault = true;
  575. FUpdates.Period = FDefaultUpdatesPeriod;
  576. FUpdates.LastCheck = 0;
  577. FUpdates.HaveResults = false;
  578. FUpdates.ShownResults = false;
  579. FUpdates.BetaVersions = asAuto;
  580. FUpdates.ShowOnStartup = true;
  581. FUpdates.AuthenticationEmail = L"";
  582. // for backward compatibility the default is decided based on value of ProxyHost
  583. FUpdates.ConnectionType = (TConnectionType)-1;
  584. FUpdates.ProxyHost = L""; // keep empty (see above)
  585. FUpdates.ProxyPort = 8080;
  586. FUpdates.Results.Reset();
  587. FUpdates.DotNetVersion = L"";
  588. FUpdates.ConsoleVersion = L"";
  589. FLogWindowOnStartup = true;
  590. FLogWindowParams = FormatDefaultWindowParams(500, 400);
  591. int ExplorerWidth = Min(WorkAreaWidthScaled - 40, 960);
  592. int ExplorerHeight = Min(WorkAreaHeightScaled - 30, 720);
  593. FScpExplorer.WindowParams = FormatDefaultWindowParams(ExplorerWidth, ExplorerHeight);
  594. // WORKAROUND (the semicolon, see TCustomListViewColProperties.GetParamsStr, and see other instances below)
  595. 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";
  596. FScpExplorer.ToolbarsLayout =
  597. UnicodeString(
  598. L"Queue_Visible=1,Queue_LastDock=QueueDock,Queue_DockRow=0,Queue_DockPos=-1,Queue_FloatLeft=0,Queue_FloatTop=0,Queue_FloatRightX=0,"
  599. "Menu_Visible=1,Menu_DockedTo=TopDock,Menu_LastDock=TopDock,Menu_DockRow=0,Menu_DockPos=0,Menu_FloatLeft=0,Menu_FloatTop=0,Menu_FloatRightX=0,"
  600. "Buttons_Visible=1,Buttons_DockedTo=TopDock,Buttons_LastDock=TopDock,Buttons_DockRow=2,Buttons_DockPos=0,Buttons_FloatLeft=0,Buttons_FloatTop=0,Buttons_FloatRightX=0,"
  601. "Selection_Visible=0,Selection_DockedTo=TopDock,Selection_LastDock=TopDock,Selection_DockRow=3,Selection_DockPos=0,Selection_FloatLeft=227,Selection_FloatTop=445,Selection_FloatRightX=0,"
  602. "Session_Visible=0,Session_DockedTo=TopDock,Session_LastDock=TopDock,Session_DockRow=6,Session_DockPos=0,Session_FloatLeft=39,Session_FloatTop=160,Session_FloatRightX=0,"
  603. "Preferences_Visible=1,Preferences_DockedTo=TopDock,Preferences_LastDock=TopDock,Preferences_DockRow=4,Preferences_DockPos=0,Preferences_FloatLeft=0,Preferences_FloatTop=0,Preferences_FloatRightX=0,"
  604. "Sort_Visible=0,Sort_DockedTo=TopDock,Sort_LastDock=TopDock,Sort_DockRow=5,Sort_DockPos=0,Sort_FloatLeft=0,Sort_FloatTop=0,Sort_FloatRightX=0,"
  605. "Address_Visible=1,Address_DockedTo=TopDock,Address_LastDock=TopDock,Address_DockRow=1,Address_DockPos=0,Address_FloatLeft=0,Address_FloatTop=0,Address_FloatRightX=0,"
  606. "Updates_Visible=1,Updates_DockedTo=TopDock,Updates_LastDock=TopDock,Updates_DockRow=4,Updates_DockPos=416,Updates_FloatLeft=0,Updates_FloatTop=0,Updates_FloatRightX=0,"
  607. "Transfer_Visible=1,Transfer_DockedTo=TopDock,Transfer_LastDock=TopDock,Transfer_DockRow=4,Transfer_DockPos=194,Transfer_FloatLeft=0,Transfer_FloatTop=0,Transfer_FloatRightX=0,"
  608. "CustomCommands_Visible=0,CustomCommands_DockedTo=TopDock,CustomCommands_LastDock=TopDock,CustomCommands_DockRow=7,CustomCommands_DockPos=0,CustomCommands_FloatLeft=0,CustomCommands_FloatTop=0,CustomCommands_FloatRightX=0,") +
  609. PixelsPerInchToolbarValue;
  610. FScpExplorer.SessionsTabs = true;
  611. FScpExplorer.StatusBar = true;
  612. FScpExplorer.LastLocalTargetDirectory = GetPersonalFolder();
  613. FScpExplorer.ViewStyle = 0; /* vsIcon */
  614. FScpExplorer.ShowFullAddress = true;
  615. FScpExplorer.DriveView = true;
  616. FScpExplorer.DriveViewWidth = 180;
  617. FScpExplorer.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  618. int CommanderWidth = Min(WorkAreaWidthScaled - 40, 1090);
  619. int CommanderHeight = Min(WorkAreaHeightScaled - 30, 700);
  620. FScpCommander.WindowParams = FormatDefaultWindowParams(CommanderWidth, CommanderHeight);
  621. FScpCommander.LocalPanelWidth = 0.5;
  622. FScpCommander.SwappedPanels = false;
  623. FScpCommander.SessionsTabs = true;
  624. FScpCommander.StatusBar = true;
  625. FScpCommander.NortonLikeMode = nlKeyboard;
  626. FScpCommander.PreserveLocalDirectory = false;
  627. // Toolbar2_FloatRightX=1 makes keybar apper initially "in column" when undocked
  628. FScpCommander.ToolbarsLayout =
  629. UnicodeString(
  630. L"Queue_Visible=1,Queue_LastDock=QueueDock,Queue_DockRow=0,Queue_DockPos=-1,Queue_FloatLeft=0,Queue_FloatTop=0,Queue_FloatRightX=0,"
  631. "Menu_Visible=1,Menu_DockedTo=TopDock,Menu_LastDock=TopDock,Menu_DockRow=0,Menu_DockPos=0,Menu_FloatLeft=0,Menu_FloatTop=0,Menu_FloatRightX=0,"
  632. "Preferences_Visible=1,Preferences_DockedTo=TopDock,Preferences_LastDock=TopDock,Preferences_DockRow=1,Preferences_DockPos=228,Preferences_FloatLeft=0,Preferences_FloatTop=0,Preferences_FloatRightX=0,"
  633. "Session_Visible=0,Session_DockedTo=TopDock,Session_LastDock=TopDock,Session_DockRow=1,Session_DockPos=602,Session_FloatLeft=380,Session_FloatTop=197,Session_FloatRightX=0,"
  634. "Sort_Visible=0,Sort_DockedTo=TopDock,Sort_LastDock=TopDock,Sort_DockRow=2,Sort_DockPos=0,Sort_FloatLeft=0,Sort_FloatTop=0,Sort_FloatRightX=0,"
  635. "Commands_Visible=1,Commands_DockedTo=TopDock,Commands_LastDock=TopDock,Commands_DockRow=1,Commands_DockPos=0,Commands_FloatLeft=0,Commands_FloatTop=0,Commands_FloatRightX=0,"
  636. "Updates_Visible=1,Updates_DockedTo=TopDock,Updates_LastDock=TopDock,Updates_DockRow=1,Updates_DockPos=619,Updates_FloatLeft=0,Updates_FloatTop=0,Updates_FloatRightX=0,"
  637. "Transfer_Visible=1,Transfer_DockedTo=TopDock,Transfer_LastDock=TopDock,Transfer_DockRow=1,Transfer_DockPos=364,Transfer_FloatLeft=0,Transfer_FloatTop=0,Transfer_FloatRightX=0,"
  638. "CustomCommands_Visible=0,CustomCommands_DockedTo=TopDock,CustomCommands_LastDock=TopDock,CustomCommands_DockRow=3,CustomCommands_DockPos=0,CustomCommands_FloatLeft=0,CustomCommands_FloatTop=0,CustomCommands_FloatRightX=0,"
  639. "RemoteHistory_Visible=1,RemoteHistory_DockedTo=RemoteTopDock,RemoteHistory_LastDock=RemoteTopDock,RemoteHistory_DockRow=0,RemoteHistory_DockPos=172,RemoteHistory_FloatLeft=0,RemoteHistory_FloatTop=0,RemoteHistory_FloatRightX=0,"
  640. "RemoteNavigation_Visible=1,RemoteNavigation_DockedTo=RemoteTopDock,RemoteNavigation_LastDock=RemoteTopDock,RemoteNavigation_DockRow=0,RemoteNavigation_DockPos=252,RemoteNavigation_FloatLeft=0,RemoteNavigation_FloatTop=0,RemoteNavigation_FloatRightX=0,"
  641. "RemotePath_Visible=1,RemotePath_DockedTo=RemoteTopDock,RemotePath_LastDock=RemoteTopDock,RemotePath_DockRow=0,RemotePath_DockPos=0,RemotePath_FloatLeft=0,RemotePath_FloatTop=0,RemotePath_FloatRightX=0,"
  642. "RemoteFile_Visible=1,RemoteFile_DockedTo=RemoteTopDock,RemoteFile_LastDock=RemoteTopDock,RemoteFile_DockRow=1,RemoteFile_DockPos=0,RemoteFile_FloatLeft=0,RemoteFile_FloatTop=0,RemoteFile_FloatRightX=0,"
  643. "RemoteSelection_Visible=1,RemoteSelection_DockedTo=RemoteTopDock,RemoteSelection_LastDock=RemoteTopDock,RemoteSelection_DockRow=1,RemoteSelection_DockPos=345,RemoteSelection_FloatLeft=0,RemoteSelection_FloatTop=0,RemoteSelection_FloatRightX=0,"
  644. "LocalHistory_Visible=1,LocalHistory_DockedTo=LocalTopDock,LocalHistory_LastDock=LocalTopDock,LocalHistory_DockRow=0,LocalHistory_DockPos=207,LocalHistory_FloatLeft=0,LocalHistory_FloatTop=0,LocalHistory_FloatRightX=0,"
  645. "LocalNavigation_Visible=1,LocalNavigation_DockedTo=LocalTopDock,LocalNavigation_LastDock=LocalTopDock,LocalNavigation_DockRow=0,LocalNavigation_DockPos=287,LocalNavigation_FloatLeft=0,LocalNavigation_FloatTop=0,LocalNavigation_FloatRightX=0,"
  646. "LocalPath_Visible=1,LocalPath_DockedTo=LocalTopDock,LocalPath_LastDock=LocalTopDock,LocalPath_DockRow=0,LocalPath_DockPos=0,LocalPath_FloatLeft=0,LocalPath_FloatTop=0,LocalPath_FloatRightX=0,"
  647. "LocalFile_Visible=1,LocalFile_DockedTo=LocalTopDock,LocalFile_LastDock=LocalTopDock,LocalFile_DockRow=1,LocalFile_DockPos=0,LocalFile_FloatLeft=0,LocalFile_FloatTop=0,LocalFile_FloatRightX=0,"
  648. "LocalSelection_Visible=1,LocalSelection_DockedTo=LocalTopDock,LocalSelection_LastDock=LocalTopDock,LocalSelection_DockRow=1,LocalSelection_DockPos=329,LocalSelection_FloatLeft=0,LocalSelection_FloatTop=0,LocalSelection_FloatRightX=0,"
  649. "Toolbar2_Visible=0,Toolbar2_DockedTo=BottomDock,Toolbar2_LastDock=BottomDock,Toolbar2_DockRow=1,Toolbar2_DockPos=0,Toolbar2_FloatLeft=0,Toolbar2_FloatTop=0,Toolbar2_FloatRightX=1,"
  650. "CommandLine_Visible=0,CommandLine_DockedTo=BottomDock,CommandLine_LastDock=BottomDock,CommandLine_DockRow=0,CommandLine_DockPos=0,CommandLine_FloatLeft=0,CommandLine_FloatTop=0,CommandLine_FloatRightX=0,") +
  651. PixelsPerInchToolbarValue;
  652. FScpCommander.CurrentPanel = osLocal;
  653. FScpCommander.CompareByTime = true;
  654. FScpCommander.CompareBySize = false;
  655. FScpCommander.TreeOnLeft = false;
  656. FScpCommander.ExplorerKeyboardShortcuts = false;
  657. FScpCommander.SystemContextMenu = false;
  658. 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";
  659. FScpCommander.RemotePanel.StatusBar = true;
  660. FScpCommander.RemotePanel.DriveView = false;
  661. FScpCommander.RemotePanel.DriveViewHeight = 100;
  662. FScpCommander.RemotePanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  663. FScpCommander.RemotePanel.DriveViewWidth = 100;
  664. FScpCommander.RemotePanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  665. 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";
  666. FScpCommander.LocalPanel.StatusBar = true;
  667. FScpCommander.LocalPanel.DriveView = false;
  668. FScpCommander.LocalPanel.DriveViewHeight = 100;
  669. FScpCommander.LocalPanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  670. FScpCommander.LocalPanel.DriveViewWidth = 100;
  671. FScpCommander.LocalPanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  672. FBookmarks->Clear();
  673. }
  674. //---------------------------------------------------------------------------
  675. void __fastcall TWinConfiguration::DefaultLocalized()
  676. {
  677. TGUIConfiguration::DefaultLocalized();
  678. if (FCustomCommandsDefaults)
  679. {
  680. FCustomCommandList->Clear();
  681. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_EXECUTE), L"\"./!\"", 0);
  682. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TOUCH), L"touch \"!\"", ccApplyToDirectories | ccRecursive);
  683. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TAR),
  684. FORMAT(L"tar -cz -f \"!?%s?archive.tgz!\" !&",
  685. (LoadStr(CUSTOM_COMMAND_TAR_ARCHIVE))), ccApplyToDirectories);
  686. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_UNTAR),
  687. FORMAT(L"tar -xz --directory=\"!?%s?.!\" -f \"!\"",
  688. (LoadStr(CUSTOM_COMMAND_UNTAR_DIRECTORY))), 0);
  689. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_GREP),
  690. FORMAT(L"grep \"!?%s?!\" !&", (LoadStr(CUSTOM_COMMAND_GREP_PATTERN))),
  691. ccShowResults);
  692. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_FC),
  693. L"cmd /c fc \"!\" \"\!^!\" | more && pause", ccLocal);
  694. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_PRINT), L"notepad.exe /p \"!\"", ccLocal);
  695. FCustomCommandList->Reset();
  696. FCustomCommandsDefaults = true;
  697. }
  698. }
  699. //---------------------------------------------------------------------------
  700. bool __fastcall TWinConfiguration::DetectRegistryStorage(HKEY RootKey)
  701. {
  702. bool Result = false;
  703. TRegistryStorage * Storage = new TRegistryStorage(RegistryStorageKey, RootKey);
  704. try
  705. {
  706. if (Storage->OpenRootKey(false))
  707. {
  708. Result = true;
  709. Storage->CloseSubKey();
  710. }
  711. }
  712. __finally
  713. {
  714. delete Storage;
  715. }
  716. return Result;
  717. }
  718. //---------------------------------------------------------------------------
  719. bool __fastcall TWinConfiguration::CanWriteToStorage()
  720. {
  721. bool Result = false;
  722. try
  723. {
  724. THierarchicalStorage * Storage = CreateConfigStorage();
  725. try
  726. {
  727. Storage->AccessMode = smReadWrite;
  728. // This is actually not very good test, as we end up potentially with
  729. // the very same config, and TIniFileStorage file won't even try to
  730. // write the file then. Lucliky, we use this for empty config only,
  731. // so we end up with at least an empty section.
  732. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  733. {
  734. Storage->WriteBool(L"WriteTest", true);
  735. Storage->DeleteValue(L"WriteTest");
  736. }
  737. Storage->Flush();
  738. }
  739. __finally
  740. {
  741. delete Storage;
  742. }
  743. Result = true;
  744. }
  745. catch(...)
  746. {
  747. }
  748. return Result;
  749. }
  750. //---------------------------------------------------------------------------
  751. TStorage __fastcall TWinConfiguration::GetStorage()
  752. {
  753. if (FStorage == stDetect)
  754. {
  755. if (FindResourceEx(NULL, RT_RCDATA, L"WINSCP_SESSION",
  756. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
  757. {
  758. FTemporarySessionFile =
  759. IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscps.tmp";
  760. DumpResourceToFile(L"WINSCP_SESSION", FTemporarySessionFile);
  761. FEmbeddedSessions = true;
  762. FTemporaryKeyFile =
  763. IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscpk.tmp";
  764. if (!DumpResourceToFile(L"WINSCP_KEY", FTemporaryKeyFile))
  765. {
  766. FTemporaryKeyFile = L"";
  767. }
  768. }
  769. FStorage = stIniFile;
  770. if (!FileExists(ApiPath(IniFileStorageNameForReading)))
  771. {
  772. if (DetectRegistryStorage(HKEY_CURRENT_USER) ||
  773. DetectRegistryStorage(HKEY_LOCAL_MACHINE) ||
  774. // FStorage is now stIniFile, so this tests writing to an INI file.
  775. // As we fall back to user profile folder, when application folder
  776. // is not writtable, it is actually unlikely that the below test ever fails.
  777. !CanWriteToStorage())
  778. {
  779. FStorage = stRegistry;
  780. }
  781. }
  782. }
  783. TStorage Result = TCustomWinConfiguration::GetStorage();
  784. return Result;
  785. }
  786. //---------------------------------------------------------------------------
  787. void __fastcall TWinConfiguration::Saved()
  788. {
  789. TCustomWinConfiguration::Saved();
  790. FBookmarks->ModifyAll(false);
  791. FCustomCommandList->Reset();
  792. FEditorList->Saved();
  793. }
  794. //---------------------------------------------------------------------------
  795. void __fastcall TWinConfiguration::RecryptPasswords(TStrings * RecryptPasswordErrors)
  796. {
  797. TCustomWinConfiguration::RecryptPasswords(RecryptPasswordErrors);
  798. try
  799. {
  800. TTerminalManager * Manager = TTerminalManager::Instance(false);
  801. DebugAssert(Manager != NULL);
  802. if (Manager != NULL)
  803. {
  804. Manager->RecryptPasswords();
  805. }
  806. }
  807. catch (Exception & E)
  808. {
  809. UnicodeString Message;
  810. if (ExceptionMessage(&E, Message))
  811. {
  812. // we do not expect this really to happen,
  813. // so we do not bother providing context
  814. RecryptPasswordErrors->Add(Message);
  815. }
  816. }
  817. }
  818. //---------------------------------------------------------------------------
  819. bool __fastcall TWinConfiguration::GetUseMasterPassword()
  820. {
  821. return FUseMasterPassword;
  822. }
  823. //---------------------------------------------------------------------------
  824. THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
  825. {
  826. // Detect embedded session, if not checked yet
  827. GetStorage();
  828. THierarchicalStorage * Result;
  829. if (SessionList && !FTemporarySessionFile.IsEmpty())
  830. {
  831. Result = new TIniFileStorage(FTemporarySessionFile);
  832. // This is session-list specific store, so the only instance,
  833. // we do not reset the SessionList argument
  834. // (compare TConfiguration::CreateScpStorage)
  835. }
  836. else
  837. {
  838. Result = TCustomWinConfiguration::CreateScpStorage(SessionList);
  839. }
  840. return Result;
  841. }
  842. //---------------------------------------------------------------------------
  843. // duplicated from core\configuration.cpp
  844. #define LASTELEM(ELEM) \
  845. ELEM.SubString(ELEM.LastDelimiter(L".>")+1, ELEM.Length() - ELEM.LastDelimiter(L".>"))
  846. #define BLOCK(KEY, CANCREATE, BLOCK) \
  847. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  848. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  849. #define REGCONFIG(CANCREATE) \
  850. BLOCK(L"Interface", CANCREATE, \
  851. KEYEX(Integer,DoubleClickAction, L"CopyOnDoubleClick"); \
  852. KEY(Bool, CopyOnDoubleClickConfirmation); \
  853. KEY(Bool, DDAllowMove); \
  854. KEY(Bool, DDAllowMoveInit); \
  855. KEYEX(Integer, DDTransferConfirmation, L"DDTransferConfirmation2"); \
  856. KEY(String, DDTemporaryDirectory); \
  857. KEY(Bool, DDWarnLackOfTempSpace); \
  858. KEY(Float, DDWarnLackOfTempSpaceRatio); \
  859. KEY(Bool, DeleteToRecycleBin); \
  860. KEY(Bool, DimmHiddenFiles); \
  861. KEY(Bool, RenameWholeName); \
  862. KEY(Bool, SelectDirectories); \
  863. KEY(String, SelectMask); \
  864. KEY(Bool, ShowHiddenFiles); \
  865. KEY(Integer, FormatSizeBytes); \
  866. KEY(Bool, ShowInaccesibleDirectories); \
  867. KEY(Bool, ConfirmTransferring); \
  868. KEY(Bool, ConfirmDeleting); \
  869. KEY(Bool, ConfirmRecycling); \
  870. KEY(Bool, ConfirmClosingSession); \
  871. KEY(String, AutoStartSession); \
  872. KEY(Bool, UseLocationProfiles); \
  873. KEY(Bool, UseSharedBookmarks); \
  874. KEY(Integer, LocaleSafe); \
  875. KEY(Bool, DDExtEnabled); \
  876. KEY(Integer, DDExtTimeout); \
  877. KEY(Bool, DefaultDirIsHome); \
  878. KEY(Bool, TemporaryDirectoryAppendSession); \
  879. KEY(Bool, TemporaryDirectoryAppendPath); \
  880. KEY(Bool, TemporaryDirectoryDeterministic); \
  881. KEY(Bool, TemporaryDirectoryCleanup); \
  882. KEY(Bool, ConfirmTemporaryDirectoryCleanup); \
  883. KEY(Bool, PreservePanelState); \
  884. KEY(String, LastStoredSession); \
  885. KEY(Bool, AutoSaveWorkspace); \
  886. KEY(Bool, AutoSaveWorkspacePasswords); \
  887. KEY(String, AutoWorkspace); \
  888. KEY(Integer, PathInCaption); \
  889. KEY(Bool, MinimizeToTray); \
  890. KEY(Bool, BalloonNotifications); \
  891. KEY(Integer, NotificationsTimeout); \
  892. KEY(Integer, NotificationsStickTime); \
  893. KEY(Bool, CopyParamAutoSelectNotice); \
  894. KEY(Bool, LockToolbars); \
  895. KEY(Bool, SelectiveToolbarText); \
  896. KEY(Bool, AutoOpenInPutty); \
  897. KEY(Bool, RefreshRemotePanel); \
  898. KEY(DateTime, RefreshRemotePanelInterval); \
  899. KEYEX(String, PanelFont.FontName, L"PanelFontName"); \
  900. KEYEX(Integer,PanelFont.FontSize, L"PanelFontSize"); \
  901. KEYEX(Integer,PanelFont.FontStyle, L"PanelFontStyle"); \
  902. KEYEX(Integer,PanelFont.FontCharset, L"PanelFontCharset"); \
  903. KEY(Bool, FullRowSelect); \
  904. KEY(Bool, OfferedEditorAutoConfig); \
  905. KEY(Integer, LastMonitor); \
  906. KEY(String, VersionHistory); \
  907. KEY(Bool, EnableQueueByDefault); \
  908. KEY(String, OpenedStoredSessionFolders); \
  909. KEY(Bool, AutoImportedFromPuttyOrFilezilla); \
  910. KEY(Integer, GenerateUrlComponents); \
  911. KEY(Integer, GenerateUrlCodeTarget); \
  912. KEY(Integer, GenerateUrlScriptFormat); \
  913. KEY(Integer, GenerateUrlAssemblyLanguage); \
  914. KEY(Bool, ExternalSessionInExistingInstance); \
  915. KEY(Bool, KeepOpenWhenNoSession); \
  916. KEY(Bool, LocalIconsByExt); \
  917. KEY(Integer, BidiModeOverride); \
  918. KEY(Integer, FlipChildrenOverride); \
  919. KEY(Bool, ShowTips); \
  920. KEY(String, TipsSeen); \
  921. KEY(DateTime, TipsShown); \
  922. KEY(Integer, RunsSinceLastTip); \
  923. KEY(Bool, HonorDrivePolicy); \
  924. KEY(Integer, LastMachineInstallations); \
  925. ); \
  926. BLOCK(L"Interface\\Editor", CANCREATE, \
  927. KEYEX(String, Editor.Font.FontName, L"FontName2"); \
  928. KEY(Integer, Editor.Font.FontSize); \
  929. KEY(Integer, Editor.Font.FontStyle); \
  930. KEY(Integer, Editor.Font.FontCharset); \
  931. KEY(Integer, Editor.FontColor); \
  932. KEY(Integer, Editor.BackgroundColor); \
  933. KEY(Bool, Editor.WordWrap); \
  934. KEY(String, Editor.FindText); \
  935. KEY(String, Editor.ReplaceText); \
  936. KEY(Bool, Editor.FindMatchCase); \
  937. KEY(Bool, Editor.FindWholeWord); \
  938. KEY(Bool, Editor.FindDown); \
  939. KEY(Integer, Editor.TabSize); \
  940. KEY(Integer, Editor.MaxEditors); \
  941. KEY(Integer, Editor.EarlyClose); \
  942. KEY(Bool, Editor.SDIShellEditor); \
  943. KEY(String, Editor.WindowParams); \
  944. KEY(Integer, Editor.Encoding); \
  945. KEY(Bool, Editor.WarnOnEncodingFallback); \
  946. KEY(Bool, Editor.WarnOrLargeFileSize); \
  947. ); \
  948. BLOCK(L"Interface\\QueueView", CANCREATE, \
  949. KEY(Integer, QueueView.Height); \
  950. KEY(Integer, QueueView.HeightPixelsPerInch); \
  951. KEY(String, QueueView.Layout); \
  952. KEY(Integer, QueueView.Show); \
  953. KEY(Integer, QueueView.LastHideShow); \
  954. KEY(Bool, QueueView.ToolBar); \
  955. KEY(Bool, QueueView.Label); \
  956. ); \
  957. BLOCK(L"Interface\\Updates", CANCREATE, \
  958. KEY(Integer, FUpdates.Period); \
  959. KEY(DateTime, FUpdates.LastCheck); \
  960. KEY(Integer, FUpdates.HaveResults); \
  961. KEY(Integer, FUpdates.ShownResults); \
  962. KEY(Integer, FUpdates.BetaVersions); \
  963. KEY(Bool, FUpdates.ShowOnStartup); \
  964. KEY(String, FUpdates.AuthenticationEmail); \
  965. KEY(Integer, FUpdates.ConnectionType); \
  966. KEY(String, FUpdates.ProxyHost); \
  967. KEY(Integer, FUpdates.ProxyPort); \
  968. KEY(Integer, FUpdates.Results.ForVersion); \
  969. KEY(Integer, FUpdates.Results.Version); \
  970. KEY(String, FUpdates.Results.Message); \
  971. KEY(Integer, FUpdates.Results.Critical); \
  972. KEY(String, FUpdates.Results.Release); \
  973. KEY(Bool, FUpdates.Results.Disabled); \
  974. KEY(String, FUpdates.Results.Url); \
  975. KEY(String, FUpdates.Results.UrlButton); \
  976. KEY(String, FUpdates.Results.NewsUrl); \
  977. KEYEX(Integer,FUpdates.Results.NewsSize.Width, L"NewsWidth"); \
  978. KEYEX(Integer,FUpdates.Results.NewsSize.Height, L"NewsHeight"); \
  979. KEY(String, FUpdates.Results.DownloadUrl); \
  980. KEY(Int64, FUpdates.Results.DownloadSize); \
  981. KEY(String, FUpdates.Results.DownloadSha256); \
  982. KEY(String, FUpdates.Results.AuthenticationError); \
  983. KEY(Bool, FUpdates.Results.OpenGettingStarted); \
  984. KEY(String, FUpdates.Results.DownloadingUrl); \
  985. KEYEX(Integer,FUpdates.Results.TipsSize.Width, L"TipsWidth"); \
  986. KEYEX(Integer,FUpdates.Results.TipsSize.Height, L"TipsHeight"); \
  987. KEY(String, FUpdates.Results.TipsUrl); \
  988. KEY(String, FUpdates.Results.Tips); \
  989. KEY(Integer, FUpdates.Results.TipsIntervalDays); \
  990. KEY(Integer, FUpdates.Results.TipsIntervalRuns); \
  991. KEY(String, FUpdates.DotNetVersion); \
  992. KEY(String, FUpdates.ConsoleVersion); \
  993. ); \
  994. BLOCK(L"Interface\\Explorer", CANCREATE, \
  995. KEY(String, ScpExplorer.ToolbarsLayout); \
  996. KEY(String, ScpExplorer.DirViewParams); \
  997. KEY(String, ScpExplorer.LastLocalTargetDirectory); \
  998. KEY(Bool, ScpExplorer.SessionsTabs); \
  999. KEY(Bool, ScpExplorer.StatusBar); \
  1000. KEY(String, ScpExplorer.WindowParams); \
  1001. KEY(Integer, ScpExplorer.ViewStyle); \
  1002. KEY(Bool, ScpExplorer.ShowFullAddress); \
  1003. KEY(Bool, ScpExplorer.DriveView); \
  1004. KEY(Integer, ScpExplorer.DriveViewWidth); \
  1005. KEY(Integer, ScpExplorer.DriveViewWidthPixelsPerInch); \
  1006. ); \
  1007. BLOCK(L"Interface\\Commander", CANCREATE, \
  1008. KEY(String, ScpCommander.ToolbarsLayout); \
  1009. KEY(Integer, ScpCommander.CurrentPanel); \
  1010. KEY(Float, ScpCommander.LocalPanelWidth); \
  1011. KEY(Bool, ScpCommander.SwappedPanels); \
  1012. KEY(Bool, ScpCommander.SessionsTabs); \
  1013. KEY(Bool, ScpCommander.StatusBar); \
  1014. KEY(String, ScpCommander.WindowParams); \
  1015. KEYEX(Integer, ScpCommander.NortonLikeMode, L"ExplorerStyleSelection"); \
  1016. KEY(Bool, ScpCommander.PreserveLocalDirectory); \
  1017. KEY(Bool, ScpCommander.CompareByTime); \
  1018. KEY(Bool, ScpCommander.CompareBySize); \
  1019. KEY(Bool, ScpCommander.TreeOnLeft); \
  1020. KEY(Bool, ScpCommander.ExplorerKeyboardShortcuts); \
  1021. KEY(Bool, ScpCommander.SystemContextMenu); \
  1022. ); \
  1023. BLOCK(L"Interface\\Commander\\LocalPanel", CANCREATE, \
  1024. KEY(String, ScpCommander.LocalPanel.DirViewParams); \
  1025. KEY(Bool, ScpCommander.LocalPanel.StatusBar); \
  1026. KEY(Bool, ScpCommander.LocalPanel.DriveView); \
  1027. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeight); \
  1028. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeightPixelsPerInch); \
  1029. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidth); \
  1030. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidthPixelsPerInch); \
  1031. ); \
  1032. BLOCK(L"Interface\\Commander\\RemotePanel", CANCREATE, \
  1033. KEY(String, ScpCommander.RemotePanel.DirViewParams); \
  1034. KEY(Bool, ScpCommander.RemotePanel.StatusBar); \
  1035. KEY(Bool, ScpCommander.RemotePanel.DriveView); \
  1036. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeight); \
  1037. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeightPixelsPerInch); \
  1038. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidth); \
  1039. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidthPixelsPerInch); \
  1040. ); \
  1041. BLOCK(L"Logging", CANCREATE, \
  1042. KEY(Bool, LogWindowOnStartup); \
  1043. KEY(String, LogWindowParams); \
  1044. ); \
  1045. BLOCK(L"Security", CANCREATE, \
  1046. KEYEX(Bool, FUseMasterPassword, L"UseMasterPassword"); \
  1047. KEYEX(String,FMasterPasswordVerifier, L"MasterPasswordVerifier"); \
  1048. );
  1049. //---------------------------------------------------------------------------
  1050. void __fastcall TWinConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  1051. {
  1052. TCustomWinConfiguration::SaveData(Storage, All);
  1053. // duplicated from core\configuration.cpp
  1054. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  1055. REGCONFIG(true);
  1056. #undef KEYEX
  1057. if (Storage->OpenSubKey(L"Bookmarks", true))
  1058. {
  1059. FBookmarks->Save(Storage, All);
  1060. Storage->CloseSubKey();
  1061. }
  1062. if ((All && !FCustomCommandsDefaults) || FCustomCommandList->Modified)
  1063. {
  1064. FCustomCommandList->Save(Storage);
  1065. }
  1066. if ((All || FEditorList->Modified) &&
  1067. Storage->OpenSubKey(L"Interface\\Editor", true, true))
  1068. try
  1069. {
  1070. FEditorList->Save(Storage);
  1071. }
  1072. __finally
  1073. {
  1074. Storage->CloseSubKey();
  1075. }
  1076. }
  1077. //---------------------------------------------------------------------------
  1078. void __fastcall TWinConfiguration::LoadFrom(THierarchicalStorage * Storage)
  1079. {
  1080. FLegacyEditor = new TEditorPreferences();
  1081. try
  1082. {
  1083. FLegacyEditor->LegacyDefaults();
  1084. TCustomWinConfiguration::LoadFrom(Storage);
  1085. // This needs to be done even if there's no Configuration key in the storage,
  1086. // so it cannot be in LoadData
  1087. int EditorCount = FEditorList->Count;
  1088. if (EditorCount == 0)
  1089. {
  1090. TEditorPreferences * AlternativeEditor = NULL;
  1091. try
  1092. {
  1093. if (FLegacyEditor->Data->Editor == edInternal)
  1094. {
  1095. if (!FLegacyEditor->Data->ExternalEditor.IsEmpty())
  1096. {
  1097. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  1098. AlternativeEditor->GetData()->Editor = edExternal;
  1099. FLegacyEditor->GetData()->ExternalEditor = L"";
  1100. }
  1101. }
  1102. else
  1103. {
  1104. if (FLegacyEditor->Data->ExternalEditor.IsEmpty())
  1105. {
  1106. FLegacyEditor->GetData()->Editor = edInternal;
  1107. }
  1108. else
  1109. {
  1110. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  1111. AlternativeEditor->GetData()->Editor = edInternal;
  1112. }
  1113. }
  1114. }
  1115. catch(...)
  1116. {
  1117. delete AlternativeEditor;
  1118. throw;
  1119. }
  1120. FEditorList->Add(FLegacyEditor);
  1121. FLegacyEditor = NULL;
  1122. if (AlternativeEditor != NULL)
  1123. {
  1124. FEditorList->Add(AlternativeEditor);
  1125. }
  1126. }
  1127. }
  1128. __finally
  1129. {
  1130. delete FLegacyEditor;
  1131. FLegacyEditor = NULL;
  1132. }
  1133. if (FUpdates.ConnectionType == -1)
  1134. {
  1135. FUpdates.ConnectionType = (FUpdates.ProxyHost.IsEmpty() ? ctAuto : ctProxy);
  1136. }
  1137. AddVersionToHistory();
  1138. }
  1139. //---------------------------------------------------------------------------
  1140. void __fastcall TWinConfiguration::LoadData(THierarchicalStorage * Storage)
  1141. {
  1142. TCustomWinConfiguration::LoadData(Storage);
  1143. // duplicated from core\configuration.cpp
  1144. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  1145. #pragma warn -eas
  1146. REGCONFIG(false);
  1147. #pragma warn +eas
  1148. #undef KEYEX
  1149. // to reflect changes to PanelFont
  1150. UpdateIconFont();
  1151. if (Storage->OpenSubKey(L"Bookmarks", false))
  1152. {
  1153. FBookmarks->Load(Storage);
  1154. Storage->CloseSubKey();
  1155. }
  1156. if (Storage->HasSubKey("CustomCommands"))
  1157. {
  1158. FCustomCommandList->Load(Storage);
  1159. FCustomCommandsDefaults = false;
  1160. }
  1161. else if (FCustomCommandList->Modified)
  1162. {
  1163. // can this (=reloading of configuration) even happen?
  1164. // if it does, shouldn't we reset default commands?
  1165. DebugFail();
  1166. FCustomCommandList->Clear();
  1167. FCustomCommandsDefaults = false;
  1168. }
  1169. FCustomCommandList->Reset();
  1170. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1171. try
  1172. {
  1173. FEditorList->Clear();
  1174. FEditorList->Load(Storage);
  1175. }
  1176. __finally
  1177. {
  1178. Storage->CloseSubKey();
  1179. }
  1180. // load legacy editor configuration
  1181. DebugAssert(FLegacyEditor != NULL);
  1182. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1183. {
  1184. try
  1185. {
  1186. FLegacyEditor->Load(Storage, true);
  1187. }
  1188. __finally
  1189. {
  1190. Storage->CloseSubKey();
  1191. }
  1192. }
  1193. }
  1194. //---------------------------------------------------------------------------
  1195. void __fastcall TWinConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  1196. {
  1197. TCustomWinConfiguration::LoadAdmin(Storage);
  1198. FDisableOpenEdit = Storage->ReadBool(L"DisableOpenEdit", FDisableOpenEdit);
  1199. FDefaultUpdatesPeriod = Storage->ReadInteger(L"DefaultUpdatesPeriod", FDefaultUpdatesPeriod);
  1200. FMachineInstallations = Storage->ReadInteger(L"Installations", 0);
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TWinConfiguration::CopyData(THierarchicalStorage * Source, THierarchicalStorage * Target)
  1204. {
  1205. TCustomWinConfiguration::CopyData(Source, Target);
  1206. if (Source->OpenSubKey(ConfigurationSubKey, false))
  1207. {
  1208. if (Target->OpenSubKey(ConfigurationSubKey, true))
  1209. {
  1210. Target->WriteString(L"JumpList", Source->ReadString(L"JumpList", L""));
  1211. Target->WriteString(L"JumpListWorkspaces", Source->ReadString(L"JumpListWorkspaces", L""));
  1212. Target->CloseSubKey();
  1213. }
  1214. Source->CloseSubKey();
  1215. }
  1216. }
  1217. //---------------------------------------------------------------------------
  1218. void __fastcall TWinConfiguration::ClearTemporaryLoginData()
  1219. {
  1220. if (!FTemporaryKeyFile.IsEmpty())
  1221. {
  1222. DeleteFile(ApiPath(FTemporaryKeyFile));
  1223. FTemporaryKeyFile = L"";
  1224. }
  1225. }
  1226. //---------------------------------------------------------------------------
  1227. void __fastcall TWinConfiguration::AddVersionToHistory()
  1228. {
  1229. int CurrentVersion = CompoundVersion;
  1230. int From = 1;
  1231. bool CurrentVersionPresent = false;
  1232. while (!CurrentVersionPresent && (From < FVersionHistory.Length()))
  1233. {
  1234. UnicodeString VersionInfo = CopyToChars(FVersionHistory, From, L";", true);
  1235. UnicodeString VersionStr = CutToChar(VersionInfo, L',', true);
  1236. int Version;
  1237. if (TryStrToInt(VersionStr, Version) &&
  1238. (Version == CurrentVersion))
  1239. {
  1240. CurrentVersionPresent = true;
  1241. }
  1242. }
  1243. if (!CurrentVersionPresent)
  1244. {
  1245. UnicodeString CurrentVersionInfo =
  1246. IntToStr(CurrentVersion) + L"," + GetReleaseType();
  1247. AddToList(FVersionHistory, CurrentVersionInfo, L';');
  1248. }
  1249. Usage->Set(L"AnyBetaUsed", AnyBetaInVersionHistory);
  1250. }
  1251. //---------------------------------------------------------------------------
  1252. bool __fastcall TWinConfiguration::DoIsBeta(const UnicodeString & ReleaseType)
  1253. {
  1254. // What about "Development" release type?
  1255. return AnsiSameText(ReleaseType, L"beta") || AnsiSameText(ReleaseType, L"rc");
  1256. }
  1257. //---------------------------------------------------------------------------
  1258. bool __fastcall TWinConfiguration::GetIsBeta()
  1259. {
  1260. return DoIsBeta(GetReleaseType());
  1261. }
  1262. //---------------------------------------------------------------------------
  1263. TFont * __fastcall TWinConfiguration::GetSystemIconFont()
  1264. {
  1265. // We should do live update from Screen->IconFont when custom panel font is not set
  1266. return FSystemIconFont.get();
  1267. }
  1268. //---------------------------------------------------------------------------
  1269. bool __fastcall TWinConfiguration::GetAnyBetaInVersionHistory()
  1270. {
  1271. int From = 1;
  1272. bool AnyBeta = false;
  1273. while (!AnyBeta && (From < VersionHistory.Length()))
  1274. {
  1275. UnicodeString VersionInfo = CopyToChars(VersionHistory, From, L";", true);
  1276. CutToChar(VersionInfo, L',', true);
  1277. UnicodeString ReleaseType = CutToChar(VersionInfo, ',', true);
  1278. if (DoIsBeta(ReleaseType))
  1279. {
  1280. AnyBeta = true;
  1281. }
  1282. }
  1283. return AnyBeta;
  1284. }
  1285. //---------------------------------------------------------------------------
  1286. bool __fastcall TWinConfiguration::GetDDExtInstalled()
  1287. {
  1288. if (FDDExtInstalled < 0)
  1289. {
  1290. if (IsWin64())
  1291. {
  1292. // WORKAROUND
  1293. // We cannot load 64-bit COM class into 32-bit process,
  1294. // so we fallback to querying registration keys
  1295. #define CLSID_SIZE 39
  1296. wchar_t ClassID[CLSID_SIZE];
  1297. StringFromGUID2(CLSID_ShellExtension, ClassID, LENOF(ClassID));
  1298. NULL_TERMINATE(ClassID);
  1299. UnicodeString SubKey = UnicodeString(L"CLSID\\") + ClassID;
  1300. HKEY HKey;
  1301. LONG Result = RegOpenKeyEx(HKEY_CLASSES_ROOT, SubKey.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &HKey);
  1302. if (Result == ERROR_SUCCESS)
  1303. {
  1304. RegCloseKey(HKey);
  1305. FDDExtInstalled = 1;
  1306. }
  1307. else
  1308. {
  1309. FDDExtInstalled = 0;
  1310. }
  1311. }
  1312. else
  1313. {
  1314. void * DragExtRef;
  1315. int CreateResult =
  1316. CoCreateInstance(CLSID_ShellExtension, NULL,
  1317. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
  1318. &DragExtRef);
  1319. bool Result = (CreateResult == S_OK);
  1320. FDDExtInstalled = (Result ? 1 : 0);
  1321. if (Result)
  1322. {
  1323. reinterpret_cast<IUnknown *>(DragExtRef)->Release();
  1324. CoFreeUnusedLibraries();
  1325. }
  1326. }
  1327. }
  1328. return (FDDExtInstalled > 0);
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. RawByteString __fastcall TWinConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString Key)
  1332. {
  1333. RawByteString Dummy;
  1334. RawByteString Result;
  1335. if (GetExternalEncryptedPassword(Password, Dummy) ||
  1336. !FUseMasterPassword)
  1337. {
  1338. // already-strongly encrypted
  1339. // or no master password set, so we cannot strongly-encrypt it
  1340. Result = Password;
  1341. }
  1342. else
  1343. {
  1344. UnicodeString PasswordText =
  1345. TCustomWinConfiguration::DecryptPassword(Password, Key);
  1346. if (!PasswordText.IsEmpty())
  1347. {
  1348. // can be not set for instance, when editing=>saving site with no prior password
  1349. AskForMasterPasswordIfNotSet();
  1350. Password = ScramblePassword(PasswordText);
  1351. AES256EncyptWithMAC(Password, FPlainMasterPasswordEncrypt, Result);
  1352. Result = SetExternalEncryptedPassword(Result);
  1353. }
  1354. }
  1355. return Result;
  1356. }
  1357. //---------------------------------------------------------------------------
  1358. UnicodeString __fastcall TWinConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
  1359. {
  1360. UnicodeString Result;
  1361. RawByteString Buf;
  1362. if (GetExternalEncryptedPassword(Password, Buf))
  1363. {
  1364. if (FDontDecryptPasswords == 0)
  1365. {
  1366. // As opposite to AskForMasterPasswordIfNotSet, we test here
  1367. // for decrypt password. This is important while recrypting password,
  1368. // when clearing master password, when encrypt password is already empty.
  1369. if (FPlainMasterPasswordDecrypt.IsEmpty())
  1370. {
  1371. AskForMasterPassword();
  1372. }
  1373. if (!AES256DecryptWithMAC(Buf, FPlainMasterPasswordDecrypt, Buf) ||
  1374. !UnscramblePassword(Buf, Result))
  1375. {
  1376. throw Exception(LoadStr(DECRYPT_PASSWORD_ERROR));
  1377. }
  1378. }
  1379. else
  1380. {
  1381. Abort();
  1382. }
  1383. }
  1384. else
  1385. {
  1386. Result = TCustomWinConfiguration::DecryptPassword(Password, Key);
  1387. }
  1388. return Result;
  1389. }
  1390. //---------------------------------------------------------------------------
  1391. void __fastcall TWinConfiguration::SetMasterPassword(UnicodeString value)
  1392. {
  1393. // just stores the plain-text version of the password
  1394. // we can get here even if master password is off,
  1395. // when we encounter stray encrypted password (e.g. manually imported site),
  1396. // make sure we do not set encrypt password to avoid starting encrypting
  1397. // new passwords
  1398. // (this is bit of edge case, not really well tested)
  1399. if (!FUseMasterPassword)
  1400. {
  1401. FPlainMasterPasswordDecrypt = value;
  1402. }
  1403. else if (DebugAlwaysTrue(FUseMasterPassword) &&
  1404. DebugAlwaysTrue(ValidateMasterPassword(value)))
  1405. {
  1406. FPlainMasterPasswordEncrypt = value;
  1407. FPlainMasterPasswordDecrypt = value;
  1408. }
  1409. }
  1410. //---------------------------------------------------------------------------
  1411. void __fastcall TWinConfiguration::ChangeMasterPassword(
  1412. UnicodeString value, TStrings * RecryptPasswordErrors)
  1413. {
  1414. RawByteString Verifier;
  1415. AES256CreateVerifier(value, Verifier);
  1416. FMasterPasswordVerifier = BytesToHex(Verifier);
  1417. FPlainMasterPasswordEncrypt = value;
  1418. FUseMasterPassword = true;
  1419. try
  1420. {
  1421. RecryptPasswords(RecryptPasswordErrors);
  1422. }
  1423. __finally
  1424. {
  1425. FPlainMasterPasswordDecrypt = value;
  1426. }
  1427. }
  1428. //---------------------------------------------------------------------------
  1429. bool __fastcall TWinConfiguration::ValidateMasterPassword(UnicodeString value)
  1430. {
  1431. DebugAssert(UseMasterPassword);
  1432. DebugAssert(!FMasterPasswordVerifier.IsEmpty());
  1433. bool Result = AES256Verify(value, HexToBytes(FMasterPasswordVerifier));
  1434. return Result;
  1435. }
  1436. //---------------------------------------------------------------------------
  1437. void __fastcall TWinConfiguration::ClearMasterPassword(TStrings * RecryptPasswordErrors)
  1438. {
  1439. FMasterPasswordVerifier = L"";
  1440. FUseMasterPassword = false;
  1441. Shred(FPlainMasterPasswordEncrypt);
  1442. try
  1443. {
  1444. RecryptPasswords(RecryptPasswordErrors);
  1445. }
  1446. __finally
  1447. {
  1448. Shred(FPlainMasterPasswordDecrypt);
  1449. }
  1450. }
  1451. //---------------------------------------------------------------------------
  1452. void __fastcall TWinConfiguration::AskForMasterPassword()
  1453. {
  1454. if (FMasterPasswordSession > 0)
  1455. {
  1456. if (FMasterPasswordSessionAsked)
  1457. {
  1458. Abort();
  1459. }
  1460. // set before call to OnMasterPasswordPrompt as it may abort
  1461. FMasterPasswordSessionAsked = true;
  1462. }
  1463. if (FOnMasterPasswordPrompt == NULL)
  1464. {
  1465. throw Exception(L"Master password handler not set");
  1466. }
  1467. else
  1468. {
  1469. FOnMasterPasswordPrompt();
  1470. DebugAssert(!FPlainMasterPasswordDecrypt.IsEmpty());
  1471. }
  1472. }
  1473. //---------------------------------------------------------------------------
  1474. void __fastcall TWinConfiguration::AskForMasterPasswordIfNotSet()
  1475. {
  1476. if (FPlainMasterPasswordEncrypt.IsEmpty())
  1477. {
  1478. AskForMasterPassword();
  1479. }
  1480. }
  1481. //---------------------------------------------------------------------------
  1482. void __fastcall TWinConfiguration::BeginMasterPasswordSession()
  1483. {
  1484. // We do not expect nesting
  1485. DebugAssert(FMasterPasswordSession == 0);
  1486. DebugAssert(!FMasterPasswordSessionAsked || (FMasterPasswordSession > 0));
  1487. // This should better be thread-specific
  1488. FMasterPasswordSession++;
  1489. }
  1490. //---------------------------------------------------------------------------
  1491. void __fastcall TWinConfiguration::EndMasterPasswordSession()
  1492. {
  1493. if (DebugAlwaysTrue(FMasterPasswordSession > 0))
  1494. {
  1495. FMasterPasswordSession--;
  1496. }
  1497. FMasterPasswordSessionAsked = false;
  1498. }
  1499. //---------------------------------------------------------------------------
  1500. void __fastcall TWinConfiguration::SetLogWindowOnStartup(bool value)
  1501. {
  1502. SET_CONFIG_PROPERTY(LogWindowOnStartup);
  1503. }
  1504. //---------------------------------------------------------------------------
  1505. void __fastcall TWinConfiguration::SetLogWindowParams(UnicodeString value)
  1506. {
  1507. SET_CONFIG_PROPERTY(LogWindowParams);
  1508. }
  1509. //---------------------------------------------------------------------------
  1510. void __fastcall TWinConfiguration::SetDDAllowMove(bool value)
  1511. {
  1512. SET_CONFIG_PROPERTY(DDAllowMove);
  1513. }
  1514. //---------------------------------------------------------------------------
  1515. void __fastcall TWinConfiguration::SetDDAllowMoveInit(bool value)
  1516. {
  1517. SET_CONFIG_PROPERTY(DDAllowMoveInit);
  1518. }
  1519. //---------------------------------------------------------------------------
  1520. void __fastcall TWinConfiguration::SetDDTransferConfirmation(TAutoSwitch value)
  1521. {
  1522. SET_CONFIG_PROPERTY(DDTransferConfirmation);
  1523. }
  1524. //---------------------------------------------------------------------------
  1525. void __fastcall TWinConfiguration::SetDDTemporaryDirectory(UnicodeString value)
  1526. {
  1527. SET_CONFIG_PROPERTY(DDTemporaryDirectory);
  1528. }
  1529. //---------------------------------------------------------------------------
  1530. void __fastcall TWinConfiguration::SetDDExtEnabled(bool value)
  1531. {
  1532. SET_CONFIG_PROPERTY(DDExtEnabled);
  1533. }
  1534. //---------------------------------------------------------------------------
  1535. void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
  1536. {
  1537. SET_CONFIG_PROPERTY(DDExtTimeout);
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpace(bool value)
  1541. {
  1542. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpace);
  1543. }
  1544. //---------------------------------------------------------------------------
  1545. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpaceRatio(double value)
  1546. {
  1547. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpaceRatio);
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. void __fastcall TWinConfiguration::SetScpExplorer(TScpExplorerConfiguration value)
  1551. {
  1552. SET_CONFIG_PROPERTY(ScpExplorer);
  1553. }
  1554. //---------------------------------------------------------------------------
  1555. void __fastcall TWinConfiguration::SetScpCommander(TScpCommanderConfiguration value)
  1556. {
  1557. SET_CONFIG_PROPERTY(ScpCommander);
  1558. }
  1559. //---------------------------------------------------------------------------
  1560. void __fastcall TWinConfiguration::SetEditor(TEditorConfiguration value)
  1561. {
  1562. SET_CONFIG_PROPERTY(Editor);
  1563. }
  1564. //---------------------------------------------------------------------------
  1565. void __fastcall TWinConfiguration::SetQueueView(TQueueViewConfiguration value)
  1566. {
  1567. SET_CONFIG_PROPERTY(QueueView);
  1568. }
  1569. //---------------------------------------------------------------------------
  1570. void __fastcall TWinConfiguration::SetEnableQueueByDefault(bool value)
  1571. {
  1572. SET_CONFIG_PROPERTY(EnableQueueByDefault);
  1573. }
  1574. //---------------------------------------------------------------------------
  1575. TUpdatesConfiguration __fastcall TWinConfiguration::GetUpdates()
  1576. {
  1577. TUpdatesConfiguration Result;
  1578. {
  1579. TGuard Guard(FCriticalSection);
  1580. Result = FUpdates;
  1581. }
  1582. return Result;
  1583. }
  1584. //---------------------------------------------------------------------------
  1585. void __fastcall TWinConfiguration::SetUpdates(TUpdatesConfiguration value)
  1586. {
  1587. TGuard Guard(FCriticalSection);
  1588. // do not use SET_CONFIG_PROPERTY to avoid OnChange handler call (not synchronized)
  1589. FUpdates = value;
  1590. }
  1591. //---------------------------------------------------------------------------
  1592. void __fastcall TWinConfiguration::SetVersionHistory(UnicodeString value)
  1593. {
  1594. SET_CONFIG_PROPERTY(VersionHistory);
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. void __fastcall TWinConfiguration::SetDeleteToRecycleBin(bool value)
  1598. {
  1599. SET_CONFIG_PROPERTY(DeleteToRecycleBin);
  1600. }
  1601. //---------------------------------------------------------------------------
  1602. void __fastcall TWinConfiguration::SetSelectDirectories(bool value)
  1603. {
  1604. SET_CONFIG_PROPERTY(SelectDirectories);
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. void __fastcall TWinConfiguration::SetShowHiddenFiles(bool value)
  1608. {
  1609. SET_CONFIG_PROPERTY(ShowHiddenFiles);
  1610. }
  1611. //---------------------------------------------------------------------------
  1612. void __fastcall TWinConfiguration::SetFormatSizeBytes(TFormatBytesStyle value)
  1613. {
  1614. SET_CONFIG_PROPERTY(FormatSizeBytes);
  1615. }
  1616. //---------------------------------------------------------------------------
  1617. void __fastcall TWinConfiguration::SetShowInaccesibleDirectories(bool value)
  1618. {
  1619. SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
  1620. }
  1621. //---------------------------------------------------------------------------
  1622. void __fastcall TWinConfiguration::SetConfirmTransferring(bool value)
  1623. {
  1624. SET_CONFIG_PROPERTY(ConfirmTransferring);
  1625. }
  1626. //---------------------------------------------------------------------------
  1627. void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
  1628. {
  1629. SET_CONFIG_PROPERTY(ConfirmDeleting);
  1630. }
  1631. //---------------------------------------------------------------------------
  1632. void __fastcall TWinConfiguration::SetConfirmRecycling(bool value)
  1633. {
  1634. SET_CONFIG_PROPERTY(ConfirmRecycling);
  1635. }
  1636. //---------------------------------------------------------------------------
  1637. void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
  1638. {
  1639. SET_CONFIG_PROPERTY(UseLocationProfiles);
  1640. }
  1641. //---------------------------------------------------------------------------
  1642. void __fastcall TWinConfiguration::SetUseSharedBookmarks(bool value)
  1643. {
  1644. SET_CONFIG_PROPERTY(UseSharedBookmarks);
  1645. }
  1646. //---------------------------------------------------------------------------
  1647. void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
  1648. {
  1649. SET_CONFIG_PROPERTY(ConfirmClosingSession);
  1650. }
  1651. //---------------------------------------------------------------------------
  1652. void __fastcall TWinConfiguration::SetDoubleClickAction(TDoubleClickAction value)
  1653. {
  1654. SET_CONFIG_PROPERTY(DoubleClickAction);
  1655. }
  1656. //---------------------------------------------------------------------------
  1657. void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
  1658. {
  1659. SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
  1660. }
  1661. //---------------------------------------------------------------------------
  1662. void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
  1663. {
  1664. SET_CONFIG_PROPERTY(DimmHiddenFiles);
  1665. }
  1666. //---------------------------------------------------------------------------
  1667. void __fastcall TWinConfiguration::SetRenameWholeName(bool value)
  1668. {
  1669. SET_CONFIG_PROPERTY(RenameWholeName);
  1670. }
  1671. //---------------------------------------------------------------------------
  1672. void __fastcall TWinConfiguration::SetAutoStartSession(UnicodeString value)
  1673. {
  1674. SET_CONFIG_PROPERTY(AutoStartSession);
  1675. }
  1676. //---------------------------------------------------------------------------
  1677. void __fastcall TWinConfiguration::SetExpertMode(bool value)
  1678. {
  1679. SET_CONFIG_PROPERTY(ExpertMode);
  1680. }
  1681. //---------------------------------------------------------------------------
  1682. void __fastcall TWinConfiguration::SetDefaultDirIsHome(bool value)
  1683. {
  1684. SET_CONFIG_PROPERTY(DefaultDirIsHome);
  1685. }
  1686. //---------------------------------------------------------------------------
  1687. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendSession(bool value)
  1688. {
  1689. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendSession);
  1690. }
  1691. //---------------------------------------------------------------------------
  1692. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendPath(bool value)
  1693. {
  1694. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendPath);
  1695. }
  1696. //---------------------------------------------------------------------------
  1697. void __fastcall TWinConfiguration::SetTemporaryDirectoryDeterministic(bool value)
  1698. {
  1699. SET_CONFIG_PROPERTY(TemporaryDirectoryDeterministic);
  1700. }
  1701. //---------------------------------------------------------------------------
  1702. void __fastcall TWinConfiguration::SetTemporaryDirectoryCleanup(bool value)
  1703. {
  1704. SET_CONFIG_PROPERTY(TemporaryDirectoryCleanup);
  1705. }
  1706. //---------------------------------------------------------------------------
  1707. void __fastcall TWinConfiguration::SetConfirmTemporaryDirectoryCleanup(bool value)
  1708. {
  1709. SET_CONFIG_PROPERTY(ConfirmTemporaryDirectoryCleanup);
  1710. }
  1711. //---------------------------------------------------------------------------
  1712. void __fastcall TWinConfiguration::SetPreservePanelState(bool value)
  1713. {
  1714. SET_CONFIG_PROPERTY(PreservePanelState);
  1715. }
  1716. //---------------------------------------------------------------------------
  1717. void __fastcall TWinConfiguration::SetLastStoredSession(UnicodeString value)
  1718. {
  1719. SET_CONFIG_PROPERTY(LastStoredSession);
  1720. }
  1721. //---------------------------------------------------------------------------
  1722. void __fastcall TWinConfiguration::SetAutoSaveWorkspace(bool value)
  1723. {
  1724. SET_CONFIG_PROPERTY(AutoSaveWorkspace);
  1725. }
  1726. //---------------------------------------------------------------------------
  1727. void __fastcall TWinConfiguration::SetAutoSaveWorkspacePasswords(bool value)
  1728. {
  1729. SET_CONFIG_PROPERTY(AutoSaveWorkspacePasswords);
  1730. }
  1731. //---------------------------------------------------------------------------
  1732. void __fastcall TWinConfiguration::SetAutoWorkspace(UnicodeString value)
  1733. {
  1734. SET_CONFIG_PROPERTY(AutoWorkspace);
  1735. }
  1736. //---------------------------------------------------------------------------
  1737. void __fastcall TWinConfiguration::SetPathInCaption(TPathInCaption value)
  1738. {
  1739. SET_CONFIG_PROPERTY(PathInCaption);
  1740. }
  1741. //---------------------------------------------------------------------------
  1742. void __fastcall TWinConfiguration::SetMinimizeToTray(bool value)
  1743. {
  1744. SET_CONFIG_PROPERTY(MinimizeToTray);
  1745. }
  1746. //---------------------------------------------------------------------------
  1747. void __fastcall TWinConfiguration::MinimizeToTrayOnce()
  1748. {
  1749. FMinimizeToTrayOnce = true;
  1750. }
  1751. //---------------------------------------------------------------------------
  1752. bool __fastcall TWinConfiguration::GetMinimizeToTray()
  1753. {
  1754. bool Result = FMinimizeToTrayOnce || FMinimizeToTray;
  1755. FMinimizeToTrayOnce = false;
  1756. return Result;
  1757. }
  1758. //---------------------------------------------------------------------------
  1759. void __fastcall TWinConfiguration::SetBalloonNotifications(bool value)
  1760. {
  1761. SET_CONFIG_PROPERTY(BalloonNotifications);
  1762. }
  1763. //---------------------------------------------------------------------------
  1764. void __fastcall TWinConfiguration::SetNotificationsTimeout(unsigned int value)
  1765. {
  1766. SET_CONFIG_PROPERTY(NotificationsTimeout);
  1767. }
  1768. //---------------------------------------------------------------------------
  1769. void __fastcall TWinConfiguration::SetNotificationsStickTime(unsigned int value)
  1770. {
  1771. SET_CONFIG_PROPERTY(NotificationsStickTime);
  1772. }
  1773. //---------------------------------------------------------------------------
  1774. void __fastcall TWinConfiguration::SetCopyParamAutoSelectNotice(bool value)
  1775. {
  1776. SET_CONFIG_PROPERTY(CopyParamAutoSelectNotice);
  1777. }
  1778. //---------------------------------------------------------------------------
  1779. void __fastcall TWinConfiguration::SetLockToolbars(bool value)
  1780. {
  1781. SET_CONFIG_PROPERTY(LockToolbars);
  1782. }
  1783. //---------------------------------------------------------------------------
  1784. void __fastcall TWinConfiguration::SetSelectiveToolbarText(bool value)
  1785. {
  1786. SET_CONFIG_PROPERTY(SelectiveToolbarText);
  1787. }
  1788. //---------------------------------------------------------------------------
  1789. void __fastcall TWinConfiguration::SetAutoOpenInPutty(bool value)
  1790. {
  1791. SET_CONFIG_PROPERTY(AutoOpenInPutty);
  1792. }
  1793. //---------------------------------------------------------------------------
  1794. void __fastcall TWinConfiguration::SetRefreshRemotePanel(bool value)
  1795. {
  1796. SET_CONFIG_PROPERTY(RefreshRemotePanel);
  1797. }
  1798. //---------------------------------------------------------------------------
  1799. void __fastcall TWinConfiguration::SetRefreshRemotePanelInterval(TDateTime value)
  1800. {
  1801. SET_CONFIG_PROPERTY(RefreshRemotePanelInterval);
  1802. }
  1803. //---------------------------------------------------------------------------
  1804. void __fastcall TWinConfiguration::UpdateSystemIconFont()
  1805. {
  1806. FSystemIconFont->Assign(Screen->IconFont);
  1807. }
  1808. //---------------------------------------------------------------------------
  1809. void __fastcall TWinConfiguration::UpdateIconFont()
  1810. {
  1811. if (!PanelFont.FontName.IsEmpty())
  1812. {
  1813. UpdateSystemIconFont();
  1814. std::unique_ptr<TFont> IconFont(new TFont());
  1815. RestoreFont(PanelFont, IconFont.get());
  1816. Screen->IconFont->Assign(IconFont.get());
  1817. // When using non-standard icon font, prevent resetting it back
  1818. // to standard one on WM_WININICHANGE. Unfortunatelly this prevents
  1819. // updating all other fonts.
  1820. Application->UpdateMetricSettings = false;
  1821. }
  1822. else
  1823. {
  1824. if (DebugAlwaysTrue(FSystemIconFont.get() != NULL) &&
  1825. !SameFont(Screen->IconFont, FSystemIconFont.get()))
  1826. {
  1827. Screen->IconFont->Assign(FSystemIconFont.get());
  1828. }
  1829. Application->UpdateMetricSettings = true;
  1830. }
  1831. }
  1832. //---------------------------------------------------------------------------
  1833. void __fastcall TWinConfiguration::SetPanelFont(const TFontConfiguration & value)
  1834. {
  1835. SET_CONFIG_PROPERTY_EX(PanelFont, UpdateIconFont());
  1836. }
  1837. //---------------------------------------------------------------------------
  1838. void __fastcall TWinConfiguration::SetFullRowSelect(bool value)
  1839. {
  1840. SET_CONFIG_PROPERTY(FullRowSelect);
  1841. }
  1842. //---------------------------------------------------------------------------
  1843. void __fastcall TWinConfiguration::SetOfferedEditorAutoConfig(bool value)
  1844. {
  1845. SET_CONFIG_PROPERTY(OfferedEditorAutoConfig);
  1846. }
  1847. //---------------------------------------------------------------------------
  1848. void __fastcall TWinConfiguration::SetOpenedStoredSessionFolders(UnicodeString value)
  1849. {
  1850. SET_CONFIG_PROPERTY(OpenedStoredSessionFolders);
  1851. }
  1852. //---------------------------------------------------------------------------
  1853. void __fastcall TWinConfiguration::SetAutoImportedFromPuttyOrFilezilla(bool value)
  1854. {
  1855. SET_CONFIG_PROPERTY(AutoImportedFromPuttyOrFilezilla);
  1856. }
  1857. //---------------------------------------------------------------------------
  1858. void __fastcall TWinConfiguration::SetGenerateUrlComponents(int value)
  1859. {
  1860. SET_CONFIG_PROPERTY(GenerateUrlComponents);
  1861. }
  1862. //---------------------------------------------------------------------------
  1863. void __fastcall TWinConfiguration::SetGenerateUrlCodeTarget(TGenerateUrlCodeTarget value)
  1864. {
  1865. SET_CONFIG_PROPERTY(GenerateUrlCodeTarget);
  1866. }
  1867. //---------------------------------------------------------------------------
  1868. void __fastcall TWinConfiguration::SetGenerateUrlScriptFormat(TScriptFormat value)
  1869. {
  1870. SET_CONFIG_PROPERTY(GenerateUrlScriptFormat);
  1871. }
  1872. //---------------------------------------------------------------------------
  1873. void __fastcall TWinConfiguration::SetGenerateUrlAssemblyLanguage(TAssemblyLanguage value)
  1874. {
  1875. SET_CONFIG_PROPERTY(GenerateUrlAssemblyLanguage);
  1876. }
  1877. //---------------------------------------------------------------------------
  1878. void __fastcall TWinConfiguration::SetExternalSessionInExistingInstance(bool value)
  1879. {
  1880. SET_CONFIG_PROPERTY(ExternalSessionInExistingInstance);
  1881. }
  1882. //---------------------------------------------------------------------------
  1883. void __fastcall TWinConfiguration::SetKeepOpenWhenNoSession(bool value)
  1884. {
  1885. SET_CONFIG_PROPERTY(KeepOpenWhenNoSession);
  1886. }
  1887. //---------------------------------------------------------------------------
  1888. void __fastcall TWinConfiguration::SetLocalIconsByExt(bool value)
  1889. {
  1890. SET_CONFIG_PROPERTY(LocalIconsByExt);
  1891. }
  1892. //---------------------------------------------------------------------------
  1893. void __fastcall TWinConfiguration::SetBidiModeOverride(TLocaleFlagOverride value)
  1894. {
  1895. SET_CONFIG_PROPERTY(BidiModeOverride);
  1896. }
  1897. //---------------------------------------------------------------------------
  1898. void __fastcall TWinConfiguration::SetFlipChildrenOverride(TLocaleFlagOverride value)
  1899. {
  1900. SET_CONFIG_PROPERTY(FlipChildrenOverride);
  1901. }
  1902. //---------------------------------------------------------------------------
  1903. void __fastcall TWinConfiguration::SetShowTips(bool value)
  1904. {
  1905. SET_CONFIG_PROPERTY(ShowTips);
  1906. }
  1907. //---------------------------------------------------------------------------
  1908. void __fastcall TWinConfiguration::SetTipsSeen(UnicodeString value)
  1909. {
  1910. SET_CONFIG_PROPERTY(TipsSeen);
  1911. }
  1912. //---------------------------------------------------------------------------
  1913. void __fastcall TWinConfiguration::SetTipsShown(TDateTime value)
  1914. {
  1915. SET_CONFIG_PROPERTY(TipsShown);
  1916. }
  1917. //---------------------------------------------------------------------------
  1918. void __fastcall TWinConfiguration::SetRunsSinceLastTip(int value)
  1919. {
  1920. SET_CONFIG_PROPERTY(RunsSinceLastTip);
  1921. }
  1922. //---------------------------------------------------------------------------
  1923. bool __fastcall TWinConfiguration::GetHonorDrivePolicy()
  1924. {
  1925. return DriveInfo->HonorDrivePolicy;
  1926. }
  1927. //---------------------------------------------------------------------------
  1928. void __fastcall TWinConfiguration::SetHonorDrivePolicy(bool value)
  1929. {
  1930. if (HonorDrivePolicy != value)
  1931. {
  1932. DriveInfo->HonorDrivePolicy = value;
  1933. Changed();
  1934. }
  1935. }
  1936. //---------------------------------------------------------------------------
  1937. void __fastcall TWinConfiguration::SetCustomCommandList(TCustomCommandList * value)
  1938. {
  1939. DebugAssert(FCustomCommandList);
  1940. if (!FCustomCommandList->Equals(value))
  1941. {
  1942. FCustomCommandList->Assign(value);
  1943. FCustomCommandsDefaults = false;
  1944. }
  1945. }
  1946. //---------------------------------------------------------------------------
  1947. void __fastcall TWinConfiguration::SetBookmarks(UnicodeString Key,
  1948. TBookmarkList * value)
  1949. {
  1950. FBookmarks->Bookmarks[Key] = value;
  1951. Changed();
  1952. }
  1953. //---------------------------------------------------------------------------
  1954. TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(UnicodeString Key)
  1955. {
  1956. return FBookmarks->Bookmarks[Key];
  1957. }
  1958. //---------------------------------------------------------------------------
  1959. void __fastcall TWinConfiguration::SetSharedBookmarks(TBookmarkList * value)
  1960. {
  1961. FBookmarks->SharedBookmarks = value;
  1962. Changed();
  1963. }
  1964. //---------------------------------------------------------------------------
  1965. TBookmarkList * __fastcall TWinConfiguration::GetSharedBookmarks()
  1966. {
  1967. return FBookmarks->SharedBookmarks;
  1968. }
  1969. //---------------------------------------------------------------------------
  1970. UnicodeString __fastcall TWinConfiguration::GetDefaultKeyFile()
  1971. {
  1972. return (!FDefaultKeyFile.IsEmpty() ? FDefaultKeyFile : FTemporaryKeyFile);
  1973. }
  1974. //---------------------------------------------------------------------------
  1975. void __fastcall TWinConfiguration::SetLastMonitor(int value)
  1976. {
  1977. ::SetLastMonitor(value);
  1978. }
  1979. //---------------------------------------------------------------------------
  1980. int __fastcall TWinConfiguration::GetLastMonitor()
  1981. {
  1982. return ::GetLastMonitor();
  1983. }
  1984. //---------------------------------------------------------------------------
  1985. UnicodeString __fastcall TWinConfiguration::ExpandedTemporaryDirectory()
  1986. {
  1987. UnicodeString Result =
  1988. ExpandFileName(ExpandEnvironmentVariables(DDTemporaryDirectory));
  1989. if (Result.IsEmpty())
  1990. {
  1991. Result = SystemTemporaryDirectory();
  1992. }
  1993. return Result;
  1994. }
  1995. //---------------------------------------------------------------------------
  1996. UnicodeString __fastcall TWinConfiguration::TemporaryDir(bool Mask)
  1997. {
  1998. return UniqTempDir(ExpandedTemporaryDirectory(), L"scp", Mask);
  1999. }
  2000. //---------------------------------------------------------------------------
  2001. TStrings * __fastcall TWinConfiguration::FindTemporaryFolders()
  2002. {
  2003. TStrings * Result = new TStringList();
  2004. try
  2005. {
  2006. TSearchRecChecked SRec;
  2007. UnicodeString Mask = TemporaryDir(true);
  2008. UnicodeString Directory = ExtractFilePath(Mask);
  2009. if (FindFirstUnchecked(Mask, faDirectory, SRec) == 0)
  2010. {
  2011. do
  2012. {
  2013. if (FLAGSET(SRec.Attr, faDirectory))
  2014. {
  2015. Result->Add(Directory + SRec.Name);
  2016. }
  2017. }
  2018. while (FindNextChecked(SRec) == 0);
  2019. }
  2020. if (Result->Count == 0)
  2021. {
  2022. delete Result;
  2023. Result = NULL;
  2024. }
  2025. }
  2026. catch(...)
  2027. {
  2028. delete Result;
  2029. throw;
  2030. }
  2031. return Result;
  2032. }
  2033. //---------------------------------------------------------------------------
  2034. void __fastcall TWinConfiguration::CleanupTemporaryFolders(TStrings * Folders)
  2035. {
  2036. UnicodeString ErrorList;
  2037. TStrings * F;
  2038. if (Folders == NULL)
  2039. {
  2040. F = FindTemporaryFolders();
  2041. }
  2042. else
  2043. {
  2044. F = Folders;
  2045. }
  2046. if (F != NULL)
  2047. {
  2048. try
  2049. {
  2050. if (DebugAlwaysTrue(F->Count > 0))
  2051. {
  2052. Usage->Inc(L"TemporaryDirectoryCleanups");
  2053. }
  2054. for (int i = 0; i < F->Count; i++)
  2055. {
  2056. if (!DeleteDirectory(F->Strings[i]))
  2057. {
  2058. if (!ErrorList.IsEmpty())
  2059. {
  2060. ErrorList += L"\n";
  2061. }
  2062. ErrorList += F->Strings[i];
  2063. }
  2064. }
  2065. }
  2066. __finally
  2067. {
  2068. if (Folders == NULL)
  2069. {
  2070. delete F;
  2071. }
  2072. }
  2073. if (!ErrorList.IsEmpty())
  2074. {
  2075. throw ExtException(LoadStr(CLEANUP_TEMP_ERROR), ErrorList);
  2076. }
  2077. }
  2078. }
  2079. //---------------------------------------------------------------------------
  2080. LCID __fastcall TWinConfiguration::GetLocale()
  2081. {
  2082. if (!FLocale)
  2083. {
  2084. UnicodeString ResourceModule =
  2085. GetResourceModuleName(Application->Name, ModuleFileName().c_str());
  2086. if (!ResourceModule.IsEmpty())
  2087. {
  2088. UnicodeString ResourceExt = ExtractFileExt(ResourceModule).UpperCase();
  2089. ResourceExt.Delete(1, 1);
  2090. TLanguages * Langs = Languages();
  2091. int Index, Count;
  2092. Count = Langs->Count;
  2093. Index = 0;
  2094. while ((Index < Count) && (FLocale == 0))
  2095. {
  2096. if (Langs->Ext[Index] == ResourceExt)
  2097. {
  2098. SetInitialLocale(Langs->LocaleID[Index]);
  2099. }
  2100. else if (Langs->Ext[Index].SubString(1, 2) == ResourceExt)
  2101. {
  2102. SetInitialLocale(
  2103. MAKELANGID(PRIMARYLANGID(Langs->LocaleID[Index]),
  2104. SUBLANG_DEFAULT));
  2105. }
  2106. if (FLocale != 0)
  2107. {
  2108. FLocaleModuleName = ResourceModule;
  2109. }
  2110. Index++;
  2111. }
  2112. }
  2113. }
  2114. return TCustomWinConfiguration::GetLocale();
  2115. }
  2116. //---------------------------------------------------------------------------
  2117. HINSTANCE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
  2118. UnicodeString & FileName)
  2119. {
  2120. HINSTANCE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
  2121. if (Instance != NULL)
  2122. {
  2123. try
  2124. {
  2125. CheckTranslationVersion(FileName, false);
  2126. }
  2127. catch(...)
  2128. {
  2129. FreeResourceModule(Instance);
  2130. throw;
  2131. }
  2132. }
  2133. return Instance;
  2134. }
  2135. //---------------------------------------------------------------------------
  2136. void __fastcall TWinConfiguration::CheckTranslationVersion(const UnicodeString FileName,
  2137. bool InternalLocaleOnError)
  2138. {
  2139. UnicodeString TranslationProductVersion = GetFileProductVersion(FileName);
  2140. UnicodeString TranslationProductName = GetFileProductName(FileName);
  2141. if ((ProductName != TranslationProductName) ||
  2142. (ProductVersion != TranslationProductVersion))
  2143. {
  2144. if (InternalLocaleOnError)
  2145. {
  2146. LocaleSafe = InternalLocale();
  2147. }
  2148. if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
  2149. {
  2150. throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
  2151. }
  2152. else
  2153. {
  2154. throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
  2155. (FileName, TranslationProductName, TranslationProductVersion)));
  2156. }
  2157. }
  2158. }
  2159. //---------------------------------------------------------------------------
  2160. void __fastcall TWinConfiguration::CheckDefaultTranslation()
  2161. {
  2162. if (!FInvalidDefaultTranslationMessage.IsEmpty())
  2163. {
  2164. MoreMessageDialog(FMTLOAD(INVALID_DEFAULT_TRANSLATION,
  2165. (FInvalidDefaultTranslationMessage)), NULL, qtWarning, qaOK, HELP_NONE);
  2166. }
  2167. }
  2168. //---------------------------------------------------------------------------
  2169. const TEditorPreferences * __fastcall TWinConfiguration::DefaultEditorForFile(
  2170. const UnicodeString FileName, bool Local, const TFileMasks::TParams & MaskParams)
  2171. {
  2172. return FEditorList->Find(FileName, Local, MaskParams);
  2173. }
  2174. //---------------------------------------------------------------------------
  2175. const TEditorList * __fastcall TWinConfiguration::GetEditorList()
  2176. {
  2177. return FEditorList;
  2178. }
  2179. //---------------------------------------------------------------------------
  2180. void __fastcall TWinConfiguration::SetEditorList(const TEditorList * value)
  2181. {
  2182. if (!(*FEditorList == *value))
  2183. {
  2184. *FEditorList = *value;
  2185. Changed();
  2186. }
  2187. }
  2188. //---------------------------------------------------------------------------
  2189. TStringList * __fastcall TWinConfiguration::LoadJumpList(
  2190. THierarchicalStorage * Storage, UnicodeString Name)
  2191. {
  2192. UnicodeString JumpList = Storage->ReadString(Name, L"");
  2193. std::unique_ptr<TStringList> List(new TStringList());
  2194. List->CaseSensitive = false;
  2195. List->CommaText = JumpList;
  2196. return List.release();
  2197. }
  2198. //---------------------------------------------------------------------------
  2199. void __fastcall TWinConfiguration::SaveJumpList(
  2200. THierarchicalStorage * Storage, UnicodeString Name, TStringList * List)
  2201. {
  2202. UnicodeString JumpList = Storage->ReadString(Name, L"");
  2203. UnicodeString NewJumpList = List->CommaText;
  2204. if (NewJumpList != JumpList)
  2205. {
  2206. Storage->WriteString(Name, NewJumpList);
  2207. }
  2208. }
  2209. //---------------------------------------------------------------------------
  2210. void __fastcall TWinConfiguration::TrimJumpList(TStringList * List)
  2211. {
  2212. while (List->Count > 30)
  2213. {
  2214. List->Delete(List->Count - 1);
  2215. }
  2216. }
  2217. //---------------------------------------------------------------------------
  2218. void __fastcall TWinConfiguration::UpdateEntryInJumpList(
  2219. bool Session, const UnicodeString & Name, bool Add)
  2220. {
  2221. THierarchicalStorage * Storage = CreateConfigStorage();
  2222. try
  2223. {
  2224. FDontDecryptPasswords++;
  2225. Storage->AccessMode = smReadWrite;
  2226. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  2227. {
  2228. std::unique_ptr<TStringList> ListSessions(LoadJumpList(Storage, L"JumpList"));
  2229. std::unique_ptr<TStringList> ListWorkspaces(LoadJumpList(Storage, L"JumpListWorkspaces"));
  2230. if (!Name.IsEmpty())
  2231. {
  2232. TStringList * List = (Session ? ListSessions : ListWorkspaces).get();
  2233. int Index = List->IndexOf(Name);
  2234. if (Index >= 0)
  2235. {
  2236. List->Delete(Index);
  2237. }
  2238. if (Add)
  2239. {
  2240. List->Insert(0, Name);
  2241. }
  2242. }
  2243. TrimJumpList(ListSessions.get());
  2244. TrimJumpList(ListWorkspaces.get());
  2245. ::UpdateJumpList(ListSessions.get(), ListWorkspaces.get());
  2246. SaveJumpList(Storage, L"JumpList", ListSessions.get());
  2247. SaveJumpList(Storage, L"JumpListWorkspaces", ListWorkspaces.get());
  2248. }
  2249. }
  2250. __finally
  2251. {
  2252. FDontDecryptPasswords--;
  2253. delete Storage;
  2254. }
  2255. }
  2256. //---------------------------------------------------------------------------
  2257. void __fastcall TWinConfiguration::AddSessionToJumpList(UnicodeString SessionName)
  2258. {
  2259. UpdateEntryInJumpList(true, SessionName, true);
  2260. }
  2261. //---------------------------------------------------------------------------
  2262. void __fastcall TWinConfiguration::DeleteSessionFromJumpList(UnicodeString SessionName)
  2263. {
  2264. UpdateEntryInJumpList(true, SessionName, false);
  2265. }
  2266. //---------------------------------------------------------------------------
  2267. void __fastcall TWinConfiguration::AddWorkspaceToJumpList(UnicodeString Workspace)
  2268. {
  2269. UpdateEntryInJumpList(false, Workspace, true);
  2270. }
  2271. //---------------------------------------------------------------------------
  2272. void __fastcall TWinConfiguration::DeleteWorkspaceFromJumpList(UnicodeString Workspace)
  2273. {
  2274. UpdateEntryInJumpList(false, Workspace, false);
  2275. }
  2276. //---------------------------------------------------------------------------
  2277. void __fastcall TWinConfiguration::UpdateJumpList()
  2278. {
  2279. AddSessionToJumpList(L"");
  2280. }
  2281. //---------------------------------------------------------------------------
  2282. void __fastcall TWinConfiguration::UpdateStaticUsage()
  2283. {
  2284. // This is here because of TStoredSessionList::UpdateStaticUsage() call
  2285. // from TConfiguration::UpdateStaticUsage()
  2286. TAutoNestingCounter DontDecryptPasswordsAutoCounter(FDontDecryptPasswords);
  2287. TCustomWinConfiguration::UpdateStaticUsage();
  2288. Usage->Set(L"Beta", IsBeta);
  2289. Usage->Set(L"Interface", Interface);
  2290. Usage->Set(L"CustomCommandsCount", (FCustomCommandsDefaults ? 0 : FCustomCommandList->Count));
  2291. Usage->Set(L"UsingLocationProfiles", UseLocationProfiles);
  2292. Usage->Set(L"UsingMasterPassword", UseMasterPassword);
  2293. Usage->Set(L"UsingAutoSaveWorkspace", AutoSaveWorkspace);
  2294. Usage->Set(L"TreeVisible",
  2295. (Interface == ifExplorer) ?
  2296. ScpExplorer.DriveView :
  2297. (ScpCommander.LocalPanel.DriveView || ScpCommander.RemotePanel.DriveView));
  2298. Usage->Set(L"MinimizeToTray", MinimizeToTray);
  2299. Usage->Set(L"ShowingTips", ShowTips);
  2300. TipsUpdateStaticUsage();
  2301. Usage->Set(L"CommanderNortonLikeMode", int(ScpCommander.NortonLikeMode));
  2302. Usage->Set(L"CommanderExplorerKeyboardShortcuts", ScpCommander.ExplorerKeyboardShortcuts);
  2303. Usage->Set(L"ExplorerViewStyle", ScpExplorer.ViewStyle);
  2304. Usage->Set(L"LastMonitor", LastMonitor);
  2305. UnicodeString ExternalEditors;
  2306. for (int Index = 0; Index < EditorList->Count; Index++)
  2307. {
  2308. const TEditorPreferences * Editor = EditorList->Editors[Index];
  2309. if (Editor->Data->Editor == edExternal)
  2310. {
  2311. AddToList(ExternalEditors, Editor->ExtractExternalEditorName(), ",");
  2312. }
  2313. }
  2314. Usage->Set(L"ExternalEditors", ExternalEditors);
  2315. if (LastMachineInstallations < FMachineInstallations)
  2316. {
  2317. Usage->Inc(L"InstallationsMachine", (FMachineInstallations - LastMachineInstallations));
  2318. LastMachineInstallations = FMachineInstallations;
  2319. }
  2320. }
  2321. //---------------------------------------------------------------------------
  2322. void __fastcall TWinConfiguration::RestoreFont(
  2323. const TFontConfiguration & Configuration, TFont * Font)
  2324. {
  2325. Font->Name = Configuration.FontName;
  2326. Font->Size = Configuration.FontSize;
  2327. Font->Charset = Configuration.FontCharset;
  2328. Font->Style = IntToFontStyles(Configuration.FontStyle);
  2329. }
  2330. //---------------------------------------------------------------------------
  2331. void __fastcall TWinConfiguration::StoreFont(
  2332. TFont * Font, TFontConfiguration & Configuration)
  2333. {
  2334. Configuration.FontName = Font->Name;
  2335. Configuration.FontSize = Font->Size;
  2336. Configuration.FontCharset = Font->Charset;
  2337. Configuration.FontStyle = FontStylesToInt(Font->Style);
  2338. }
  2339. //---------------------------------------------------------------------------
  2340. //---------------------------------------------------------------------------
  2341. __fastcall TCustomCommandType::TCustomCommandType() :
  2342. FParams(0), FShortCut(0)
  2343. {
  2344. }
  2345. //---------------------------------------------------------------------------
  2346. __fastcall TCustomCommandType::TCustomCommandType(const TCustomCommandType & Other) :
  2347. FName(Other.FName),
  2348. FCommand(Other.FCommand),
  2349. FParams(Other.FParams),
  2350. FShortCut(Other.FShortCut)
  2351. {
  2352. }
  2353. //---------------------------------------------------------------------------
  2354. TCustomCommandType & TCustomCommandType::operator=(const TCustomCommandType & Other)
  2355. {
  2356. FName = Other.FName;
  2357. FCommand = Other.FCommand;
  2358. FParams = Other.FParams;
  2359. FShortCut = Other.FShortCut;
  2360. return *this;
  2361. }
  2362. //---------------------------------------------------------------------------
  2363. bool __fastcall TCustomCommandType::Equals(const TCustomCommandType * Other) const
  2364. {
  2365. return
  2366. (FName == Other->FName) &&
  2367. (FCommand == Other->FCommand) &&
  2368. (FParams == Other->FParams) &&
  2369. (FShortCut == Other->FShortCut);
  2370. }
  2371. //---------------------------------------------------------------------------
  2372. //---------------------------------------------------------------------------
  2373. __fastcall TCustomCommandList::TCustomCommandList()
  2374. {
  2375. FCommands = new TList();
  2376. FModified = false;
  2377. }
  2378. //---------------------------------------------------------------------------
  2379. __fastcall TCustomCommandList::~TCustomCommandList()
  2380. {
  2381. Clear();
  2382. delete FCommands;
  2383. }
  2384. //---------------------------------------------------------------------------
  2385. void __fastcall TCustomCommandList::Reset()
  2386. {
  2387. FModified = false;
  2388. }
  2389. //---------------------------------------------------------------------------
  2390. void __fastcall TCustomCommandList::Modify()
  2391. {
  2392. FModified = true;
  2393. }
  2394. //---------------------------------------------------------------------------
  2395. void __fastcall TCustomCommandList::Load(THierarchicalStorage * Storage)
  2396. {
  2397. Clear();
  2398. if (Storage->OpenSubKey(L"CustomCommands", false))
  2399. {
  2400. TStrings * Names = new TStringList();
  2401. try
  2402. {
  2403. Storage->ReadValues(Names, true);
  2404. for (int Index = 0; Index < Names->Count; Index++)
  2405. {
  2406. TCustomCommandType * Command = new TCustomCommandType();
  2407. Command->Name = Names->Names[Index];
  2408. Command->Command = Names->Values[Names->Names[Index]];
  2409. FCommands->Add(Command);
  2410. }
  2411. Storage->CloseSubKey();
  2412. }
  2413. __finally
  2414. {
  2415. delete Names;
  2416. }
  2417. }
  2418. if (Storage->OpenSubKey(L"CustomCommandsParams", false))
  2419. {
  2420. for (int Index = 0; Index < FCommands->Count; Index++)
  2421. {
  2422. TCustomCommandType * Command = GetCommand(Index);
  2423. Command->Params = Storage->ReadInteger(Command->Name, Command->Params);
  2424. }
  2425. Storage->CloseSubKey();
  2426. }
  2427. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", false))
  2428. {
  2429. for (int Index = 0; Index < FCommands->Count; Index++)
  2430. {
  2431. TCustomCommandType * Command = GetCommand(Index);
  2432. Command->ShortCut = (Word)Storage->ReadInteger(Command->Name, Command->ShortCut);
  2433. }
  2434. Storage->CloseSubKey();
  2435. }
  2436. Reset();
  2437. }
  2438. //---------------------------------------------------------------------------
  2439. void __fastcall TCustomCommandList::Save(THierarchicalStorage * Storage)
  2440. {
  2441. if (Storage->OpenSubKey(L"CustomCommands", true))
  2442. {
  2443. Storage->ClearValues();
  2444. for (int Index = 0; Index < FCommands->Count; Index++)
  2445. {
  2446. const TCustomCommandType * Command = Commands[Index];
  2447. Storage->WriteString(Command->Name, Command->Command);
  2448. }
  2449. Storage->CloseSubKey();
  2450. }
  2451. if (Storage->OpenSubKey(L"CustomCommandsParams", true))
  2452. {
  2453. Storage->ClearValues();
  2454. for (int Index = 0; Index < FCommands->Count; Index++)
  2455. {
  2456. const TCustomCommandType * Command = Commands[Index];
  2457. Storage->WriteInteger(Command->Name, Command->Params);
  2458. }
  2459. Storage->CloseSubKey();
  2460. }
  2461. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", true))
  2462. {
  2463. Storage->ClearValues();
  2464. for (int Index = 0; Index < FCommands->Count; Index++)
  2465. {
  2466. const TCustomCommandType * Command = Commands[Index];
  2467. if (Command->ShortCut != 0)
  2468. {
  2469. Storage->WriteInteger(Command->Name, Command->ShortCut);
  2470. }
  2471. }
  2472. Storage->CloseSubKey();
  2473. }
  2474. }
  2475. //---------------------------------------------------------------------------
  2476. void __fastcall TCustomCommandList::Clear()
  2477. {
  2478. for (int Index = 0; Index < FCommands->Count; Index++)
  2479. {
  2480. delete Commands[Index];
  2481. }
  2482. FCommands->Clear();
  2483. }
  2484. //---------------------------------------------------------------------------
  2485. void __fastcall TCustomCommandList::Add(const UnicodeString Name,
  2486. const UnicodeString ACommand, int Params)
  2487. {
  2488. TCustomCommandType * Command = new TCustomCommandType();
  2489. Command->Name = Name;
  2490. Command->Command = ACommand;
  2491. Command->Params = Params;
  2492. Add(Command);
  2493. }
  2494. //---------------------------------------------------------------------------
  2495. void __fastcall TCustomCommandList::Add(TCustomCommandType * Command)
  2496. {
  2497. Insert(Count, Command);
  2498. }
  2499. //---------------------------------------------------------------------------
  2500. void __fastcall TCustomCommandList::Insert(int Index, TCustomCommandType * Command)
  2501. {
  2502. FCommands->Insert(Index, Command);
  2503. Modify();
  2504. }
  2505. //---------------------------------------------------------------------------
  2506. void __fastcall TCustomCommandList::Change(int Index, TCustomCommandType * ACommand)
  2507. {
  2508. TCustomCommandType * Command = GetCommand(Index);
  2509. if (!Command->Equals(ACommand))
  2510. {
  2511. delete Command;
  2512. FCommands->Items[Index] = ACommand;
  2513. Modify();
  2514. }
  2515. else
  2516. {
  2517. delete ACommand;
  2518. }
  2519. }
  2520. //---------------------------------------------------------------------------
  2521. void __fastcall TCustomCommandList::Move(int CurIndex, int NewIndex)
  2522. {
  2523. if (CurIndex != NewIndex)
  2524. {
  2525. FCommands->Move(CurIndex, NewIndex);
  2526. Modify();
  2527. }
  2528. }
  2529. //---------------------------------------------------------------------------
  2530. void __fastcall TCustomCommandList::Delete(int Index)
  2531. {
  2532. DebugAssert((Index >= 0) && (Index < Count));
  2533. delete GetCommand(Index);
  2534. FCommands->Delete(Index);
  2535. Modify();
  2536. }
  2537. //---------------------------------------------------------------------------
  2538. int __fastcall TCustomCommandList::GetCount() const
  2539. {
  2540. return FCommands->Count;
  2541. }
  2542. //---------------------------------------------------------------------------
  2543. const TCustomCommandType * __fastcall TCustomCommandList::GetConstCommand(int Index) const
  2544. {
  2545. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2546. }
  2547. //---------------------------------------------------------------------------
  2548. TCustomCommandType * __fastcall TCustomCommandList::GetCommand(int Index)
  2549. {
  2550. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2551. }
  2552. //---------------------------------------------------------------------------
  2553. bool __fastcall TCustomCommandList::Equals(const TCustomCommandList * Other) const
  2554. {
  2555. bool Result = (Count == Other->Count);
  2556. for (int Index = 0; Result && (Index < Count); Index++)
  2557. {
  2558. Result = Commands[Index]->Equals(Other->Commands[Index]);
  2559. }
  2560. return Result;
  2561. }
  2562. //---------------------------------------------------------------------------
  2563. void __fastcall TCustomCommandList::Assign(const TCustomCommandList * Other)
  2564. {
  2565. Clear();
  2566. for (int Index = 0; Index < Other->Count; Index++)
  2567. {
  2568. Add(new TCustomCommandType(*Other->Commands[Index]));
  2569. }
  2570. // there should be comparison of with the assigned list, be we rely on caller
  2571. // to do it instead (TGUIConfiguration::SetCopyParamList)
  2572. Modify();
  2573. }
  2574. //---------------------------------------------------------------------------
  2575. const TCustomCommandType * TCustomCommandList::Find(const UnicodeString Name) const
  2576. {
  2577. for (int Index = 0; Index < FCommands->Count; Index++)
  2578. {
  2579. if (Commands[Index]->Name == Name)
  2580. {
  2581. return Commands[Index];
  2582. }
  2583. }
  2584. return NULL;
  2585. }
  2586. //---------------------------------------------------------------------------
  2587. const TCustomCommandType * TCustomCommandList::Find(TShortCut ShortCut) const
  2588. {
  2589. for (int Index = 0; Index < FCommands->Count; Index++)
  2590. {
  2591. if (Commands[Index]->ShortCut == ShortCut)
  2592. {
  2593. return Commands[Index];
  2594. }
  2595. }
  2596. return NULL;
  2597. }
  2598. //---------------------------------------------------------------------------
  2599. void __fastcall TCustomCommandList::ShortCuts(TShortCuts & ShortCuts) const
  2600. {
  2601. for (int Index = 0; Index < FCommands->Count; Index++)
  2602. {
  2603. const TCustomCommandType * Command = Commands[Index];
  2604. if (Command->ShortCut != 0)
  2605. {
  2606. ShortCuts.Add(Command->ShortCut);
  2607. }
  2608. }
  2609. }