diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index 6abcbb4..bd058a4 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -215,18 +215,6 @@ namespace FileConverter if (System.IO.File.Exists(conversionJob.OutputFilePath)) { Diagnostics.Log("Success!"); - - if (this.debugMode) - { - Diagnostics.Log("Delete file {0}.", conversionJob.OutputFilePath); - try - { - //System.IO.File.Delete(conversionJob.OutputFilePath); - } - catch - { - } - } } else { diff --git a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs index 81e2259..90f6421 100644 --- a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs +++ b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs @@ -1,15 +1,13 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter.Controls { - using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; - using System.ComponentModel; /// - /// Interaction logic for EncodingQualitySliderControl.xaml + /// Interaction logic for EncodingQualitySliderControl. /// public partial class EncodingQualitySliderControl : UserControl { @@ -31,7 +29,6 @@ namespace FileConverter.Controls this.CoerceValue(EncodingQualitySliderControl.BitrateProperty); - Debug.Assert(this.slider != null); this.slider.ValueChanged += this.Slider_ValueChanged; } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index 47adce2..11e25c5 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -59,8 +59,7 @@ namespace FileConverter.ConversionJobs { EncodingMode encodingMode = this.ConversionPreset.GetSettingsValue("Encoding"); string encoderArgs = string.Format("-acodec {0}", this.WAVEncodingToCodecArgument(encodingMode)); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", - this.InputFilePath, this.OutputFilePath, encoderArgs); + arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); } break; @@ -73,8 +72,7 @@ namespace FileConverter.ConversionJobs switch (encodingMode) { case EncodingMode.Mp3VBR: - encoderArgs = string.Format("-codec:a libmp3lame -q:a {0}", - this.MP3VBRBitrateToQualityIndex(encodingQuality)); + encoderArgs = string.Format("-codec:a libmp3lame -q:a {0}", this.MP3VBRBitrateToQualityIndex(encodingQuality)); break; case EncodingMode.Mp3CBR: @@ -85,8 +83,7 @@ namespace FileConverter.ConversionJobs break; } - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", - this.InputFilePath, this.OutputFilePath, encoderArgs); + arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); } break; @@ -94,10 +91,8 @@ namespace FileConverter.ConversionJobs case OutputType.Ogg: { int encodingQuality = this.ConversionPreset.GetSettingsValue("Bitrate"); - string encoderArgs = string.Format("-codec:a libvorbis -qscale:a {0}", - this.OGGVBRBitrateToQualityIndex(encodingQuality)); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", - this.InputFilePath, this.OutputFilePath, encoderArgs); + string encoderArgs = string.Format("-codec:a libvorbis -qscale:a {0}", this.OGGVBRBitrateToQualityIndex(encodingQuality)); + arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); } break; @@ -194,10 +189,10 @@ namespace FileConverter.ConversionJobs } /// - /// Convert bitrate in vorbis encoder quality index. + /// Convert bitrate in vorbis encoder quality index. /// /// Wanted bitrate value. - /// The vorbis encoder quality index assotiated to the given bitrate value. + /// The vorbis encoder quality index associated to the given bitrate value. /// http://wiki.hydrogenaud.io/index.php?title=Recommended_Ogg_Vorbis private int OGGVBRBitrateToQualityIndex(int bitrate) { @@ -247,10 +242,10 @@ namespace FileConverter.ConversionJobs } /// - /// Convert encoding mode setting to ffmpeg argument option. + /// Convert encoding mode setting to ffmpeg argument option. /// /// The encoding mode setting. - /// Returns the ffmpeg argument corresponding to the given envoding mode. + /// Returns the ffmpeg argument corresponding to the given encoding mode. /// https://trac.ffmpeg.org/wiki/audio%20types private string WAVEncodingToCodecArgument(EncodingMode encoding) { diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 8e3cd64..04e9873 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -1,4 +1,4 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter { @@ -22,7 +22,7 @@ namespace FileConverter private InputPostConversionAction inputPostConversionAction; private ConversionSettings settings = new ConversionSettings(); private string outputFileNameTemplate; - FileNameConverter outputFileNameConverter = new FileNameConverter(); + private FileNameConverter outputFileNameConverter = new FileNameConverter(); public ConversionPreset() { @@ -68,7 +68,7 @@ namespace FileConverter set { this.outputType = value; - this.InitializeDefaultSettings(outputType); + this.InitializeDefaultSettings(this.outputType); this.OnPropertyChanged(); } } @@ -193,14 +193,6 @@ namespace FileConverter } } - public string this[string columnName] - { - get - { - return this.Validate(columnName); - } - } - public string Error { get @@ -221,6 +213,14 @@ namespace FileConverter } } + public string this[string columnName] + { + get + { + return this.Validate(columnName); + } + } + public void OnDeserializationComplete() { for (int index = 0; index < this.InputTypes.Count; index++) @@ -250,7 +250,7 @@ namespace FileConverter public string GenerateOutputFilePath(string inputFilePath) { - return (string)this.outputFileNameConverter.Convert(new object[] {inputFilePath, this.OutputType, this.OutputFileNameTemplate}, typeof (string), null, null); + return (string)this.outputFileNameConverter.Convert(new object[] { inputFilePath, this.OutputType, this.OutputFileNameTemplate }, typeof(string), null, null); } public void SetSettingsValue(string settingsKey, string value) @@ -403,17 +403,14 @@ namespace FileConverter if (this.Name.Contains(";")) { - return "The preset name can't contains the character ';'."; + return "The preset name can't contains the character ';'."; } Application application = Application.Current as Application; - if (application?.Settings != null) + int? count = application?.Settings?.ConversionPresets?.Count(match => match?.name == this.Name); + if (count > 1) { - int count = application.Settings.ConversionPresets.Count(match => match.name == this.Name); - if (count > 1) - { - return "The preset name is already used."; - } + return "The preset name is already used."; } } diff --git a/Application/FileConverter/ConversionPreset/ConversionSettingsOverride.cs b/Application/FileConverter/ConversionPreset/ConversionSettingsOverride.cs index 4a9ce2e..22eb066 100644 --- a/Application/FileConverter/ConversionPreset/ConversionSettingsOverride.cs +++ b/Application/FileConverter/ConversionPreset/ConversionSettingsOverride.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter { + using System.Collections; + using System.Collections.Generic; + public struct ConversionSettingsOverride : IConversionSettings { private string key; @@ -18,16 +16,6 @@ namespace FileConverter this.value = value; } - IEnumerator IEnumerable.GetEnumerator() - { - return this.GetEnumerator(); - } - - public IEnumerator> GetEnumerator() - { - yield return new KeyValuePair(this.key, this.value); - } - public int Count { get @@ -36,6 +24,40 @@ namespace FileConverter } } + public IEnumerable Keys + { + get + { + yield return this.key; + } + } + + public IEnumerable Values + { + get + { + yield return this.value; + } + } + + public string this[string key] + { + get + { + if (key == this.key) + { + return this.value; + } + + throw new KeyNotFoundException(); + } + } + + public IEnumerator> GetEnumerator() + { + yield return new KeyValuePair(this.key, this.value); + } + public bool ContainsKey(string key) { return key == this.key; @@ -54,33 +76,9 @@ namespace FileConverter return false; } - public string this[string key] + IEnumerator IEnumerable.GetEnumerator() { - get - { - if (key == this.key) - { - return this.value; - } - - throw new KeyNotFoundException(); - } - } - - public IEnumerable Keys - { - get - { - yield return this.key; - } - } - - public IEnumerable Values - { - get - { - yield return this.value; - } + return this.GetEnumerator(); } } } diff --git a/Application/FileConverter/FileConverter.sln.DotSettings b/Application/FileConverter/FileConverter.sln.DotSettings index 6c4d4f7..876a5e5 100644 --- a/Application/FileConverter/FileConverter.sln.DotSettings +++ b/Application/FileConverter/FileConverter.sln.DotSettings @@ -15,6 +15,7 @@ UseExplicitType // <copyright file="$FILENAME$" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright> CBR + OGGVBR VBR <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> diff --git a/Application/FileConverter/Settings.cs b/Application/FileConverter/Settings.cs index f239a82..d749387 100644 --- a/Application/FileConverter/Settings.cs +++ b/Application/FileConverter/Settings.cs @@ -5,18 +5,17 @@ namespace FileConverter using System; using System.Collections.Generic; using System.Collections.ObjectModel; + using System.ComponentModel; using System.Diagnostics; using System.IO; + using System.Linq; using System.Reflection; + using System.Runtime.CompilerServices; using System.Security.Principal; using System.Windows; - using System.ComponentModel; - using System.Linq; - using System.Runtime.CompilerServices; - - using Microsoft.Win32; using FileConverter.Annotations; + using Microsoft.Win32; public class Settings : INotifyPropertyChanged, IDataErrorInfo { @@ -26,6 +25,29 @@ namespace FileConverter public event PropertyChangedEventHandler PropertyChanged; + public ObservableCollection ConversionPresets + { + get { return this.conversionPresets; } + set { this.conversionPresets = value; } + } + + public string Error + { + get + { + for (int index = 0; index < this.ConversionPresets.Count; index++) + { + string error = this.ConversionPresets[index].Error; + if (!string.IsNullOrEmpty(error)) + { + return error; + } + } + + return string.Empty; + } + } + private static bool IsInAdmininstratorPrivileges { get @@ -34,16 +56,45 @@ namespace FileConverter } } - public ObservableCollection ConversionPresets + public string this[string columnName] { - get { return this.conversionPresets; } - set { this.conversionPresets = value; } + get + { + return this.Error; + } } - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + public static void ApplyTemporarySettings() { - this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + // Load temporary settings. + string temporaryFilePath = Settings.GetUserSettingsTemporaryFilePath(); + if (!File.Exists(temporaryFilePath)) + { + return; + } + + ICollection conversionPresets = new ObservableCollection(); + XmlHelpers.LoadFromFile("Settings", temporaryFilePath, ref conversionPresets); + + RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\FileConverter"); + if (registryKey == null) + { + MessageBox.Show("Can't apply settings in registry. (code 0x03)", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + + // Compute the registry entries data from settings. + Dictionary> registryEntries = ComputeRegistryEntriesFromConvertionPresets(conversionPresets); + + bool succeed = Settings.ApplyRegistryModifications(registryEntries); + + if (succeed) + { + // Copy temporary settings file to the real settings file. + string userFilePath = Settings.GetUserSettingsFilePath(); + File.Copy(temporaryFilePath, userFilePath, true); + File.Delete(temporaryFilePath); + } } public ConversionPreset GetPresetFromName(string presetName) @@ -118,39 +169,6 @@ namespace FileConverter } } - public static void ApplyTemporarySettings() - { - // Load temporary settings. - string temporaryFilePath = Settings.GetUserSettingsTemporaryFilePath(); - if (!File.Exists(temporaryFilePath)) - { - return; - } - - ICollection conversionPresets = new ObservableCollection(); - XmlHelpers.LoadFromFile("Settings", temporaryFilePath, ref conversionPresets); - - RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\FileConverter"); - if (registryKey == null) - { - MessageBox.Show("Can't apply settings in registry. (code 0x03)", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - // Compute the registry entries data from settings. - Dictionary> registryEntries = ComputeRegistryEntriesFromConvertionPresets(conversionPresets); - - bool succeed = Settings.ApplyRegistryModifications(registryEntries); - - if (succeed) - { - // Copy temporary settings file to the real settings file. - string userFilePath = Settings.GetUserSettingsFilePath(); - File.Copy(temporaryFilePath, userFilePath, true); - File.Delete(temporaryFilePath); - } - } - private static bool ApplyRegistryModifications(Dictionary> registryEntries) { if (!Settings.IsInAdmininstratorPrivileges) @@ -359,29 +377,10 @@ namespace FileConverter } } - public string this[string columnName] + [NotifyPropertyChangedInvocator] + private void OnPropertyChanged([CallerMemberName] string propertyName = null) { - get - { - return this.Error; - } - } - - public string Error - { - get - { - for (int index = 0; index < this.ConversionPresets.Count; index++) - { - string error = this.ConversionPresets[index].Error; - if (!string.IsNullOrEmpty(error)) - { - return error; - } - } - - return string.Empty; - } + this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } } diff --git a/Application/FileConverter/ValueConverters/Generic/BoolInverterConverter.cs b/Application/FileConverter/ValueConverters/Generic/BoolInverterConverter.cs index 9005e0b..bbab540 100644 --- a/Application/FileConverter/ValueConverters/Generic/BoolInverterConverter.cs +++ b/Application/FileConverter/ValueConverters/Generic/BoolInverterConverter.cs @@ -1,4 +1,4 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter.ValueConverters.Generic { diff --git a/Application/FileConverter/ValueConverters/Generic/CollectionContainsElementToBool.cs b/Application/FileConverter/ValueConverters/Generic/CollectionContainsElementToBool.cs index 2d355ed..7ab3d9c 100644 --- a/Application/FileConverter/ValueConverters/Generic/CollectionContainsElementToBool.cs +++ b/Application/FileConverter/ValueConverters/Generic/CollectionContainsElementToBool.cs @@ -1,17 +1,12 @@ // 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.Controls; -using System.Windows.Data; - namespace FileConverter.ValueConverters.Generic { + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Windows.Data; + public class CollectionContainsElementToBool : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) @@ -21,8 +16,8 @@ namespace FileConverter.ValueConverters.Generic throw new ArgumentException("The values must contains the collection of elements and the researched element."); } - // TODO: Make this converter generic. - + //// TODO: Make this converter generic. + if (!(values[0] is ICollection)) { return false; diff --git a/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs index 0ba302c..46b2fe3 100644 --- a/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs +++ b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs @@ -1,4 +1,4 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter.Windows { diff --git a/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs b/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs index 5e89bf6..ce1eb92 100644 --- a/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs +++ b/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs @@ -5,7 +5,7 @@ namespace FileConverter.Windows using System.Windows; /// - /// Interaction logic for DiagnosticsWindow.xaml + /// Interaction logic for DiagnosticsWindow. /// public partial class DiagnosticsWindow : Window { diff --git a/Application/FileConverter/Windows/InputExtension.cs b/Application/FileConverter/Windows/InputExtension.cs index 70c76cd..ea8c7e7 100644 --- a/Application/FileConverter/Windows/InputExtension.cs +++ b/Application/FileConverter/Windows/InputExtension.cs @@ -1,22 +1,23 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// 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; + private string name; public InputExtension(string name) { this.Name = name; } + public event PropertyChangedEventHandler PropertyChanged; + public string Name { get diff --git a/Application/FileConverter/Windows/InputExtensionCategory.cs b/Application/FileConverter/Windows/InputExtensionCategory.cs index 86dca84..f1c9924 100644 --- a/Application/FileConverter/Windows/InputExtensionCategory.cs +++ b/Application/FileConverter/Windows/InputExtensionCategory.cs @@ -1,24 +1,25 @@ // 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 { + using System.Collections.Generic; + using System.ComponentModel; + using System.Runtime.CompilerServices; + + using FileConverter.Annotations; + public class InputExtensionCategory : INotifyPropertyChanged { private string name; private List inputExtensions = new List(); - public event PropertyChangedEventHandler PropertyChanged; - public InputExtensionCategory(string name) { this.Name = name; } + public event PropertyChangedEventHandler PropertyChanged; + public string Name { get diff --git a/Application/FileConverter/Windows/MainWindow.xaml.cs b/Application/FileConverter/Windows/MainWindow.xaml.cs index 612a01c..5f15899 100644 --- a/Application/FileConverter/Windows/MainWindow.xaml.cs +++ b/Application/FileConverter/Windows/MainWindow.xaml.cs @@ -54,7 +54,7 @@ namespace FileConverter private void SettingsWindow_Closed(object sender, System.EventArgs e) { - settingsWindow.OnSettingsWindowHide -= this.SettingsWindow_Closed; + this.settingsWindow.OnSettingsWindowHide -= this.SettingsWindow_Closed; this.Close(); } diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml.cs b/Application/FileConverter/Windows/SettingsWindow.xaml.cs index 6406ec4..d428a99 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml.cs +++ b/Application/FileConverter/Windows/SettingsWindow.xaml.cs @@ -2,19 +2,19 @@ namespace FileConverter { - using Microsoft.Win32; using System; using System.Collections.Generic; + using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; - using System.ComponentModel; using System.Windows.Controls; using System.Windows.Input; using FileConverter.Annotations; + using Microsoft.Win32; /// - /// Interaction logic for Settings.xaml + /// Interaction logic for Settings. /// public partial class SettingsWindow : Window, INotifyPropertyChanged { @@ -30,7 +30,7 @@ namespace FileConverter Application application = Application.Current as Application; this.settings = application.Settings; - this.PresetList.ItemsSource = settings.ConversionPresets; + this.PresetList.ItemsSource = this.settings.ConversionPresets; OutputType[] outputTypes = new[] {