chore: added function blocks and fixed if statement
This commit is contained in:
parent
210a0419ca
commit
c1307624d9
2 changed files with 22 additions and 9 deletions
|
@ -94,7 +94,9 @@ namespace SafeExamBrowser.SystemComponents.Registry
|
|||
names = default;
|
||||
|
||||
if (!TryOpenKey(keyName, out var key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var success = true;
|
||||
using (key)
|
||||
|
@ -117,9 +119,11 @@ namespace SafeExamBrowser.SystemComponents.Registry
|
|||
public bool TryGetSubKeys(string keyName, out IEnumerable<string> subKeys)
|
||||
{
|
||||
subKeys = default;
|
||||
|
||||
|
||||
if (!TryOpenKey(keyName, out var key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var success = true;
|
||||
using (key)
|
||||
|
@ -234,15 +238,12 @@ namespace SafeExamBrowser.SystemComponents.Registry
|
|||
|
||||
try
|
||||
{
|
||||
if (!TryGetBaseKeyFromKeyName(keyName, out var baseKey, out var subKey))
|
||||
return false;
|
||||
|
||||
key = baseKey.OpenSubKey(subKey);
|
||||
if (key == null)
|
||||
logger.Info($"default(RegistryKey) == null: {key == null}");
|
||||
if (TryGetBaseKeyFromKeyName(keyName, out var baseKey, out var subKey))
|
||||
{
|
||||
key = default;
|
||||
return false;
|
||||
key = baseKey.OpenSubKey(subKey);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -250,7 +251,7 @@ namespace SafeExamBrowser.SystemComponents.Registry
|
|||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return key != default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,9 @@ namespace SafeExamBrowser.SystemComponents
|
|||
*/
|
||||
const string hwConfigParentKey = "HKEY_LOCAL_MACHINE\\SYSTEM\\HardwareConfig";
|
||||
if (!registry.TryGetSubKeys(hwConfigParentKey, out var hardwareConfigSubkeys))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (string configId in hardwareConfigSubkeys)
|
||||
{
|
||||
|
@ -143,7 +145,9 @@ namespace SafeExamBrowser.SystemComponents
|
|||
didReadKeys &= registry.TryRead(hwConfigKey, "SystemManufacturer", out var systemManufacturer);
|
||||
didReadKeys &= registry.TryRead(hwConfigKey, "SystemProductName", out var systemProductName);
|
||||
if (!didReadKeys)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// reconstruct the systemInfo.biosInfo string
|
||||
var biosInfo = $"{(string) biosVendor} {(string) biosVersion}";
|
||||
|
@ -153,13 +157,17 @@ namespace SafeExamBrowser.SystemComponents
|
|||
// check even more hardware information
|
||||
var computerIdsKey = $"{hwConfigKey}\\ComputerIds";
|
||||
if (!registry.TryGetNames(computerIdsKey, out var computerIdNames))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var computerIdName in computerIdNames)
|
||||
{
|
||||
// collect computer hardware summary (e.g. manufacturer&version&sku&...)
|
||||
if (!registry.TryRead(computerIdsKey, computerIdName, out var computerSummary))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
isVirtualMachine |= IsVirtualSystemInfo((string) computerSummary, (string) systemManufacturer, (string) systemProductName);
|
||||
}
|
||||
|
@ -192,12 +200,16 @@ namespace SafeExamBrowser.SystemComponents
|
|||
|
||||
didReadKeys &= registry.TryRead(cacheIdKey, "DeviceName", out var cacheDeviceName);
|
||||
if (!didReadKeys || deviceName.ToLower() != ((string) cacheDeviceName).ToLower())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
didReadKeys &= registry.TryRead(cacheIdKey, "DeviceMake", out var cacheDeviceManufacturer);
|
||||
didReadKeys &= registry.TryRead(cacheIdKey, "DeviceModel", out var cacheDeviceModel);
|
||||
if (!didReadKeys)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
isVirtualMachine |= IsVirtualSystemInfo("", (string) cacheDeviceManufacturer, (string) cacheDeviceModel);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue