Skip to content

Commit

Permalink
v0.9.2.0版本!
Browse files Browse the repository at this point in the history
1.异步优化,现在起创建工作区,导出聊天记录,都是独立线程操作了!体验更好!并且多了相关状态提示,体验更好。
2.新增批量导出模式,左侧工作区,右键->管理就见啦!
3.修复视频、图片导出时逻辑bug
  • Loading branch information
SuxueCode committed Dec 11, 2023
1 parent 24f2962 commit c996a89
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 114 deletions.
5 changes: 3 additions & 2 deletions Export/ExportInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using System.Text;
using System.Threading.Tasks;
using WechatBakTool.Model;
using WechatBakTool.ViewModel;

namespace WechatBakTool.Export
{
public interface IExport
{
void InitTemplate(WXContact session,string path);
void SetMsg(WXUserReader reader, WXContact session);
void SetMsg(WXUserReader reader, WXContact session, WorkspaceViewModel viewModel);
void SetEnd();
void Save(string path = "", bool append = false);
void Save(string path = "");
}
}
44 changes: 32 additions & 12 deletions Export/HtmlExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Threading.Tasks;
using WechatBakTool.Model;
using System.Xml;
using Newtonsoft.Json;
using WechatBakTool.ViewModel;

namespace WechatBakTool.Export
{
Expand All @@ -23,6 +25,7 @@ public void InitTemplate(WXSession session)

HtmlBody += string.Format("<div class=\"msg\"><p class=\"nickname\"><b>与 {0}({1}) 的聊天记录</b></p>", Session.NickName, Session.UserName);
HtmlBody += string.Format("<div class=\"msg\"><p class=\"nickname\"><b>导出时间:{0}</b></p><hr/>", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
File.WriteAllText(Path, HtmlBody);
}

public void InitTemplate(WXContact contact, string p)
Expand All @@ -34,25 +37,18 @@ public void InitTemplate(WXContact contact, string p)
InitTemplate(session);
}

public void Save(string path = "", bool append = false)
public void Save(string path = "")
{
if (!append)
{
File.WriteAllText(path, HtmlBody);
}
else
{
File.AppendAllText(path, HtmlBody);
HtmlBody = "";
}

}

public void SetEnd()
{
HtmlBody += "</body></html>";
File.AppendAllText(Path, HtmlBody);
}

