Merge pull request #777 from Notselwyn/issue-747-fix

Issue 747 fix
This commit is contained in:
Damian Büchel 2024-01-15 09:51:54 +01:00 committed by GitHub
commit ef267ef186
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View file

@ -77,7 +77,7 @@ namespace SafeExamBrowser.Runtime.Operations
foreach (var cursor in cursors.Where(c => !string.IsNullOrWhiteSpace(c))) foreach (var cursor in cursors.Where(c => !string.IsNullOrWhiteSpace(c)))
{ {
success &= registry.TryRead(RegistryValue.UserHive.Cursors_Key, cursor, out var value); success &= registry.TryRead(RegistryValue.UserHive.Cursors_Key, cursor, out var value);
success &= value == default || !(value is string) || (value is string path && (string.IsNullOrWhiteSpace(path) || IsValidCursorPath(path))); success &= !(value is string) || (value is string path && (string.IsNullOrWhiteSpace(path) || IsValidCursorPath(path)));
if (!success) if (!success)
{ {
@ -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 && !ReferenceEquals(value, defaultValue);
} }
public bool TryGetNames(string keyName, out IEnumerable<string> names) public bool TryGetNames(string keyName, out IEnumerable<string> names)