From 4bccf4610b79af9ec9ba2f9e6838c40bc039fc2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Fri, 11 Dec 2020 09:58:31 +0100 Subject: [PATCH] #28 : Ensured nodrives mechanism in file system dialog doesn't crash if registry value doesn't exist. --- .../Windows/FileSystemDialog.xaml.cs | 4 ++-- .../Windows/FileSystemDialog.xaml.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs index f32b9eba..8be01cd0 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs @@ -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(); } diff --git a/SafeExamBrowser.UserInterface.Mobile/Windows/FileSystemDialog.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Windows/FileSystemDialog.xaml.cs index 937406c3..e458edc5 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Windows/FileSystemDialog.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Windows/FileSystemDialog.xaml.cs @@ -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(); }