Exemplo n.º 1
0
        /// <summary>
        /// Set text of specific TextFrame
        /// </summary>
        /// <param name="FrameID">FrameID</param>
        /// <param name="Text">Text to set</param>
        public void SetTextFrame(string FrameID, string Text)
        {
            if (!FramesInfo.IsValidFrameID(FrameID))
            {
                return;
            }

            TextFrame[] TF = TextFrames.ToArray();
            for (int i = 0; i < TextFrames.Count - 1; i++)
            {
                if (TF[i].FrameID == FrameID)
                {
                    TextFrames.RemoveAt(i);
                    break;
                }
            }

            if (Text != "")
            {
                HaveTag = true;
                TextFrames.Add(FrameID, new TextFrame(FrameID, new FrameFlags(),
                                                      Text, (StaticMethods.IsAscii(Text) ? TextEncodings.Ascii : _DefaultUnicodeEncoding),
                                                      _Version.Minor, TStream.FS));
            }
        }
Exemplo n.º 2
0
        protected bool ValidatingFrameID(string FrameIdentifier, ValidatingErrorTypes ErrorType)
        {
            bool IsValid = FramesInfo.IsValidFrameID(FrameIdentifier);

            if (!IsValid)
            {
                if (ErrorType == ValidatingErrorTypes.Exception)
                {
                    throw (new ArgumentException("FrameID must be 4 capital letters"));
                }
                else if (ErrorType == ValidatingErrorTypes.ID3Error)
                {
                    ErrorOccur(FrameIdentifier + " is not valid FrameID", true);
                }
            }

            return(IsValid);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Indicate is specific FrameID valid or not
        /// </summary>
        /// <param name="FrameIdentifier">FrameID to check</param>
        /// <param name="ErrorType">Error type that must occur if frame identifier was not valid</param>
        /// <returns>true if frame identifer was valid otherwise false</returns>
        protected bool ValidatingFrameID(string FrameIdentifier, ExceptionLevels ErrorType)
        {
            bool IsValid = FramesInfo.IsValidFrameID(FrameIdentifier);

            if (!IsValid)
            {
                ID3Exception Ex = new ID3Exception(FrameIdentifier + " is not valid FrameID", FrameIdentifier, ErrorType);
                if (ErrorType == ExceptionLevels.Error)
                {
                    throw Ex;
                }
                else if (ErrorType == ExceptionLevels.Error)
                {
                    ExceptionOccured(Ex);
                }
            }

            return(IsValid);
        }
Exemplo n.º 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);
        }