PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/GitCommands/Settings.cs

https://github.com/eisnerd/gitextensions
C# | 1385 lines | 1281 code | 95 blank | 9 comment | 55 complexity | ebd0e3df8cc31a8203434c2605438d4a MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using GitCommands.Config;
  10. using GitCommands.Logging;
  11. using GitCommands.Repository;
  12. using Microsoft.Win32;
  13. namespace GitCommands
  14. {
  15. public static class Settings
  16. {
  17. //semi-constants
  18. public static readonly string GitExtensionsVersionString;
  19. public static readonly int GitExtensionsVersionInt;
  20. public static readonly char PathSeparator = '\\';
  21. public static readonly char PathSeparatorWrong = '/';
  22. private static readonly Dictionary<String, object> byNameMap = new Dictionary<String, object>();
  23. static Settings()
  24. {
  25. Version version = Assembly.GetCallingAssembly().GetName().Version;
  26. GitExtensionsVersionString = version.Major.ToString() + '.' + version.Minor.ToString();
  27. GitExtensionsVersionInt = version.Major * 100 + (version.Minor < 100 ? version.Minor : 99);
  28. if (!RunningOnWindows())
  29. {
  30. PathSeparator = '/';
  31. PathSeparatorWrong = '\\';
  32. }
  33. GitLog = new CommandLogger();
  34. //Make applicationdatapath version dependent
  35. ApplicationDataPath = Application.UserAppDataPath.Replace(Application.ProductVersion, string.Empty);
  36. }
  37. private static int? _UserMenuLocationX;
  38. public static int UserMenuLocationX
  39. {
  40. get { return SafeGet("usermenulocationx", -1, ref _UserMenuLocationX); }
  41. set { SafeSet("usermenulocationx", value, ref _UserMenuLocationX); }
  42. }
  43. private static int? _UserMenuLocationY;
  44. public static int UserMenuLocationY
  45. {
  46. get { return SafeGet("usermenulocationy", -1, ref _UserMenuLocationY); }
  47. set { SafeSet("usermenulocationy", value, ref _UserMenuLocationY); }
  48. }
  49. private static bool? _cherryPickSilently;
  50. public static bool CherryPickSilently
  51. {
  52. get { return SafeGet("cherrypicksilently", true, ref _cherryPickSilently); }
  53. set { SafeSet("cherrypicksilently", value, ref _cherryPickSilently); }
  54. }
  55. private static bool? _cherryPickAddsReference;
  56. public static bool CherryPickAddsReference
  57. {
  58. get { return SafeGet("cherrypickaddsreference", true, ref _cherryPickAddsReference); }
  59. set { SafeSet("cherrypickaddsreference", value, ref _cherryPickAddsReference); }
  60. }
  61. private static bool? _stashKeepIndex;
  62. public static bool StashKeepIndex
  63. {
  64. get { return SafeGet("stashkeepindex", false, ref _stashKeepIndex); }
  65. set { SafeSet("stashkeepindex", value, ref _stashKeepIndex); }
  66. }
  67. private static bool? _stashConfirmDropShow;
  68. public static bool StashConfirmDropShow
  69. {
  70. get { return SafeGet("stashconfirmdropshow", true, ref _stashConfirmDropShow); }
  71. set { SafeSet("stashconfirmdropshow", value, ref _stashConfirmDropShow); }
  72. }
  73. private static bool? _applyPatchIgnoreWhitespace;
  74. public static bool ApplyPatchIgnoreWhitespace
  75. {
  76. get { return SafeGet("applypatchignorewhitespace", false, ref _applyPatchIgnoreWhitespace); }
  77. set { SafeSet("applypatchignorewhitespace", value, ref _applyPatchIgnoreWhitespace); }
  78. }
  79. private static bool? _usePatienceDiffAlgorithm;
  80. public static bool UsePatienceDiffAlgorithm
  81. {
  82. get { return SafeGet("usepatiencediffalgorithm", false, ref _usePatienceDiffAlgorithm); }
  83. set { SafeSet("usepatiencediffalgorithm", value, ref _usePatienceDiffAlgorithm); }
  84. }
  85. private static bool? _showErrorsWhenStagingFiles;
  86. public static bool ShowErrorsWhenStagingFiles
  87. {
  88. get { return SafeGet("showerrorswhenstagingfiles", true, ref _showErrorsWhenStagingFiles); }
  89. set { SafeSet("showerrorswhenstagingfiles", value, ref _showErrorsWhenStagingFiles); }
  90. }
  91. private static string _lastCommitMessage;
  92. public static string LastCommitMessage
  93. {
  94. get { return SafeGet("lastCommitMessage", "", ref _lastCommitMessage); }
  95. set { SafeSet("lastCommitMessage", value, ref _lastCommitMessage); }
  96. }
  97. private static string _truncatePathMethod;
  98. public static string TruncatePathMethod
  99. {
  100. get { return SafeGet("truncatepathmethod", "none", ref _truncatePathMethod); }
  101. set { SafeSet("truncatepathmethod", value, ref _truncatePathMethod); }
  102. }
  103. private static bool? _showGitStatusInBrowseToolbar;
  104. public static bool ShowGitStatusInBrowseToolbar
  105. {
  106. get { return SafeGet("showgitstatusinbrowsetoolbar", true, ref _showGitStatusInBrowseToolbar); }
  107. set { SafeSet("showgitstatusinbrowsetoolbar", value, ref _showGitStatusInBrowseToolbar); }
  108. }
  109. public static bool CommitInfoShowContainedInBranches
  110. {
  111. get
  112. {
  113. return CommitInfoShowContainedInBranchesLocal ||
  114. CommitInfoShowContainedInBranchesRemote ||
  115. CommitInfoShowContainedInBranchesRemoteIfNoLocal;
  116. }
  117. }
  118. private static bool? _commitInfoShowContainedInBranchesLocal;
  119. public static bool CommitInfoShowContainedInBranchesLocal
  120. {
  121. get { return SafeGet("commitinfoshowcontainedinbrancheslocal", true, ref _commitInfoShowContainedInBranchesLocal); }
  122. set { SafeSet("commitinfoshowcontainedinbrancheslocal", value, ref _commitInfoShowContainedInBranchesLocal); }
  123. }
  124. private static bool? _commitInfoShowContainedInBranchesRemote;
  125. public static bool CommitInfoShowContainedInBranchesRemote
  126. {
  127. get { return SafeGet("commitinfoshowcontainedinbranchesremote", false, ref _commitInfoShowContainedInBranchesRemote); }
  128. set { SafeSet("commitinfoshowcontainedinbranchesremote", value, ref _commitInfoShowContainedInBranchesRemote); }
  129. }
  130. private static bool? _commitInfoShowContainedInBranchesRemoteIfNoLocal;
  131. public static bool CommitInfoShowContainedInBranchesRemoteIfNoLocal
  132. {
  133. get { return SafeGet("commitinfoshowcontainedinbranchesremoteifnolocal", false, ref _commitInfoShowContainedInBranchesRemoteIfNoLocal); }
  134. set { SafeSet("commitinfoshowcontainedinbranchesremoteifnolocal", value, ref _commitInfoShowContainedInBranchesRemoteIfNoLocal); }
  135. }
  136. private static bool? _commitInfoShowContainedInTags;
  137. public static bool CommitInfoShowContainedInTags
  138. {
  139. get { return SafeGet("commitinfoshowcontainedintags", true, ref _commitInfoShowContainedInTags); }
  140. set { SafeSet("commitinfoshowcontainedintags", value, ref _commitInfoShowContainedInTags); }
  141. }
  142. public static string ApplicationDataPath { get; private set; }
  143. public static string GravatarCachePath
  144. {
  145. get { return ApplicationDataPath + "Images\\"; }
  146. }
  147. private static string _translation;
  148. public static string Translation
  149. {
  150. get { return SafeGet("translation", "", ref _translation); }
  151. set { SafeSet("translation", value, ref _translation); }
  152. }
  153. private static bool? _userProfileHomeDir;
  154. public static bool UserProfileHomeDir
  155. {
  156. get { return SafeGet("userprofilehomedir", false, ref _userProfileHomeDir); }
  157. set { SafeSet("userprofilehomedir", value, ref _userProfileHomeDir); }
  158. }
  159. private static string _customHomeDir;
  160. public static string CustomHomeDir
  161. {
  162. get { return SafeGet("customhomedir", "", ref _customHomeDir); }
  163. set { SafeSet("customhomedir", value, ref _customHomeDir); }
  164. }
  165. private static string _iconColor;
  166. public static string IconColor
  167. {
  168. get { return SafeGet("iconcolor", "default", ref _iconColor); }
  169. set { SafeSet("iconcolor", value, ref _iconColor); }
  170. }
  171. private static string _iconStyle;
  172. public static string IconStyle
  173. {
  174. get { return SafeGet("iconstyle", "default", ref _iconStyle); }
  175. set { SafeSet("iconstyle", value, ref _iconStyle); }
  176. }
  177. private static int? _authorImageSize;
  178. public static int AuthorImageSize
  179. {
  180. get { return SafeGet("authorimagesize", 80, ref _authorImageSize); }
  181. set { SafeSet("authorimagesize", value, ref _authorImageSize); }
  182. }
  183. private static int? _authorImageCacheDays;
  184. public static int AuthorImageCacheDays
  185. {
  186. get { return SafeGet("authorimagecachedays", 5, ref _authorImageCacheDays); }
  187. set { SafeSet("authorimagecachedays", value, ref _authorImageCacheDays); }
  188. }
  189. private static bool? _showAuthorGravatar;
  190. public static bool ShowAuthorGravatar
  191. {
  192. get { return SafeGet("showauthorgravatar", true, ref _showAuthorGravatar); }
  193. set { SafeSet("showauthorgravatar", value, ref _showAuthorGravatar); }
  194. }
  195. private static bool? _closeCommitDialogAfterCommit;
  196. public static bool CloseCommitDialogAfterCommit
  197. {
  198. get { return SafeGet("closecommitdialogaftercommit", true, ref _closeCommitDialogAfterCommit); }
  199. set { SafeSet("closecommitdialogaftercommit", value, ref _closeCommitDialogAfterCommit); }
  200. }
  201. private static bool? _closeCommitDialogAfterLastCommit;
  202. public static bool CloseCommitDialogAfterLastCommit
  203. {
  204. get { return SafeGet("closecommitdialogafterlastcommit", true, ref _closeCommitDialogAfterLastCommit); }
  205. set { SafeSet("closecommitdialogafterlastcommit", value, ref _closeCommitDialogAfterLastCommit); }
  206. }
  207. private static bool? _refreshCommitDialogOnFormFocus;
  208. public static bool RefreshCommitDialogOnFormFocus
  209. {
  210. get { return SafeGet("refreshcommitdialogonformfocus", false, ref _refreshCommitDialogOnFormFocus); }
  211. set { SafeSet("refreshcommitdialogonformfocus", value, ref _refreshCommitDialogOnFormFocus); }
  212. }
  213. private static bool? _PlaySpecialStartupSound;
  214. public static bool PlaySpecialStartupSound
  215. {
  216. get { return SafeGet("PlaySpecialStartupSound", false, ref _PlaySpecialStartupSound); }
  217. set { SafeSet("PlaySpecialStartupSound", value, ref _PlaySpecialStartupSound); }
  218. }
  219. private static bool? _followRenamesInFileHistory;
  220. public static bool FollowRenamesInFileHistory
  221. {
  222. get { return SafeGet("followrenamesinfilehistory", true, ref _followRenamesInFileHistory); }
  223. set { SafeSet("followrenamesinfilehistory", value, ref _followRenamesInFileHistory); }
  224. }
  225. private static bool? _fullHistoryInFileHistory;
  226. public static bool FullHistoryInFileHistory
  227. {
  228. get { return SafeGet("fullhistoryinfilehistory", false, ref _fullHistoryInFileHistory); }
  229. set { SafeSet("fullhistoryinfilehistory", value, ref _fullHistoryInFileHistory); }
  230. }
  231. public static bool LoadFileHistoryOnShow
  232. {
  233. get { return GetBool("LoadFileHistoryOnShow", true).Value; }
  234. set { SetBool("LoadFileHistoryOnShow", value); }
  235. }
  236. public static bool LoadBlameOnShow
  237. {
  238. get { return GetBool("LoadBlameOnShow", true).Value; }
  239. set { SetBool("LoadBlameOnShow", value); }
  240. }
  241. private static bool? _revisionGraphShowWorkingDirChanges;
  242. public static bool RevisionGraphShowWorkingDirChanges
  243. {
  244. get { return SafeGet("revisiongraphshowworkingdirchanges", false, ref _revisionGraphShowWorkingDirChanges); }
  245. set { SafeSet("revisiongraphshowworkingdirchanges", value, ref _revisionGraphShowWorkingDirChanges); }
  246. }
  247. private static bool? _revisionGraphDrawNonRelativesGray;
  248. public static bool RevisionGraphDrawNonRelativesGray
  249. {
  250. get { return SafeGet("revisiongraphdrawnonrelativesgray", true, ref _revisionGraphDrawNonRelativesGray); }
  251. set { SafeSet("revisiongraphdrawnonrelativesgray", value, ref _revisionGraphDrawNonRelativesGray); }
  252. }
  253. private static bool? _revisionGraphDrawNonRelativesTextGray;
  254. public static bool RevisionGraphDrawNonRelativesTextGray
  255. {
  256. get { return SafeGet("revisiongraphdrawnonrelativestextgray", false, ref _revisionGraphDrawNonRelativesTextGray); }
  257. set { SafeSet("revisiongraphdrawnonrelativestextgray", value, ref _revisionGraphDrawNonRelativesTextGray); }
  258. }
  259. public static readonly Dictionary<string, Encoding> availableEncodings = new Dictionary<string, Encoding>();
  260. private static Encoding GetEncoding(bool local, string settingName, bool fromSettings)
  261. {
  262. string lname = local ? "_local" + '_' + WorkingDir : "_global";
  263. lname = settingName + lname;
  264. object o;
  265. if (byNameMap.TryGetValue(lname, out o))
  266. return o as Encoding;
  267. string encodingName;
  268. if (fromSettings)
  269. encodingName = GetString("n_" + lname, null);
  270. else
  271. {
  272. ConfigFile cfg;
  273. if (local)
  274. cfg = Module.GetLocalConfig();
  275. else
  276. cfg = GitCommandHelpers.GetGlobalConfig();
  277. encodingName = cfg.GetValue(settingName);
  278. }
  279. Encoding result;
  280. if (string.IsNullOrEmpty(encodingName))
  281. result = null;
  282. else if (!availableEncodings.TryGetValue(encodingName, out result))
  283. {
  284. try
  285. {
  286. result = Encoding.GetEncoding(encodingName);
  287. }
  288. catch (ArgumentException)
  289. {
  290. Debug.WriteLine(string.Format("Unsupported encoding set in git config file: {0}\nPlease check the setting {1} in your {2} config file.", encodingName, settingName, (local ? "local" : "global")));
  291. result = null;
  292. }
  293. }
  294. byNameMap[lname] = result;
  295. return result;
  296. }
  297. private static void SetEncoding(bool local, string settingName, Encoding encoding, bool toSettings)
  298. {
  299. string lname = local ? "_local" + '_' + WorkingDir : "_global";
  300. lname = settingName + lname;
  301. // remove local settings
  302. var items = (from item in byNameMap.Keys where item.StartsWith(lname) select item).ToList();
  303. foreach (var item in items)
  304. byNameMap.Remove(item);
  305. byNameMap[lname] = encoding;
  306. //storing to config file is handled by FormSettings
  307. if (toSettings)
  308. SetString("n_" + lname, encoding == null ? null : encoding.HeaderName);
  309. }
  310. //encoding for files paths
  311. public static Encoding SystemEncoding;
  312. //Encoding that let us read all bytes without replacing any char
  313. public static readonly Encoding LosslessEncoding = Encoding.GetEncoding("ISO-8859-1");//is any better?
  314. //follow by git i18n CommitEncoding and LogOutputEncoding is a hell
  315. //command output may consist of:
  316. //1) commit message encoded in CommitEncoding, recoded to LogOutputEncoding or not dependent of
  317. // pretty parameter (pretty=raw - recoded, pretty=format - not recoded)
  318. //2) author name encoded dependently on config file encoding, not recoded to LogOutputEncoding
  319. //3) file content encoded in its original encoding, not recoded to LogOutputEncoding
  320. //4) file path (file name is encoded in system default encoding), not recoded to LogOutputEncoding,
  321. // every not ASCII character is escaped with \ followed by its code as a three digit octal number
  322. //5) branch or tag name encoded in system default encoding, not recoded to LogOutputEncoding
  323. //saying that "At the core level, git is character encoding agnostic." is not enough
  324. //In my opinion every data not encoded in utf8 should contain information
  325. //about its encoding, also git should emit structured data
  326. //i18n CommitEncoding and LogOutputEncoding properties are stored in config file, because of 2)
  327. //it is better to encode this file in utf8 for international projects. To read config file properly
  328. //we must know its encoding, let user decide by setting AppEncoding property which encoding has to be used
  329. //to read/write config file
  330. public static Encoding GetAppEncoding(bool local, bool returnDefault)
  331. {
  332. Encoding result = GetEncoding(local, "AppEncoding", true);
  333. if (result == null && returnDefault)
  334. result = new UTF8Encoding(false);
  335. return result;
  336. }
  337. public static void SetAppEncoding(bool local, Encoding encoding)
  338. {
  339. SetEncoding(local, "AppEncoding", encoding, true);
  340. }
  341. public static Encoding AppEncoding
  342. {
  343. get
  344. {
  345. Encoding result = GetAppEncoding(true, false);
  346. if (result == null)
  347. result = GetAppEncoding(false, true);
  348. return result;
  349. }
  350. }
  351. public static Encoding GetFilesEncoding(bool local)
  352. {
  353. return GetEncoding(local, "i18n.filesEncoding", false);
  354. }
  355. public static void SetFilesEncoding(bool local, Encoding encoding)
  356. {
  357. SetEncoding(local, "i18n.filesEncoding", encoding, false);
  358. }
  359. public static Encoding FilesEncoding
  360. {
  361. get
  362. {
  363. Encoding result = GetFilesEncoding(true);
  364. if (result == null)
  365. result = GetFilesEncoding(false);
  366. if (result == null)
  367. result = new UTF8Encoding(false);
  368. return result;
  369. }
  370. }
  371. public static Encoding GetCommitEncoding(bool local)
  372. {
  373. return GetEncoding(local, "i18n.commitEncoding", false);
  374. }
  375. public static void SetCommitEncoding(bool local, Encoding encoding)
  376. {
  377. SetEncoding(local, "i18n.commitEncoding", encoding, false);
  378. }
  379. public static Encoding CommitEncoding
  380. {
  381. get
  382. {
  383. Encoding result = GetCommitEncoding(true);
  384. if (result == null)
  385. result = GetCommitEncoding(false);
  386. if (result == null)
  387. result = new UTF8Encoding(false);
  388. return result;
  389. }
  390. }
  391. public static Encoding GetLogOutputEncoding(bool local)
  392. {
  393. return GetEncoding(local, "i18n.logoutputencoding", false);
  394. }
  395. public static void SetLogOutputEncoding(bool local, Encoding encoding)
  396. {
  397. SetEncoding(local, "i18n.logoutputencoding", encoding, false);
  398. }
  399. public static Encoding LogOutputEncoding
  400. {
  401. get
  402. {
  403. Encoding result = GetLogOutputEncoding(true);
  404. if (result == null)
  405. result = GetLogOutputEncoding(false);
  406. if (result == null)
  407. result = CommitEncoding;
  408. return result;
  409. }
  410. }
  411. public enum PullAction
  412. {
  413. None,
  414. Merge,
  415. Rebase,
  416. Fetch,
  417. FetchAll
  418. }
  419. public static PullAction PullMerge
  420. {
  421. get { return GetEnum<PullAction>("pullmerge", PullAction.Merge); }
  422. set { SetEnum<PullAction>("pullmerge", value); }
  423. }
  424. public static bool DonSetAsLastPullAction
  425. {
  426. get { return GetBool("DonSetAsLastPullAction", true).Value; }
  427. set { SetBool("DonSetAsLastPullAction", value); }
  428. }
  429. public static PullAction LastPullAction
  430. {
  431. get { return GetEnum<PullAction>("LastPullAction_" + WorkingDir, PullAction.None); }
  432. set { SetEnum<PullAction>("LastPullAction_" + WorkingDir, value); }
  433. }
  434. public static void LastPullActionToPullMerge()
  435. {
  436. if (LastPullAction == PullAction.FetchAll)
  437. PullMerge = PullAction.Fetch;
  438. else if (LastPullAction != PullAction.None)
  439. PullMerge = LastPullAction;
  440. }
  441. private static string _smtp;
  442. public static string Smtp
  443. {
  444. get { return SafeGet("smtp", "", ref _smtp); }
  445. set { SafeSet("smtp", value, ref _smtp); }
  446. }
  447. private static bool? _autoStash;
  448. public static bool AutoStash
  449. {
  450. get { return SafeGet("autostash", false, ref _autoStash); }
  451. set { SafeSet("autostash", value, ref _autoStash); }
  452. }
  453. private static int? _checkoutBranchAction;
  454. public static int CheckoutBranchAction
  455. {
  456. get { return SafeGet("checkoutBranchAction", 1, ref _checkoutBranchAction); }
  457. set { SafeSet("checkoutBranchAction", value, ref _checkoutBranchAction); }
  458. }
  459. private static bool? _includeUntrackedFilesInAutoStash;
  460. public static bool IncludeUntrackedFilesInAutoStash
  461. {
  462. get { return SafeGet("includeUntrackedFilesInAutoStash", true, ref _includeUntrackedFilesInAutoStash); }
  463. set { SafeSet("includeUntrackedFilesInAutoStash", value, ref _includeUntrackedFilesInAutoStash); }
  464. }
  465. private static bool? _includeUntrackedFilesInManualStash;
  466. public static bool IncludeUntrackedFilesInManualStash
  467. {
  468. get { return SafeGet("includeUntrackedFilesInManualStash", true, ref _includeUntrackedFilesInManualStash); }
  469. set { SafeSet("includeUntrackedFilesInManualStash", value, ref _includeUntrackedFilesInManualStash); }
  470. }
  471. private static bool? _orderRevisionByDate;
  472. public static bool OrderRevisionByDate
  473. {
  474. get { return SafeGet("orderrevisionbydate", true, ref _orderRevisionByDate); }
  475. set { SafeSet("orderrevisionbydate", value, ref _orderRevisionByDate); }
  476. }
  477. private static string _dictionary;
  478. public static string Dictionary
  479. {
  480. get { return SafeGet("dictionary", "en-US", ref _dictionary); }
  481. set { SafeSet("dictionary", value, ref _dictionary); }
  482. }
  483. private static bool? _showGitCommandLine;
  484. public static bool ShowGitCommandLine
  485. {
  486. get { return SafeGet("showgitcommandline", false, ref _showGitCommandLine); }
  487. set { SafeSet("showgitcommandline", value, ref _showGitCommandLine); }
  488. }
  489. private static bool? _showStashCount;
  490. public static bool ShowStashCount
  491. {
  492. get { return SafeGet("showstashcount", false, ref _showStashCount); }
  493. set { SafeSet("showstashcount", value, ref _showStashCount); }
  494. }
  495. private static bool? _relativeDate;
  496. public static bool RelativeDate
  497. {
  498. get { return SafeGet("relativedate", true, ref _relativeDate); }
  499. set { SafeSet("relativedate", value, ref _relativeDate); }
  500. }
  501. private static bool? _useFastChecks;
  502. public static bool UseFastChecks
  503. {
  504. get { return SafeGet("usefastchecks", false, ref _useFastChecks); }
  505. set { SafeSet("usefastchecks", value, ref _useFastChecks); }
  506. }
  507. private static bool? _showGitNotes;
  508. public static bool ShowGitNotes
  509. {
  510. get { return SafeGet("showgitnotes", false, ref _showGitNotes); }
  511. set { SafeSet("showgitnotes", value, ref _showGitNotes); }
  512. }
  513. private static int? _revisionGraphLayout;
  514. public static int RevisionGraphLayout
  515. {
  516. get { return SafeGet("revisiongraphlayout", 2, ref _revisionGraphLayout); }
  517. set { SafeSet("revisiongraphlayout", value, ref _revisionGraphLayout); }
  518. }
  519. private static bool? _showAuthorDate;
  520. public static bool ShowAuthorDate
  521. {
  522. get { return SafeGet("showauthordate", true, ref _showAuthorDate); }
  523. set { SafeSet("showauthordate", value, ref _showAuthorDate); }
  524. }
  525. private static bool? _closeProcessDialog;
  526. public static bool CloseProcessDialog
  527. {
  528. get { return SafeGet("closeprocessdialog", false, ref _closeProcessDialog); }
  529. set { SafeSet("closeprocessdialog", value, ref _closeProcessDialog); }
  530. }
  531. private static bool? _showCurrentBranchOnly;
  532. public static bool ShowCurrentBranchOnly
  533. {
  534. get { return SafeGet("showcurrentbranchonly", false, ref _showCurrentBranchOnly); }
  535. set { SafeSet("showcurrentbranchonly", value, ref _showCurrentBranchOnly); }
  536. }
  537. private static bool? _branchFilterEnabled;
  538. public static bool BranchFilterEnabled
  539. {
  540. get { return SafeGet("branchfilterenabled", false, ref _branchFilterEnabled); }
  541. set { SafeSet("branchfilterenabled", value, ref _branchFilterEnabled); }
  542. }
  543. private static int? _commitDialogSplitter;
  544. public static int CommitDialogSplitter
  545. {
  546. get { return SafeGet("commitdialogsplitter", 400, ref _commitDialogSplitter); }
  547. set { SafeSet("commitdialogsplitter", value, ref _commitDialogSplitter); }
  548. }
  549. private static int? _revisionGridQuickSearchTimeout;
  550. public static int RevisionGridQuickSearchTimeout
  551. {
  552. get { return SafeGet("revisiongridquicksearchtimeout", 750, ref _revisionGridQuickSearchTimeout); }
  553. set { SafeSet("revisiongridquicksearchtimeout", value, ref _revisionGridQuickSearchTimeout); }
  554. }
  555. private static string _gravatarFallbackService;
  556. public static string GravatarFallbackService
  557. {
  558. get { return SafeGet("gravatarfallbackservice", "Identicon", ref _gravatarFallbackService); }
  559. set { SafeSet("gravatarfallbackservice", value, ref _gravatarFallbackService); }
  560. }
  561. private static string _gitCommand;
  562. public static string GitCommand
  563. {
  564. get { return SafeGet("gitcommand", "git", ref _gitCommand); }
  565. set { SafeSet("gitcommand", value, ref _gitCommand); }
  566. }
  567. private static string _gitBinDir;
  568. public static string GitBinDir
  569. {
  570. get { return SafeGet("gitbindir", "", ref _gitBinDir); }
  571. set
  572. {
  573. var temp = value;
  574. if (temp.Length > 0 && temp[temp.Length - 1] != PathSeparator)
  575. temp += PathSeparator;
  576. SafeSet("gitbindir", temp, ref _gitBinDir);
  577. //if (string.IsNullOrEmpty(_gitBinDir))
  578. // return;
  579. //var path =
  580. // Environment.GetEnvironmentVariable("path", EnvironmentVariableTarget.Process) + ";" +
  581. // _gitBinDir;
  582. //Environment.SetEnvironmentVariable("path", path, EnvironmentVariableTarget.Process);
  583. }
  584. }
  585. private static int? _maxRevisionGraphCommits;
  586. public static int MaxRevisionGraphCommits
  587. {
  588. get { return SafeGet("maxrevisiongraphcommits", 100000, ref _maxRevisionGraphCommits); }
  589. set { SafeSet("maxrevisiongraphcommits", value, ref _maxRevisionGraphCommits); }
  590. }
  591. public delegate void WorkingDirChangedEventHandler(string oldDir, string newDir, string newGitDir);
  592. public static event WorkingDirChangedEventHandler WorkingDirChanged;
  593. private static readonly GitModule _module = new GitModule();
  594. public static GitModule Module
  595. {
  596. [DebuggerStepThrough]
  597. get
  598. {
  599. return _module;
  600. }
  601. }
  602. public static string WorkingDir
  603. {
  604. get
  605. {
  606. return _module.WorkingDir;
  607. }
  608. set
  609. {
  610. string old = _module.WorkingDir;
  611. _module.WorkingDir = value;
  612. RecentWorkingDir = _module.WorkingDir;
  613. if (WorkingDirChanged != null)
  614. {
  615. WorkingDirChanged(old, _module.WorkingDir, _module.GetGitDirectory());
  616. }
  617. }
  618. }
  619. public static string RecentWorkingDir
  620. {
  621. get { return GetString("RecentWorkingDir", null); }
  622. set { SetString("RecentWorkingDir", value); }
  623. }
  624. public static bool StartWithRecentWorkingDir
  625. {
  626. get { return GetBool("StartWithRecentWorkingDir", false).Value; }
  627. set { SetBool("StartWithRecentWorkingDir", value); }
  628. }
  629. public static CommandLogger GitLog { get; private set; }
  630. private static string _plink;
  631. public static string Plink
  632. {
  633. get { return SafeGet("plink", "", ref _plink); }
  634. set { SafeSet("plink", value, ref _plink); }
  635. }
  636. private static string _puttygen;
  637. public static string Puttygen
  638. {
  639. get { return SafeGet("puttygen", "", ref _puttygen); }
  640. set { SafeSet("puttygen", value, ref _puttygen); }
  641. }
  642. private static string _pageant;
  643. public static string Pageant
  644. {
  645. get { return SafeGet("pageant", "", ref _pageant); }
  646. set { SafeSet("pageant", value, ref _pageant); }
  647. }
  648. private static bool? _autoStartPageant;
  649. public static bool AutoStartPageant
  650. {
  651. get { return SafeGet("autostartpageant", true, ref _autoStartPageant); }
  652. set { SafeSet("autostartpageant", value, ref _autoStartPageant); }
  653. }
  654. private static bool? _markIllFormedLinesInCommitMsg;
  655. public static bool MarkIllFormedLinesInCommitMsg
  656. {
  657. get { return SafeGet("markillformedlinesincommitmsg", false, ref _markIllFormedLinesInCommitMsg); }
  658. set { SafeSet("markillformedlinesincommitmsg", value, ref _markIllFormedLinesInCommitMsg); }
  659. }
  660. #region Colors
  661. private static Color? _otherTagColor;
  662. public static Color OtherTagColor
  663. {
  664. get { return SafeGet("othertagcolor", Color.Gray, ref _otherTagColor); }
  665. set { SafeSet("othertagcolor", value, ref _otherTagColor); }
  666. }
  667. private static Color? _tagColor;
  668. public static Color TagColor
  669. {
  670. get { return SafeGet("tagcolor", Color.DarkBlue, ref _tagColor); }
  671. set { SafeSet("tagcolor", value, ref _tagColor); }
  672. }
  673. private static Color? _graphColor;
  674. public static Color GraphColor
  675. {
  676. get { return SafeGet("graphcolor", Color.DarkRed, ref _graphColor); }
  677. set { SafeSet("graphcolor", value, ref _graphColor); }
  678. }
  679. private static Color? _branchColor;
  680. public static Color BranchColor
  681. {
  682. get { return SafeGet("branchcolor", Color.DarkRed, ref _branchColor); }
  683. set { SafeSet("branchcolor", value, ref _branchColor); }
  684. }
  685. private static Color? _remoteBranchColor;
  686. public static Color RemoteBranchColor
  687. {
  688. get { return SafeGet("remotebranchcolor", Color.Green, ref _remoteBranchColor); }
  689. set { SafeSet("remotebranchcolor", value, ref _remoteBranchColor); }
  690. }
  691. private static Color? _diffSectionColor;
  692. public static Color DiffSectionColor
  693. {
  694. get { return SafeGet("diffsectioncolor", Color.FromArgb(230, 230, 230), ref _diffSectionColor); }
  695. set { SafeSet("diffsectioncolor", value, ref _diffSectionColor); }
  696. }
  697. private static Color? _diffRemovedColor;
  698. public static Color DiffRemovedColor
  699. {
  700. get { return SafeGet("diffremovedcolor", Color.FromArgb(255, 200, 200), ref _diffRemovedColor); }
  701. set { SafeSet("diffremovedcolor", value, ref _diffRemovedColor); }
  702. }
  703. private static Color? _diffRemovedExtraColor;
  704. public static Color DiffRemovedExtraColor
  705. {
  706. get { return SafeGet("diffremovedextracolor", Color.FromArgb(255, 150, 150), ref _diffRemovedExtraColor); }
  707. set { SafeSet("diffremovedextracolor", value, ref _diffRemovedExtraColor); }
  708. }
  709. private static Color? _diffAddedColor;
  710. public static Color DiffAddedColor
  711. {
  712. get { return SafeGet("diffaddedcolor", Color.FromArgb(200, 255, 200), ref _diffAddedColor); }
  713. set { SafeSet("diffaddedcolor", value, ref _diffAddedColor); }
  714. }
  715. private static Color? _diffAddedExtraColor;
  716. public static Color DiffAddedExtraColor
  717. {
  718. get { return SafeGet("diffaddedextracolor", Color.FromArgb(135, 255, 135), ref _diffAddedExtraColor); }
  719. set { SafeSet("diffaddedextracolor", value, ref _diffAddedExtraColor); }
  720. }
  721. private static Font _diffFont;
  722. public static Font DiffFont
  723. {
  724. get { return SafeGet("difffont", new Font("Courier New", 10), ref _diffFont); }
  725. set { SafeSet("difffont", value, ref _diffFont); }
  726. }
  727. #endregion
  728. private static bool? _multicolorBranches;
  729. public static bool MulticolorBranches
  730. {
  731. get { return SafeGet("multicolorbranches", true, ref _multicolorBranches); }
  732. set { SafeSet("multicolorbranches", value, ref _multicolorBranches); }
  733. }
  734. private static bool? _stripedBranchChange;
  735. public static bool StripedBranchChange
  736. {
  737. get { return SafeGet("stripedbranchchange", true, ref _stripedBranchChange); }
  738. set { SafeSet("stripedbranchchange", value, ref _stripedBranchChange); }
  739. }
  740. private static bool? _branchBorders;
  741. public static bool BranchBorders
  742. {
  743. get { return SafeGet("branchborders", true, ref _branchBorders); }
  744. set { SafeSet("branchborders", value, ref _branchBorders); }
  745. }
  746. private static bool? _showCurrentBranchInVisualStudio;
  747. public static bool ShowCurrentBranchInVisualStudio
  748. {
  749. //This setting MUST be set to false by default, otherwise it will not work in Visual Studio without
  750. //other changes in the Visual Studio plugin itself.
  751. get { return SafeGet("showcurrentbranchinvisualstudio", true, ref _showCurrentBranchInVisualStudio); }
  752. set { SafeSet("showcurrentbranchinvisualstudio", value, ref _showCurrentBranchInVisualStudio); }
  753. }
  754. private static string _lastFormatPatchDir;
  755. public static string LastFormatPatchDir
  756. {
  757. get { return SafeGet("lastformatpatchdir", "", ref _lastFormatPatchDir); }
  758. set { SafeSet("lastformatpatchdir", value, ref _lastFormatPatchDir); }
  759. }
  760. public static string GetDictionaryDir()
  761. {
  762. return GetInstallDir() + "\\Dictionaries\\";
  763. }
  764. public static string GetInstallDir()
  765. {
  766. return GetValue("InstallDir", "");
  767. }
  768. public static void SetInstallDir(string dir)
  769. {
  770. if (VersionIndependentRegKey != null)
  771. SetValue("InstallDir", dir);
  772. }
  773. public static bool RunningOnWindows()
  774. {
  775. switch (Environment.OSVersion.Platform)
  776. {
  777. case PlatformID.Win32NT:
  778. case PlatformID.Win32S:
  779. case PlatformID.Win32Windows:
  780. case PlatformID.WinCE:
  781. return true;
  782. default:
  783. return false;
  784. }
  785. }
  786. public static bool RunningOnUnix()
  787. {
  788. switch (Environment.OSVersion.Platform)
  789. {
  790. case PlatformID.Unix:
  791. return true;
  792. default:
  793. return false;
  794. }
  795. }
  796. public static bool RunningOnMacOSX()
  797. {
  798. switch (Environment.OSVersion.Platform)
  799. {
  800. case PlatformID.MacOSX:
  801. return true;
  802. default:
  803. return false;
  804. }
  805. }
  806. public static void SaveSettings()
  807. {
  808. try
  809. {
  810. SetValue("gitssh", GitCommandHelpers.GetSsh());
  811. Repositories.SaveSettings();
  812. }
  813. catch
  814. { }
  815. }
  816. private static void TransferEncodings()
  817. {
  818. string encoding = GetValue("encoding", "");
  819. if (!encoding.IsNullOrEmpty())
  820. {
  821. Encoding _encoding;
  822. if (encoding.Equals("Default", StringComparison.CurrentCultureIgnoreCase))
  823. _encoding = Encoding.Default;
  824. else if (encoding.Equals("Unicode", StringComparison.CurrentCultureIgnoreCase))
  825. _encoding = new UnicodeEncoding();
  826. else if (encoding.Equals("ASCII", StringComparison.CurrentCultureIgnoreCase))
  827. _encoding = new ASCIIEncoding();
  828. else if (encoding.Equals("UTF7", StringComparison.CurrentCultureIgnoreCase))
  829. _encoding = new UTF7Encoding();
  830. else if (encoding.Equals("UTF32", StringComparison.CurrentCultureIgnoreCase))
  831. _encoding = new UTF32Encoding(true, false);
  832. else
  833. _encoding = new UTF8Encoding(false);
  834. SetFilesEncoding(false, _encoding);
  835. SetAppEncoding(false, _encoding);
  836. SetValue("encoding", null as string);
  837. }
  838. }
  839. private static void SetupSystemEncoding()
  840. {
  841. //check whether GitExtensions works with standard msysgit or msysgit-unicode
  842. // invoke a git command that returns an invalid argument in its response, and
  843. // check if a unicode-only character is reported back. If so assume msysgit-unicode
  844. // git config --get with a malformed key (no section) returns:
  845. // "error: key does not contain a section: <key>"
  846. const string controlStr = "ą"; // "a caudata"
  847. string arguments = string.Format("config --get {0}", controlStr);
  848. int exitCode;
  849. String s = Module.RunGitCmd(arguments, out exitCode, null, Encoding.UTF8);
  850. if (s != null && s.IndexOf(controlStr) != -1)
  851. SystemEncoding = Encoding.UTF8;
  852. else
  853. SystemEncoding = Encoding.Default;
  854. Debug.WriteLine("System encoding: " + SystemEncoding.EncodingName);
  855. }
  856. public static void LoadSettings()
  857. {
  858. SetupSystemEncoding();
  859. Action<Encoding> addEncoding = delegate(Encoding e) { availableEncodings[e.HeaderName] = e; };
  860. addEncoding(Encoding.Default);
  861. addEncoding(new ASCIIEncoding());
  862. addEncoding(new UnicodeEncoding());
  863. addEncoding(new UTF7Encoding());
  864. addEncoding(new UTF8Encoding());
  865. try
  866. {
  867. TransferEncodings();
  868. TransferVerDependentReg();
  869. }
  870. catch
  871. { }
  872. try
  873. {
  874. GitCommandHelpers.SetSsh(GetValue<string>("gitssh", null));
  875. }
  876. catch
  877. { }
  878. Debug.WriteLine("Files encoding: " + FilesEncoding.EncodingName);
  879. Debug.WriteLine("App encoding: " + AppEncoding.EncodingName);
  880. Debug.WriteLine("Commit encoding: " + CommitEncoding.EncodingName);
  881. if (LogOutputEncoding != CommitEncoding)
  882. Debug.WriteLine("Log output encoding: " + LogOutputEncoding.EncodingName);
  883. }
  884. private static bool? _dashboardShowCurrentBranch;
  885. public static bool DashboardShowCurrentBranch
  886. {
  887. get { return SafeGet("dashboardshowcurrentbranch", true, ref _dashboardShowCurrentBranch); }
  888. set { SafeSet("dashboardshowcurrentbranch", value, ref _dashboardShowCurrentBranch); }
  889. }
  890. private static string _ownScripts;
  891. public static string ownScripts
  892. {
  893. get { return SafeGet("ownScripts", "", ref _ownScripts); }
  894. set { SafeSet("ownScripts", value, ref _ownScripts); }
  895. }
  896. private static bool? _pushAllTags;
  897. public static bool PushAllTags
  898. {
  899. get { return SafeGet("pushalltags", false, ref _pushAllTags); }
  900. set { SafeSet("pushalltags", value, ref _pushAllTags); }
  901. }
  902. private static bool? _AutoPullOnRejected;
  903. public static bool AutoPullOnRejected
  904. {
  905. get { return SafeGet("AutoPullOnRejected", false, ref _AutoPullOnRejected); }
  906. set { SafeSet("AutoPullOnRejected", value, ref _AutoPullOnRejected); }
  907. }
  908. private static bool? _RecursiveSubmodulesCheck;
  909. public static bool RecursiveSubmodulesCheck
  910. {
  911. get { return SafeGet("RecursiveSubmodulesCheck", true, ref _RecursiveSubmodulesCheck); }
  912. set { SafeSet("RecursiveSubmodulesCheck", value, ref _RecursiveSubmodulesCheck); }
  913. }
  914. private static string _ShorteningRecentRepoPathStrategy;
  915. public static string ShorteningRecentRepoPathStrategy
  916. {
  917. get { return SafeGet("ShorteningRecentRepoPathStrategy", "", ref _ShorteningRecentRepoPathStrategy); }
  918. set { SafeSet("ShorteningRecentRepoPathStrategy", value, ref _ShorteningRecentRepoPathStrategy); }
  919. }
  920. private static int? _MaxMostRecentRepositories;
  921. public static int MaxMostRecentRepositories
  922. {
  923. get { return SafeGet("MaxMostRecentRepositories", 0, ref _MaxMostRecentRepositories); }
  924. set { SafeSet("MaxMostRecentRepositories", value, ref _MaxMostRecentRepositories); }
  925. }
  926. private static int? _RecentReposComboMinWidth;
  927. public static int RecentReposComboMinWidth
  928. {
  929. get { return SafeGet("RecentReposComboMinWidth", 0, ref _RecentReposComboMinWidth); }
  930. set { SafeSet("RecentReposComboMinWidth", value, ref _RecentReposComboMinWidth); }
  931. }
  932. private static bool? _SortMostRecentRepos;
  933. public static bool SortMostRecentRepos
  934. {
  935. get { return SafeGet("SortMostRecentRepos", false, ref _SortMostRecentRepos); }
  936. set { SafeSet("SortMostRecentRepos", value, ref _SortMostRecentRepos); }
  937. }
  938. private static bool? _SortLessRecentRepos;
  939. public static bool SortLessRecentRepos
  940. {
  941. get { return SafeGet("SortLessRecentRepos", false, ref _SortLessRecentRepos); }
  942. set { SafeSet("SortLessRecentRepos", value, ref _SortLessRecentRepos); }
  943. }
  944. private static bool? _NoFastForwardMerge;
  945. public static bool NoFastForwardMerge
  946. {
  947. get { return SafeGet("NoFastForwardMerge", false, ref _NoFastForwardMerge); }
  948. set { SafeSet("NoFastForwardMerge", value, ref _NoFastForwardMerge); }
  949. }
  950. private static int? _CommitValidationMaxCntCharsFirstLine;
  951. public static int CommitValidationMaxCntCharsFirstLine
  952. {
  953. get { return SafeGet("CommitValidationMaxCntCharsFirstLine", 0, ref _CommitValidationMaxCntCharsFirstLine); }
  954. set { SafeSet("CommitValidationMaxCntCharsFirstLine", value, ref _CommitValidationMaxCntCharsFirstLine); }
  955. }
  956. private static int? _CommitValidationMaxCntCharsPerLine;
  957. public static int CommitValidationMaxCntCharsPerLine
  958. {
  959. get { return SafeGet("CommitValidationMaxCntCharsPerLine", 0, ref _CommitValidationMaxCntCharsPerLine); }
  960. set { SafeSet("CommitValidationMaxCntCharsPerLine", value, ref _CommitValidationMaxCntCharsPerLine); }
  961. }
  962. private static bool? _CommitValidationSecondLineMustBeEmpty;
  963. public static bool CommitValidationSecondLineMustBeEmpty
  964. {
  965. get { return SafeGet("CommitValidationSecondLineMustBeEmpty", false, ref _CommitValidationSecondLineMustBeEmpty); }
  966. set { SafeSet("CommitValidationSecondLineMustBeEmpty", value, ref _CommitValidationSecondLineMustBeEmpty); }
  967. }
  968. private static string _CommitValidationRegEx;
  969. public static string CommitValidationRegEx
  970. {
  971. get { return SafeGet("CommitValidationRegEx", String.Empty, ref _CommitValidationRegEx); }
  972. set { SafeSet("CommitValidationRegEx", value, ref _CommitValidationRegEx); }
  973. }
  974. private static string _CommitTemplates;
  975. public static string CommitTemplates
  976. {
  977. get { return SafeGet("CommitTemplates", String.Empty, ref _CommitTemplates); }
  978. set { SafeSet("CommitTemplates", value, ref _CommitTemplates); }
  979. }
  980. private static bool? _CreateLocalBranchForRemote;
  981. public static bool CreateLocalBranchForRemote
  982. {
  983. get { return SafeGet("CreateLocalBranchForRemote", false, ref _CreateLocalBranchForRemote); }
  984. set { SafeSet("CreateLocalBranchForRemote", value, ref _CreateLocalBranchForRemote); }
  985. }
  986. private static bool? _ShellCascadeContextMenu;
  987. public static bool ShellCascadeContextMenu
  988. {
  989. get { return SafeGet("ShellCascadeContextMenu", true, ref _ShellCascadeContextMenu); }
  990. set { SafeSet("ShellCascadeContextMenu", value, ref _ShellCascadeContextMenu); }
  991. }
  992. private static string _ShellVisibleMenuItems;
  993. public static string ShellVisibleMenuItems
  994. {
  995. get { return SafeGet("ShellVisibleMenuItems", "11111111111111", ref _ShellVisibleMenuItems); }
  996. set { SafeSet("ShellVisibleMenuItems", value, ref _ShellVisibleMenuItems); }
  997. }
  998. public static string GetGitExtensionsFullPath()
  999. {
  1000. return GetGitExtensionsDirectory() + "\\GitExtensions.exe";
  1001. }
  1002. public static string GetGitExtensionsDirectory()
  1003. {
  1004. string fileName = Assembly.GetAssembly(typeof(Settings)).Location;
  1005. fileName = fileName.Substring(0, fileName.LastIndexOfAny(new[] { '\\', '/' }));
  1006. return fileName;
  1007. }
  1008. private static T SafeGet<T>(string key, T defaultValue, ref T field, Func<string, T> converter)
  1009. {
  1010. if (field == null && VersionIndependentRegKey != null)
  1011. {
  1012. var value = GetValue<object>(key, null);
  1013. field = value == null ? defaultValue : converter(value.ToString());
  1014. }
  1015. return field;
  1016. }
  1017. private static string SafeGet(string key, string defaultValue, ref string field)
  1018. {
  1019. return SafeGet(key, defaultValue, ref field, x => x);
  1020. }
  1021. private static Font SafeGet(string key, Font defaultValue, ref Font field)
  1022. {
  1023. return SafeGet(key, defaultValue, ref field, x => x.Parse(defaultValue));
  1024. }
  1025. private static bool SafeGet(string key, bool defaultValue, ref bool? field)
  1026. {
  1027. return SafeGet(key, defaultValue, ref field, x => x == "True").Value;
  1028. }
  1029. private static int SafeGet(string key, int defaultValue, ref int? field)
  1030. {
  1031. return SafeGet(key, defaultValue, ref field, x =>
  1032. {
  1033. int result;
  1034. return int.TryParse(x, out result) ? result : defaultValue;
  1035. }).Value;
  1036. }
  1037. private static Color SafeGet(string key, Color defaultValue, ref Color? field)
  1038. {
  1039. return SafeGet(key, defaultValue, ref field, x => ColorTranslator.FromHtml(x)).Value;
  1040. }
  1041. private static void SafeSet<T>(string key, T value, ref T field)
  1042. {
  1043. if (Object.Equals(field, value))
  1044. return;
  1045. field = value;
  1046. SetValue(

Large files files are truncated, but you can click here to view the full file