diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs index 1a26ba86..ed34b488 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs @@ -15,12 +15,11 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using FontAwesome.WPF; +using Microsoft.Win32; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.UserInterface.Contracts.FileSystemDialog; using SafeExamBrowser.UserInterface.Contracts.Windows; using SafeExamBrowser.UserInterface.Shared.Utilities; -using Microsoft.Win32; - namespace SafeExamBrowser.UserInterface.Desktop.Windows { @@ -31,6 +30,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows private string message; private FileSystemOperation operation; private IWindow parent; + private bool restrictNavigation; private IText text; private string title; @@ -41,13 +41,15 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows string initialPath = default(string), string message = default(string), string title = default(string), - IWindow parent = default(IWindow)) + IWindow parent = default(IWindow), + bool restrictNavigation = false) { this.element = element; this.initialPath = initialPath; this.message = message; this.operation = operation; this.parent = parent; + this.restrictNavigation = restrictNavigation; this.text = text; this.title = title; @@ -286,13 +288,13 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows InitializeText(); InitializeFileSystem(); } - + private DriveInfo[] GetDrives(bool showAll = false) { var drives = DriveInfo.GetDrives(); int noDrives = (int)Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0); - if (noDrives > 0 || showAll) + if (noDrives > 0 && !showAll) { return drives.Where(drive => (noDrives & (int)(Math.Pow(2, (int)(drive.RootDirectory.ToString()[0]) - 65))) == 0).ToArray(); } @@ -300,7 +302,36 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows return drives; } + private void InitializeFileSystem() + { + if (restrictNavigation && !string.IsNullOrEmpty(initialPath)) + { + InitializeRestricted(); + } + else + { + InitializeUnrestricted(); + } + } + + private void InitializeRestricted() + { + var root = Directory.Exists(initialPath) ? initialPath : Path.GetDirectoryName(initialPath); + + if (Directory.Exists(root)) + { + var directory = CreateItem(new DirectoryInfo(root)); + + FileSystem.Items.Add(directory); + + directory.IsExpanded = true; + directory.IsSelected = true; + directory.BringIntoView(); + } + } + + private void InitializeUnrestricted() { foreach (var drive in GetDrives()) {