WinConfiguration.cpp 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432
  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 <LanguagesDEPfix.hpp>
  19. #include <InitGUID.h>
  20. #include <DragExt.h>
  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. Default();
  380. try
  381. {
  382. CheckTranslationVersion(
  383. GetResourceModuleName(Application->Name, ModuleFileName().c_str()), true);
  384. }
  385. catch(Exception & E)
  386. {
  387. FInvalidDefaultTranslationMessage = E.Message;
  388. }
  389. }
  390. //---------------------------------------------------------------------------
  391. __fastcall TWinConfiguration::~TWinConfiguration()
  392. {
  393. if (!FTemporarySessionFile.IsEmpty()) DeleteFile(FTemporarySessionFile);
  394. ClearTemporaryLoginData();
  395. delete FBookmarks;
  396. delete FCustomCommandList;
  397. delete FEditorList;
  398. }
  399. //---------------------------------------------------------------------------
  400. UnicodeString __fastcall TWinConfiguration::FormatDefaultWindowParams(int Width, int Height)
  401. {
  402. return FORMAT(L"-1;-1;%d;%d;0", (Width, Height));
  403. }
  404. //---------------------------------------------------------------------------
  405. void __fastcall TWinConfiguration::Default()
  406. {
  407. FCustomCommandsDefaults = true;
  408. TCustomWinConfiguration::Default();
  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, when may be undesirable
  446. FLastWorkspace = LoadStr(NEW_WORKSPACE);
  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 = L"Courier New";
  472. FEditor.FontHeight = -12;
  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. // with 1000 pixels wide screen, both interfaces are wide enough to fit wider queue
  490. FQueueView.Layout = (Screen->Width > 1000) ? L"70,250,250,80,80,80,80" : L"70,160,160,80,80,80,80";
  491. FQueueView.Show = qvHideWhenEmpty;
  492. FQueueView.LastHideShow = qvHideWhenEmpty;
  493. FQueueView.ToolBar = false;
  494. FQueueView.Label = true;
  495. FEnableQueueByDefault = true;
  496. FUpdates.Period = FDefaultUpdatesPeriod;
  497. FUpdates.LastCheck = 0;
  498. FUpdates.HaveResults = false;
  499. FUpdates.ShownResults = false;
  500. FUpdates.BetaVersions = asAuto;
  501. // for backward compatibility the default is decided based on value of ProxyHost
  502. FUpdates.ConnectionType = (TConnectionType)-1;
  503. FUpdates.ProxyHost = L""; // keep empty (see above)
  504. FUpdates.ProxyPort = 8080;
  505. FUpdates.Results.Reset();
  506. FUpdates.DotNetVersion = "";
  507. FUpdates.ConsoleVersion = "";
  508. FLogWindowOnStartup = true;
  509. FLogWindowParams = L"-1;-1;500;400";
  510. int ExplorerWidth = (Screen->Width > 900) ? 860 : 600;
  511. int ExplorerHeight = (Screen->Height > 750) ? 720 : 400;
  512. FScpExplorer.WindowParams = FormatDefaultWindowParams(ExplorerWidth, ExplorerHeight);
  513. FScpExplorer.DirViewParams = L"0;1;0|150,1;70,1;120,1;79,1;62,1;55,1;20,0;150,0;125,0|6;7;8;0;1;2;3;4;5";
  514. FScpExplorer.ToolbarsLayout =
  515. L"Queue_Visible=1,Queue_LastDock=QueueDock,Queue_DockRow=0,Queue_DockPos=-1,Queue_FloatLeft=0,Queue_FloatTop=0,Queue_FloatRightX=0,"
  516. "Menu_Visible=1,Menu_DockedTo=TopDock,Menu_LastDock=TopDock,Menu_DockRow=0,Menu_DockPos=0,Menu_FloatLeft=0,Menu_FloatTop=0,Menu_FloatRightX=0,"
  517. "Buttons_Visible=1,Buttons_DockedTo=TopDock,Buttons_LastDock=TopDock,Buttons_DockRow=2,Buttons_DockPos=0,Buttons_FloatLeft=0,Buttons_FloatTop=0,Buttons_FloatRightX=0,"
  518. "Selection_Visible=0,Selection_DockedTo=TopDock,Selection_LastDock=TopDock,Selection_DockRow=3,Selection_DockPos=0,Selection_FloatLeft=227,Selection_FloatTop=445,Selection_FloatRightX=0,"
  519. "Session_Visible=0,Session_DockedTo=TopDock,Session_LastDock=TopDock,Session_DockRow=6,Session_DockPos=0,Session_FloatLeft=39,Session_FloatTop=160,Session_FloatRightX=0,"
  520. "Preferences_Visible=1,Preferences_DockedTo=TopDock,Preferences_LastDock=TopDock,Preferences_DockRow=4,Preferences_DockPos=0,Preferences_FloatLeft=0,Preferences_FloatTop=0,Preferences_FloatRightX=0,"
  521. "Sort_Visible=0,Sort_DockedTo=TopDock,Sort_LastDock=TopDock,Sort_DockRow=5,Sort_DockPos=0,Sort_FloatLeft=0,Sort_FloatTop=0,Sort_FloatRightX=0,"
  522. "Address_Visible=1,Address_DockedTo=TopDock,Address_LastDock=TopDock,Address_DockRow=1,Address_DockPos=0,Address_FloatLeft=0,Address_FloatTop=0,Address_FloatRightX=0,"
  523. "Updates_Visible=1,Updates_DockedTo=TopDock,Updates_LastDock=TopDock,Updates_DockRow=4,Updates_DockPos=416,Updates_FloatLeft=0,Updates_FloatTop=0,Updates_FloatRightX=0,"
  524. "Transfer_Visible=1,Transfer_DockedTo=TopDock,Transfer_LastDock=TopDock,Transfer_DockRow=4,Transfer_DockPos=194,Transfer_FloatLeft=0,Transfer_FloatTop=0,Transfer_FloatRightX=0,"
  525. "CustomCommands_Visible=0,CustomCommands_DockedTo=TopDock,CustomCommands_LastDock=TopDock,CustomCommands_DockRow=7,CustomCommands_DockPos=0,CustomCommands_FloatLeft=0,CustomCommands_FloatTop=0,CustomCommands_FloatRightX=0";
  526. FScpExplorer.SessionsTabs = true;
  527. FScpExplorer.StatusBar = true;
  528. UnicodeString PersonalFolder;
  529. ::SpecialFolderLocation(CSIDL_PERSONAL, PersonalFolder);
  530. FScpExplorer.LastLocalTargetDirectory = PersonalFolder;
  531. FScpExplorer.ViewStyle = 0; /* vsIcon */
  532. FScpExplorer.ShowFullAddress = true;
  533. FScpExplorer.DriveView = true;
  534. FScpExplorer.DriveViewWidth = 180;
  535. int CommanderWidth = (Screen->Width > 1100) ? 1050 : ((Screen->Width > 1000) ? 950 : 600);
  536. int CommanderHeight = (Screen->Height > 750) ? 700 : 400;
  537. FScpCommander.WindowParams = FormatDefaultWindowParams(CommanderWidth, CommanderHeight);
  538. FScpCommander.LocalPanelWidth = 0.5;
  539. FScpCommander.SwappedPanels = false;
  540. FScpCommander.SessionsTabs = true;
  541. FScpCommander.StatusBar = true;
  542. FScpCommander.NortonLikeMode = nlKeyboard;
  543. FScpCommander.PreserveLocalDirectory = false;
  544. // Toolbar2_FloatRightX=1 makes keybar apper initially "in column" when undocked
  545. FScpCommander.ToolbarsLayout =
  546. L"Queue_Visible=1,Queue_LastDock=QueueDock,Queue_DockRow=0,Queue_DockPos=-1,Queue_FloatLeft=0,Queue_FloatTop=0,Queue_FloatRightX=0,"
  547. "Menu_Visible=1,Menu_DockedTo=TopDock,Menu_LastDock=TopDock,Menu_DockRow=0,Menu_DockPos=0,Menu_FloatLeft=0,Menu_FloatTop=0,Menu_FloatRightX=0,"
  548. "Preferences_Visible=1,Preferences_DockedTo=TopDock,Preferences_LastDock=TopDock,Preferences_DockRow=1,Preferences_DockPos=228,Preferences_FloatLeft=0,Preferences_FloatTop=0,Preferences_FloatRightX=0,"
  549. "Session_Visible=0,Session_DockedTo=TopDock,Session_LastDock=TopDock,Session_DockRow=1,Session_DockPos=602,Session_FloatLeft=380,Session_FloatTop=197,Session_FloatRightX=0,"
  550. "Sort_Visible=0,Sort_DockedTo=TopDock,Sort_LastDock=TopDock,Sort_DockRow=2,Sort_DockPos=0,Sort_FloatLeft=0,Sort_FloatTop=0,Sort_FloatRightX=0,"
  551. "Commands_Visible=1,Commands_DockedTo=TopDock,Commands_LastDock=TopDock,Commands_DockRow=1,Commands_DockPos=0,Commands_FloatLeft=0,Commands_FloatTop=0,Commands_FloatRightX=0,"
  552. "Updates_Visible=1,Updates_DockedTo=TopDock,Updates_LastDock=TopDock,Updates_DockRow=1,Updates_DockPos=619,Updates_FloatLeft=0,Updates_FloatTop=0,Updates_FloatRightX=0,"
  553. "Transfer_Visible=1,Transfer_DockedTo=TopDock,Transfer_LastDock=TopDock,Transfer_DockRow=1,Transfer_DockPos=364,Transfer_FloatLeft=0,Transfer_FloatTop=0,Transfer_FloatRightX=0,"
  554. "CustomCommands_Visible=0,CustomCommands_DockedTo=TopDock,CustomCommands_LastDock=TopDock,CustomCommands_DockRow=3,CustomCommands_DockPos=0,CustomCommands_FloatLeft=0,CustomCommands_FloatTop=0,CustomCommands_FloatRightX=0,"
  555. "RemoteHistory_Visible=1,RemoteHistory_DockedTo=RemoteTopDock,RemoteHistory_LastDock=RemoteTopDock,RemoteHistory_DockRow=0,RemoteHistory_DockPos=172,RemoteHistory_FloatLeft=0,RemoteHistory_FloatTop=0,RemoteHistory_FloatRightX=0,"
  556. "RemoteNavigation_Visible=1,RemoteNavigation_DockedTo=RemoteTopDock,RemoteNavigation_LastDock=RemoteTopDock,RemoteNavigation_DockRow=0,RemoteNavigation_DockPos=252,RemoteNavigation_FloatLeft=0,RemoteNavigation_FloatTop=0,RemoteNavigation_FloatRightX=0,"
  557. "RemotePath_Visible=1,RemotePath_DockedTo=RemoteTopDock,RemotePath_LastDock=RemoteTopDock,RemotePath_DockRow=0,RemotePath_DockPos=0,RemotePath_FloatLeft=0,RemotePath_FloatTop=0,RemotePath_FloatRightX=0,"
  558. "RemoteFile_Visible=1,RemoteFile_DockedTo=RemoteTopDock,RemoteFile_LastDock=RemoteTopDock,RemoteFile_DockRow=1,RemoteFile_DockPos=0,RemoteFile_FloatLeft=0,RemoteFile_FloatTop=0,RemoteFile_FloatRightX=0,"
  559. "RemoteSelection_Visible=1,RemoteSelection_DockedTo=RemoteTopDock,RemoteSelection_LastDock=RemoteTopDock,RemoteSelection_DockRow=1,RemoteSelection_DockPos=345,RemoteSelection_FloatLeft=0,RemoteSelection_FloatTop=0,RemoteSelection_FloatRightX=0,"
  560. "LocalHistory_Visible=1,LocalHistory_DockedTo=LocalTopDock,LocalHistory_LastDock=LocalTopDock,LocalHistory_DockRow=0,LocalHistory_DockPos=207,LocalHistory_FloatLeft=0,LocalHistory_FloatTop=0,LocalHistory_FloatRightX=0,"
  561. "LocalNavigation_Visible=1,LocalNavigation_DockedTo=LocalTopDock,LocalNavigation_LastDock=LocalTopDock,LocalNavigation_DockRow=0,LocalNavigation_DockPos=287,LocalNavigation_FloatLeft=0,LocalNavigation_FloatTop=0,LocalNavigation_FloatRightX=0,"
  562. "LocalPath_Visible=1,LocalPath_DockedTo=LocalTopDock,LocalPath_LastDock=LocalTopDock,LocalPath_DockRow=0,LocalPath_DockPos=0,LocalPath_FloatLeft=0,LocalPath_FloatTop=0,LocalPath_FloatRightX=0,"
  563. "LocalFile_Visible=1,LocalFile_DockedTo=LocalTopDock,LocalFile_LastDock=LocalTopDock,LocalFile_DockRow=1,LocalFile_DockPos=0,LocalFile_FloatLeft=0,LocalFile_FloatTop=0,LocalFile_FloatRightX=0,"
  564. "LocalSelection_Visible=1,LocalSelection_DockedTo=LocalTopDock,LocalSelection_LastDock=LocalTopDock,LocalSelection_DockRow=1,LocalSelection_DockPos=329,LocalSelection_FloatLeft=0,LocalSelection_FloatTop=0,LocalSelection_FloatRightX=0,"
  565. "Toolbar2_Visible=0,Toolbar2_DockedTo=BottomDock,Toolbar2_LastDock=BottomDock,Toolbar2_DockRow=1,Toolbar2_DockPos=0,Toolbar2_FloatLeft=0,Toolbar2_FloatTop=0,Toolbar2_FloatRightX=1,"
  566. "CommandLine_Visible=0,CommandLine_DockedTo=BottomDock,CommandLine_LastDock=BottomDock,CommandLine_DockRow=0,CommandLine_DockPos=0,CommandLine_FloatLeft=0,CommandLine_FloatTop=0,CommandLine_FloatRightX=0";
  567. FScpCommander.CurrentPanel = osLocal;
  568. FScpCommander.CompareByTime = true;
  569. FScpCommander.CompareBySize = false;
  570. FScpCommander.TreeOnLeft = false;
  571. FScpCommander.ExplorerKeyboardShortcuts = false;
  572. FScpCommander.SystemContextMenu = false;
  573. FScpCommander.RemotePanel.DirViewParams = L"0;1;0|150,1;70,1;120,1;79,1;62,1;55,0;20,0;150,0;125,0|6;7;8;0;1;2;3;4;5";
  574. FScpCommander.RemotePanel.StatusBar = true;
  575. FScpCommander.RemotePanel.DriveView = false;
  576. FScpCommander.RemotePanel.DriveViewHeight = 100;
  577. FScpCommander.RemotePanel.DriveViewWidth = 100;
  578. FScpCommander.LocalPanel.DirViewParams = L"0;1;0|150,1;70,1;101,1;120,1;55,0;55,0|5;0;1;2;3;4";
  579. FScpCommander.LocalPanel.StatusBar = true;
  580. FScpCommander.LocalPanel.DriveView = false;
  581. FScpCommander.LocalPanel.DriveViewHeight = 100;
  582. FScpCommander.LocalPanel.DriveViewWidth = 100;
  583. FBookmarks->Clear();
  584. }
  585. //---------------------------------------------------------------------------
  586. void __fastcall TWinConfiguration::DefaultLocalized()
  587. {
  588. TGUIConfiguration::DefaultLocalized();
  589. if (FCustomCommandsDefaults)
  590. {
  591. FCustomCommandList->Clear();
  592. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_EXECUTE), L"\"./!\"", 0);
  593. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TOUCH), L"touch \"!\"", ccApplyToDirectories | ccRecursive);
  594. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_TAR),
  595. FORMAT(L"tar -cz -f \"!?%s?archive.tgz!\" !&",
  596. (LoadStr(CUSTOM_COMMAND_TAR_ARCHIVE))), ccApplyToDirectories);
  597. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_UNTAR),
  598. FORMAT(L"tar -xz --directory=\"!?%s?.!\" -f \"!\"",
  599. (LoadStr(CUSTOM_COMMAND_UNTAR_DIRECTORY))), 0);
  600. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_GREP),
  601. FORMAT(L"grep \"!?%s?!\" !&", (LoadStr(CUSTOM_COMMAND_GREP_PATTERN))),
  602. ccShowResults);
  603. if (Win32Platform == VER_PLATFORM_WIN32_NT)
  604. {
  605. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_FC),
  606. L"cmd /c fc \"!\" \"\!^!\" | more && pause", ccLocal);
  607. }
  608. FCustomCommandList->Add(LoadStr(CUSTOM_COMMAND_PRINT), L"notepad.exe /p \"!\"", ccLocal);
  609. FCustomCommandList->Reset();
  610. FCustomCommandsDefaults = true;
  611. }
  612. }
  613. //---------------------------------------------------------------------------
  614. bool __fastcall TWinConfiguration::DetectRegistryStorage(HKEY RootKey)
  615. {
  616. bool Result = false;
  617. TRegistryStorage * Storage = new TRegistryStorage(RegistryStorageKey, RootKey);
  618. try
  619. {
  620. if (Storage->OpenRootKey(false))
  621. {
  622. Result = true;
  623. Storage->CloseSubKey();
  624. }
  625. }
  626. __finally
  627. {
  628. delete Storage;
  629. }
  630. return Result;
  631. }
  632. //---------------------------------------------------------------------------
  633. bool __fastcall TWinConfiguration::CanWriteToStorage()
  634. {
  635. bool Result = false;
  636. try
  637. {
  638. THierarchicalStorage * Storage = CreateScpStorage(false);
  639. try
  640. {
  641. Storage->AccessMode = smReadWrite;
  642. // This is actually not very good test, as we end up potentially with
  643. // the very same config, and TIniFileStorage file won't even try to
  644. // write the file then. Lucliky, we use this for empty config only,
  645. // so we end up with at least an empty section.
  646. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  647. {
  648. Storage->WriteBool(L"WriteTest", true);
  649. Storage->DeleteValue(L"WriteTest");
  650. }
  651. Storage->Flush();
  652. }
  653. __finally
  654. {
  655. delete Storage;
  656. }
  657. Result = true;
  658. }
  659. catch(...)
  660. {
  661. }
  662. return Result;
  663. }
  664. //---------------------------------------------------------------------------
  665. TStorage __fastcall TWinConfiguration::GetStorage()
  666. {
  667. if (FStorage == stDetect)
  668. {
  669. if (FindResourceEx(NULL, RT_RCDATA, L"WINSCP_SESSION",
  670. MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
  671. {
  672. FTemporarySessionFile =
  673. IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscps.tmp";
  674. DumpResourceToFile(L"WINSCP_SESSION", FTemporarySessionFile);
  675. FEmbeddedSessions = true;
  676. FTemporaryKeyFile =
  677. IncludeTrailingBackslash(SystemTemporaryDirectory()) + L"winscpk.tmp";
  678. if (!DumpResourceToFile(L"WINSCP_KEY", FTemporaryKeyFile))
  679. {
  680. FTemporaryKeyFile = L"";
  681. }
  682. }
  683. FStorage = stIniFile;
  684. if (!FileExists(IniFileStorageNameForReading))
  685. {
  686. if (DetectRegistryStorage(HKEY_CURRENT_USER) ||
  687. DetectRegistryStorage(HKEY_LOCAL_MACHINE) ||
  688. !CanWriteToStorage())
  689. {
  690. FStorage = stRegistry;
  691. }
  692. }
  693. }
  694. return TCustomWinConfiguration::GetStorage();
  695. }
  696. //---------------------------------------------------------------------------
  697. void __fastcall TWinConfiguration::Saved()
  698. {
  699. TCustomWinConfiguration::Saved();
  700. FBookmarks->ModifyAll(false);
  701. FCustomCommandList->Reset();
  702. FEditorList->Saved();
  703. }
  704. //---------------------------------------------------------------------------
  705. void __fastcall TWinConfiguration::RecryptPasswords()
  706. {
  707. TCustomWinConfiguration::RecryptPasswords();
  708. TTerminalManager * Manager = TTerminalManager::Instance(false);
  709. assert(Manager != NULL);
  710. if (Manager != NULL)
  711. {
  712. Manager->RecryptPasswords();
  713. }
  714. }
  715. //---------------------------------------------------------------------------
  716. bool __fastcall TWinConfiguration::GetUseMasterPassword()
  717. {
  718. return FUseMasterPassword;
  719. }
  720. //---------------------------------------------------------------------------
  721. THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool SessionList)
  722. {
  723. if (SessionList && !FTemporarySessionFile.IsEmpty())
  724. {
  725. return new TIniFileStorage(FTemporarySessionFile);
  726. }
  727. else
  728. {
  729. return TCustomWinConfiguration::CreateScpStorage(SessionList);
  730. }
  731. }
  732. //---------------------------------------------------------------------------
  733. // duplicated from core\configuration.cpp
  734. #define LASTELEM(ELEM) \
  735. ELEM.SubString(ELEM.LastDelimiter(L".>")+1, ELEM.Length() - ELEM.LastDelimiter(L".>"))
  736. #define BLOCK(KEY, CANCREATE, BLOCK) \
  737. if (Storage->OpenSubKey(KEY, CANCREATE, true)) try { BLOCK } __finally { Storage->CloseSubKey(); }
  738. #define KEY(TYPE, VAR) KEYEX(TYPE, VAR, PropertyToKey(TEXT(#VAR)))
  739. #define REGCONFIG(CANCREATE) \
  740. BLOCK(L"Interface", CANCREATE, \
  741. KEYEX(Integer,DoubleClickAction, L"CopyOnDoubleClick"); \
  742. KEY(Bool, CopyOnDoubleClickConfirmation); \
  743. KEY(Bool, DDAllowMove); \
  744. KEY(Bool, DDAllowMoveInit); \
  745. KEYEX(Integer, DDTransferConfirmation, L"DDTransferConfirmation2"); \
  746. KEY(String, DDTemporaryDirectory); \
  747. KEY(Bool, DDWarnLackOfTempSpace); \
  748. KEY(Float, DDWarnLackOfTempSpaceRatio); \
  749. KEY(Bool, DeleteToRecycleBin); \
  750. KEY(Bool, DimmHiddenFiles); \
  751. KEY(Bool, RenameWholeName); \
  752. KEY(Bool, SelectDirectories); \
  753. KEY(String, SelectMask); \
  754. KEY(Bool, ShowHiddenFiles); \
  755. KEY(Bool, FormatSizeBytes); \
  756. KEY(Bool, ShowInaccesibleDirectories); \
  757. KEY(Bool, ConfirmTransferring); \
  758. KEY(Bool, ConfirmDeleting); \
  759. KEY(Bool, ConfirmRecycling); \
  760. KEY(Bool, ConfirmClosingSession); \
  761. KEY(String, AutoStartSession); \
  762. KEY(Bool, UseLocationProfiles); \
  763. KEY(Bool, UseSharedBookmarks); \
  764. KEY(Integer, LocaleSafe); \
  765. KEY(Bool, DDExtEnabled); \
  766. KEY(Integer, DDExtTimeout); \
  767. KEY(Bool, DefaultDirIsHome); \
  768. KEY(Bool, TemporaryDirectoryAppendSession); \
  769. KEY(Bool, TemporaryDirectoryAppendPath); \
  770. KEY(Bool, TemporaryDirectoryCleanup); \
  771. KEY(Bool, ConfirmTemporaryDirectoryCleanup); \
  772. KEY(Bool, PreservePanelState); \
  773. KEY(String, Theme); \
  774. KEY(String, LastStoredSession); \
  775. KEY(Bool, AutoSaveWorkspace); \
  776. KEY(Bool, AutoSaveWorkspacePasswords); \
  777. KEY(String, AutoWorkspace); \
  778. KEY(Integer, PathInCaption); \
  779. KEY(Bool, MinimizeToTray); \
  780. KEY(Bool, BalloonNotifications); \
  781. KEY(Integer, NotificationsTimeout); \
  782. KEY(Integer, NotificationsStickTime); \
  783. KEY(Bool, CopyParamAutoSelectNotice); \
  784. KEY(Bool, LockToolbars); \
  785. KEY(Bool, SelectiveToolbarText); \
  786. KEY(Bool, AutoOpenInPutty); \
  787. KEY(Bool, RefreshRemotePanel); \
  788. KEY(DateTime, RefreshRemotePanelInterval); \
  789. KEY(Bool, FullRowSelect); \
  790. KEY(Bool, OfferedEditorAutoConfig); \
  791. KEY(Integer, LastMonitor); \
  792. KEY(String, VersionHistory); \
  793. KEY(Bool, EnableQueueByDefault); \
  794. KEY(String, OpenedStoredSessionFolders); \
  795. KEY(Bool, AutoImportedFromPuttyOrFilezilla); \
  796. ); \
  797. BLOCK(L"Interface\\Editor", CANCREATE, \
  798. KEY(String, Editor.FontName); \
  799. KEY(Integer, Editor.FontHeight); \
  800. KEY(Integer, Editor.FontStyle); \
  801. KEY(Integer, Editor.FontCharset); \
  802. KEY(Bool, Editor.WordWrap); \
  803. KEY(String, Editor.FindText); \
  804. KEY(String, Editor.ReplaceText); \
  805. KEY(Bool, Editor.FindMatchCase); \
  806. KEY(Bool, Editor.FindWholeWord); \
  807. KEY(Bool, Editor.FindDown); \
  808. KEY(Integer, Editor.TabSize); \
  809. KEY(Integer, Editor.MaxEditors); \
  810. KEY(Integer, Editor.EarlyClose); \
  811. KEY(Bool, Editor.SDIShellEditor); \
  812. KEY(String, Editor.WindowParams); \
  813. KEY(Integer, Editor.Encoding); \
  814. KEY(Bool, Editor.WarnOnEncodingFallback); \
  815. ); \
  816. BLOCK(L"Interface\\QueueView", CANCREATE, \
  817. KEY(Integer, QueueView.Height); \
  818. KEY(String, QueueView.Layout); \
  819. KEY(Integer, QueueView.Show); \
  820. KEY(Integer, QueueView.LastHideShow); \
  821. KEY(Bool, QueueView.ToolBar); \
  822. KEY(Bool, QueueView.Label); \
  823. ); \
  824. BLOCK(L"Interface\\Updates", CANCREATE, \
  825. KEY(Integer, FUpdates.Period); \
  826. KEY(DateTime, FUpdates.LastCheck); \
  827. KEY(Integer, FUpdates.HaveResults); \
  828. KEY(Integer, FUpdates.ShownResults); \
  829. KEY(Integer, FUpdates.BetaVersions); \
  830. KEY(Integer, FUpdates.ConnectionType); \
  831. KEY(String, FUpdates.ProxyHost); \
  832. KEY(Integer, FUpdates.ProxyPort); \
  833. KEY(Integer, FUpdates.Results.ForVersion); \
  834. KEY(Integer, FUpdates.Results.Version); \
  835. KEY(String, FUpdates.Results.Message); \
  836. KEY(Integer, FUpdates.Results.Critical); \
  837. KEY(String, FUpdates.Results.Release); \
  838. KEY(Bool, FUpdates.Results.Disabled); \
  839. KEY(String, FUpdates.Results.Url); \
  840. KEY(String, FUpdates.Results.UrlButton); \
  841. KEY(String, FUpdates.DotNetVersion); \
  842. KEY(String, FUpdates.ConsoleVersion); \
  843. ); \
  844. BLOCK(L"Interface\\Explorer", CANCREATE, \
  845. KEY(String, ScpExplorer.ToolbarsLayout); \
  846. KEY(String, ScpExplorer.DirViewParams); \
  847. KEY(String, ScpExplorer.LastLocalTargetDirectory); \
  848. KEY(Bool, ScpExplorer.SessionsTabs); \
  849. KEY(Bool, ScpExplorer.StatusBar); \
  850. KEY(String, ScpExplorer.WindowParams); \
  851. KEY(Integer, ScpExplorer.ViewStyle); \
  852. KEY(Bool, ScpExplorer.ShowFullAddress); \
  853. KEY(Bool, ScpExplorer.DriveView); \
  854. KEY(Integer, ScpExplorer.DriveViewWidth); \
  855. ); \
  856. BLOCK(L"Interface\\Commander", CANCREATE, \
  857. KEY(String, ScpCommander.ToolbarsLayout); \
  858. KEY(Integer, ScpCommander.CurrentPanel); \
  859. KEY(Float, ScpCommander.LocalPanelWidth); \
  860. KEY(Bool, ScpCommander.SwappedPanels); \
  861. KEY(Bool, ScpCommander.SessionsTabs); \
  862. KEY(Bool, ScpCommander.StatusBar); \
  863. KEY(String, ScpCommander.WindowParams); \
  864. KEYEX(Integer, ScpCommander.NortonLikeMode, L"ExplorerStyleSelection"); \
  865. KEY(Bool, ScpCommander.PreserveLocalDirectory); \
  866. KEY(Bool, ScpCommander.CompareByTime); \
  867. KEY(Bool, ScpCommander.CompareBySize); \
  868. KEY(Bool, ScpCommander.TreeOnLeft); \
  869. KEY(Bool, ScpCommander.ExplorerKeyboardShortcuts); \
  870. KEY(Bool, ScpCommander.SystemContextMenu); \
  871. ); \
  872. BLOCK(L"Interface\\Commander\\LocalPanel", CANCREATE, \
  873. KEY(String, ScpCommander.LocalPanel.DirViewParams); \
  874. KEY(Bool, ScpCommander.LocalPanel.StatusBar); \
  875. KEY(Bool, ScpCommander.LocalPanel.DriveView); \
  876. KEY(Integer, ScpCommander.LocalPanel.DriveViewHeight); \
  877. KEY(Integer, ScpCommander.LocalPanel.DriveViewWidth); \
  878. ); \
  879. BLOCK(L"Interface\\Commander\\RemotePanel", CANCREATE, \
  880. KEY(String, ScpCommander.RemotePanel.DirViewParams); \
  881. KEY(Bool, ScpCommander.RemotePanel.StatusBar); \
  882. KEY(Bool, ScpCommander.RemotePanel.DriveView); \
  883. KEY(Integer, ScpCommander.RemotePanel.DriveViewHeight); \
  884. KEY(Integer, ScpCommander.RemotePanel.DriveViewWidth); \
  885. ); \
  886. BLOCK(L"Logging", CANCREATE, \
  887. KEY(Bool, LogWindowOnStartup); \
  888. KEY(String, LogWindowParams); \
  889. ); \
  890. BLOCK(L"Security", CANCREATE, \
  891. KEYEX(Bool, FUseMasterPassword, L"UseMasterPassword"); \
  892. KEYEX(String,FMasterPasswordVerifier, L"MasterPasswordVerifier"); \
  893. );
  894. //---------------------------------------------------------------------------
  895. void __fastcall TWinConfiguration::SaveData(THierarchicalStorage * Storage, bool All)
  896. {
  897. TCustomWinConfiguration::SaveData(Storage, All);
  898. // duplicated from core\configuration.cpp
  899. #define KEYEX(TYPE, VAR, NAME) Storage->Write ## TYPE(NAME, VAR)
  900. REGCONFIG(true);
  901. #undef KEYEX
  902. if (Storage->OpenSubKey(L"Bookmarks", true))
  903. {
  904. FBookmarks->Save(Storage, All);
  905. Storage->CloseSubKey();
  906. }
  907. if ((All && !FCustomCommandsDefaults) || FCustomCommandList->Modified)
  908. {
  909. FCustomCommandList->Save(Storage);
  910. }
  911. if ((All || FEditorList->Modified) &&
  912. Storage->OpenSubKey(L"Interface\\Editor", true, true))
  913. try
  914. {
  915. FEditorList->Save(Storage);
  916. }
  917. __finally
  918. {
  919. Storage->CloseSubKey();
  920. }
  921. }
  922. //---------------------------------------------------------------------------
  923. void __fastcall TWinConfiguration::LoadFrom(THierarchicalStorage * Storage)
  924. {
  925. FLegacyEditor = new TEditorPreferences();
  926. try
  927. {
  928. FLegacyEditor->LegacyDefaults();
  929. TCustomWinConfiguration::LoadFrom(Storage);
  930. // This needs to be done even if there's no Configuration key in the storage,
  931. // so it cannot be in LoadData
  932. int EditorCount = FEditorList->Count;
  933. if (EditorCount == 0)
  934. {
  935. TEditorPreferences * AlternativeEditor = NULL;
  936. try
  937. {
  938. if (FLegacyEditor->Data->Editor == edInternal)
  939. {
  940. if (!FLegacyEditor->Data->ExternalEditor.IsEmpty())
  941. {
  942. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  943. AlternativeEditor->GetData()->Editor = edExternal;
  944. FLegacyEditor->GetData()->ExternalEditor = L"";
  945. }
  946. }
  947. else
  948. {
  949. if (FLegacyEditor->Data->ExternalEditor.IsEmpty())
  950. {
  951. FLegacyEditor->GetData()->Editor = edInternal;
  952. }
  953. else
  954. {
  955. AlternativeEditor = new TEditorPreferences(*FLegacyEditor);
  956. AlternativeEditor->GetData()->Editor = edInternal;
  957. }
  958. }
  959. }
  960. catch(...)
  961. {
  962. delete AlternativeEditor;
  963. throw;
  964. }
  965. FEditorList->Add(FLegacyEditor);
  966. FLegacyEditor = NULL;
  967. if (AlternativeEditor != NULL)
  968. {
  969. FEditorList->Add(AlternativeEditor);
  970. }
  971. }
  972. }
  973. __finally
  974. {
  975. delete FLegacyEditor;
  976. FLegacyEditor = NULL;
  977. }
  978. if (FUpdates.ConnectionType == -1)
  979. {
  980. FUpdates.ConnectionType = (FUpdates.ProxyHost.IsEmpty() ? ctAuto : ctProxy);
  981. }
  982. AddVersionToHistory();
  983. }
  984. //---------------------------------------------------------------------------
  985. void __fastcall TWinConfiguration::LoadData(THierarchicalStorage * Storage)
  986. {
  987. TCustomWinConfiguration::LoadData(Storage);
  988. // duplicated from core\configuration.cpp
  989. #define KEYEX(TYPE, VAR, NAME) VAR = Storage->Read ## TYPE(NAME, VAR)
  990. #pragma warn -eas
  991. REGCONFIG(false);
  992. #pragma warn +eas
  993. #undef KEYEX
  994. if (Storage->OpenSubKey(L"Bookmarks", false))
  995. {
  996. FBookmarks->Load(Storage);
  997. Storage->CloseSubKey();
  998. }
  999. if (Storage->HasSubKey("CustomCommands"))
  1000. {
  1001. FCustomCommandList->Load(Storage);
  1002. FCustomCommandsDefaults = false;
  1003. }
  1004. else if (FCustomCommandList->Modified)
  1005. {
  1006. // can this (=reloading of configuration) even happen?
  1007. // if it does, shouldn't we reset default commands?
  1008. assert(false);
  1009. FCustomCommandList->Clear();
  1010. FCustomCommandsDefaults = false;
  1011. }
  1012. FCustomCommandList->Reset();
  1013. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1014. try
  1015. {
  1016. FEditorList->Clear();
  1017. FEditorList->Load(Storage);
  1018. }
  1019. __finally
  1020. {
  1021. Storage->CloseSubKey();
  1022. }
  1023. // load legacy editor configuration
  1024. assert(FLegacyEditor != NULL);
  1025. if (Storage->OpenSubKey(L"Interface\\Editor", false, true))
  1026. {
  1027. try
  1028. {
  1029. FLegacyEditor->Load(Storage, true);
  1030. }
  1031. __finally
  1032. {
  1033. Storage->CloseSubKey();
  1034. }
  1035. }
  1036. }
  1037. //---------------------------------------------------------------------------
  1038. void __fastcall TWinConfiguration::LoadAdmin(THierarchicalStorage * Storage)
  1039. {
  1040. TCustomWinConfiguration::LoadAdmin(Storage);
  1041. FDisableOpenEdit = Storage->ReadBool(L"DisableOpenEdit", FDisableOpenEdit);
  1042. FDefaultUpdatesPeriod = Storage->ReadInteger(L"DefaultUpdatesPeriod", FDefaultUpdatesPeriod);
  1043. }
  1044. //---------------------------------------------------------------------------
  1045. void __fastcall TWinConfiguration::CopyData(THierarchicalStorage * Source, THierarchicalStorage * Target)
  1046. {
  1047. TCustomWinConfiguration::CopyData(Source, Target);
  1048. if (Source->OpenSubKey(ConfigurationSubKey, false))
  1049. {
  1050. if (Target->OpenSubKey(ConfigurationSubKey, true))
  1051. {
  1052. Target->WriteString(L"JumpList", Source->ReadString(L"JumpList", L""));
  1053. Target->WriteString(L"JumpListWorkspaces", Source->ReadString(L"JumpListWorkspaces", L""));
  1054. Target->CloseSubKey();
  1055. }
  1056. Source->CloseSubKey();
  1057. }
  1058. }
  1059. //---------------------------------------------------------------------------
  1060. void __fastcall TWinConfiguration::ClearTemporaryLoginData()
  1061. {
  1062. if (!FTemporaryKeyFile.IsEmpty())
  1063. {
  1064. DeleteFile(FTemporaryKeyFile);
  1065. FTemporaryKeyFile = "";
  1066. }
  1067. }
  1068. //---------------------------------------------------------------------------
  1069. void __fastcall TWinConfiguration::AddVersionToHistory()
  1070. {
  1071. int CurrentVersion = CompoundVersion;
  1072. int From = 1;
  1073. bool CurrentVersionPresent = false;
  1074. while (!CurrentVersionPresent && (From < FVersionHistory.Length()))
  1075. {
  1076. UnicodeString VersionInfo = CopyToChars(FVersionHistory, From, L";", true);
  1077. UnicodeString VersionStr = ::CutToChar(VersionInfo, L',', true);
  1078. int Version;
  1079. if (TryStrToInt(VersionStr, Version) &&
  1080. (Version == CurrentVersion))
  1081. {
  1082. CurrentVersionPresent = true;
  1083. }
  1084. }
  1085. if (!CurrentVersionPresent)
  1086. {
  1087. UnicodeString CurrentVersionInfo =
  1088. IntToStr(CurrentVersion) + L"," + FileInfoString[L"ReleaseType"];
  1089. AddToList(FVersionHistory, CurrentVersionInfo, L';');
  1090. }
  1091. Usage->Set(L"AnyBetaUsed", AnyBetaInVersionHistory);
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. bool __fastcall TWinConfiguration::DoIsBeta(const UnicodeString & ReleaseType)
  1095. {
  1096. return AnsiSameText(ReleaseType, L"beta") || AnsiSameText(ReleaseType, L"rc");
  1097. }
  1098. //---------------------------------------------------------------------------
  1099. bool __fastcall TWinConfiguration::GetIsBeta()
  1100. {
  1101. return DoIsBeta(FileInfoString[L"ReleaseType"]);
  1102. }
  1103. //---------------------------------------------------------------------------
  1104. bool __fastcall TWinConfiguration::GetAnyBetaInVersionHistory()
  1105. {
  1106. int From = 1;
  1107. bool AnyBeta = false;
  1108. while (!AnyBeta && (From < VersionHistory.Length()))
  1109. {
  1110. UnicodeString VersionInfo = CopyToChars(VersionHistory, From, L";", true);
  1111. ::CutToChar(VersionInfo, L',', true);
  1112. UnicodeString ReleaseType = ::CutToChar(VersionInfo, ',', true);
  1113. if (DoIsBeta(ReleaseType))
  1114. {
  1115. AnyBeta = true;
  1116. }
  1117. }
  1118. return AnyBeta;
  1119. }
  1120. //---------------------------------------------------------------------------
  1121. bool __fastcall TWinConfiguration::GetDDExtInstalled()
  1122. {
  1123. if (FDDExtInstalled < 0)
  1124. {
  1125. if (IsWin64())
  1126. {
  1127. // temporarily consider dragext always present on 64-bit system
  1128. FDDExtInstalled = 1;
  1129. }
  1130. else
  1131. {
  1132. void * DragExtRef;
  1133. int CreateResult =
  1134. CoCreateInstance(CLSID_ShellExtension, NULL,
  1135. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
  1136. &DragExtRef);
  1137. bool Result = (CreateResult == S_OK);
  1138. FDDExtInstalled = (Result ? 1 : 0);
  1139. if (Result)
  1140. {
  1141. reinterpret_cast<IUnknown *>(DragExtRef)->Release();
  1142. CoFreeUnusedLibraries();
  1143. }
  1144. }
  1145. }
  1146. return (FDDExtInstalled > 0);
  1147. }
  1148. //---------------------------------------------------------------------------
  1149. RawByteString __fastcall TWinConfiguration::StronglyRecryptPassword(RawByteString Password, UnicodeString Key)
  1150. {
  1151. RawByteString Dummy;
  1152. RawByteString Result;
  1153. if (GetExternalEncryptedPassword(Password, Dummy) ||
  1154. !FUseMasterPassword)
  1155. {
  1156. // already-strongly encrypted
  1157. // or no master password set, so we cannot strongly-encrypt it
  1158. Result = Password;
  1159. }
  1160. else
  1161. {
  1162. UnicodeString PasswordText =
  1163. TCustomWinConfiguration::DecryptPassword(Password, Key);
  1164. if (!PasswordText.IsEmpty())
  1165. {
  1166. assert(!FPlainMasterPasswordEncrypt.IsEmpty());
  1167. Password = ScramblePassword(PasswordText);
  1168. AES256EncyptWithMAC(Password, FPlainMasterPasswordEncrypt, Result);
  1169. Result = SetExternalEncryptedPassword(Result);
  1170. }
  1171. }
  1172. return Result;
  1173. }
  1174. //---------------------------------------------------------------------------
  1175. UnicodeString __fastcall TWinConfiguration::DecryptPassword(RawByteString Password, UnicodeString Key)
  1176. {
  1177. UnicodeString Result;
  1178. RawByteString Buf;
  1179. if (GetExternalEncryptedPassword(Password, Buf))
  1180. {
  1181. if (FDontDecryptPasswords == 0)
  1182. {
  1183. if (FPlainMasterPasswordDecrypt.IsEmpty())
  1184. {
  1185. assert(FOnMasterPasswordPrompt != NULL);
  1186. FOnMasterPasswordPrompt();
  1187. }
  1188. if (!AES256DecryptWithMAC(Buf, FPlainMasterPasswordDecrypt, Buf) ||
  1189. !UnscramblePassword(Buf, Result))
  1190. {
  1191. throw Exception(LoadStr(DECRYPT_PASSWORD_ERROR));
  1192. }
  1193. }
  1194. else
  1195. {
  1196. Abort();
  1197. }
  1198. }
  1199. else
  1200. {
  1201. Result = TCustomWinConfiguration::DecryptPassword(Password, Key);
  1202. }
  1203. return Result;
  1204. }
  1205. //---------------------------------------------------------------------------
  1206. void __fastcall TWinConfiguration::SetMasterPassword(UnicodeString value)
  1207. {
  1208. if (FUseMasterPassword && ValidateMasterPassword(value))
  1209. {
  1210. // just store the plain-text version of the password
  1211. FPlainMasterPasswordEncrypt = value;
  1212. FPlainMasterPasswordDecrypt = value;
  1213. }
  1214. else
  1215. {
  1216. RawByteString Verifier;
  1217. AES256CreateVerifier(value, Verifier);
  1218. FMasterPasswordVerifier = BytesToHex(Verifier);
  1219. FPlainMasterPasswordEncrypt = value;
  1220. FUseMasterPassword = true;
  1221. try
  1222. {
  1223. RecryptPasswords();
  1224. }
  1225. __finally
  1226. {
  1227. FPlainMasterPasswordDecrypt = value;
  1228. }
  1229. }
  1230. }
  1231. //---------------------------------------------------------------------------
  1232. bool __fastcall TWinConfiguration::ValidateMasterPassword(UnicodeString value)
  1233. {
  1234. assert(UseMasterPassword);
  1235. assert(!FMasterPasswordVerifier.IsEmpty());
  1236. return AES256Verify(value, HexToBytes(FMasterPasswordVerifier));
  1237. }
  1238. //---------------------------------------------------------------------------
  1239. void __fastcall TWinConfiguration::ClearMasterPassword()
  1240. {
  1241. FMasterPasswordVerifier = L"";
  1242. FUseMasterPassword = false;
  1243. Shred(FPlainMasterPasswordEncrypt);
  1244. try
  1245. {
  1246. RecryptPasswords();
  1247. }
  1248. __finally
  1249. {
  1250. Shred(FPlainMasterPasswordDecrypt);
  1251. }
  1252. }
  1253. //---------------------------------------------------------------------------
  1254. void __fastcall TWinConfiguration::AskForMasterPasswordIfNotSet()
  1255. {
  1256. if (FPlainMasterPasswordEncrypt.IsEmpty())
  1257. {
  1258. assert(FOnMasterPasswordPrompt != NULL);
  1259. FOnMasterPasswordPrompt();
  1260. assert(!FPlainMasterPasswordDecrypt.IsEmpty());
  1261. }
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. void __fastcall TWinConfiguration::SetLogWindowOnStartup(bool value)
  1265. {
  1266. SET_CONFIG_PROPERTY(LogWindowOnStartup);
  1267. }
  1268. //---------------------------------------------------------------------------
  1269. void __fastcall TWinConfiguration::SetLogWindowParams(UnicodeString value)
  1270. {
  1271. SET_CONFIG_PROPERTY(LogWindowParams);
  1272. }
  1273. //---------------------------------------------------------------------------
  1274. void __fastcall TWinConfiguration::SetDDAllowMove(bool value)
  1275. {
  1276. SET_CONFIG_PROPERTY(DDAllowMove);
  1277. }
  1278. //---------------------------------------------------------------------------
  1279. void __fastcall TWinConfiguration::SetDDAllowMoveInit(bool value)
  1280. {
  1281. SET_CONFIG_PROPERTY(DDAllowMoveInit);
  1282. }
  1283. //---------------------------------------------------------------------------
  1284. void __fastcall TWinConfiguration::SetDDTransferConfirmation(TAutoSwitch value)
  1285. {
  1286. SET_CONFIG_PROPERTY(DDTransferConfirmation);
  1287. }
  1288. //---------------------------------------------------------------------------
  1289. void __fastcall TWinConfiguration::SetDDTemporaryDirectory(UnicodeString value)
  1290. {
  1291. SET_CONFIG_PROPERTY(DDTemporaryDirectory);
  1292. }
  1293. //---------------------------------------------------------------------------
  1294. void __fastcall TWinConfiguration::SetDDExtEnabled(bool value)
  1295. {
  1296. SET_CONFIG_PROPERTY(DDExtEnabled);
  1297. }
  1298. //---------------------------------------------------------------------------
  1299. void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
  1300. {
  1301. SET_CONFIG_PROPERTY(DDExtTimeout);
  1302. }
  1303. //---------------------------------------------------------------------------
  1304. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpace(bool value)
  1305. {
  1306. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpace);
  1307. }
  1308. //---------------------------------------------------------------------------
  1309. void __fastcall TWinConfiguration::SetDDWarnLackOfTempSpaceRatio(double value)
  1310. {
  1311. SET_CONFIG_PROPERTY(DDWarnLackOfTempSpaceRatio);
  1312. }
  1313. //---------------------------------------------------------------------------
  1314. void __fastcall TWinConfiguration::SetScpExplorer(TScpExplorerConfiguration value)
  1315. {
  1316. SET_CONFIG_PROPERTY(ScpExplorer);
  1317. }
  1318. //---------------------------------------------------------------------------
  1319. void __fastcall TWinConfiguration::SetScpCommander(TScpCommanderConfiguration value)
  1320. {
  1321. SET_CONFIG_PROPERTY(ScpCommander);
  1322. }
  1323. //---------------------------------------------------------------------------
  1324. void __fastcall TWinConfiguration::SetEditor(TEditorConfiguration value)
  1325. {
  1326. SET_CONFIG_PROPERTY(Editor);
  1327. }
  1328. //---------------------------------------------------------------------------
  1329. void __fastcall TWinConfiguration::SetQueueView(TQueueViewConfiguration value)
  1330. {
  1331. SET_CONFIG_PROPERTY(QueueView);
  1332. }
  1333. //---------------------------------------------------------------------------
  1334. void __fastcall TWinConfiguration::SetEnableQueueByDefault(bool value)
  1335. {
  1336. SET_CONFIG_PROPERTY(EnableQueueByDefault);
  1337. }
  1338. //---------------------------------------------------------------------------
  1339. TUpdatesConfiguration __fastcall TWinConfiguration::GetUpdates()
  1340. {
  1341. TUpdatesConfiguration Result;
  1342. {
  1343. TGuard Guard(FCriticalSection);
  1344. Result = FUpdates;
  1345. }
  1346. return Result;
  1347. }
  1348. //---------------------------------------------------------------------------
  1349. void __fastcall TWinConfiguration::SetUpdates(TUpdatesConfiguration value)
  1350. {
  1351. TGuard Guard(FCriticalSection);
  1352. // do not use SET_CONFIG_PROPERTY to avoid OnChange handler call (not synchronized)
  1353. FUpdates = value;
  1354. }
  1355. //---------------------------------------------------------------------------
  1356. void __fastcall TWinConfiguration::SetVersionHistory(UnicodeString value)
  1357. {
  1358. SET_CONFIG_PROPERTY(VersionHistory);
  1359. }
  1360. //---------------------------------------------------------------------------
  1361. void __fastcall TWinConfiguration::SetDeleteToRecycleBin(bool value)
  1362. {
  1363. SET_CONFIG_PROPERTY(DeleteToRecycleBin);
  1364. }
  1365. //---------------------------------------------------------------------------
  1366. void __fastcall TWinConfiguration::SetSelectDirectories(bool value)
  1367. {
  1368. SET_CONFIG_PROPERTY(SelectDirectories);
  1369. }
  1370. //---------------------------------------------------------------------------
  1371. void __fastcall TWinConfiguration::SetShowHiddenFiles(bool value)
  1372. {
  1373. SET_CONFIG_PROPERTY(ShowHiddenFiles);
  1374. }
  1375. //---------------------------------------------------------------------------
  1376. void __fastcall TWinConfiguration::SetFormatSizeBytes(bool value)
  1377. {
  1378. SET_CONFIG_PROPERTY(FormatSizeBytes);
  1379. }
  1380. //---------------------------------------------------------------------------
  1381. void __fastcall TWinConfiguration::SetShowInaccesibleDirectories(bool value)
  1382. {
  1383. SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
  1384. }
  1385. //---------------------------------------------------------------------------
  1386. void __fastcall TWinConfiguration::SetConfirmTransferring(bool value)
  1387. {
  1388. SET_CONFIG_PROPERTY(ConfirmTransferring);
  1389. }
  1390. //---------------------------------------------------------------------------
  1391. void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
  1392. {
  1393. SET_CONFIG_PROPERTY(ConfirmDeleting);
  1394. }
  1395. //---------------------------------------------------------------------------
  1396. void __fastcall TWinConfiguration::SetConfirmRecycling(bool value)
  1397. {
  1398. SET_CONFIG_PROPERTY(ConfirmRecycling);
  1399. }
  1400. //---------------------------------------------------------------------------
  1401. void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
  1402. {
  1403. SET_CONFIG_PROPERTY(UseLocationProfiles);
  1404. }
  1405. //---------------------------------------------------------------------------
  1406. void __fastcall TWinConfiguration::SetUseSharedBookmarks(bool value)
  1407. {
  1408. SET_CONFIG_PROPERTY(UseSharedBookmarks);
  1409. }
  1410. //---------------------------------------------------------------------------
  1411. void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
  1412. {
  1413. SET_CONFIG_PROPERTY(ConfirmClosingSession);
  1414. }
  1415. //---------------------------------------------------------------------------
  1416. void __fastcall TWinConfiguration::SetDoubleClickAction(TDoubleClickAction value)
  1417. {
  1418. SET_CONFIG_PROPERTY(DoubleClickAction);
  1419. }
  1420. //---------------------------------------------------------------------------
  1421. void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
  1422. {
  1423. SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
  1424. }
  1425. //---------------------------------------------------------------------------
  1426. void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
  1427. {
  1428. SET_CONFIG_PROPERTY(DimmHiddenFiles);
  1429. }
  1430. //---------------------------------------------------------------------------
  1431. void __fastcall TWinConfiguration::SetRenameWholeName(bool value)
  1432. {
  1433. SET_CONFIG_PROPERTY(RenameWholeName);
  1434. }
  1435. //---------------------------------------------------------------------------
  1436. void __fastcall TWinConfiguration::SetAutoStartSession(UnicodeString value)
  1437. {
  1438. SET_CONFIG_PROPERTY(AutoStartSession);
  1439. }
  1440. //---------------------------------------------------------------------------
  1441. void __fastcall TWinConfiguration::SetExpertMode(bool value)
  1442. {
  1443. SET_CONFIG_PROPERTY(ExpertMode);
  1444. }
  1445. //---------------------------------------------------------------------------
  1446. void __fastcall TWinConfiguration::SetDefaultDirIsHome(bool value)
  1447. {
  1448. SET_CONFIG_PROPERTY(DefaultDirIsHome);
  1449. }
  1450. //---------------------------------------------------------------------------
  1451. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendSession(bool value)
  1452. {
  1453. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendSession);
  1454. }
  1455. //---------------------------------------------------------------------------
  1456. void __fastcall TWinConfiguration::SetTemporaryDirectoryAppendPath(bool value)
  1457. {
  1458. SET_CONFIG_PROPERTY(TemporaryDirectoryAppendPath);
  1459. }
  1460. //---------------------------------------------------------------------------
  1461. void __fastcall TWinConfiguration::SetTemporaryDirectoryCleanup(bool value)
  1462. {
  1463. SET_CONFIG_PROPERTY(TemporaryDirectoryCleanup);
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TWinConfiguration::SetConfirmTemporaryDirectoryCleanup(bool value)
  1467. {
  1468. SET_CONFIG_PROPERTY(ConfirmTemporaryDirectoryCleanup);
  1469. }
  1470. //---------------------------------------------------------------------------
  1471. void __fastcall TWinConfiguration::SetPreservePanelState(bool value)
  1472. {
  1473. SET_CONFIG_PROPERTY(PreservePanelState);
  1474. }
  1475. //---------------------------------------------------------------------------
  1476. void __fastcall TWinConfiguration::SetTheme(UnicodeString value)
  1477. {
  1478. SET_CONFIG_PROPERTY_EX(Theme, ConfigureInterface());
  1479. }
  1480. //---------------------------------------------------------------------------
  1481. void __fastcall TWinConfiguration::SetLastStoredSession(UnicodeString value)
  1482. {
  1483. SET_CONFIG_PROPERTY(LastStoredSession);
  1484. }
  1485. //---------------------------------------------------------------------------
  1486. void __fastcall TWinConfiguration::SetAutoSaveWorkspace(bool value)
  1487. {
  1488. SET_CONFIG_PROPERTY(AutoSaveWorkspace);
  1489. }
  1490. //---------------------------------------------------------------------------
  1491. void __fastcall TWinConfiguration::SetAutoSaveWorkspacePasswords(bool value)
  1492. {
  1493. SET_CONFIG_PROPERTY(AutoSaveWorkspacePasswords);
  1494. }
  1495. //---------------------------------------------------------------------------
  1496. void __fastcall TWinConfiguration::SetAutoWorkspace(UnicodeString value)
  1497. {
  1498. SET_CONFIG_PROPERTY(AutoWorkspace);
  1499. }
  1500. //---------------------------------------------------------------------------
  1501. void __fastcall TWinConfiguration::SetPathInCaption(TPathInCaption value)
  1502. {
  1503. SET_CONFIG_PROPERTY(PathInCaption);
  1504. }
  1505. //---------------------------------------------------------------------------
  1506. void __fastcall TWinConfiguration::SetMinimizeToTray(bool value)
  1507. {
  1508. SET_CONFIG_PROPERTY(MinimizeToTray);
  1509. }
  1510. //---------------------------------------------------------------------------
  1511. void __fastcall TWinConfiguration::SetBalloonNotifications(bool value)
  1512. {
  1513. SET_CONFIG_PROPERTY(BalloonNotifications);
  1514. }
  1515. //---------------------------------------------------------------------------
  1516. void __fastcall TWinConfiguration::SetNotificationsTimeout(unsigned int value)
  1517. {
  1518. SET_CONFIG_PROPERTY(NotificationsTimeout);
  1519. }
  1520. //---------------------------------------------------------------------------
  1521. void __fastcall TWinConfiguration::SetNotificationsStickTime(unsigned int value)
  1522. {
  1523. SET_CONFIG_PROPERTY(NotificationsStickTime);
  1524. }
  1525. //---------------------------------------------------------------------------
  1526. void __fastcall TWinConfiguration::SetCopyParamAutoSelectNotice(bool value)
  1527. {
  1528. SET_CONFIG_PROPERTY(CopyParamAutoSelectNotice);
  1529. }
  1530. //---------------------------------------------------------------------------
  1531. void __fastcall TWinConfiguration::SetLockToolbars(bool value)
  1532. {
  1533. SET_CONFIG_PROPERTY(LockToolbars);
  1534. }
  1535. //---------------------------------------------------------------------------
  1536. void __fastcall TWinConfiguration::SetSelectiveToolbarText(bool value)
  1537. {
  1538. SET_CONFIG_PROPERTY(SelectiveToolbarText);
  1539. }
  1540. //---------------------------------------------------------------------------
  1541. void __fastcall TWinConfiguration::SetAutoOpenInPutty(bool value)
  1542. {
  1543. SET_CONFIG_PROPERTY(AutoOpenInPutty);
  1544. }
  1545. //---------------------------------------------------------------------------
  1546. void __fastcall TWinConfiguration::SetRefreshRemotePanel(bool value)
  1547. {
  1548. SET_CONFIG_PROPERTY(RefreshRemotePanel);
  1549. }
  1550. //---------------------------------------------------------------------------
  1551. void __fastcall TWinConfiguration::SetRefreshRemotePanelInterval(TDateTime value)
  1552. {
  1553. SET_CONFIG_PROPERTY(RefreshRemotePanelInterval);
  1554. }
  1555. //---------------------------------------------------------------------------
  1556. void __fastcall TWinConfiguration::SetFullRowSelect(bool value)
  1557. {
  1558. SET_CONFIG_PROPERTY(FullRowSelect);
  1559. }
  1560. //---------------------------------------------------------------------------
  1561. void __fastcall TWinConfiguration::SetOfferedEditorAutoConfig(bool value)
  1562. {
  1563. SET_CONFIG_PROPERTY(OfferedEditorAutoConfig);
  1564. }
  1565. //---------------------------------------------------------------------------
  1566. void __fastcall TWinConfiguration::SetOpenedStoredSessionFolders(UnicodeString value)
  1567. {
  1568. SET_CONFIG_PROPERTY(OpenedStoredSessionFolders);
  1569. }
  1570. //---------------------------------------------------------------------------
  1571. void __fastcall TWinConfiguration::SetAutoImportedFromPuttyOrFilezilla(bool value)
  1572. {
  1573. SET_CONFIG_PROPERTY(AutoImportedFromPuttyOrFilezilla);
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. void __fastcall TWinConfiguration::SetCustomCommandList(TCustomCommandList * value)
  1577. {
  1578. assert(FCustomCommandList);
  1579. if (!FCustomCommandList->Equals(value))
  1580. {
  1581. FCustomCommandList->Assign(value);
  1582. FCustomCommandsDefaults = false;
  1583. }
  1584. }
  1585. //---------------------------------------------------------------------------
  1586. void __fastcall TWinConfiguration::SetBookmarks(UnicodeString Key,
  1587. TBookmarkList * value)
  1588. {
  1589. FBookmarks->Bookmarks[Key] = value;
  1590. Changed();
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(UnicodeString Key)
  1594. {
  1595. return FBookmarks->Bookmarks[Key];
  1596. }
  1597. //---------------------------------------------------------------------------
  1598. void __fastcall TWinConfiguration::SetSharedBookmarks(TBookmarkList * value)
  1599. {
  1600. FBookmarks->SharedBookmarks = value;
  1601. Changed();
  1602. }
  1603. //---------------------------------------------------------------------------
  1604. TBookmarkList * __fastcall TWinConfiguration::GetSharedBookmarks()
  1605. {
  1606. return FBookmarks->SharedBookmarks;
  1607. }
  1608. //---------------------------------------------------------------------------
  1609. UnicodeString __fastcall TWinConfiguration::GetDefaultKeyFile()
  1610. {
  1611. return (!FDefaultKeyFile.IsEmpty() ? FDefaultKeyFile : FTemporaryKeyFile);
  1612. }
  1613. //---------------------------------------------------------------------------
  1614. void __fastcall TWinConfiguration::SetLastMonitor(int value)
  1615. {
  1616. ::SetLastMonitor(value);
  1617. }
  1618. //---------------------------------------------------------------------------
  1619. int __fastcall TWinConfiguration::GetLastMonitor()
  1620. {
  1621. return ::GetLastMonitor();
  1622. }
  1623. //---------------------------------------------------------------------------
  1624. UnicodeString __fastcall TWinConfiguration::TemporaryDir(bool Mask)
  1625. {
  1626. return UniqTempDir(ExpandFileName(ExpandEnvironmentVariables(DDTemporaryDirectory)),
  1627. L"scp", Mask);
  1628. }
  1629. //---------------------------------------------------------------------------
  1630. TStrings * __fastcall TWinConfiguration::FindTemporaryFolders()
  1631. {
  1632. TStrings * Result = new TStringList();
  1633. try
  1634. {
  1635. TSearchRec SRec;
  1636. UnicodeString Mask = TemporaryDir(true);
  1637. UnicodeString Directory = ExtractFilePath(Mask);
  1638. if (FindFirst(Mask, faDirectory, SRec) == 0)
  1639. {
  1640. do
  1641. {
  1642. if (FLAGSET(SRec.Attr, faDirectory))
  1643. {
  1644. Result->Add(Directory + SRec.Name);
  1645. }
  1646. }
  1647. while (FindNextChecked(SRec) == 0);
  1648. }
  1649. if (Result->Count == 0)
  1650. {
  1651. delete Result;
  1652. Result = NULL;
  1653. }
  1654. }
  1655. catch(...)
  1656. {
  1657. delete Result;
  1658. throw;
  1659. }
  1660. return Result;
  1661. }
  1662. //---------------------------------------------------------------------------
  1663. void __fastcall TWinConfiguration::CleanupTemporaryFolders(TStrings * Folders)
  1664. {
  1665. UnicodeString ErrorList;
  1666. TStrings * F;
  1667. if (Folders == NULL)
  1668. {
  1669. F = FindTemporaryFolders();
  1670. }
  1671. else
  1672. {
  1673. F = Folders;
  1674. }
  1675. if (F != NULL)
  1676. {
  1677. try
  1678. {
  1679. for (int i = 0; i < F->Count; i++)
  1680. {
  1681. if (!DeleteDirectory(F->Strings[i]))
  1682. {
  1683. if (!ErrorList.IsEmpty())
  1684. {
  1685. ErrorList += L"\n";
  1686. }
  1687. ErrorList += F->Strings[i];
  1688. }
  1689. }
  1690. }
  1691. __finally
  1692. {
  1693. if (Folders == NULL)
  1694. {
  1695. delete F;
  1696. }
  1697. }
  1698. if (!ErrorList.IsEmpty())
  1699. {
  1700. throw ExtException(LoadStr(CLEANUP_TEMP_ERROR), ErrorList);
  1701. }
  1702. }
  1703. }
  1704. //---------------------------------------------------------------------------
  1705. //---------------------------------------------------------------------------
  1706. #pragma warn -inl
  1707. //---------------------------------------------------------------------------
  1708. class TAsInheritedReader : public TReader
  1709. {
  1710. public:
  1711. __fastcall TAsInheritedReader(TStream * Stream, int BufSize) :
  1712. TReader(Stream, BufSize)
  1713. {
  1714. OnAncestorNotFound = AncestorNotFound;
  1715. }
  1716. virtual void __fastcall ReadPrefix(TFilerFlags & Flags, int & AChildPos)
  1717. {
  1718. TReader::ReadPrefix(Flags, AChildPos);
  1719. Flags << ffInherited;
  1720. }
  1721. void __fastcall AncestorNotFound(TReader * Reader,
  1722. const UnicodeString ComponentName, TMetaClass * ComponentClass,
  1723. TComponent *& Component)
  1724. {
  1725. assert(!Component);
  1726. if (ComponentName.IsEmpty())
  1727. {
  1728. for (int Index = 0; Index < LookupRoot->ComponentCount; Index++)
  1729. {
  1730. Component = LookupRoot->Components[Index];
  1731. if (Component->Name.IsEmpty())
  1732. {
  1733. return;
  1734. }
  1735. }
  1736. Component = NULL;
  1737. }
  1738. }
  1739. };
  1740. //---------------------------------------------------------------------------
  1741. #pragma warn .inl
  1742. //---------------------------------------------------------------------------
  1743. bool __fastcall TWinConfiguration::InternalReloadComponentRes(const UnicodeString ResName,
  1744. HINSTANCE HInst, TComponent * Instance)
  1745. {
  1746. HANDLE HRsrc;
  1747. bool Result;
  1748. if (!HInst)
  1749. {
  1750. HInst = HInstance;
  1751. }
  1752. HRsrc = FindResource(HInst, ResName.c_str(), RT_RCDATA);
  1753. Result = (HRsrc != 0);
  1754. if (Result)
  1755. {
  1756. TResourceStream * ResStream = new TResourceStream(
  1757. reinterpret_cast<int>(HInst), ResName, RT_RCDATA);
  1758. try
  1759. {
  1760. TReader * Reader;
  1761. Reader = new TAsInheritedReader(ResStream, 4096);
  1762. try
  1763. {
  1764. /*Instance =*/ Reader->ReadRootComponent(Instance);
  1765. }
  1766. __finally
  1767. {
  1768. delete Reader;
  1769. }
  1770. }
  1771. __finally
  1772. {
  1773. delete ResStream;
  1774. }
  1775. }
  1776. return Result;
  1777. }
  1778. //---------------------------------------------------------------------------
  1779. bool __fastcall TWinConfiguration::InitComponent(TComponent * Instance,
  1780. TClass RootAncestor, TClass ClassType)
  1781. {
  1782. bool Result = false;
  1783. if ((ClassType != __classid(TComponent)) && (ClassType != RootAncestor))
  1784. {
  1785. if (InitComponent(Instance, RootAncestor, ClassType->ClassParent()))
  1786. {
  1787. Result = true;
  1788. }
  1789. if (InternalReloadComponentRes(ClassType->ClassName(),
  1790. reinterpret_cast<HINSTANCE>(FindResourceHInstance(FindClassHInstance(ClassType))),
  1791. Instance))
  1792. {
  1793. Result = true;
  1794. }
  1795. }
  1796. return Result;
  1797. }
  1798. //---------------------------------------------------------------------------
  1799. LCID __fastcall TWinConfiguration::GetLocale()
  1800. {
  1801. if (!FLocale)
  1802. {
  1803. UnicodeString ResourceModule =
  1804. GetResourceModuleName(Application->Name, ModuleFileName().c_str());
  1805. if (!ResourceModule.IsEmpty())
  1806. {
  1807. UnicodeString ResourceExt = ExtractFileExt(ResourceModule).UpperCase();
  1808. ResourceExt.Delete(1, 1);
  1809. TLanguages * Langs = LanguagesDEPF();
  1810. int Index, Count;
  1811. Count = Langs->Count;
  1812. Index = 0;
  1813. while ((Index < Count) && !FLocale)
  1814. {
  1815. if (Langs->Ext[Index] == ResourceExt)
  1816. {
  1817. FLocale = Langs->LocaleID[Index];
  1818. }
  1819. else if (Langs->Ext[Index].SubString(1, 2) == ResourceExt)
  1820. {
  1821. FLocale = MAKELANGID(PRIMARYLANGID(Langs->LocaleID[Index]),
  1822. SUBLANG_DEFAULT);
  1823. }
  1824. Index++;
  1825. }
  1826. }
  1827. }
  1828. return TCustomWinConfiguration::GetLocale();
  1829. }
  1830. //---------------------------------------------------------------------------
  1831. HINSTANCE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
  1832. UnicodeString * FileName)
  1833. {
  1834. UnicodeString FileNameStorage;
  1835. if (FileName == NULL)
  1836. {
  1837. FileName = &FileNameStorage;
  1838. }
  1839. HINSTANCE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
  1840. if (Instance != NULL)
  1841. {
  1842. try
  1843. {
  1844. CheckTranslationVersion(*FileName, false);
  1845. }
  1846. catch(...)
  1847. {
  1848. FreeResourceModule(Instance);
  1849. throw;
  1850. }
  1851. }
  1852. return Instance;
  1853. }
  1854. //---------------------------------------------------------------------------
  1855. void __fastcall TWinConfiguration::SetResourceModule(HINSTANCE Instance)
  1856. {
  1857. TCustomWinConfiguration::SetResourceModule(Instance);
  1858. Busy(true);
  1859. try
  1860. {
  1861. int Count;
  1862. UnicodeString OrigName;
  1863. int OrigLeft;
  1864. int OrigTop;
  1865. TForm * Form;
  1866. Count = Screen->FormCount;
  1867. for (int Index = 0; Index < Count; Index++)
  1868. {
  1869. Form = Screen->Forms[Index];
  1870. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 0, 1);
  1871. }
  1872. ConfigureInterface();
  1873. for (int Index = 0; Index < Count; Index++)
  1874. {
  1875. Form = Screen->Forms[Index];
  1876. TComponent * Component;
  1877. for (int Index = 0; Index < Form->ComponentCount; Index++)
  1878. {
  1879. Component = Form->Components[Index];
  1880. if (dynamic_cast<TFrame*>(Component))
  1881. {
  1882. OrigName = Component->Name;
  1883. InitComponent(Component, __classid(TFrame), Component->ClassType());
  1884. Component->Name = OrigName;
  1885. }
  1886. }
  1887. OrigLeft = Form->Left;
  1888. OrigTop = Form->Top;
  1889. OrigName = Form->Name;
  1890. InitComponent(Form, __classid(TForm), Form->ClassType());
  1891. Form->Name = OrigName;
  1892. Form->Position = poDesigned;
  1893. Form->Left = OrigLeft;
  1894. Form->Top = OrigTop;
  1895. SendMessage(Form->Handle, WM_LOCALE_CHANGE, 1, 1);
  1896. }
  1897. TDataModule * DataModule;
  1898. Count = Screen->DataModuleCount;
  1899. for (int Index = 0; Index < Count; Index++)
  1900. {
  1901. DataModule = Screen->DataModules[Index];
  1902. OrigName = DataModule->Name;
  1903. InitComponent(DataModule, __classid(TDataModule), DataModule->ClassType());
  1904. DataModule->Name = OrigName;
  1905. }
  1906. }
  1907. __finally
  1908. {
  1909. Busy(false);
  1910. }
  1911. }
  1912. //---------------------------------------------------------------------------
  1913. void __fastcall TWinConfiguration::CheckTranslationVersion(const UnicodeString FileName,
  1914. bool InternalLocaleOnError)
  1915. {
  1916. UnicodeString TranslationProductVersion = GetFileProductVersion(FileName);
  1917. UnicodeString TranslationProductName = GetFileProductName(FileName);
  1918. if ((ProductName != TranslationProductName) ||
  1919. (ProductVersion != TranslationProductVersion))
  1920. {
  1921. if (InternalLocaleOnError)
  1922. {
  1923. LocaleSafe = InternalLocale();
  1924. }
  1925. if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
  1926. {
  1927. throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
  1928. }
  1929. else
  1930. {
  1931. throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
  1932. (FileName, TranslationProductName, TranslationProductVersion)));
  1933. }
  1934. }
  1935. }
  1936. //---------------------------------------------------------------------------
  1937. void __fastcall TWinConfiguration::CheckDefaultTranslation()
  1938. {
  1939. if (!FInvalidDefaultTranslationMessage.IsEmpty())
  1940. {
  1941. MoreMessageDialog(FMTLOAD(INVALID_DEFAULT_TRANSLATION,
  1942. (FInvalidDefaultTranslationMessage)), NULL, qtWarning, qaOK, HELP_NONE);
  1943. }
  1944. }
  1945. //---------------------------------------------------------------------------
  1946. const TEditorPreferences * __fastcall TWinConfiguration::DefaultEditorForFile(
  1947. const UnicodeString FileName, bool Local, const TFileMasks::TParams & MaskParams)
  1948. {
  1949. return FEditorList->Find(FileName, Local, MaskParams);
  1950. }
  1951. //---------------------------------------------------------------------------
  1952. const TEditorList * __fastcall TWinConfiguration::GetEditorList()
  1953. {
  1954. return FEditorList;
  1955. }
  1956. //---------------------------------------------------------------------------
  1957. void __fastcall TWinConfiguration::SetEditorList(const TEditorList * value)
  1958. {
  1959. if (!(*FEditorList == *value))
  1960. {
  1961. *FEditorList = *value;
  1962. Changed();
  1963. }
  1964. }
  1965. //---------------------------------------------------------------------------
  1966. TStringList * __fastcall TWinConfiguration::LoadJumpList(
  1967. THierarchicalStorage * Storage, UnicodeString Name)
  1968. {
  1969. UnicodeString JumpList = Storage->ReadString(Name, L"");
  1970. std::auto_ptr<TStringList> List(new TStringList());
  1971. List->CaseSensitive = false;
  1972. List->CommaText = JumpList;
  1973. return List.release();
  1974. }
  1975. //---------------------------------------------------------------------------
  1976. void __fastcall TWinConfiguration::SaveJumpList(
  1977. THierarchicalStorage * Storage, UnicodeString Name, TStringList * List)
  1978. {
  1979. UnicodeString JumpList = Storage->ReadString(Name, L"");
  1980. UnicodeString NewJumpList = List->CommaText;
  1981. if (NewJumpList != JumpList)
  1982. {
  1983. Storage->WriteString(Name, NewJumpList);
  1984. }
  1985. }
  1986. //---------------------------------------------------------------------------
  1987. void __fastcall TWinConfiguration::TrimJumpList(TStringList * List)
  1988. {
  1989. while (List->Count > 30)
  1990. {
  1991. List->Delete(List->Count - 1);
  1992. }
  1993. }
  1994. //---------------------------------------------------------------------------
  1995. void __fastcall TWinConfiguration::UpdateEntryInJumpList(
  1996. bool Session, const UnicodeString & Name, bool Add)
  1997. {
  1998. THierarchicalStorage * Storage = CreateScpStorage(false);
  1999. try
  2000. {
  2001. FDontDecryptPasswords++;
  2002. Storage->AccessMode = smReadWrite;
  2003. if (Storage->OpenSubKey(ConfigurationSubKey, true))
  2004. {
  2005. std::auto_ptr<TStringList> ListSessions(LoadJumpList(Storage, L"JumpList"));
  2006. std::auto_ptr<TStringList> ListWorkspaces(LoadJumpList(Storage, L"JumpListWorkspaces"));
  2007. if (!Name.IsEmpty())
  2008. {
  2009. TStringList * List = (Session ? ListSessions : ListWorkspaces).get();
  2010. int Index = List->IndexOf(Name);
  2011. if (Index >= 0)
  2012. {
  2013. List->Delete(Index);
  2014. }
  2015. if (Add)
  2016. {
  2017. List->Insert(0, Name);
  2018. }
  2019. }
  2020. TrimJumpList(ListSessions.get());
  2021. TrimJumpList(ListWorkspaces.get());
  2022. ::UpdateJumpList(ListSessions.get(), ListWorkspaces.get());
  2023. SaveJumpList(Storage, L"JumpList", ListSessions.get());
  2024. SaveJumpList(Storage, L"JumpListWorkspaces", ListWorkspaces.get());
  2025. }
  2026. }
  2027. __finally
  2028. {
  2029. FDontDecryptPasswords--;
  2030. delete Storage;
  2031. }
  2032. }
  2033. //---------------------------------------------------------------------------
  2034. void __fastcall TWinConfiguration::AddSessionToJumpList(UnicodeString SessionName)
  2035. {
  2036. UpdateEntryInJumpList(true, SessionName, true);
  2037. }
  2038. //---------------------------------------------------------------------------
  2039. void __fastcall TWinConfiguration::DeleteSessionFromJumpList(UnicodeString SessionName)
  2040. {
  2041. UpdateEntryInJumpList(true, SessionName, false);
  2042. }
  2043. //---------------------------------------------------------------------------
  2044. void __fastcall TWinConfiguration::AddWorkspaceToJumpList(UnicodeString Workspace)
  2045. {
  2046. UpdateEntryInJumpList(false, Workspace, true);
  2047. }
  2048. //---------------------------------------------------------------------------
  2049. void __fastcall TWinConfiguration::DeleteWorkspaceFromJumpList(UnicodeString Workspace)
  2050. {
  2051. UpdateEntryInJumpList(false, Workspace, false);
  2052. }
  2053. //---------------------------------------------------------------------------
  2054. void __fastcall TWinConfiguration::UpdateJumpList()
  2055. {
  2056. AddSessionToJumpList(L"");
  2057. }
  2058. //---------------------------------------------------------------------------
  2059. void __fastcall TWinConfiguration::UpdateStaticUsage()
  2060. {
  2061. TCustomWinConfiguration::UpdateStaticUsage();
  2062. Usage->Set(L"Interface", Interface);
  2063. Usage->Set(L"CustomCommandsCount", (FCustomCommandsDefaults ? 0 : FCustomCommandList->Count));
  2064. Usage->Set(L"UsingLocationProfiles", UseLocationProfiles);
  2065. Usage->Set(L"UsingMasterPassword", UseMasterPassword);
  2066. Usage->Set(L"UsingAutoSaveWorkspace", AutoSaveWorkspace);
  2067. UnicodeString ExternalEditors;
  2068. for (int Index = 0; Index < EditorList->Count; Index++)
  2069. {
  2070. const TEditorPreferences * Editor = EditorList->Editors[Index];
  2071. if (Editor->Data->Editor == edExternal)
  2072. {
  2073. UnicodeString ExternalEditor = Editor->Data->ExternalEditor;
  2074. ReformatFileNameCommand(ExternalEditor);
  2075. UnicodeString Name = ExtractFileName(ExtractProgram(ExternalEditor));
  2076. int Dot = Name.LastDelimiter(L".");
  2077. if (Dot > 0)
  2078. {
  2079. Name = Name.SubString(1, Dot - 1);
  2080. }
  2081. AddToList(ExternalEditors, Name, ",");
  2082. }
  2083. }
  2084. Usage->Set(L"ExternalEditors", ExternalEditors);
  2085. }
  2086. //---------------------------------------------------------------------------
  2087. //---------------------------------------------------------------------------
  2088. __fastcall TCustomCommandType::TCustomCommandType() :
  2089. FParams(0), FShortCut(0)
  2090. {
  2091. }
  2092. //---------------------------------------------------------------------------
  2093. __fastcall TCustomCommandType::TCustomCommandType(const TCustomCommandType & Other) :
  2094. FName(Other.FName),
  2095. FCommand(Other.FCommand),
  2096. FParams(Other.FParams),
  2097. FShortCut(Other.FShortCut)
  2098. {
  2099. }
  2100. //---------------------------------------------------------------------------
  2101. TCustomCommandType & TCustomCommandType::operator=(const TCustomCommandType & Other)
  2102. {
  2103. FName = Other.FName;
  2104. FCommand = Other.FCommand;
  2105. FParams = Other.FParams;
  2106. FShortCut = Other.FShortCut;
  2107. return *this;
  2108. }
  2109. //---------------------------------------------------------------------------
  2110. bool __fastcall TCustomCommandType::Equals(const TCustomCommandType * Other) const
  2111. {
  2112. return
  2113. (FName == Other->FName) &&
  2114. (FCommand == Other->FCommand) &&
  2115. (FParams == Other->FParams) &&
  2116. (FShortCut == Other->FShortCut);
  2117. }
  2118. //---------------------------------------------------------------------------
  2119. //---------------------------------------------------------------------------
  2120. __fastcall TCustomCommandList::TCustomCommandList()
  2121. {
  2122. FCommands = new TList();
  2123. FModified = false;
  2124. }
  2125. //---------------------------------------------------------------------------
  2126. __fastcall TCustomCommandList::~TCustomCommandList()
  2127. {
  2128. Clear();
  2129. delete FCommands;
  2130. }
  2131. //---------------------------------------------------------------------------
  2132. void __fastcall TCustomCommandList::Reset()
  2133. {
  2134. FModified = false;
  2135. }
  2136. //---------------------------------------------------------------------------
  2137. void __fastcall TCustomCommandList::Modify()
  2138. {
  2139. FModified = true;
  2140. }
  2141. //---------------------------------------------------------------------------
  2142. void __fastcall TCustomCommandList::Load(THierarchicalStorage * Storage)
  2143. {
  2144. Clear();
  2145. if (Storage->OpenSubKey(L"CustomCommands", false))
  2146. {
  2147. TStrings * Names = new TStringList();
  2148. try
  2149. {
  2150. Storage->ReadValues(Names, true);
  2151. for (int Index = 0; Index < Names->Count; Index++)
  2152. {
  2153. TCustomCommandType * Command = new TCustomCommandType();
  2154. Command->Name = Names->Names[Index];
  2155. Command->Command = Names->Values[Names->Names[Index]];
  2156. FCommands->Add(Command);
  2157. }
  2158. Storage->CloseSubKey();
  2159. }
  2160. __finally
  2161. {
  2162. delete Names;
  2163. }
  2164. }
  2165. if (Storage->OpenSubKey(L"CustomCommandsParams", false))
  2166. {
  2167. for (int Index = 0; Index < FCommands->Count; Index++)
  2168. {
  2169. TCustomCommandType * Command = GetCommand(Index);
  2170. Command->Params = Storage->ReadInteger(Command->Name, Command->Params);
  2171. }
  2172. Storage->CloseSubKey();
  2173. }
  2174. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", false))
  2175. {
  2176. for (int Index = 0; Index < FCommands->Count; Index++)
  2177. {
  2178. TCustomCommandType * Command = GetCommand(Index);
  2179. Command->ShortCut = (Word)Storage->ReadInteger(Command->Name, Command->ShortCut);
  2180. }
  2181. Storage->CloseSubKey();
  2182. }
  2183. Reset();
  2184. }
  2185. //---------------------------------------------------------------------------
  2186. void __fastcall TCustomCommandList::Save(THierarchicalStorage * Storage)
  2187. {
  2188. if (Storage->OpenSubKey(L"CustomCommands", true))
  2189. {
  2190. Storage->ClearValues();
  2191. for (int Index = 0; Index < FCommands->Count; Index++)
  2192. {
  2193. const TCustomCommandType * Command = Commands[Index];
  2194. Storage->WriteString(Command->Name, Command->Command);
  2195. }
  2196. Storage->CloseSubKey();
  2197. }
  2198. if (Storage->OpenSubKey(L"CustomCommandsParams", true))
  2199. {
  2200. Storage->ClearValues();
  2201. for (int Index = 0; Index < FCommands->Count; Index++)
  2202. {
  2203. const TCustomCommandType * Command = Commands[Index];
  2204. Storage->WriteInteger(Command->Name, Command->Params);
  2205. }
  2206. Storage->CloseSubKey();
  2207. }
  2208. if (Storage->OpenSubKey(L"CustomCommandsShortCuts", true))
  2209. {
  2210. Storage->ClearValues();
  2211. for (int Index = 0; Index < FCommands->Count; Index++)
  2212. {
  2213. const TCustomCommandType * Command = Commands[Index];
  2214. if (Command->ShortCut != 0)
  2215. {
  2216. Storage->WriteInteger(Command->Name, Command->ShortCut);
  2217. }
  2218. }
  2219. Storage->CloseSubKey();
  2220. }
  2221. }
  2222. //---------------------------------------------------------------------------
  2223. void __fastcall TCustomCommandList::Clear()
  2224. {
  2225. for (int Index = 0; Index < FCommands->Count; Index++)
  2226. {
  2227. delete Commands[Index];
  2228. }
  2229. FCommands->Clear();
  2230. }
  2231. //---------------------------------------------------------------------------
  2232. void __fastcall TCustomCommandList::Add(const UnicodeString Name,
  2233. const UnicodeString ACommand, int Params)
  2234. {
  2235. TCustomCommandType * Command = new TCustomCommandType();
  2236. Command->Name = Name;
  2237. Command->Command = ACommand;
  2238. Command->Params = Params;
  2239. Add(Command);
  2240. }
  2241. //---------------------------------------------------------------------------
  2242. void __fastcall TCustomCommandList::Add(TCustomCommandType * Command)
  2243. {
  2244. Insert(Count, Command);
  2245. }
  2246. //---------------------------------------------------------------------------
  2247. void __fastcall TCustomCommandList::Insert(int Index, TCustomCommandType * Command)
  2248. {
  2249. FCommands->Insert(Index, Command);
  2250. Modify();
  2251. }
  2252. //---------------------------------------------------------------------------
  2253. void __fastcall TCustomCommandList::Change(int Index, TCustomCommandType * ACommand)
  2254. {
  2255. TCustomCommandType * Command = GetCommand(Index);
  2256. if (!Command->Equals(ACommand))
  2257. {
  2258. delete Command;
  2259. FCommands->Items[Index] = ACommand;
  2260. Modify();
  2261. }
  2262. else
  2263. {
  2264. delete ACommand;
  2265. }
  2266. }
  2267. //---------------------------------------------------------------------------
  2268. void __fastcall TCustomCommandList::Move(int CurIndex, int NewIndex)
  2269. {
  2270. if (CurIndex != NewIndex)
  2271. {
  2272. FCommands->Move(CurIndex, NewIndex);
  2273. Modify();
  2274. }
  2275. }
  2276. //---------------------------------------------------------------------------
  2277. void __fastcall TCustomCommandList::Delete(int Index)
  2278. {
  2279. assert((Index >= 0) && (Index < Count));
  2280. delete GetCommand(Index);
  2281. FCommands->Delete(Index);
  2282. Modify();
  2283. }
  2284. //---------------------------------------------------------------------------
  2285. int __fastcall TCustomCommandList::GetCount() const
  2286. {
  2287. return FCommands->Count;
  2288. }
  2289. //---------------------------------------------------------------------------
  2290. const TCustomCommandType * __fastcall TCustomCommandList::GetConstCommand(int Index) const
  2291. {
  2292. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2293. }
  2294. //---------------------------------------------------------------------------
  2295. TCustomCommandType * __fastcall TCustomCommandList::GetCommand(int Index)
  2296. {
  2297. return static_cast<TCustomCommandType *>(FCommands->Items[Index]);
  2298. }
  2299. //---------------------------------------------------------------------------
  2300. bool __fastcall TCustomCommandList::Equals(const TCustomCommandList * Other) const
  2301. {
  2302. bool Result = (Count == Other->Count);
  2303. for (int Index = 0; Result && (Index < Count); Index++)
  2304. {
  2305. Result = Commands[Index]->Equals(Other->Commands[Index]);
  2306. }
  2307. return Result;
  2308. }
  2309. //---------------------------------------------------------------------------
  2310. void __fastcall TCustomCommandList::Assign(const TCustomCommandList * Other)
  2311. {
  2312. Clear();
  2313. for (int Index = 0; Index < Other->Count; Index++)
  2314. {
  2315. Add(new TCustomCommandType(*Other->Commands[Index]));
  2316. }
  2317. // there should be comparison of with the assigned list, be we rely on caller
  2318. // to do it instead (TGUIConfiguration::SetCopyParamList)
  2319. Modify();
  2320. }
  2321. //---------------------------------------------------------------------------
  2322. const TCustomCommandType * TCustomCommandList::Find(const UnicodeString Name) const
  2323. {
  2324. for (int Index = 0; Index < FCommands->Count; Index++)
  2325. {
  2326. if (Commands[Index]->Name == Name)
  2327. {
  2328. return Commands[Index];
  2329. }
  2330. }
  2331. return NULL;
  2332. }
  2333. //---------------------------------------------------------------------------
  2334. const TCustomCommandType * TCustomCommandList::Find(TShortCut ShortCut) const
  2335. {
  2336. for (int Index = 0; Index < FCommands->Count; Index++)
  2337. {
  2338. if (Commands[Index]->ShortCut == ShortCut)
  2339. {
  2340. return Commands[Index];
  2341. }
  2342. }
  2343. return NULL;
  2344. }
  2345. //---------------------------------------------------------------------------
  2346. void __fastcall TCustomCommandList::ShortCuts(TShortCuts & ShortCuts) const
  2347. {
  2348. for (int Index = 0; Index < FCommands->Count; Index++)
  2349. {
  2350. const TCustomCommandType * Command = Commands[Index];
  2351. if (Command->ShortCut != 0)
  2352. {
  2353. ShortCuts.Add(Command->ShortCut);
  2354. }
  2355. }
  2356. }