forked from SuxueCode/WechatBakTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tools.xaml.cs
167 lines (158 loc) · 6.48 KB
/
Tools.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
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 WechatBakTool.Model;
namespace WechatBakTool
{
/// <summary>
/// Tools.xaml 的交互逻辑
/// </summary>
public partial class Tools : Window
{
public Tools()
{
InitializeComponent();
LoadWorkspace();
}
private void LoadWorkspace()
{
list_workspace.Items.Clear();
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "workspace");
if (Directory.Exists(path))
{
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
string type = file.Substring(file.Length - 5, 5);
if (type == ".json")
{
string jsonString = File.ReadAllText(file);
UserBakConfig? userBakConfig = null;
try
{
userBakConfig = JsonConvert.DeserializeObject<UserBakConfig>(jsonString);
}
catch
{
MessageBox.Show("读取到异常工作区文件,请确认备份数据是否正常\r\n文件路径:" + file, "错误");
}
if (userBakConfig != null)
{
list_workspace.Items.Add(userBakConfig);
}
}
}
}
}
private void back_video_file_Click(object sender, RoutedEventArgs e)
{
Task.Run(() => {
UserBakConfig? selectConfig = null;
Dispatcher.Invoke(() => {
selectConfig = list_workspace.SelectedItem as UserBakConfig;
});
if (selectConfig != null)
{
if (!selectConfig.Decrypt)
{
MessageBox.Show("工作区未解密,请先用主程序进行解密");
return;
}
// 检查工作区视频文件夹
string video_dir = Path.Combine(selectConfig.UserWorkspacePath, "Video");
string[] files = Directory.GetFiles(video_dir);
if (!Directory.Exists(video_dir))
{
Dispatcher.Invoke(() => {
txt_log.Text += video_dir + "不存在\r\n";
txt_log.ScrollToEnd();
});
return;
}
WXUserReader UserReader = new WXUserReader(selectConfig);
// 获取用户
var atc_list = UserReader.GetWXMsgAtc();
if(atc_list == null)
{
Dispatcher.Invoke(() => {
txt_log.Text += "视频列表没有内容,无法回退\r\n";
txt_log.ScrollToEnd();
});
return;
}
foreach (string file in files)
{
FileInfo fileInfo = new FileInfo(file);
var search = atc_list.FindAll(x => x.attachPath.Contains(fileInfo.Name));
if (search != null)
{
WXSessionAttachInfo? select_atc = null;
if (search.Count > 1)
{
foreach (var s in search)
{
Dispatcher.Invoke(() =>
{
txt_log.Text += s + "\r\n";
txt_log.ScrollToEnd();
});
if (s.attachPath.Contains("_raw"))
select_atc = s;
}
}
else if (search.Count == 1)
select_atc = search[0];
else
{
Dispatcher.Invoke(() =>
{
txt_log.Text += "匹配不到文件\r\n";
txt_log.ScrollToEnd();
});
continue;
}
if (select_atc == null)
{
Dispatcher.Invoke(() =>
{
txt_log.Text += "匹配失败\r\n";
txt_log.ScrollToEnd();
});
continue;
}
// 建立路径
string source_video_file = Path.Combine(selectConfig.UserResPath, select_atc.attachPath);
if (File.Exists(source_video_file))
{
Dispatcher.Invoke(() => {
txt_log.Text += source_video_file + "已经存在\r\n";
txt_log.ScrollToEnd();
});
continue;
}
else
{
Dispatcher.Invoke(() => {
txt_log.Text += source_video_file + "开始发起回退\r\n";
txt_log.ScrollToEnd();
});
File.Copy(fileInfo.FullName, source_video_file);
}
}
}
}
});
}
}
}