SelectWechat.xaml.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. string[] lines = i.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  42. bool hitFind = false;
  43. ProcessInfo processInfo = new ProcessInfo();
  44. foreach (string line in lines)
  45. {
  46. if (line.Length < 6)
  47. continue;
  48. if (line.Substring(0, 6).ToLower() == "wechat")
  49. {
  50. hitFind = true;
  51. processInfo = new ProcessInfo();
  52. string[] lineInfo = line.Split(' ');
  53. processInfo.ProcessName = lineInfo[0];
  54. processInfo.ProcessId = lineInfo[2];
  55. }
  56. if (hitFind)
  57. {
  58. if (line.Substring(line.Length - 11, 11) == "MicroMsg.db")
  59. {
  60. Regex regex = new Regex("[a-zA-Z]:\\\\([a-zA-Z0-9() ]*\\\\)*\\w*.*\\w*");
  61. string path = regex.Match(line).Value;
  62. processInfo.DBPath = path;
  63. processInfos.Add(processInfo);
  64. hitFind = false;
  65. }
  66. }
  67. }
  68. list_process.ItemsSource = processInfos;
  69. }
  70. private void list_process_SelectionChanged(object sender, SelectionChangedEventArgs e)
  71. {
  72. SelectProcess = list_process.SelectedItem as ProcessInfo;
  73. }
  74. private void btn_close_Click(object sender, RoutedEventArgs e)
  75. {
  76. Close();
  77. }
  78. }
  79. }