WinConfiguration.cpp 79 KB

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