PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/GitCommands/Settings/AppSettings.cs

https://github.com/qgppl/gitextensions
C# | 1459 lines | 1401 code | 51 blank | 7 comment | 13 complexity | 71bef147ca3c0c0edf45a03733e2dcc6 MD5 | raw file
Possible License(s): GPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using GitCommands.Logging;
  11. using GitCommands.Repository;
  12. using GitCommands.Settings;
  13. using Microsoft.Win32;
  14. namespace GitCommands
  15. {
  16. public enum LocalChangesAction
  17. {
  18. DontChange,
  19. Merge,
  20. Reset,
  21. Stash
  22. }
  23. public static class AppSettings
  24. {
  25. //semi-constants
  26. public static readonly char PosixPathSeparator = '/';
  27. public static Version AppVersion { get { return Assembly.GetCallingAssembly().GetName().Version; } }
  28. public static string ProductVersion { get { return Application.ProductVersion; } }
  29. public static readonly string SettingsFileName = "GitExtensions.settings";
  30. public static readonly Lazy<string> ApplicationDataPath;
  31. public static string SettingsFilePath { get { return Path.Combine(ApplicationDataPath.Value, SettingsFileName); } }
  32. private static RepoDistSettings _SettingsContainer;
  33. public static RepoDistSettings SettingsContainer { get { return _SettingsContainer; } }
  34. public static readonly int BranchDropDownMinWidth = 300;
  35. public static readonly int BranchDropDownMaxWidth = 600;
  36. static AppSettings()
  37. {
  38. ApplicationDataPath = new Lazy<string>(() =>
  39. {
  40. if (IsPortable())
  41. {
  42. return GetGitExtensionsDirectory();
  43. }
  44. else
  45. {
  46. //Make applicationdatapath version independent
  47. return Application.UserAppDataPath.Replace(Application.ProductVersion, string.Empty);
  48. }
  49. }
  50. );
  51. _SettingsContainer = new RepoDistSettings(null, GitExtSettingsCache.FromCache(SettingsFilePath));
  52. GitLog = new CommandLogger();
  53. if (!File.Exists(SettingsFilePath))
  54. {
  55. ImportFromRegistry();
  56. }
  57. }
  58. public static bool AutoNormaliseBranchName
  59. {
  60. get { return GetBool("AutoNormaliseBranchName", true); }
  61. set { SetBool("AutoNormaliseBranchName", value); }
  62. }
  63. public static string AutoNormaliseSymbol
  64. {
  65. // when persisted "" is treated as null, so use "+" instead
  66. get
  67. {
  68. var value = GetString("AutoNormaliseSymbol", "_");
  69. return (value == "+") ? "" : value;
  70. }
  71. set
  72. {
  73. if (string.IsNullOrWhiteSpace(value))
  74. {
  75. value = "+";
  76. }
  77. SetString("AutoNormaliseSymbol", value);
  78. }
  79. }
  80. public static void UsingContainer(RepoDistSettings aSettingsContainer, Action action)
  81. {
  82. SettingsContainer.LockedAction(() =>
  83. {
  84. var oldSC = SettingsContainer;
  85. try
  86. {
  87. _SettingsContainer = aSettingsContainer;
  88. action();
  89. }
  90. finally
  91. {
  92. _SettingsContainer = oldSC;
  93. //refresh settings if needed
  94. SettingsContainer.GetString(string.Empty, null);
  95. }
  96. }
  97. );
  98. }
  99. public static string GetInstallDir()
  100. {
  101. if (IsPortable())
  102. return GetGitExtensionsDirectory();
  103. string dir = ReadStringRegValue("InstallDir", string.Empty);
  104. if (String.IsNullOrEmpty(dir))
  105. return GetGitExtensionsDirectory();
  106. return dir;
  107. }
  108. public static string GetResourceDir()
  109. {
  110. #if DEBUG
  111. string gitExtDir = GetGitExtensionsDirectory().TrimEnd('\\').TrimEnd('/');
  112. string debugPath = @"GitExtensions\bin\Debug";
  113. int len = debugPath.Length;
  114. var path = gitExtDir.Substring(gitExtDir.Length - len);
  115. if (debugPath.ToPosixPath().Equals(path.ToPosixPath()))
  116. {
  117. string projectPath = gitExtDir.Substring(0, gitExtDir.Length - len);
  118. return Path.Combine(projectPath, "Bin");
  119. }
  120. #endif
  121. return GetInstallDir();
  122. }
  123. //for repair only
  124. public static void SetInstallDir(string dir)
  125. {
  126. WriteStringRegValue("InstallDir", dir);
  127. }
  128. private static bool ReadBoolRegKey(string key, bool defaultValue)
  129. {
  130. object obj = VersionIndependentRegKey.GetValue(key);
  131. if (!(obj is string))
  132. obj = null;
  133. if (obj == null)
  134. return defaultValue;
  135. return ((string)obj).Equals("true", StringComparison.CurrentCultureIgnoreCase);
  136. }
  137. private static void WriteBoolRegKey(string key, bool value)
  138. {
  139. VersionIndependentRegKey.SetValue(key, value ? "true" : "false");
  140. }
  141. private static string ReadStringRegValue(string key, string defaultValue)
  142. {
  143. return (string)VersionIndependentRegKey.GetValue(key, defaultValue);
  144. }
  145. private static void WriteStringRegValue(string key, string value)
  146. {
  147. VersionIndependentRegKey.SetValue(key, value);
  148. }
  149. public static bool CheckSettings
  150. {
  151. get { return ReadBoolRegKey("CheckSettings", true); }
  152. set { WriteBoolRegKey("CheckSettings", value); }
  153. }
  154. public static string CascadeShellMenuItems
  155. {
  156. get { return ReadStringRegValue("CascadeShellMenuItems", "110111000111111111"); }
  157. set { WriteStringRegValue("CascadeShellMenuItems", value); }
  158. }
  159. public static string SshPath
  160. {
  161. get { return ReadStringRegValue("gitssh", null); }
  162. set { WriteStringRegValue("gitssh", value); }
  163. }
  164. public static bool AlwaysShowAllCommands
  165. {
  166. get { return ReadBoolRegKey("AlwaysShowAllCommands", false); }
  167. set { WriteBoolRegKey("AlwaysShowAllCommands", value); }
  168. }
  169. public static bool ShowCurrentBranchInVisualStudio
  170. {
  171. //This setting MUST be set to false by default, otherwise it will not work in Visual Studio without
  172. //other changes in the Visual Studio plugin itself.
  173. get { return ReadBoolRegKey("ShowCurrentBranchInVS", true); }
  174. set { WriteBoolRegKey("ShowCurrentBranchInVS", value); }
  175. }
  176. public static string GitCommandValue
  177. {
  178. get
  179. {
  180. if (IsPortable())
  181. return GetString("gitcommand", "");
  182. else
  183. return ReadStringRegValue("gitcommand", "");
  184. }
  185. set
  186. {
  187. if (IsPortable())
  188. SetString("gitcommand", value);
  189. else
  190. WriteStringRegValue("gitcommand", value);
  191. }
  192. }
  193. public static string GitCommand
  194. {
  195. get
  196. {
  197. if (String.IsNullOrEmpty(GitCommandValue))
  198. return "git";
  199. return GitCommandValue;
  200. }
  201. }
  202. public static int UserMenuLocationX
  203. {
  204. get { return GetInt("usermenulocationx", -1); }
  205. set { SetInt("usermenulocationx", value); }
  206. }
  207. public static int UserMenuLocationY
  208. {
  209. get { return GetInt("usermenulocationy", -1); }
  210. set { SetInt("usermenulocationy", value); }
  211. }
  212. public static bool StashKeepIndex
  213. {
  214. get { return GetBool("stashkeepindex", false); }
  215. set { SetBool("stashkeepindex", value); }
  216. }
  217. public static bool StashConfirmDropShow
  218. {
  219. get { return GetBool("stashconfirmdropshow", true); }
  220. set { SetBool("stashconfirmdropshow", value); }
  221. }
  222. public static bool ApplyPatchIgnoreWhitespace
  223. {
  224. get { return GetBool("applypatchignorewhitespace", false); }
  225. set { SetBool("applypatchignorewhitespace", value); }
  226. }
  227. public static bool UsePatienceDiffAlgorithm
  228. {
  229. get { return GetBool("usepatiencediffalgorithm", false); }
  230. set { SetBool("usepatiencediffalgorithm", value); }
  231. }
  232. public static bool ShowErrorsWhenStagingFiles
  233. {
  234. get { return GetBool("showerrorswhenstagingfiles", true); }
  235. set { SetBool("showerrorswhenstagingfiles", value); }
  236. }
  237. public static bool AddNewlineToCommitMessageWhenMissing
  238. {
  239. get { return GetBool("addnewlinetocommitmessagewhenmissing", true); }
  240. set { SetBool("addnewlinetocommitmessagewhenmissing", value); }
  241. }
  242. public static string LastCommitMessage
  243. {
  244. get { return GetString("lastCommitMessage", ""); }
  245. set { SetString("lastCommitMessage", value); }
  246. }
  247. public static int CommitDialogNumberOfPreviousMessages
  248. {
  249. get { return GetInt("commitDialogNumberOfPreviousMessages", 4); }
  250. set { SetInt("commitDialogNumberOfPreviousMessages", value); }
  251. }
  252. public static bool ShowCommitAndPush
  253. {
  254. get { return GetBool("showcommitandpush", true); }
  255. set { SetBool("showcommitandpush", value); }
  256. }
  257. public static bool ShowResetUnstagedChanges
  258. {
  259. get { return GetBool("showresetunstagedchanges", true); }
  260. set { SetBool("showresetunstagedchanges", value); }
  261. }
  262. public static bool ShowResetAllChanges
  263. {
  264. get { return GetBool("showresetallchanges", true); }
  265. set { SetBool("showresetallchanges", value); }
  266. }
  267. public static bool ProvideAutocompletion
  268. {
  269. get { return GetBool("provideautocompletion", true); }
  270. set { SetBool("provideautocompletion", value); }
  271. }
  272. public static string TruncatePathMethod
  273. {
  274. get { return GetString("truncatepathmethod", "none"); }
  275. set { SetString("truncatepathmethod", value); }
  276. }
  277. public static bool ShowGitStatusInBrowseToolbar
  278. {
  279. get { return GetBool("showgitstatusinbrowsetoolbar", true); }
  280. set { SetBool("showgitstatusinbrowsetoolbar", value); }
  281. }
  282. public static bool CommitInfoShowContainedInBranches
  283. {
  284. get
  285. {
  286. return CommitInfoShowContainedInBranchesLocal ||
  287. CommitInfoShowContainedInBranchesRemote ||
  288. CommitInfoShowContainedInBranchesRemoteIfNoLocal;
  289. }
  290. }
  291. public static bool CommitInfoShowContainedInBranchesLocal
  292. {
  293. get { return GetBool("commitinfoshowcontainedinbrancheslocal", true); }
  294. set { SetBool("commitinfoshowcontainedinbrancheslocal", value); }
  295. }
  296. public static bool CheckForUncommittedChangesInCheckoutBranch
  297. {
  298. get { return GetBool("checkforuncommittedchangesincheckoutbranch", true); }
  299. set { SetBool("checkforuncommittedchangesincheckoutbranch", value); }
  300. }
  301. public static bool AlwaysShowCheckoutBranchDlg
  302. {
  303. get { return GetBool("AlwaysShowCheckoutBranchDlg", false); }
  304. set { SetBool("AlwaysShowCheckoutBranchDlg", value); }
  305. }
  306. public static bool CommitInfoShowContainedInBranchesRemote
  307. {
  308. get { return GetBool("commitinfoshowcontainedinbranchesremote", false); }
  309. set { SetBool("commitinfoshowcontainedinbranchesremote", value); }
  310. }
  311. public static bool CommitInfoShowContainedInBranchesRemoteIfNoLocal
  312. {
  313. get { return GetBool("commitinfoshowcontainedinbranchesremoteifnolocal", false); }
  314. set { SetBool("commitinfoshowcontainedinbranchesremoteifnolocal", value); }
  315. }
  316. public static bool CommitInfoShowContainedInTags
  317. {
  318. get { return GetBool("commitinfoshowcontainedintags", true); }
  319. set { SetBool("commitinfoshowcontainedintags", value); }
  320. }
  321. public static string GravatarCachePath
  322. {
  323. get { return ApplicationDataPath.Value + "Images\\"; }
  324. }
  325. public static string Translation
  326. {
  327. get { return GetString("translation", ""); }
  328. set { SetString("translation", value); }
  329. }
  330. private static string _currentTranslation;
  331. public static string CurrentTranslation
  332. {
  333. get { return _currentTranslation ?? Translation; }
  334. set { _currentTranslation = value; }
  335. }
  336. private static readonly Dictionary<string, string> _languageCodes =
  337. new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
  338. {
  339. {"Czech", "cs"},
  340. {"Dutch", "nl"},
  341. {"English", "en"},
  342. {"French", "fr"},
  343. {"German", "de"},
  344. {"Indonesian", "id"},
  345. {"Italian", "it"},
  346. {"Japanese", "ja"},
  347. {"Korean", "ko"},
  348. {"Polish", "pl"},
  349. {"Portuguese (Brazil)", "pt-BR"},
  350. {"Portuguese (Portugal)", "pt-PT"},
  351. {"Romanian", "ro"},
  352. {"Russian", "ru"},
  353. {"Simplified Chinese", "zh-CN"},
  354. {"Spanish", "es"},
  355. {"Traditional Chinese", "zh-TW"}
  356. };
  357. public static string CurrentLanguageCode
  358. {
  359. get
  360. {
  361. string code;
  362. if (_languageCodes.TryGetValue(CurrentTranslation, out code))
  363. return code;
  364. return "en";
  365. }
  366. }
  367. public static CultureInfo CurrentCultureInfo
  368. {
  369. get
  370. {
  371. try
  372. {
  373. return CultureInfo.GetCultureInfo(CurrentLanguageCode);
  374. }
  375. catch (System.Globalization.CultureNotFoundException)
  376. {
  377. Debug.WriteLine("Culture {0} not found", CurrentLanguageCode);
  378. return CultureInfo.GetCultureInfo("en");
  379. }
  380. }
  381. }
  382. public static bool UserProfileHomeDir
  383. {
  384. get { return GetBool("userprofilehomedir", false); }
  385. set { SetBool("userprofilehomedir", value); }
  386. }
  387. public static string CustomHomeDir
  388. {
  389. get { return GetString("customhomedir", ""); }
  390. set { SetString("customhomedir", value); }
  391. }
  392. public static bool EnableAutoScale
  393. {
  394. get { return GetBool("enableautoscale", true); }
  395. set { SetBool("enableautoscale", value); }
  396. }
  397. public static string IconColor
  398. {
  399. get { return GetString("iconcolor", "default"); }
  400. set { SetString("iconcolor", value); }
  401. }
  402. public static string IconStyle
  403. {
  404. get { return GetString("iconstyle", "default"); }
  405. set { SetString("iconstyle", value); }
  406. }
  407. public static int AuthorImageSize
  408. {
  409. get { return GetInt("authorimagesize", 80); }
  410. set { SetInt("authorimagesize", value); }
  411. }
  412. public static int AuthorImageCacheDays
  413. {
  414. get { return GetInt("authorimagecachedays", 5); }
  415. set { SetInt("authorimagecachedays", value); }
  416. }
  417. public static bool ShowAuthorGravatar
  418. {
  419. get { return GetBool("showauthorgravatar", true); }
  420. set { SetBool("showauthorgravatar", value); }
  421. }
  422. public static bool CloseCommitDialogAfterCommit
  423. {
  424. get { return GetBool("closecommitdialogaftercommit", true); }
  425. set { SetBool("closecommitdialogaftercommit", value); }
  426. }
  427. public static bool CloseCommitDialogAfterLastCommit
  428. {
  429. get { return GetBool("closecommitdialogafterlastcommit", true); }
  430. set { SetBool("closecommitdialogafterlastcommit", value); }
  431. }
  432. public static bool RefreshCommitDialogOnFormFocus
  433. {
  434. get { return GetBool("refreshcommitdialogonformfocus", false); }
  435. set { SetBool("refreshcommitdialogonformfocus", value); }
  436. }
  437. public static bool StageInSuperprojectAfterCommit
  438. {
  439. get { return GetBool("stageinsuperprojectaftercommit", true); }
  440. set { SetBool("stageinsuperprojectaftercommit", value); }
  441. }
  442. public static bool PlaySpecialStartupSound
  443. {
  444. get { return GetBool("PlaySpecialStartupSound", false); }
  445. set { SetBool("PlaySpecialStartupSound", value); }
  446. }
  447. public static bool FollowRenamesInFileHistory
  448. {
  449. get { return GetBool("followrenamesinfilehistory", true); }
  450. set { SetBool("followrenamesinfilehistory", value); }
  451. }
  452. public static bool FollowRenamesInFileHistoryExactOnly
  453. {
  454. get { return GetBool("followrenamesinfilehistoryexactonly", false); }
  455. set { SetBool("followrenamesinfilehistoryexactonly", value); }
  456. }
  457. public static bool FullHistoryInFileHistory
  458. {
  459. get { return GetBool("fullhistoryinfilehistory", false); }
  460. set { SetBool("fullhistoryinfilehistory", value); }
  461. }
  462. public static bool LoadFileHistoryOnShow
  463. {
  464. get { return GetBool("LoadFileHistoryOnShow", true); }
  465. set { SetBool("LoadFileHistoryOnShow", value); }
  466. }
  467. public static bool LoadBlameOnShow
  468. {
  469. get { return GetBool("LoadBlameOnShow", true); }
  470. set { SetBool("LoadBlameOnShow", value); }
  471. }
  472. public static bool RevisionGraphShowWorkingDirChanges
  473. {
  474. get { return GetBool("revisiongraphshowworkingdirchanges", false); }
  475. set { SetBool("revisiongraphshowworkingdirchanges", value); }
  476. }
  477. public static bool RevisionGraphDrawNonRelativesGray
  478. {
  479. get { return GetBool("revisiongraphdrawnonrelativesgray", true); }
  480. set { SetBool("revisiongraphdrawnonrelativesgray", value); }
  481. }
  482. public static bool RevisionGraphDrawNonRelativesTextGray
  483. {
  484. get { return GetBool("revisiongraphdrawnonrelativestextgray", false); }
  485. set { SetBool("revisiongraphdrawnonrelativestextgray", value); }
  486. }
  487. public static readonly Dictionary<string, Encoding> AvailableEncodings = new Dictionary<string, Encoding>();
  488. public enum PullAction
  489. {
  490. None,
  491. Merge,
  492. Rebase,
  493. Fetch,
  494. FetchAll,
  495. Default
  496. }
  497. public static PullAction FormPullAction
  498. {
  499. get { return GetEnum("FormPullAction", PullAction.Merge); }
  500. set { SetEnum("FormPullAction", value); }
  501. }
  502. public static bool SetNextPullActionAsDefault
  503. {
  504. get { return !GetBool("DonSetAsLastPullAction", true); }
  505. set { SetBool("DonSetAsLastPullAction", !value); }
  506. }
  507. public static string SmtpServer
  508. {
  509. get { return GetString("SmtpServer", "smtp.gmail.com"); }
  510. set { SetString("SmtpServer", value); }
  511. }
  512. public static int SmtpPort
  513. {
  514. get { return GetInt("SmtpPort", 465); }
  515. set { SetInt("SmtpPort", value); }
  516. }
  517. public static bool SmtpUseSsl
  518. {
  519. get { return GetBool("SmtpUseSsl", true); }
  520. set { SetBool("SmtpUseSsl", value); }
  521. }
  522. public static bool AutoStash
  523. {
  524. get { return GetBool("autostash", false); }
  525. set { SetBool("autostash", value); }
  526. }
  527. public static bool RebaseAutoStash
  528. {
  529. get { return GetBool("RebaseAutostash", false); }
  530. set { SetBool("RebaseAutostash", value); }
  531. }
  532. public static LocalChangesAction CheckoutBranchAction
  533. {
  534. get { return GetEnum("checkoutbranchaction", LocalChangesAction.DontChange); }
  535. set { SetEnum("checkoutbranchaction", value); }
  536. }
  537. public static bool UseDefaultCheckoutBranchAction
  538. {
  539. get { return GetBool("UseDefaultCheckoutBranchAction", false); }
  540. set { SetBool("UseDefaultCheckoutBranchAction", value); }
  541. }
  542. public static bool DontShowHelpImages
  543. {
  544. get { return GetBool("DontShowHelpImages", false); }
  545. set { SetBool("DontShowHelpImages", value); }
  546. }
  547. public static bool AlwaysShowAdvOpt
  548. {
  549. get { return GetBool("AlwaysShowAdvOpt", false); }
  550. set { SetBool("AlwaysShowAdvOpt", value); }
  551. }
  552. public static bool DontConfirmAmend
  553. {
  554. get { return GetBool("DontConfirmAmend", false); }
  555. set { SetBool("DontConfirmAmend", value); }
  556. }
  557. public static bool? AutoPopStashAfterPull
  558. {
  559. get { return GetBool("AutoPopStashAfterPull"); }
  560. set { SetBool("AutoPopStashAfterPull", value); }
  561. }
  562. public static bool? AutoPopStashAfterCheckoutBranch
  563. {
  564. get { return GetBool("AutoPopStashAfterCheckoutBranch"); }
  565. set { SetBool("AutoPopStashAfterCheckoutBranch", value); }
  566. }
  567. public static PullAction? AutoPullOnPushRejectedAction
  568. {
  569. get { return GetNullableEnum<PullAction>("AutoPullOnPushRejectedAction"); }
  570. set { SetNullableEnum<PullAction>("AutoPullOnPushRejectedAction", value); }
  571. }
  572. public static bool DontConfirmPushNewBranch
  573. {
  574. get { return GetBool("DontConfirmPushNewBranch", false); }
  575. set { SetBool("DontConfirmPushNewBranch", value); }
  576. }
  577. public static bool DontConfirmAddTrackingRef
  578. {
  579. get { return GetBool("DontConfirmAddTrackingRef", false); }
  580. set { SetBool("DontConfirmAddTrackingRef", value); }
  581. }
  582. public static bool IncludeUntrackedFilesInAutoStash
  583. {
  584. get { return GetBool("includeUntrackedFilesInAutoStash", false); }
  585. set { SetBool("includeUntrackedFilesInAutoStash", value); }
  586. }
  587. public static bool IncludeUntrackedFilesInManualStash
  588. {
  589. get { return GetBool("includeUntrackedFilesInManualStash", false); }
  590. set { SetBool("includeUntrackedFilesInManualStash", value); }
  591. }
  592. public static bool OrderRevisionByDate
  593. {
  594. get { return GetBool("orderrevisionbydate", true); }
  595. set { SetBool("orderrevisionbydate", value); }
  596. }
  597. public static bool ShowRemoteBranches
  598. {
  599. get { return GetBool("showRemoteBranches", true); }
  600. set { SetBool("showRemoteBranches", value); }
  601. }
  602. public static bool ShowSuperprojectTags
  603. {
  604. get { return GetBool("showSuperprojectTags", false); }
  605. set { SetBool("showSuperprojectTags", value); }
  606. }
  607. public static bool ShowSuperprojectBranches
  608. {
  609. get { return GetBool("showSuperprojectBranches", true); }
  610. set { SetBool("showSuperprojectBranches", value); }
  611. }
  612. public static bool ShowSuperprojectRemoteBranches
  613. {
  614. get { return GetBool("showSuperprojectRemoteBranches", false); }
  615. set { SetBool("showSuperprojectRemoteBranches", value); }
  616. }
  617. public static bool? UpdateSubmodulesOnCheckout
  618. {
  619. get { return GetBool("updateSubmodulesOnCheckout"); }
  620. set { SetBool("updateSubmodulesOnCheckout", value); }
  621. }
  622. public static string Dictionary
  623. {
  624. get { return SettingsContainer.Dictionary; }
  625. set { SettingsContainer.Dictionary = value; }
  626. }
  627. public static bool ShowGitCommandLine
  628. {
  629. get { return GetBool("showgitcommandline", false); }
  630. set { SetBool("showgitcommandline", value); }
  631. }
  632. public static bool ShowStashCount
  633. {
  634. get { return GetBool("showstashcount", false); }
  635. set { SetBool("showstashcount", value); }
  636. }
  637. public static bool RelativeDate
  638. {
  639. get { return GetBool("relativedate", true); }
  640. set { SetBool("relativedate", value); }
  641. }
  642. public static bool UseFastChecks
  643. {
  644. get { return GetBool("usefastchecks", false); }
  645. set { SetBool("usefastchecks", value); }
  646. }
  647. public static bool ShowGitNotes
  648. {
  649. get { return GetBool("showgitnotes", false); }
  650. set { SetBool("showgitnotes", value); }
  651. }
  652. public static bool ShowIndicatorForMultilineMessage
  653. {
  654. get { return GetBool("showindicatorformultilinemessage", false); }
  655. set { SetBool("showindicatorformultilinemessage", value); }
  656. }
  657. public static bool ShowAnnotatedTagsMessages
  658. {
  659. get { return GetBool("showannotatedtagsmessages", true); }
  660. set { SetBool("showannotatedtagsmessages", value); }
  661. }
  662. public static bool ShowMergeCommits
  663. {
  664. get { return GetBool("showmergecommits", true); }
  665. set { SetBool("showmergecommits", value); }
  666. }
  667. public static bool ShowTags
  668. {
  669. get { return GetBool("showtags", true); }
  670. set { SetBool("showtags", value); }
  671. }
  672. public static bool ShowIds
  673. {
  674. get { return GetBool("showids", false); }
  675. set { SetBool("showids", value); }
  676. }
  677. public static int RevisionGraphLayout
  678. {
  679. get { return GetInt("revisiongraphlayout", 2); }
  680. set { SetInt("revisiongraphlayout", value); }
  681. }
  682. public static bool ShowAuthorDate
  683. {
  684. get { return GetBool("showauthordate", true); }
  685. set { SetBool("showauthordate", value); }
  686. }
  687. public static bool CloseProcessDialog
  688. {
  689. get { return GetBool("closeprocessdialog", false); }
  690. set { SetBool("closeprocessdialog", value); }
  691. }
  692. public static bool ShowCurrentBranchOnly
  693. {
  694. get { return GetBool("showcurrentbranchonly", false); }
  695. set { SetBool("showcurrentbranchonly", value); }
  696. }
  697. public static bool ShowSimplifyByDecoration
  698. {
  699. get { return GetBool("showsimplifybydecoration", false); }
  700. set { SetBool("showsimplifybydecoration", value); }
  701. }
  702. public static bool BranchFilterEnabled
  703. {
  704. get { return GetBool("branchfilterenabled", false); }
  705. set { SetBool("branchfilterenabled", value); }
  706. }
  707. public static bool ShowFirstParent
  708. {
  709. get { return GetBool("showfirstparent", false); }
  710. set { SetBool("showfirstparent", value); }
  711. }
  712. public static int CommitDialogSplitter
  713. {
  714. get { return GetInt("commitdialogsplitter", -1); }
  715. set { SetInt("commitdialogsplitter", value); }
  716. }
  717. public static int CommitDialogRightSplitter
  718. {
  719. get { return GetInt("commitdialogrightsplitter", -1); }
  720. set { SetInt("commitdialogrightsplitter", value); }
  721. }
  722. public static string DefaultCloneDestinationPath
  723. {
  724. get { return GetString("defaultclonedestinationpath", string.Empty); }
  725. set { SetString("defaultclonedestinationpath", value); }
  726. }
  727. public static int RevisionGridQuickSearchTimeout
  728. {
  729. get { return GetInt("revisiongridquicksearchtimeout", 750); }
  730. set { SetInt("revisiongridquicksearchtimeout", value); }
  731. }
  732. public static string GravatarFallbackService
  733. {
  734. get { return GetString("gravatarfallbackservice", "Identicon"); }
  735. set { SetString("gravatarfallbackservice", value); }
  736. }
  737. /// <summary>Gets or sets the path to the git application executable.</summary>
  738. public static string GitBinDir
  739. {
  740. get { return GetString("gitbindir", ""); }
  741. set
  742. {
  743. var temp = value.EnsureTrailingPathSeparator();
  744. SetString("gitbindir", temp);
  745. //if (string.IsNullOrEmpty(_gitBinDir))
  746. // return;
  747. //var path =
  748. // Environment.GetEnvironmentVariable("path", EnvironmentVariableTarget.Process) + ";" +
  749. // _gitBinDir;
  750. //Environment.SetEnvironmentVariable("path", path, EnvironmentVariableTarget.Process);
  751. }
  752. }
  753. public static int MaxRevisionGraphCommits
  754. {
  755. get { return GetInt("maxrevisiongraphcommits", 100000); }
  756. set { SetInt("maxrevisiongraphcommits", value); }
  757. }
  758. public static bool ShowDiffForAllParents
  759. {
  760. get { return GetBool("showdiffforallparents", true); }
  761. set { SetBool("showdiffforallparents", value); }
  762. }
  763. public static string RecentWorkingDir
  764. {
  765. get { return GetString("RecentWorkingDir", null); }
  766. set { SetString("RecentWorkingDir", value); }
  767. }
  768. public static bool StartWithRecentWorkingDir
  769. {
  770. get { return GetBool("StartWithRecentWorkingDir", false); }
  771. set { SetBool("StartWithRecentWorkingDir", value); }
  772. }
  773. public static CommandLogger GitLog { get; private set; }
  774. public static string Plink
  775. {
  776. get { return GetString("plink", ReadStringRegValue("plink", "")); }
  777. set { SetString("plink", value); }
  778. }
  779. public static string Puttygen
  780. {
  781. get { return GetString("puttygen", ReadStringRegValue("puttygen", "")); }
  782. set { SetString("puttygen", value); }
  783. }
  784. /// <summary>Gets the path to Pageant (SSH auth agent).</summary>
  785. public static string Pageant
  786. {
  787. get { return GetString("pageant", ReadStringRegValue("pageant", "")); }
  788. set { SetString("pageant", value); }
  789. }
  790. public static bool AutoStartPageant
  791. {
  792. get { return GetBool("autostartpageant", true); }
  793. set { SetBool("autostartpageant", value); }
  794. }
  795. public static bool MarkIllFormedLinesInCommitMsg
  796. {
  797. get { return GetBool("markillformedlinesincommitmsg", false); }
  798. set { SetBool("markillformedlinesincommitmsg", value); }
  799. }
  800. #region Colors
  801. public static Color OtherTagColor
  802. {
  803. get { return GetColor("othertagcolor", Color.Gray); }
  804. set { SetColor("othertagcolor", value); }
  805. }
  806. public static Color TagColor
  807. {
  808. get { return GetColor("tagcolor", Color.DarkBlue); }
  809. set { SetColor("tagcolor", value); }
  810. }
  811. public static Color GraphColor
  812. {
  813. get { return GetColor("graphcolor", Color.DarkRed); }
  814. set { SetColor("graphcolor", value); }
  815. }
  816. public static Color BranchColor
  817. {
  818. get { return GetColor("branchcolor", Color.DarkRed); }
  819. set { SetColor("branchcolor", value); }
  820. }
  821. public static Color RemoteBranchColor
  822. {
  823. get { return GetColor("remotebranchcolor", Color.Green); }
  824. set { SetColor("remotebranchcolor", value); }
  825. }
  826. public static Color DiffSectionColor
  827. {
  828. get { return GetColor("diffsectioncolor", Color.FromArgb(230, 230, 230)); }
  829. set { SetColor("diffsectioncolor", value); }
  830. }
  831. public static Color DiffRemovedColor
  832. {
  833. get { return GetColor("diffremovedcolor", Color.FromArgb(255, 200, 200)); }
  834. set { SetColor("diffremovedcolor", value); }
  835. }
  836. public static Color DiffRemovedExtraColor
  837. {
  838. get { return GetColor("diffremovedextracolor", Color.FromArgb(255, 150, 150)); }
  839. set { SetColor("diffremovedextracolor", value); }
  840. }
  841. public static Color DiffAddedColor
  842. {
  843. get { return GetColor("diffaddedcolor", Color.FromArgb(200, 255, 200)); }
  844. set { SetColor("diffaddedcolor", value); }
  845. }
  846. public static Color DiffAddedExtraColor
  847. {
  848. get { return GetColor("diffaddedextracolor", Color.FromArgb(135, 255, 135)); }
  849. set { SetColor("diffaddedextracolor", value); }
  850. }
  851. public static Color AuthoredRevisionsColor
  852. {
  853. get { return GetColor("authoredrevisionscolor", Color.LightYellow); }
  854. set { SetColor("authoredrevisionscolor", value); }
  855. }
  856. public static Font DiffFont
  857. {
  858. get { return GetFont("difffont", new Font("Courier New", 10)); }
  859. set { SetFont("difffont", value); }
  860. }
  861. public static Font CommitFont
  862. {
  863. get { return GetFont("commitfont", new Font(SystemFonts.DialogFont.Name, SystemFonts.MessageBoxFont.Size)); }
  864. set { SetFont("commitfont", value); }
  865. }
  866. public static Font Font
  867. {
  868. get { return GetFont("font", new Font(SystemFonts.DialogFont.Name, SystemFonts.DefaultFont.Size)); }
  869. set { SetFont("font", value); }
  870. }
  871. #endregion
  872. public static bool MulticolorBranches
  873. {
  874. get { return GetBool("multicolorbranches", true); }
  875. set { SetBool("multicolorbranches", value); }
  876. }
  877. public static bool StripedBranchChange
  878. {
  879. get { return GetBool("stripedbranchchange", true); }
  880. set { SetBool("stripedbranchchange", value); }
  881. }
  882. public static bool BranchBorders
  883. {
  884. get { return GetBool("branchborders", true); }
  885. set { SetBool("branchborders", value); }
  886. }
  887. public static bool HighlightAuthoredRevisions
  888. {
  889. get { return GetBool("highlightauthoredrevisions", true); }
  890. set { SetBool("highlightauthoredrevisions", value); }
  891. }
  892. public static string LastFormatPatchDir
  893. {
  894. get { return GetString("lastformatpatchdir", ""); }
  895. set { SetString("lastformatpatchdir", value); }
  896. }
  897. public static bool IgnoreWhitespaceChanges
  898. {
  899. get
  900. {
  901. return RememberIgnoreWhiteSpacePreference && GetBool("IgnoreWhitespaceChanges", false);
  902. }
  903. set
  904. {
  905. if (RememberIgnoreWhiteSpacePreference)
  906. {
  907. SetBool("IgnoreWhitespaceChanges", value);
  908. }
  909. }
  910. }
  911. public static bool RememberIgnoreWhiteSpacePreference
  912. {
  913. get { return GetBool("rememberIgnoreWhiteSpacePreference", false); }
  914. set { SetBool("rememberIgnoreWhiteSpacePreference", value); }
  915. }
  916. public static string GetDictionaryDir()
  917. {
  918. return Path.Combine(GetResourceDir(), "Dictionaries");
  919. }
  920. public static void SaveSettings()
  921. {
  922. try
  923. {
  924. SettingsContainer.LockedAction(() =>
  925. {
  926. SshPath = GitCommandHelpers.GetSsh();
  927. Repositories.SaveSettings();
  928. SettingsContainer.Save();
  929. });
  930. }
  931. catch
  932. { }
  933. }
  934. public static void LoadSettings()
  935. {
  936. Action<Encoding> addEncoding = delegate(Encoding e) { AvailableEncodings[e.HeaderName] = e; };
  937. addEncoding(Encoding.Default);
  938. addEncoding(new ASCIIEncoding());
  939. addEncoding(new UnicodeEncoding());
  940. addEncoding(new UTF7Encoding());
  941. addEncoding(new UTF8Encoding(false));
  942. addEncoding(System.Text.Encoding.GetEncoding("CP852"));
  943. try
  944. {
  945. GitCommandHelpers.SetSsh(SshPath);
  946. }
  947. catch
  948. { }
  949. }
  950. public static bool DashboardShowCurrentBranch
  951. {
  952. get { return GetBool("dashboardshowcurrentbranch", true); }
  953. set { SetBool("dashboardshowcurrentbranch", value); }
  954. }
  955. public static string ownScripts
  956. {
  957. get { return GetString("ownScripts", ""); }
  958. set { SetString("ownScripts", value); }
  959. }
  960. public static int RecursiveSubmodules
  961. {
  962. get { return GetInt("RecursiveSubmodules", 1); }
  963. set { SetInt("RecursiveSubmodules", value); }
  964. }
  965. public static string ShorteningRecentRepoPathStrategy
  966. {
  967. get { return GetString("ShorteningRecentRepoPathStrategy", ""); }
  968. set { SetString("ShorteningRecentRepoPathStrategy", value); }
  969. }
  970. public static int MaxMostRecentRepositories
  971. {
  972. get { return GetInt("MaxMostRecentRepositories", 0); }
  973. set { SetInt("MaxMostRecentRepositories", value); }
  974. }
  975. public static int RecentReposComboMinWidth
  976. {
  977. get { return GetInt("RecentReposComboMinWidth", 0); }
  978. set { SetInt("RecentReposComboMinWidth", value); }
  979. }
  980. public static bool SortMostRecentRepos
  981. {
  982. get { return GetBool("SortMostRecentRepos", false); }
  983. set { SetBool("SortMostRecentRepos", value); }
  984. }
  985. public static bool SortLessRecentRepos
  986. {
  987. get { return GetBool("SortLessRecentRepos", false); }
  988. set { SetBool("SortLessRecentRepos", value); }
  989. }
  990. public static bool DontCommitMerge
  991. {
  992. get { return GetBool("DontCommitMerge", false); }
  993. set { SetBool("DontCommitMerge", value); }
  994. }
  995. public static int CommitValidationMaxCntCharsFirstLine
  996. {
  997. get { return GetInt("CommitValidationMaxCntCharsFirstLine", 0); }
  998. set { SetInt("CommitValidationMaxCntCharsFirstLine", value); }
  999. }
  1000. public static int CommitValidationMaxCntCharsPerLine
  1001. {
  1002. get { return GetInt("CommitValidationMaxCntCharsPerLine", 0); }
  1003. set { SetInt("CommitValidationMaxCntCharsPerLine", value); }
  1004. }
  1005. public static bool CommitValidationSecondLineMustBeEmpty
  1006. {
  1007. get { return GetBool("CommitValidationSecondLineMustBeEmpty", false); }
  1008. set { SetBool("CommitValidationSecondLineMustBeEmpty", value); }
  1009. }
  1010. public static bool CommitValidationIndentAfterFirstLine
  1011. {
  1012. get { return GetBool("CommitValidationIndentAfterFirstLine", true); }
  1013. set { SetBool("CommitValidationIndentAfterFirstLine", value); }
  1014. }
  1015. public static bool CommitValidationAutoWrap
  1016. {
  1017. get { return GetBool("CommitValidationAutoWrap", true); }
  1018. set { SetBool("CommitValidationAutoWrap", value); }
  1019. }
  1020. public static string CommitValidationRegEx
  1021. {
  1022. get { return GetString("CommitValidationRegEx", String.Empty); }
  1023. set { SetString("CommitValidationRegEx", value); }
  1024. }
  1025. public static string CommitTemplates
  1026. {
  1027. get { return GetString("CommitTemplates", String.Empty); }
  1028. set { SetString("CommitTemplates", value); }
  1029. }
  1030. public static bool CreateLocalBranchForRemote
  1031. {
  1032. get { return GetBool("CreateLocalBranchForRemote", false); }
  1033. set { SetBool("CreateLocalBranchForRemote", value); }
  1034. }
  1035. public static bool UseFormCommitMessage
  1036. {
  1037. get { return GetBool("UseFormCommitMessage", true); }
  1038. set { SetBool("UseFormCommitMessage", value); }
  1039. }
  1040. public static bool CommitAutomaticallyAfterCherryPick
  1041. {
  1042. get { return GetBool("CommitAutomaticallyAfterCherryPick", false); }
  1043. set { SetBool("CommitAutomaticallyAfterCherryPick", value); }
  1044. }
  1045. public static bool AddCommitReferenceToCherryPick
  1046. {
  1047. get { return GetBool("AddCommitReferenceToCherryPick", false); }
  1048. set { SetBool("AddCommitReferenceToCherryPick", value); }
  1049. }
  1050. public static DateTime LastUpdateCheck
  1051. {
  1052. get { return GetDate("LastUpdateCheck", default(DateTime)); }
  1053. set { SetDate("LastUpdateCheck", value); }
  1054. }
  1055. public static bool CheckForReleaseCandidates
  1056. {
  1057. get { return GetBool("CheckForReleaseCandidates", false); }
  1058. set { SetBool("CheckForReleaseCandidates", value); }
  1059. }
  1060. public static bool OmitUninterestingDiff
  1061. {
  1062. get { return GetBool("OmitUninterestingDiff", false); }
  1063. set { SetBool("OmitUninterestingDiff", value); }
  1064. }
  1065. public static bool UseConsoleEmulatorForCommands
  1066. {
  1067. get { return GetBool("UseConsoleEmulatorForCommands", true); }
  1068. set { SetBool("UseConsoleEmulatorForCommands", value); }
  1069. }
  1070. public static string GetGitExtensionsFullPath()
  1071. {
  1072. return Application.ExecutablePath;
  1073. }
  1074. public static string GetGitExtensionsDirectory()
  1075. {
  1076. return Path.GetDirectoryName(GetGitExtensionsFullPath());
  1077. }
  1078. private static RegistryKey _VersionIndependentRegKey;
  1079. private static RegistryKey VersionIndependentRegKey
  1080. {
  1081. get
  1082. {
  1083. if (_VersionIndependentRegKey == null)
  1084. _VersionIndependentRegKey = Registry.CurrentUser.CreateSubKey("Software\\GitExtensions", RegistryKeyPermissionCheck.ReadWriteSubTree);
  1085. return _VersionIndependentRegKey;
  1086. }
  1087. }
  1088. public static bool IsPortable()
  1089. {
  1090. return Properties.Settings.Default.IsPortable;
  1091. }
  1092. private static IEnumerable<Tuple<string, string>> GetSettingsFromRegistry()
  1093. {
  1094. RegistryKey oldSettings = VersionIndependentRegKey.OpenSubKey("GitExtensions");
  1095. if (oldSettings == null)
  1096. yield break;
  1097. foreach (String name in oldSettings.GetValueNames())
  1098. {
  1099. object value = oldSettings.GetValue(name, null);
  1100. if (value != null)
  1101. yield return new Tuple<string, string>(name, value.ToString());
  1102. }
  1103. }
  1104. private static void ImportFromRegistry()
  1105. {
  1106. SettingsContainer.SettingsCache.Import(GetSettingsFromRegistry());
  1107. }
  1108. public static string PrefixedName(string prefix, string name)
  1109. {
  1110. return prefix == null ? name : prefix + '_' + name;
  1111. }
  1112. public static bool? GetBool(string name)
  1113. {
  1114. return SettingsContainer.GetBool(name);
  1115. }
  1116. public static bool GetBool(string name, bool defaultValue)
  1117. {
  1118. return SettingsContainer.GetBool(name, defaultValue);
  1119. }
  1120. public static void SetBool(string name, bool? value)
  1121. {
  1122. SettingsContainer.SetBool(name, value);
  1123. }
  1124. public static void SetInt(string name, int? value)
  1125. {
  1126. SettingsContainer.SetInt(name, value);
  1127. }
  1128. public static int? GetInt(string name)
  1129. {
  1130. return SettingsContainer.GetInt(name);
  1131. }
  1132. public static DateTime GetDate(string name, DateTime defaultValue)
  1133. {
  1134. return SettingsContainer.GetDate(name, defaultValue);
  1135. }
  1136. public static void SetDate(string name, DateTime? value)
  1137. {
  1138. SettingsContainer.SetDate(name, value);
  1139. }
  1140. public static DateTime? GetDate(string name)
  1141. {
  1142. return SettingsContainer.GetDate(name);
  1143. }
  1144. public static int GetInt(string name, int defaultValue)
  1145. {
  1146. return SettingsContainer.GetInt(name, defaultValue);
  1147. }
  1148. public static void SetFont(string name, Font value)
  1149. {
  1150. SettingsContainer.SetFont(name, value);
  1151. }
  1152. public static Font GetFont(string name, Font defaultValue)
  1153. {
  1154. return SettingsContainer.GetFont(name, defaultValue);
  1155. }
  1156. public static void SetColor(string name, Color? value)
  1157. {
  1158. SettingsContainer.SetColor(name, value);
  1159. }
  1160. public static Color? GetColor(string name)
  1161. {
  1162. return SettingsContainer.GetColor(name);
  1163. }
  1164. public static Color GetColor(string name, Color defaultValue)
  1165. {
  1166. return SettingsContainer.GetColor(name, defaultValue);
  1167. }
  1168. public static void SetEnum<T>(string name, T value)
  1169. {
  1170. SettingsContainer.SetEnum(name, value);
  1171. }
  1172. public static T GetEnum<T>(string name, T defaultValue) where T : struct
  1173. {
  1174. return SettingsContainer.GetEnum(name, defaultValue);
  1175. }
  1176. public static void SetNullableEnum<T>(string name, T? value) where T : struct
  1177. {
  1178. SettingsContainer.SetNullableEnum(name, value);
  1179. }
  1180. public static T? GetNullableEnum<T>(string name) where T : struct
  1181. {
  1182. return SettingsContainer.GetNullableEnum<T>(name);
  1183. }
  1184. public static void SetString(string name, string value)
  1185. {
  1186. SettingsContainer.SetString(name, value);
  1187. }
  1188. public static string GetString(string name, string defaultValue)
  1189. {
  1190. return SettingsContainer.GetString(name, defaultValue);
  1191. }
  1192. }
  1193. /*
  1194. public abstract class Setting<T> : IXmlSerializable
  1195. {
  1196. public SettingsContainer SettingsSource { get; private set; }
  1197. private T _Value;
  1198. public bool HasValue { get; private set; }
  1199. public string Name { get; private set; }
  1200. public T DefaultValue { get; private set; }
  1201. public Setting(SettingsContainer aSettingsSource, string aName, T aDefaultValue)
  1202. {
  1203. SettingsSource = aSettingsSource;
  1204. Name = aName;
  1205. DefaultValue = aDefaultValue;
  1206. HasValue = false;
  1207. }
  1208. public T Value
  1209. {
  1210. get
  1211. {
  1212. return SettingsSource.GetValue(Name, DefaultValue, (s) => DefaultValue);
  1213. }
  1214. set
  1215. {
  1216. //SettingsSource.SetValue(this, value);
  1217. }
  1218. }
  1219. public virtual System.Xml.Schema.XmlSchema GetSchema()
  1220. {
  1221. return null;
  1222. }
  1223. public abstract void ReadXml(XmlReader reader);
  1224. public abstract void WriteXml(XmlWriter writer);
  1225. }
  1226. */
  1227. }