fix: return val is not true when registry val does not exist
This commit is contained in:
parent
622df39fca
commit
98fb7a32db
2 changed files with 7 additions and 7 deletions
|
@ -113,7 +113,7 @@ namespace SafeExamBrowser.Runtime.Operations
|
|||
|
||||
if (registry.TryRead(RegistryValue.MachineHive.EaseOfAccess_Key, RegistryValue.MachineHive.EaseOfAccess_Name, out var value))
|
||||
{
|
||||
if (value == default || (value is string s && string.IsNullOrWhiteSpace(s)))
|
||||
if (value is string s && string.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
success = true;
|
||||
logger.Info("Ease of access configuration successfully verified.");
|
||||
|
@ -135,7 +135,8 @@ namespace SafeExamBrowser.Runtime.Operations
|
|||
}
|
||||
else
|
||||
{
|
||||
logger.Error("Failed to verify ease of access configuration!");
|
||||
success = true;
|
||||
logger.Info("Ease of access configuration successfully verified (value does not exist).");
|
||||
}
|
||||
|
||||
return success;
|
||||
|
|
|
@ -73,21 +73,20 @@ namespace SafeExamBrowser.SystemComponents.Registry
|
|||
|
||||
public bool TryRead(string key, string name, out object value)
|
||||
{
|
||||
var success = false;
|
||||
|
||||
var defaultValue = new object();
|
||||
|
||||
value = default;
|
||||
|
||||
try
|
||||
{
|
||||
value = Microsoft.Win32.Registry.GetValue(key, name, default);
|
||||
success = true;
|
||||
value = Microsoft.Win32.Registry.GetValue(key, name, defaultValue);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error($"Failed to read value '{name}' from registry key '{key}'!", e);
|
||||
}
|
||||
|
||||
return success;
|
||||
return value != default && value != defaultValue;
|
||||
}
|
||||
|
||||
public bool TryGetNames(string keyName, out IEnumerable<string> names)
|
||||
|
|
Loading…
Reference in a new issue