From 5bbd3a4a1cf3779285f6d3dce5fd969c9f327bc8 Mon Sep 17 00:00:00 2001 From: Zeugma440 Date: Mon, 10 Aug 2020 20:29:07 +0200 Subject: [PATCH] Fall back to the first supported metadata format if none of the selected formats is able to write to the file --- ATL/AudioData/AudioDataManager.cs | 20 ++++++++++++++++---- ATL/AudioData/AudioFileIO.cs | 12 ++++++++++-- ATL/AudioData/MetaDataIOFactory.cs | 14 ++++++++++++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/ATL/AudioData/AudioDataManager.cs b/ATL/AudioData/AudioDataManager.cs index 8d24c8ea..a91e27a3 100644 --- a/ATL/AudioData/AudioDataManager.cs +++ b/ATL/AudioData/AudioDataManager.cs @@ -124,10 +124,22 @@ public IList getAvailableMetas() { IList result = new List(); - if (hasMeta(MetaDataIOFactory.TAG_ID3V1)) result.Add(MetaDataIOFactory.TAG_ID3V1); - if (hasMeta(MetaDataIOFactory.TAG_ID3V2)) result.Add(MetaDataIOFactory.TAG_ID3V2); - if (hasMeta(MetaDataIOFactory.TAG_APE)) result.Add(MetaDataIOFactory.TAG_APE); - if (hasMeta(MetaDataIOFactory.TAG_NATIVE)) result.Add(MetaDataIOFactory.TAG_NATIVE); + foreach(int tagType in Enum.GetValues(typeof(MetaDataIOFactory.TagType))) + { + if (hasMeta(tagType)) result.Add(tagType); + } + + return result; + } + + public IList getSupportedMetas() + { + IList result = new List(); + + foreach (int tagType in Enum.GetValues(typeof(MetaDataIOFactory.TagType))) + { + if (audioDataIO.IsMetaSupported(tagType)) result.Add(tagType); + } return result; } diff --git a/ATL/AudioData/AudioFileIO.cs b/ATL/AudioData/AudioFileIO.cs index a238af48..2cddf8b2 100644 --- a/ATL/AudioData/AudioFileIO.cs +++ b/ATL/AudioData/AudioFileIO.cs @@ -83,13 +83,20 @@ public AudioFileIO(Stream stream, String mimeType, bool readEmbeddedPictures, bo public void Save(TagData data) { IList availableMetas = audioManager.getAvailableMetas(); + IList supportedMetas = audioManager.getSupportedMetas(); + // File has no existing metadata + // => Try writing with one of the metas set in the Settings if (0 == availableMetas.Count) { foreach (int i in Settings.DefaultTagsWhenNoMetadata) { - availableMetas.Add(i); + if (supportedMetas.Contains(i)) availableMetas.Add(i); } + + // File does not support any of the metas we want to write + // => Use the first supported meta available + if (0 == availableMetas.Count && supportedMetas.Count > 0) availableMetas.Add(supportedMetas[0]); } float written = 0; @@ -108,7 +115,8 @@ public void Remove(int tagType = MetaDataIOFactory.TAG_ANY) if (MetaDataIOFactory.TAG_ANY == tagType) { metasToRemove = audioManager.getAvailableMetas(); - } else + } + else { metasToRemove = new List() { tagType }; } diff --git a/ATL/AudioData/MetaDataIOFactory.cs b/ATL/AudioData/MetaDataIOFactory.cs index 1f27016d..4f354a68 100644 --- a/ATL/AudioData/MetaDataIOFactory.cs +++ b/ATL/AudioData/MetaDataIOFactory.cs @@ -17,8 +17,18 @@ public class MetaDataIOFactory // Count of the types defined above, excluding "any" type public static readonly int TAG_TYPE_COUNT = 4; - // Defines the default reading priority of the metadata - private int[] tagPriority; + public enum TagType + { + ID3V1 = TAG_ID3V1, + ID3V2 = TAG_ID3V2, + APE = TAG_APE, + NATIVE = TAG_NATIVE, + ANY = TAG_ANY + } + + + // Defines the default reading priority of the metadata + private int[] tagPriority; // Defines whether the next created metadatareaders should use cross-tag reading private bool m_enableCrossReading = true;