Tools.xaml.cs 6.5 KB

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