-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathWindowsSettings.cs
More file actions
56 lines (47 loc) · 1.9 KB
/
WindowsSettings.cs
File metadata and controls
56 lines (47 loc) · 1.9 KB
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
namespace GitCredentialManager.Interop.Windows
{
/// <summary>
/// Reads settings from Git configuration, environment variables, and defaults from the Windows Registry.
/// </summary>
public class WindowsSettings : Settings
{
private readonly ITrace _trace;
public WindowsSettings(IEnvironment environment, IGit git, ITrace trace)
: base(environment, git)
{
EnsureArgument.NotNull(trace, nameof(trace));
_trace = trace;
PlatformUtils.EnsureWindows();
}
protected internal override bool TryGetExternalDefault(string section, string scope, string property, out string value)
{
value = null;
#if NETFRAMEWORK
// Check for machine (HKLM) registry keys that match the Git configuration name.
// These can be set by system administrators via Group Policy, so make useful defaults.
using (Microsoft.Win32.RegistryKey configKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Constants.WindowsRegistry.HKConfigurationPath))
{
if (configKey is null)
{
// No configuration key exists
return false;
}
string name = string.IsNullOrWhiteSpace(scope)
? $"{section}.{property}"
: $"{section}.{scope}.{property}";
object registryValue = configKey.GetValue(name);
if (registryValue is null)
{
// No property exists
return false;
}
value = registryValue.ToString();
_trace.WriteLine($"Default setting found in registry: {name}={value}");
return true;
}
#else
return base.TryGetExternalDefault(section, scope, property, out value);
#endif
}
}
}