Пример #1
0
        /// <summary>
        /// Write all frames to specific TagStream
        /// </summary>
        /// <param name="writer">TagStream to write data to</param>
        /// <param name="Ver">Minor Version of ID3</param>
        private void WriteFrames(int Ver)
        {
            foreach (FrameCollectionBase Coll in _CollectionFrames.Values)
            {
                if (Coll.Name != CollectionIndex.Unknown.ToString() ||
                    (Coll.Name == CollectionIndex.Unknown.ToString() && !_DropUnknown))
                {
                    foreach (Frame Fr in Coll)
                    {
                        // If Frame is not valid and is not UserTextFrame we ignore it
                        if (!FramesInfo.IsCompatible(Fr.FrameID, Ver) && FramesInfo.IsTextFrame(Fr.FrameID, Ver) != 2)
                        {
                            AddError(new ID3Exception("nonCompatible Frame found on Frames and will not save with file", Fr.FrameID, ExceptionLevels.Warning));
                            continue;
                        }

                        if (Fr.IsValid)
                        {
                            Fr.WriteData(Ver);
                        }
                    }
                }
            }

            foreach (Frame Fr in _SingleFrames.Values)
            {
                if (FramesInfo.IsCompatible(Fr.FrameID, Ver) && Fr.IsValid)
                {
                    Fr.WriteData(Ver);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Create new TextFrame with specific information
        /// </summary>
        /// <param name="Text">Text of TextFrame</param>
        /// <param name="TextEncoding">TextEncoding of TextFrame</param>
        /// <param name="FrameID">FrameID of TextFrame</param>
        /// <param name="Flags">Flags of Frame</param>
        public TextFrame(string FrameID, FrameFlags Flags, string Text, TextEncodings TextEncoding,
                         int Ver)
            : base(FrameID, Flags)
        {
            if (FramesInfo.IsTextFrame(FrameID, Ver) != 1)
            {
                throw (new ArgumentException(FrameID + " is not valid TextFrame FrameID"));
            }

            this.Text         = Text;
            this.TextEncoding = TextEncoding;
        }
Пример #3
0
        /// <summary>
        /// Create new UserTextFrame from specific information
        /// </summary>
        /// <param name="FrameID">FrameID of frame</param>
        /// <param name="Flags">Frame flags</param>
        /// <param name="Text">Frame text</param>
        /// <param name="Description">Frame description</param>
        /// <param name="TextEncoding">TextEncoding of texts</param>
        /// <param name="Ver">Minor version of ID3v2</param>
        public UserTextFrame(string FrameID, FrameFlags Flags, string Text,
                             string Description, TextEncodings TextEncoding, int Ver)
            : base(FrameID, Flags)
        {
            if (FramesInfo.IsTextFrame(FrameID, Ver) != 2)
            {
                throw (new ArgumentException(FrameID + " is not valid for UserTextFrame class"));
            }

            this.Text         = Text;
            this.TextEncoding = TextEncoding;
            this.Description  = Description;
        }
Пример #4
0
        /// <summary>
        /// Add Frame information to where it must store
        /// </summary>
        /// <param name="Data">FileStream contain Frame</param>
        /// <param name="FrameID">FrameID of frame</param>
        /// <param name="Length">Maximum available length to read</param>
        /// <param name="Flags">Flags of frame</param>
        private bool AddFrame(string FrameID, int Length, FrameFlags Flags, Stream FS)
        {
            // NOTE: All FrameIDs must be capital letters
            if (!FramesInfo.IsValidFrameID(FrameID))
            {
                AddError(new ID3Exception("nonValid Frame found and dropped", FrameID, ExceptionLevels.Repaired));
                return(false);
            }

            int IsText = FramesInfo.IsTextFrame(FrameID, _Version.Minor);

            if (IsText == 1)
            {
                TextFrame TempTextFrame = new TextFrame(FrameID, Flags, Length, FS);
                if (TempTextFrame.IsValid && !TextFrames.ContainsKey(FrameID))
                {
                    TextFrames.Add(FrameID, TempTextFrame);
                    return(true);
                }
                return(false);
            }
            else if (IsText == 2)
            {
                UserTextFrame TempUserTextFrame = new UserTextFrame(FrameID, Flags, Length, FS);
                if (TempUserTextFrame.IsValid && FrameID != "TXXX" && !UserTextFrames.ContainsKey(FrameID))
                {
                    UserTextFrames.Add(FrameID, TempUserTextFrame);
                    return(true);
                }
                return(false);
            }
            else if (FrameID == "LINK")
            {
                LinkFrame LF = new LinkFrame(FrameID, Flags, Length, FS);
                if (LF.IsValid && !LinkFrames.ContainsKey(FrameID))
                {
                    LinkFrames.Add(FrameID, LF);
                    if (_LoadLinkedFrames)
                    {
                        LoadFrameFromFile(LF.FrameIdentifier, LF.URL); return(true);
                    }
                }
                else
                {
                    AddError(LF.Exception);
                }
            }

            Frame F = null;

            if (!FramesInfo.ExcludedList.Any(t => t == FrameID))
            {
                FrameInfo Info = FramesInfo.GetFrame(FrameID);

                if (Info == null || Info.ClassType == null)
                {
                    AddError(new ID3Exception("Unknown Frame found and dropped according to setting", FrameID, ExceptionLevels.Warning));
                    return(true);
                }

                try
                {
                    F = Info.Constuctor(FrameID, Flags, Length, TStream.FS);
                }
                catch { }
                try
                {
                    if (Info.IsSingle)
                    {
                        if (_SingleFrames.Contains(FrameID))
                        {
                            _SingleFrames.Remove(FrameID);
                        }

                        _SingleFrames.Add(FrameID, F);
                        return(true);
                    }
                    else
                    {
                        foreach (FrameCollectionBase Coll in _CollectionFrames.Values)
                        {
                            if (Coll.CollectionType == Info.ClassType)
                            {
                                Coll.Remove(F.FrameID);
                                Coll.Add(F.FrameID, F);
                                return(true);
                            }
                        }
                    }
                    AddError(new ID3Exception("ClassType not found in Collection list", FrameID, ExceptionLevels.Error));
                }
                catch {}
            }

            return(false);
        }