@@ -16,7 +16,8 @@ public enum DllVersion
16
16
Vbe7
17
17
}
18
18
19
- private readonly string _registryRootPath ;
19
+ private readonly string _activeRegistryRootPath ;
20
+ private readonly string [ ] _registryRootPaths = { Vbe7SettingPath , Vbe6SettingPath } ;
20
21
21
22
public VBESettings ( IVBE vbe )
22
23
{
@@ -26,11 +27,11 @@ public VBESettings(IVBE vbe)
26
27
{
27
28
case 6 :
28
29
Version = DllVersion . Vbe6 ;
29
- _registryRootPath = Vbe6SettingPath ;
30
+ _activeRegistryRootPath = Vbe6SettingPath ;
30
31
break ;
31
32
case 7 :
32
33
Version = DllVersion . Vbe7 ;
33
- _registryRootPath = Vbe7SettingPath ;
34
+ _activeRegistryRootPath = Vbe7SettingPath ;
34
35
break ;
35
36
default :
36
37
Version = DllVersion . Unknown ;
@@ -40,36 +41,53 @@ public VBESettings(IVBE vbe)
40
41
catch
41
42
{
42
43
Version = DllVersion . Unknown ;
43
- _registryRootPath = null ;
44
+ _activeRegistryRootPath = null ;
44
45
}
45
46
}
46
47
47
48
public DllVersion Version { get ; }
48
49
49
50
public bool CompileOnDemand
50
51
{
51
- get => DWordToBooleanConverter ( nameof ( CompileOnDemand ) ) ;
52
- set => BooleanToDWordConverter ( nameof ( CompileOnDemand ) , value ) ;
52
+ get => ReadActiveRegistryPath ( nameof ( CompileOnDemand ) ) ;
53
+ set => WriteAllRegistryPaths ( nameof ( CompileOnDemand ) , value ) ;
53
54
}
54
55
55
56
public bool BackGroundCompile
56
57
{
57
- get => DWordToBooleanConverter ( nameof ( BackGroundCompile ) ) ;
58
- set => BooleanToDWordConverter ( nameof ( BackGroundCompile ) , value ) ;
58
+ get => ReadActiveRegistryPath ( nameof ( BackGroundCompile ) ) ;
59
+ set => WriteAllRegistryPaths ( nameof ( BackGroundCompile ) , value ) ;
60
+ }
61
+
62
+ private bool ReadActiveRegistryPath ( string keyName )
63
+ {
64
+ return DWordToBooleanConverter ( _activeRegistryRootPath , keyName ) ?? false ;
65
+ }
66
+
67
+ private void WriteAllRegistryPaths ( string keyName , bool value )
68
+ {
69
+ foreach ( var path in _registryRootPaths )
70
+ {
71
+ if ( DWordToBooleanConverter ( path , keyName ) != null )
72
+ {
73
+ BooleanToDWordConverter ( path , keyName , value ) ;
74
+ }
75
+ }
59
76
}
60
77
61
78
private const int DWordTrueValue = 1 ;
62
79
private const int DWordFalseValue = 0 ;
63
80
64
- private bool DWordToBooleanConverter ( string keyName )
81
+ private bool ? DWordToBooleanConverter ( string path , string keyName )
65
82
{
66
- var result = Registry . GetValue ( _registryRootPath , keyName , DWordFalseValue ) as int ? ;
67
- return Convert . ToBoolean ( result ?? DWordFalseValue ) ;
83
+ return ! ( Registry . GetValue ( path , keyName , DWordFalseValue ) is int result )
84
+ ? ( bool ? ) null
85
+ : Convert . ToBoolean ( result ) ;
68
86
}
69
87
70
- private void BooleanToDWordConverter ( string keyName , bool value )
88
+ private void BooleanToDWordConverter ( string path , string keyName , bool value )
71
89
{
72
- Registry . SetValue ( _registryRootPath , keyName , value ? DWordTrueValue : DWordFalseValue , RegistryValueKind . DWord ) ;
90
+ Registry . SetValue ( path , keyName , value ? DWordTrueValue : DWordFalseValue , RegistryValueKind . DWord ) ;
73
91
}
74
92
}
75
93
}
0 commit comments