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