forked from blinkbox/Git-Source-Control-Provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitSccOptions.cs
123 lines (107 loc) · 3.7 KB
/
GitSccOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
namespace GitScc
{
[Serializable]
public class GitSccOptions
{
private static string configFileName = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"gitscc.config");
public string GitBashPath { get; set; }
public string GitExtensionPath { get; set; }
public string DifftoolPath { get; set; }
public string TortoiseGitPath { get; set; }
public bool NotExpandTortoiseGit { get; set; }
public bool NotExpandGitExtensions { get; set; }
public bool UseTGitIconSet { get; set; }
public bool DisableAutoRefresh { get; set; }
public bool DisableAutoLoad { get; set; }
public bool NotUseUTF8FileNames { get; set; }
private static GitSccOptions gitSccOptions;
public static GitSccOptions Current
{
get
{
if (gitSccOptions == null)
{
gitSccOptions = LoadFromConfig();
}
return gitSccOptions;
}
}
private GitSccOptions()
{
}
internal static GitSccOptions LoadFromConfig()
{
GitSccOptions options = null;
if (File.Exists(configFileName))
{
try
{
XmlSerializer serializer = new XmlSerializer(typeof(GitSccOptions));
using (TextReader tr = new StreamReader(configFileName))
{
options = (GitSccOptions)serializer.Deserialize(tr);
}
}
catch
{
}
}
if(options == null) options = new GitSccOptions();
options.Init();
return options;
}
private void Init()
{
if (string.IsNullOrEmpty(GitBashPath))
{
GitBashPath = TryFindFile(new string[]{
@"C:\Program Files\Git\bin\sh.exe",
@"C:\Program Files (x86)\Git\bin\sh.exe",
});
}
if (string.IsNullOrEmpty(GitExtensionPath))
{
GitExtensionPath = TryFindFile(new string[]{
@"C:\Program Files\GitExtensions\GitExtensions.exe",
@"C:\Program Files (x86)\GitExtensions\GitExtensions.exe",
});
}
if (string.IsNullOrEmpty(TortoiseGitPath))
{
TortoiseGitPath = TryFindFile(new string[]{
@"C:\Program Files\TortoiseGit\bin\TortoiseProc.exe",
@"C:\Program Files (x86)\TortoiseGit\bin\TortoiseProc.exe",
});
}
if (string.IsNullOrEmpty(DifftoolPath)) DifftoolPath = "diffmerge.exe";
}
internal void SaveConfig()
{
try
{
XmlSerializer x = new XmlSerializer(typeof(GitSccOptions));
using (TextWriter tw = new StreamWriter(configFileName))
{
x.Serialize(tw, this);
}
}
catch { }
}
private string TryFindFile(string[] paths)
{
foreach (var path in paths)
{
if (File.Exists(path)) return path;
}
return null;
}
}
}