Skip to content

Commit b87bbed

Browse files
committed
Support writing to all registry paths whenever available
1 parent b9c6d14 commit b87bbed

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

RetailCoder.VBE/VBERuntime/VBESettings.cs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public enum DllVersion
1616
Vbe7
1717
}
1818

19-
private readonly string _registryRootPath;
19+
private readonly string _activeRegistryRootPath;
20+
private readonly string[] _registryRootPaths = {Vbe7SettingPath, Vbe6SettingPath};
2021

2122
public VBESettings(IVBE vbe)
2223
{
@@ -26,11 +27,11 @@ public VBESettings(IVBE vbe)
2627
{
2728
case 6:
2829
Version = DllVersion.Vbe6;
29-
_registryRootPath = Vbe6SettingPath;
30+
_activeRegistryRootPath = Vbe6SettingPath;
3031
break;
3132
case 7:
3233
Version = DllVersion.Vbe7;
33-
_registryRootPath = Vbe7SettingPath;
34+
_activeRegistryRootPath = Vbe7SettingPath;
3435
break;
3536
default:
3637
Version = DllVersion.Unknown;
@@ -40,36 +41,53 @@ public VBESettings(IVBE vbe)
4041
catch
4142
{
4243
Version = DllVersion.Unknown;
43-
_registryRootPath = null;
44+
_activeRegistryRootPath = null;
4445
}
4546
}
4647

4748
public DllVersion Version { get; }
4849

4950
public bool CompileOnDemand
5051
{
51-
get => DWordToBooleanConverter(nameof(CompileOnDemand));
52-
set => BooleanToDWordConverter(nameof(CompileOnDemand), value);
52+
get => ReadActiveRegistryPath(nameof(CompileOnDemand));
53+
set => WriteAllRegistryPaths(nameof(CompileOnDemand), value);
5354
}
5455

5556
public bool BackGroundCompile
5657
{
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+
}
5976
}
6077

6178
private const int DWordTrueValue = 1;
6279
private const int DWordFalseValue = 0;
6380

64-
private bool DWordToBooleanConverter(string keyName)
81+
private bool? DWordToBooleanConverter(string path, string keyName)
6582
{
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);
6886
}
6987

70-
private void BooleanToDWordConverter(string keyName, bool value)
88+
private void BooleanToDWordConverter(string path, string keyName, bool value)
7189
{
72-
Registry.SetValue(_registryRootPath, keyName, value ? DWordTrueValue : DWordFalseValue, RegistryValueKind.DWord);
90+
Registry.SetValue(path, keyName, value ? DWordTrueValue : DWordFalseValue, RegistryValueKind.DWord);
7391
}
7492
}
7593
}

0 commit comments

Comments
 (0)