fix: return val is not true when registry val does not exist

This commit is contained in:
Notselwyn 2023-12-28 16:11:26 +01:00
parent 622df39fca
commit 98fb7a32db
2 changed files with 7 additions and 7 deletions

View file

@ -113,7 +113,7 @@ namespace SafeExamBrowser.Runtime.Operations
if (registry.TryRead(RegistryValue.MachineHive.EaseOfAccess_Key, RegistryValue.MachineHive.EaseOfAccess_Name, out var value)) 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; success = true;
logger.Info("Ease of access configuration successfully verified."); logger.Info("Ease of access configuration successfully verified.");
@ -135,7 +135,8 @@ namespace SafeExamBrowser.Runtime.Operations
} }
else 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; return success;

View file

@ -73,21 +73,20 @@ namespace SafeExamBrowser.SystemComponents.Registry
public bool TryRead(string key, string name, out object value) public bool TryRead(string key, string name, out object value)
{ {
var success = false; var defaultValue = new object();
value = default; value = default;
try try
{ {
value = Microsoft.Win32.Registry.GetValue(key, name, default); value = Microsoft.Win32.Registry.GetValue(key, name, defaultValue);
success = true;
} }
catch (Exception e) catch (Exception e)
{ {
logger.Error($"Failed to read value '{name}' from registry key '{key}'!", 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) public bool TryGetNames(string keyName, out IEnumerable<string> names)