/// <summary> /// Looks for a tag starting at a specified position and moves /// the cursor to its start position. /// </summary> /// <param name="position"> /// A <see cref="long" /> value reference specifying at what /// position the potential tag starts. If a tag is found, /// this value will be updated to the position at which the /// found tag ends. /// </param> /// <returns> /// A <see cref="TagLib.TagTypes" /> value specifying the /// type of tag found at the specified position, or <see /// cref="TagTypes.None" /> if no tag was found. /// </returns> TagTypes ReadTagInfo(ref long position) { file.Seek(position); ByteVector data = file.ReadBlock(read_size); try { if (data.StartsWith(Ape.Footer.FileIdentifier)) { Ape.Footer footer = new Ape.Footer(data); position += footer.CompleteTagSize; return(TagTypes.Ape); } if (data.StartsWith(Id3v2.Header.FileIdentifier)) { Id3v2.Header header = new Id3v2.Header(data); position += header.CompleteTagSize; return(TagTypes.Id3v2); } } catch (CorruptFileException) { } return(TagTypes.None); }
/// <summary> /// Looks for a tag ending at a specified position and moves /// the cursor to its start position. /// </summary> /// <param name="position"> /// A <see cref="long" /> value reference specifying at what /// position the potential tag ends. If a tag is found, /// this value will be updated to the position at which the /// found tag starts. /// </param> /// <returns> /// A <see cref="TagLib.TagTypes" /> value specifying the /// type of tag found at the specified position, or <see /// cref="TagTypes.None" /> if no tag was found. /// </returns> TagTypes ReadTagInfo(ref long position) { if (position - read_size < 0) { return(TagTypes.None); } file.Seek(position - read_size); ByteVector data = file.ReadBlock(read_size); try { int offset = (int)(data.Count - Ape.Footer.Size); if (data.ContainsAt(Ape.Footer.FileIdentifier, offset)) { Ape.Footer footer = new Ape.Footer(data.Mid(offset)); // If the complete tag size is zero or // the tag is a header, this indicates // some sort of corruption. if (footer.CompleteTagSize == 0 || (footer.Flags & Ape.FooterFlags.IsHeader) != 0) { return(TagTypes.None); } position -= footer.CompleteTagSize; return(TagTypes.Ape); } offset = (int)(data.Count - Id3v2.Footer.Size); if (data.ContainsAt(Id3v2.Footer.FileIdentifier, offset)) { var footer = new Id3v2.Footer(data.Mid(offset)); position -= footer.CompleteTagSize; return(TagTypes.Id3v2); } if (data.StartsWith(Id3v1.Tag.FileIdentifier)) { position -= Id3v1.Tag.Size; return(TagTypes.Id3v1); } } catch (CorruptFileException) { } return(TagTypes.None); }