diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index 782ee0d..6994978 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -391,7 +391,7 @@ namespace FileConverter IConversionService conversionService = SimpleIoc.Default.GetInstance(); // Create conversion jobs. - Debug.Log("Create jobs for conversion preset: '{0}'", conversionPreset.Name); + Debug.Log("Create jobs for conversion preset: '{0}'", conversionPreset.FullName); try { for (int index = 0; index < filePaths.Count; index++) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob.cs b/Application/FileConverter/ConversionJobs/ConversionJob.cs index 1523e82..5852a9f 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob.cs @@ -319,7 +319,7 @@ namespace FileConverter.ConversionJobs this.State = ConversionState.Ready; } - Debug.Log("Job initialized: Preset: '{0}' Input: {1} Output: {2}", this.ConversionPreset.Name, this.InputFilePath, this.OutputFilePath); + Debug.Log("Job initialized: Preset: '{0}' Input: {1} Output: {2}", this.ConversionPreset.FullName, this.InputFilePath, this.OutputFilePath); if (this.State != ConversionState.Failed) { diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 9e2fcfd..959c0e1 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -19,7 +19,8 @@ namespace FileConverter [XmlType] public class ConversionPreset : ObservableObject, IDataErrorInfo, IXmlSerializable { - private string name; + private string shortName; + private OutputType outputType; private List inputTypes; private InputPostConversionAction inputPostConversionAction; @@ -28,12 +29,12 @@ namespace FileConverter public ConversionPreset() { - this.Name = Properties.Resources.DefaultPresetName; + this.FullName = Properties.Resources.DefaultPresetName; } - public ConversionPreset(string name, OutputType outputType, params string[] inputTypes) + public ConversionPreset(string fullName, OutputType outputType, params string[] inputTypes) { - this.Name = name; + this.FullName = fullName; this.OutputType = outputType; List inputTypeList = new List(); inputTypeList.AddRange(inputTypes); @@ -42,9 +43,9 @@ namespace FileConverter this.outputFileNameTemplate = "(p)(f)"; } - public ConversionPreset(string name, ConversionPreset source, params string[] additionalInputTypes) + public ConversionPreset(string fullName, ConversionPreset source, params string[] additionalInputTypes) { - this.Name = name; + this.FullName = fullName; this.OutputType = source.outputType; List inputTypeList = new List(); if (source.inputTypes != null) @@ -67,22 +68,61 @@ namespace FileConverter } } - - [XmlAttribute] - public string Name + [XmlAttribute("Name")] + public string FullName { get { - return this.name; + string fullName = string.Empty; + if (this.ParentFoldersNames != null) + { + foreach (string folder in this.ParentFoldersNames) + { + fullName += $"{folder}/"; + } + } + + fullName += this.shortName; + + return fullName; } set { - this.name = value; + string[] folders = value.Split('/'); + if (folders.Length == 0) + { + Diagnostics.Debug.Log("Invalid full name."); + this.ShortName = value; + return; + } + + this.ShortName = folders[folders.Length - 1]; + Array.Resize(ref folders, folders.Length - 1); + + this.ParentFoldersNames = folders; + } + } + + [XmlIgnore] + public string ShortName + { + get => this.shortName; + + set + { + this.shortName = value; this.RaisePropertyChanged(); } } + [XmlIgnore] + public string[] ParentFoldersNames + { + get; + private set; + } + [XmlAttribute] public OutputType OutputType { @@ -551,20 +591,25 @@ namespace FileConverter // Return error message if there is an error, else return empty or null string. switch (propertyName) { - case "Name": + case "ShortName": { - if (string.IsNullOrEmpty(this.Name)) + if (string.IsNullOrEmpty(this.ShortName)) { return "The preset name can't be empty."; } - if (this.Name.Contains(";")) + if (this.ShortName.Contains(";")) { return "The preset name can't contains the character ';'."; } + if (this.ShortName.Contains("/")) + { + return "The preset name can't contains the character '/'."; + } + ISettingsService settingsService = SimpleIoc.Default.GetInstance(); - int? count = settingsService.Settings?.ConversionPresets?.Count(match => match?.name == this.Name); + int? count = settingsService.Settings?.ConversionPresets?.Count(match => match?.shortName == this.ShortName); if (count > 1) { return "The preset name is already used."; diff --git a/Application/FileConverter/Services/SettingsService.cs b/Application/FileConverter/Services/SettingsService.cs index de4b0eb..c2d63e5 100644 --- a/Application/FileConverter/Services/SettingsService.cs +++ b/Application/FileConverter/Services/SettingsService.cs @@ -451,7 +451,7 @@ namespace FileConverter.Services registryEntries.Add(inputType, new List()); } - registryEntries[inputType].Add(conversionPreset.Name); + registryEntries[inputType].Add(conversionPreset.FullName); } } diff --git a/Application/FileConverter/Settings.cs b/Application/FileConverter/Settings.cs index 48a6b56..ca1fa1f 100644 --- a/Application/FileConverter/Settings.cs +++ b/Application/FileConverter/Settings.cs @@ -52,7 +52,7 @@ namespace FileConverter public ConversionPreset GetPresetFromName(string presetName) { - return this.conversionPresets.FirstOrDefault(match => match.Name == presetName); + return this.conversionPresets.FirstOrDefault(match => match.FullName == presetName); } public void Clean() @@ -73,7 +73,7 @@ namespace FileConverter for (int index = 0; index < settings.conversionPresets.Count; index++) { ConversionPreset conversionPreset = settings.conversionPresets[index]; - if (this.conversionPresets.Any(match => match.Name == conversionPreset.Name)) + if (this.conversionPresets.Any(match => match.FullName == conversionPreset.FullName)) { continue; }