summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF
diff options
context:
space:
mode:
authorsr55 <[email protected]>2016-11-16 19:55:22 +0000
committersr55 <[email protected]>2016-11-16 19:55:31 +0000
commitb9c5daa5663a78f8d68af69f58cf476d0ccaa8b6 (patch)
tree5a5dc8aa2d57f0da3272f772b06fe05aa117c57c /win/CS/HandBrakeWPF
parentef33de1a07c79ad0f6d676b5153de1548dc01709 (diff)
WinGui: Prompt to create folder when the destination path does not exist. Fixes #394
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.Designer.cs45
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.resx19
-rw-r--r--win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs20
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs52
4 files changed, 115 insertions, 21 deletions
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
index e8e956363..b692aa83f 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
+++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
@@ -594,6 +594,25 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to Create Folder?.
+ /// </summary>
+ public static string DirectoryUtils_CreateFolder {
+ get {
+ return ResourceManager.GetString("DirectoryUtils_CreateFolder", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// 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?
+ ///{0}.
+ /// </summary>
+ public static string DirectoryUtils_CreateFolderMsg {
+ get {
+ return ResourceManager.GetString("DirectoryUtils_CreateFolderMsg", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Error.
/// </summary>
public static string Error {
@@ -684,7 +703,7 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
- /// Looks up a localized string similar to The entered destination contained illegal characters. You must fix the path and filename before continuing..
+ /// Looks up a localized string similar to The entered destination path contained illegal characters and will not be updated..
/// </summary>
public static string Main_InvalidDestination {
get {
@@ -729,11 +748,11 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
- /// Looks up a localized string similar to You do not have the appropriate folder permissions to write files into the directory you have chosen..
+ /// 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..
/// </summary>
- public static string Main_NoPermissionsOnDirectory {
+ public static string Main_NoPermissionsOrMissingDirectory {
get {
- return ResourceManager.GetString("Main_NoPermissionsOnDirectory", resourceCulture);
+ return ResourceManager.GetString("Main_NoPermissionsOrMissingDirectory", resourceCulture);
}
}
@@ -1107,6 +1126,24 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to Unable to launch destination directory..
+ /// </summary>
+ public static string MainViewModel_UnableToLaunchDestDir {
+ get {
+ return ResourceManager.GetString("MainViewModel_UnableToLaunchDestDir", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Please check that you have a valid destination directory..
+ /// </summary>
+ public static string MainViewModel_UnableToLaunchDestDirSolution {
+ get {
+ return ResourceManager.GetString("MainViewModel_UnableToLaunchDestDirSolution", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Notice.
/// </summary>
public static string Notice {
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx
index be0adb41f..6791f06e6 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.resx
+++ b/win/CS/HandBrakeWPF/Properties/Resources.resx
@@ -465,7 +465,7 @@ Do you wish to proceed?</value>
<value>You must first set the destination path for the output file before adding to the queue.</value>
</data>
<data name="Main_InvalidDestination" xml:space="preserve">
- <value>The entered destination contained illegal characters. You must fix the path and filename before continuing.</value>
+ <value>The entered destination path contained illegal characters and will not be updated.</value>
</data>
<data name="Preview" xml:space="preserve">
<value>Preview</value>
@@ -809,7 +809,20 @@ Your preset file will be archived and new one created. You will need to re-creat
<data name="UserSettings_UnableToLoadSolution" xml:space="preserve">
<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>
</data>
- <data name="Main_NoPermissionsOnDirectory" xml:space="preserve">
- <value>You do not have the appropriate folder permissions to write files into the directory you have chosen.</value>
+ <data name="Main_NoPermissionsOrMissingDirectory" xml:space="preserve">
+ <value>The output directory you have chosen either does not exist, or you do not have permissions to write files to it.</value>
+ </data>
+ <data name="DirectoryUtils_CreateFolder" xml:space="preserve">
+ <value>Create Folder?</value>
+ </data>
+ <data name="DirectoryUtils_CreateFolderMsg" xml:space="preserve">
+ <value>The folder you are trying to write to does not exist. Would you like HandBrake to create the following folder?
+{0}</value>
+ </data>
+ <data name="MainViewModel_UnableToLaunchDestDir" xml:space="preserve">
+ <value>Unable to launch destination directory.</value>
+ </data>
+ <data name="MainViewModel_UnableToLaunchDestDirSolution" xml:space="preserve">
+ <value>Please check that you have a valid destination directory.</value>
</data>
</root> \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs b/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs
index 45450f4eb..0f63ebfce 100644
--- a/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs
+++ b/win/CS/HandBrakeWPF/Utilities/DirectoryUtilities.cs
@@ -11,6 +11,10 @@ namespace HandBrakeWPF.Utilities
{
using System;
using System.IO;
+ using System.Windows;
+
+ using HandBrakeWPF.Properties;
+ using HandBrakeWPF.Services.Interfaces;
/// <summary>
/// The directory utilities.
@@ -42,11 +46,25 @@ namespace HandBrakeWPF.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))
{
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index b1e231412..957ce4d29 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -698,21 +698,25 @@ namespace HandBrakeWPF.ViewModels
{
if (!Equals(this.CurrentTask.Destination, value))
{
- this.CurrentTask.Destination = value;
- this.NotifyOfPropertyChange(() => this.Destination);
-
- if (!string.IsNullOrEmpty(this.CurrentTask.Destination))
+ if (!string.IsNullOrEmpty(value))
{
string ext = string.Empty;
try
{
- ext = Path.GetExtension(this.CurrentTask.Destination);
+ ext = Path.GetExtension(value);
}
catch (ArgumentException)
{
- this.errorService.ShowMessageBox(Resources.Main_InvalidDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
+ this.errorService.ShowMessageBox(
+ Resources.Main_InvalidDestination,
+ Resources.Error,
+ MessageBoxButton.OK,
+ MessageBoxImage.Error);
}
+ this.CurrentTask.Destination = value;
+ this.NotifyOfPropertyChange(() => this.Destination);
+
switch (ext)
{
case ".mkv":
@@ -726,6 +730,11 @@ namespace HandBrakeWPF.ViewModels
break;
}
}
+ else
+ {
+ this.CurrentTask.Destination = string.Empty;
+ this.NotifyOfPropertyChange(() => this.Destination);
+ }
}
}
}
@@ -1397,9 +1406,9 @@ namespace HandBrakeWPF.ViewModels
return false;
}
- if (!DirectoryUtilities.IsWritable(Path.GetDirectoryName(this.CurrentTask.Destination)))
+ if (!DirectoryUtilities.IsWritable(Path.GetDirectoryName(this.CurrentTask.Destination), true, this.errorService))
{
- this.errorService.ShowMessageBox(Resources.Main_NoPermissionsOnDirectory, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
+ this.errorService.ShowMessageBox(Resources.Main_NoPermissionsOrMissingDirectory, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
@@ -1794,14 +1803,31 @@ namespace HandBrakeWPF.ViewModels
{
if (!string.IsNullOrEmpty(this.Destination))
{
- string directory = Path.GetDirectoryName(this.Destination);
- if (!string.IsNullOrEmpty(directory))
+ try
{
- Process.Start(directory);
+ string directory = Path.GetDirectoryName(this.Destination);
+ if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
+ {
+ Process.Start(directory);
+ }
+ else
+ {
+ MessageBoxResult result =
+ errorService.ShowMessageBox(
+ string.Format(Resources.DirectoryUtils_CreateFolderMsg, directory),
+ Resources.DirectoryUtils_CreateFolder,
+ MessageBoxButton.YesNo,
+ MessageBoxImage.Question);
+ if (MessageBoxResult.Yes == result)
+ {
+ Directory.CreateDirectory(directory);
+ Process.Start(directory);
+ }
+ }
}
- else
+ catch (Exception exc)
{
- Process.Start(AppDomain.CurrentDomain.BaseDirectory);
+ this.errorService.ShowError(Resources.MainViewModel_UnableToLaunchDestDir, Resources.MainViewModel_UnableToLaunchDestDirSolution, exc);
}
}
}