WinConfiguration.cpp 90 KB

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