Bläddra i källkod

features:
1.workspace page 引入mvvm
2.wxcontact修改为联合模型

Suxue 1 år sedan
förälder
incheckning
85b0b1db52
8 ändrade filer med 214 tillägg och 18 borttagningar
  1. 16 0
      Model/WXModel.cs
  2. 82 1
      Pages/Workspace.xaml
  3. 33 8
      Pages/Workspace.xaml.cs
  4. 13 0
      README.md
  5. 0 1
      SelectWechat.xaml.cs
  6. 47 0
      ViewModel/WorkspaceViewModel.cs
  7. 22 3
      WXUserReader.cs
  8. 1 5
      WechatPCMsgBakTool.csproj

+ 16 - 0
Model/WXModel.cs

@@ -154,5 +154,21 @@ namespace WechatPCMsgBakTool.Model
         public string Alias { get; set; } = "";
         [Column("NickName")]
         public string NickName { get; set; } = "";
+        [Column("strContent")]
+        public string LastMsg { get; set; } = "";
+        [Column("ExtraBuf")]
+        public byte[]? ExtraBuf { get; set; }
+        [Column("smallHeadImgUrl")]
+        public string Avatar { get; set; } = "";
+    }
+
+    [Table("ContactHeadImgUrl")]
+    public class WXUserImg {
+        [Column("usrName")]
+        public string UserName { get; set; } = "";
+        [Column("smallHeadImgUrl")]
+        public string SmallImg { get; set; } = "";
+        [Column("bigHeadImgUrl")]
+        public string BigImg { get; set; } = "";
     }
 }

+ 82 - 1
Pages/Workspace.xaml

@@ -7,8 +7,51 @@
       mc:Ignorable="d" 
       d:DesignHeight="450" d:DesignWidth="800"
       Title="Workspace" Background="White">
-
+    <Page.Resources>
+        <Style x:Key="RepeatButtonTransparent" TargetType="{x:Type RepeatButton}">
+            <Setter Property="OverridesDefaultStyle" Value="true"/>
+            <Setter Property="Background" Value="#2775b6"/>
+            <Setter Property="Focusable" Value="false"/>
+            <Setter Property="IsTabStop" Value="false"/>
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type RepeatButton}">
+                        <Border Background="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" CornerRadius="4"/>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+        
+        <!-- 这里是listview滚动条的滑动块部分样式-->
+        <Style x:Key="ScrollBarThumbVertical" TargetType="{x:Type Thumb}">
+            <Setter Property="OverridesDefaultStyle" Value="true"/>
+            <Setter Property="IsTabStop" Value="false"/>
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type Thumb}">
+                        <Border x:Name="rectangle" Background="#BB2775b6" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="{TemplateBinding Width}" CornerRadius="4"/>
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="IsMouseOver" Value="true">
+                                <Setter Property="Background" TargetName="rectangle" Value="#772775b6"/>
+                            </Trigger>
+                            <Trigger Property="IsDragging" Value="true">
+                                <Setter Property="Background" TargetName="rectangle" Value="#772775b6"/>
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+        <DataTemplate x:Key="ListViewItemContentTemplate">
+            <Grid Margin="0">
+                <Image Width="40" Height="40" Margin="10" VerticalAlignment="Top" HorizontalAlignment="Left" Source="{Binding Avatar}"  />
+                <Label Margin="60,8,0,0" FontWeight="Bold" VerticalAlignment="Top" HorizontalAlignment="Left" Content="{Binding NickName}" Width="130"/>
+                <Label Margin="60,25,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="140" Content="{Binding LastMsg}"/>
+            </Grid>
+        </DataTemplate>
+    </Page.Resources>
     <Grid>
+        <!--
         <Label FontSize="20" Margin="30,15" Content="工作台" HorizontalAlignment="Left" VerticalAlignment="Top" />
         <Label Name="lab_status" Margin="30,45,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Content="当前工作区还未解密,请先解密。"></Label>
         <Button Name="btn_decrypt" Margin="35,80,0,0" Width="60" Height="30" Content="解密" Foreground="White" Background="#2775b6" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="btn_decrypt_Click">
@@ -25,5 +68,43 @@
                 </Style>
             </Button.Resources>
         </Button>
