From 2e31d8c9838ae177f23fdb5cec56a6da48d17828 Mon Sep 17 00:00:00 2001 From: Jan Philipp Weber <10946850+jp-weber@users.noreply.github.com> Date: Fri, 4 Sep 2020 12:04:17 +0200 Subject: [PATCH 1/4] Update FileSystemDialog.xaml.cs --- .../Windows/FileSystemDialog.xaml.cs | 58 ++++++++----------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs index 5ee9e37c..e279c554 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2020 ETH Zürich, Educational Development and Technology (LET) * * This Source Code Form is subject to the terms of the Mozilla Public @@ -20,6 +20,10 @@ using SafeExamBrowser.UserInterface.Contracts.FileSystemDialog; using SafeExamBrowser.UserInterface.Contracts.Windows; using SafeExamBrowser.UserInterface.Shared.Utilities; +// uni-goettingen-patch: start +using Microsoft.Win32; +// uni-goettingen-patch: end + namespace SafeExamBrowser.UserInterface.Desktop.Windows { internal partial class FileSystemDialog : Window @@ -29,7 +33,6 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows private string message; private FileSystemOperation operation; private IWindow parent; - private bool restrictNavigation; private IText text; private string title; @@ -40,15 +43,13 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows string initialPath = default(string), string message = default(string), string title = default(string), - IWindow parent = default(IWindow), - bool restrictNavigation = false) + IWindow parent = default(IWindow)) { this.element = element; this.initialPath = initialPath; this.message = message; this.operation = operation; this.parent = parent; - this.restrictNavigation = restrictNavigation; this.text = text; this.title = title; @@ -288,37 +289,26 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows InitializeFileSystem(); } + // uni-goettingen-patch: begin + 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) + { + return drives.Where(drive => (noDrives & (int)(Math.Pow(2, (int)(drive.RootDirectory.ToString()[0]) - 65))) == 0).ToArray(); + } + + return drives; + } + // uni-goettingen-patch: end + 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 DriveInfo.GetDrives()) + // uni-goettingen-patch: begin + foreach (var drive in GetDrives()) + // uni-goettingen-patch: end { FileSystem.Items.Add(CreateItem(drive.RootDirectory)); } From c970ce68730199156271b6da12e11962297b4df5 Mon Sep 17 00:00:00 2001 From: Jan Philipp Weber <10946850+jp-weber@users.noreply.github.com> Date: Fri, 4 Sep 2020 12:52:15 +0200 Subject: [PATCH 2/4] Update FileSystemDialog.xaml.cs --- .../Windows/FileSystemDialog.xaml.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs index e279c554..1a26ba86 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs @@ -19,10 +19,8 @@ using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.UserInterface.Contracts.FileSystemDialog; using SafeExamBrowser.UserInterface.Contracts.Windows; using SafeExamBrowser.UserInterface.Shared.Utilities; - -// uni-goettingen-patch: start using Microsoft.Win32; -// uni-goettingen-patch: end + namespace SafeExamBrowser.UserInterface.Desktop.Windows { @@ -288,8 +286,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows InitializeText(); InitializeFileSystem(); } - - // uni-goettingen-patch: begin + private DriveInfo[] GetDrives(bool showAll = false) { var drives = DriveInfo.GetDrives(); @@ -302,13 +299,10 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows return drives; } - // uni-goettingen-patch: end private void InitializeFileSystem() { - // uni-goettingen-patch: begin foreach (var drive in GetDrives()) - // uni-goettingen-patch: end { FileSystem.Items.Add(CreateItem(drive.RootDirectory)); } From 75e0737acd7bd0771010b4aa8afd3212c462a2f1 Mon Sep 17 00:00:00 2001 From: Jan Philipp Weber <10946850+jp-weber@users.noreply.github.com> Date: Sat, 5 Sep 2020 17:41:18 +0200 Subject: [PATCH 3/4] Fixed wrong replacements --- .../Windows/FileSystemDialog.xaml.cs | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) 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()) { From 8908efc93e9ea5b48cc0020ffa70e82f3ed2ad94 Mon Sep 17 00:00:00 2001 From: Jan Philipp Weber <10946850+jp-weber@users.noreply.github.com> Date: Fri, 18 Sep 2020 19:22:24 +0200 Subject: [PATCH 4/4] - mobile UI adapted --- .../Windows/FileSystemDialog.xaml.cs | 4 ++-- .../Windows/FileSystemDialog.xaml.cs | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs index ed34b488..a43095b5 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/FileSystemDialog.xaml.cs @@ -289,12 +289,12 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows InitializeFileSystem(); } - private DriveInfo[] GetDrives(bool showAll = false) + private DriveInfo[] GetDrives() { 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) { return drives.Where(drive => (noDrives & (int)(Math.Pow(2, (int)(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 f6796540..e039c06e 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Windows/FileSystemDialog.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Windows/FileSystemDialog.xaml.cs @@ -15,6 +15,7 @@ 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; @@ -288,6 +289,20 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows InitializeFileSystem(); } + private DriveInfo[] GetDrives() + { + var drives = DriveInfo.GetDrives(); + int noDrives = (int)Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDrives", 0); + + if (noDrives > 0) + { + return drives.Where(drive => (noDrives & (int)(Math.Pow(2, (int)(drive.RootDirectory.ToString()[0]) - 65))) == 0).ToArray(); + } + + return drives; + } + + private void InitializeFileSystem() { if (restrictNavigation && !string.IsNullOrEmpty(initialPath)) @@ -318,7 +333,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows private void InitializeUnrestricted() { - foreach (var drive in DriveInfo.GetDrives()) + foreach (var drive in GetDrives()) { FileSystem.Items.Add(CreateItem(drive.RootDirectory)); }