#28 : Ensured nodrives mechanism in file system dialog doesn't crash if registry value doesn't exist.

This commit is contained in:
Damian Büchel 2020-12-11 09:58:31 +01:00
parent 9b8379bdae
commit 4bccf4610b
2 changed files with 4 additions and 4 deletions

View file

@ -292,9 +292,9 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows
private DriveInfo[] GetDrives()
{
var drives = DriveInfo.GetDrives();
var noDrives = (int) Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0);
var noDrives = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0) as int?;
if (noDrives > 0)
if (noDrives.HasValue && noDrives > 0)
{
return drives.Where(drive => (noDrives & (int) Math.Pow(2, drive.RootDirectory.ToString()[0] - 65)) == 0).ToArray();
}

View file

@ -292,9 +292,9 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows
private DriveInfo[] GetDrives()
{
var drives = DriveInfo.GetDrives();
var noDrives = (int) Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0);
var noDrives = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0) as int?;
if (noDrives > 0)
if (noDrives.HasValue && noDrives > 0)
{
return drives.Where(drive => (noDrives & (int) Math.Pow(2, drive.RootDirectory.ToString()[0] - 65)) == 0).ToArray();
}