}\r
}\r
\r
+ /// <summary>\r
+ /// Looks up a localized string similar to Create Folder?.\r
+ /// </summary>\r
+ public static string DirectoryUtils_CreateFolder {\r
+ get {\r
+ return ResourceManager.GetString("DirectoryUtils_CreateFolder", resourceCulture);\r
+ }\r
+ }\r
+ \r
+ /// <summary>\r
+ /// Looks up a localized string similar to The folder you are trying to write to does not exist. Would you like HandBrake to create the following folder?\r
+ ///{0}.\r
+ /// </summary>\r
+ public static string DirectoryUtils_CreateFolderMsg {\r
+ get {\r
+ return ResourceManager.GetString("DirectoryUtils_CreateFolderMsg", resourceCulture);\r
+ }\r
+ }\r
+ \r
/// <summary>\r
/// Looks up a localized string similar to Error.\r
/// </summary>\r
}\r
\r
/// <summary>\r
- /// Looks up a localized string similar to The entered destination contained illegal characters. You must fix the path and filename before continuing..\r
+ /// Looks up a localized string similar to The entered destination path contained illegal characters and will not be updated..\r
/// </summary>\r
public static string Main_InvalidDestination {\r
get {\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
+ /// Looks up a localized string similar to The output directory you have chosen either does not exist, or you do not have permissions to write files to it..\r
/// </summary>\r
- public static string Main_NoPermissionsOnDirectory {\r
+ public static string Main_NoPermissionsOrMissingDirectory {\r
get {\r
- return ResourceManager.GetString("Main_NoPermissionsOnDirectory", resourceCulture);\r
+ return ResourceManager.GetString("Main_NoPermissionsOrMissingDirectory", resourceCulture);\r
}\r
}\r
\r
}\r
}\r
\r
+ /// <summary>\r
+ /// Looks up a localized string similar to Unable to launch destination directory..\r
+ /// </summary>\r
+ public static string MainViewModel_UnableToLaunchDestDir {\r
+ get {\r
+ return ResourceManager.GetString("MainViewModel_UnableToLaunchDestDir", resourceCulture);\r
+ }\r
+ }\r
+ \r
+ /// <summary>\r
+ /// Looks up a localized string similar to Please check that you have a valid destination directory..\r
+ /// </summary>\r
+ public static string MainViewModel_UnableToLaunchDestDirSolution {\r
+ get {\r
+ return ResourceManager.GetString("MainViewModel_UnableToLaunchDestDirSolution", resourceCulture);\r
+ }\r
+ }\r
+ \r
/// <summary>\r
/// Looks up a localized string similar to Notice.\r
/// </summary>\r
<value>You must first set the destination path for the output file before adding to the queue.</value>\r
</data>\r
<data name="Main_InvalidDestination" xml:space="preserve">\r
- <value>The entered destination contained illegal characters. You must fix the path and filename before continuing.</value>\r
+ <value>The entered destination path contained illegal characters and will not be updated.</value>\r
</data>\r
<data name="Preview" xml:space="preserve">\r
<value>Preview</value>\r
<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 name="Main_NoPermissionsOrMissingDirectory" xml:space="preserve">\r
+ <value>The output directory you have chosen either does not exist, or you do not have permissions to write files to it.</value>\r
+ </data>\r
+ <data name="DirectoryUtils_CreateFolder" xml:space="preserve">\r
+ <value>Create Folder?</value>\r
+ </data>\r
+ <data name="DirectoryUtils_CreateFolderMsg" xml:space="preserve">\r
+ <value>The folder you are trying to write to does not exist. Would you like HandBrake to create the following folder?\r
+{0}</value>\r
+ </data>\r
+ <data name="MainViewModel_UnableToLaunchDestDir" xml:space="preserve">\r
+ <value>Unable to launch destination directory.</value>\r
+ </data>\r
+ <data name="MainViewModel_UnableToLaunchDestDirSolution" xml:space="preserve">\r
+ <value>Please check that you have a valid destination directory.</value>\r
</data>\r
</root>
\ No newline at end of file
{
using System;
using System.IO;
+ using System.Windows;
+
+ using HandBrakeWPF.Properties;
+ using HandBrakeWPF.Services.Interfaces;
/// <summary>
/// The directory utilities.
/// Simple way of checking if a directory is writeable.
/// </summary>
/// <param name="dirPath">Path to check</param>
+ /// <param name="createDirectoryPrompt">
+ /// Prompt to create directory if it doesn't exist.
+ /// </param>
+ /// <param name="errorService">
+ /// An instance of the error service to allow prompting.
+ /// </param>
/// <returns>True if writable</returns>
- public static bool IsWritable(string dirPath)
+ public static bool IsWritable(string dirPath, bool createDirectoryPrompt, IErrorService errorService)
{
try
{
+ if (!Directory.Exists(dirPath))
+ {
+ MessageBoxResult result = errorService.ShowMessageBox(string.Format(Resources.DirectoryUtils_CreateFolderMsg, dirPath), Resources.DirectoryUtils_CreateFolder, MessageBoxButton.YesNo, MessageBoxImage.Question);
+ if (MessageBoxResult.Yes == result)
+ {
+ Directory.CreateDirectory(dirPath);
+ }
+ }
using (File.Create(Path.Combine(dirPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose))
{
}
{\r
if (!Equals(this.CurrentTask.Destination, value))\r
{\r
- this.CurrentTask.Destination = value;\r
- this.NotifyOfPropertyChange(() => this.Destination);\r
-\r
- if (!string.IsNullOrEmpty(this.CurrentTask.Destination))\r
+ if (!string.IsNullOrEmpty(value))\r
{\r
string ext = string.Empty;\r
try\r
{\r
- ext = Path.GetExtension(this.CurrentTask.Destination);\r
+ ext = Path.GetExtension(value);\r
}\r
catch (ArgumentException)\r
{\r
- this.errorService.ShowMessageBox(Resources.Main_InvalidDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
+ this.errorService.ShowMessageBox(\r
+ Resources.Main_InvalidDestination,\r
+ Resources.Error,\r
+ MessageBoxButton.OK,\r
+ MessageBoxImage.Error);\r
}\r
\r
+ this.CurrentTask.Destination = value;\r
+ this.NotifyOfPropertyChange(() => this.Destination);\r
+\r
switch (ext)\r
{\r
case ".mkv":\r
break;\r
}\r
}\r
+ else\r
+ {\r
+ this.CurrentTask.Destination = string.Empty;\r
+ this.NotifyOfPropertyChange(() => this.Destination);\r
+ }\r
}\r
}\r
}\r
return false;\r
}\r
\r
- if (!DirectoryUtilities.IsWritable(Path.GetDirectoryName(this.CurrentTask.Destination)))\r
+ if (!DirectoryUtilities.IsWritable(Path.GetDirectoryName(this.CurrentTask.Destination), true, this.errorService))\r
{\r
- this.errorService.ShowMessageBox(Resources.Main_NoPermissionsOnDirectory, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
+ this.errorService.ShowMessageBox(Resources.Main_NoPermissionsOrMissingDirectory, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
return false;\r
}\r
\r
{\r
if (!string.IsNullOrEmpty(this.Destination))\r
{\r
- string directory = Path.GetDirectoryName(this.Destination);\r
- if (!string.IsNullOrEmpty(directory))\r
+ try\r
{\r
- Process.Start(directory);\r
+ string directory = Path.GetDirectoryName(this.Destination);\r
+ if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))\r
+ {\r
+ Process.Start(directory);\r
+ }\r
+ else\r
+ {\r
+ MessageBoxResult result =\r
+ errorService.ShowMessageBox(\r
+ string.Format(Resources.DirectoryUtils_CreateFolderMsg, directory),\r
+ Resources.DirectoryUtils_CreateFolder,\r
+ MessageBoxButton.YesNo,\r
+ MessageBoxImage.Question);\r
+ if (MessageBoxResult.Yes == result)\r
+ {\r
+ Directory.CreateDirectory(directory);\r
+ Process.Start(directory);\r
+ }\r
+ }\r
}\r
- else\r
+ catch (Exception exc)\r
{\r
- Process.Start(AppDomain.CurrentDomain.BaseDirectory);\r
+ this.errorService.ShowError(Resources.MainViewModel_UnableToLaunchDestDir, Resources.MainViewModel_UnableToLaunchDestDirSolution, exc);\r
}\r
}\r
}\r