2
0

Manager.xaml.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net.Http;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Xml;
  21. using WechatBakTool.Export;
  22. using WechatBakTool.Model;
  23. using WechatBakTool.ViewModel;
  24. namespace WechatBakTool.Pages
  25. {
  26. /// <summary>
  27. /// Manager.xaml 的交互逻辑
  28. /// </summary>
  29. public partial class Manager : Page
  30. {
  31. private WorkspaceViewModel workspaceViewModel = new WorkspaceViewModel();
  32. public WXUserReader? UserReader;
  33. private List<WXContact>? ExpContacts;
  34. private bool Suspend = false;
  35. public Manager()
  36. {
  37. DataContext = workspaceViewModel;
  38. InitializeComponent();
  39. UserBakConfig? config = Main2.CurrentUserBakConfig;
  40. if (config != null)
  41. {
  42. UserReader = new WXUserReader(config);
  43. if (!config.Decrypt)
  44. {
  45. MessageBox.Show("请先解密数据库", "错误");
  46. return;
  47. }
  48. }
  49. }
  50. private void btn_export_all_Click(object sender, RoutedEventArgs e)
  51. {
  52. Task.Run(() =>
  53. {
  54. bool group = false, user = false;
  55. Dispatcher.Invoke(() =>
  56. {
  57. if (cb_group.IsChecked == null || cb_user.IsChecked == null)
  58. return;
  59. group = (bool)cb_group.IsChecked;
  60. user = (bool)cb_user.IsChecked;
  61. });
  62. if (UserReader != null)
  63. {
  64. if (!Suspend)
  65. ExpContacts = UserReader.GetWXContacts().ToList();
  66. else
  67. Suspend = false;
  68. foreach (var contact in ExpContacts!)
  69. {
  70. if (Suspend)
  71. {
  72. workspaceViewModel.ExportCount = "已暂停";
  73. return;
  74. }
  75. if (group && contact.UserName.Contains("@chatroom"))
  76. {
  77. workspaceViewModel.WXContact = contact;
  78. ExportMsg(contact);
  79. }
  80. if (user && !contact.UserName.Contains("@chatroom") && !contact.UserName.Contains("gh_"))
  81. {
  82. workspaceViewModel.WXContact = contact;
  83. ExportMsg(contact);
  84. }
  85. }
  86. MessageBox.Show("批量导出完成", "提示");
  87. }
  88. });
  89. }
  90. private void ExportMsg(WXContact contact)
  91. {
  92. workspaceViewModel.ExportCount = "";
  93. // string path = Path.Combine(Main2.CurrentUserBakConfig!.UserWorkspacePath, contact.UserName + ".html");
  94. string name = contact.NickName;
  95. name = name.Replace(@"\", "");
  96. name = Regex.Replace(name, "[ \\[ \\] \\^ \\-_*×――(^)$%~!/@#$…&%¥—+=<>《》|!!???::•`·、。,;,.;\"‘’“”-]", "");
  97. string path = Path.Combine(
  98. Main2.CurrentUserBakConfig!.UserWorkspacePath,
  99. string.Format(
  100. "{0}-{1}.html",
  101. contact.UserName,
  102. contact.Remark == "" ? name : contact.Remark
  103. )
  104. );
  105. IExport export = new HtmlExport();
  106. export.InitTemplate(contact, path);
  107. if(export.SetMsg(UserReader!, contact, workspaceViewModel))
  108. {
  109. export.SetEnd();
  110. export.Save(path);
  111. }
  112. }
  113. private void btn_emoji_download_Click(object sender, RoutedEventArgs e)
  114. {
  115. if (UserReader != null)
  116. {
  117. Task.Run(() =>
  118. {
  119. UserReader.PreDownloadEmoji();
  120. MessageBox.Show("所有表情预下载完毕");
  121. });
  122. }
  123. }
  124. private void btn_analyse_Click(object sender, RoutedEventArgs e)
  125. {
  126. if (UserReader == null || Main2.CurrentUserBakConfig == null)
  127. {
  128. MessageBox.Show("请先读取数据");
  129. return;
  130. }
  131. Analyse analyse = new Analyse(Main2.CurrentUserBakConfig, UserReader);
  132. analyse.Show();
  133. }
  134. }
  135. }