diff --git a/Application/FileConverter/Application.xaml b/Application/FileConverter/Application.xaml index 0a4644e..d0b126d 100644 --- a/Application/FileConverter/Application.xaml +++ b/Application/FileConverter/Application.xaml @@ -9,67 +9,69 @@ xmlns:services="clr-namespace:FileConverter.Services" ShutdownMode="OnLastWindowClose"> - - - - - - + + + + + - - + + + + + + - + + - + + + + + - + + + - - - - + + + - - - - - + + + + + - - + + - - - - - + + + + + diff --git a/Application/FileConverter/Controls/ConversionJobControl.xaml b/Application/FileConverter/Controls/ConversionJobControl.xaml index 0cb02a9..7a18468 100644 --- a/Application/FileConverter/Controls/ConversionJobControl.xaml +++ b/Application/FileConverter/Controls/ConversionJobControl.xaml @@ -8,17 +8,10 @@ mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="800" d:DataContext="{d:DesignData /SampleData/ConversionJobSampleData.xaml}"> - - - - - - - - + @@ -44,7 +37,7 @@ - + @@ -57,10 +50,15 @@ - - - + + diff --git a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml index f78ef4c..ef2d7dc 100644 --- a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml +++ b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml @@ -5,12 +5,12 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters" xmlns:project="clr-namespace:FileConverter.Properties" - x:Name="userControl" x:Class="FileConverter.Controls.EncodingQualitySliderControl" mc:Ignorable="d" d:DesignWidth="300" Height="50"> + @@ -21,8 +21,10 @@ - - diff --git a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs index ce790fd..d54a0b5 100644 --- a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs +++ b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs @@ -2,7 +2,6 @@ namespace FileConverter.Controls { - using System.Diagnostics; using System.Windows; using System.Windows.Controls; diff --git a/Application/FileConverter/Controls/IconButton.cs b/Application/FileConverter/Controls/IconButton.cs new file mode 100644 index 0000000..bdc3c17 --- /dev/null +++ b/Application/FileConverter/Controls/IconButton.cs @@ -0,0 +1,38 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.Controls +{ + using System.Windows; + using System.Windows.Controls; + using System.Windows.Media; + + public class IconButton : Button + { + public static readonly DependencyProperty IconSourceProperty = DependencyProperty.Register("IconSource", typeof(ImageSource), typeof(IconButton)); + public static readonly DependencyProperty MouseOverBrushProperty = DependencyProperty.Register("MouseOverBrush", typeof(Brush), typeof(IconButton)); + public static readonly DependencyProperty PressedBrushProperty = DependencyProperty.Register("PressedBrush", typeof(Brush), typeof(IconButton)); + + static IconButton() + { + FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(IconButton), new FrameworkPropertyMetadata(typeof(IconButton))); + } + + public ImageSource IconSource + { + get => (ImageSource)this.GetValue(IconButton.IconSourceProperty); + set => this.SetValue(IconButton.IconSourceProperty, value); + } + + public Brush MouseOverBrush + { + get => (Brush)this.GetValue(IconButton.MouseOverBrushProperty); + set => this.SetValue(IconButton.MouseOverBrushProperty, value); + } + + public Brush PressedBrush + { + get => (Brush)this.GetValue(IconButton.PressedBrushProperty); + set => this.SetValue(IconButton.PressedBrushProperty, value); + } + } +} diff --git a/Application/FileConverter/ConversionJobs/ConversionJob.cs b/Application/FileConverter/ConversionJobs/ConversionJob.cs index 5852a9f..9c51027 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob.cs @@ -20,7 +20,7 @@ namespace FileConverter.ConversionJobs private string userState = string.Empty; private RelayCommand cancelCommand; - private string initialInputPath; + private readonly string initialInputPath; private int currentOutputFilePathIndex; public ConversionJob() @@ -101,10 +101,7 @@ namespace FileConverter.ConversionJobs public string UserState { - get - { - return this.userState; - } + get => this.userState; protected set { @@ -115,10 +112,7 @@ namespace FileConverter.ConversionJobs public float Progress { - get - { - return this.progress; - } + get => this.progress; protected set { @@ -127,12 +121,9 @@ namespace FileConverter.ConversionJobs } } - public System.DateTime StartTime + public DateTime StartTime { - get - { - return this.startTime; - } + get => this.startTime; protected set { @@ -143,10 +134,7 @@ namespace FileConverter.ConversionJobs public string ErrorMessage { - get - { - return this.errorMessage; - } + get => this.errorMessage; private set { @@ -182,10 +170,7 @@ namespace FileConverter.ConversionJobs protected int CurrentOutputFilePathIndex { - get - { - return this.currentOutputFilePathIndex; - } + get => this.currentOutputFilePathIndex; set { @@ -207,6 +192,8 @@ namespace FileConverter.ConversionJobs } } + protected virtual bool IsCancelable => this.State == ConversionState.InProgress; + protected string[] OutputFilePaths { get; @@ -376,7 +363,7 @@ namespace FileConverter.ConversionJobs public virtual void Cancel() { - if (!this.IsCancelable()) + if (!this.IsCancelable) { return; } @@ -385,11 +372,6 @@ namespace FileConverter.ConversionJobs this.ConversionFailed(Properties.Resources.ErrorCanceled); } - protected virtual bool IsCancelable() - { - return this.State == ConversionState.InProgress; - } - protected virtual int GetOutputFilesCount() { return 1; diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Excel.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Excel.cs index a3d33ba..f900a85 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_Excel.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Excel.cs @@ -26,18 +26,9 @@ namespace FileConverter.ConversionJobs { } - protected override ApplicationName Application - { - get - { - return ApplicationName.Excel; - } - } + protected override ApplicationName Application => ApplicationName.Excel; - protected override bool IsCancelable() - { - return false; - } + protected override bool IsCancelable => false; protected override int GetOutputFilesCount() { diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs index 14012ab..934d102 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs @@ -16,7 +16,7 @@ namespace FileConverter.ConversionJobs return string.Empty; } - return string.Format("{0} \"{1}\"", optionName, args); + return $"{optionName} \"{args}\""; } /// diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index cac27bb..dd84eb2 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -21,7 +21,7 @@ namespace FileConverter.ConversionJobs private ProcessStartInfo ffmpegProcessStartInfo; - private List ffmpegArgumentStringByPass = new List(); + private readonly List ffmpegArgumentStringByPass = new List(); public ConversionJob_FFMPEG() : base() { @@ -72,12 +72,13 @@ namespace FileConverter.ConversionJobs return; } - this.ffmpegProcessStartInfo = new ProcessStartInfo(ffmpegPath); - - this.ffmpegProcessStartInfo.CreateNoWindow = true; - this.ffmpegProcessStartInfo.UseShellExecute = false; - this.ffmpegProcessStartInfo.RedirectStandardOutput = true; - this.ffmpegProcessStartInfo.RedirectStandardError = true; + this.ffmpegProcessStartInfo = new ProcessStartInfo(ffmpegPath) + { + CreateNoWindow = true, + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true + }; this.FillFFMpegArgumentsList(); } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Office.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Office.cs index 60e5d50..567dd63 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_Office.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Office.cs @@ -26,10 +26,7 @@ namespace FileConverter.ConversionJobs get; } - protected override bool IsCancelable() - { - return false; - } + protected override bool IsCancelable => false; protected override void Initialize() { diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs b/Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs index 2a30c42..dc88f0c 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs @@ -27,18 +27,9 @@ namespace FileConverter.ConversionJobs { } - protected override ApplicationName Application - { - get - { - return ApplicationName.PowerPoint; - } - } + protected override ApplicationName Application => ApplicationName.PowerPoint; - protected override bool IsCancelable() - { - return false; - } + protected override bool IsCancelable => false; protected override int GetOutputFilesCount() { diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs index 5721896..36d3e54 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs @@ -26,18 +26,9 @@ namespace FileConverter.ConversionJobs { } - protected override ApplicationName Application - { - get - { - return ApplicationName.Word; - } - } + protected override ApplicationName Application => ApplicationName.Word; - protected override bool IsCancelable() - { - return false; - } + protected override bool IsCancelable => false; protected override int GetOutputFilesCount() { diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 59a4c6e..693892d 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -4,16 +4,12 @@ namespace FileConverter { using System; using System.Collections.Generic; - using System.ComponentModel; using System.Globalization; - using System.Linq; using System.Xml.Serialization; using FileConverter.Controls; - using FileConverter.Services; using GalaSoft.MvvmLight; - using GalaSoft.MvvmLight.Ioc; [XmlRoot] [XmlType] @@ -332,7 +328,7 @@ namespace FileConverter { if (string.IsNullOrEmpty(settingsKey)) { - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(settingsKey)); } if (value == null) @@ -359,7 +355,7 @@ namespace FileConverter { if (string.IsNullOrEmpty(settingsKey)) { - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(settingsKey)); } if (this.settings.ContainsKey(settingsKey)) @@ -382,10 +378,10 @@ namespace FileConverter Type type = typeof(T); if (type.IsEnum) { - return (T)System.Enum.Parse(type, settingsValue); + return (T)Enum.Parse(type, settingsValue); } - return (T)System.Convert.ChangeType(settingsValue, type, NumberFormatInfo.InvariantInfo); + return (T)Convert.ChangeType(settingsValue, type, NumberFormatInfo.InvariantInfo); } public bool IsRelevantSetting(string settingsKey) diff --git a/Application/FileConverter/ConversionPreset/ConversionSettingsOverride.cs b/Application/FileConverter/ConversionPreset/ConversionSettingsOverride.cs index 22eb066..1c4b383 100644 --- a/Application/FileConverter/ConversionPreset/ConversionSettingsOverride.cs +++ b/Application/FileConverter/ConversionPreset/ConversionSettingsOverride.cs @@ -16,13 +16,7 @@ namespace FileConverter this.value = value; } - public int Count - { - get - { - return 1; - } - } + public int Count => 1; public IEnumerable Keys { diff --git a/Application/FileConverter/Diagnostics/Debug.cs b/Application/FileConverter/Diagnostics/Debug.cs index fc538f8..603f636 100644 --- a/Application/FileConverter/Diagnostics/Debug.cs +++ b/Application/FileConverter/Diagnostics/Debug.cs @@ -12,10 +12,10 @@ namespace FileConverter.Diagnostics public static class Debug { - private static string diagnosticsFolderPath; - private static Dictionary diagnosticsDataById = new Dictionary(); + private static readonly string diagnosticsFolderPath; + private static readonly Dictionary diagnosticsDataById = new Dictionary(); private static int threadCount = 0; - private static int mainThreadId = 0; + private static readonly int mainThreadId = 0; static Debug() { @@ -45,13 +45,7 @@ namespace FileConverter.Diagnostics public static event EventHandler StaticPropertyChanged; - public static DiagnosticsData[] Data - { - get - { - return Debug.diagnosticsDataById.Values.ToArray(); - } - } + public static DiagnosticsData[] Data => Debug.diagnosticsDataById.Values.ToArray(); public static void Log(string message, params object[] arguments) { diff --git a/Application/FileConverter/Diagnostics/DiagnosticsData.cs b/Application/FileConverter/Diagnostics/DiagnosticsData.cs index a5b0fb8..5353367 100644 --- a/Application/FileConverter/Diagnostics/DiagnosticsData.cs +++ b/Application/FileConverter/Diagnostics/DiagnosticsData.cs @@ -13,8 +13,8 @@ namespace FileConverter.Diagnostics public class DiagnosticsData : INotifyPropertyChanged { - private List logMessages = new List(); - private StringBuilder stringBuilder = new StringBuilder(); + private readonly List logMessages = new List(); + private readonly StringBuilder stringBuilder = new StringBuilder(); private System.IO.TextWriter logFileWriter; private string name; @@ -28,10 +28,7 @@ namespace FileConverter.Diagnostics public string Name { - get - { - return this.name; - } + get => this.name; private set { @@ -62,7 +59,7 @@ namespace FileConverter.Diagnostics public void Initialize(string diagnosticsFolderPath, int id) { - string path = Path.Combine(diagnosticsFolderPath, string.Format("Diagnostics{0}.log", id)); + string path = Path.Combine(diagnosticsFolderPath, $"Diagnostics{id}.log"); path = PathHelpers.GenerateUniquePath(path); this.logFileWriter = new StreamWriter(File.Open(path, FileMode.Create)); @@ -81,7 +78,7 @@ namespace FileConverter.Diagnostics this.logFileWriter.WriteLine(log); this.logFileWriter.Flush(); - this.OnPropertyChanged("Content"); + this.OnPropertyChanged(nameof(this.Content)); } [NotifyPropertyChangedInvocator] diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 0e77bd1..70be402 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -144,6 +144,7 @@ ConversionJobControl.xaml + EncodingQualitySliderControl.xaml @@ -291,6 +292,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -384,12 +389,6 @@ - - - - - - {0c44ca69-42d6-4357-bdfd-83069d1aba2f} @@ -414,6 +413,22 @@ + + + + + + + + + + + + + + + + copy /Y "$(SolutionDir)Middleware\ffmpeg\$(PlatformName)\ffmpeg.exe" "$(TargetDir)ffmpeg.exe" diff --git a/Application/FileConverter/PathHelpers.cs b/Application/FileConverter/PathHelpers.cs index bf8a484..6d49641 100644 --- a/Application/FileConverter/PathHelpers.cs +++ b/Application/FileConverter/PathHelpers.cs @@ -129,7 +129,7 @@ namespace FileConverter } catch (Exception) { - Debug.Log(string.Format("Can't create directories for path {0}", filePath)); + Debug.Log($"Can't create directories for path {filePath}"); return false; } } @@ -213,8 +213,8 @@ namespace FileConverter for (int index = 0; index < directories.Length; index++) { - outputPath = outputPath.Replace(string.Format("(d{0})", directories.Length - index - 1), directories[index]); - outputPath = outputPath.Replace(string.Format("(D{0})", directories.Length - index - 1), directories[index].ToUpperInvariant()); + outputPath = outputPath.Replace($"(d{directories.Length - index - 1})", directories[index]); + outputPath = outputPath.Replace($"(D{directories.Length - index - 1})", directories[index].ToUpperInvariant()); } outputPath = outputPath.Replace("(n:i)", numberIndex.ToString()); diff --git a/Application/FileConverter/Properties/Resources.Designer.cs b/Application/FileConverter/Properties/Resources.Designer.cs index 0c0ca11..d357b63 100644 --- a/Application/FileConverter/Properties/Resources.Designer.cs +++ b/Application/FileConverter/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace FileConverter.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Resources { @@ -88,7 +88,7 @@ namespace FileConverter.Properties { } /// - /// Looks up a localized string similar to Add new preset (duplicate selected preset). + /// Looks up a localized string similar to New preset. /// public static string AddNewPreset { get { @@ -168,6 +168,15 @@ namespace FileConverter.Properties { } } + /// + /// Looks up a localized string similar to Cancel. + /// + public static string CancelJobTooltip { + get { + return ResourceManager.GetString("CancelJobTooltip", resourceCulture); + } + } + /// /// Looks up a localized string similar to Channel count :. /// @@ -313,7 +322,7 @@ namespace FileConverter.Properties { } /// - /// Looks up a localized string similar to Create a new folder.. + /// Looks up a localized string similar to New folder. /// public static string CreateANewFolder { get { @@ -351,9 +360,9 @@ namespace FileConverter.Properties { /// /// Looks up a localized string similar to Logs. /// - public static string DiagnosticsButtonTitle { + public static string DiagnosticsButtonTooltip { get { - return ResourceManager.GetString("DiagnosticsButtonTitle", resourceCulture); + return ResourceManager.GetString("DiagnosticsButtonTooltip", resourceCulture); } } @@ -411,6 +420,15 @@ namespace FileConverter.Properties { } } + /// + /// Looks up a localized string similar to Duplicate preset. + /// + public static string DuplicatePreset { + get { + return ResourceManager.GetString("DuplicatePreset", resourceCulture); + } + } + /// /// Looks up a localized string similar to Encoding :. /// @@ -636,6 +654,15 @@ namespace FileConverter.Properties { } } + /// + /// Looks up a localized string similar to Export. + /// + public static string ExportSelectedPresets { + get { + return ResourceManager.GetString("ExportSelectedPresets", resourceCulture); + } + } + /// /// Looks up a localized string similar to Custom Arguments. /// @@ -717,6 +744,15 @@ namespace FileConverter.Properties { } } + /// + /// Looks up a localized string similar to Import. + /// + public static string ImportPresets { + get { + return ResourceManager.GetString("ImportPresets", resourceCulture); + } + } + /// /// Looks up a localized string similar to Input example. /// @@ -897,6 +933,15 @@ namespace FileConverter.Properties { } } + /// + /// Looks up a localized string similar to No preset selected. + /// + public static string NoPresetSelected { + get { + return ResourceManager.GetString("NoPresetSelected", resourceCulture); + } + } + /// /// Looks up a localized string similar to Ok. /// @@ -1024,14 +1069,14 @@ namespace FileConverter.Properties { /// /// Looks up a localized string similar to Recommended bitrate range in blue. /// - public static string RecommendeBitrateRangeInBlue { + public static string RecommendedBitrateRangeInBlue { get { - return ResourceManager.GetString("RecommendeBitrateRangeInBlue", resourceCulture); + return ResourceManager.GetString("RecommendedBitrateRangeInBlue", resourceCulture); } } /// - /// Looks up a localized string similar to Remove selected preset. + /// Looks up a localized string similar to Delete. /// public static string RemoveSelectedPreset { get { @@ -1105,9 +1150,9 @@ namespace FileConverter.Properties { /// /// Looks up a localized string similar to Settings. /// - public static string SettingsButtonTitle { + public static string SettingsButtonTooltip { get { - return ResourceManager.GetString("SettingsButtonTitle", resourceCulture); + return ResourceManager.GetString("SettingsButtonTooltip", resourceCulture); } } diff --git a/Application/FileConverter/Properties/Resources.en.resx b/Application/FileConverter/Properties/Resources.en.resx index 722acb6..2c35246 100644 --- a/Application/FileConverter/Properties/Resources.en.resx +++ b/Application/FileConverter/Properties/Resources.en.resx @@ -127,7 +127,7 @@ Action when conversion succeed - Add new preset (duplicate selected preset) + New preset Application @@ -159,7 +159,7 @@ Logs - + Logs @@ -289,11 +289,11 @@ use maj for uppercase version Quality : - + Recommended bitrate range in blue - Remove selected preset + Delete Rotate : @@ -310,7 +310,7 @@ use maj for uppercase version File Converter Settings - + Settings @@ -550,4 +550,25 @@ use maj for uppercase version Error during conversion job initialization. + + Export + + + Import + + + Duplicate preset + + + Cancel + + + Advanced mode + + + Custom Arguments + + + Custom FFMPEG command line arguments + \ No newline at end of file diff --git a/Application/FileConverter/Properties/Resources.es-ES.resx b/Application/FileConverter/Properties/Resources.es-ES.resx index c34f10b..c37383e 100644 --- a/Application/FileConverter/Properties/Resources.es-ES.resx +++ b/Application/FileConverter/Properties/Resources.es-ES.resx @@ -159,7 +159,7 @@ Registros - + Registros @@ -292,7 +292,7 @@ Use May para versión en mayúsculas Calidad: - + Rango de tasa de bits recomendado en azul @@ -313,7 +313,7 @@ Use May para versión en mayúsculas Configuración - + Configuración diff --git a/Application/FileConverter/Properties/Resources.fr.resx b/Application/FileConverter/Properties/Resources.fr.resx index 9e93ac2..4a172d5 100644 --- a/Application/FileConverter/Properties/Resources.fr.resx +++ b/Application/FileConverter/Properties/Resources.fr.resx @@ -161,7 +161,7 @@ Historique d'activité - + Historique d'activité @@ -300,7 +300,7 @@ utilisez maj pour une version en majuscules Qualité : - + Taux recommandés en bleu @@ -321,7 +321,7 @@ utilisez maj pour une version en majuscules Configuration de File Converter - + Configuration @@ -568,4 +568,16 @@ utilisez maj pour une version en majuscules L'initialisation du processus de conversion a échoué. + + Annuler + + + Mode avancé + + + Arguments personalisés + + + Arguments de ligne de commande FFMPEG personalisés + \ No newline at end of file diff --git a/Application/FileConverter/Properties/Resources.it-IT.resx b/Application/FileConverter/Properties/Resources.it-IT.resx index 4271bfe..a74c6f5 100644 --- a/Application/FileConverter/Properties/Resources.it-IT.resx +++ b/Application/FileConverter/Properties/Resources.it-IT.resx @@ -173,7 +173,7 @@ Log Logs - + Log Logs @@ -361,7 +361,7 @@ use maj for uppercase version Qualità : Quality : - + In blu l'intervallo di bitrate consigliato Recommended bitrate range in blue @@ -389,7 +389,7 @@ use maj for uppercase version Impostazioni Settings - + Impostazioni Settings diff --git a/Application/FileConverter/Properties/Resources.pt-BR.resx b/Application/FileConverter/Properties/Resources.pt-BR.resx index abf93f3..8ac4866 100644 --- a/Application/FileConverter/Properties/Resources.pt-BR.resx +++ b/Application/FileConverter/Properties/Resources.pt-BR.resx @@ -159,7 +159,7 @@ Logs - + Logs @@ -292,7 +292,7 @@ Use maj para a versão em maiúsculas Qualidade : - + O bitrate recomendado está representado em azul @@ -313,7 +313,7 @@ Use maj para a versão em maiúsculas Configurações - + Configurações diff --git a/Application/FileConverter/Properties/Resources.pt.resx b/Application/FileConverter/Properties/Resources.pt.resx index 213bc9a..48fbb8f 100644 --- a/Application/FileConverter/Properties/Resources.pt.resx +++ b/Application/FileConverter/Properties/Resources.pt.resx @@ -159,7 +159,7 @@ Logs - + Logs @@ -292,7 +292,7 @@ Use maj para a versão em maiúsculas Qualidade : - + O bitrate recomendado está representado a azul @@ -313,7 +313,7 @@ Use maj para a versão em maiúsculas Definições - + Definições diff --git a/Application/FileConverter/Properties/Resources.resx b/Application/FileConverter/Properties/Resources.resx index 7412c0e..f02d00e 100644 --- a/Application/FileConverter/Properties/Resources.resx +++ b/Application/FileConverter/Properties/Resources.resx @@ -127,7 +127,7 @@ Action when conversion succeed - Add new preset (duplicate selected preset) + New preset Application @@ -159,7 +159,7 @@ Logs - + Logs @@ -292,11 +292,11 @@ use maj for uppercase version Quality : - + Recommended bitrate range in blue - Remove selected preset + Delete Rotate : @@ -313,7 +313,7 @@ use maj for uppercase version Settings - + Settings @@ -551,7 +551,7 @@ use maj for uppercase version Error during conversion job initialization. - Create a new folder. + New folder New folder @@ -571,4 +571,19 @@ use maj for uppercase version Custom FFMPEG command line arguments + + No preset selected + + + Export + + + Import + + + Duplicate preset + + + Cancel + \ No newline at end of file diff --git a/Application/FileConverter/Registry.cs b/Application/FileConverter/Registry.cs index 85d4a64..a9b7e03 100644 --- a/Application/FileConverter/Registry.cs +++ b/Application/FileConverter/Registry.cs @@ -80,14 +80,13 @@ namespace FileConverter } } - public static T GetValue(string key) + public static T GetValue(string key, T defaultValue = default(T)) { Registry registry = Registry.Instance; - string stringValue; - if (!registry.registryEntries.TryGetValue(key, out stringValue)) + if (!registry.registryEntries.TryGetValue(key, out string stringValue)) { - return default(T); + return defaultValue; } try @@ -100,7 +99,7 @@ namespace FileConverter Diagnostics.Debug.LogError("Can't convert registry value: {0}.", exception.Message); } - return default(T); + return defaultValue; } public static void SetValue(string key, T value) @@ -198,6 +197,7 @@ namespace FileConverter public static class Keys { public static readonly string LastUpdateCheckDate = "LastUpdateCheckDate"; + public static readonly string ImportInitialFolder = "ImportInitialFolder"; } } } diff --git a/Application/FileConverter/Resources/CancelIcon.png b/Application/FileConverter/Resources/CancelIcon.png index 1f3948d..869f269 100644 Binary files a/Application/FileConverter/Resources/CancelIcon.png and b/Application/FileConverter/Resources/CancelIcon.png differ diff --git a/Resources/PresetIcon.ico b/Application/FileConverter/Resources/DuplicatePresetIcon.ico similarity index 100% rename from Resources/PresetIcon.ico rename to Application/FileConverter/Resources/DuplicatePresetIcon.ico diff --git a/Application/FileConverter/Resources/ExportIcon.ico b/Application/FileConverter/Resources/ExportIcon.ico new file mode 100644 index 0000000..b24fc0c Binary files /dev/null and b/Application/FileConverter/Resources/ExportIcon.ico differ diff --git a/Application/FileConverter/Resources/FailIcon.png b/Application/FileConverter/Resources/FailIcon.png index 6f9b86f..cd1cede 100644 Binary files a/Application/FileConverter/Resources/FailIcon.png and b/Application/FileConverter/Resources/FailIcon.png differ diff --git a/Application/FileConverter/Resources/ImportIcon.ico b/Application/FileConverter/Resources/ImportIcon.ico new file mode 100644 index 0000000..d28c549 Binary files /dev/null and b/Application/FileConverter/Resources/ImportIcon.ico differ diff --git a/Application/FileConverter/Resources/ItchIO-icon.png b/Application/FileConverter/Resources/ItchIO-icon.png deleted file mode 100644 index 5d29f5b..0000000 Binary files a/Application/FileConverter/Resources/ItchIO-icon.png and /dev/null differ diff --git a/Application/FileConverter/Resources/LogIcon.png b/Application/FileConverter/Resources/LogIcon.png new file mode 100644 index 0000000..65187dd Binary files /dev/null and b/Application/FileConverter/Resources/LogIcon.png differ diff --git a/Application/FileConverter/Resources/PaypalIcon.png b/Application/FileConverter/Resources/PaypalIcon.png new file mode 100644 index 0000000..e54a9b0 Binary files /dev/null and b/Application/FileConverter/Resources/PaypalIcon.png differ diff --git a/Application/FileConverter/Resources/PresetIcon.ico b/Application/FileConverter/Resources/PresetIcon.ico index e1f4f12..67df382 100644 Binary files a/Application/FileConverter/Resources/PresetIcon.ico and b/Application/FileConverter/Resources/PresetIcon.ico differ diff --git a/Application/FileConverter/Resources/SayThanks-Icon.png b/Application/FileConverter/Resources/SayThanks-Icon.png deleted file mode 100644 index af5781e..0000000 Binary files a/Application/FileConverter/Resources/SayThanks-Icon.png and /dev/null differ diff --git a/Application/FileConverter/Resources/SayThanksIcon.png b/Application/FileConverter/Resources/SayThanksIcon.png new file mode 100644 index 0000000..b22acc2 Binary files /dev/null and b/Application/FileConverter/Resources/SayThanksIcon.png differ diff --git a/Application/FileConverter/Resources/SuccessIcon.png b/Application/FileConverter/Resources/SuccessIcon.png index 00ce2bf..ae1adf9 100644 Binary files a/Application/FileConverter/Resources/SuccessIcon.png and b/Application/FileConverter/Resources/SuccessIcon.png differ diff --git a/Application/FileConverter/SampleData/SettingsSampleData.xaml b/Application/FileConverter/SampleData/SettingsSampleData.xaml index 49693e1..b28a3ba 100644 --- a/Application/FileConverter/SampleData/SettingsSampleData.xaml +++ b/Application/FileConverter/SampleData/SettingsSampleData.xaml @@ -55,7 +55,7 @@ - + - + diff --git a/Application/FileConverter/Services/NavigationService.cs b/Application/FileConverter/Services/NavigationService.cs index b4e7a7a..e3c832a 100644 --- a/Application/FileConverter/Services/NavigationService.cs +++ b/Application/FileConverter/Services/NavigationService.cs @@ -4,9 +4,6 @@ namespace FileConverter.Services { using System; using System.Collections.Generic; - using System.ComponentModel; - using System.Linq; - using System.Runtime.CompilerServices; using System.Windows; using FileConverter.Annotations; diff --git a/Application/FileConverter/Services/UpgradeVersionDescription.cs b/Application/FileConverter/Services/UpgradeVersionDescription.cs index 6457ce0..673bf8a 100644 --- a/Application/FileConverter/Services/UpgradeVersionDescription.cs +++ b/Application/FileConverter/Services/UpgradeVersionDescription.cs @@ -2,12 +2,8 @@ namespace FileConverter.Services { - using System.ComponentModel; - using System.Runtime.CompilerServices; using System.Xml.Serialization; - using FileConverter.Annotations; - using GalaSoft.MvvmLight; public class UpgradeVersionDescription : ObservableObject @@ -52,10 +48,7 @@ namespace FileConverter.Services [XmlIgnore] public bool InstallerDownloadInProgress { - get - { - return this.installerDownloadInProgress; - } + get => this.installerDownloadInProgress; set { @@ -69,10 +62,7 @@ namespace FileConverter.Services [XmlIgnore] public int InstallerDownloadProgress { - get - { - return this.installerDownloadProgress; - } + get => this.installerDownloadProgress; set { @@ -84,22 +74,10 @@ namespace FileConverter.Services } [XmlIgnore] - public bool InstallerDownloadDone - { - get - { - return !this.InstallerDownloadInProgress && this.InstallerDownloadProgress == 100; - } - } + public bool InstallerDownloadDone => !this.InstallerDownloadInProgress && this.InstallerDownloadProgress == 100; [XmlIgnore] - public bool InstallerDownloadNotStarted - { - get - { - return !this.InstallerDownloadInProgress && this.InstallerDownloadProgress == 0; - } - } + public bool InstallerDownloadNotStarted => !this.InstallerDownloadInProgress && this.InstallerDownloadProgress == 0; [XmlIgnore] public bool NeedToUpgrade diff --git a/Application/FileConverter/Settings.cs b/Application/FileConverter/Settings.cs index de8c016..33f1d10 100644 --- a/Application/FileConverter/Settings.cs +++ b/Application/FileConverter/Settings.cs @@ -16,7 +16,7 @@ namespace FileConverter { public const int Version = 4; - private bool exitApplicationWhenConversionsFinished = true; + private bool exitApplicationWhenConversionsFinished = false; private float durationBetweenEndOfConversionsAndApplicationExit = 3f; private ObservableCollection conversionPresets = new ObservableCollection(); private bool checkUpgradeAtStartup = true; diff --git a/Application/FileConverter/Settings.default.xml b/Application/FileConverter/Settings.default.xml index b770030..b73161f 100644 --- a/Application/FileConverter/Settings.default.xml +++ b/Application/FileConverter/Settings.default.xml @@ -1,7 +1,5 @@ - true - 3 2 3gp @@ -1126,7 +1124,7 @@ - (p)(f) (720p) + (p)(f) (1080p) 3gp @@ -1151,7 +1149,7 @@ - (p)(f) (720p) + (p)(f) (1080p) 3gp @@ -1175,7 +1173,7 @@ - (p)(f) (720p) + (p)(f) (1080p) 3gp @@ -1199,7 +1197,7 @@ - (p)(f) (720p) + (p)(f) (1080p) 3gp @@ -1223,7 +1221,7 @@ - (p)(f) (720p) + (p)(f) (1080p) 3gp diff --git a/Application/FileConverter/ValueConverters/ApplicationVersionToApplicationName.cs b/Application/FileConverter/ValueConverters/ApplicationVersionToApplicationName.cs index 514c818..cc93d8c 100644 --- a/Application/FileConverter/ValueConverters/ApplicationVersionToApplicationName.cs +++ b/Application/FileConverter/ValueConverters/ApplicationVersionToApplicationName.cs @@ -17,7 +17,7 @@ namespace FileConverter.ValueConverters FileConverter.Version version = (FileConverter.Version)value; - return string.Format("File Converter v{0}", version.ToString()); + return $"File Converter v{version}"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Application/FileConverter/ValueConverters/BitrateToString.cs b/Application/FileConverter/ValueConverters/BitrateToString.cs index 213b843..acea132 100644 --- a/Application/FileConverter/ValueConverters/BitrateToString.cs +++ b/Application/FileConverter/ValueConverters/BitrateToString.cs @@ -17,7 +17,7 @@ namespace FileConverter.ValueConverters double bitrate = (double)value; - return string.Format("{0} kbit/s", bitrate.ToString("0")); + return $"{bitrate:0} kbit/s"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Application/FileConverter/ValueConverters/ConversionStateToBrush.cs b/Application/FileConverter/ValueConverters/ConversionStateToBrush.cs index cb50b51..36f6b9d 100644 --- a/Application/FileConverter/ValueConverters/ConversionStateToBrush.cs +++ b/Application/FileConverter/ValueConverters/ConversionStateToBrush.cs @@ -21,52 +21,7 @@ namespace FileConverter.ValueConverters ConversionState conversionState = (ConversionState)value; string type = parameter as string; - if (type == "Background") - { - switch (conversionState) - { - case ConversionState.Unknown: - return new SolidColorBrush(Color.FromRgb(230, 230, 230)); - - case ConversionState.Ready: - return new SolidColorBrush(Color.FromRgb(230, 230, 230)); - - case ConversionState.InProgress: - return new SolidColorBrush(Color.FromRgb(250, 236, 179)); - - case ConversionState.Done: - return new SolidColorBrush(Color.FromRgb(200, 230, 201)); - - case ConversionState.Failed: - return new SolidColorBrush(Color.FromRgb(255, 205, 210)); - } - } - else if (type == "Foreground") - { - switch (conversionState) - { - case ConversionState.Unknown: - return new SolidColorBrush(Color.FromRgb(128, 128, 128)); - - case ConversionState.Ready: - return new SolidColorBrush(Color.FromRgb(32, 32, 32)); - - case ConversionState.InProgress: - return new SolidColorBrush(Color.FromRgb(255, 160, 0)); - - case ConversionState.Done: - return new SolidColorBrush(Color.FromRgb(56, 142, 60)); - - case ConversionState.Failed: - return new SolidColorBrush(Color.FromRgb(255, 82, 82)); - } - } - else - { - throw new SystemException("Unknown type."); - } - - throw new SystemException("Unknown state."); + return Application.Current.Resources[$"{conversionState}{type}Brush"]; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Application/FileConverter/ValueConverters/Generic/BoolToVisibility.cs b/Application/FileConverter/ValueConverters/Generic/BoolToVisibility.cs index e278ef6..5a6d03f 100644 --- a/Application/FileConverter/ValueConverters/Generic/BoolToVisibility.cs +++ b/Application/FileConverter/ValueConverters/Generic/BoolToVisibility.cs @@ -10,11 +10,13 @@ namespace FileConverter.ValueConverters.Generic { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (!(value is bool)) + if (value != null && !(value is bool)) { throw new ArgumentException("The value must be a boolean."); } + bool booleanValue = (bool?) value ?? false; + string stringParameter = parameter as string; string trueResult = "Visible"; @@ -35,7 +37,6 @@ namespace FileConverter.ValueConverters.Generic } } - bool booleanValue = (bool)value; return booleanValue ? trueResult : falseResult; } diff --git a/Application/FileConverter/ValueConverters/Generic/DoubleToTimeString.cs b/Application/FileConverter/ValueConverters/Generic/DoubleToTimeString.cs index 30d0800..d7e533b 100644 --- a/Application/FileConverter/ValueConverters/Generic/DoubleToTimeString.cs +++ b/Application/FileConverter/ValueConverters/Generic/DoubleToTimeString.cs @@ -17,7 +17,7 @@ namespace FileConverter.ValueConverters.Generic double doubleValue = (double)value; - return string.Format("{0} second{1}", doubleValue.ToString("0.#"), doubleValue >= 2 ? "s" : string.Empty); + return $"{doubleValue:0.#} second{(doubleValue >= 2 ? "s" : string.Empty)}"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Application/FileConverter/ValueConverters/Generic/ObjectToLocalizedString.cs b/Application/FileConverter/ValueConverters/Generic/ObjectToLocalizedString.cs index e7e6edd..5fae50d 100644 --- a/Application/FileConverter/ValueConverters/Generic/ObjectToLocalizedString.cs +++ b/Application/FileConverter/ValueConverters/Generic/ObjectToLocalizedString.cs @@ -12,7 +12,7 @@ namespace FileConverter.ValueConverters.Generic { if (value == null) { - throw new System.ArgumentNullException("value."); + throw new System.ArgumentNullException(nameof(value)); } string stringValue = value.ToString(); diff --git a/Application/FileConverter/ValueConverters/Generic/StringToEnum.cs b/Application/FileConverter/ValueConverters/Generic/StringToEnum.cs index d11984f..66b64ba 100644 --- a/Application/FileConverter/ValueConverters/Generic/StringToEnum.cs +++ b/Application/FileConverter/ValueConverters/Generic/StringToEnum.cs @@ -20,7 +20,7 @@ namespace FileConverter.ValueConverters.Generic string typeName = parameter as string; if (typeName == null) { - throw new ArgumentNullException("parameter", "The parameter must contains the enum type."); + throw new ArgumentNullException(nameof(parameter), "The parameter must contains the enum type."); } Type enumType = Type.GetType(typeName); diff --git a/Application/FileConverter/ValueConverters/Generic/StringToValueType.cs b/Application/FileConverter/ValueConverters/Generic/StringToValueType.cs index 650a959..2a29ba0 100644 --- a/Application/FileConverter/ValueConverters/Generic/StringToValueType.cs +++ b/Application/FileConverter/ValueConverters/Generic/StringToValueType.cs @@ -18,7 +18,7 @@ namespace FileConverter.ValueConverters.Generic string typeName = parameter as string; if (typeName == null) { - throw new ArgumentNullException("parameter", "The parameter must contains a convertible type."); + throw new ArgumentNullException(nameof(parameter), "The parameter must contains a convertible type."); } Type type = Type.GetType(typeName); diff --git a/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs b/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs index eded1f2..4e8b742 100644 --- a/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs +++ b/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs @@ -23,8 +23,7 @@ namespace FileConverter.ValueConverters return "Hidden"; } - OutputType referenceType; - if (!Enum.TryParse(referenceTypeName, out referenceType)) + if (!Enum.TryParse(referenceTypeName, out OutputType referenceType)) { return "Hidden"; } diff --git a/Application/FileConverter/Version.cs b/Application/FileConverter/Version.cs index 08b9f2d..97303bc 100644 --- a/Application/FileConverter/Version.cs +++ b/Application/FileConverter/Version.cs @@ -49,10 +49,10 @@ namespace FileConverter { if (this.Patch == 0) { - return string.Format("{0}.{1}", this.Major, this.Minor); + return $"{this.Major}.{this.Minor}"; } - return string.Format("{0}.{1}.{2}", this.Major, this.Minor, this.Patch); + return $"{this.Major}.{this.Minor}.{this.Patch}"; } public override bool Equals(object obj) diff --git a/Application/FileConverter/ViewModels/InputExtension.cs b/Application/FileConverter/ViewModels/InputExtension.cs index 65cf46b..4299f1c 100644 --- a/Application/FileConverter/ViewModels/InputExtension.cs +++ b/Application/FileConverter/ViewModels/InputExtension.cs @@ -2,14 +2,15 @@ namespace FileConverter.ViewModels { - using System.ComponentModel; - using System.Runtime.CompilerServices; using System.Windows.Media; + using CommonServiceLocator; + using GalaSoft.MvvmLight; + using FileConverter.Annotations; using FileConverter.ConversionJobs; - public class InputExtension : INotifyPropertyChanged + public class InputExtension : ObservableObject { private readonly Brush defaultBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0)); private readonly Brush errorBrush = new SolidColorBrush(Color.FromRgb(255, 65, 0)); @@ -48,54 +49,69 @@ namespace FileConverter.ViewModels } } - public event PropertyChangedEventHandler PropertyChanged; - public string Name { - get - { - return this.name; - } + get => this.name; set { this.name = value; - this.OnPropertyChanged(); + this.RaisePropertyChanged(); } } public Brush ForegroundBrush { - get - { - return this.foregroundBrush; - } + get => this.foregroundBrush; set { this.foregroundBrush = value; - this.OnPropertyChanged(); + this.RaisePropertyChanged(); } } public string ToolTip { - get - { - return this.toolTip; - } + get => this.toolTip; set { this.toolTip = value; - this.OnPropertyChanged(); + this.RaisePropertyChanged(); } } - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + public bool IsChecked { - this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + get + { + SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance(); + PresetNode selectedPreset = settingsViewModel.SelectedPreset; + if (selectedPreset == null) + { + return false; + } + + return selectedPreset.Preset.InputTypes.Contains(this.name.ToLowerInvariant()); + } + + set + { + SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance(); + PresetNode selectedPreset = settingsViewModel.SelectedPreset; + + if (value) + { + selectedPreset?.Preset.AddInputType(this.name.ToLowerInvariant()); + } + else + { + selectedPreset?.Preset.RemoveInputType(this.name.ToLowerInvariant()); + } + + this.RaisePropertyChanged(nameof(this.IsChecked)); + } } } } \ No newline at end of file diff --git a/Application/FileConverter/ViewModels/InputExtensionCategory.cs b/Application/FileConverter/ViewModels/InputExtensionCategory.cs index 95c9842..8affdbe 100644 --- a/Application/FileConverter/ViewModels/InputExtensionCategory.cs +++ b/Application/FileConverter/ViewModels/InputExtensionCategory.cs @@ -2,13 +2,15 @@ namespace FileConverter.ViewModels { - using System.Collections.Generic; + using CommonServiceLocator; using GalaSoft.MvvmLight; + using System.ComponentModel; + using System.Collections.Generic; public class InputExtensionCategory : ObservableObject { + private readonly List inputExtensions = new List(); private string name; - private List inputExtensions = new List(); public InputExtensionCategory(string name) { @@ -17,10 +19,7 @@ namespace FileConverter.ViewModels public string Name { - get - { - return this.name; - } + get => this.name; set { @@ -29,13 +28,7 @@ namespace FileConverter.ViewModels } } - public IEnumerable InputExtensions - { - get - { - return this.inputExtensions; - } - } + public IEnumerable InputExtensions => this.inputExtensions; public IEnumerable InputExtensionNames { @@ -55,9 +48,77 @@ namespace FileConverter.ViewModels { inputExtension = new InputExtension(extension); this.inputExtensions.Add(inputExtension); - this.RaisePropertyChanged("InputExtensions"); - this.RaisePropertyChanged("InputExtensionNames"); + + inputExtension.PropertyChanged += this.OnExtensionPropertyChange; + + this.RaisePropertyChanged(nameof(this.InputExtensions)); + this.RaisePropertyChanged(nameof(this.InputExtensionNames)); + this.RaisePropertyChanged(nameof(this.IsChecked)); } } + + public bool? IsChecked + { + get + { + SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance(); + PresetNode selectedPreset = settingsViewModel.SelectedPreset; + if (selectedPreset == null) + { + return false; + } + + bool all = true; + bool none = true; + foreach (string extension in this.InputExtensionNames) + { + bool contains = selectedPreset.Preset.InputTypes.Contains(extension); + all &= contains; + none &= !contains; + } + + if (all) + { + return true; + } + else if (none) + { + return false; + } + + return null; + } + + set + { + SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance(); + PresetNode selectedPreset = settingsViewModel.SelectedPreset; + + foreach (string extension in this.InputExtensionNames) + { + if (value == true) + { + selectedPreset?.Preset.AddInputType(extension); + } + else + { + selectedPreset?.Preset.RemoveInputType(extension); + } + } + + // Raise property change for extensions. + foreach (InputExtension inputExtension in this.InputExtensions) + { + inputExtension.RaisePropertyChanged(nameof(inputExtension.IsChecked)); + } + + this.RaisePropertyChanged(nameof(this.IsChecked)); + } + } + + private void OnExtensionPropertyChange(object sender, PropertyChangedEventArgs e) + { + this.RaisePropertyChanged(nameof(this.IsChecked)); + } } } \ No newline at end of file diff --git a/Application/FileConverter/ViewModels/MainViewModel.cs b/Application/FileConverter/ViewModels/MainViewModel.cs index beee5c2..8c0e50f 100644 --- a/Application/FileConverter/ViewModels/MainViewModel.cs +++ b/Application/FileConverter/ViewModels/MainViewModel.cs @@ -58,10 +58,7 @@ namespace FileConverter.ViewModels public string InformationMessage { - get - { - return this.informationMessage; - } + get => this.informationMessage; private set { @@ -71,10 +68,7 @@ namespace FileConverter.ViewModels public ObservableCollection ConversionJobs { - get - { - return this.conversionJobs; - } + get => this.conversionJobs; private set { diff --git a/Application/FileConverter/ViewModels/PresetNode.cs b/Application/FileConverter/ViewModels/PresetNode.cs index a3d25e5..1ee5c55 100644 --- a/Application/FileConverter/ViewModels/PresetNode.cs +++ b/Application/FileConverter/ViewModels/PresetNode.cs @@ -1,6 +1,5 @@ // License: http://www.gnu.org/licenses/gpl.html GPL version 3. -using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; @@ -143,10 +142,7 @@ namespace FileConverter.ViewModels public string OutputFileNameTemplate { - get - { - return this.Preset.OutputFileNameTemplate; - } + get => this.Preset.OutputFileNameTemplate; set { diff --git a/Application/FileConverter/ViewModels/SettingsViewModel.cs b/Application/FileConverter/ViewModels/SettingsViewModel.cs index 62f2b47..f0e4b56 100644 --- a/Application/FileConverter/ViewModels/SettingsViewModel.cs +++ b/Application/FileConverter/ViewModels/SettingsViewModel.cs @@ -2,6 +2,8 @@ namespace FileConverter.ViewModels { + using System; + using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; @@ -11,6 +13,7 @@ namespace FileConverter.ViewModels using System.Windows.Data; using System.Windows.Input; + using FileConverter.Annotations; using FileConverter.Services; using FileConverter.Views; @@ -45,9 +48,10 @@ namespace FileConverter.ViewModels private RelayCommand openUrlCommand; private RelayCommand getChangeLogContentCommand; private RelayCommand createFolderCommand; - private RelayCommand movePresetUpCommand; - private RelayCommand movePresetDownCommand; - private RelayCommand addNewPresetCommand; + private RelayCommand newPresetCommand; + private RelayCommand duplicatePresetCommand; + private RelayCommand importPresetCommand; + private RelayCommand exportPresetCommand; private RelayCommand removePresetCommand; private RelayCommand saveCommand; private RelayCommand closeCommand; @@ -63,9 +67,10 @@ namespace FileConverter.ViewModels this.getChangeLogContentCommand = new RelayCommand(this.DownloadChangeLogAction); this.openUrlCommand = new RelayCommand((url) => Process.Start(url)); this.createFolderCommand = new RelayCommand(this.CreateFolder); - this.movePresetUpCommand = new RelayCommand(this.MoveSelectedPresetUp, this.CanMoveSelectedPresetUp); - this.movePresetDownCommand = new RelayCommand(this.MoveSelectedPresetDown, this.CanMoveSelectedPresetDown); - this.addNewPresetCommand = new RelayCommand(this.AddNewPreset); + this.newPresetCommand = new RelayCommand(() => this.AddNewPreset(false)); + this.duplicatePresetCommand = new RelayCommand(() => this.AddNewPreset(true), this.CanDuplicateSelectedPreset); + this.importPresetCommand = new RelayCommand(this.ImportPreset); + this.exportPresetCommand = new RelayCommand(this.ExportSelectedPreset, this.CanExportSelectedPreset); this.removePresetCommand = new RelayCommand(this.RemoveSelectedPreset, this.CanRemoveSelectedPreset); this.saveCommand = new RelayCommand(this.SaveSettings, this.CanSaveSettings); this.closeCommand = new RelayCommand(this.CloseSettings); @@ -190,9 +195,9 @@ namespace FileConverter.ViewModels this.RaisePropertyChanged(); this.RaisePropertyChanged(nameof(this.SelectedItem)); - this.movePresetUpCommand?.RaiseCanExecuteChanged(); - this.movePresetDownCommand?.RaiseCanExecuteChanged(); this.removePresetCommand?.RaiseCanExecuteChanged(); + this.exportPresetCommand?.RaiseCanExecuteChanged(); + this.duplicatePresetCommand?.RaiseCanExecuteChanged(); } } @@ -217,9 +222,9 @@ namespace FileConverter.ViewModels this.RaisePropertyChanged(); this.RaisePropertyChanged(nameof(this.SelectedItem)); this.RaisePropertyChanged(nameof(this.InputCategories)); - this.movePresetUpCommand?.RaiseCanExecuteChanged(); - this.movePresetDownCommand?.RaiseCanExecuteChanged(); this.removePresetCommand?.RaiseCanExecuteChanged(); + this.exportPresetCommand?.RaiseCanExecuteChanged(); + this.duplicatePresetCommand?.RaiseCanExecuteChanged(); } } @@ -275,11 +280,13 @@ namespace FileConverter.ViewModels public ICommand CreateFolderCommand => this.createFolderCommand; - public ICommand MovePresetUpCommand => this.movePresetUpCommand; + public ICommand AddNewPresetCommand => this.newPresetCommand; - public ICommand MovePresetDownCommand => this.movePresetDownCommand; + public ICommand DuplicatePresetCommand => this.duplicatePresetCommand; - public ICommand AddNewPresetCommand => this.addNewPresetCommand; + public ICommand ImportPresetCommand => this.importPresetCommand; + + public ICommand ExportPresetCommand => this.exportPresetCommand; public ICommand RemoveSelectedPresetCommand => this.removePresetCommand; @@ -316,6 +323,31 @@ namespace FileConverter.ViewModels public string this[string columnName] => this.Error; + [NotNull] + public string ImportDirectoryPath + { + get + { + string path = FileConverter.Registry.GetValue(FileConverter.Registry.Keys.ImportInitialFolder, Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); + if (!Directory.Exists(path)) + { + path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + } + + return path; + } + + set + { + if (!Directory.Exists(value)) + { + return; + } + + FileConverter.Registry.SetValue(FileConverter.Registry.Keys.ImportInitialFolder, value); + } + } + private string CheckErrorRecursively(AbstractTreeNode node) { string nodeError = node.Error; @@ -409,19 +441,13 @@ namespace FileConverter.ViewModels PresetFolderNode subFolder = parent.Children.FirstOrDefault(match => match is PresetFolderNode && ((PresetFolderNode)match).Name == folderName) as PresetFolderNode; if (subFolder == null) { - subFolder = new PresetFolderNode(folderName, parent); - parent.Children.Add(subFolder); - - subFolder.PropertyChanged += this.NodePropertyChanged; + subFolder = this.CreateFolderNode(folderName, parent); } parent = subFolder; } - PresetNode presetNode = new PresetNode(preset, parent); - parent.Children.Add(presetNode); - - presetNode.PropertyChanged += this.NodePropertyChanged; + this.CreatePresetNode(preset, parent); } this.RaisePropertyChanged(nameof(this.PresetsRootFolder)); @@ -525,120 +551,12 @@ namespace FileConverter.ViewModels Messenger.Default.Send("FolderName", "DoFocus"); } - private bool CanMoveSelectedPresetUp() + private bool CanDuplicateSelectedPreset() { - if (this.SelectedItem == null) - { - // no preset selected. - return false; - } - - if (this.SelectedItem.Parent != this.presetsRootFolder) - { - // The parent is not the root, we can move the preset up. - return true; - } - - int indexOfSelectedPreset = this.SelectedItem.Parent.Children.IndexOf(this.SelectedItem); - return indexOfSelectedPreset > 0; + return this.SelectedPreset != null; } - private void MoveSelectedPresetUp() - { - Diagnostics.Debug.Assert(this.SelectedItem != null, "this.SelectedItem != null"); - - AbstractTreeNode itemToMoveUp = this.SelectedItem; - PresetFolderNode currentParent = itemToMoveUp.Parent; - int indexOfSelectedPreset = currentParent.Children.IndexOf(itemToMoveUp); - if (indexOfSelectedPreset == 0) - { - // Move to the parent folder. - int indexOfFolder = currentParent.Parent.Children.IndexOf(currentParent); - currentParent.Children.RemoveAt(indexOfSelectedPreset); - currentParent.Parent.Children.Insert(indexOfFolder, itemToMoveUp); - itemToMoveUp.Parent = currentParent.Parent; - } - else - { - int newIndexOfSelectedPreset = System.Math.Max(0, indexOfSelectedPreset - 1); - if (currentParent.Children[newIndexOfSelectedPreset] is PresetFolderNode newParent) - { - // Move to child folder. - currentParent.Children.RemoveAt(indexOfSelectedPreset); - newParent.Children.Add(itemToMoveUp); - itemToMoveUp.Parent = newParent; - } - else - { - // Swap nodes. - currentParent.Children.Move(indexOfSelectedPreset, newIndexOfSelectedPreset); - } - } - - this.SelectedItem = itemToMoveUp; - this.movePresetUpCommand.RaiseCanExecuteChanged(); - this.movePresetDownCommand.RaiseCanExecuteChanged(); - this.saveCommand.RaiseCanExecuteChanged(); - } - - private bool CanMoveSelectedPresetDown() - { - if (this.SelectedItem == null) - { - // no preset selected. - return false; - } - - if (this.SelectedItem.Parent != this.presetsRootFolder) - { - // The parent is not the root, we can move the preset down. - return true; - } - - int indexOfSelectedPreset = this.SelectedItem.Parent.Children.IndexOf(this.SelectedItem); - return indexOfSelectedPreset < this.SelectedItem.Parent.Children.Count - 1; - } - - private void MoveSelectedPresetDown() - { - Diagnostics.Debug.Assert(this.SelectedItem != null, "this.SelectedItem != null"); - - AbstractTreeNode itemToMoveDown = this.SelectedItem; - PresetFolderNode currentParent = itemToMoveDown.Parent; - int indexOfSelectedPreset = currentParent.Children.IndexOf(itemToMoveDown); - if (indexOfSelectedPreset == currentParent.Children.Count - 1) - { - // Move to the parent folder. - int indexOfFolder = currentParent.Parent.Children.IndexOf(currentParent); - currentParent.Children.RemoveAt(indexOfSelectedPreset); - currentParent.Parent.Children.Insert(indexOfFolder + 1, itemToMoveDown); - itemToMoveDown.Parent = currentParent.Parent; - } - else - { - int newIndexOfSelectedPreset = System.Math.Min(this.SelectedItem.Parent.Children.Count - 1, indexOfSelectedPreset + 1); - if (currentParent.Children[newIndexOfSelectedPreset] is PresetFolderNode newParent) - { - // Move to child folder. - currentParent.Children.RemoveAt(indexOfSelectedPreset); - newParent.Children.Insert(0, itemToMoveDown); - itemToMoveDown.Parent = newParent; - } - else - { - // Swap nodes. - currentParent.Children.Move(indexOfSelectedPreset, newIndexOfSelectedPreset); - } - } - - this.SelectedItem = itemToMoveDown; - - this.movePresetUpCommand.RaiseCanExecuteChanged(); - this.movePresetDownCommand.RaiseCanExecuteChanged(); - this.saveCommand.RaiseCanExecuteChanged(); - } - - private void AddNewPreset() + private void AddNewPreset(bool duplicate) { PresetFolderNode parent; if (this.SelectedFolder != null) @@ -671,7 +589,7 @@ namespace FileConverter.ViewModels // Create preset by copying the selected one. ConversionPreset newPreset = null; - if (this.SelectedPreset != null) + if (this.SelectedPreset != null && duplicate) { newPreset = new ConversionPreset(presetName, this.SelectedPreset.Preset); } @@ -694,6 +612,101 @@ namespace FileConverter.ViewModels this.saveCommand.RaiseCanExecuteChanged(); } + private void ImportPreset() + { + OpenFileDialog openFileDialog = new OpenFileDialog + { + Title = "Import presets", + Filter = "Preset file (*.xml)|*.xml", + InitialDirectory = this.ImportDirectoryPath, + }; + + if (openFileDialog.ShowDialog() == true) + { + if (!File.Exists(openFileDialog.FileName)) + { + Diagnostics.Debug.LogError("File does not exists."); + } + + string directoryPath = Path.GetDirectoryName(openFileDialog.FileName); + if (!string.IsNullOrEmpty(directoryPath)) + { + this.ImportDirectoryPath = directoryPath; + } + + List presetsToImport = new List(); + XmlHelpers.LoadFromFile("Presets", openFileDialog.FileName, out presetsToImport); + + // Add imported preset to preset tree. + bool itemSelected = false; + foreach (ConversionPreset conversionPreset in presetsToImport) + { + PresetFolderNode parent = this.PresetsRootFolder; + foreach (string folderName in conversionPreset.ParentFoldersNames) + { + PresetFolderNode folderNode = parent.Children.FirstOrDefault(match => match is PresetFolderNode && match.Name == folderName) as PresetFolderNode; + if (folderNode == null) + { + folderNode = this.CreateFolderNode(folderName, parent); + + if (!itemSelected) + { + this.SelectedItem = folderNode; + itemSelected = true; + } + } + + parent = folderNode; + } + + PresetNode node = this.CreatePresetNode(conversionPreset, parent); + if (!itemSelected) + { + this.SelectedItem = node; + itemSelected = true; + } + } + } + } + + private void ExportSelectedPreset() + { + SaveFileDialog saveFileDialog = new SaveFileDialog + { + Title = "Export selected preset or folder", + Filter = "Preset file (*.xml)|*.xml", + InitialDirectory = this.ImportDirectoryPath, + }; + + if (saveFileDialog.ShowDialog() == true) + { + string filePath = saveFileDialog.FileName; + string directoryPath = Path.GetDirectoryName(filePath); + if (!string.IsNullOrEmpty(directoryPath)) + { + this.ImportDirectoryPath = directoryPath; + } + + if (Path.GetExtension(filePath) != ".xml") + { + filePath += ".xml"; + } + + this.settings.ConversionPresets.Clear(); + this.ComputePresetsParentFoldersNamesAndFillSettings(this.presetsRootFolder, new List()); + + List presetsToExport = new List(); + this.FillWithPresetsRecursively(this.SelectedItem, presetsToExport); + + XmlHelpers.SaveToFile("Presets", filePath, presetsToExport); + } + } + + private bool CanExportSelectedPreset() + { + return this.SelectedItem != null; + } + private void RemoveSelectedPreset() { this.SelectedItem.PropertyChanged -= this.NodePropertyChanged; @@ -730,5 +743,38 @@ namespace FileConverter.ViewModels } } } + + private void FillWithPresetsRecursively(AbstractTreeNode node, List presets) + { + if (node is PresetNode presetNode) + { + presets.Add(presetNode.Preset); + } + else if (node is PresetFolderNode folder) + { + foreach (AbstractTreeNode childNode in folder.Children) + { + this.FillWithPresetsRecursively(childNode, presets); + } + } + } + + private PresetFolderNode CreateFolderNode(string folderName, PresetFolderNode parent) + { + PresetFolderNode subFolder = new PresetFolderNode(folderName, parent); + parent.Children.Add(subFolder); + + subFolder.PropertyChanged += this.NodePropertyChanged; + return subFolder; + } + + private PresetNode CreatePresetNode(ConversionPreset preset, PresetFolderNode parent) + { + PresetNode presetNode = new PresetNode(preset, parent); + parent.Children.Add(presetNode); + + presetNode.PropertyChanged += this.NodePropertyChanged; + return presetNode; + } } } diff --git a/Application/FileConverter/ViewModels/UpgradeViewModel.cs b/Application/FileConverter/ViewModels/UpgradeViewModel.cs index 63cdaa4..2250525 100644 --- a/Application/FileConverter/ViewModels/UpgradeViewModel.cs +++ b/Application/FileConverter/ViewModels/UpgradeViewModel.cs @@ -3,7 +3,6 @@ namespace FileConverter.ViewModels { using System.ComponentModel; - using System.Threading.Tasks; using System.Windows.Input; using FileConverter.Services; diff --git a/Application/FileConverter/Views/DiagnosticsWindow.xaml b/Application/FileConverter/Views/DiagnosticsWindow.xaml index 8e9121f..c6aad8b 100644 --- a/Application/FileConverter/Views/DiagnosticsWindow.xaml +++ b/Application/FileConverter/Views/DiagnosticsWindow.xaml @@ -21,10 +21,19 @@ - + - @@ -395,12 +424,12 @@ - - - + @@ -410,44 +439,34 @@ - - - - - public partial class SettingsWindow : Window { + private TextBox selectedPresetNameTextBox; + private TextBox selectedFolderNameTextBox; + private string focusMessage; + private bool dragInProgress = false; + private enum DragDropTargetPosition { Before, @@ -31,109 +36,63 @@ namespace FileConverter.Views this.InitializeComponent(); Messenger.Default.Register(this, "DoFocus", this.DoFocus); + + (this.DataContext as SettingsViewModel).PropertyChanged += this.SettingsWindow_PropertyChanged; + + this.PresetTreeView.MouseDown += this.TreeView_MouseDown; + this.PresetTreeView.MouseUp += this.TreeView_MouseUp; + } + + private void SettingsWindow_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs args) + { + if (args.PropertyName == "SelectedItem") + { + TreeViewItem selectedItem = this.GetTreeViewItem(this.PresetTreeView, this.PresetTreeView.SelectedItem); + selectedItem?.BringIntoView(); + } } public void DoFocus(string message) { + this.focusMessage = message; switch (message) { case "PresetName": - this.PresetNameTextBox.Focus(); - this.PresetNameTextBox.SelectAll(); + this.selectedPresetNameTextBox?.Focus(); + this.selectedPresetNameTextBox?.SelectAll(); break; case "FolderName": - this.FolderNameTextBox.Focus(); - this.FolderNameTextBox.SelectAll(); + this.selectedFolderNameTextBox?.Focus(); + this.selectedFolderNameTextBox?.SelectAll(); break; } } - private void OnInputTypeChecked(object sender, RoutedEventArgs e) + private void TreeView_MouseDown(object sender, MouseButtonEventArgs args) { - SettingsViewModel dataContext = this.DataContext as SettingsViewModel; - if (dataContext.SelectedPreset == null) + FrameworkElement element = args.OriginalSource as FrameworkElement; + TreeViewItem treeViewItem = this.GetNearestContainer(element); + if (treeViewItem != null) { - return; + treeViewItem.IsSelected = true; + this.dragInProgress = args.ChangedButton == MouseButton.Left; } - - CheckBox checkBox = sender as CheckBox; - if (!checkBox.IsVisible) + else { - return; - } - - string inputFormat = (checkBox.Content as string).ToLowerInvariant(); - - dataContext.SelectedPreset.Preset.AddInputType(inputFormat); - } - - private void OnInputTypeUnchecked(object sender, RoutedEventArgs e) - { - SettingsViewModel dataContext = this.DataContext as SettingsViewModel; - if (dataContext.SelectedPreset == null) - { - return; - } - - CheckBox checkBox = sender as CheckBox; - if (!checkBox.IsVisible) - { - return; - } - - string inputFormat = (checkBox.Content as string).ToLowerInvariant(); - - dataContext.SelectedPreset.Preset.RemoveInputType(inputFormat); - } - - private void OnInputTypeCategoryChecked(object sender, RoutedEventArgs e) - { - SettingsViewModel dataContext = this.DataContext as SettingsViewModel; - if (dataContext.SelectedPreset == null) - { - return; - } - - CheckBox checkBox = sender as CheckBox; - string categoryName = checkBox.Content as string; - InputExtensionCategory category = dataContext.InputCategories.FirstOrDefault(match => match.Name == categoryName); - if (category == null) - { - return; - } - - foreach (string inputExtension in category.InputExtensionNames) - { - dataContext.SelectedPreset.Preset.AddInputType(inputExtension); + this.dragInProgress = false; } } - private void OnInputTypeCategoryUnchecked(object sender, RoutedEventArgs e) + private void TreeView_MouseUp(object sender, MouseButtonEventArgs args) { - SettingsViewModel dataContext = this.DataContext as SettingsViewModel; - if (dataContext.SelectedPreset == null) - { - return; - } - - CheckBox checkBox = sender as CheckBox; - string categoryName = checkBox.Content as string; - InputExtensionCategory category = dataContext.InputCategories.FirstOrDefault(match => match.Name == categoryName); - if (category == null) - { - return; - } - - foreach (string inputExtension in category.InputExtensionNames) - { - dataContext.SelectedPreset.Preset.RemoveInputType(inputExtension); - } + this.dragInProgress = false; } - + private void TreeView_MouseMove(object sender, MouseEventArgs args) { - if (args.LeftButton == MouseButtonState.Pressed && + if (this.dragInProgress && + args.LeftButton == MouseButtonState.Pressed && this.PresetTreeView.SelectedItem is AbstractTreeNode nodeToDrag) { var dataObj = new DataObject(); @@ -380,5 +339,25 @@ namespace FileConverter.Views return null; } + + private void SelectedPresetName_OnLoaded(object sender, RoutedEventArgs e) + { + this.selectedPresetNameTextBox = (TextBox)sender; + if (this.focusMessage == "PresetName") + { + this.DoFocus(this.focusMessage); + this.focusMessage = null; + } + } + + private void SelectedFolderName_OnLoaded(object sender, RoutedEventArgs e) + { + this.selectedFolderNameTextBox = (TextBox)sender; + if (this.focusMessage == "FolderName") + { + this.DoFocus(this.focusMessage); + this.focusMessage = null; + } + } } } diff --git a/Application/FileConverter/Views/UpgradeWindow.xaml b/Application/FileConverter/Views/UpgradeWindow.xaml index 41c0b4c..f3ee4b4 100644 --- a/Application/FileConverter/Views/UpgradeWindow.xaml +++ b/Application/FileConverter/Views/UpgradeWindow.xaml @@ -35,7 +35,7 @@ Document="{Binding UpgradeVersionDescription.ChangeLog, Source={StaticResource Upgrade}, Converter={StaticResource ChangelogToMarkdown}}"/> -