public void SetMsg(WXUserReader reader, WXContact contact)
public void SetMsg(WXUserReader reader, WXContact contact,WorkspaceViewModel viewModel)
{
if (Session == null)
throw new Exception("请初始化模版:Not Use InitTemplate");
Expand All @@ -63,6 +59,9 @@ public void SetMsg(WXUserReader reader, WXContact contact)

msgList.Sort((x, y) => x.CreateTime.CompareTo(y.CreateTime));

int msgCount = 0;
HtmlBody = "";
StreamWriter streamWriter = new StreamWriter(Path, true);
foreach (var msg in msgList)
{
HtmlBody += string.Format("<div class=\"msg\"><p class=\"nickname\">{0} <span style=\"padding-left:10px;\">{1}</span></p>", msg.IsSender ? "我" : msg.NickName, TimeStampToDateTime(msg.CreateTime).ToString("yyyy-MM-dd HH:mm:ss"));
Expand All @@ -74,6 +73,10 @@ public void SetMsg(WXUserReader reader, WXContact contact)
string? path = reader.GetAttachment(WXMsgType.Image, msg);
if (path == null)
{
#if DEBUG
File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Img Error Path=>", path));
File.AppendAllText("debug.log", string.Format("[D]{0} {1}:{2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),"Img Error Msg=>",JsonConvert.SerializeObject(msg)));
#endif
HtmlBody += string.Format("<p class=\"content\">{0}</p></div>", "图片转换出现错误或文件不存在");
continue;
}
Expand Down Expand Up @@ -154,8 +157,25 @@ public void SetMsg(WXUserReader reader, WXContact contact)
{
HtmlBody += string.Format("<p class=\"content\">{0}</p></div>", "暂未支持的消息");
}

msgCount++;
if(msgCount % 50 == 0)
{
streamWriter.WriteLine(HtmlBody);
HtmlBody = "";
viewModel.ExportCount = msgCount.ToString();
}

}

if(msgCount % 50 != 0)
{
streamWriter.WriteLine(HtmlBody);
HtmlBody = "";
viewModel.ExportCount = msgCount.ToString();
}
streamWriter.Close();
streamWriter.Dispose();

}
private static DateTime TimeStampToDateTime(long timeStamp, bool inMilli = false)
{
Expand Down
8 changes: 6 additions & 2 deletions Export/TXTExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using System.Xml;
using WechatBakTool.Model;
using WechatBakTool.ViewModel;

namespace WechatBakTool.Export
{
Expand All @@ -29,7 +30,7 @@ public void InitTemplate(WXContact contact,string p)
File.AppendAllText(Path, string.Format("=================================================================\n\n\n"));
}

void IExport.Save(string path, bool append)
void IExport.Save(string path)
{

}
Expand All @@ -39,7 +40,7 @@ void IExport.SetEnd()

}

public void SetMsg(WXUserReader reader, WXContact session)
public void SetMsg(WXUserReader reader, WXContact session, WorkspaceViewModel viewModel)
{
if (Contact == null)
throw new Exception("请初始化模版:Not Use InitTemplate");
Expand All @@ -50,6 +51,7 @@ public void SetMsg(WXUserReader reader, WXContact session)

msgList.Sort((x, y) => x.CreateTime.CompareTo(y.CreateTime));

int msgCount = 0;
foreach (var msg in msgList)
{
string txtMsg = "";
Expand Down Expand Up @@ -134,6 +136,8 @@ public void SetMsg(WXUserReader reader, WXContact session)
}
string row = string.Format("{2} | {0}:{1}\n", msg.IsSender ? "我" : msg.NickName, txtMsg, TimeStampToDateTime(msg.CreateTime).ToString("yyyy-MM-dd HH:mm:ss"));
File.AppendAllText(Path, row);
msgCount++;
viewModel.ExportCount = msgCount.ToString();
}
}

Expand Down
5 changes: 4 additions & 1 deletion Helpers/DecryptionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using System.Threading.Tasks;
using System.Windows;
using WechatBakTool.Model;
using WechatBakTool.Pages;
using WechatBakTool.ViewModel;

namespace WechatBakTool.Helpers
{
Expand Down Expand Up @@ -283,7 +285,7 @@ public static string SaveDecImage(byte[] fileRaw,string source,string to_dir,str
}
return saveFilePath;
}
public static void DecryUserData(byte[] key, string source, string to)
public static void DecryUserData(byte[] key, string source, string to,CreateWorkViewModel viewModel)
{
string dbPath = source;
string decPath = to;
Expand All @@ -294,6 +296,7 @@ public static void DecryUserData(byte[] key, string source, string to)
foreach (string file in filePath)
{
FileInfo info = new FileInfo(file);
viewModel.LabelStatus = "正在解密" + info.Name;
var db_bytes = File.ReadAllBytes(file);
var decrypted_file_bytes = DecryptDB(db_bytes, key);
if (decrypted_file_bytes == null || decrypted_file_bytes.Length == 0)
Expand Down
19 changes: 14 additions & 5 deletions Main2.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WechatBakTool"
mc:Ignorable="d" WindowStartupLocation="CenterScreen" WindowStyle="None" WindowState="Normal" Background="Transparent" AllowsTransparency="True" ResizeMode="NoResize"
Title="Main2" Height="550" Width="950" >
Title="Main2" Height="550" Width="950" >
<Window.Resources>
<Style TargetType="local:Main2">
<!-- 设置窗体的WindowChrome -->
Expand All @@ -15,7 +15,7 @@
<!-- CornerRadius:窗体圆角;-->
<!-- CaptionHeight顶部标题的高度;-->
<!-- GlassFrameThickness:默认边框的大小,0为不使用默认边框(这样定义的圆角才有效),-1为使用默认边框默认值-->
<WindowChrome CornerRadius="5" CaptionHeight="0" GlassFrameThickness="0" />
<WindowChrome CornerRadius="5" CaptionHeight="5" GlassFrameThickness="0" />
</Setter.Value>
</Setter>
</Style>
Expand Down Expand Up @@ -61,8 +61,8 @@
</Grid>
</DataTemplate>
</Window.Resources>
<Grid Background="White">
<Image Panel.ZIndex="100" Name="img_btn_min" Source="{StaticResource svg_min}" Width="20" Height="20" HorizontalAlignment="Left" Margin="860,20,0,0" VerticalAlignment="Top">
<Grid Background="White" MouseDown="Grid_MouseDown">
<Image Panel.ZIndex="100" Name="img_btn_min" Source="{StaticResource svg_min}" Width="20" Height="20" HorizontalAlignment="Left" Margin="860,20,0,0" VerticalAlignment="Top" MouseLeftButtonDown="img_btn_min_MouseLeftButtonDown">
<Image.RenderTransform>
<RotateTransform CenterX="0.5" CenterY="0.5" />
</Image.RenderTransform>
Expand Down Expand Up @@ -122,8 +122,17 @@
</EventTrigger>
</Image.Triggers>
</Image>

<Grid Width="230" Background="#2775b6" HorizontalAlignment="Left" IsHitTestVisible="True">
<ListView BorderThickness="0" Background="Transparent" Margin="0,0,0,85" Name="list_workspace" ItemTemplate="{DynamicResource ListViewItemContentTemplate}" SelectionChanged="list_workspace_SelectionChanged"/>

<ListView BorderThickness="0" Background="Transparent" Margin="0,0,0,85" Name="list_workspace" ItemTemplate="{DynamicResource ListViewItemContentTemplate}" SelectionChanged="list_workspace_SelectionChanged">
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="查看" Click="MenuItem_Click" />
<MenuItem Header="管理" Click="MenuItem_Click_1" />
</ContextMenu>
</ListView.ContextMenu>
</ListView>
<Grid Name="new_workspace" Width="170" Height="40" VerticalAlignment="Bottom" Margin="30,45" IsHitTestVisible="True">
<Rectangle Name="new_workspace_fill" Fill="Transparent" RadiusX="0" RadiusY="0" Stroke="White" StrokeDashArray="5" MouseDown="new_workspace_fill_MouseDown">
<Rectangle.Triggers>
Expand Down
28 changes: 27 additions & 1 deletion Main2.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public partial class Main2 : Window
public Main2()
{
InitializeComponent();
// 获取文件版本
lab_version.Content += $" {Application.ResourceAssembly.GetName().Version}";
// list_workspace.Items.Add(new { Name = "sxcoder", Friends_Number=23, Msg_Number=102302, Decrypt="已解密" });
//加载工作区
LoadWorkspace();
}

Expand All @@ -40,10 +41,12 @@ private void img_btn_close_MouseLeftButtonDown(object sender, MouseButtonEventAr
public void LoadWorkspace()
{
userBakConfigs.Clear();
// 根目录worksapce读工作区
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "workspace");
if (Directory.Exists(path))
{
string[] files = Directory.GetFiles(path);
//目录内json文件为各工作区配置文件
foreach (string file in files)
{
string type = file.Substring(file.Length - 5, 5);
Expand Down Expand Up @@ -92,5 +95,28 @@ private void new_workspace_fill_MouseDown(object sender, MouseButtonEventArgs e)
{
MainFrame.Navigate(new Uri("pack://application:,,,/Pages/CreateWork.xaml?datatime=" + DateTime.Now.Ticks));
}

private void img_btn_min_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
WindowState = WindowState.Minimized;
}

private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}

private void MenuItem_Click(object sender, RoutedEventArgs e)
{
MainFrame.Navigate(new Uri("pack://application:,,,/Pages/Workspace.xaml?datatime=" + DateTime.Now.Ticks));
}

private void MenuItem_Click_1(object sender, RoutedEventArgs e)
{
MainFrame.Navigate(new Uri("pack://application:,,,/Pages/Manager.xaml?datatime=" + DateTime.Now.Ticks));
}
}
}
28 changes: 28 additions & 0 deletions Model/YearReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WechatBakTool.Model
{
public class YearReport
{
public List<ReportItem>? List { get; set; }
public int Version { get; set; }
}

public class ReportItem
{
public string ImgName { get; set; } = "";
public string Type { get; set; } = "";
public List<TextPostion>? TextPostions { get; set; }
}

public class TextPostion
{
public double X { get; set; }
public double Y { get; set; }
public string TextTemplate { get; set; } = "";
}
}
11 changes: 6 additions & 5 deletions Pages/CreateWork.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Grid>
<Label FontSize="20" Margin="30,15" Content="新建工作区" HorizontalAlignment="Left" VerticalAlignment="Top" />
<Label Margin="30,55,0,0" Content="请选择要创建工作区的微信,可以通过微信路径判断是哪一个微信哦!" HorizontalAlignment="Left" VerticalAlignment="Top" />
<ListView Name="list_process" Margin="35,95,35,0" VerticalAlignment="Top" Height="160" ItemsSource="{Binding ProcessInfos}" SelectionChanged="list_process_SelectionChanged" SelectedItem="{Binding SelectProcess}">
<ListView Name="list_process" Margin="35,95,35,0" IsEnabled="{Binding IsEnable}" VerticalAlignment="Top" Height="160" ItemsSource="{Binding ProcessInfos}" SelectionChanged="list_process_SelectionChanged" SelectedItem="{Binding SelectProcess}">
<ListView.View>
<GridView>
<GridViewColumn Header="进程名" Width="120" DisplayMemberBinding="{Binding ProcessName}" />
Expand All @@ -23,13 +23,13 @@
</ListView.View>
</ListView>
<Label Margin="30,275,0,0" Content="选择微信后,请确认下方自动获取的微信名是否正确。不正确请修改!" FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox x:Name="txt_username" Margin="35,300,0,0" Width="280" HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness="0,0,0,1" Text="{Binding UserName}" />
<TextBox IsEnabled="{Binding IsEnable}" x:Name="txt_username" Margin="35,300,0,0" Width="280" HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness="0,0,0,1" Text="{Binding UserName}" />

<Label Margin="30,350,0,0" Content="请选择解密方式:" FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<RadioButton Margin="35,380,0,0" Content="固定地址查找" HorizontalAlignment="Left" VerticalAlignment="Top" GroupName="rb_find_key" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsChecked="{Binding KeyType, Converter={StaticResource ResourceKey=getKeyConverterKey}, ConverterParameter=1}" />
<RadioButton Margin="35,405,0,0" Content="用户名推断查找" HorizontalAlignment="Left" VerticalAlignment="Top" GroupName="rb_find_key" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsChecked="{Binding KeyType, Converter={StaticResource ResourceKey=getKeyConverterKey}, ConverterParameter=2}"/>
<RadioButton Margin="35,380,0,0" Content="固定地址查找" HorizontalAlignment="Left" VerticalAlignment="Top" GroupName="rb_find_key" HorizontalContentAlignment="Center" IsEnabled="{Binding IsEnable}" VerticalContentAlignment="Center" IsChecked="{Binding KeyType, Converter={StaticResource ResourceKey=getKeyConverterKey}, ConverterParameter=1}" />
<RadioButton Margin="35,405,0,0" Content="用户名推断查找" HorizontalAlignment="Left" VerticalAlignment="Top" GroupName="rb_find_key" HorizontalContentAlignment="Center" IsEnabled="{Binding IsEnable}" VerticalContentAlignment="Center" IsChecked="{Binding KeyType, Converter={StaticResource ResourceKey=getKeyConverterKey}, ConverterParameter=2}"/>

<Button Name="btn_create_worksapce" Margin="0,0,35,50" Height="60" Width="100" HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="创建工作区" BorderThickness="0" Background="#2775b6" Foreground="White" Click="btn_create_worksapce_Click">
<Button Name="btn_create_worksapce" Margin="0,0,35,50" Height="60" Width="100" HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="创建工作区" BorderThickness="0" IsEnabled="{Binding IsEnable}" Background="#2775b6" Foreground="White" Click="btn_create_worksapce_Click">
<Button.Resources>
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="8"/>
Expand All @@ -39,5 +39,6 @@
<Label Margin="210,350,0,0" Content="其他选项:" FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<CheckBox Margin="215,380,0,0" Content="打包资源文件夹(功能规划中)" IsEnabled="False" HorizontalAlignment="Left" VerticalAlignment="Top" />
<CheckBox Margin="215,405,0,0" Content="手动模式(功能规划中)" IsEnabled="False" HorizontalAlignment="Left" VerticalAlignment="Top" />
<Label Name="lab_status" Content="{Binding LabelStatus}" HorizontalAlignment="Left" Margin="30,450,0,0" VerticalAlignment="Top"/>
</Grid>
</Page>
Loading

0 comments on commit c996a89

Please sign in to comment.