diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs
index 7cc866b..6f576c7 100644
--- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs
+++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs
@@ -1,7 +1,5 @@
// License: http://www.gnu.org/licenses/gpl.html GPL version 3.
-using FileConverter.ValueConverters;
-
namespace FileConverter
{
using System;
@@ -12,10 +10,11 @@ namespace FileConverter
using System.Xml.Serialization;
using FileConverter.Annotations;
+ using FileConverter.ValueConverters;
[XmlRoot]
[XmlType]
- public class ConversionPreset : INotifyPropertyChanged, IDataErrorInfo
+ public class ConversionPreset : INotifyPropertyChanged, IDataErrorInfo, IXmlSerializable
{
private string name;
private OutputType outputType;
@@ -34,8 +33,10 @@ namespace FileConverter
{
this.Name = name;
this.OutputType = outputType;
- this.InputTypes = new List();
- this.InputTypes.AddRange(inputTypes);
+ List inputTypeList = new List();
+ inputTypeList.AddRange(inputTypes);
+ this.InputTypes = inputTypeList;
+
this.outputFileNameTemplate = "(p)(f)";
}
@@ -83,6 +84,11 @@ namespace FileConverter
set
{
this.inputTypes = value;
+ for (int index = 0; index < this.inputTypes.Count; index++)
+ {
+ this.inputTypes[index] = this.inputTypes[index].ToLowerInvariant();
+ }
+
this.OnPropertyChanged();
}
}
@@ -215,6 +221,14 @@ namespace FileConverter
}
}
+ public void OnDeserializationComplete()
+ {
+ for (int index = 0; index < this.InputTypes.Count; index++)
+ {
+ this.InputTypes[index] = this.InputTypes[index].ToLowerInvariant();
+ }
+ }
+
public string GenerateOutputFilePath(string inputFilePath)
{
return (string)this.outputFileNameConverter.Convert(new object[] {inputFilePath, this.OutputType, this.OutputFileNameTemplate}, typeof (string), null, null);
diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj
index 1accfe1..9c788ee 100644
--- a/Application/FileConverter/FileConverter.csproj
+++ b/Application/FileConverter/FileConverter.csproj
@@ -83,6 +83,7 @@
+
Resources.en.resx
@@ -97,6 +98,7 @@
+
@@ -107,6 +109,8 @@
DiagnosticsWindow.xaml
+
+
SettingsWindow.xaml
diff --git a/Application/FileConverter/PathHelpers.cs b/Application/FileConverter/PathHelpers.cs
index e09c6aa..6078203 100644
--- a/Application/FileConverter/PathHelpers.cs
+++ b/Application/FileConverter/PathHelpers.cs
@@ -58,5 +58,26 @@ namespace FileConverter
return path;
}
+
+ public static string GetExtensionCategory(string extension)
+ {
+ switch (extension)
+ {
+ case "ape":
+ case "flac":
+ case "mp3":
+ case "m4a":
+ case "ogg":
+ case "wav":
+ case "wma":
+ return "Audio";
+
+ case "avi":
+ case "mp4":
+ return "Video";
+ }
+
+ return "Misc";
+ }
}
}
diff --git a/Application/FileConverter/ValueConverters/Generic/CollectionContainsElementToBool.cs b/Application/FileConverter/ValueConverters/Generic/CollectionContainsElementToBool.cs
new file mode 100644
index 0000000..43b49b1
--- /dev/null
+++ b/Application/FileConverter/ValueConverters/Generic/CollectionContainsElementToBool.cs
@@ -0,0 +1,41 @@
+// License: http://www.gnu.org/licenses/gpl.html GPL version 3.
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Data;
+
+namespace FileConverter.ValueConverters.Generic
+{
+ public class CollectionContainsElementToBool : IMultiValueConverter
+ {
+ public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (values == null || values.Length != 2)
+ {
+ throw new ArgumentException("The values must contains the collection of elements and the researched element.");
+ }
+
+ // TODO: Make this converter generic.
+
+ if (!(values[0] is ICollection))
+ {
+ return false;
+ }
+
+ ICollection collection = values[0] as ICollection;
+ string objectToFind = values[1] as string;
+
+ return collection.Contains(objectToFind);
+ }
+
+ public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Application/FileConverter/Windows/InputExtension.cs b/Application/FileConverter/Windows/InputExtension.cs
new file mode 100644
index 0000000..70c76cd
--- /dev/null
+++ b/Application/FileConverter/Windows/InputExtension.cs
@@ -0,0 +1,40 @@
+// License: http://www.gnu.org/licenses/gpl.html GPL version 3.
+
+namespace FileConverter
+{
+ using System.ComponentModel;
+ using System.Runtime.CompilerServices;
+ using FileConverter.Annotations;
+
+ public class InputExtension : INotifyPropertyChanged
+ {
+ public string name;
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ public InputExtension(string name)
+ {
+ this.Name = name;
+ }
+
+ public string Name
+ {
+ get
+ {
+ return this.name;
+ }
+
+ set
+ {
+ this.name = value;
+ this.OnPropertyChanged();
+ }
+ }
+
+ [NotifyPropertyChangedInvocator]
+ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+}
\ No newline at end of file
diff --git a/Application/FileConverter/Windows/InputExtensionCategory.cs b/Application/FileConverter/Windows/InputExtensionCategory.cs
new file mode 100644
index 0000000..79ea898
--- /dev/null
+++ b/Application/FileConverter/Windows/InputExtensionCategory.cs
@@ -0,0 +1,61 @@
+// License: http://www.gnu.org/licenses/gpl.html GPL version 3.
+
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+using FileConverter.Annotations;
+
+namespace FileConverter
+{
+ public class InputExtensionCategory : INotifyPropertyChanged
+ {
+ private string name;
+ private List inputExtensions = new List();
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ public InputExtensionCategory(string name)
+ {
+ this.Name = name;
+ }
+
+ public string Name
+ {
+ get
+ {
+ return this.name;
+ }
+
+ set
+ {
+ this.name = value;
+ this.OnPropertyChanged();
+ }
+ }
+
+ public IEnumerable InputExtensions
+ {
+ get
+ {
+ return this.inputExtensions;
+ }
+ }
+
+ public void AddExtension(string extension)
+ {
+ InputExtension inputExtension = this.inputExtensions.Find(match => match.Name == extension);
+ if (inputExtension == null)
+ {
+ inputExtension = new InputExtension(extension);
+ this.inputExtensions.Add(inputExtension);
+ this.OnPropertyChanged("InputExtensions");
+ }
+ }
+
+ [NotifyPropertyChangedInvocator]
+ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+}
\ No newline at end of file
diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml
index 9dcd765..6e82a5c 100644
--- a/Application/FileConverter/Windows/SettingsWindow.xaml
+++ b/Application/FileConverter/Windows/SettingsWindow.xaml
@@ -1,4 +1,4 @@
-
@@ -15,6 +16,8 @@
+
+
@@ -81,8 +84,8 @@
+ EncodingMode="{Binding SelectedPreset.Settings, ConverterParameter=Encoding|FileConverter.EncodingMode, Converter={StaticResource ConversionSettingsToEnum}, ElementName=window, Mode=OneWay, TargetNullValue=VBR}"
+ Bitrate="{Binding SelectedPreset.Settings, ConverterParameter=Bitrate|System.Double, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=190}" />
@@ -92,7 +95,7 @@
+ Bitrate="{Binding SelectedPreset.Settings, ConverterParameter=Bitrate|System.Double, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=160}" />
@@ -127,11 +130,7 @@
-
+
@@ -150,22 +149,22 @@
-
-
+
+
-
-
+
+
-
+
-
-
-
-
+
+
+
+
@@ -181,7 +180,7 @@
-
+
@@ -194,34 +193,41 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+ Content="{Binding SelectedPreset.OutputType, ElementName=window, UpdateSourceTrigger=PropertyChanged}" />
@@ -237,7 +243,7 @@
-
+
@@ -258,8 +264,8 @@
-
-
+
+
diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml.cs b/Application/FileConverter/Windows/SettingsWindow.xaml.cs
index 9c7b992..6bc022d 100644
--- a/Application/FileConverter/Windows/SettingsWindow.xaml.cs
+++ b/Application/FileConverter/Windows/SettingsWindow.xaml.cs
@@ -2,7 +2,9 @@
namespace FileConverter
{
+ using Microsoft.Win32;
using System;
+ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Windows;
using System.ComponentModel;
@@ -20,6 +22,8 @@ namespace FileConverter
private Settings settings;
+ private InputExtensionCategory[] inputCategories;
+
public SettingsWindow()
{
this.InitializeComponent();
@@ -46,6 +50,8 @@ namespace FileConverter
};
this.PostConversionActionComboBox.ItemsSource = postConversionActions;
+
+ this.InitializeCompatibleInputExtensions();
}
public event PropertyChangedEventHandler PropertyChanged;
@@ -65,7 +71,21 @@ namespace FileConverter
this.OnPropertyChanged();
}
}
-
+
+ public InputExtensionCategory[] InputCategories
+ {
+ get
+ {
+ return this.inputCategories;
+ }
+
+ set
+ {
+ this.inputCategories = value;
+ this.OnPropertyChanged();
+ }
+ }
+
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
@@ -80,7 +100,7 @@ namespace FileConverter
}
CheckBox checkBox = sender as System.Windows.Controls.CheckBox;
- string inputFormat = checkBox.Content as string;
+ string inputFormat = (checkBox.Content as string).ToLowerInvariant();
if (!this.selectedPreset.InputTypes.Contains(inputFormat))
{
@@ -96,7 +116,7 @@ namespace FileConverter
}
CheckBox checkBox = sender as System.Windows.Controls.CheckBox;
- string inputFormat = checkBox.Content as string;
+ string inputFormat = (checkBox.Content as string).ToLowerInvariant();
this.selectedPreset.InputTypes.Remove(inputFormat);
}
@@ -183,5 +203,41 @@ namespace FileConverter
this.settings.ConversionPresets.Move(indexOfSelectedPreset, newIndexOfSelectedPreset);
}
+
+ private void InitializeCompatibleInputExtensions()
+ {
+ RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\FileConverter");
+ if (registryKey == null)
+ {
+ MessageBox.Show("Can't retrieve the list of compatible input extensions. (code 0x09)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ return;
+ }
+
+ string registryValue = registryKey.GetValue("CompatibleInputExtensions") as string;
+ if (registryValue == null)
+ {
+ MessageBox.Show("Can't retrieve the list of compatible input extensions. (code 0x0A)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ return;
+ }
+
+ string[] compatibleInputExtensions = registryValue.Split(';');
+
+ List categories = new List();
+ for (int index = 0; index < compatibleInputExtensions.Length; index++)
+ {
+ string compatibleInputExtension = compatibleInputExtensions[index];
+ string extensionCategory = PathHelpers.GetExtensionCategory(compatibleInputExtension);
+ InputExtensionCategory category = categories.Find(match => match.Name == extensionCategory);
+ if (category == null)
+ {
+ category = new InputExtensionCategory(extensionCategory);
+ categories.Add(category);
+ }
+
+ category.AddExtension(compatibleInputExtension);
+ }
+
+ this.InputCategories = categories.ToArray();
+ }
}
}
diff --git a/Application/FileConverterExtension/FileConverterExtension.cs b/Application/FileConverterExtension/FileConverterExtension.cs
index cd10a47..4055250 100644
--- a/Application/FileConverterExtension/FileConverterExtension.cs
+++ b/Application/FileConverterExtension/FileConverterExtension.cs
@@ -26,6 +26,7 @@ namespace FileConverterExtension
private string fileConverterPath;
private RegistryKey fileConverterRegistryKey;
private List presetList = new List();
+ private List compatibleInputExtensions = new List();
private RegistryKey FileConverterRegistryKey
{
@@ -57,6 +58,27 @@ namespace FileConverterExtension
}
}
+ private IEnumerable CompatibleInputExtensions
+ {
+ get
+ {
+ if (this.compatibleInputExtensions != null && this.compatibleInputExtensions.Count > 0)
+ {
+ return this.compatibleInputExtensions;
+ }
+
+ this.compatibleInputExtensions.Clear();
+ string registryValue = this.FileConverterRegistryKey.GetValue("CompatibleInputExtensions") as string;
+ string[] extensions = registryValue.Split(';');
+ for (int index = 0; index < extensions.Length; index++)
+ {
+ this.compatibleInputExtensions.Add(extensions[index]);
+ }
+
+ return this.compatibleInputExtensions;
+ }
+ }
+
protected override bool CanShowMenu()
{
foreach (string filePath in this.SelectedItemPaths)
@@ -68,15 +90,9 @@ namespace FileConverterExtension
}
extension = extension.Substring(1).ToLowerInvariant();
- switch (extension)
+ if (this.CompatibleInputExtensions.Contains(extension))
{
- case "ape":
- case "mp3":
- case "wav":
- case "ogg":
- case "flac":
- case "wma":
- return true;
+ return true;
}
}