From 932b2d099f32c43bada7fd33e1ce6971586c7086 Mon Sep 17 00:00:00 2001 From: Suxue Date: Tue, 19 Dec 2023 23:17:39 +0800 Subject: [PATCH] =?UTF-8?q?v0.9.6.2=20Release=EF=BC=81=201.=E5=88=9D?= =?UTF-8?q?=E6=AD=A5=E6=94=AF=E6=8C=81=E8=BD=AC=E5=8F=91=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E3=80=82=202.=E6=96=B0=E5=A2=9EHTML=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=85=A8=E5=B1=80=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9ELOG=E6=96=B9=E4=BE=BF=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Export/HtmlExport.cs | 249 ++++++++++++++++++++++++++++--------------- WechatBakTool.csproj | 17 +-- YearReport.xaml | 11 -- YearReport.xaml.cs | 27 ----- 4 files changed, 172 insertions(+), 132 deletions(-) delete mode 100644 YearReport.xaml delete mode 100644 YearReport.xaml.cs diff --git a/Export/HtmlExport.cs b/Export/HtmlExport.cs index 6db03d3..c1b755b 100644 --- a/Export/HtmlExport.cs +++ b/Export/HtmlExport.cs @@ -11,6 +11,7 @@ using Newtonsoft.Json; using WechatBakTool.ViewModel; using System.Security.Policy; +using System.Windows; namespace WechatBakTool.Export { @@ -60,134 +61,204 @@ public void SetMsg(WXUserReader reader, WXContact contact,WorkspaceViewModel vie msgList.Sort((x, y) => x.CreateTime.CompareTo(y.CreateTime)); + bool err = false; int msgCount = 0; HtmlBody = ""; StreamWriter streamWriter = new StreamWriter(Path, true); foreach (var msg in msgList) { - HtmlBody += string.Format("

{0} {1}

", msg.IsSender ? "我" : msg.NickName, TimeStampToDateTime(msg.CreateTime).ToString("yyyy-MM-dd HH:mm:ss")); - - if (msg.Type == 1) - HtmlBody += string.Format("

{0}

", msg.StrContent); - else if (msg.Type == 3) + try { - string? path = reader.GetAttachment(WXMsgType.Image, msg); - if (path == null) + HtmlBody += string.Format("

{0} {1}

", msg.IsSender ? "我" : msg.NickName, TimeStampToDateTime(msg.CreateTime).ToString("yyyy-MM-dd HH:mm:ss")); + + if (msg.Type == 1) + HtmlBody += string.Format("

{0}

", msg.StrContent); + else if (msg.Type == 3) { + string? path = reader.GetAttachment(WXMsgType.Image, msg); + if (path == null) + { #if DEBUG - File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Img Error Path=>", path)); - File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),"Img Error Msg=>",JsonConvert.SerializeObject(msg))); + File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Img Error Path=>", path)); + File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Img Error Msg=>", JsonConvert.SerializeObject(msg))); #endif - HtmlBody += string.Format("

{0}

", "图片转换出现错误或文件不存在"); - continue; + HtmlBody += string.Format("

{0}

", "图片转换出现错误或文件不存在"); + continue; + } + HtmlBody += string.Format("

", path); } - HtmlBody += string.Format("

", path); - } - else if (msg.Type == 43) - { - string? path = reader.GetAttachment(WXMsgType.Video, msg); - if (path == null) + else if (msg.Type == 43) { - HtmlBody += string.Format("

{0}

", "视频不存在"); - continue; + string? path = reader.GetAttachment(WXMsgType.Video, msg); + if (path == null) + { + HtmlBody += string.Format("

{0}

", "视频不存在"); + continue; + } + HtmlBody += string.Format("

", path); } - HtmlBody += string.Format("

", path); - } - else if(msg.Type == 47) - { - string? path = reader.GetAttachment(WXMsgType.Emoji, msg); - if (path == null) + else if (msg.Type == 47) { + string? path = reader.GetAttachment(WXMsgType.Emoji, msg); + if (path == null) + { #if DEBUG - File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Emoji Error Path=>", path)); - File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Emoji Error Msg=>", JsonConvert.SerializeObject(msg))); + File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Emoji Error Path=>", path)); + File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Emoji Error Msg=>", JsonConvert.SerializeObject(msg))); #endif - HtmlBody += string.Format("

