Ejemplo n.º 1
0
        /// <summary>
        /// Remove a tag from the file.
        /// This command writes to disk.
        /// </summary>
        /// <param name="TagName">
        /// A <see cref="System.String"/> indicating which tag to remove
        /// </param>
        /// <returns>
        /// An <see cref="OggTagWriteCommandReturn"/> indicating the result of the operation
        /// </returns>
        public OggTagWriteCommandReturn RemoveTag(string TagName)
        {
            // Check that the tag name contains at least one character
            if (TagName.Length < 1)
            {
                return(OggTagWriteCommandReturn.UnknownTag);
            }
            XiphComment XC = (XiphComment)m_TagLibFile.GetTag(TagTypes.Xiph, false);

            if (XC != null)
            {
                // Remove the tag
                XC.RemoveField(TagName);
                // Copy the XC instance into our file (might need to clear the Xiph block first, but we'll see)
                XC.CopyTo(m_TagLibFile.Tag, true);
                // Save
                m_TagLibFile.Save();
                return(OggTagWriteCommandReturn.Success);
            }
            else
            {
                // Either there isn't a Xiph comment block or something went wrong
                return(OggTagWriteCommandReturn.Error);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Write a single Xiph tag to the file
        /// This will overwrite the tag if it already exists, or create it if it doesn't
        /// It will also create the Xiph tag block within the file if it doesn't already have one
        /// This function writes to disk. If setting multiple tags consider using SetTags(OggTag[] Tags) to reduce the number of write operations
        /// If setting an array, Tag.Values must contain at least one item. Tag.Value is ignored in this case
        /// If setting a single value, Tag.Value must contain at least one character. Tag.Values is ignored in this case
        /// </summary>
        /// <param name="Tag">
        /// The <see cref="OggTag"/> to write
        /// </param>
        /// <returns>
        /// An <see cref="OggTagWriteCommandReturn"/> indicating the result of the operation
        /// </returns>
        public OggTagWriteCommandReturn SetTag(OggTag Tag)
        {
            // Validate Tag
            if (Tag.IsEmpty)
            {
                return(OggTagWriteCommandReturn.InvalidValue);
            }
            if (Tag.Name.Length <= 0)
            {
                return(OggTagWriteCommandReturn.UnknownTag);
            }
            if (Tag.IsArray)
            {
                if (Tag.Values.Length <= 0)
                {
                    return(OggTagWriteCommandReturn.InvalidValue);
                }
            }
            else
            {
                if (Tag.Value.Length <= 0)
                {
                    return(OggTagWriteCommandReturn.InvalidValue);
                }
            }
            // Tag valid, try and write it
            XiphComment XC = (XiphComment)m_TagLibFile.GetTag(TagTypes.Xiph, true);

            if (XC != null)
            {
                string[] tmpStrArray;
                if (Tag.IsArray)
                {
                    tmpStrArray = Tag.Values;
                }
                else
                {
                    tmpStrArray = new string[1]; tmpStrArray[0] = Tag.Value;
                }
                // Set field
                XC.SetField(Tag.Name, tmpStrArray);
                // Copy the XC instance into our file (not sure if this is needed)
                XC.CopyTo(m_TagLibFile.Tag, true);
                // Commit
                m_TagLibFile.Save();
                return(OggTagWriteCommandReturn.Success);
            }
            else
            {
                // If we're null something went wrong (we tried to create the XiphComment block and it failed probably)
                return(OggTagWriteCommandReturn.Error);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Write multiple Xiph tags to the file
        /// This will overwrite any existing tags, and create them if they don't exist
        /// It will also create the Xiph tag block within the file if it doesn't already have one
        /// This function writes to disk. If setting only a single tag, consider using SetTag(OggTag Tag) to reduce the array handling overheads
        /// If setting an array value Tags[i].Values must contain at least one item. Tags[i].Value is ignored in this case
        /// If setting a single value, Tags[i].Value must contain at least one character. Tags[i].Values is ignored in this case
        /// If AbortOnError is true, this function will abort (and not write) if any item in the Tags array is invalid.
        /// If AbortOnError is false, this function will continue (and write) if items in the Tags array are invalid. It will still abort (and not write) if there are other errors.
        /// </summary>
        /// <param name="Tags">
        /// An <see cref="OggTag[]"/> containing the tags to be written
        /// </param>
        /// <param name="AbortOnError">
        /// A <see cref="System.bool"/> indicating whether to invalid items in the Tags array.
        /// <returns>
        /// An <see cref="OggTagWriteCommandReturn"/> indicating the result of the operation
        /// </returns>
        public OggTagWriteCommandReturn SetTags(OggTag[] Tags, bool AbortOnError)
        {
            // Check that the Tags array has at least one item in it
            if (Tags.Length < 1)
            {
                return(OggTagWriteCommandReturn.UnknownTag);
            }
            XiphComment XC = (XiphComment)m_TagLibFile.GetTag(TagTypes.Xiph, true);

            if (XC != null)
            {
                // Write the tags to the 'virtual' file
                foreach (OggTag Tag in Tags)
                {
                    // Validate tag
                    if (Tag.IsEmpty)
                    {
                        if (AbortOnError)
                        {
                            return(OggTagWriteCommandReturn.InvalidValue);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    if (Tag.Name.Length <= 0)
                    {
                        if (AbortOnError)
                        {
                            return(OggTagWriteCommandReturn.UnknownTag);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    if (Tag.IsArray)
                    {
                        if (Tag.Values.Length <= 0)
                        {
                            if (AbortOnError)
                            {
                                return(OggTagWriteCommandReturn.InvalidValue);
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    else
                    {
                        if (Tag.Value.Length <= 0)
                        {
                            if (AbortOnError)
                            {
                                return(OggTagWriteCommandReturn.InvalidValue);
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    string[] tmpStrArray;
                    if (Tag.IsArray)
                    {
                        tmpStrArray = Tag.Values;
                    }
                    else
                    {
                        tmpStrArray = new string[1]; tmpStrArray[0] = Tag.Value;
                    }
                    // Write tag
                    XC.SetField(Tag.Name, tmpStrArray);
                }
                // Copy the XC instance into our file (not sure if this is needed)
                XC.CopyTo(m_TagLibFile.Tag, true);
                // Save to disk
                m_TagLibFile.Save();
                return(OggTagWriteCommandReturn.Success);
            }
            else
            {
                // If we're null something went wrong (we tried to create the XiphComment block and it failed probably)
                return(OggTagWriteCommandReturn.Error);
            }
        }