Kaynağa Gözat

v0.9.7.7
1.完善了的版本支持
2.修复了导出时非法文件名及XML字符问题

suxue 6 gün önce
ebeveyn
işleme
c66a539d48

+ 4 - 3
Export/HtmlExport.cs

@@ -13,6 +13,7 @@ using WechatBakTool.ViewModel;
 using System.Security.Policy;
 using System.Windows;
 using System.Xml.Linq;
+using WechatBakTool.Helpers;
 
 namespace WechatBakTool.Export
 {
@@ -144,7 +145,7 @@ namespace WechatBakTool.Export
                                 string xml = Encoding.UTF8.GetString(data);
                                 if (!string.IsNullOrEmpty(xml))
                                 {
-                                    xml = xml.Replace("\n", "");
+                                    xml = StringHelper.CleanInvalidXmlChars(xml);
                                     XmlDocument xmlObj = new XmlDocument();
                                     xmlObj.LoadXml(xml);
                                     if (xmlObj.DocumentElement != null)
@@ -211,7 +212,7 @@ namespace WechatBakTool.Export
                                 string xml = Encoding.UTF8.GetString(data);
                                 if (!string.IsNullOrEmpty(xml))
                                 {
-                                    xml = xml.Replace("\n", "");
+                                    xml = StringHelper.CleanInvalidXmlChars(xml);
                                     XmlDocument xmlObj = new XmlDocument();
                                     xmlObj.LoadXml(xml);
                                     if (xmlObj.DocumentElement != null)
@@ -263,7 +264,7 @@ namespace WechatBakTool.Export
                                 string xml = Encoding.UTF8.GetString(data);
                                 if (!string.IsNullOrEmpty(xml))
                                 {
-                                    xml = xml.Replace("\n", "");
+                                    xml = StringHelper.CleanInvalidXmlChars(xml);
                                     XmlDocument xmlObj = new XmlDocument();
                                     xmlObj.LoadXml(xml);
                                     if (xmlObj.DocumentElement != null)

+ 46 - 0
Helpers/StringHelper.cs

@@ -0,0 +1,46 @@
+using System.IO;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace WechatBakTool.Helpers
+{
+  public static class StringHelper
+    {
+        /// <summary>
+        /// 清理XML中的非法字符
+        /// </summary>
+        /// <param name="input">需要清理的字符串</param>
+        /// <returns>清理后的字符串</returns>
+        public static string CleanInvalidXmlChars(string input)
+        {
+            if (string.IsNullOrEmpty(input))
+                return input;
+
+            // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
+            // 这里使用正则表达式匹配非法字符并替换
+            return Regex.Replace(input, @"[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD]", "");
+        }
+
+        /// <summary>
+        /// 替换文件名中的非法字符为指定字符
+        /// </summary>
+        /// <param name="fileName">原始文件名</param>
+        /// <param name="replacement">用于替换非法字符的字符,默认为 "-"</param>
+        /// <returns>清理后的文件名</returns>
+        public static string SanitizeFileName(string fileName, char replacement = '-')
+        {
+            if (string.IsNullOrEmpty(fileName))
+                return fileName;
+
+            // 处理Windows系统中文件名不允许的特殊字符
+            char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
+
+            foreach (char invalidChar in invalidFileNameChars)
+            {
+                fileName = fileName.Replace(invalidChar, '-');
+            }
+
+            return fileName;
+        }
+    }
+}

+ 7 - 0
NuGet.config

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <packageSources>
+    <clear />
+    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
+  </packageSources>
+</configuration>

+ 7 - 8
Pages/Manager.xaml.cs

@@ -20,6 +20,7 @@ using System.Windows.Navigation;
 using System.Xml;
 using WechatBakTool.Dialog;
 using WechatBakTool.Export;
+using WechatBakTool.Helpers;
 using WechatBakTool.Model;
 using WechatBakTool.ViewModel;
 
@@ -135,16 +136,14 @@ namespace WechatBakTool.Pages
         {
             workspaceViewModel.ExportCount = "";
             // string path = Path.Combine(Main2.CurrentUserBakConfig!.UserWorkspacePath, contact.UserName + ".html");
-            string name = contact.NickName;
-            name = name.Replace(@"\", "");
-            name = Regex.Replace(name, "[ \\[ \\] \\^ \\-_*×――(^)$%~!/@#$…&%¥—+=<>《》|!!???::•`·、。,;,.;\"‘’“”-]", "");
+            string fileName = StringHelper.SanitizeFileName(string.Format(
+                "{0}-{1}.html",
+                contact.UserName,
+                contact.Remark == "" ? contact.NickName : contact.Remark
+            ));
             string path = Path.Combine(
                 Main2.CurrentUserBakConfig!.UserWorkspacePath,
-                string.Format(
-                    "{0}-{1}.html",
-                    contact.UserName,
-                    contact.Remark == "" ? name : contact.Remark
-                )
+                fileName
             );
 
             IExport export = new HtmlExport();

+ 6 - 8
Pages/Workspace.xaml.cs

@@ -270,16 +270,14 @@ namespace WechatBakTool.Pages
                     return;
                 }
 
-                string name = ViewModel.WXContact.NickName;
-                name = name.Replace(@"\", "");
-                name = Regex.Replace(name, "[ \\[ \\] \\^ \\-_*×――(^)$%~!/@#$…&%¥—+=<>《》|!!???::•`·、。,;,.;\"‘’“”-]", "");
+                string fileName = StringHelper.SanitizeFileName(string.Format(
+                    "{0}-{1}",
+                    ViewModel.WXContact.UserName,
+                    ViewModel.WXContact.Remark == "" ? ViewModel.WXContact.NickName : ViewModel.WXContact.Remark
+                ));
                 string path = Path.Combine(
                     Main2.CurrentUserBakConfig!.UserWorkspacePath,
-                    string.Format(
-                        "{0}-{1}",
-                        ViewModel.WXContact.UserName,
-                        ViewModel.WXContact.Remark == "" ? name : ViewModel.WXContact.Remark
-                    )
+                    fileName
                 );
                 IExport export;
 

+ 3 - 3
WechatBakTool.csproj

@@ -6,9 +6,9 @@
     <Nullable>enable</Nullable>
     <UseWPF>true</UseWPF>
     <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
-    <AssemblyVersion>0.9.7.5</AssemblyVersion>
-    <FileVersion>0.9.7.5</FileVersion>
-    <Version>0.9.7.5</Version>
+    <AssemblyVersion>0.9.7.7</AssemblyVersion>
+    <FileVersion>0.9.7.7</FileVersion>
+    <Version>0.9.7.7</Version>
   </PropertyGroup>
 
   <ItemGroup>

+ 20 - 0
version.json

@@ -54,5 +54,25 @@
 	{
 		"Version": "3.9.12.15",
 		"BaseAddr": 93814816
+	},
+	{
+		"Version": "3.9.12.17",
+		"BaseAddr": 93836256
+	},
+	{
+		"Version": "3.9.12.31",
+		"BaseAddr": 94518176
+	},
+	{
+		"Version": "3.9.12.37",
+		"BaseAddr": 94522080
+	},
+	{
+		"Version": "3.9.12.45",
+		"BaseAddr": 94505056
+	},
+	{
+		"Version": "3.9.12.51",
+		"BaseAddr": 94556448
 	}
 ]