+        -->
+        <TextBox Name="txt_find_user" Padding="10,0" Height="30" VerticalAlignment="Top" VerticalContentAlignment="Center" FontSize="14" HorizontalAlignment="Left" Width="230" BorderThickness="0,0,10,1" BorderBrush="#2775b6" TextChanged="txt_find_user_TextChanged" GotFocus="txt_find_user_GotFocus" Text="{Binding SearchString, Mode=TwoWay}" />
+        <ListView Margin="0,30,0,0" Background="Transparent" HorizontalAlignment="Left" Width="230" Name="list_users" ItemTemplate="{DynamicResource ListViewItemContentTemplate}" BorderThickness="0,0,1,0" BorderBrush="#2775b6" SelectionChanged="list_users_SelectionChanged" ItemsSource="{Binding Contacts}">
+            <ListView.Resources>
+                <Style TargetType="{x:Type ScrollBar}">
+                    <Setter Property="Background" Value="Transparent"/>
+                    <Setter Property="BorderBrush" Value="Transparent"/>
+                    <Setter Property="BorderThickness" Value="0" />
+                    <Setter Property="Template">
+                        <Setter.Value>
+                            <ControlTemplate TargetType="{x:Type ScrollBar}">
+                                <Grid x:Name="Bg" SnapsToDevicePixels="true" Width="8" HorizontalAlignment="Right">
+                                    <Grid.RowDefinitions>
+                                        <RowDefinition Height="0"/>
+                                        <RowDefinition Height="1*"/>
+                                        <RowDefinition Height="0"/>
+                                    </Grid.RowDefinitions>
+                                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Row="1" CornerRadius="5"/>
+                                    <Track x:Name="PART_Track" IsDirectionReversed="true" IsEnabled="{TemplateBinding IsMouseOver}" Grid.Row="1">
+                                        <Track.DecreaseRepeatButton>
+                                            <RepeatButton Command="{x:Static ScrollBar.PageUpCommand}" Style="{StaticResource RepeatButtonTransparent}" HorizontalAlignment="Right" Width="8"/>
+                                        </Track.DecreaseRepeatButton>
+                                        <Track.IncreaseRepeatButton>
+                                            <RepeatButton Command="{x:Static ScrollBar.PageDownCommand}" Style="{StaticResource RepeatButtonTransparent}" HorizontalAlignment="Right" Width="8"/>
+                                        </Track.IncreaseRepeatButton>
+                                        <Track.Thumb>
+                                            <Thumb Style="{StaticResource ScrollBarThumbVertical}" Width="8" />
+                                        </Track.Thumb>
+                                    </Track>
+                                </Grid>
+                            </ControlTemplate>
+                        </Setter.Value>
+                    </Setter>
+                </Style>
+            </ListView.Resources>
+        </ListView>
+        <Label Content="{Binding WXContact.UserName}" HorizontalAlignment="Left" Margin="258,21,0,0" VerticalAlignment="Top"/>
+
     </Grid>
 </Page>

+ 33 - 8
Pages/Workspace.xaml.cs

@@ -1,10 +1,14 @@
 using System;
+using System.Collections;
 using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
 using System.Windows.Data;
 using System.Windows.Documents;
 using System.Windows.Input;
@@ -13,6 +17,7 @@ using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
 using WechatPCMsgBakTool.Model;
+using WechatPCMsgBakTool.ViewModel;
 
 namespace WechatPCMsgBakTool.Pages
 {
@@ -22,25 +27,22 @@ namespace WechatPCMsgBakTool.Pages
     public partial class Workspace : Page
     {
         public WXUserReader? UserReader { get; set; }
+        private WorkspaceViewModel ViewModel { get; set; } = new WorkspaceViewModel();
         public Workspace()
         {
             InitializeComponent();
+            DataContext = ViewModel;
             UserBakConfig? config = Main2.CurrentUserBakConfig;
             if (config != null)
             {
+                UserReader = new WXUserReader(config);
                 if (config.Decrypt)
                 {
-                    btn_decrypt.IsEnabled = false;
-                    btn_read.IsEnabled = true;
+                    ViewModel.Contacts = UserReader.GetWXContacts();
                 }
             }
         }
 
-        private void btn_decrypt_Click(object sender, RoutedEventArgs e)
-        {
-            
-        }
-
         private void btn_read_Click(object sender, RoutedEventArgs e)
         {
             if (Main2.CurrentUserBakConfig == null)
@@ -48,8 +50,31 @@ namespace WechatPCMsgBakTool.Pages
                 MessageBox.Show("工作区配置加载失败,请检查配置文件是否正常","错误");
                 return;
             }
+        }
+
+        private void list_users_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            ViewModel.WXContact = list_users.SelectedItem as WXContact;
+        }
+
+        private void txt_find_user_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            if (UserReader == null)
+                return;
+
+            string findName = txt_find_user.Text;
+            if (txt_find_user.Text == "搜索...")
+                findName = "";
+
+            ViewModel.Contacts = UserReader.GetWXContacts(findName);
+        }
+
+        private void txt_find_user_GotFocus(object sender, RoutedEventArgs e)
+        {
+            if (txt_find_user.Text == "搜索...")
+                txt_find_user.Text = "";
 
-            UserReader = new WXUserReader(Main2.CurrentUserBakConfig);
+            Debug.WriteLine(ViewModel.SearchString);
         }
     }
 }