{0}

", "表情未预下载或加密表情"); - continue; - } - HtmlBody += string.Format("

", path); - } - else if (msg.Type == 49) - { - if(msg.SubType == 6||msg.SubType == 19||msg.SubType == 40) - { - string? path = reader.GetAttachment(WXMsgType.File, msg); - if(path == null) - { - HtmlBody += string.Format("

{0}

", "文件不存在"); + HtmlBody += string.Format("

{0}

", "表情未预下载或加密表情"); continue; } - else - { - HtmlBody += string.Format("

{0}

点击访问

", "文件:" + path, path); - } + HtmlBody += string.Format("

", path); } - else + else if (msg.Type == 49) { - using (var decoder = LZ4Decoder.Create(true, 64)) + if (msg.SubType == 6 || msg.SubType == 40) { - byte[] target = new byte[10240]; - int res = 0; - if (msg.CompressContent != null) - res = LZ4Codec.Decode(msg.CompressContent, 0, msg.CompressContent.Length, target, 0, target.Length); - - byte[] data = target.Skip(0).Take(res).ToArray(); - string xml = Encoding.UTF8.GetString(data); - if (!string.IsNullOrEmpty(xml)) + string? path = reader.GetAttachment(WXMsgType.File, msg); + if (path == null) + { + HtmlBody += string.Format("

{0}

", "文件不存在"); + continue; + } + else + { + HtmlBody += string.Format("

{0}

点击访问

