WinConfiguration.cpp 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558
  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. TStorage Result = TCustomWinConfiguration::GetStorage();
  709. return Result;
  710. }
  711. //---------------------------------------------------------------------------
  712. void __fastcall TWinConfiguration::Saved()
  713. {
  714. TCustomWinConfiguration::Saved();
  715. FBookmarks->ModifyAll(false);
  716. FCustomCommandList->Reset();
  717. FEditorList->Saved();
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TWinConfiguration::RecryptPasswords(TStrings * RecryptPasswordErrors)
  721. {
  722. TCustomWinConfiguration::RecryptPasswords(RecryptPasswordErrors);
  723. try
  724. {
  725. TTerminalManager * Manager = TTerminalManager::Instance(false);
  726. assert(Manager != NULL);
  727. if (Manager != NULL)
  728. {
  729. Manager->RecryptPasswords();
  730. }
  731. }
  732. catch (Exception & E)
  733. {
  734. UnicodeString Message;
  735. if (ExceptionMessage(&E, Message))
  736. {
  737. // we do not expect this really to happen,
  738. // so we do not bother providing context
  739. RecryptPasswordErrors->Add(Message);
  740. }
  741. }
  742. }
  743. //---------------------------------------------------------------------------
  744. bool __fastcall TWinConfiguration::GetUseMasterPassword()
  745. {
  746. return FUseMasterPassword;
  747. }
  748. //---------------------------------------------------------------------------
  749. THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool SessionList)
  750. {
  751. THierarchicalStorage * Result;
  752. if (SessionList && !FTemporarySessionFile.IsEmpty())
  753. {
  754. Result = new TIniFileStorage(FTemporarySessionFile);
  755. }
  756. else
  757. {
  758. Result = TCustomWinConfiguration::CreateScpStorage(SessionList);
  759. }
  760. return Result;
  761. }
  762. //---------------------------------------------------------------------------
  763. // duplicated from core\configuration.cpp
  764. #define LASTELEM(ELEM) \
  765. ELEM.SubString(ELEM.LastDelimiter(L".>")+1, ELEM.Length() - ELEM.LastDelimiter(L".>"))
  766. #define BLOCK(KEY, CANCREATE, BLOCK) \
  767. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  768. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  769. #define REGCONFIG(CANCREATE) \
  770. BLOCK(L"Interface", CANCREATE, \
  771. KEYEX(Integer,DoubleClickAction, L"CopyOnDoubleClick"); \
  772. KEY(Bool, CopyOnDoubleClickConfirmation); \
  773. KEY(Bool, DDAllowMove); \
  774. KEY(Bool, DDAllowMoveInit); \
  775. KEYEX(Integer, DDTransferConfirmation, L"DDTransferConfirmation2"); \
  776. KEY(String, DDTemporaryDirectory); \
  777. KEY(Bool, DDWarnLackOfTempSpace); \
  778. KEY(Float, DDWarnLackOfTempSpaceRatio); \
  779. KEY(Bool, DeleteToRecycleBin); \
  780. KEY(Bool, DimmHiddenFiles); \
  781. KEY(Bool, RenameWholeName); \
  782. KEY(Bool, SelectDirectories); \
  783. KEY(String, SelectMask); \
  784. KEY(Bool, ShowHiddenFiles); \
  785. KEY(Bool, FormatSizeBytes); \
  786. KEY(Bool, ShowInaccesibleDirectories); \
  787. KEY(Bool, ConfirmTransferring); \
  788. KEY(Bool, ConfirmDeleting); \
  789. KEY(Bool, ConfirmRecycling); \
  790. KEY(Bool, ConfirmClosingSession); \
  791. KEY(String, AutoStartSession); \
  792. KEY(Bool, UseLocationProfiles); \
  793. KEY(Bool, UseSharedBookmarks); \
  794. KEY(Integer, LocaleSafe); \
  795. KEY(Bool, DDExtEnabled); \
  796. KEY(Integer, DDExtTimeout); \
  797. KEY(Bool, DefaultDirIsHome); \
  798. KEY(Bool, TemporaryDirectoryAppendSession); \
  799. KEY(Bool, TemporaryDirectoryAppendPath); \
  800. KEY(Bool, TemporaryDirectoryCleanup); \
  801. KEY(Bool, ConfirmTemporaryDirectoryCleanup); \
  802. KEY(Bool, PreservePanelState); \
  803. KEY(String, Theme); \
  804. KEY(String, LastStoredSession); \
  805. KEY(Bool, AutoSaveWorkspace); \
  806. KEY(Bool, AutoSaveWorkspacePasswords); \
  807. KEY(String, AutoWorkspace); \
  808. KEY(Integer, PathInCaption); \
  809. KEY(Bool, MinimizeToTray); \
  810. KEY(Bool, BalloonNotifications); \
  811. KEY(Integer, NotificationsTimeout); \
  812. KEY(Integer, NotificationsStickTime); \
  813. KEY(Bool, CopyParamAutoSelectNotice); \
  814. KEY(Bool, LockToolbars); \
  815. KEY(Bool, SelectiveToolbarText); \
  816. KEY(Bool, AutoOpenInPutty); \
  817. KEY(Bool, RefreshRemotePanel); \
  818. KEY(DateTime, RefreshRemotePanelInterval); \
  819. KEY(Bool, FullRowSelect); \
  820. KEY(Bool, OfferedEditorAutoConfig); \
  821. KEY(Integer, LastMonitor); \
  822. KEY(String, VersionHistory); \
  823. KEY(Bool, EnableQueueByDefault); \
  824. KEY(String, OpenedStoredSessionFolders); \
  825. KEY(Bool, AutoImportedFromPuttyOrFilezilla); \
  826. ); \
  827. BLOCK(L"Interface\\Editor", CANCREATE, \
  828. KEYEX(String, Editor.FontName, L"FontName2"); \
  829. KEY(Integer, Editor.FontSize); \
  830. KEY(Integer, Editor.FontStyle); \
  831. KEY(Integer, Editor.FontCharset); \
  832. KEY(Bool, Editor.WordWrap); \
  833. KEY(String, Editor.FindText); \
  834. KEY(String, Editor.ReplaceText); \
  835. KEY(Bool, Editor.FindMatchCase); \
  836. KEY(Bool, Editor.FindWholeWord); \
  837. KEY(Bool, Editor.FindDown); \
  838. KEY(Integer, Editor.TabSize); \
  839. KEY(Integer, Editor.MaxEditors); \
  840. KEY(Integer, Editor.EarlyClose); \
  841. KEY(Bool, Editor.SDIShellEditor); \
  842. KEY(String, Editor.WindowParams); \
  843. KEY(Integer, Editor.Encoding); \
  844. KEY(Bool, Editor.WarnOnEncodingFallback); \
  845. ); \
  846. BLOCK(L"Interface\\QueueView", CANCREATE, \
  847. KEY(Integer, QueueView.Height); \
  848. KEY(Integer, QueueView.HeightPixelsPerInch); \
  849. KEY(String, QueueView.Layout); \
  850. KEY(Integer, QueueView.Show); \
  851. KEY(Integer, QueueView.LastHideShow); \
  852. KEY(Bool, QueueView.ToolBar); \
  853. KEY(Bool, QueueView.Label); \
  854. ); \
  855. BLOCK(L"Interface\\Updates", CANCREATE, \
  856. KEY(Integer, FUpdates.Period); \
  857. KEY(DateTime, FUpdates.LastCheck); \
  858. KEY(Integer, FUpdates.HaveResults); \
  859. KEY(Integer, FUpdates.ShownResults); \
  860. KEY(Integer, FUpdates.BetaVersions); \
  861. KEY(Integer, FUpdates.ConnectionType); \
  862. KEY(String, FUpdates.ProxyHost); \
  863. KEY(Integer, FUpdates.ProxyPort); \
  864. KEY(Integer, FUpdates.Results.ForVersion); \
  865. KEY(Integer, FUpdates.Results.Version); \
  866. KEY(String, FUpdates.Results.Message); \
  867. KEY(Integer, FUpdates.Results.Critical); \
  868. KEY(String, FUpdates.Results.Release); \
  869. KEY(Bool, FUpdates.Results.Disabled); \
  870. KEY(String, FUpdates.Results.Url); \
  871. KEY(String, FUpdates.Results.UrlButton); \
  872. KEY(String, FUpdates.DotNetVersion); \
  873. KEY(String, FUpdates.ConsoleVersion); \
  874. ); \
  875. BLOCK(L"Interface\\Explorer", CANCREATE, \
  876. KEY(String, ScpExplorer.ToolbarsLayout); \
  877. KEY(String, ScpExplorer.DirViewParams); \
  878. KEY(String, ScpExplorer.LastLocalTargetDirectory); \
  879. KEY(Bool, ScpExplorer.SessionsTabs); \
  880. KEY(Bool, ScpExplorer.StatusBar); \
  881. KEY(String, ScpExplorer.WindowParams); \
  882. KEY(Integer, ScpExplorer.ViewStyle); \
  883. KEY(Bool, ScpExplorer.ShowFullAddress); \
  884. KEY(Bool, ScpExplorer.DriveView); \
  885. KEY(Integer, ScpExplorer.DriveViewWidth); \
  886. KEY(Integer, ScpExplorer.DriveViewWidthPixelsPerInch); \
  887. ); \
  888. BLOCK(L"Interface\\Commander", CANCREATE, \
  889. KEY(String, ScpCommander.ToolbarsLayout); \
  890. KEY(Integer, ScpCommander.CurrentPanel); \
  891. KEY(Float, ScpCommander.LocalPanelWidth); \
  892. KEY(Bool, ScpCommander.SwappedPanels); \
  893. KEY(Bool, ScpCommander.SessionsTabs); \
  894. KEY(Bool, ScpCommander.StatusBar); \
  895. KEY(String, ScpCommander.WindowParams); \
  896. KEYEX(Integer, ScpCommander.NortonLikeMode, L"ExplorerStyleSelection"); \
  897. KEY(Bool, ScpCommander.PreserveLocalDirectory); \
  898. KEY(Bool, ScpCommander.CompareByTime); \
  899. KEY(Bool, ScpCommander.CompareBySize); \
  900. KEY(Bool, ScpCommander.TreeOnLeft); \
  901. KEY(Bool, ScpCommander.ExplorerKeyboardShortcuts); \
  902. KEY(Bool, ScpCommander.SystemContextMenu); \
  903. ); \
  904. BLOCK(L"Interface\\Commander\\LocalPanel", CANCREATE, \
  905. KEY(String, ScpCommander.LocalPanel.DirViewParams); \
  906. KEY(Bool, ScpCommander.LocalPanel.StatusBar); \
  907. KEY(Bool, ScpCommander.LocalPanel.DriveView); \
  908. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeight); \
  909. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeightPixelsPerInch); \
  910. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidth); \
  911. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidthPixelsPerInch); \
  912. ); \
  913. BLOCK(L"Interface\\Commander\\RemotePanel", CANCREATE, \
  914. KEY(String, ScpCommander.RemotePanel.DirViewParams); \
  915. KEY(Bool, ScpCommander.RemotePanel.StatusBar); \
  916. KEY(Bool, ScpCommander.RemotePanel.DriveView); \
  917. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeight); \
  918. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeightPixelsPerInch); \
  919. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidth); \
  920. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidthPixelsPerInch); \
  921. ); \
  922. BLOCK(L"Logging", CANCREATE, \
  923. KEY(Bool, LogWindowOnStartup); \
  924. KEY(String, LogWindowParams); \
  925. ); \
  926. BLOCK(L"Security", CANCREATE, \
  927. KEYEX(Bool, FUseMasterPassword, L"UseMasterPassword"); \
  928. KEYEX(String,FMasterPasswordVerifier, L"MasterPasswordVerifier"); \
  929. );
  930. //---------------------------------------------------------------------------
  931. void __fastcall TWinConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  932. {
  933. TCustomWinConfiguration::SaveData(Storage, All);
  934. // duplicated from core\configuration.cpp
  935. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  936. REGCONFIG(true);
  937. #undef KEYEX
  938. if (Storage->OpenSubKey(L"Bookmarks", true))
  939. {
  940. FBookmarks->Save(Storage, All);
  941. Storage->CloseSubKey();
  942. }
  943. if ((All && !FCustomCommandsDefaults) || FCustomCommandList->Modified)
  944. {
  945. FCustomCommandList->Save(Storage);
  946. }
  947. if ((All || FEditorList->Modified) &&
  948. Storage->OpenSubKey(L"Interface\\Editor", true, true))
  949. try
  950. {
  951. FEditorList->Save(Storage);
  952. }
  953. __finally
  954. {
  955. Storage->CloseSubKey();
  956. }
  957. }
  958. //---------------------------------------------------------------------------
  959. void __fastcall TWinConfiguration::LoadFrom(THierarchicalStorage * Storage)
  960. {
  961. FLegacyEditor = new TEditorPreferences();
  962. try
  963. {
  964. FLegacyEditor->LegacyDefaults();
  965. TCustomWinConfiguration::LoadFrom(Storage);
  966. // This needs to be done even if there's no Configuration key in the storage,
  967. // so it cannot be in LoadData
  968. int EditorCount = FEditorList->Count;
  969. if (EditorCount == 0)
  970. {
  971. TEditorPreferences * AlternativeEditor = NULL;
  972. try
  973. {
  974. if (FLegacyEditor->Data->Editor == edInternal)
  975. {
  976. if (!FLegacyEditor->Data->ExternalEditor.IsEmpty())
  977. {
  978. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  979. AlternativeEditor->GetData()->Editor = edExternal;
  980. FLegacyEditor->GetData()->ExternalEditor = L"";
  981. }
  982. }
  983. else
  984. {
  985. if (FLegacyEditor->Data->ExternalEditor.IsEmpty())
  986. {
  987. FLegacyEditor->GetData()->Editor = edInternal;
  988. }
  989. else
  990. {
  991. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  992. AlternativeEditor->GetData()->Editor = edInternal;
  993. }
  994. }
  995. }
  996. catch(...)
  997. {
  998. delete AlternativeEditor;
  999. throw;
  1000. }
  1001. FEditorList->Add(FLegacyEditor);
  1002. FLegacyEditor = NULL;
  1003. if (AlternativeEditor != NULL)
  1004. {
  1005. FEditorList->Add(AlternativeEditor);
  1006. }
  1007. }
  1008. }
  1009. __finally
  1010. {
  1011. delete FLegacyEditor;
  1012. FLegacyEditor = NULL;
  1013. }
  1014. if (FUpdates.ConnectionType == -1)
  1015. {
  1016. FUpdates.ConnectionType = (FUpdates.ProxyHost.IsEmpty() ? ctAuto : ctProxy);
  1017. }
  1018. AddVersionToHistory();
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. void __fastcall TWinConfiguration::LoadData(THierarchicalStorage * Storage)
  1022. {
  1023. TCustomWinConfiguration::LoadData(Storage);
  1024. // duplicated from core\configuration.cpp
  1025. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  1026. #pragma warn -eas
  1027. REGCONFIG(false);
  1028. #pragma warn +eas
  1029. #undef KEYEX
  1030. if (Storage->OpenSubKey(L"Bookmarks", false))
  1031. {
  1032. FBookmarks->Load(Storage);
  1033. Storage->CloseSubKey();
  1034. }
  1035. if (Storage->HasSubKey("CustomCommands"))
  1036. {
  1037. FCustomCommandList->Load(Storage);
  1038. FCustomCommandsDefaults = false;
  1039. }
  1040. else if (FCustomCommandList->Modified)
  1041. {
  1042. // can this (=reloading of configuration) even happen?
  1043. // if it does, shouldn't we reset default commands?
  1044. assert(false);
  1045. FCustomCommandList->Clear();
  1046. FCustomCommandsDefaults = false;
  1047. }
  1048. FCustomCommandList->Reset();
  1049. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1050. try
  1051. {
  1052. FEditorList->Clear();
  1053. FEditorList->Load(Storage);
  1054. }
  1055. __finally
  1056. {
  1057. Storage->CloseSubKey();
  1058. }
  1059. // load legacy editor configuration
  1060. assert(FLegacyEditor != NULL);
  1061. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1062. {
  1063. try
  1064. {
  1065. FLegacyEditor->Load(Storage, true);
  1066. }
  1067. __finally
  1068. {
  1069. Storage->CloseSubKey();
  1070. }
  1071. }
  1072. }
  1073. //---------------------------------------------------------------------------
  1074. void __fastcall TWinConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  1075. {
  1076. TCustomWinConfiguration::LoadAdmin(Storage);
  1077. FDisableOpenEdit = Storage->ReadBool(L"DisableOpenEdit", FDisableOpenEdit);
  1078. FDefaultUpdatesPeriod = Storage->ReadInteger(L"DefaultUpdatesPeriod", FDefaultUpdatesPeriod);
  1079. }
  1080. //---------------------------------------------------------------------------
  1081. void __fastcall TWinConfiguration::CopyData(THierarchicalStorage * Source, THierarchicalStorage * Target)
  1082. {
  1083. TCustomWinConfiguration::CopyData(Source, Target);
  1084. if (Source->OpenSubKey(ConfigurationSubKey, false))
  1085. {
  1086. if (Target->OpenSubKey(ConfigurationSubKey, true))
  1087. {
  1088. Target->WriteString(L"JumpList", Source->ReadString(L"JumpList", L""));
  1089. Target->WriteString(L"JumpListWorkspaces", Source->ReadString(L"JumpListWorkspaces", L""));
  1090. Target->CloseSubKey();
  1091. }
  1092. Source->CloseSubKey();
  1093. }
  1094. }
  1095. //---------------------------------------------------------------------------
  1096. void __fastcall TWinConfiguration::ClearTemporaryLoginData()
  1097. {
  1098. if (!FTemporaryKeyFile.IsEmpty())
  1099. {
  1100. DeleteFile(FTemporaryKeyFile);
  1101. FTemporaryKeyFile = "";
  1102. }
  1103. }
  1104. //---------------------------------------------------------------------------
  1105. void __fastcall TWinConfiguration::AddVersionToHistory()
  1106. {
  1107. int CurrentVersion = CompoundVersion;
  1108. int From = 1;
  1109. bool CurrentVersionPresent = false;
  1110. while (!CurrentVersionPresent && (From < FVersionHistory.Length()))
  1111. {
  1112. UnicodeString VersionInfo = CopyToChars(FVersionHistory, From, L";", true);
  1113. UnicodeString VersionStr = ::CutToChar(VersionInfo, L',', true);
  1114. int Version;
  1115. if (TryStrToInt(VersionStr, Version) &&
  1116. (Version == CurrentVersion))
  1117. {
  1118. CurrentVersionPresent = true;
  1119. }
  1120. }
  1121. if (!CurrentVersionPresent)
  1122. {
  1123. UnicodeString CurrentVersionInfo =
  1124. IntToStr(CurrentVersion) + L"," + FileInfoString[L"ReleaseType"];
  1125. AddToList(FVersionHistory, CurrentVersionInfo, L';');
  1126. }
  1127. Usage->Set(L"AnyBetaUsed", AnyBetaInVersionHistory);
  1128. }
  1129. //---------------------------------------------------------------------------
  1130. bool __fastcall TWinConfiguration::DoIsBeta(const UnicodeString & ReleaseType)
  1131. {
  1132. return AnsiSameText(ReleaseType, L"beta") || AnsiSameText(ReleaseType, L"rc");
  1133. }
  1134. //---------------------------------------------------------------------------
  1135. bool __fastcall TWinConfiguration::GetIsBeta()
  1136. {
  1137. return DoIsBeta(FileInfoString[L"ReleaseType"]);
  1138. }
  1139. //---------------------------------------------------------------------------
  1140. bool __fastcall TWinConfiguration::GetAnyBetaInVersionHistory()
  1141. {
  1142. int From = 1;
  1143. bool AnyBeta = false;
  1144. while (!AnyBeta && (From < VersionHistory.Length()))
  1145. {
  1146. UnicodeString VersionInfo = CopyToChars(VersionHistory, From, L";", true);
  1147. ::CutToChar(VersionInfo, L',', true);
  1148. UnicodeString ReleaseType = ::CutToChar(VersionInfo, ',', true);
  1149. if (DoIsBeta(ReleaseType))
  1150. {
  1151. AnyBeta = true;
  1152. }
  1153. }
  1154. return AnyBeta;
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. bool __fastcall TWinConfiguration::GetDDExtInstalled()
  1158. {
  1159. if (FDDExtInstalled < 0)
  1160. {
  1161. if (IsWin64())
  1162. {
  1163. // WORKAROUND
  1164. // We cannot load 64-bit COM class into 32-bit process,
  1165. // so we fallback to querying registration keys
  1166. #define CLSID_SIZE 39
  1167. wchar_t ClassID[CLSID_SIZE];
  1168. StringFromGUID2(CLSID_ShellExtension, ClassID, LENOF(ClassID));
  1169. NULL_TERMINATE(ClassID);
  1170. UnicodeString SubKey = UnicodeString(L"CLSID\\") + ClassID;
  1171. HKEY HKey;
  1172. LONG Result = RegOpenKeyEx(HKEY_CLASSES_ROOT, SubKey.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &HKey);
  1173. if (Result == ERROR_SUCCESS)
  1174. {
  1175. RegCloseKey(HKey);
  1176. FDDExtInstalled = 1;
  1177. }
  1178. else
  1179. {
  1180. FDDExtInstalled = 0;
  1181. }
  1182. }
  1183. else
  1184. {
  1185. void * DragExtRef;
  1186. int CreateResult =
  1187. CoCreateInstance(CLSID_ShellExtension, NULL,
  1188. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
  1189. &DragExtRef);
  1190. bool Result = (CreateResult == S_OK);
  1191. FDDExtInstalled = (Result ? 1 : 0);
  1192. if (Result)
  1193. {
  1194. reinterpret_cast<IUnknown *>(DragExtRef)->Release();
  1195. CoFreeUnusedLibraries();
  1196. }
  1197. }
  1198. }
  1199. return (FDDExtInstalled > 0);
  1200. }
  1201. //---------------------------------------------------------------------------
  1202. RawByteString __fastcall TWinConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString Key)
  1203. {
  1204. RawByteString Dummy;
  1205. RawByteString Result;
  1206. if (GetExternalEncryptedPassword(Password, Dummy) ||
  1207. !FUseMasterPassword)
  1208. {
  1209. // already-strongly encrypted
  1210. // or no master password set, so we cannot strongly-encrypt it
  1211. Result = Password;
  1212. }
  1213. else
  1214. {
  1215. UnicodeString PasswordText =
  1216. TCustomWinConfiguration::DecryptPassword(Password, Key);
  1217. if (!PasswordText.IsEmpty())
  1218. {
  1219. // can be not set for instance, when editing=>saving site with no prior password
  1220. AskForMasterPasswordIfNotSet();
  1221. Password = ScramblePassword(PasswordText);
  1222. AES256EncyptWithMAC(Password, FPlainMasterPasswordEncrypt, Result);
  1223. Result = SetExternalEncryptedPassword(Result);
  1224. }
  1225. }
  1226. return Result;
  1227. }
  1228. //---------------------------------------------------------------------------
  1229. UnicodeString __fastcall TWinConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
  1230. {
  1231. UnicodeString Result;
  1232. RawByteString Buf;
  1233. if (GetExternalEncryptedPassword(Password, Buf))
  1234. {
  1235. if (FDontDecryptPasswords == 0)
  1236. {
  1237. // As opposite to AskForMasterPasswordIfNotSet, we test here
  1238. // for decrypt password. This is important while recrypting password,
  1239. // when clearing master password, when encrypt password is already empty.
  1240. if (FPlainMasterPasswordDecrypt.IsEmpty())
  1241. {
  1242. AskForMasterPassword();
  1243. }
  1244. if (!AES256DecryptWithMAC(Buf, FPlainMasterPasswordDecrypt, Buf) ||
  1245. !UnscramblePassword(Buf, Result))
  1246. {
  1247. throw Exception(LoadStr(DECRYPT_PASSWORD_ERROR));
  1248. }
  1249. }
  1250. else
  1251. {
  1252. Abort();
  1253. }
  1254. }
  1255. else
  1256. {
  1257. Result = TCustomWinConfiguration::DecryptPassword(Password, Key);
  1258. }
  1259. return Result;
  1260. }
  1261. //---------------------------------------------------------------------------
  1262. void __fastcall TWinConfiguration::SetMasterPassword(UnicodeString value)
  1263. {
  1264. // just stores the plain-text version of the password
  1265. // we can get here even if master password is off,
  1266. // when we encounter stray encrypted password (e.g. manually imported site),
  1267. // make sure we do not set encrypt password to avoid starting encrypting
  1268. // new passwords
  1269. // (this is bit of edge case, not really well tested)
  1270. if (!FUseMasterPassword)
  1271. {
  1272. FPlainMasterPasswordDecrypt = value;
  1273. }
  1274. else if (ALWAYS_TRUE(FUseMasterPassword) &&
  1275. ALWAYS_TRUE(ValidateMasterPassword(value)))
  1276. {
  1277. FPlainMasterPasswordEncrypt = value;
  1278. FPlainMasterPasswordDecrypt = value;
  1279. }
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. void __fastcall TWinConfiguration::ChangeMasterPassword(
  1283. UnicodeString value, TStrings * RecryptPasswordErrors)
  1284. {
  1285. RawByteString Verifier;
  1286. AES256CreateVerifier(value, Verifier);
  1287. FMasterPasswordVerifier = BytesToHex(Verifier);
  1288. FPlainMasterPasswordEncrypt = value;
  1289. FUseMasterPassword = true;
  1290. try
  1291. {
  1292. RecryptPasswords(RecryptPasswordErrors);
  1293. }
  1294. __finally
  1295. {
  1296. FPlainMasterPasswordDecrypt = value;
  1297. }
  1298. }
  1299. //---------------------------------------------------------------------------
  1300. bool __fastcall TWinConfiguration::ValidateMasterPassword(UnicodeString value)
  1301. {
  1302. assert(UseMasterPassword);
  1303. assert(!FMasterPasswordVerifier.IsEmpty());
  1304. bool Result = AES256Verify(value, HexToBytes(FMasterPasswordVerifier));
  1305. return Result;
  1306. }
  1307. //---------------------------------------------------------------------------
  1308. void __fastcall TWinConfiguration::ClearMasterPassword(TStrings * RecryptPasswordErrors)
  1309. {
  1310. FMasterPasswordVerifier = L"";
  1311. FUseMasterPassword = false;
  1312. Shred(FPlainMasterPasswordEncrypt);
  1313. try
  1314. {
  1315. RecryptPasswords(RecryptPasswordErrors);
  1316. }
  1317. __finally
  1318. {
  1319. Shred(FPlainMasterPasswordDecrypt);
  1320. }
  1321. }
  1322. //---------------------------------------------------------------------------
  1323. void __fastcall TWinConfiguration::AskForMasterPassword()
  1324. {
  1325. if (FMasterPasswordSession > 0)
  1326. {
  1327. if (FMasterPasswordSessionAsked)
  1328. {
  1329. Abort();
  1330. }
  1331. // set before call to OnMasterPasswordPrompt as it may abort
  1332. FMasterPasswordSessionAsked = true;
  1333. }
  1334. if (FOnMasterPasswordPrompt == NULL)
  1335. {
  1336. throw Exception(L"Master password handler not set");
  1337. }
  1338. else
  1339. {
  1340. FOnMasterPasswordPrompt();
  1341. assert(!FPlainMasterPasswordDecrypt.IsEmpty());
  1342. }
  1343. }
  1344. //---------------------------------------------------------------------------
  1345. void __fastcall TWinConfiguration::AskForMasterPasswordIfNotSet()
  1346. {
  1347. if (FPlainMasterPasswordEncrypt.IsEmpty())
  1348. {
  1349. AskForMasterPassword();
  1350. }
  1351. }
  1352. //---------------------------------------------------------------------------
  1353. void __fastcall TWinConfiguration::BeginMasterPasswordSession()
  1354. {
  1355. // We do not expect nesting
  1356. assert(FMasterPasswordSession == 0);
  1357. assert(!FMasterPasswordSessionAsked || (FMasterPasswordSession > 0));
  1358. // This should better be thread-specific
  1359. FMasterPasswordSession++;
  1360. }
  1361. //---------------------------------------------------------------------------
  1362. void __fastcall TWinConfiguration::EndMasterPasswordSession()
  1363. {
  1364. if (ALWAYS_TRUE(FMasterPasswordSession > 0))
  1365. {
  1366. FMasterPasswordSession--;
  1367. }
  1368. FMasterPasswordSessionAsked = false;
  1369. }
  1370. //---------------------------------------------------------------------------
  1371. void __fastcall TWinConfiguration::SetLogWindowOnStartup(bool value)
  1372. {
  1373. SET_CONFIG_PROPERTY(LogWindowOnStartup);
  1374. }
  1375. //---------------------------------------------------------------------------
  1376. void __fastcall TWinConfiguration::SetLogWindowParams(UnicodeString value)
  1377. {
  1378. SET_CONFIG_PROPERTY(LogWindowParams);
  1379. }
  1380. //---------------------------------------------------------------------------
  1381. void __fastcall TWinConfiguration::SetDDAllowMove(bool value)
  1382. {
  1383. SET_CONFIG_PROPERTY(DDAllowMove);
  1384. }
  1385. //---------------------------------------------------------------------------
  1386. void __fastcall TWinConfiguration::SetDDAllowMoveInit(bool value)
  1387. {
  1388. SET_CONFIG_PROPERTY(DDAllowMoveInit);
  1389. }
  1390. //---------------------------------------------------------------------------
  1391. void __fastcall TWinConfiguration::SetDDTransferConfirmation(TAutoSwitch value)
  1392. {
  1393. SET_CONFIG_PROPERTY(DDTransferConfirmation);
  1394. }
  1395. //---------------------------------------------------------------------------
  1396. void __fastcall TWinConfiguration::SetDDTemporaryDirectory(UnicodeString value)
  1397. {
  1398. SET_CONFIG_PROPERTY(DDTemporaryDirectory);
  1399. }
  1400. //---------------------------------------------------------------------------
  1401. void __fastcall TWinConfiguration::SetDDExtEnabled(bool value)
  1402. {
  1403. SET_CONFIG_PROPERTY(DDExtEnabled);
  1404. }
  1405. //---------------------------------------------------------------------------
  1406. void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
  1407. {
  1408. SET_CONFIG_PROPERTY(DDExtTimeout);
  1409. }
  1410. //---------------------------------------------------------------------------
  1411. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpace(bool value)
  1412. {
  1413. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpace);
  1414. }
  1415. //---------------------------------------------------------------------------
  1416. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpaceRatio(double value)
  1417. {
  1418. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpaceRatio);
  1419. }
  1420. //---------------------------------------------------------------------------
  1421. void __fastcall TWinConfiguration::SetScpExplorer(TScpExplorerConfiguration value)
  1422. {
  1423. SET_CONFIG_PROPERTY(ScpExplorer);
  1424. }
  1425. //---------------------------------------------------------------------------
  1426. void __fastcall TWinConfiguration::SetScpCommander(TScpCommanderConfiguration value)
  1427. {
  1428. SET_CONFIG_PROPERTY(ScpCommander);
  1429. }
  1430. //---------------------------------------------------------------------------
  1431. void __fastcall TWinConfiguration::SetEditor(TEditorConfiguration value)
  1432. {
  1433. SET_CONFIG_PROPERTY(Editor);
  1434. }
  1435. //---------------------------------------------------------------------------
  1436. void __fastcall TWinConfiguration::SetQueueView(TQueueViewConfiguration value)
  1437. {
  1438. SET_CONFIG_PROPERTY(QueueView);
  1439. }
  1440. //---------------------------------------------------------------------------
  1441. void __fastcall TWinConfiguration::SetEnableQueueByDefault(bool value)
  1442. {
  1443. SET_CONFIG_PROPERTY(EnableQueueByDefault);
  1444. }
  1445. //---------------------------------------------------------------------------
  1446. TUpdatesConfiguration __fastcall TWinConfiguration::GetUpdates()
  1447. {
  1448. TUpdatesConfiguration Result;
  1449. {
  1450. TGuard Guard(FCriticalSection);
  1451. Result = FUpdates;
  1452. }
  1453. return Result;
  1454. }
  1455. //---------------------------------------------------------------------------
  1456. void __fastcall TWinConfiguration::SetUpdates(TUpdatesConfiguration value)
  1457. {
  1458. TGuard Guard(FCriticalSection);
  1459. // do not use SET_CONFIG_PROPERTY to avoid OnChange handler call (not synchronized)
  1460. FUpdates = value;
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. void __fastcall TWinConfiguration::SetVersionHistory(UnicodeString value)
  1464. {
  1465. SET_CONFIG_PROPERTY(VersionHistory);
  1466. }
  1467. //---------------------------------------------------------------------------
  1468. void __fastcall TWinConfiguration::SetDeleteToRecycleBin(bool value)
  1469. {
  1470. SET_CONFIG_PROPERTY(DeleteToRecycleBin);
  1471. }
  1472. //---------------------------------------------------------------------------
  1473. void __fastcall TWinConfiguration::SetSelectDirectories(bool value)
  1474. {
  1475. SET_CONFIG_PROPERTY(SelectDirectories);
  1476. }
  1477. //---------------------------------------------------------------------------
  1478. void __fastcall TWinConfiguration::SetShowHiddenFiles(bool value)
  1479. {
  1480. SET_CONFIG_PROPERTY(ShowHiddenFiles);
  1481. }
  1482. //---------------------------------------------------------------------------
  1483. void __fastcall TWinConfiguration::SetFormatSizeBytes(bool value)
  1484. {
  1485. SET_CONFIG_PROPERTY(FormatSizeBytes);
  1486. }
  1487. //---------------------------------------------------------------------------
  1488. void __fastcall TWinConfiguration::SetShowInaccesibleDirectories(bool value)
  1489. {
  1490. SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
  1491. }
  1492. //---------------------------------------------------------------------------
  1493. void __fastcall TWinConfiguration::SetConfirmTransferring(bool value)
  1494. {
  1495. SET_CONFIG_PROPERTY(ConfirmTransferring);
  1496. }
  1497. //---------------------------------------------------------------------------
  1498. void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
  1499. {
  1500. SET_CONFIG_PROPERTY(ConfirmDeleting);
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. void __fastcall TWinConfiguration::SetConfirmRecycling(bool value)
  1504. {
  1505. SET_CONFIG_PROPERTY(ConfirmRecycling);
  1506. }
  1507. //---------------------------------------------------------------------------
  1508. void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
  1509. {
  1510. SET_CONFIG_PROPERTY(UseLocationProfiles);
  1511. }
  1512. //---------------------------------------------------------------------------
  1513. void __fastcall TWinConfiguration::SetUseSharedBookmarks(bool value)
  1514. {
  1515. SET_CONFIG_PROPERTY(UseSharedBookmarks);
  1516. }
  1517. //---------------------------------------------------------------------------
  1518. void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
  1519. {
  1520. SET_CONFIG_PROPERTY(ConfirmClosingSession);
  1521. }
  1522. //---------------------------------------------------------------------------
  1523. void __fastcall TWinConfiguration::SetDoubleClickAction(TDoubleClickAction value)
  1524. {
  1525. SET_CONFIG_PROPERTY(DoubleClickAction);
  1526. }
  1527. //---------------------------------------------------------------------------
  1528. void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
  1529. {
  1530. SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
  1531. }
  1532. //---------------------------------------------------------------------------
  1533. void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
  1534. {
  1535. SET_CONFIG_PROPERTY(DimmHiddenFiles);
  1536. }
  1537. //---------------------------------------------------------------------------
  1538. void __fastcall TWinConfiguration::SetRenameWholeName(bool value)
  1539. {
  1540. SET_CONFIG_PROPERTY(RenameWholeName);
  1541. }
  1542. //---------------------------------------------------------------------------
  1543. void __fastcall TWinConfiguration::SetAutoStartSession(UnicodeString value)
  1544. {
  1545. SET_CONFIG_PROPERTY(AutoStartSession);
  1546. }
  1547. //---------------------------------------------------------------------------
  1548. void __fastcall TWinConfiguration::SetExpertMode(bool value)
  1549. {
  1550. SET_CONFIG_PROPERTY(ExpertMode);
  1551. }
  1552. //---------------------------------------------------------------------------
  1553. void __fastcall TWinConfiguration::SetDefaultDirIsHome(bool value)
  1554. {
  1555. SET_CONFIG_PROPERTY(DefaultDirIsHome);
  1556. }
  1557. //---------------------------------------------------------------------------
  1558. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendSession(bool value)
  1559. {
  1560. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendSession);
  1561. }
  1562. //---------------------------------------------------------------------------
  1563. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendPath(bool value)
  1564. {
  1565. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendPath);
  1566. }
  1567. //---------------------------------------------------------------------------
  1568. void __fastcall TWinConfiguration::SetTemporaryDirectoryCleanup(bool value)
  1569. {
  1570. SET_CONFIG_PROPERTY(TemporaryDirectoryCleanup);
  1571. }
  1572. //---------------------------------------------------------------------------
  1573. void __fastcall TWinConfiguration::SetConfirmTemporaryDirectoryCleanup(bool value)
  1574. {
  1575. SET_CONFIG_PROPERTY(ConfirmTemporaryDirectoryCleanup);
  1576. }
  1577. //---------------------------------------------------------------------------
  1578. void __fastcall TWinConfiguration::SetPreservePanelState(bool value)
  1579. {
  1580. SET_CONFIG_PROPERTY(PreservePanelState);
  1581. }
  1582. //---------------------------------------------------------------------------
  1583. void __fastcall TWinConfiguration::SetTheme(UnicodeString value)
  1584. {
  1585. SET_CONFIG_PROPERTY_EX(Theme, ConfigureInterface());
  1586. }
  1587. //---------------------------------------------------------------------------
  1588. void __fastcall TWinConfiguration::SetLastStoredSession(UnicodeString value)
  1589. {
  1590. SET_CONFIG_PROPERTY(LastStoredSession);
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. void __fastcall TWinConfiguration::SetAutoSaveWorkspace(bool value)
  1594. {
  1595. SET_CONFIG_PROPERTY(AutoSaveWorkspace);
  1596. }
  1597. //---------------------------------------------------------------------------
  1598. void __fastcall TWinConfiguration::SetAutoSaveWorkspacePasswords(bool value)
  1599. {
  1600. SET_CONFIG_PROPERTY(AutoSaveWorkspacePasswords);
  1601. }
  1602. //---------------------------------------------------------------------------
  1603. void __fastcall TWinConfiguration::SetAutoWorkspace(UnicodeString value)
  1604. {
  1605. SET_CONFIG_PROPERTY(AutoWorkspace);
  1606. }
  1607. //---------------------------------------------------------------------------
  1608. void __fastcall TWinConfiguration::SetPathInCaption(TPathInCaption value)
  1609. {
  1610. SET_CONFIG_PROPERTY(PathInCaption);
  1611. }
  1612. //---------------------------------------------------------------------------
  1613. void __fastcall TWinConfiguration::SetMinimizeToTray(bool value)
  1614. {
  1615. SET_CONFIG_PROPERTY(MinimizeToTray);
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. void __fastcall TWinConfiguration::SetBalloonNotifications(bool value)
  1619. {
  1620. SET_CONFIG_PROPERTY(BalloonNotifications);
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. void __fastcall TWinConfiguration::SetNotificationsTimeout(unsigned int value)
  1624. {
  1625. SET_CONFIG_PROPERTY(NotificationsTimeout);
  1626. }
  1627. //---------------------------------------------------------------------------
  1628. void __fastcall TWinConfiguration::SetNotificationsStickTime(unsigned int value)
  1629. {
  1630. SET_CONFIG_PROPERTY(NotificationsStickTime);
  1631. }
  1632. //---------------------------------------------------------------------------
  1633. void __fastcall TWinConfiguration::SetCopyParamAutoSelectNotice(bool value)
  1634. {
  1635. SET_CONFIG_PROPERTY(CopyParamAutoSelectNotice);
  1636. }
  1637. //---------------------------------------------------------------------------
  1638. void __fastcall TWinConfiguration::SetLockToolbars(bool value)
  1639. {
  1640. SET_CONFIG_PROPERTY(LockToolbars);
  1641. }
  1642. //---------------------------------------------------------------------------
  1643. void __fastcall TWinConfiguration::SetSelectiveToolbarText(bool value)
  1644. {
  1645. SET_CONFIG_PROPERTY(SelectiveToolbarText);
  1646. }
  1647. //---------------------------------------------------------------------------
  1648. void __fastcall TWinConfiguration::SetAutoOpenInPutty(bool value)
  1649. {
  1650. SET_CONFIG_PROPERTY(AutoOpenInPutty);
  1651. }
  1652. //---------------------------------------------------------------------------
  1653. void __fastcall TWinConfiguration::SetRefreshRemotePanel(bool value)
  1654. {
  1655. SET_CONFIG_PROPERTY(RefreshRemotePanel);
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. void __fastcall TWinConfiguration::SetRefreshRemotePanelInterval(TDateTime value)
  1659. {
  1660. SET_CONFIG_PROPERTY(RefreshRemotePanelInterval);
  1661. }
  1662. //---------------------------------------------------------------------------
  1663. void __fastcall TWinConfiguration::SetFullRowSelect(bool value)
  1664. {
  1665. SET_CONFIG_PROPERTY(FullRowSelect);
  1666. }
  1667. //---------------------------------------------------------------------------
  1668. void __fastcall TWinConfiguration::SetOfferedEditorAutoConfig(bool value)
  1669. {
  1670. SET_CONFIG_PROPERTY(OfferedEditorAutoConfig);
  1671. }
  1672. //---------------------------------------------------------------------------
  1673. void __fastcall TWinConfiguration::SetOpenedStoredSessionFolders(UnicodeString value)
  1674. {
  1675. SET_CONFIG_PROPERTY(OpenedStoredSessionFolders);
  1676. }
  1677. //---------------------------------------------------------------------------
  1678. void __fastcall TWinConfiguration::SetAutoImportedFromPuttyOrFilezilla(bool value)
  1679. {
  1680. SET_CONFIG_PROPERTY(AutoImportedFromPuttyOrFilezilla);
  1681. }
  1682. //---------------------------------------------------------------------------
  1683. void __fastcall TWinConfiguration::SetCustomCommandList(TCustomCommandList * value)
  1684. {
  1685. assert(FCustomCommandList);
  1686. if (!FCustomCommandList->Equals(value))
  1687. {
  1688. FCustomCommandList->Assign(value);
  1689. FCustomCommandsDefaults = false;
  1690. }
  1691. }
  1692. //---------------------------------------------------------------------------
  1693. void __fastcall TWinConfiguration::SetBookmarks(UnicodeString Key,
  1694. TBookmarkList * value)
  1695. {
  1696. FBookmarks->Bookmarks[Key] = value;
  1697. Changed();
  1698. }
  1699. //---------------------------------------------------------------------------
  1700. TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(UnicodeString Key)
  1701. {
  1702. return FBookmarks->Bookmarks[Key];
  1703. }
  1704. //---------------------------------------------------------------------------
  1705. void __fastcall TWinConfiguration::SetSharedBookmarks(TBookmarkList * value)
  1706. {
  1707. FBookmarks->SharedBookmarks = value;
  1708. Changed();
  1709. }
  1710. //---------------------------------------------------------------------------
  1711. TBookmarkList * __fastcall TWinConfiguration::GetSharedBookmarks()
  1712. {
  1713. return FBookmarks->SharedBookmarks;
  1714. }
  1715. //---------------------------------------------------------------------------
  1716. UnicodeString __fastcall TWinConfiguration::GetDefaultKeyFile()
  1717. {
  1718. return (!FDefaultKeyFile.IsEmpty() ? FDefaultKeyFile : FTemporaryKeyFile);
  1719. }
  1720. //---------------------------------------------------------------------------
  1721. void __fastcall TWinConfiguration::SetLastMonitor(int value)
  1722. {
  1723. ::SetLastMonitor(value);
  1724. }
  1725. //---------------------------------------------------------------------------
  1726. int __fastcall TWinConfiguration::GetLastMonitor()
  1727. {
  1728. return ::GetLastMonitor();
  1729. }
  1730. //---------------------------------------------------------------------------
  1731. UnicodeString __fastcall TWinConfiguration::TemporaryDir(bool Mask)
  1732. {
  1733. return UniqTempDir(ExpandFileName(ExpandEnvironmentVariables(DDTemporaryDirectory)),
  1734. L"scp", Mask);
  1735. }
  1736. //---------------------------------------------------------------------------
  1737. TStrings * __fastcall TWinConfiguration::FindTemporaryFolders()
  1738. {
  1739. TStrings * Result = new TStringList();
  1740. try
  1741. {
  1742. TSearchRec SRec;
  1743. UnicodeString Mask = TemporaryDir(true);
  1744. UnicodeString Directory = ExtractFilePath(Mask);
  1745. if (FindFirst(Mask, faDirectory, SRec) == 0)
  1746. {
  1747. do
  1748. {
  1749. if (FLAGSET(SRec.Attr, faDirectory))
  1750. {
  1751. Result->Add(Directory + SRec.Name);
  1752. }
  1753. }
  1754. while (FindNextChecked(SRec) == 0);
  1755. }
  1756. if (Result->Count == 0)
  1757. {
  1758. delete Result;
  1759. Result = NULL;
  1760. }
  1761. }
  1762. catch(...)
  1763. {
  1764. delete Result;
  1765. throw;
  1766. }
  1767. return Result;
  1768. }
  1769. //---------------------------------------------------------------------------
  1770. void __fastcall TWinConfiguration::CleanupTemporaryFolders(TStrings * Folders)
  1771. {
  1772. UnicodeString ErrorList;
  1773. TStrings * F;
  1774. if (Folders == NULL)
  1775. {
  1776. F = FindTemporaryFolders();
  1777. }
  1778. else
  1779. {
  1780. F = Folders;
  1781. }
  1782. if (F != NULL)
  1783. {
  1784. try
  1785. {
  1786. if (ALWAYS_TRUE(F->Count > 0))
  1787. {
  1788. Usage->Inc(L"TemporaryDirectoryCleanups");
  1789. }
  1790. for (int i = 0; i < F->Count; i++)
  1791. {
  1792. if (!DeleteDirectory(F->Strings[i]))
  1793. {
  1794. if (!ErrorList.IsEmpty())
  1795. {
  1796. ErrorList += L"\n";
  1797. }
  1798. ErrorList += F->Strings[i];
  1799. }
  1800. }
  1801. }
  1802. __finally
  1803. {
  1804. if (Folders == NULL)
  1805. {
  1806. delete F;
  1807. }
  1808. }
  1809. if (!ErrorList.IsEmpty())
  1810. {
  1811. throw ExtException(LoadStr(CLEANUP_TEMP_ERROR), ErrorList);
  1812. }
  1813. }
  1814. }
  1815. //---------------------------------------------------------------------------
  1816. //---------------------------------------------------------------------------
  1817. #pragma warn -inl
  1818. //---------------------------------------------------------------------------
  1819. class TAsInheritedReader : public TReader
  1820. {
  1821. public:
  1822. __fastcall TAsInheritedReader(TStream * Stream, int BufSize) :
  1823. TReader(Stream, BufSize)
  1824. {
  1825. OnAncestorNotFound = AncestorNotFound;
  1826. }
  1827. virtual void __fastcall ReadPrefix(TFilerFlags & Flags, int & AChildPos)
  1828. {
  1829. TReader::ReadPrefix(Flags, AChildPos);
  1830. Flags << ffInherited;
  1831. }
  1832. void __fastcall AncestorNotFound(TReader * Reader,
  1833. const UnicodeString ComponentName, TMetaClass * ComponentClass,
  1834. TComponent *& Component)
  1835. {
  1836. assert(!Component);
  1837. if (ComponentName.IsEmpty())
  1838. {
  1839. for (int Index = 0; Index < LookupRoot->ComponentCount; Index++)
  1840. {
  1841. Component = LookupRoot->Components[Index];
  1842. if (Component->Name.IsEmpty())
  1843. {
  1844. return;
  1845. }
  1846. }
  1847. Component = NULL;
  1848. }
  1849. }
  1850. };
  1851. //---------------------------------------------------------------------------
  1852. #pragma warn .inl
  1853. //---------------------------------------------------------------------------
  1854. bool __fastcall TWinConfiguration::InternalReloadComponentRes(const UnicodeString ResName,
  1855. HINSTANCE HInst, TComponent * Instance)
  1856. {
  1857. HANDLE HRsrc;
  1858. bool Result;
  1859. if (!HInst)
  1860. {
  1861. HInst = HInstance;
  1862. }
  1863. HRsrc = FindResource(HInst, ResName.c_str(), RT_RCDATA);
  1864. Result = (HRsrc != 0);
  1865. if (Result)
  1866. {
  1867. TResourceStream * ResStream = new TResourceStream(
  1868. reinterpret_cast<int>(HInst), ResName, RT_RCDATA);
  1869. try
  1870. {
  1871. TReader * Reader;
  1872. Reader = new TAsInheritedReader(ResStream, 4096);
  1873. try
  1874. {
  1875. /*Instance =*/ Reader->ReadRootComponent(Instance);
  1876. }
  1877. __finally
  1878. {
  1879. delete Reader;
  1880. }
  1881. }
  1882. __finally
  1883. {
  1884. delete ResStream;
  1885. }
  1886. }
  1887. return Result;
  1888. }
  1889. //---------------------------------------------------------------------------
  1890. bool __fastcall TWinConfiguration::InitComponent(TComponent * Instance,
  1891. TClass RootAncestor, TClass ClassType)
  1892. {
  1893. bool Result = false;
  1894. if ((ClassType != __classid(TComponent)) && (ClassType != RootAncestor))
  1895. {
  1896. if (InitComponent(Instance, RootAncestor, ClassType->ClassParent()))
  1897. {
  1898. Result = true;
  1899. }
  1900. if (InternalReloadComponentRes(ClassType->ClassName(),
  1901. reinterpret_cast<HINSTANCE>(FindResourceHInstance(FindClassHInstance(ClassType))),
  1902. Instance))
  1903. {
  1904. Result = true;
  1905. }
  1906. }
  1907. return Result;
  1908. }
  1909. //---------------------------------------------------------------------------
  1910. LCID __fastcall TWinConfiguration::GetLocale()
  1911. {
  1912. if (!FLocale)
  1913. {
  1914. UnicodeString ResourceModule =
  1915. GetResourceModuleName(Application->Name, ModuleFileName().c_str());
  1916. if (!ResourceModule.IsEmpty())
  1917. {
  1918. UnicodeString ResourceExt = ExtractFileExt(ResourceModule).UpperCase();
  1919. ResourceExt.Delete(1, 1);
  1920. TLanguages * Langs = Languages();
  1921. int Index, Count;
  1922. Count = Langs->Count;
  1923. Index = 0;
  1924. while ((Index < Count) && !FLocale)
  1925. {
  1926. if (Langs->Ext[Index] == ResourceExt)
  1927. {
  1928. SetInitialLocale(Langs->LocaleID[Index]);
  1929. }
  1930. else if (Langs->Ext[Index].SubString(1, 2) == ResourceExt)
  1931. {
  1932. SetInitialLocale(
  1933. MAKELANGID(PRIMARYLANGID(Langs->LocaleID[Index]),
  1934. SUBLANG_DEFAULT));
  1935. }
  1936. Index++;
  1937. }
  1938. }
  1939. }
  1940. return TCustomWinConfiguration::GetLocale();
  1941. }
  1942. //---------------------------------------------------------------------------
  1943. HINSTANCE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
  1944. UnicodeString * FileName)
  1945. {
  1946. UnicodeString FileNameStorage;
  1947. if (FileName == NULL)
  1948. {
  1949. FileName = &FileNameStorage;
  1950. }
  1951. HINSTANCE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
  1952. if (Instance != NULL)
  1953. {
  1954. try
  1955. {
  1956. CheckTranslationVersion(*FileName, false);
  1957. }
  1958. catch(...)
  1959. {
  1960. FreeResourceModule(Instance);
  1961. throw;
  1962. }
  1963. }
  1964. return Instance;
  1965. }
  1966. //---------------------------------------------------------------------------
  1967. void __fastcall TWinConfiguration::SetResourceModule(HINSTANCE Instance)
  1968. {
  1969. TCustomWinConfiguration::SetResourceModule(Instance);
  1970. TOperationVisualizer Visualizer;
  1971. int Count;
  1972. UnicodeString OrigName;
  1973. int OrigLeft;
  1974. int OrigTop;
  1975. TForm * Form;
  1976. Count = Screen->FormCount;
  1977. for (int Index = 0; Index < Count; Index++)
  1978. {
  1979. Form = Screen->Forms[Index];
  1980. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 0, 1);
  1981. }
  1982. ConfigureInterface();
  1983. for (int Index = 0; Index < Count; Index++)
  1984. {
  1985. Form = Screen->Forms[Index];
  1986. TComponent * Component;
  1987. for (int Index = 0; Index < Form->ComponentCount; Index++)
  1988. {
  1989. Component = Form->Components[Index];
  1990. if (dynamic_cast<TFrame*>(Component))
  1991. {
  1992. OrigName = Component->Name;
  1993. InitComponent(Component, __classid(TFrame), Component->ClassType());
  1994. Component->Name = OrigName;
  1995. }
  1996. }
  1997. OrigLeft = Form->Left;
  1998. OrigTop = Form->Top;
  1999. OrigName = Form->Name;
  2000. InitComponent(Form, __classid(TForm), Form->ClassType());
  2001. Form->Name = OrigName;
  2002. Form->Position = poDesigned;
  2003. Form->Left = OrigLeft;
  2004. Form->Top = OrigTop;
  2005. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 1, 1);
  2006. }
  2007. TDataModule * DataModule;
  2008. Count = Screen->DataModuleCount;
  2009. for (int Index = 0; Index < Count; Index++)
  2010. {
  2011. DataModule = Screen->DataModules[Index];
  2012. OrigName = DataModule->Name;
  2013. InitComponent(DataModule, __classid(TDataModule), DataModule->ClassType());
  2014. DataModule->Name = OrigName;
  2015. }
  2016. }
  2017. //---------------------------------------------------------------------------
  2018. void __fastcall TWinConfiguration::CheckTranslationVersion(const UnicodeString FileName,
  2019. bool InternalLocaleOnError)
  2020. {
  2021. UnicodeString TranslationProductVersion = GetFileProductVersion(FileName);
  2022. UnicodeString TranslationProductName = GetFileProductName(FileName);
  2023. if ((ProductName != TranslationProductName) ||
  2024. (ProductVersion != TranslationProductVersion))
  2025. {
  2026. if (InternalLocaleOnError)
  2027. {
  2028. LocaleSafe = InternalLocale();
  2029. }
  2030. if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
  2031. {
  2032. throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
  2033. }
  2034. else
  2035. {
  2036. throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
  2037. (FileName, TranslationProductName, TranslationProductVersion)));
  2038. }
  2039. }
  2040. }
  2041. //---------------------------------------------------------------------------
  2042. void __fastcall TWinConfiguration::CheckDefaultTranslation()
  2043. {
  2044. if (!FInvalidDefaultTranslationMessage.IsEmpty())
  2045. {
  2046. MoreMessageDialog(FMTLOAD(INVALID_DEFAULT_TRANSLATION,
  2047. (FInvalidDefaultTranslationMessage)), NULL, qtWarning, qaOK, HELP_NONE);
  2048. }
  2049. }
  2050. //---------------------------------------------------------------------------
  2051. const TEditorPreferences * __fastcall TWinConfiguration::DefaultEditorForFile(
  2052. const UnicodeString FileName, bool Local, const TFileMasks::TParams & MaskParams)
  2053. {
  2054. return FEditorList->Find(FileName, Local, MaskParams);
  2055. }
  2056. //---------------------------------------------------------------------------
  2057. const TEditorList * __fastcall TWinConfiguration::GetEditorList()
  2058. {
  2059. return FEditorList;
  2060. }
  2061. //---------------------------------------------------------------------------
  2062. void __fastcall TWinConfiguration::SetEditorList(const TEditorList * value)
  2063. {
  2064. if (!(*FEditorList == *value))
  2065. {
  2066. *FEditorList = *value;
  2067. Changed();
  2068. }
  2069. }
  2070. //---------------------------------------------------------------------------
  2071. TStringList * __fastcall TWinConfiguration::LoadJumpList(
  2072. THierarchicalStorage * Storage, UnicodeString Name)
  2073. {
  2074. UnicodeString JumpList = Storage->ReadString(Name, L"");
  2075. std::unique_ptr<TStringList> List(new TStringList());
  2076. List->CaseSensitive = false;
  2077. List->CommaText = JumpList;
  2078. return List.release();
  2079. }
  2080. //---------------------------------------------------------------------------
  2081. void __fastcall TWinConfiguration::SaveJumpList(
  2082. THierarchicalStorage * Storage, UnicodeString Name, TStringList * List)
  2083. {
  2084. UnicodeString JumpList = Storage->ReadString(Name, L"");
  2085. UnicodeString NewJumpList = List->CommaText;
  2086. if (NewJumpList != JumpList)
  2087. {
  2088. Storage->WriteString(Name, NewJumpList);
  2089. }
  2090. }
  2091. //---------------------------------------------------------------------------
  2092. void __fastcall TWinConfiguration::TrimJumpList(TStringList * List)
  2093. {
  2094. while (List->Count > 30)
  2095. {
  2096. List->Delete(List->Count - 1);
  2097. }
  2098. }
  2099. //---------------------------------------------------------------------------
  2100. void __fastcall TWinConfiguration::UpdateEntryInJumpList(
  2101. bool Session, const UnicodeString & Name, bool Add)
  2102. {
  2103. THierarchicalStorage * Storage = CreateScpStorage(false);
  2104. try
  2105. {
  2106. FDontDecryptPasswords++;
  2107. Storage->AccessMode = smReadWrite;
  2108. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  2109. {
  2110. std::unique_ptr<TStringList> ListSessions(LoadJumpList(Storage, L"JumpList"));
  2111. std::unique_ptr<TStringList> ListWorkspaces(LoadJumpList(Storage, L"JumpListWorkspaces"));
  2112. if (!Name.IsEmpty())
  2113. {
  2114. TStringList * List = (Session ? ListSessions : ListWorkspaces).get();
  2115. int Index = List->IndexOf(Name);
  2116. if (Index >= 0)
  2117. {
  2118. List->Delete(Index);
  2119. }
  2120. if (Add)
  2121. {
  2122. List->Insert(0, Name);
  2123. }
  2124. }
  2125. TrimJumpList(ListSessions.get());
  2126. TrimJumpList(ListWorkspaces.get());
  2127. ::UpdateJumpList(ListSessions.get(), ListWorkspaces.get());
  2128. SaveJumpList(Storage, L"JumpList", ListSessions.get());
  2129. SaveJumpList(Storage, L"JumpListWorkspaces", ListWorkspaces.get());
  2130. }
  2131. }
  2132. __finally
  2133. {
  2134. FDontDecryptPasswords--;
  2135. delete Storage;
  2136. }
  2137. }
  2138. //---------------------------------------------------------------------------
  2139. void __fastcall TWinConfiguration::AddSessionToJumpList(UnicodeString SessionName)
  2140. {
  2141. UpdateEntryInJumpList(true, SessionName, true);
  2142. }
  2143. //---------------------------------------------------------------------------
  2144. void __fastcall TWinConfiguration::DeleteSessionFromJumpList(UnicodeString SessionName)
  2145. {
  2146. UpdateEntryInJumpList(true, SessionName, false);
  2147. }
  2148. //---------------------------------------------------------------------------
  2149. void __fastcall TWinConfiguration::AddWorkspaceToJumpList(UnicodeString Workspace)
  2150. {
  2151. UpdateEntryInJumpList(false, Workspace, true);
  2152. }
  2153. //---------------------------------------------------------------------------
  2154. void __fastcall TWinConfiguration::DeleteWorkspaceFromJumpList(UnicodeString Workspace)
  2155. {
  2156. UpdateEntryInJumpList(false, Workspace, false);
  2157. }
  2158. //---------------------------------------------------------------------------
  2159. void __fastcall TWinConfiguration::UpdateJumpList()
  2160. {
  2161. AddSessionToJumpList(L"");
  2162. }
  2163. //---------------------------------------------------------------------------
  2164. void __fastcall TWinConfiguration::UpdateStaticUsage()
  2165. {
  2166. // This is here because of TStoredSessionList::UpdateStaticUsage() call
  2167. // from TConfiguration::UpdateStaticUsage()
  2168. TAutoNestingCounter DontDecryptPasswordsAutoCounter(FDontDecryptPasswords);
  2169. TCustomWinConfiguration::UpdateStaticUsage();
  2170. Usage->Set(L"Beta", IsBeta);
  2171. Usage->Set(L"Interface", Interface);
  2172. Usage->Set(L"CustomCommandsCount", (FCustomCommandsDefaults ? 0 : FCustomCommandList->Count));
  2173. Usage->Set(L"UsingLocationProfiles", UseLocationProfiles);
  2174. Usage->Set(L"UsingMasterPassword", UseMasterPassword);
  2175. Usage->Set(L"UsingAutoSaveWorkspace", AutoSaveWorkspace);
  2176. Usage->Set(L"TreeVisible",
  2177. (Interface == ifExplorer) ?
  2178. ScpExplorer.DriveView :
  2179. (ScpCommander.LocalPanel.DriveView || ScpCommander.RemotePanel.DriveView));
  2180. Usage->Set(L"CommanderNortonLikeMode", int(ScpCommander.NortonLikeMode));
  2181. Usage->Set(L"CommanderExplorerKeyboardShortcuts", ScpCommander.ExplorerKeyboardShortcuts);
  2182. Usage->Set(L"ExplorerViewStyle", ScpExplorer.ViewStyle);
  2183. Usage->Set(L"LastMonitor", LastMonitor);
  2184. UnicodeString ExternalEditors;
  2185. for (int Index = 0; Index < EditorList->Count; Index++)
  2186. {
  2187. const TEditorPreferences * Editor = EditorList->Editors[Index];
  2188. if (Editor->Data->Editor == edExternal)
  2189. {
  2190. UnicodeString ExternalEditor = Editor->Data->ExternalEditor;
  2191. ReformatFileNameCommand(ExternalEditor);
  2192. UnicodeString Name = ExtractProgramName(ExternalEditor);
  2193. AddToList(ExternalEditors, Name, ",");
  2194. }
  2195. }
  2196. Usage->Set(L"ExternalEditors", ExternalEditors);
  2197. }
  2198. //---------------------------------------------------------------------------
  2199. //---------------------------------------------------------------------------
  2200. __fastcall TCustomCommandType::TCustomCommandType() :
  2201. FParams(0), FShortCut(0)
  2202. {
  2203. }
  2204. //---------------------------------------------------------------------------
  2205. __fastcall TCustomCommandType::TCustomCommandType(const TCustomCommandType & Other) :
  2206. FName(Other.FName),
  2207. FCommand(Other.FCommand),
  2208. FParams(Other.FParams),
  2209. FShortCut(Other.FShortCut)
  2210. {
  2211. }
  2212. //---------------------------------------------------------------------------
  2213. TCustomCommandType & TCustomCommandType::operator=(const TCustomCommandType & Other)
  2214. {
  2215. FName = Other.FName;
  2216. FCommand = Other.FCommand;
  2217. FParams = Other.FParams;
  2218. FShortCut = Other.FShortCut;
  2219. return *this;
  2220. }
  2221. //---------------------------------------------------------------------------
  2222. bool __fastcall TCustomCommandType::Equals(const TCustomCommandType * Other) const
  2223. {
  2224. return
  2225. (FName == Other->FName) &&
  2226. (FCommand == Other->FCommand) &&
  2227. (FParams == Other->FParams) &&
  2228. (FShortCut == Other->FShortCut);
  2229. }
  2230. //---------------------------------------------------------------------------
  2231. //---------------------------------------------------------------------------
  2232. __fastcall TCustomCommandList::TCustomCommandList()
  2233. {
  2234. FCommands = new TList();
  2235. FModified = false;
  2236. }
  2237. //---------------------------------------------------------------------------
  2238. __fastcall TCustomCommandList::~TCustomCommandList()
  2239. {
  2240. Clear();
  2241. delete FCommands;
  2242. }
  2243. //---------------------------------------------------------------------------
  2244. void __fastcall TCustomCommandList::Reset()
  2245. {
  2246. FModified = false;
  2247. }
  2248. //---------------------------------------------------------------------------
  2249. void __fastcall TCustomCommandList::Modify()
  2250. {
  2251. FModified = true;
  2252. }
  2253. //---------------------------------------------------------------------------
  2254. void __fastcall TCustomCommandList::Load(THierarchicalStorage * Storage)
  2255. {
  2256. Clear();
  2257. if (Storage->OpenSubKey(L"CustomCommands", false))
  2258. {
  2259. TStrings * Names = new TStringList();
  2260. try
  2261. {
  2262. Storage->ReadValues(Names, true);
  2263. for (int Index = 0; Index < Names->Count; Index++)
  2264. {
  2265. TCustomCommandType * Command = new TCustomCommandType();
  2266. Command->Name = Names->Names[Index];
  2267. Command->Command = Names->Values[Names->Names[Index]];
  2268. FCommands->Add(Command);
  2269. }
  2270. Storage->CloseSubKey();
  2271. }
  2272. __finally
  2273. {
  2274. delete Names;
  2275. }
  2276. }
  2277. if (Storage->OpenSubKey(L"CustomCommandsParams", false))
  2278. {
  2279. for (int Index = 0; Index < FCommands->Count; Index++)
  2280. {
  2281. TCustomCommandType * Command = GetCommand(Index);
  2282. Command->Params = Storage->ReadInteger(Command->Name, Command->Params);
  2283. }
  2284. Storage->CloseSubKey();
  2285. }
  2286. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", false))
  2287. {
  2288. for (int Index = 0; Index < FCommands->Count; Index++)
  2289. {
  2290. TCustomCommandType * Command = GetCommand(Index);
  2291. Command->ShortCut = (Word)Storage->ReadInteger(Command->Name, Command->ShortCut);
  2292. }
  2293. Storage->CloseSubKey();
  2294. }
  2295. Reset();
  2296. }
  2297. //---------------------------------------------------------------------------
  2298. void __fastcall TCustomCommandList::Save(THierarchicalStorage * Storage)
  2299. {
  2300. if (Storage->OpenSubKey(L"CustomCommands", true))
  2301. {
  2302. Storage->ClearValues();
  2303. for (int Index = 0; Index < FCommands->Count; Index++)
  2304. {
  2305. const TCustomCommandType * Command = Commands[Index];
  2306. Storage->WriteString(Command->Name, Command->Command);
  2307. }
  2308. Storage->CloseSubKey();
  2309. }
  2310. if (Storage->OpenSubKey(L"CustomCommandsParams", true))
  2311. {
  2312. Storage->ClearValues();
  2313. for (int Index = 0; Index < FCommands->Count; Index++)
  2314. {
  2315. const TCustomCommandType * Command = Commands[Index];
  2316. Storage->WriteInteger(Command->Name, Command->Params);
  2317. }
  2318. Storage->CloseSubKey();
  2319. }
  2320. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", true))
  2321. {
  2322. Storage->ClearValues();
  2323. for (int Index = 0; Index < FCommands->Count; Index++)
  2324. {
  2325. const TCustomCommandType * Command = Commands[Index];
  2326. if (Command->ShortCut != 0)
  2327. {
  2328. Storage->WriteInteger(Command->Name, Command->ShortCut);
  2329. }
  2330. }
  2331. Storage->CloseSubKey();
  2332. }
  2333. }
  2334. //---------------------------------------------------------------------------
  2335. void __fastcall TCustomCommandList::Clear()
  2336. {
  2337. for (int Index = 0; Index < FCommands->Count; Index++)
  2338. {
  2339. delete Commands[Index];
  2340. }
  2341. FCommands->Clear();
  2342. }
  2343. //---------------------------------------------------------------------------
  2344. void __fastcall TCustomCommandList::Add(const UnicodeString Name,
  2345. const UnicodeString ACommand, int Params)
  2346. {
  2347. TCustomCommandType * Command = new TCustomCommandType();
  2348. Command->Name = Name;
  2349. Command->Command = ACommand;
  2350. Command->Params = Params;
  2351. Add(Command);
  2352. }
  2353. //---------------------------------------------------------------------------
  2354. void __fastcall TCustomCommandList::Add(TCustomCommandType * Command)
  2355. {
  2356. Insert(Count, Command);
  2357. }
  2358. //---------------------------------------------------------------------------
  2359. void __fastcall TCustomCommandList::Insert(int Index, TCustomCommandType * Command)
  2360. {
  2361. FCommands->Insert(Index, Command);
  2362. Modify();
  2363. }
  2364. //---------------------------------------------------------------------------
  2365. void __fastcall TCustomCommandList::Change(int Index, TCustomCommandType * ACommand)
  2366. {
  2367. TCustomCommandType * Command = GetCommand(Index);
  2368. if (!Command->Equals(ACommand))
  2369. {
  2370. delete Command;
  2371. FCommands->Items[Index] = ACommand;
  2372. Modify();
  2373. }
  2374. else
  2375. {
  2376. delete ACommand;
  2377. }
  2378. }
  2379. //---------------------------------------------------------------------------
  2380. void __fastcall TCustomCommandList::Move(int CurIndex, int NewIndex)
  2381. {
  2382. if (CurIndex != NewIndex)
  2383. {
  2384. FCommands->Move(CurIndex, NewIndex);
  2385. Modify();
  2386. }
  2387. }
  2388. //---------------------------------------------------------------------------
  2389. void __fastcall TCustomCommandList::Delete(int Index)
  2390. {
  2391. assert((Index >= 0) && (Index < Count));
  2392. delete GetCommand(Index);
  2393. FCommands->Delete(Index);
  2394. Modify();
  2395. }
  2396. //---------------------------------------------------------------------------
  2397. int __fastcall TCustomCommandList::GetCount() const
  2398. {
  2399. return FCommands->Count;
  2400. }
  2401. //---------------------------------------------------------------------------
  2402. const TCustomCommandType * __fastcall TCustomCommandList::GetConstCommand(int Index) const
  2403. {
  2404. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2405. }
  2406. //---------------------------------------------------------------------------
  2407. TCustomCommandType * __fastcall TCustomCommandList::GetCommand(int Index)
  2408. {
  2409. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2410. }
  2411. //---------------------------------------------------------------------------
  2412. bool __fastcall TCustomCommandList::Equals(const TCustomCommandList * Other) const
  2413. {
  2414. bool Result = (Count == Other->Count);
  2415. for (int Index = 0; Result && (Index < Count); Index++)
  2416. {
  2417. Result = Commands[Index]->Equals(Other->Commands[Index]);
  2418. }
  2419. return Result;
  2420. }
  2421. //---------------------------------------------------------------------------
  2422. void __fastcall TCustomCommandList::Assign(const TCustomCommandList * Other)
  2423. {
  2424. Clear();
  2425. for (int Index = 0; Index < Other->Count; Index++)
  2426. {
  2427. Add(new TCustomCommandType(*Other->Commands[Index]));
  2428. }
  2429. // there should be comparison of with the assigned list, be we rely on caller
  2430. // to do it instead (TGUIConfiguration::SetCopyParamList)
  2431. Modify();
  2432. }
  2433. //---------------------------------------------------------------------------
  2434. const TCustomCommandType * TCustomCommandList::Find(const UnicodeString Name) const
  2435. {
  2436. for (int Index = 0; Index < FCommands->Count; Index++)
  2437. {
  2438. if (Commands[Index]->Name == Name)
  2439. {
  2440. return Commands[Index];
  2441. }
  2442. }
  2443. return NULL;
  2444. }
  2445. //---------------------------------------------------------------------------
  2446. const TCustomCommandType * TCustomCommandList::Find(TShortCut ShortCut) const
  2447. {
  2448. for (int Index = 0; Index < FCommands->Count; Index++)
  2449. {
  2450. if (Commands[Index]->ShortCut == ShortCut)
  2451. {
  2452. return Commands[Index];
  2453. }
  2454. }
  2455. return NULL;
  2456. }
  2457. //---------------------------------------------------------------------------
  2458. void __fastcall TCustomCommandList::ShortCuts(TShortCuts & ShortCuts) const
  2459. {
  2460. for (int Index = 0; Index < FCommands->Count; Index++)
  2461. {
  2462. const TCustomCommandType * Command = Commands[Index];
  2463. if (Command->ShortCut != 0)
  2464. {
  2465. ShortCuts.Add(Command->ShortCut);
  2466. }
  2467. }
  2468. }