/// <summary> /// Creates a deep copy of the current instance. /// </summary> /// <returns> /// A new <see cref="Frame" /> object identical to the /// current instance. /// </returns> /// <remarks> /// This method is implemented by rendering the current /// instance as an ID3v2.4 frame and using <see /// cref="FrameFactory.CreateFrame" /> to create a new /// frame. As such, this method should be overridden by /// child classes. /// </remarks> public virtual Frame Clone() { int index = 0; return(FrameFactory.CreateFrame(Render(4), null, ref index, 4, false)); }
protected void Parse(ByteVector data) { if (data == null) { throw new ArgumentNullException("data"); } bool fullTagUnsynch = (header.MajorVersion < 4) && ((header.Flags & HeaderFlags.Unsynchronisation) != 0); if (fullTagUnsynch) { SynchData.ResynchByteVector(data); } int frame_data_position = 0; int frame_data_length = data.Count; if ((header.Flags & HeaderFlags.ExtendedHeader) != 0) { extended_header = new ExtendedHeader(data, header.MajorVersion); if (extended_header.Size <= data.Count) { frame_data_position += (int)extended_header.Size; frame_data_length -= (int)extended_header.Size; } } TextInformationFrame tdrc = null; TextInformationFrame tyer = null; TextInformationFrame tdat = null; TextInformationFrame time = null; while (frame_data_position < frame_data_length - FrameHeader.Size(header.MajorVersion)) { if (data[frame_data_position] == 0) { break; } Frame frame = null; try { frame = FrameFactory.CreateFrame(data, ref frame_data_position, header.MajorVersion, fullTagUnsynch); } catch (NotImplementedException) { continue; } catch (CorruptFileException) { continue; } if (frame == null) { break; } if (frame.Size == 0) { continue; } AddFrame(frame); if (header.MajorVersion == 4) { continue; } if (tdrc == null && frame.FrameId.Equals(FrameType.TDRC)) { tdrc = frame as TextInformationFrame; } else if (tyer == null && frame.FrameId.Equals(FrameType.TYER)) { tyer = frame as TextInformationFrame; } else if (tdat == null && frame.FrameId.Equals(FrameType.TDAT)) { tdat = frame as TextInformationFrame; } else if (time == null && frame.FrameId.Equals(FrameType.TIME)) { time = frame as TextInformationFrame; } } if (tdrc == null || tdat == null || tdrc.ToString().Length > 4) { return; } string year = tdrc.ToString(); if (year.Length != 4) { return; } StringBuilder tdrc_text = new StringBuilder(); tdrc_text.Append(year); if (tdat != null) { string tdat_text = tdat.ToString(); if (tdat_text.Length == 4) { tdrc_text.Append("-").Append(tdat_text, 0, 2).Append("-").Append(tdat_text, 2, 2); if (time != null) { string time_text = time.ToString(); if (time_text.Length == 4) { tdrc_text.Append("T").Append(time_text, 0, 2).Append(":").Append(time_text, 2, 2); } RemoveFrames(FrameType.TIME); } } RemoveFrames(FrameType.TDAT); } tdrc.Text = new string[] { tdrc_text.ToString() }; }