Esempio n. 1
0
        void AndroidRun()
        {
            int maxCount = int.MaxValue;

            if (!softReg.GetIsReg())
            {
                maxCount = 10;
                MessageBox.Show("非注册用户暂时支持部分导出 \n如果导出全量信息请到https://www.weixinxqm.com/购买注册!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            var saveBase = savePathTextBox.Text;

            Directory.CreateDirectory(saveBase);
            AddLog("分析文件夹结构");
            AndroidWeChatInterface wechat = null;

            if (string.IsNullOrEmpty(resPathTextBox.Text))
            {
                wechat = new AndroidWeChatInterface(wechatPathTextBox.Text);
            }
            else
            {
                wechat = new AndroidWeChatInterface(wechatPathTextBox.Text, resPathTextBox.Text);
            }

            wechat.Init();
            AddLog("查找UID");
            var users = wechat.users;

            AddLog("找到" + users.Count + "个账号的消息记录");
            var uidList = new List <DisplayItem>();

            foreach (var user in users)
            {
                user.Init();
                AddLog("开始处理UID: " + user.uid);

                AddLog("打开数据库");
                if (!user.OpenMMSqlite())
                {
                    AddLog("无法打开数据库");
                    continue;
                }

                AddLog("读取账号信息");
                if (!user.GetUserBasics())
                {
                    AddLog("没有找到本人信息,用默认值替代");
                }

                Friend myself = user.myself;
                AddLog("微信号:" + myself.ID() + " 昵称:" + myself.DisplayName());

                AddLog("读取好友列表");
                if (!user.GetFriendsDict(out int friendcount))
                {
                    AddLog("获取好友列表失败,跳过");
                    continue;
                }
                if (!user.GetChatRoomMember(out int chatroomCount))
                {
                    AddLog("获取聊天室用户列表失败,跳过");
                    continue;
                }
                AddLog("找到" + (friendcount - chatroomCount) + "个好友");
                AddLog("找到" + chatroomCount + "个聊天室");

                AddLog("查找对话:");
                user.GetChatSessions(out List <string> chats);
                AddLog("找到" + chats.Count + "个对话");

                var userSaveBase = Path.Combine(saveBase, myself.ID());
                Directory.CreateDirectory(userSaveBase);
                user.userSaveDir = userSaveBase;

                AddLog("导出好友列表:");
                if (user.saveFriends(maxCount, out int exportCount))
                {
                    AddLog("导出" + exportCount + "个好友");
                }
                else
                {
                    AddLog("导出好友列表出错");
                }

                var emojidown = new HashSet <DownloadTask>();
                var chatList  = new List <DisplayItem>();

                if (htmlRadioButton.Checked)
                {
                    try
                    {
                        AddLog("复制头像:");
                        user.CopyResource();
                        File.Copy("res\\[email protected]", Path.Combine(userSaveBase, "avatar", "*****@*****.**"));
                    }
                    catch (Exception) { }
                }

                foreach (var chat in chats)
                {
                    string displayname = chat;
                    Friend friend      = user.GetFriend(chat);
                    if (friend != null)
                    {
                        displayname = friend.DisplayName();
                        AddLog("处理与" + displayname + "的对话");
                    }
                    else
                    {
                        AddLog("未找到好友信息,用默认名字代替");
                    }

                    if (textRadioButton.Checked)
                    {
                        if (user.SaveTextRecord(chat, maxCount, out int count))
                        {
                            AddLog("成功处理" + count + "条");
                        }
                        else
                        {
                            AddLog("失败");
                        }
                    }
                    else if (htmlRadioButton.Checked)
                    {
                        if (user.SaveHtmlRecord(chat, maxCount, out int count, out HashSet <DownloadTask> _emojidown))
                        {
                            AddLog("成功处理" + count + "条");
                            chatList.Add(new DisplayItem()
                            {
                                pic = "avatar/" + (friend != null ? friend.GetAndroidUserAvatar() : "*****@*****.**"), text = displayname, link = chat + ".html"
                            });
                        }
                        else
                        {
                            AddLog("失败");
                        }
                        emojidown.UnionWith(_emojidown);
                    }
                }

                if (htmlRadioButton.Checked)
                {
                    BaseWeChat.MakeListHTML(chatList, Path.Combine(userSaveBase, "聊天记录.html"));
                }

                var downloader = new Downloader(6);
                var emojidir   = Path.Combine(userSaveBase, "Emoji");
                Directory.CreateDirectory(emojidir);
                if (emojidown != null && emojidown.Count > 0)
                {
                    AddLog("下载" + emojidown.Count + "个表情");
                    foreach (var item in emojidown)
                    {
                        downloader.AddTask(item.url, Path.Combine(emojidir, item.filename));
                    }
                }
                uidList.Add(new DisplayItem()
                {
                    pic = myself.ID() + "/avatar/" + user.myself.GetAndroidUserAvatar(), text = myself.DisplayName(), link = myself.ID() + "/聊天记录.html"
                });
                downloader.StartDownload();
                downloader.WaitToEnd();

                AddLog("完成当前账号");
            }
Esempio n. 2
0
        private void IphoneRun()
        {
            int maxCount = int.MaxValue;

            if (!softReg.GetIsReg())
            {
                maxCount = 10;
                MessageBox.Show("非注册用户暂时支持部分导出 \n如果导出全量信息请到https://www.weixinxqm.com/购买注册!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            var saveBase = textBox1.Text;

            Directory.CreateDirectory(saveBase);
            AddLog("分析文件夹结构");
            IphoneWeChatInterface wechat = new IphoneWeChatInterface(((IPhoneBackup)comboBox1.SelectedItem).path, files92);

            wechat.BuildFilesDictionary();
            AddLog("查找UID");
            var UIDs = wechat.FindUIDs();

            AddLog("找到" + UIDs.Count + "个账号的消息记录");
            var uidList = new List <DisplayItem>();
            int delta   = 90 / ((UIDs.Count > 0 ? UIDs.Count : 1) * 5);

            foreach (var uid in UIDs)
            {
                var userBase = Path.Combine("Documents", uid);
                AddLog("开始处理UID: " + uid);
                AddLog("读取账号信息");
                if (wechat.GetUserBasics(uid, userBase, out Friend myself))
                {
                    AddLog("微信号:" + myself.ID() + " 昵称:" + myself.DisplayName());
                }
                else
                {
                    AddLog("没有找到本人信息,用默认值替代");
                }
                var userSaveBase = Path.Combine(saveBase, myself.ID());
                Directory.CreateDirectory(userSaveBase);
                AddLog("正在打开数据库");
                if (!wechat.OpenMMSqlite(userBase, out System.Data.SQLite.SQLiteConnection conn))
                {
                    AddLog("打开MM.sqlite失败,跳过");
                    continue;
                }
                if (wechat.OpenWCDBContact(userBase, out SQLiteConnection wcdb))
                {
                    AddLog("存在WCDB,与旧版好友列表合并使用");
                }
                AddLog("读取好友列表");
                if (!wechat.GetFriendsDict(conn, wcdb, myself, out Dictionary <string, Friend> friends, out int friendcount))
                {
                    AddLog("读取好友列表失败,跳过");
                    continue;
                }
                AddLog("找到" + friendcount + "个好友/聊天室");

                AddLog("导出好友列表:");
                BaseWeChat.saveFriends(Path.Combine(userSaveBase, "好友列表.txt"), friends, maxCount, out int exportCount);
                AddLog("导出" + exportCount + "个好友");

                conn.Close();
                wcdb.Close();

                var emojidown = new HashSet <DownloadTask>();
                var chatList  = new List <DisplayItem>();

                var messageDBs = wechat.FindMessageDB(uid);

                foreach (var messageDB in messageDBs)
                {
                    if (!wechat.OpenMessageSqlite(messageDB, out SQLiteConnection msgConn))
                    {
                        AddLog("读取" + messageDB + "出错,跳过");
                        continue;
                    }

                    AddLog("查找对话:" + messageDB);
                    wechat.GetChatSessions(msgConn, out List <string> chats);
                    AddLog("找到" + chats.Count + "个对话");

                    foreach (var chat in chats)
                    {
                        var    hash = chat;
                        string displayname = chat, id = displayname;
                        Friend friend = null;
                        if (friends.ContainsKey(hash))
                        {
                            friend      = friends[hash];
                            displayname = friend.DisplayName();
                            AddLog("处理与" + displayname + "的对话");
                            id = friend.ID();
                        }
                        else
                        {
                            AddLog("未找到好友信息,用默认名字代替");
                        }
                        if (textRadioButton.Checked)
                        {
                            if (wechat.SaveTextRecord(msgConn, Path.Combine(userSaveBase, id + ".txt"), displayname, id, myself, chat, friend, friends, maxCount, out int count))
                            {
                                AddLog("成功处理" + count + "条");
                            }
                            else
                            {
                                AddLog("失败");
                            }
                        }
                        else if (htmlRadioButton.Checked)
                        {
                            if (wechat.SaveHtmlRecord(msgConn, userBase, userSaveBase, displayname, id, myself, chat, friend, friends, maxCount, out int count, out HashSet <DownloadTask> _emojidown))
                            {
                                AddLog("成功处理" + count + "条");
                                chatList.Add(new DisplayItem()
                                {
                                    pic = "Portrait/" + (friend != null ? friend.FindPortrait() : "*****@*****.**"), text = displayname, link = id + ".html"
                                });
                            }
                            else
                            {
                                AddLog("失败");
                            }
                            emojidown.UnionWith(_emojidown);
                        }
                    }

                    msgConn.Close();
                }


                if (htmlRadioButton.Checked)
                {
                    BaseWeChat.MakeListHTML(chatList, Path.Combine(userSaveBase, "聊天记录.html"));
                }
                var portraitdir = Path.Combine(userSaveBase, "Portrait");
                Directory.CreateDirectory(portraitdir);
                var downlist = new HashSet <DownloadTask>();
                foreach (var item in friends)
                {
                    var tfriend = item.Value;
                    if (!tfriend.PortraitRequired)
                    {
                        continue;
                    }
                    if (tfriend.Portrait != null && tfriend.Portrait != "")
                    {
                        downlist.Add(new DownloadTask()
                        {
                            url = tfriend.Portrait, filename = tfriend.ID() + ".jpg"
                        });
                    }
                    //if (tfriend.PortraitHD != null && tfriend.PortraitHD != "") downlist.Add(new DownloadTask() { url = tfriend.PortraitHD, filename = tfriend.ID() + "_hd.jpg" });
                }
                var downloader = new Downloader(6);
                if (downlist.Count > 0)
                {
                    AddLog("下载" + downlist.Count + "个头像");
                    foreach (var item in downlist)
                    {
                        downloader.AddTask(item.url, Path.Combine(portraitdir, item.filename));
                    }
                    try
                    {
                        File.Copy("res\\[email protected]", Path.Combine(portraitdir, "*****@*****.**"));
                    }
                    catch (Exception) { }
                }
                var emojidir = Path.Combine(userSaveBase, "Emoji");
                Directory.CreateDirectory(emojidir);
                if (emojidown != null && emojidown.Count > 0)
                {
                    AddLog("下载" + emojidown.Count + "个表情");
                    foreach (var item in emojidown)
                    {
                        downloader.AddTask(item.url, Path.Combine(emojidir, item.filename));
                    }
                }
                uidList.Add(new DisplayItem()
                {
                    pic = myself.ID() + "/Portrait/" + myself.FindPortrait(), text = myself.DisplayName(), link = myself.ID() + "/聊天记录.html"
                });
                downloader.StartDownload();
                downloader.WaitToEnd();

                AddLog("完成当前账号");
            }