SelectWechat.xaml.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  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 System.Windows.Shapes;
  16. using WechatPCMsgBakTool.Model;
  17. namespace WechatPCMsgBakTool
  18. {
  19. /// <summary>
  20. /// SelectWechat.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class SelectWechat : Window
  23. {
  24. List<ProcessInfo> processInfos = new List<ProcessInfo>();
  25. public ProcessInfo? SelectProcess { get; set; } = null;
  26. public SelectWechat()
  27. {
  28. InitializeComponent();
  29. GetWechatProcess();
  30. }
  31. public void GetWechatProcess()
  32. {
  33. Process p = new Process();
  34. p.StartInfo.FileName = "tools/handle64.exe";
  35. p.StartInfo.Arguments = "-p wechat.exe";
  36. p.StartInfo.UseShellExecute = false;
  37. p.StartInfo.CreateNoWindow = true;
  38. p.StartInfo.RedirectStandardOutput = true;
  39. p.Start();
  40. string i = p.StandardOutput.ReadToEnd();
  41. if (i.Contains("SYSINTERNALS SOFTWARE LICENSE TERMS"))
  42. {
  43. MessageBox.Show("请先同意Handle64的使用协议,同意后关闭弹窗重新打开新增工作区即可");
  44. Process p1 = new Process();
  45. p1.StartInfo.FileName = "tools/handle64.exe";
  46. p1.StartInfo.Arguments = "-p wechat.exe";
  47. p1.Start();
  48. }
  49. string[] lines = i.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  50. bool hitFind = false;
  51. ProcessInfo processInfo = new ProcessInfo();
  52. foreach (string line in lines)
  53. {
  54. if (line.Length < 6)
  55. continue;
  56. if (line.Substring(0, 6).ToLower() == "wechat")
  57. {
  58. hitFind = true;
  59. processInfo = new ProcessInfo();
  60. string[] lineInfo = line.Split(' ');
  61. processInfo.ProcessName = lineInfo[0];
  62. processInfo.ProcessId = lineInfo[2];
  63. }
  64. if (hitFind)
  65. {
  66. if (line.Substring(line.Length - 11, 11) == "MicroMsg.db")
  67. {
  68. Regex regex = new Regex("[a-zA-Z]:\\\\([a-zA-Z0-9() ]*\\\\)*\\w*.*\\w*");
  69. string path = regex.Match(line).Value;
  70. processInfo.DBPath = path;
  71. processInfos.Add(processInfo);
  72. hitFind = false;
  73. }
  74. }
  75. }
  76. list_process.ItemsSource = processInfos;
  77. }
  78. private void list_process_SelectionChanged(object sender, SelectionChangedEventArgs e)
  79. {
  80. SelectProcess = list_process.SelectedItem as ProcessInfo;
  81. }
  82. private void btn_close_Click(object sender, RoutedEventArgs e)
  83. {
  84. Close();
  85. }
  86. }
  87. }