Exemple #1
0
 /// <summary>
 /// タグ情報を再読み込みします。
 /// </summary>
 /// <param name="path">ファイル名</param>
 /// <param name="tag">タグ</param>
 public static void ReloadTagInfo(TagInfo tag)
 {
     lock (Native.SyncRoot)
     {
         // 各プロパティのValueNameAttributeを見て読み込む。
         LoadFile(tag.Path);
         PropertyInfo[] properties = tag.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
         foreach (var p in properties)
         {
             ValueNameAttribute vna = Attribute.GetCustomAttribute(p, typeof(ValueNameAttribute)) as ValueNameAttribute;
             if (vna != null)
             {
                 IntPtr ptr;
                 if (Native.GetValue(vna.ValueName, out ptr))
                 {
                     p.GetSetMethod(true).Invoke(tag, new object[] { Marshal.PtrToStringAnsi(ptr) });
                 }
             }
         }
     }
 }
Exemple #2
0
        public override string ToString()
        {
            PropertyInfo[] properties   = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            List <string>  propertyList = new List <string>();

            foreach (var p in properties)
            {
                ValueNameAttribute vna = Attribute.GetCustomAttribute(p, typeof(ValueNameAttribute)) as ValueNameAttribute;
                if (vna != null && p.GetValue(this, null).ToString() != "")
                {
                    propertyList.Add("" + p.Name + "=\"" + p.GetValue(this, null).ToString() + "\", ");
                }
            }

            StringBuilder sb = new StringBuilder();

            propertyList.Sort();
            foreach (string s in propertyList)
            {
                sb.Append(s);
            }
            return("{ " + sb.ToString() + " }");
        }
Exemple #3
0
        /// <summary>
        /// タグ情報を保存します。
        /// </summary>
        /// <param name="tag">タグ</param>
        /// <param name="unicode">Unicode形式で保存するか? false: ANSI</param>
        public static void SaveTagInfo(TagInfo tag, bool unicode)
        {
            if (tag is TagInfo.Unknown)
            {
                throw new MP3Infp.Mp3infpException("タグの種類が不明なため保存できません。\nMP3ファイルの場合は、ファイルがタグを含むかどうかを確認し、もしタグを持たない場合はあらかじめAddMP3Tagで作成します。");
            }

            int error = 0;

            lock (Native.SyncRoot)
            {
                LoadFile(tag.Path);
                Native.SetConf("mp3_ID3v2Unicode", unicode ? "1" : "0");
                Native.SetConf("mp3_ID3v2Unsync", !unicode ? "1" : "0");

                // 各プロパティのValueNameAttributeを見て書き込む。
                PropertyInfo[] properties = tag.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
                foreach (var p in properties)
                {
                    ValueNameAttribute vna = Attribute.GetCustomAttribute(p, typeof(ValueNameAttribute)) as ValueNameAttribute;
                    if (vna != null && p.GetSetMethod() != null)
                    {
                        Native.SetValue(vna.ValueName, p.GetValue(tag, null).ToString());
                    }
                }

                error = Native.Save(tag.Path);
            }
            if (error > 0)
            {
                throw new System.ComponentModel.Win32Exception(error);
            }
            if (error < 0)
            {
                throw new MP3Infp.Mp3infpException("タグの保存中にエラーが発生しました。");
            }
        }