+ 13 - 0
README.md

@@ -1,7 +1,13 @@
+> [!NOTE]
+> 本分支为项目开发分支,变动较为频繁且可能不可用<br/>
+> 如果你希望观察作者的开发动态,可以参考这个分支。
+<br/>
+
 # WechatPCMsgBakTool
 微信PC聊天记录备份工具,仅支持Windows
 
 - 支持3.9.6.33版本后,若版本更新可在version.json添加版本号和地址即可完成新版本支持
+- 支持用户名推定key位置,无视版本,创建工作区请正常录入微信号
 - 导出图片、视频、音频、分享链接
 - 导出Html文件
 - 支持聊天频率分析,全消息库内容搜索
@@ -12,6 +18,13 @@
 
 如果有什么好的建议或意见,或者遇到什么问题,欢迎提issue,看到会回。
 
+### 近期开发规划
+- 【进行中】UI、界面交互全面更新;
+- 【进行中】群聊支持;
+- 各种消息记录完善
+- 工作区更新逻辑完善
+- 自定义HTML模版
+- 各种数据信息统计
 
 > [!NOTE]
 > 反馈群:815054692<br/>

+ 0 - 1
SelectWechat.xaml.cs

@@ -4,7 +4,6 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
-using System.Management;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;

+ 47 - 0
ViewModel/WorkspaceViewModel.cs

@@ -0,0 +1,47 @@
+using CommunityToolkit.Mvvm.ComponentModel;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WechatPCMsgBakTool.Model;
+
+namespace WechatPCMsgBakTool.ViewModel
+{
+    partial class WorkspaceViewModel : ObservableObject
+    {
+        [ObservableProperty]
+        public WXContact? wXContact;
+
+        [ObservableProperty]
+        public List<WXContact>? contacts;
+
+        private string searchString = "";
+        public string SearchString
+        {
+            set
+            {
+                if (value == "搜索...")
+                    searchString = "";
+                else
+                    searchString = value;
+
+                OnPropertyChanged("SearchString");
+            }
+            get
+            {
+                if (searchString == "")
+                    return "搜索...";
+                return searchString;
+            }
+        }
+
+        public string SearchRealString
+        {
+            get
+            {
+                return searchString;
+            }
+        }
+    }
+}

+ 22 - 3
WXUserReader.cs

@@ -43,14 +43,33 @@ namespace WechatPCMsgBakTool
             SQLiteConnection con = DBInfo["MicroMsg"];
             if (con == null)
                 return null;
-            string query = "select * from contact";
+            string query = @"select contact.*,session.strContent,contactHeadImgUrl.smallHeadImgUrl,contactHeadImgUrl.bigHeadImgUrl from contact 
+            left join session on session.strUsrName = contact.username
+            left join contactHeadImgUrl on contactHeadImgUrl.usrName = contact.username
+            where type != 4 {searchName}
+            order by nOrder desc";
+            
             if (name != null)
             {
-                query = "select * from contact where username like ? or alias like ? or nickname like ? or remark like ?";
+                query = query.Replace("{searchName}", " and (username like ? or alias like ? or nickname like ? or remark like ?)");
                 return con.Query<WXContact>(query, $"%{name}%", $"%{name}%", $"%{name}%", $"%{name}%");
             }
-            return con.Query<WXContact>(query);
+            else
+            {
+                query = query.Replace("{searchName}", "");
+                return con.Query<WXContact>(query);
+            }
         }
+
+        public List<WXUserImg>? GetUserImgs()
+        {
+            SQLiteConnection con = DBInfo["MicroMsg"];
+            if (con == null)
+                return null;
+            string query = "select * from contactHeadImgUrl";
+            return con.Query<WXUserImg>(query);
+        }
+
         public List<WXChatRoom>? GetWXChatRooms()
         {
             SQLiteConnection con = DBInfo["MicroMsg"];

+ 1 - 5
WechatPCMsgBakTool.csproj

@@ -12,10 +12,10 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
     <PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.6" />
     <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
     <PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
-    <PackageReference Include="System.Management" Version="7.0.2" />
   </ItemGroup>
 
   <ItemGroup>
@@ -36,8 +36,4 @@
     </None>
   </ItemGroup>
 
-  <ItemGroup>
-    <Folder Include="ViewModel\" />
-  </ItemGroup>
-
 </Project>