示例#1
0
 public bool WriteTag(Id3Tag tag, int majorVersion, int minorVersion,
                      WriteConflictAction conflictAction = WriteConflictAction.NoAction)
 {
     tag.MajorVersion = majorVersion;
     tag.MinorVersion = minorVersion;
     return(WriteTag(tag, conflictAction));
 }
示例#2
0
        public bool WriteTag(Id3Tag tag, WriteConflictAction conflictAction = WriteConflictAction.NoAction)
        {
            EnsureWritePermissions(Id3Messages.NoWritePermissions_CannotWriteTag);
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }

            //The tag should specify major version number
            if (tag.MajorVersion == 0)
            {
                throw new ArgumentException(Id3Messages.MajorTagVersionMissing, "tag");
            }

            //Get any existing handlers from the same family as the tag
            IEnumerable <RegisteredId3Handler> familyHandlers = ExistingHandlers.GetHandlers(tag.Family);

            //If a tag already exists from the same family, but is a different version than the passed tag,
            //delete it if conflictAction is Replace.
            RegisteredId3Handler familyHandler = familyHandlers.FirstOrDefault();

            if (familyHandler != null)
            {
                Id3Handler handler = familyHandler.Handler;
                if (handler.MajorVersion != tag.MajorVersion || handler.MinorVersion != tag.MinorVersion)
                {
                    if (conflictAction == WriteConflictAction.NoAction)
                    {
                        return(false);
                    }
                    if (conflictAction == WriteConflictAction.Replace)
                    {
                        Id3Handler handlerCopy = handler;
                        handlerCopy.DeleteTag(_stream);
                    }
                }
            }

            //Write the tag to the file. The handler will know how to overwrite itself.
            RegisteredId3Handler registeredHandler = RegisteredHandlers.GetHandler(tag.MajorVersion, tag.MinorVersion);
            bool writeSuccessful = registeredHandler.Handler.WriteTag(_stream, tag);

            if (writeSuccessful)
            {
                InvalidateExistingHandlers();
            }
            return(writeSuccessful);
        }
示例#3
0
        public bool WriteTag(Id3Tag tag, WriteConflictAction conflictAction = WriteConflictAction.NoAction)
        {
            if (tag == null)
            {
                throw new ArgumentNullException(nameof(tag));
            }

            EnsureWritePermissions(Mp3Messages.NoWritePermissions_CannotWriteTag);

            //If a tag already exists from the same family, but is a different version than the passed tag,
            //delete it if conflictAction is Replace.
            Id3Handler familyHandler = ExistingHandlers.FirstOrDefault(handler => handler.Family == tag.Family);

            if (familyHandler != null)
            {
                Id3Handler handler = familyHandler;
                if (handler.Version != tag.Version)
                {
                    if (conflictAction == WriteConflictAction.NoAction)
                    {
                        return(false);
                    }
                    if (conflictAction == WriteConflictAction.Replace)
                    {
                        Id3Handler handlerCopy = handler; //TODO: Why did we need a copy of the handler?
                        handlerCopy.DeleteTag(Stream);
                    }
                }
            }

            //Write the tag to the file. The handler will know how to overwrite itself.
            Id3Handler writeHandler    = Id3Handler.GetHandler(tag.Version);
            bool       writeSuccessful = writeHandler.WriteTag(Stream, tag);

            if (writeSuccessful)
            {
                InvalidateExistingHandlers();
            }
            return(writeSuccessful);
        }
 public bool WriteTag(Id3Tag tag, int majorVersion, int minorVersion, WriteConflictAction conflictAction = WriteConflictAction.NoAction)
 {
     return(false);
 }
 public bool WriteTag(Id3Tag tag, WriteConflictAction conflictAction = WriteConflictAction.NoAction)
 {
     return(false);
 }
示例#6
0
 public bool WriteTag(Id3Tag tag, Id3Version version,
                      WriteConflictAction conflictAction = WriteConflictAction.NoAction)
 {
     tag.Version = version;
     return(WriteTag(tag, conflictAction));
 }