From: sr55 Date: Thu, 9 Jun 2016 19:35:11 +0000 (+0100) Subject: WinGui: Check directory permissions before adding a job to the queue for processing... X-Git-Tag: 1.0.0~384 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cea9d238dbc4c09788604a15672145bde5fad29e;p=handbrake WinGui: Check directory permissions before adding a job to the queue for processing. Fixes #219 --- diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 2f8cd2bef..297a5caf1 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -728,6 +728,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to You do not have the appropriate folder permissions to write files into the directory you have chosen.. + /// + public static string Main_NoPermissionsOnDirectory { + get { + return ResourceManager.GetString("Main_NoPermissionsOnDirectory", resourceCulture); + } + } + /// /// Looks up a localized string similar to No Preset selected.. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index dcb268430..17767838a 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -808,4 +808,7 @@ Your preset file will be archived and new one created. You will need to re-creat Your user settings file appears to be inaccessible or corrupted. You may have to delete the file and let HandBrake generate a new one. + + You do not have the appropriate folder permissions to write files into the directory you have chosen. + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs b/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs index 23b10ede8..5461605d0 100644 --- a/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs +++ b/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs @@ -37,5 +37,24 @@ namespace HandBrakeWPF.Utilities return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "HandBrake"); } } + + + /// + /// Simple way of checking if a directory is writeable. + /// + /// Path to check + /// True if writable + public static bool IsWritable(string dirPath) + { + try + { + using (File.Create(Path.Combine(dirPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose)) { } + return true; + } + catch + { + return false; + } + } } } diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 39f199892..fff4d8a70 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -1378,6 +1378,13 @@ namespace HandBrakeWPF.ViewModels return false; } + if (!DirectoryUtilities.IsWritable(Path.GetDirectoryName(this.CurrentTask.Destination))) + { + this.errorService.ShowMessageBox(Resources.Main_NoPermissionsOnDirectory, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + + // Sanity check the filename if (!string.IsNullOrEmpty(this.Destination) && FileHelper.FilePathHasInvalidChars(this.Destination)) {