private void downloadImageMainAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite) { EMImageMessageBody body = mMessage.bodies()[0] as EMImageMessageBody; 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") + ".jpg"; HttpUitls.Instance.DownloadFile(body.remotePath(), path, (p) => { if (progress != null) { progress(p); } }, (b) => { if (b) { var fi = new FileInfo(path); body.setFileLength(fi.Length); body.setLocalPath(path); Image image = Image.FromFile(path); body.setSize(new EMImageMessageBody.Size((double)image.Width, (double)image.Height)); body.setDownloadStatus(EMDownloadStatus.SUCCESSED); conversation.updateMessage(mMessage); complite(mMessage); } else { body.setDownloadStatus(EMDownloadStatus.FAILED); conversation.updateMessage(mMessage); complite(mMessage); } }); }
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); } }); }