/// <summary>
 /// 下载消息文件
 /// </summary>
 /// <param name="mMessage">消息</param>
 /// <param name="progress">进度回调</param>
 /// <param name="complite">完成回调</param>
 public void downloadFileAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
 {
     new Thread(new ThreadStart(() =>
     {
         if (mMessage.bodies().Length < 1)
         {
             return;
         }
         if (mMessage.bodies()[0].type == EMMessageBodyType.IMAGE)
         {
             downloadImageMainAttchment(mMessage, progress, complite);
         }
         else if (mMessage.bodies()[0].type == EMMessageBodyType.VIDEO)
         {
             downloadVideoMainAttchment(mMessage, progress, complite);
         }
         else if (mMessage.bodies()[0].type == EMMessageBodyType.FILE)
         {
             downloadFileMainAttchment(mMessage, progress, complite);
         }
     })).Start();
 }
        private void downloadVideoMainAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
        {
            EMVideoMessageBody body = mMessage.bodies()[0] as EMVideoMessageBody;

            body.setDownloadStatus(EMDownloadStatus.DOWNLOADING);
            mMessage.clearBodies();
            mMessage.addBody(body);
            var conversation = EaseHelper.shard.client.getChatManager().conversationWithType(mMessage.conversationId(), DCUtilTool.GetMConversationType(mMessage.chatType()), true);

            conversation.updateMessage(mMessage);
            string dir = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\Changliao" + "\\ChangLiao\\" + SettingMenager.shard.idCard;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string path = dir + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".mp4";

            HttpUitls.Instance.DownloadFile(body.remotePath(), path, (p) =>
            {
                Console.WriteLine(p);
                if (progress != null)
                {
                    progress(p);
                }
            }, (b) =>
            {
                if (b)
                {
                    var fi = new FileInfo(path);
                    body.setFileLength(fi.Length);
                    body.setLocalPath(path);
                    body.setDownloadStatus(EMDownloadStatus.SUCCESSED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
                else
                {
                    body.setDownloadStatus(EMDownloadStatus.FAILED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
            });
        }
 /// <summary>
 /// 下载消息文件
 /// </summary>
 /// <param name="mMessage">消息</param>
 /// <param name="complite">完成回调</param>
 public void downloadFileAttchment(EMMessage mMessage, DownloadMessageAttchmentComplite complite)
 {
     downloadFileAttchment(mMessage, null, complite);
 }
        private void downloadFileMainAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
        {
            EMFileMessageBody body = mMessage.bodies()[0] as EMFileMessageBody;

            body.setDownloadStatus(EMDownloadStatus.DOWNLOADING);
            mMessage.clearBodies();
            mMessage.addBody(body);
            var conversation = EaseHelper.shard.client.getChatManager().conversationWithType(mMessage.conversationId(), DCUtilTool.GetMConversationType(mMessage.chatType()), true);

            conversation.updateMessage(mMessage);
            string dir = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\Changliao" + "\\ChangLiao\\" + SettingMenager.shard.idCard;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string path = dir + "\\" + body.displayName();
            var    p    = path;
            int    i    = 0;

            while (File.Exists(p))
            {
                i += 1;
                var arr = path.Split('.');
                if (arr.Length > 2)
                {
                    p = "";
                    for (int j = 0; j < arr.Length - 1; j++)
                    {
                        p += arr[j];
                    }
                    p = p + "(" + i + ")." + arr[arr.Length - 1];
                }
                else if (arr.Length == 2)
                {
                    p = arr[0] + "(" + i + ")." + arr[1];
                }
                else
                {
                    p = path + "(" + i + ")";
                }
            }
            HttpUitls.Instance.DownloadFile(body.remotePath(), p, (p1) =>
            {
                if (progress != null)
                {
                    progress(p1);
                }
            }, (b) =>
            {
                if (b)
                {
                    var fi = new FileInfo(path);
                    body.setFileLength(fi.Length);
                    body.setLocalPath(path);
                    body.setDownloadStatus(EMDownloadStatus.SUCCESSED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
                else
                {
                    body.setDownloadStatus(EMDownloadStatus.FAILED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
            });
        }