forked from yysun/Git-Source-Control-Provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitSccOptions.cs
154 lines (136 loc) · 4.94 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
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; }
public bool DisableDiffMargin { get; set; }
public bool UseVsDiff { get; set; }
private static GitSccOptions gitSccOptions;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public static GitSccOptions Current
{
get
{
if (gitSccOptions == null)
{
gitSccOptions = LoadFromConfig();
}
return gitSccOptions;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public static bool IsVisualStudio2010
{
get
{
return !IsVisualStudio2012 && BasicSccProvider.GetGlobalService(typeof(SVsSolution)) is IVsSolution4;
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public static bool IsVisualStudio2012
{
get
{
return BasicSccProvider.GetGlobalService(typeof(SVsDifferenceService)) != null;
}
}
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(TortoiseGitPath))
{
TortoiseGitPath = TryFindFile(new string[]{
@"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe",
@"C:\Program Files (x86)\TortoiseGit\bin\TortoiseGitProc.exe",
});
}
if (string.IsNullOrEmpty(DifftoolPath)) DifftoolPath = "diffmerge.exe";
bool diffServiceAvailable = Package.GetGlobalService(typeof(SVsDifferenceService)) != null;
if (!diffServiceAvailable)
UseVsDiff = false;
}
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;
}
}
}