]> granicus.if.org Git - handbrake/commitdiff
WinGui: Check directory permissions before adding a job to the queue for processing...
authorsr55 <sr55.hb@outlook.com>
Thu, 9 Jun 2016 19:35:11 +0000 (20:35 +0100)
committersr55 <sr55.hb@outlook.com>
Thu, 9 Jun 2016 19:35:28 +0000 (20:35 +0100)
win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
win/CS/HandBrakeWPF/Properties/Resources.resx
win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs

index 2f8cd2bef91cfe9201973f645028edaecb2808b1..297a5caf1cfce774b46e4b1bdda5b926e635296a 100644 (file)
@@ -728,6 +728,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to You do not have the appropriate folder permissions to write files into the directory you have chosen..\r
+        /// </summary>\r
+        public static string Main_NoPermissionsOnDirectory {\r
+            get {\r
+                return ResourceManager.GetString("Main_NoPermissionsOnDirectory", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to No Preset selected..\r
         /// </summary>\r
index dcb2684307938719d408ef3b8a7a8c11eb7f51ed..17767838a44bfc5430f03e7f28847e628c04c737 100644 (file)
@@ -808,4 +808,7 @@ Your preset file will be archived and new one created. You will need to re-creat
   <data name="UserSettings_UnableToLoadSolution" xml:space="preserve">\r
     <value>Your user settings file appears to be inaccessible or corrupted. You may have to delete the file and let HandBrake generate a new one.</value>\r
   </data>\r
+  <data name="Main_NoPermissionsOnDirectory" xml:space="preserve">\r
+    <value>You do not have the appropriate folder permissions to write files into the directory you have chosen.</value>\r
+  </data>\r
 </root>
\ No newline at end of file
index 23b10ede846c63d9ec551dbcd5a6faccea2c3493..5461605d0afc4b65c88268d34356bec43e778d12 100644 (file)
@@ -37,5 +37,24 @@ namespace HandBrakeWPF.Utilities
                 return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "HandBrake");
             }
         }
+
+
+        /// <summary>
+        /// Simple way of checking if a directory is writeable.
+        /// </summary>
+        /// <param name="dirPath">Path to check</param>
+        /// <returns>True if writable</returns>
+        public static bool IsWritable(string dirPath)
+        {
+            try
+            {
+                using (File.Create(Path.Combine(dirPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose)) { }
+                return true;
+            }
+            catch
+            {
+                return false;
+            }
+        }
     }
 }
index 39f199892637a2e319d83edbf213563da5703a85..fff4d8a709393e5683d29f2ec455e89f820d632a 100644 (file)
@@ -1378,6 +1378,13 @@ namespace HandBrakeWPF.ViewModels
                 return false;\r
             }\r
 \r
+            if (!DirectoryUtilities.IsWritable(Path.GetDirectoryName(this.CurrentTask.Destination)))\r
+            {\r
+                this.errorService.ShowMessageBox(Resources.Main_NoPermissionsOnDirectory, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
+                return false;\r
+            }\r
+\r
+\r
             // Sanity check the filename\r
             if (!string.IsNullOrEmpty(this.Destination) && FileHelper.FilePathHasInvalidChars(this.Destination))\r
             {\r