浏览代码

修复bug
dev分支预下载暂时不可用,拿来调试功能了

Suxue 1 年之前
父节点
当前提交
f3d73d2507
共有 5 个文件被更改,包括 71 次插入2 次删除
  1. 4 1
      Helpers/DevicePathMapper.cs
  2. 8 0
      Model/WXModel.cs
  3. 1 1
      Pages/Workspace.xaml
  4. 56 0
      Pages/Workspace.xaml.cs
  5. 2 0
      WXUserReader.cs

+ 4 - 1
Helpers/DevicePathMapper.cs

@@ -15,7 +15,10 @@ namespace WechatBakTool.Helpers
 
         public static string FromDevicePath(string devicePath)
         {
-            var drive = Array.Find(DriveInfo.GetDrives(), d => devicePath.StartsWith(d.GetDevicePath(), StringComparison.InvariantCultureIgnoreCase));
+            var drive = Array.Find(
+                DriveInfo.GetDrives(), d =>
+                devicePath.StartsWith(d.GetDevicePath() + "\\", StringComparison.InvariantCultureIgnoreCase)
+            );
             return drive != null ?
                 devicePath.ReplaceFirst(drive.GetDevicePath(), drive.GetDriveLetter()) :
                 null;

+ 8 - 0
Model/WXModel.cs

@@ -158,6 +158,14 @@ namespace WechatBakTool.Model
         public string Reserved0 { get; set; } = "";
     }
 
+    public class WXContactHT
+    {
+        public string UserName { get; set; } = "";
+        public string NickName { get; set; } = "";
+        public string LastMsg { get; set; } = "";
+        public int FileCount { get; set; } = 1;
+        public string AvatarString { get; set; } = "";
+    }
     [Table("Contact")]
     public class WXContact
     {

+ 1 - 1
Pages/Workspace.xaml

@@ -225,7 +225,7 @@
                 </Style>
             </Button.Resources>
         </Button>
-        <Button x:Name="btn_pre_emoji" Width="80" Height="30" Style="{StaticResource  ButtonStyle}" Content="表情预下载" BorderBrush="Transparent" BorderThickness="0" Background="#2775b6" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,292,15" IsEnabled="{Binding SelectContact}" Click="btn_pre_emoji_Click" >
+        <Button x:Name="btn_pre_emoji" Width="80" Height="30" Style="{StaticResource  ButtonStyle}" Content="表情预下载" BorderBrush="Transparent" BorderThickness="0" Background="#2775b6" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,405,292,0" IsEnabled="{Binding SelectContact}" Click="btn_pre_emoji_Click" >
             <Button.Resources>
                 <Style TargetType="{x:Type Border}">
                     <Setter Property="CornerRadius" Value="3"/>

+ 56 - 0
Pages/Workspace.xaml.cs

@@ -25,6 +25,8 @@ using WordCloudSharp;
 using System.Drawing;
 using System.Windows.Controls;
 using System.Text.RegularExpressions;
+using Newtonsoft.Json;
+using System.Drawing.Imaging;
 
 namespace WechatBakTool.Pages
 {
@@ -263,12 +265,66 @@ namespace WechatBakTool.Pages
 
         private void btn_pre_emoji_Click(object sender, RoutedEventArgs e)
         {
+            /*
             if(UserReader != null && ViewModel.WXContact != null)
             {
                 Task.Run(() => {
                     UserReader.PreDownloadEmoji(ViewModel.WXContact.UserName);
                     MessageBox.Show("用户所有表情预下载完毕");
                 });
+            }*/
+            if (UserReader != null && ViewModel.WXContact != null)
+            {
+                Task.Run(() =>
+                {
+                    List<WXMsg> msgs = UserReader.GetWXMsgs(ViewModel.WXContact.UserName).ToList();
+                    List<WXContactHT> users = new List<WXContactHT>();
+                    if (File.Exists("WXContact.json"))
+                    {
+                        string text = File.ReadAllText("WXContact.json");
+                        text = text.Substring(8, text.Length - 8);
+                        users = JsonConvert.DeserializeObject<List<WXContactHT>>(text);
+                    }
+
+                    int i = 1; int all = 1;
+                    List<WXMsg> tmp = new List<WXMsg>();
+                    foreach (WXMsg m in msgs)
+                    {
+                        m.BytesExtra = null;
+                        tmp.Add(m);
+                        if (all % 20000 == 0)
+                        {
+                            File.WriteAllText(ViewModel.WXContact.UserName + "-" + i.ToString() + ".json", string.Format("showMsg({0})", JsonConvert.SerializeObject(tmp)));
+                            tmp.Clear();
+                            i++;
+                        }
+                        all++;
+                    }
+
+                    if (users!.Find(x => x.UserName == ViewModel.WXContact.UserName) == null)
+                    {
+                        WXContactHT html = new WXContactHT();
+                        html.NickName = ViewModel.WXContact.NickName;
+                        html.UserName = ViewModel.WXContact.UserName;
+                        html.LastMsg = ViewModel.WXContact.LastMsg;
+                        if (ViewModel.WXContact.Avatar != null)
+                        {
+
+                            using (var ms = new MemoryStream())
+                            {
+                                ViewModel.WXContact.Avatar.StreamSource.CopyTo(ms);
+                                byte[] bytes = new byte[ms.Length];
+                                ms.Write(bytes, 0, bytes.Length);
+                                html.AvatarString = Convert.ToBase64String(bytes);
+                            }
+                        }
+                        html.FileCount = i;
+                        users.Add(html);
+                    }
+                    File.WriteAllText(ViewModel.WXContact.UserName + "-" + i.ToString() + ".json", string.Format("showMsg({0})", JsonConvert.SerializeObject(tmp)));
+                    File.WriteAllText("WXContact.json", string.Format("getUser({0})", JsonConvert.SerializeObject(users)));
+                    MessageBox.Show("json已导出");
+                });
             }
         }
     }

+ 2 - 0
WXUserReader.cs

@@ -367,6 +367,8 @@ namespace WechatBakTool
                                 w.NickName = contact.Remark;
                             else
                                 w.NickName = contact.NickName;
+
+                            w.StrTalker = contact.UserName;
                         }
                     }