importcontactsfromvcard.cs

来自「破解的飞信源代码」· CS 代码 · 共 74 行

CS
74
字号
namespace Imps.Client.Pc
{
    using Imps.Common;
    using System;
    using System.IO;
    using System.Text;
    using System.Windows.Forms;

    internal class ImportContactsFromVcard : IImportContacts
    {
        private ImportContactType _type;

        public string GetContactsXML(IWin32Window owner, string filePath)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<Contacts>");
            using (StreamReader reader = new StreamReader(filePath, Encoding.Default, true))
            {
                string text;
                if (!reader.ReadLine().ToUpper().Contains("BEGIN:VCARD"))
                {
                    throw new NotSupportedException();
                }
                string text2 = "";
                string text3 = "";
                string text4 = "";
                while ((text = reader.ReadLine()) != null)
                {
                    if (text.StartsWith("TEL;CELL;VOICE:"))
                    {
                        text2 = text.Replace("TEL;CELL;VOICE:", "");
                    }
                    if (text.StartsWith("FN"))
                    {
                        string[] textArray = text.Split(new char[] { ':' });
                        text3 = textArray[textArray.Length - 1];
                    }
                    if (text.StartsWith("NICKNAME:"))
                    {
                        text4 = text.Replace("NICKNAME:", "");
                    }
                }
                if (text2 != "")
                {
                    builder.Append("<Contact>");
                    builder.Append(string.Format("<MobileNo>{0}</MobileNo>", text2));
                    builder.Append(string.Format("<Name>{0}</Name>", text3));
                    builder.Append(string.Format("<Nickname>{0}</Nickname>", text4));
                    builder.Append("</Contact>");
                }
            }
            builder.Append("</Contacts>");
            return builder.ToString();
        }

        public string Filter
        {
            get
            {
                return "vcf files (*.vcf)|*.vcf";
            }
        }

        public ImportContactType Type
        {
            get
            {
                return ImportContactType.VCard;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?