", "文件:" + path, path); + } + } + else if (msg.SubType == 19) + { + using (var decoder = LZ4Decoder.Create(true, 64)) { - xml = xml.Replace("\n", ""); - XmlDocument xmlObj = new XmlDocument(); - xmlObj.LoadXml(xml); - if (xmlObj.DocumentElement != null) + byte[] target = new byte[10240]; + int res = 0; + if (msg.CompressContent != null) + res = LZ4Codec.Decode(msg.CompressContent, 0, msg.CompressContent.Length, target, 0, target.Length); + + byte[] data = target.Skip(0).Take(res).ToArray(); + string xml = Encoding.UTF8.GetString(data); + if (!string.IsNullOrEmpty(xml)) { - string title = ""; - string appName = ""; - string url = ""; - XmlNodeList? findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/title"); - if (findNode != null) + xml = xml.Replace("\n", ""); + XmlDocument xmlObj = new XmlDocument(); + xmlObj.LoadXml(xml); + if (xmlObj.DocumentElement != null) { - if (findNode.Count > 0) + string title = ""; + string record = ""; + string url = ""; + XmlNodeList? findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/title"); + if (findNode != null) { - title = findNode[0]!.InnerText; + if (findNode.Count > 0) + { + title = findNode[0]!.InnerText; + } } - } - findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/sourcedisplayname"); - if (findNode != null) - { - if (findNode.Count > 0) + + HtmlBody += string.Format("

{0}

", title); + findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/recorditem"); + if (findNode != null) { - appName = findNode[0]!.InnerText; + if (findNode.Count > 0) + { + XmlDocument itemObj = new XmlDocument(); + itemObj.LoadXml(findNode[0]!.InnerText); + XmlNodeList? itemNode = itemObj.DocumentElement.SelectNodes("/recordinfo/datalist/dataitem"); + if (itemNode.Count > 0) + { + foreach (XmlNode node in itemNode) + { + string nodeMsg; + string name = node["sourcename"].InnerText; + if (node.Attributes["datatype"].InnerText == "1") + nodeMsg = node["datadesc1"].InnerText; + else if (node.Attributes["datatype"].InnerText == "2") + nodeMsg = "不支持的消息"; + else + nodeMsg = node["datatitle"].InnerText; + HtmlBody += string.Format("

{0}:{1}

", name, nodeMsg); + } + } + } } } - findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/url"); - if (findNode != null) + } + } + } + else + { + using (var decoder = LZ4Decoder.Create(true, 64)) + { + byte[] target = new byte[10240]; + int res = 0; + if (msg.CompressContent != null) + res = LZ4Codec.Decode(msg.CompressContent, 0, msg.CompressContent.Length, target, 0, target.Length); + + byte[] data = target.Skip(0).Take(res).ToArray(); + string xml = Encoding.UTF8.GetString(data); + if (!string.IsNullOrEmpty(xml)) + { + xml = xml.Replace("\n", ""); + XmlDocument xmlObj = new XmlDocument(); + xmlObj.LoadXml(xml); + if (xmlObj.DocumentElement != null) { - if (findNode.Count > 0) + string title = ""; + string appName = ""; + string url = ""; + XmlNodeList? findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/title"); + if (findNode != null) + { + if (findNode.Count > 0) + { + title = findNode[0]!.InnerText; + } + } + findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/sourcedisplayname"); + if (findNode != null) { - url = findNode[0]!.InnerText; + if (findNode.Count > 0) + { + appName = findNode[0]!.InnerText; + } } + findNode = xmlObj.DocumentElement.SelectNodes("/msg/appmsg/url"); + if (findNode != null) + { + if (findNode.Count > 0) + { + url = findNode[0]!.InnerText; + } + } + HtmlBody += string.Format("

{0}|{1}

点击访问

", appName, title, url); } - HtmlBody += string.Format("

{0}|{1}

点击访问

", appName, title, url); } } } } - } - else if (msg.Type == 34) - { - string? path = reader.GetAttachment(WXMsgType.Audio, msg); - if (path == null) + else if (msg.Type == 34) + { + string? path = reader.GetAttachment(WXMsgType.Audio, msg); + if (path == null) + { + HtmlBody += string.Format("

{0}

", "语音不存在"); + continue; + } + HtmlBody += string.Format("

", path); + } + else { - HtmlBody += string.Format("

{0}

", "语音不存在"); - continue; + HtmlBody += string.Format("

{0}

", "暂未支持的消息"); } - HtmlBody += string.Format("

", path); } - else + catch(Exception ex) { - HtmlBody += string.Format("

{0}

", "暂未支持的消息"); + err = true; + File.AppendAllText("Err.log", JsonConvert.SerializeObject(msg)); + File.AppendAllText("Err.log", ex.ToString()); } - + msgCount++; if(msgCount % 50 == 0) { @@ -202,6 +273,10 @@ public void SetMsg(WXUserReader reader, WXContact contact,WorkspaceViewModel vie streamWriter.WriteLine(HtmlBody); HtmlBody = ""; viewModel.ExportCount = msgCount.ToString(); + if (err) + { + MessageBox.Show("本次导出发生了异常,部分消息被跳过,更新至最新版本后还有此问题,请将Err.log反馈给开发,谢谢。", "错误"); + } } streamWriter.Close(); streamWriter.Dispose(); diff --git a/WechatBakTool.csproj b/WechatBakTool.csproj index 8876cef..1bf7674 100644 --- a/WechatBakTool.csproj +++ b/WechatBakTool.csproj @@ -6,11 +6,18 @@ enable true True - 0.9.6.1 - 0.9.6.1 - 0.9.6.1 + 0.9.6.2 + 0.9.6.2 + 0.9.6.2 + + + + + + + @@ -73,8 +80,4 @@ - - - - diff --git a/YearReport.xaml b/YearReport.xaml deleted file mode 100644 index ee0e6c0..0000000 --- a/YearReport.xaml +++ /dev/null @@ -1,11 +0,0 @@ - - - - diff --git a/YearReport.xaml.cs b/YearReport.xaml.cs deleted file mode 100644 index b14aa26..0000000 --- a/YearReport.xaml.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace WechatBakTool -{ - /// - /// YearReport.xaml 的交互逻辑 - /// - public partial class YearReport : Window - { - public YearReport() - { - InitializeComponent(); - } - } -}