diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 760d4c7..2cc6d28 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -18,7 +18,8 @@ namespace FileConverter private string name; private OutputType outputType; private List inputTypes; - private ConversionSettings settings = new ConversionSettings(); + private ConversionSettings settings = new ConversionSettings(); + private string outputFileNameTemplate; public ConversionPreset() { @@ -111,6 +112,21 @@ namespace FileConverter } } + [XmlElement] + public string OutputFileNameTemplate + { + get + { + return this.outputFileNameTemplate; + } + + set + { + this.outputFileNameTemplate = value; + this.OnPropertyChanged(); + } + } + [XmlIgnore] public IConversionSettings Settings { diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 9ef83fb..ba72c0f 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -82,9 +82,15 @@ + + Resources.en.resx + True + True + + @@ -151,8 +157,12 @@ Settings.settings True + + PublicResXFileCodeGenerator + Resources.en.Designer.cs + - ResXFileCodeGenerator + PublicResXFileCodeGenerator Resources.Designer.cs diff --git a/Application/FileConverter/Properties/Resources.Designer.cs b/Application/FileConverter/Properties/Resources.Designer.cs index d240821..a47c80d 100644 --- a/Application/FileConverter/Properties/Resources.Designer.cs +++ b/Application/FileConverter/Properties/Resources.Designer.cs @@ -1,17 +1,17 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18444 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ -namespace FileConverter.Properties -{ - - +namespace FileConverter.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -22,50 +22,51 @@ namespace FileConverter.Properties [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + public class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FileConverter.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + public static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } + + /// + /// Looks up a localized string similar to C:\Data\MyFolder\Default.wav. + /// + public static string OuputFileNameTemplateSample { + get { + return ResourceManager.GetString("OuputFileNameTemplateSample", resourceCulture); + } + } } } diff --git a/Application/FileConverter/Properties/Resources.en.Designer.cs b/Application/FileConverter/Properties/Resources.en.Designer.cs new file mode 100644 index 0000000..e69de29 diff --git a/Application/FileConverter/Properties/Resources.en.resx b/Application/FileConverter/Properties/Resources.en.resx new file mode 100644 index 0000000..98819aa --- /dev/null +++ b/Application/FileConverter/Properties/Resources.en.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + C:\Data\MyFolder\SomeMusic.wav + + \ No newline at end of file diff --git a/Application/FileConverter/Properties/Resources.resx b/Application/FileConverter/Properties/Resources.resx index af7dbeb..3cc1e96 100644 --- a/Application/FileConverter/Properties/Resources.resx +++ b/Application/FileConverter/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,12 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + C:\Data\MyFolder\Default.wav + \ No newline at end of file diff --git a/Application/FileConverter/ValueConverters/FileNameConverter.cs b/Application/FileConverter/ValueConverters/FileNameConverter.cs new file mode 100644 index 0000000..41e560a --- /dev/null +++ b/Application/FileConverter/ValueConverters/FileNameConverter.cs @@ -0,0 +1,80 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.ValueConverters +{ + using System; + using System.Globalization; + using System.Windows.Data; + + public class FileNameConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values == null || values.Length != 3) + { + throw new ArgumentException("The values must contains the input file path, the output file extension and the ouput file template."); + } + + if (!(values[1] is OutputType)) + { + return "Invalid output file extension (argument 1)."; + } + + string inputFilePath = values[0] as string; + OutputType outputFileExtension = (OutputType)values[1]; + string outputFileTemplate = values[2] as string; + + if (inputFilePath == null) + { + return "Invalid input file path (argument 0)."; + } + + string inputExtension = System.IO.Path.GetExtension(inputFilePath).Substring(1); + string inputPathWithoutExtension = inputFilePath.Substring(0, inputFilePath.Length - inputExtension.Length - 1); + string outputExtension = outputFileExtension.ToString().ToLowerInvariant(); + + if (outputFileTemplate == null) + { + // Default output path. + return inputPathWithoutExtension + "." + outputExtension; + } + + string fileName = System.IO.Path.GetFileName(inputPathWithoutExtension); + string parentDirectory = System.IO.Path.GetDirectoryName(inputPathWithoutExtension); + string[] directories = parentDirectory.Split(System.IO.Path.DirectorySeparatorChar); + parentDirectory += System.IO.Path.DirectorySeparatorChar; + + // Generate output path from template. + string outputPath = outputFileTemplate; + + outputPath = outputPath.Replace("(path)", parentDirectory); + outputPath = outputPath.Replace("(p)", parentDirectory); + + outputPath = outputPath.Replace("(filename)", fileName); + outputPath = outputPath.Replace("(f)", fileName); + outputPath = outputPath.Replace("(F)", fileName.ToUpperInvariant()); + + outputPath = outputPath.Replace("(outputext)", outputExtension); + outputPath = outputPath.Replace("(o)", outputExtension); + outputPath = outputPath.Replace("(O)", outputExtension.ToUpperInvariant()); + + outputPath = outputPath.Replace("(inputext)", inputExtension); + outputPath = outputPath.Replace("(i)", inputExtension); + outputPath = outputPath.Replace("(I)", inputExtension.ToUpperInvariant()); + + for (int index = 0; index < directories.Length; index++) + { + outputPath = outputPath.Replace(string.Format("(d{0})", directories.Length - index - 1), directories[index]); + } + + outputPath += "." + outputExtension; + + return outputPath; + } + + public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml index 481366b..516861b 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml +++ b/Application/FileConverter/Windows/SettingsWindow.xaml @@ -5,10 +5,12 @@ xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters" xmlns:generic="clr-namespace:FileConverter.ValueConverters.Generic" xmlns:windows="clr-namespace:FileConverter.Windows" + xmlns:project="clr-namespace:FileConverter.Properties" Height="500" Width="700" MinHeight="370" MinWidth="440" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon-16x16.ico" Closing="SettingsWindow_OnClosing"> + @@ -34,7 +36,7 @@ - + - - + - + @@ -74,14 +75,14 @@ @@ -91,7 +92,7 @@ @@ -187,9 +188,39 @@ - + + + + + + + + + + + + + + + + diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml.cs b/Application/FileConverter/Windows/SettingsWindow.xaml.cs index 346c68c..4d57802 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml.cs +++ b/Application/FileConverter/Windows/SettingsWindow.xaml.cs @@ -56,7 +56,7 @@ namespace FileConverter this.OnPropertyChanged(); } } - + [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) {